From patchwork Fri May 19 16:08:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 100198 Delivered-To: patch@linaro.org Received: by 10.182.142.97 with SMTP id rv1csp362536obb; Fri, 19 May 2017 09:10:37 -0700 (PDT) X-Received: by 10.157.83.30 with SMTP id g30mr5452740oth.48.1495210237463; Fri, 19 May 2017 09:10:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495210237; cv=none; d=google.com; s=arc-20160816; b=N3Fj+rN5MZvzcxtZFaxGCfMQF3ZrC07dlgDrg6XJtUWaJxjYzIaQHUtgpp+49thQV/ D5y2dM6vYVV6S7wSuXFgckLvX2OTJgPFGe+hqbbq5qRvBf2o7982FDlZK7nQluP2RTux BRTvQnWkuE0kf+DQTDJD/Sx4RqmTYkkF9dY2am5QzuQIrTHY6J5aHUG5Xttkf6vN0rSr QQIQNg9RMnUbSPi5qeZnNVJd+FqT5o0hUO17TZuioZ6cP2sFvn/rymjfGw4S+KI1Vt/j +DzkJb1t3AqLHaQeNZZUVc3NyaNFzY5YApn9A1D1cf5IYa1+TCAzrANWvWmtJq6TjySV hdVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:message-id:date:to:from :arc-authentication-results; bh=nzIut/B5AC8sQUwhUrtYWISe3I9ZjHtSLcIjWDlClak=; b=fM2MRNhovbMa+ok3nKjw46ZUnF6y6iNH36hPrQ2cQymgvfgbOURtgl+VHLC7YeVfNQ WqnwQDFrMtrUDBiDXwxK+Mug1jz99Ti2pK3g97U8PiIqlOTZe7BI4u0USbG4t65Zv8Qg 59bBSKsUb7P4gILjZN1g+HS5BQyp4p67OUVqgXMTCu0eo1wJciD8xtWCqtSPaoBXsy4j 1eWFduEX4vEFQdzSWP3vHEapwDxvZZ4vQSUbzXEo94NwkBTgqYZQQw1pTel3iup7Xn86 XhobxlpqrdY+WVYZy0+T/r77uBrLLks8RxxyHg3L0CSHRkAarZszTvP3V2ic5xFyFpvk qoEQ== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id i202si3649128oib.187.2017.05.19.09.10.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 May 2017 09:10:37 -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 1dBkSP-0004HF-D4; Fri, 19 May 2017 16:08:49 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dBkSO-0004H7-3U for xen-devel@lists.xen.org; Fri, 19 May 2017 16:08:48 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id DA/38-03058-F881F195; Fri, 19 May 2017 16:08:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrPLMWRWlGSWpSXmKPExsVysyfVTbdPQj7 SYNtlI4slHxezODB6HN39mymAMYo1My8pvyKBNePRlb3sBc94K+4+WMnUwHiJq4uRi0NIYBOj ROesLmYI5zSjxKKmx4xdjJwcbAKaEnc+f2ICsUUEpCWufb4MFmcWcJB48/EeC4gtLOAl0bHuJ SuIzSKgKnH98z12EJtXwFLi2cFtYL0SAvISu9ousk5g5FzAyLCKUaM4tagstUjXyEwvqSgzPa MkNzEzR9fQwEwvN7W4ODE9NScxqVgvOT93EyPQYwxAsIPxzILAQ4ySHExKoryOh+UihfiS8lM qMxKLM+KLSnNSiw8xynBwKEnwmojLRwoJFqWmp1akZeYAQwcmLcHBoyTC+1sMKM1bXJCYW5yZ DpE6xagoJc6bBNInAJLIKM2Da4OF6yVGWSlhXkagQ4R4ClKLcjNLUOVfMYpzMCoJ814HGc+Tm VcCN/0V0GImoMXND6RBFpckIqSkGhj7Ltx4/VXxl8uSPS/O7Qm6rM9lVnrgB4tsaFrdhk9x7R 1/hI8fX6XGKffuq3Ypo/S8C/5Ozyt33E37ou8Z0NGln6OQM3/L9ddJFvEeeletdtz70Wxw2ul X0+f/m0P0j5oo77HhKuh0zw/M//TivfSt+Au23Vv0rzw2+924QfvFh/w9MwW0m04osRRnJBpq MRcVJwIAfos1S1ICAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-13.tower-21.messagelabs.com!1495210126!63753706!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 1114 invoked from network); 19 May 2017 16:08:46 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-13.tower-21.messagelabs.com with SMTP; 19 May 2017 16:08:46 -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 A6F36344; Fri, 19 May 2017 09:08:45 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 083433F575; Fri, 19 May 2017 09:08:44 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Fri, 19 May 2017 17:08:39 +0100 Message-Id: <20170519160839.20186-1-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 Cc: Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH for-4.9] xen/arm: p2m: Fix incorrect mapping of superpages 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" The same set of functions is used to set as well as to clean P2M entries, except for clean operations (INVALID_MFN ~0UL) is passed as a parameter. Unfortunately, when calculating an appropriate target order for a particular mapping INVALID_MFN is taken into account which leads to 4K page target order being set each time even for 2MB and 1GB mappings. This will result to break down the superpage into 4K mappings and leave empty tables allocated. This was introduced by commit 2ef3e36ec7 "xen/arm: p2m: Introduce p2m_set_entry and __p2m_set_entry". Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- This patch is a candidate for Xen 4.9 and also backporting to Xen 4.8. Without this patch, removing superpage mapping (2MB, 1GB) will breakdown into 4K mapping first then remove 4K by 4K. --- xen/arch/arm/p2m.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 34d57760d7..752e948070 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1005,12 +1005,18 @@ int p2m_set_entry(struct p2m_domain *p2m, while ( nr ) { + unsigned long mask; + unsigned long order; + /* + * Don't take into account the MFN when removing mapping (i.e + * MFN_INVALID) to calculate the correct target order. + * * XXX: Support superpage mappings if nr is not aligned to a * superpage size. */ - unsigned long mask = gfn_x(sgfn) | mfn_x(smfn) | nr; - unsigned long order; + mask = !mfn_eq(smfn, INVALID_MFN) ? mfn_x(smfn) : 0; + mask |= gfn_x(sgfn) | nr; /* Always map 4k by 4k when memaccess is enabled */ if ( unlikely(p2m->mem_access_enabled) )