From patchwork Mon May 16 14:08:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 67901 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1559292qge; Mon, 16 May 2016 07:10:40 -0700 (PDT) X-Received: by 10.140.25.193 with SMTP id 59mr29635422qgt.77.1463407840432; Mon, 16 May 2016 07:10:40 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id e97si23153125qgd.9.2016.05.16.07.10.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 May 2016 07:10:40 -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 1b2JCw-0004hF-H5; Mon, 16 May 2016 14:09:18 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b2JCv-0004gv-Ih for xen-devel@lists.xen.org; Mon, 16 May 2016 14:09:17 +0000 Received: from [85.158.143.35] by server-1.bemta-6.messagelabs.com id 26/FD-18833-C84D9375; Mon, 16 May 2016 14:09:16 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrMLMWRWlGSWpSXmKPExsVysyfVTbfnimW 4wesH4hZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bhx3uYCqYLV/x818PWwPicr4uRi0NIYBOj xKMz51kgnNOMEvuvNrF3MXJysAloStz5/IkJxBYRkJa49vkyI4jNLJApcaxtLguILSwQLjFjz 1OgGg4OFgFVicsXRUHCvALOElMevWYDsSUE5CROHpvMClLCKeAi8WW/BIgpBFRy86zXBEbuBY wMqxjVi1OLylKLdI31kooy0zNKchMzc3QNDcz0clOLixPTU3MSk4r1kvNzNzECPcsABDsYO/4 5HWKU5GBSEuWNX2MZLsSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mC1+syUE6wKDU9tSItMwcYYjBp CQ4eJRHedpA0b3FBYm5xZjpE6hSjopQ4LzdIQgAkkVGaB9cGC+tLjLJSwryMQIcI8RSkFuVml qDKv2IU52BUEub1B5nCk5lXAjf9FdBiJqDFE8wsQBaXJCKkpBoYl+qFrdHQCu/uZSrf7sp2/c hWWeHiXTaLIiSEe+dmPz7bvemxkMACz6MawnmnilmmOcSYbGRed9Lzbkxpf3LkDO+Indctl8a xa6zp9j46n61n+8TMBIbKOkf9hvC4viP+i1bb9GoX73u29OTuiy+EDB6JfnvPb3T4UE7QNn2G cPHu9w6+vNFKLMUZiYZazEXFiQBiXmefZgIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-14.tower-21.messagelabs.com!1463407755!14347956!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 37628 invoked from network); 16 May 2016 14:09:16 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-14.tower-21.messagelabs.com with SMTP; 16 May 2016 14:09:16 -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 E9AE13DB; Mon, 16 May 2016 07:09:31 -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 B65CB3F21A; Mon, 16 May 2016 07:09:14 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Mon, 16 May 2016 15:08:54 +0100 Message-Id: <1463407735-7409-2-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1463407735-7409-1-git-send-email-julien.grall@arm.com> References: <1463407735-7409-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 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 --- 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. --- 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); }