From patchwork Thu Jul 28 14:20:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 72959 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp880500qga; Thu, 28 Jul 2016 07:24:32 -0700 (PDT) X-Received: by 10.36.74.137 with SMTP id k131mr108770280itb.85.1469715872796; Thu, 28 Jul 2016 07:24:32 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 36si13303187iot.138.2016.07.28.07.24.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jul 2016 07:24:32 -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 1bSmAr-00078j-O3; Thu, 28 Jul 2016 14:20:33 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSmAq-00077r-6M for xen-devel@lists.xen.org; Thu, 28 Jul 2016 14:20:32 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id 9D/78-13744-FA41A975; Thu, 28 Jul 2016 14:20:31 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRWlGSWpSXmKPExsVysyfVTXedyKx wg8v/TSyWfFzM4sDocXT3b6YAxijWzLyk/IoE1oznC6QL1vJXzOr8ytTA+IW7i5GLQ0hgE6NE 6449LBDOaUaJ3w9OMXYxcnKwCWhK3Pn8iQnEFhGQlrj2+TIjSBGzQDujxNr+XuYuRg4OYYEki VPHlUBqWARUJbb8X84GYvMKOEu8uHWcGcSWEJCTOHlsMiuIzSngInGv7TuYLQRUc/rudvYJjN wLGBlWMaoXpxaVpRbpmuolFWWmZ5TkJmbm6BoamOnlphYXJ6an5iQmFesl5+duYgR6lwEIdjB Ov+x/iFGSg0lJlDcsdGa4EF9SfkplRmJxRnxRaU5q8SFGGQ4OJQneE8KzwoUEi1LTUyvSMnOA YQaTluDgURLhjQRJ8xYXJOYWZ6ZDpE4xKkqJ894BSQiAJDJK8+DaYKF9iVFWSpiXEegQIZ6C1 KLczBJU+VeM4hyMSsK8uSBTeDLzSuCmvwJazAS0uDh2BsjikkSElFQD40qB+8FX3eKrfDcaXd k6ISfrx5fZ3SxFC146/613kwvNcFZ688LUgnviIrPANTOzumfnCySGx35Sii1meXLgDMOcu2v MjVa9TzVIVTnZUxR9LNbV5bL6/0vRv1hF5761mhDy1Wkpq82M9i8/VPd0hSftuDWPPVgs0V7J 5eaDu6KaT7Q/8CdMUGIpzkg01GIuKk4EAEyl8X1oAgAA X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-7.tower-21.messagelabs.com!1469715630!26161622!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 30842 invoked from network); 28 Jul 2016 14:20:30 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-7.tower-21.messagelabs.com with SMTP; 28 Jul 2016 14:20:30 -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 1BB40451; Thu, 28 Jul 2016 07:21:46 -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 E16403F21A; Thu, 28 Jul 2016 07:20:27 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 28 Jul 2016 15:20:07 +0100 Message-Id: <1469715620-4670-3-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1469715620-4670-1-git-send-email-julien.grall@arm.com> References: <1469715620-4670-1-git-send-email-julien.grall@arm.com> Cc: proskurin@sec.in.tum.de, Julien Grall , sstabellini@kernel.org, steve.capper@arm.com, wei.chen@linaro.org Subject: [Xen-devel] [PATCH v2 02/15] 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. Note with this change, it is not possible anymore to retrieve a page when the p2m type is p2m_iommu_map_*. This is fine because they are special mappings for direct mapping workaround and the associated GFN should be used at all by callers of get_page_from_gfn. Signed-off-by: Julien Grall --- Changes in v2: - Update the commit message about iommu_mappings --- 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) )