{"id":815478,"url":"http://patchwork.ozlabs.org/api/patches/815478/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170919115055.19278-2-jgross@suse.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170919115055.19278-2-jgross@suse.com>","list_archive_url":null,"date":"2017-09-19T11:50:54","name":"[1/2] xen: add a global indicator for grant copy being available","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"8587ca96c9fdb6daae2c3319855024ed32dfa1ca","submitter":{"id":64874,"url":"http://patchwork.ozlabs.org/api/people/64874/?format=json","name":"Jürgen Groß","email":"jgross@suse.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170919115055.19278-2-jgross@suse.com/mbox/","series":[{"id":3854,"url":"http://patchwork.ozlabs.org/api/series/3854/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=3854","date":"2017-09-19T11:50:55","name":"xen: fix gnttab handling with old dom0 kernels","version":1,"mbox":"http://patchwork.ozlabs.org/series/3854/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/815478/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/815478/checks/","tags":{},"related":[],"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 3xxLnc6WsVz9sBZ\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 19 Sep 2017 21:51:48 +1000 (AEST)","from localhost ([::1]:41946 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 1duH46-0002DQ-UA\n\tfor incoming@patchwork.ozlabs.org; Tue, 19 Sep 2017 07:51:46 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:36326)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <jgross@suse.com>) id 1duH3U-0002CI-E6\n\tfor qemu-devel@nongnu.org; Tue, 19 Sep 2017 07:51:09 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <jgross@suse.com>) id 1duH3R-0006Bc-G4\n\tfor qemu-devel@nongnu.org; Tue, 19 Sep 2017 07:51:08 -0400","from mx2.suse.de ([195.135.220.15]:47667 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 1duH3R-0006AG-6N\n\tfor qemu-devel@nongnu.org; Tue, 19 Sep 2017 07:51:05 -0400","from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254])\n\tby mx1.suse.de (Postfix) with ESMTP id C9A9A5CBBF;\n\tTue, 19 Sep 2017 11:51:02 +0000 (UTC)"],"X-Virus-Scanned":"by amavisd-new at test-mx.suse.de","From":"Juergen Gross <jgross@suse.com>","To":"qemu-devel@nongnu.org,\n\txen-devel@lists.xenproject.org","Date":"Tue, 19 Sep 2017 13:50:54 +0200","Message-Id":"<20170919115055.19278-2-jgross@suse.com>","X-Mailer":"git-send-email 2.12.3","In-Reply-To":"<20170919115055.19278-1-jgross@suse.com>","References":"<20170919115055.19278-1-jgross@suse.com>","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":"[Qemu-devel] [PATCH 1/2] xen: add a global indicator for grant copy\n\tbeing 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":"anthony.perard@citrix.com, Juergen Gross <jgross@suse.com>,\n\tsstabellini@kernel.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>"},"content":"The Xen qdisk backend needs to test whether grant copy operations is\navailable in the kernel. Unfortunately this collides with using\nxengnttab_set_max_grants() on some kernels as this operation has to\nbe the first one after opening the gnttab device.\n\nIn order to solve this problem test for the availability of grant copy\nin xen_be_init() opening the gnttab device just for that purpose and\nclosing it again afterwards. Advertise the availability via a global\nflag and use that flag in the qdisk backend.\n\nSigned-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(-)","diff":"diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c\nindex 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\",\ndiff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c\nindex 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 /* 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\");\ndiff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h\nindex 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","prefixes":["1/2"]}