From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Wilson Subject: [RFC PATCH 1/2] gnttab: lock the local grant table earlier in __gnttab_unmap_common() Date: Mon, 11 Nov 2013 18:03:11 -0800 Message-ID: <1384221792-3456-2-git-send-email-msw@linux.com> References: <1384221792-3456-1-git-send-email-msw@linux.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Vg3KN-0003kL-9b for xen-devel@lists.xenproject.org; Tue, 12 Nov 2013 02:03:39 +0000 Received: by mail-pb0-f53.google.com with SMTP id up7so6022216pbc.40 for ; Mon, 11 Nov 2013 18:03:35 -0800 (PST) In-Reply-To: <1384221792-3456-1-git-send-email-msw@linux.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Felipe Franciosi , Anthony Liguori , Andrew Cooper , David Vrabel , Jan Beulich , Keir Fraser , Matt Wilson , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= List-Id: xen-devel@lists.xenproject.org From: Matt Wilson Luckily today maptrack_limit never shrinks. But if at some point in the future this were to change, checking maptrack_limit without holding the grant table spinlock would no longer be safe. Cc: xen-devel@lists.xenproject.org Cc: Keir Fraser Cc: Jan Beulich Reviewed-by: Andrew Cooper Reviewed-by: Anthony Liguori Signed-off-by: Matt Wilson --- v1->v2: * updated summary to use "local" instead of "left" --- xen/common/grant_table.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 21c6a14..ef10ff4 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -842,15 +842,16 @@ __gnttab_unmap_common( op->frame = (unsigned long)(op->dev_bus_addr >> PAGE_SHIFT); + spin_lock(&lgt->lock); if ( unlikely(op->handle >= lgt->maptrack_limit) ) { + spin_unlock(&lgt->lock); gdprintk(XENLOG_INFO, "Bad handle (%d).\n", op->handle); op->status = GNTST_bad_handle; return; } op->map = &maptrack_entry(lgt, op->handle); - spin_lock(&lgt->lock); if ( unlikely(!op->map->flags) ) { -- 1.7.9.5