From patchwork Fri May 20 13:37:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 68242 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp3784453qge; Fri, 20 May 2016 06:39:08 -0700 (PDT) X-Received: by 10.55.212.221 with SMTP id s90mr3066278qks.99.1463751546976; Fri, 20 May 2016 06:39:06 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id p68si18113731qkd.184.2016.05.20.06.39.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 May 2016 06:39:06 -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 1b3kcj-0005gy-Al; Fri, 20 May 2016 13:37:53 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b3kch-0005gR-LX for xen-devel@lists.xen.org; Fri, 20 May 2016 13:37:51 +0000 Received: from [193.109.254.147] by server-6.bemta-14.messagelabs.com id B0/03-03753-E231F375; Fri, 20 May 2016 13:37:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrCLMWRWlGSWpSXmKPExsVysyfVTVdP2D7 cYOEiFoslHxezODB6HN39mymAMYo1My8pvyKBNePetR7mgt0iFTsPWDQwvuXvYuTiEBLYyCix vPs1C4RzmlFi7dLVbF2MnBxsApoSdz5/YgKxRQSkJa59vswIYjMLZEoca5vLAmILC0RJLFj5H ayGRUBV4uHmaWA1vALOEqt2LQKbIyEgJ3Hy2GRWEJtTwEXiz6q1QDYH0DJniY+zlCcwci9gZF jFqF6cWlSWWqRropdUlJmeUZKbmJmja2hoopebWlycmJ6ak5hUrJecn7uJEehbBiDYwbhiofM hRkkOJiVR3mpB+3AhvqT8lMqMxOKM+KLSnNTiQ4wyHBxKErx6QkA5waLU9NSKtMwcYJDBpCU4 eJREeKVB0rzFBYm5xZnpEKlTjIpS4rxnQGYKgCQySvPg2mCBfYlRVkqYlxHoECGegtSi3MwSV PlXjOIcjErCvG9BpvBk5pXATX8FtJgJaPEtMRuQxSWJCCmpBkYvLdMLd8of2Jlttjeyap0k+E yh1JjjXZZHsPOdE1NWpMpd/ihcM8to85r5LeYv/1T3LVp1SeSP1PXHBxQ3SLd03tcptfqo7Ht BkEmjqcH9lpjtO6+XAYIHX574sNle9etGYRfP/FkpSys+ht1T0WDa9k/qbXXXJIOZ6rNWOJZt +O60ctvlt1+VWIozEg21mIuKEwE6WbnGZwIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-10.tower-27.messagelabs.com!1463751469!42869079!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 39048 invoked from network); 20 May 2016 13:37:49 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-10.tower-27.messagelabs.com with SMTP; 20 May 2016 13:37:49 -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 B10623C; Fri, 20 May 2016 06:38:08 -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 3C2B13F246; Fri, 20 May 2016 06:37:48 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Fri, 20 May 2016 14:37:41 +0100 Message-Id: <1463751462-8015-2-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 1/2] xen/arm: p2m: apply_p2m_changes: Do not undo more than necessary 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. The function apply_p2m_changes can work with region not-aligned to a block size (2MB, 1G) or page size (4K). The mapping will be done by splitting the region in a set of regions aligned to the size supported by the page table. The mapping of a region could fail when it is not possible to allocate memory for an intermediate table (i.e a new or when shattering a block). When the mapping is undone, the end of the region is computed using the base address of the current region and the size of the failing level. However the failing level may not be the leaf one, therefore unrelated entries will be removed. Fix it by removing the mapping from the start address up to the last region that has been successfully mapped. Signed-off-by: Julien Grall Reviewed-by: Wei Chen Reviewed-by: Stefano Stabellini --- This patch is a bug fix for Xen 4.7 and candidate for backporting up to Xen 4.5. Without this patch, Xen may undo mapping which are not part of the region mapped when memory allocation has failed. Note that Xen 4.7 has code to remove empty translation table (see commit de5162b "xen/arm: p2m: Remove translation table when it's empty"), however with this patch those tables will not be removed in case of failure. This will be fixed after the release as the change will be too intrusive for Xen 4.7. Changes in v2: - Add Stefano's and Wei's reviewed-by --- xen/arch/arm/p2m.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index db21433..68c67b0 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1189,13 +1189,10 @@ out: { BUG_ON(addr == end_gpaddr); /* - * addr keeps the address of the last successfully-inserted mapping, - * while apply_p2m_changes() considers an address range which is - * exclusive of end_gpaddr: add level_size to addr to obtain the - * right end of the range + * addr keeps the address of the end of the last successfully-inserted + * mapping. */ - apply_p2m_changes(d, REMOVE, - start_gpaddr, addr + level_sizes[level], orig_maddr, + apply_p2m_changes(d, REMOVE, start_gpaddr, addr, orig_maddr, mattr, 0, p2m_invalid, d->arch.p2m.default_access); }