From patchwork Wed Jul 20 16:10:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 72450 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp66575qga; Wed, 20 Jul 2016 09:14:26 -0700 (PDT) X-Received: by 10.36.81.15 with SMTP id s15mr10910832ita.57.1469031259352; Wed, 20 Jul 2016 09:14:19 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id r134si2545822iod.111.2016.07.20.09.14.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jul 2016 09:14:19 -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 1bPu5x-0007cu-Vi; Wed, 20 Jul 2016 16:11:37 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bPu5w-0007aJ-Kz for xen-devel@lists.xen.org; Wed, 20 Jul 2016 16:11:36 +0000 Received: from [85.158.137.68] by server-8.bemta-3.messagelabs.com id 3E/FD-10540-7B2AF875; Wed, 20 Jul 2016 16:11:35 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrBLMWRWlGSWpSXmKPExsVysyfVTXf7ov5 wgyvnpSyWfFzM4sDocXT3b6YAxijWzLyk/IoE1oyZb68wFVzlqVj5/SpjA+NDzi5GLg4hgU2M EovfH2GGcE4zSnRe7GLsYuTkYBPQlLjz+RMTiC0iIC1x7fNlRpAiZoF2RonlG/+xgCSEBeIlj i65zAxiswioSrQ/+ArWwCvgKvGvfQKYLSEgJ3Hy2GRWEJsTKH7+5E+wBUICLhKb3n5jnsDIvY CRYRWjRnFqUVlqka6RsV5SUWZ6RkluYmaOrqGBsV5uanFxYnpqTmJSsV5yfu4mRqCP6xkYGHc w9u31O8QoycGkJMqrKtobLsSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mCd/HC/nAhwaLU9NSKtMwc YLDBpCU4eJREeI+DpHmLCxJzizPTIVKnGBWlxHndQRICIImM0jy4NliAX2KUlRLmZWRgYBDiK Ugtys0sQZV/xSjOwagkzNsKMoUnM68EbvoroMVMQIvnCIAtLklESEk1MObu+R3dHeQYuGyBzi 2uF0Glf6ocFeUnXPp7tW9PwRa7OrUvf5TkI+8ueuK0NM7pYfER/vLD+fWVVipGwrlHtFfO2jF H7FHdl6NLXQvP/E+YpyfNkX1UJGrKfrdbQfxr5SWMj3n93X/Kp6p4F1sHc+66kznVRyzXruDg r4zz9/R5vOa8oYZ6jBJLcUaioRZzUXEiAAZxaGFrAgAA X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-11.tower-31.messagelabs.com!1469031094!25335396!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.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 54290 invoked from network); 20 Jul 2016 16:11:35 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-11.tower-31.messagelabs.com with SMTP; 20 Jul 2016 16:11:35 -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 42995BBB; Wed, 20 Jul 2016 09:12:45 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.218.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 976753F387; Wed, 20 Jul 2016 09:11:33 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Wed, 20 Jul 2016 17:10:51 +0100 Message-Id: <1469031064-23344-10-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1469031064-23344-1-git-send-email-julien.grall@arm.com> References: <1469031064-23344-1-git-send-email-julien.grall@arm.com> Cc: proskurin@sec.in.tum.de, Julien Grall , sstabellini@kernel.org, wei.chen@linaro.org, steve.capper@arm.com Subject: [Xen-devel] [PATCH 09/22] xen/arm: p2m: Use a whitelist rather than blacklist in get_page_from_gfn 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" Currently, the check in get_page_from_gfn is using a blacklist. This is very fragile because we may forgot to update the check when a new p2m type is added. To avoid any possible issue, use a whitelist. All type backed by a RAM page can could potential be valid. The check is borrowed from x86. Signed-off-by: Julien Grall --- xen/include/asm-arm/p2m.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 3091c04..78d37ab 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -104,9 +104,16 @@ typedef enum { #define P2M_RAM_TYPES (p2m_to_mask(p2m_ram_rw) | \ p2m_to_mask(p2m_ram_ro)) +/* Grant mapping types, which map to a real frame in another VM */ +#define P2M_GRANT_TYPES (p2m_to_mask(p2m_grant_map_rw) | \ + p2m_to_mask(p2m_grant_map_ro)) + /* Useful predicates */ #define p2m_is_ram(_t) (p2m_to_mask(_t) & P2M_RAM_TYPES) #define p2m_is_foreign(_t) (p2m_to_mask(_t) & p2m_to_mask(p2m_map_foreign)) +#define p2m_is_any_ram(_t) (p2m_to_mask(_t) & \ + (P2M_RAM_TYPES | P2M_GRANT_TYPES | \ + p2m_to_mask(p2m_map_foreign))) static inline void p2m_mem_access_emulate_check(struct vcpu *v, @@ -224,7 +231,7 @@ static inline struct page_info *get_page_from_gfn( if (t) *t = p2mt; - if ( p2mt == p2m_invalid || p2mt == p2m_mmio_direct ) + if ( !p2m_is_any_ram(p2mt) ) return NULL; if ( !mfn_valid(mfn) )