[{"id":1772034,"web_url":"http://patchwork.ozlabs.org/comment/1772034/","msgid":"<20170920145300.GA1859@perard.uk.xensource.com>","list_archive_url":null,"date":"2017-09-20T14:53:00","subject":"Re: [Qemu-devel] [PATCH 1/2] xen: add a global indicator for grant\n\tcopy being available","submitter":{"id":4759,"url":"http://patchwork.ozlabs.org/api/people/4759/","name":"Anthony PERARD","email":"anthony.perard@citrix.com"},"content":"On Tue, Sep 19, 2017 at 01:50:54PM +0200, Juergen Gross wrote:\n> The Xen qdisk backend needs to test whether grant copy operations is\n> available in the kernel. Unfortunately this collides with using\n> xengnttab_set_max_grants() on some kernels as this operation has to\n> be the first one after opening the gnttab device.\n> \n> In order to solve this problem test for the availability of grant copy\n> in xen_be_init() opening the gnttab device just for that purpose and\n> closing it again afterwards. Advertise the availability via a global\n> flag and use that flag in the qdisk backend.\n> \n> Signed-off-by: Juergen Gross <jgross@suse.com>\n> ---\n>  hw/block/xen_disk.c          | 18 ++++++------------\n>  hw/xen/xen_backend.c         | 11 +++++++++++\n>  include/hw/xen/xen_backend.h |  1 +\n>  3 files changed, 18 insertions(+), 12 deletions(-)\n> \n> diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c\n> index d42ed7070d..6632746250 100644\n> --- a/hw/block/xen_disk.c\n> +++ b/hw/block/xen_disk.c\n> @@ -121,9 +121,6 @@ struct XenBlkDev {\n>      unsigned int        persistent_gnt_count;\n>      unsigned int        max_grants;\n>  \n> -    /* Grant copy */\n> -    gboolean            feature_grant_copy;\n> -\n>      /* qemu block driver */\n>      DriveInfo           *dinfo;\n>      BlockBackend        *blk;\n> @@ -616,7 +613,7 @@ static void qemu_aio_complete(void *opaque, int ret)\n>          return;\n>      }\n>  \n> -    if (ioreq->blkdev->feature_grant_copy) {\n> +    if (xen_feature_grant_copy) {\n>          switch (ioreq->req.operation) {\n>          case BLKIF_OP_READ:\n>              /* in case of failure ioreq->aio_errors is increased */\n> @@ -638,7 +635,7 @@ static void qemu_aio_complete(void *opaque, int ret)\n>      }\n>  \n>      ioreq->status = ioreq->aio_errors ? BLKIF_RSP_ERROR : BLKIF_RSP_OKAY;\n> -    if (!ioreq->blkdev->feature_grant_copy) {\n> +    if (!xen_feature_grant_copy) {\n>          ioreq_unmap(ioreq);\n>      }\n>      ioreq_finish(ioreq);\n> @@ -698,7 +695,7 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq)\n>  {\n>      struct XenBlkDev *blkdev = ioreq->blkdev;\n>  \n> -    if (ioreq->blkdev->feature_grant_copy) {\n> +    if (xen_feature_grant_copy) {\n>          ioreq_init_copy_buffers(ioreq);\n>          if (ioreq->req.nr_segments && (ioreq->req.operation == BLKIF_OP_WRITE ||\n>              ioreq->req.operation == BLKIF_OP_FLUSH_DISKCACHE) &&\n> @@ -750,7 +747,7 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq)\n>      }\n>      default:\n>          /* unknown operation (shouldn't happen -- parse catches this) */\n> -        if (!ioreq->blkdev->feature_grant_copy) {\n> +        if (!xen_feature_grant_copy) {\n>              ioreq_unmap(ioreq);\n>          }\n>          goto err;\n> @@ -1010,18 +1007,15 @@ static int blk_init(struct XenDevice *xendev)\n>  \n>      blkdev->file_blk  = BLOCK_SIZE;\n>  \n> -    blkdev->feature_grant_copy =\n> -                (xengnttab_grant_copy(blkdev->xendev.gnttabdev, 0, NULL) == 0);\n> -\n>      xen_pv_printf(&blkdev->xendev, 3, \"grant copy operation %s\\n\",\n> -                  blkdev->feature_grant_copy ? \"enabled\" : \"disabled\");\n> +                  xen_feature_grant_copy ? \"enabled\" : \"disabled\");\n>  \n>      /* fill info\n>       * blk_connect supplies sector-size and sectors\n>       */\n>      xenstore_write_be_int(&blkdev->xendev, \"feature-flush-cache\", 1);\n>      xenstore_write_be_int(&blkdev->xendev, \"feature-persistent\",\n> -                          !blkdev->feature_grant_copy);\n> +                          !xen_feature_grant_copy);\n>      xenstore_write_be_int(&blkdev->xendev, \"info\", info);\n>  \n>      xenstore_write_be_int(&blkdev->xendev, \"max-ring-page-order\",\n> diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c\n> index c46cbb0759..00210627a9 100644\n> --- a/hw/xen/xen_backend.c\n> +++ b/hw/xen/xen_backend.c\n> @@ -44,6 +44,7 @@ BusState *xen_sysbus;\n>  /* public */\n>  struct xs_handle *xenstore = NULL;\n>  const char *xen_protocol;\n> +gboolean xen_feature_grant_copy;\n\nI think it would be better if this was changed to bool instead of a\ngboolean.\n\nBeside that,\nAcked-by: Anthony PERARD <anthony.perard@citrix.com>\n\n>  \n>  /* private */\n>  static int debug;\n> @@ -519,6 +520,8 @@ void xenstore_update_fe(char *watch, struct XenDevice *xendev)\n>  \n>  int xen_be_init(void)\n>  {\n> +    xengnttab_handle *gnttabdev;\n> +\n>      xenstore = xs_daemon_open();\n>      if (!xenstore) {\n>          xen_pv_printf(NULL, 0, \"can't connect to xenstored\\n\");\n> @@ -532,6 +535,14 @@ int xen_be_init(void)\n>          goto err;\n>      }\n>  \n> +    gnttabdev = xengnttab_open(NULL, 0);\n> +    if (gnttabdev != NULL) {\n> +        if (xengnttab_grant_copy(gnttabdev, 0, NULL) == 0) {\n> +            xen_feature_grant_copy = true;\n> +        }\n> +        xengnttab_close(gnttabdev);\n> +    }\n> +\n>      xen_sysdev = qdev_create(NULL, TYPE_XENSYSDEV);\n>      qdev_init_nofail(xen_sysdev);\n>      xen_sysbus = qbus_create(TYPE_XENSYSBUS, DEVICE(xen_sysdev), \"xen-sysbus\");\n> diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h\n> index 8a6fbcbe20..08a054f524 100644\n> --- a/include/hw/xen/xen_backend.h\n> +++ b/include/hw/xen/xen_backend.h\n> @@ -16,6 +16,7 @@\n>  /* variables */\n>  extern struct xs_handle *xenstore;\n>  extern const char *xen_protocol;\n> +extern gboolean xen_feature_grant_copy;\n>  extern DeviceState *xen_sysdev;\n>  extern BusState *xen_sysbus;\n>  \n> -- \n> 2.12.3\n>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xy4bK4n4cz9s7c\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 21 Sep 2017 02:15:25 +1000 (AEST)","from localhost ([::1]:49404 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1duhel-0003Pz-NJ\n\tfor incoming@patchwork.ozlabs.org; Wed, 20 Sep 2017 12:15:23 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:37594)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <prvs=4297b1e9d=anthony.perard@citrix.com>)\n\tid 1dugN8-0005pk-W6\n\tfor qemu-devel@nongnu.org; Wed, 20 Sep 2017 10:53:08 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <prvs=4297b1e9d=anthony.perard@citrix.com>)\n\tid 1dugN5-0003K1-TW\n\tfor qemu-devel@nongnu.org; Wed, 20 Sep 2017 10:53:07 -0400","from smtp.citrix.com ([66.165.176.89]:60964)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71)\n\t(envelope-from <prvs=4297b1e9d=anthony.perard@citrix.com>)\n\tid 1dugN5-0003JL-Ma\n\tfor qemu-devel@nongnu.org; Wed, 20 Sep 2017 10:53:03 -0400"],"X-IronPort-AV":"E=Sophos;i=\"5.42,421,1500940800\"; d=\"scan'208\";a=\"440521174\"","Date":"Wed, 20 Sep 2017 15:53:00 +0100","From":"Anthony PERARD <anthony.perard@citrix.com>","To":"Juergen Gross <jgross@suse.com>","Message-ID":"<20170920145300.GA1859@perard.uk.xensource.com>","References":"<20170919115055.19278-1-jgross@suse.com>\n\t<20170919115055.19278-2-jgross@suse.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Disposition":"inline","In-Reply-To":"<20170919115055.19278-2-jgross@suse.com>","User-Agent":"Mutt/1.9.0 (2017-09-02)","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"66.165.176.89","Subject":"Re: [Qemu-devel] [PATCH 1/2] xen: add a global indicator for grant\n\tcopy being available","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"xen-devel@lists.xenproject.org, sstabellini@kernel.org,\n\tqemu-devel@nongnu.org, kraxel@redhat.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1773513,"web_url":"http://patchwork.ozlabs.org/comment/1773513/","msgid":"<55c1c15f-ead3-54a1-5269-a4149cc83005@suse.com>","list_archive_url":null,"date":"2017-09-22T11:46:20","subject":"Re: [Qemu-devel] [PATCH 1/2] xen: add a global indicator for grant\n\tcopy being available","submitter":{"id":64874,"url":"http://patchwork.ozlabs.org/api/people/64874/","name":"Jürgen Groß","email":"jgross@suse.com"},"content":"On 20/09/17 16:53, Anthony PERARD wrote:\n> On Tue, Sep 19, 2017 at 01:50:54PM +0200, Juergen Gross wrote:\n>> The Xen qdisk backend needs to test whether grant copy operations is\n>> available in the kernel. Unfortunately this collides with using\n>> xengnttab_set_max_grants() on some kernels as this operation has to\n>> be the first one after opening the gnttab device.\n>>\n>> In order to solve this problem test for the availability of grant copy\n>> in xen_be_init() opening the gnttab device just for that purpose and\n>> closing it again afterwards. Advertise the availability via a global\n>> flag and use that flag in the qdisk backend.\n>>\n>> Signed-off-by: Juergen Gross <jgross@suse.com>\n>> ---\n>>  hw/block/xen_disk.c          | 18 ++++++------------\n>>  hw/xen/xen_backend.c         | 11 +++++++++++\n>>  include/hw/xen/xen_backend.h |  1 +\n>>  3 files changed, 18 insertions(+), 12 deletions(-)\n>>\n>> diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c\n>> index d42ed7070d..6632746250 100644\n>> --- a/hw/block/xen_disk.c\n>> +++ b/hw/block/xen_disk.c\n>> @@ -121,9 +121,6 @@ struct XenBlkDev {\n>>      unsigned int        persistent_gnt_count;\n>>      unsigned int        max_grants;\n>>  \n>> -    /* Grant copy */\n>> -    gboolean            feature_grant_copy;\n>> -\n>>      /* qemu block driver */\n>>      DriveInfo           *dinfo;\n>>      BlockBackend        *blk;\n>> @@ -616,7 +613,7 @@ static void qemu_aio_complete(void *opaque, int ret)\n>>          return;\n>>      }\n>>  \n>> -    if (ioreq->blkdev->feature_grant_copy) {\n>> +    if (xen_feature_grant_copy) {\n>>          switch (ioreq->req.operation) {\n>>          case BLKIF_OP_READ:\n>>              /* in case of failure ioreq->aio_errors is increased */\n>> @@ -638,7 +635,7 @@ static void qemu_aio_complete(void *opaque, int ret)\n>>      }\n>>  \n>>      ioreq->status = ioreq->aio_errors ? BLKIF_RSP_ERROR : BLKIF_RSP_OKAY;\n>> -    if (!ioreq->blkdev->feature_grant_copy) {\n>> +    if (!xen_feature_grant_copy) {\n>>          ioreq_unmap(ioreq);\n>>      }\n>>      ioreq_finish(ioreq);\n>> @@ -698,7 +695,7 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq)\n>>  {\n>>      struct XenBlkDev *blkdev = ioreq->blkdev;\n>>  \n>> -    if (ioreq->blkdev->feature_grant_copy) {\n>> +    if (xen_feature_grant_copy) {\n>>          ioreq_init_copy_buffers(ioreq);\n>>          if (ioreq->req.nr_segments && (ioreq->req.operation == BLKIF_OP_WRITE ||\n>>              ioreq->req.operation == BLKIF_OP_FLUSH_DISKCACHE) &&\n>> @@ -750,7 +747,7 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq)\n>>      }\n>>      default:\n>>          /* unknown operation (shouldn't happen -- parse catches this) */\n>> -        if (!ioreq->blkdev->feature_grant_copy) {\n>> +        if (!xen_feature_grant_copy) {\n>>              ioreq_unmap(ioreq);\n>>          }\n>>          goto err;\n>> @@ -1010,18 +1007,15 @@ static int blk_init(struct XenDevice *xendev)\n>>  \n>>      blkdev->file_blk  = BLOCK_SIZE;\n>>  \n>> -    blkdev->feature_grant_copy =\n>> -                (xengnttab_grant_copy(blkdev->xendev.gnttabdev, 0, NULL) == 0);\n>> -\n>>      xen_pv_printf(&blkdev->xendev, 3, \"grant copy operation %s\\n\",\n>> -                  blkdev->feature_grant_copy ? \"enabled\" : \"disabled\");\n>> +                  xen_feature_grant_copy ? \"enabled\" : \"disabled\");\n>>  \n>>      /* fill info\n>>       * blk_connect supplies sector-size and sectors\n>>       */\n>>      xenstore_write_be_int(&blkdev->xendev, \"feature-flush-cache\", 1);\n>>      xenstore_write_be_int(&blkdev->xendev, \"feature-persistent\",\n>> -                          !blkdev->feature_grant_copy);\n>> +                          !xen_feature_grant_copy);\n>>      xenstore_write_be_int(&blkdev->xendev, \"info\", info);\n>>  \n>>      xenstore_write_be_int(&blkdev->xendev, \"max-ring-page-order\",\n>> diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c\n>> index c46cbb0759..00210627a9 100644\n>> --- a/hw/xen/xen_backend.c\n>> +++ b/hw/xen/xen_backend.c\n>> @@ -44,6 +44,7 @@ BusState *xen_sysbus;\n>>  /* public */\n>>  struct xs_handle *xenstore = NULL;\n>>  const char *xen_protocol;\n>> +gboolean xen_feature_grant_copy;\n> \n> I think it would be better if this was changed to bool instead of a\n> gboolean.\n\nOkay.\n\n> \n> Beside that,\n> Acked-by: Anthony PERARD <anthony.perard@citrix.com>\n\nThanks,\n\nJuergen","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xzBXz02tLz9sP1\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 22 Sep 2017 21:47:15 +1000 (AEST)","from localhost ([::1]:58160 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dvMQL-0008MU-2C\n\tfor incoming@patchwork.ozlabs.org; Fri, 22 Sep 2017 07:47:13 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:42378)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <jgross@suse.com>) id 1dvMPb-0008DQ-BQ\n\tfor qemu-devel@nongnu.org; Fri, 22 Sep 2017 07:46:29 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <jgross@suse.com>) id 1dvMPY-00026v-6k\n\tfor qemu-devel@nongnu.org; Fri, 22 Sep 2017 07:46:27 -0400","from mx2.suse.de ([195.135.220.15]:58203 helo=mx1.suse.de)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <jgross@suse.com>) id 1dvMPX-00024f-T3\n\tfor qemu-devel@nongnu.org; Fri, 22 Sep 2017 07:46:24 -0400","from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254])\n\tby mx1.suse.de (Postfix) with ESMTP id 80303ABB8;\n\tFri, 22 Sep 2017 11:46:21 +0000 (UTC)"],"X-Virus-Scanned":"by amavisd-new at test-mx.suse.de","To":"Anthony PERARD <anthony.perard@citrix.com>","References":"<20170919115055.19278-1-jgross@suse.com>\n\t<20170919115055.19278-2-jgross@suse.com>\n\t<20170920145300.GA1859@perard.uk.xensource.com>","From":"Juergen Gross <jgross@suse.com>","Message-ID":"<55c1c15f-ead3-54a1-5269-a4149cc83005@suse.com>","Date":"Fri, 22 Sep 2017 13:46:20 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<20170920145300.GA1859@perard.uk.xensource.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"de-DE","Content-Transfer-Encoding":"7bit","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no\n\ttimestamps) [generic] [fuzzy]","X-Received-From":"195.135.220.15","Subject":"Re: [Qemu-devel] [PATCH 1/2] xen: add a global indicator for grant\n\tcopy being available","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"xen-devel@lists.xenproject.org, sstabellini@kernel.org,\n\tqemu-devel@nongnu.org, kraxel@redhat.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}}]