From nobody Fri May 3 06:19:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506082389077895.2327530946199; Fri, 22 Sep 2017 05:13:09 -0700 (PDT) Received: from localhost ([::1]:58529 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvMpJ-0005Ei-UW for importer@patchew.org; Fri, 22 Sep 2017 08:13:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47928) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvMk3-0000mH-Qj for qemu-devel@nongnu.org; Fri, 22 Sep 2017 08:07:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dvMjx-0007Ia-KJ for qemu-devel@nongnu.org; Fri, 22 Sep 2017 08:07:35 -0400 Received: from mx2.suse.de ([195.135.220.15]:33104 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dvMjx-0007Hu-AK for qemu-devel@nongnu.org; Fri, 22 Sep 2017 08:07:29 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 48FADACB8; Fri, 22 Sep 2017 12:07:28 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: qemu-devel@nongnu.org, xen-devel@lists.xenproject.org Date: Fri, 22 Sep 2017 14:07:24 +0200 Message-Id: <20170922120725.10910-2-jgross@suse.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20170922120725.10910-1-jgross@suse.com> References: <20170922120725.10910-1-jgross@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 195.135.220.15 Subject: [Qemu-devel] [PATCH v2 1/2] xen: add a global indicator for grant copy being available X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: anthony.perard@citrix.com, Juergen Gross , sstabellini@kernel.org, kraxel@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The Xen qdisk backend needs to test whether grant copy operations is available in the kernel. Unfortunately this collides with using xengnttab_set_max_grants() on some kernels as this operation has to be the first one after opening the gnttab device. In order to solve this problem test for the availability of grant copy in xen_be_init() opening the gnttab device just for that purpose and closing it again afterwards. Advertise the availability via a global flag and use that flag in the qdisk backend. Signed-off-by: Juergen Gross Acked-by: Anthony PERARD --- V2: - gboolean -> bool (Anthony PERARD) --- hw/block/xen_disk.c | 18 ++++++------------ hw/xen/xen_backend.c | 11 +++++++++++ include/hw/xen/xen_backend.h | 1 + 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 536e2ee735..62506e3167 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -121,9 +121,6 @@ struct XenBlkDev { unsigned int persistent_gnt_count; unsigned int max_grants; =20 - /* Grant copy */ - gboolean feature_grant_copy; - /* qemu block driver */ DriveInfo *dinfo; BlockBackend *blk; @@ -616,7 +613,7 @@ static void qemu_aio_complete(void *opaque, int ret) return; } =20 - if (ioreq->blkdev->feature_grant_copy) { + if (xen_feature_grant_copy) { switch (ioreq->req.operation) { case BLKIF_OP_READ: /* in case of failure ioreq->aio_errors is increased */ @@ -638,7 +635,7 @@ static void qemu_aio_complete(void *opaque, int ret) } =20 ioreq->status =3D ioreq->aio_errors ? BLKIF_RSP_ERROR : BLKIF_RSP_OKAY; - if (!ioreq->blkdev->feature_grant_copy) { + if (!xen_feature_grant_copy) { ioreq_unmap(ioreq); } ioreq_finish(ioreq); @@ -698,7 +695,7 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq) { struct XenBlkDev *blkdev =3D ioreq->blkdev; =20 - if (ioreq->blkdev->feature_grant_copy) { + if (xen_feature_grant_copy) { ioreq_init_copy_buffers(ioreq); if (ioreq->req.nr_segments && (ioreq->req.operation =3D=3D BLKIF_O= P_WRITE || ioreq->req.operation =3D=3D BLKIF_OP_FLUSH_DISKCACHE) && @@ -750,7 +747,7 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq) } default: /* unknown operation (shouldn't happen -- parse catches this) */ - if (!ioreq->blkdev->feature_grant_copy) { + if (!xen_feature_grant_copy) { ioreq_unmap(ioreq); } goto err; @@ -1010,18 +1007,15 @@ static int blk_init(struct XenDevice *xendev) =20 blkdev->file_blk =3D BLOCK_SIZE; =20 - blkdev->feature_grant_copy =3D - (xengnttab_grant_copy(blkdev->xendev.gnttabdev, 0, NULL) = =3D=3D 0); - xen_pv_printf(&blkdev->xendev, 3, "grant copy operation %s\n", - blkdev->feature_grant_copy ? "enabled" : "disabled"); + xen_feature_grant_copy ? "enabled" : "disabled"); =20 /* fill info * blk_connect supplies sector-size and sectors */ xenstore_write_be_int(&blkdev->xendev, "feature-flush-cache", 1); xenstore_write_be_int(&blkdev->xendev, "feature-persistent", - !blkdev->feature_grant_copy); + !xen_feature_grant_copy); xenstore_write_be_int(&blkdev->xendev, "info", info); =20 xenstore_write_be_int(&blkdev->xendev, "max-ring-page-order", diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index c46cbb0759..0f849a26d2 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -44,6 +44,7 @@ BusState *xen_sysbus; /* public */ struct xs_handle *xenstore =3D NULL; const char *xen_protocol; +bool xen_feature_grant_copy; =20 /* private */ static int debug; @@ -519,6 +520,8 @@ void xenstore_update_fe(char *watch, struct XenDevice *= xendev) =20 int xen_be_init(void) { + xengnttab_handle *gnttabdev; + xenstore =3D xs_daemon_open(); if (!xenstore) { xen_pv_printf(NULL, 0, "can't connect to xenstored\n"); @@ -532,6 +535,14 @@ int xen_be_init(void) goto err; } =20 + gnttabdev =3D xengnttab_open(NULL, 0); + if (gnttabdev !=3D NULL) { + if (xengnttab_grant_copy(gnttabdev, 0, NULL) =3D=3D 0) { + xen_feature_grant_copy =3D true; + } + xengnttab_close(gnttabdev); + } + xen_sysdev =3D qdev_create(NULL, TYPE_XENSYSDEV); qdev_init_nofail(xen_sysdev); xen_sysbus =3D qbus_create(TYPE_XENSYSBUS, DEVICE(xen_sysdev), "xen-sy= sbus"); diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index 8a6fbcbe20..3a27692407 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -16,6 +16,7 @@ /* variables */ extern struct xs_handle *xenstore; extern const char *xen_protocol; +extern bool xen_feature_grant_copy; extern DeviceState *xen_sysdev; extern BusState *xen_sysbus; =20 --=20 2.12.3 From nobody Fri May 3 06:19:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506082295777794.9368632883162; Fri, 22 Sep 2017 05:11:35 -0700 (PDT) Received: from localhost ([::1]:58521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvMnu-0003yE-HK for importer@patchew.org; Fri, 22 Sep 2017 08:11:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47904) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvMk1-0000kY-5l for qemu-devel@nongnu.org; Fri, 22 Sep 2017 08:07:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dvMjx-0007In-Ow for qemu-devel@nongnu.org; Fri, 22 Sep 2017 08:07:33 -0400 Received: from mx2.suse.de ([195.135.220.15]:33111 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dvMjx-0007I7-Im for qemu-devel@nongnu.org; Fri, 22 Sep 2017 08:07:29 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 92B59ACC3; Fri, 22 Sep 2017 12:07:28 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: qemu-devel@nongnu.org, xen-devel@lists.xenproject.org Date: Fri, 22 Sep 2017 14:07:25 +0200 Message-Id: <20170922120725.10910-3-jgross@suse.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20170922120725.10910-1-jgross@suse.com> References: <20170922120725.10910-1-jgross@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 195.135.220.15 Subject: [Qemu-devel] [PATCH v2 2/2] xen: dont try setting max grants multiple times X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: anthony.perard@citrix.com, Juergen Gross , sstabellini@kernel.org, kraxel@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Trying to call xengnttab_set_max_grants() with the same file handle might fail on some kernels, as this operation is allowed only once. This is a problem for the qdisk backend as blk_connect() can be called multiple times for a domain, e.g. in case grub-xen is being used to boot it. So instead of letting the generic backend code open the gnttab device do it in blk_connect() and close it again in blk_disconnect. Signed-off-by: Juergen Gross Acked-by: Anthony PERARD --- V2: - always call blk_disconnect() from blk_free() in order to have the gnttab device node closed (Anthony Perard) --- hw/block/xen_disk.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 62506e3167..e431bd89e8 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -1220,6 +1220,12 @@ static int blk_connect(struct XenDevice *xendev) /* Add on the number needed for the ring pages */ max_grants +=3D blkdev->nr_ring_ref; =20 + blkdev->xendev.gnttabdev =3D xengnttab_open(NULL, 0); + if (blkdev->xendev.gnttabdev =3D=3D NULL) { + xen_pv_printf(xendev, 0, "xengnttab_open failed: %s\n", + strerror(errno)); + return -1; + } if (xengnttab_set_max_grants(blkdev->xendev.gnttabdev, max_grants)) { xen_pv_printf(xendev, 0, "xengnttab_set_max_grants failed: %s\n", strerror(errno)); @@ -1327,6 +1333,11 @@ static void blk_disconnect(struct XenDevice *xendev) } blkdev->feature_persistent =3D false; } + + if (blkdev->xendev.gnttabdev) { + xengnttab_close(blkdev->xendev.gnttabdev); + blkdev->xendev.gnttabdev =3D NULL; + } } =20 static int blk_free(struct XenDevice *xendev) @@ -1334,9 +1345,7 @@ static int blk_free(struct XenDevice *xendev) struct XenBlkDev *blkdev =3D container_of(xendev, struct XenBlkDev, xe= ndev); struct ioreq *ioreq; =20 - if (blkdev->blk || blkdev->sring) { - blk_disconnect(xendev); - } + blk_disconnect(xendev); =20 while (!QLIST_EMPTY(&blkdev->freelist)) { ioreq =3D QLIST_FIRST(&blkdev->freelist); @@ -1363,7 +1372,6 @@ static void blk_event(struct XenDevice *xendev) =20 struct XenDevOps xen_blkdev_ops =3D { .size =3D sizeof(struct XenBlkDev), - .flags =3D DEVOPS_FLAG_NEED_GNTDEV, .alloc =3D blk_alloc, .init =3D blk_init, .initialise =3D blk_connect, --=20 2.12.3