From patchwork Tue Sep 19 11:50:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 9958735 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6F1DA6056A for ; Tue, 19 Sep 2017 11:52:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DFE528DF3 for ; Tue, 19 Sep 2017 11:52:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62EB228E3B; Tue, 19 Sep 2017 11:52:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4FACE28DF3 for ; Tue, 19 Sep 2017 11:52:19 +0000 (UTC) Received: from localhost ([::1]:41946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duH4c-0002DQ-De for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Sep 2017 07:52:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duH3U-0002CI-E6 for qemu-devel@nongnu.org; Tue, 19 Sep 2017 07:51:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1duH3R-0006Bc-G4 for qemu-devel@nongnu.org; Tue, 19 Sep 2017 07:51:08 -0400 Received: from mx2.suse.de ([195.135.220.15]:47667 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 1duH3R-0006AG-6N for qemu-devel@nongnu.org; Tue, 19 Sep 2017 07:51:05 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C9A9A5CBBF; Tue, 19 Sep 2017 11:51:02 +0000 (UTC) From: Juergen Gross To: qemu-devel@nongnu.org, xen-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 timestamps) [generic] [fuzzy] X-Received-From: 195.135.220.15 Subject: [Qemu-devel] [PATCH 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 d42ed7070d..6632746250 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; - /* 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; } - 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) } ioreq->status = 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 = ioreq->blkdev; - if (ioreq->blkdev->feature_grant_copy) { + if (xen_feature_grant_copy) { ioreq_init_copy_buffers(ioreq); if (ioreq->req.nr_segments && (ioreq->req.operation == BLKIF_OP_WRITE || ioreq->req.operation == 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) blkdev->file_blk = BLOCK_SIZE; - blkdev->feature_grant_copy = - (xengnttab_grant_copy(blkdev->xendev.gnttabdev, 0, NULL) == 0); - xen_pv_printf(&blkdev->xendev, 3, "grant copy operation %s\n", - blkdev->feature_grant_copy ? "enabled" : "disabled"); + xen_feature_grant_copy ? "enabled" : "disabled"); /* 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); 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..00210627a9 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 = NULL; const char *xen_protocol; +gboolean xen_feature_grant_copy; /* private */ static int debug; @@ -519,6 +520,8 @@ void xenstore_update_fe(char *watch, struct XenDevice *xendev) int xen_be_init(void) { + xengnttab_handle *gnttabdev; + xenstore = 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; } + gnttabdev = xengnttab_open(NULL, 0); + if (gnttabdev != NULL) { + if (xengnttab_grant_copy(gnttabdev, 0, NULL) == 0) { + xen_feature_grant_copy = true; + } + xengnttab_close(gnttabdev); + } + xen_sysdev = qdev_create(NULL, TYPE_XENSYSDEV); qdev_init_nofail(xen_sysdev); xen_sysbus = qbus_create(TYPE_XENSYSBUS, DEVICE(xen_sysdev), "xen-sysbus"); diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index 8a6fbcbe20..08a054f524 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 gboolean xen_feature_grant_copy; extern DeviceState *xen_sysdev; extern BusState *xen_sysbus;