From patchwork Fri May 20 13:37:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 68241 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp3784438qge; Fri, 20 May 2016 06:39:06 -0700 (PDT) X-Received: by 10.55.172.6 with SMTP id v6mr3117238qke.98.1463751545102; Fri, 20 May 2016 06:39:05 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id s52si18147758qge.53.2016.05.20.06.39.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 May 2016 06:39:05 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b3kck-0005iF-Mf; Fri, 20 May 2016 13:37:54 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b3kcj-0005gs-5w for xen-devel@lists.xen.org; Fri, 20 May 2016 13:37:53 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id B6/03-09532-0331F375; Fri, 20 May 2016 13:37:52 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRWlGSWpSXmKPExsVysyfVTddA2D7 c4P5cZoslHxezODB6HN39mymAMYo1My8pvyKBNePFyqUsBZcEKna0n2NvYHzM08XIxSEksJFR 4vKbblYI5zSjxIPr2xm7GDk52AQ0Je58/sQEYosISEtc+3wZLM4skClxrG0uC4gtLBAh8eX7M bAaFgFViZPfdoLFeQWcJS52bwezJQTkJE4em8wKYnMKuEj8WbUWyOYAWuYs8XGW8gRG7gWMDK sY1YtTi8pSi3QN9ZKKMtMzSnITM3N0DQ3M9HJTi4sT01NzEpOK9ZLzczcxAr3LAAQ7GHc+dzr EKMnBpCTKWy1oHy7El5SfUpmRWJwRX1Sak1p8iFGGg0NJgldPCCgnWJSanlqRlpkDDDOYtAQH j5IIbzBImre4IDG3ODMdInWKUVFKnNcXJCEAksgozYNrg4X2JUZZKWFeRqBDhHgKUotyM0tQ5 V8xinMwKgnzxoFM4cnMK4Gb/gpoMRPQ4ltiNiCLSxIRUlINjJxs7754rt1xWaL/K5OC1cU6kc aEPpenrV9jnjzi2bVER0xu1kqeGawehiqnD3JJt+dsfnrApOl1bm9mztEHk6/HNavN99x+lbH s5s3dRWEb2ZoSWBZLcHJUTPwXc0xLkCXtf3SMjFWuKreQl9C2E3Xy829c2DDD4nLH8mVH25VW PnzovqXjvxJLcUaioRZzUXEiAMi+Ut5oAgAA X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-3.tower-21.messagelabs.com!1463751471!14602413!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 25779 invoked from network); 20 May 2016 13:37:51 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-3.tower-21.messagelabs.com with SMTP; 20 May 2016 13:37:51 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DCC1E34; Fri, 20 May 2016 06:38:09 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.215.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 63F8A3F246; Fri, 20 May 2016 06:37:49 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Fri, 20 May 2016 14:37:42 +0100 Message-Id: <1463751462-8015-3-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1463751462-8015-1-git-send-email-julien.grall@arm.com> References: <1463751462-8015-1-git-send-email-julien.grall@arm.com> Cc: Julien Grall , sstabellini@kernel.org, wei.liu2@citrix.com, wei.chen@arm.com Subject: [Xen-devel] [for-4.7 v2 2/2] xen/arm: p2m: Release the p2m lock before undoing the mappings 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" Since commit 4b25423a "arch/arm: unmap partially-mapped memory regions", Xen has been undoing the P2M mappings when an error occurred during insertion or memory allocation. This is done by calling recursively apply_p2m_changes, however the second call is done with the p2m lock taken which will result in a deadlock for the current processor. The p2m lock is here to protect 2 threads modifying concurrently the page tables. However, it does not guarantee the ordering of the changes. I.e if 2 threads request change on regions that overlaps, then the result is undefined. Therefore it is fine to move the recursive call to undo the changes after the lock is released. Signed-off-by: Julien Grall Reviewed-by: Wei Chen Tested-by: Wei Chen --- I think we could unlock the p2m lock before freeing the temporary mapping. Although, I played safe as this is a bug fix for Xen 4.7 and to be backported up to Xen 4.5. Changes in v2: - Update the commit message to explain why unlocking before the recursive call is fine. - Add Wei Chen's reviewed-by and tested-by --- xen/arch/arm/p2m.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 68c67b0..838d004 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1184,6 +1184,14 @@ out: while ( (pg = page_list_remove_head(&free_pages)) ) free_domheap_page(pg); + for ( level = P2M_ROOT_LEVEL; level < 4; level ++ ) + { + if ( mappings[level] ) + unmap_domain_page(mappings[level]); + } + + spin_unlock(&p2m->lock); + if ( rc < 0 && ( op == INSERT || op == ALLOCATE ) && addr != start_gpaddr ) { @@ -1196,14 +1204,6 @@ out: mattr, 0, p2m_invalid, d->arch.p2m.default_access); } - for ( level = P2M_ROOT_LEVEL; level < 4; level ++ ) - { - if ( mappings[level] ) - unmap_domain_page(mappings[level]); - } - - spin_unlock(&p2m->lock); - return rc; }