From patchwork Fri Sep 22 12:07:25 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: 9965907 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 1121F600C5 for ; Fri, 22 Sep 2017 12:11:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6A8D29889 for ; Fri, 22 Sep 2017 12:11:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB45C29897; Fri, 22 Sep 2017 12:11:11 +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 339D529889 for ; Fri, 22 Sep 2017 12:11:10 +0000 (UTC) Received: from localhost ([::1]:58507 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvMnW-0002nB-78 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 Sep 2017 08:11:10 -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 X-Virus-Scanned: by amavisd-new at test-mx.suse.de 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 += blkdev->nr_ring_ref; + blkdev->xendev.gnttabdev = xengnttab_open(NULL, 0); + if (blkdev->xendev.gnttabdev == 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 = false; } + + if (blkdev->xendev.gnttabdev) { + xengnttab_close(blkdev->xendev.gnttabdev); + blkdev->xendev.gnttabdev = NULL; + } } static int blk_free(struct XenDevice *xendev) @@ -1334,9 +1345,7 @@ static int blk_free(struct XenDevice *xendev) struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev); struct ioreq *ioreq; - if (blkdev->blk || blkdev->sring) { - blk_disconnect(xendev); - } + blk_disconnect(xendev); while (!QLIST_EMPTY(&blkdev->freelist)) { ioreq = QLIST_FIRST(&blkdev->freelist); @@ -1363,7 +1372,6 @@ static void blk_event(struct XenDevice *xendev) struct XenDevOps xen_blkdev_ops = { .size = sizeof(struct XenBlkDev), - .flags = DEVOPS_FLAG_NEED_GNTDEV, .alloc = blk_alloc, .init = blk_init, .initialise = blk_connect,