From patchwork Wed Sep 13 15:46:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 9951575 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 9302F6038F for ; Wed, 13 Sep 2017 15:49:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 856B22885A for ; Wed, 13 Sep 2017 15:49:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79D662887B; Wed, 13 Sep 2017 15:49:14 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2B8BD2885A for ; Wed, 13 Sep 2017 15:49:14 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ds9sS-00027h-A8; Wed, 13 Sep 2017 15:47:00 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ds9sR-00027N-1j for xen-devel@lists.xen.org; Wed, 13 Sep 2017 15:46:59 +0000 Received: from [85.158.139.211] by server-12.bemta-5.messagelabs.com id 4C/CB-30935-2F259B95; Wed, 13 Sep 2017 15:46:58 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrKLMWRWlGSWpSXmKPExsVyuP0Ov+7HoJ2 RBieb9S2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ozvs/8yFUzgqVi5ZS97A+M+zi5GTg4JASOJ txP/MYHYQgILGSVmv3QGsdkEVCU2XD/FCmKLCEhLXPt8mbGLkYuDWWASk8SC7nXsIAlhAUeJn zdbmLsYOThYgBrOzE8ECfMKGEv82PqBBWK+vETHgcksICWcAiYSc/7rQawylrg4fQ7bBEbuBY wMqxjVi1OLylKLdI31kooy0zNKchMzc3QNDUz1clOLixPTU3MSk4r1kvNzNzECPcsABDsY9/5 zOsQoycGkJMq7V3dnpBBfUn5KZUZicUZ8UWlOavEhRhkODiUJXlZgoAgJFqWmp1akZeYAQwwm LcHBoyTC+zwQKM1bXJCYW5yZDpE6xWjMcWzT5T9MHB037/5hEmLJy89LlRLnXQFSKgBSmlGaB zcIFvqXGGWlhHkZgU4T4ilILcrNLEGVf8UozsGoJMxbCDKFJzOvBG7fK6BTmIBOOXN6B8gpJY kIKakGxpLjna2Vmj4Z8eqH5UpqHqou1f13IrKxOjhJyGOOcV8Nx8TkmTJ7p130nLdi7aOPD+/ dv7h+sZGvCWPMthX6h5UC58XZmv5wj2K4IM5T8V5zatzc2rnycnferSj3kHvDqBg2P6Vq0+2v QXdy814zT14h/9677lydmKT73ITj5YvitjvwHVywS4mlOCPRUIu5qDgRADDXcul4AgAA X-Env-Sender: jgross@suse.com X-Msg-Ref: server-3.tower-206.messagelabs.com!1505317617!107809126!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 13211 invoked from network); 13 Sep 2017 15:46:57 -0000 Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by server-3.tower-206.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 13 Sep 2017 15:46:57 -0000 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 F3B10ACFA; Wed, 13 Sep 2017 15:46:56 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xen.org Date: Wed, 13 Sep 2017 17:46:40 +0200 Message-Id: <20170913154651.2366-2-jgross@suse.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20170913154651.2366-1-jgross@suse.com> References: <20170913154651.2366-1-jgross@suse.com> Cc: Juergen Gross , sstabellini@kernel.org, wei.liu2@citrix.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, julien.grall@arm.com, jbeulich@suse.com, dgdegra@tycho.nsa.gov Subject: [Xen-devel] [PATCH v6 01/12] xen: correct gnttab_get_status_frames() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP In gnttab_get_status_frames() all accesses to nr_status_frames should be done with the grant table lock held. While at it correct coding style: labels should be indented by one space. Signed-off-by: Juergen Gross Reviewed-by: Paul Durrant Reviewed-by: Wei Liu --- xen/common/grant_table.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index c3895e6201..00ff075bd9 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -2866,19 +2866,19 @@ gnttab_get_status_frames(XEN_GUEST_HANDLE_PARAM(gnttab_get_status_frames_t) uop, gt = d->grant_table; + op.status = GNTST_okay; + + grant_read_lock(gt); + if ( unlikely(op.nr_frames > nr_status_frames(gt)) ) { gdprintk(XENLOG_INFO, "Guest requested addresses for %d grant status " "frames, but only %d are available.\n", op.nr_frames, nr_status_frames(gt)); op.status = GNTST_general_error; - goto out2; + goto unlock; } - op.status = GNTST_okay; - - grant_read_lock(gt); - for ( i = 0; i < op.nr_frames; i++ ) { gmfn = gnttab_status_gmfn(d, gt, i); @@ -2886,10 +2886,11 @@ gnttab_get_status_frames(XEN_GUEST_HANDLE_PARAM(gnttab_get_status_frames_t) uop, op.status = GNTST_bad_virt_addr; } + unlock: grant_read_unlock(gt); -out2: + out2: rcu_unlock_domain(d); -out1: + out1: if ( unlikely(__copy_field_to_guest(uop, &op, status)) ) return -EFAULT;