From patchwork Tue Dec 4 20:26:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 152853 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp8503419ljp; Tue, 4 Dec 2018 12:29:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/XP57sTW1Y5tbq3nlXSzW5T30ILLm1hRIHtj1kXf9n0Zk5S+TiqFvng2qs9IphMi1xpUwk1 X-Received: by 2002:a25:4a83:: with SMTP id x125-v6mr20618527yba.413.1543955367845; Tue, 04 Dec 2018 12:29:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543955367; cv=none; d=google.com; s=arc-20160816; b=Sg30HnWRHnHOAHThF03OLTRjKbdmUs1PVk/bjwpkfM/0N0XWUpMduMVZfvtUFmSARc 1G6arEeuna+bWJZLYfVwzFRJcFLvwENZlXo7NLnYxps3ukIkPcm5UMwJiKKnfrWooJsT BjVdo/IfKpt8wko5uLB/myyIhzFFNpHCk8UPRyI0gZDH3WJxMmtrTusWvDU+EjtFQwb9 zcbcxzH40JScGYqsZrYBWDVte/zBcPLxtjKOiClhYUsT7ZDO32kUdQ+sXq8YVzt8vo+A QeKcIVK6bJJCz3DYbt3HwCJ9xLawoc4C/SOd3n7irvz1bUuKKpFKdLkVoEAFZ+QqySo3 NIYg== 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:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=Xxi/GvlZ9XZKDPydUYToaSn2bGWZD3JsAUvbWR+x9DM=; b=HRX9khRuCiEc0f0ON50rtenR55ymzuF7z9qmsne3BFENZz5Kssv8lAn2pMz0jYAAY1 dAObNeiyiDo1sjERZVqeNji+I2X8fQgz+hhd6gXyWXFrFYbvP3BV0EJDwFQBOR3mBKjJ txwtLjgl9KsJ1i0DDbBPoXPXR1o3To18CGoQ2hdjzMyqlwBmC44LKOOU9Rz8ONGWnS0R /0UjyI1UM3hdBDRDDBnEKxr9KFGiq9fgYebZK9Rkk7AolCNftregHX/NgeSfd9MzbhwA NBcQVFqayzeN089xzHGMpZ5dEcfHmkvSQW/cGZJbpOzHSG1ZRHtd59/+qeoRyKZii9xJ R9TQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id e184si10668288ywf.2.2018.12.04.12.29.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Dec 2018 12:29:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1gUHHw-00086N-2i; Tue, 04 Dec 2018 20:27:24 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1gUHHu-000867-UQ for xen-devel@lists.xenproject.org; Tue, 04 Dec 2018 20:27:22 +0000 X-Inumbo-ID: 00e163a2-f803-11e8-a4b4-0feac6537a25 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 00e163a2-f803-11e8-a4b4-0feac6537a25; Tue, 04 Dec 2018 20:27:21 +0000 (UTC) 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 B854F168F; Tue, 4 Dec 2018 12:27:21 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F00563F614; Tue, 4 Dec 2018 12:27:20 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 4 Dec 2018 20:26:38 +0000 Message-Id: <20181204202651.8836-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181204202651.8836-1-julien.grall@arm.com> References: <20181204202651.8836-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v2 04/17] xen/arm: p2m: Introduce p2m_is_valid and use it X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , sstabellini@kernel.org MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The LPAE format allows to store information in an entry even with the valid bit unset. In a follow-up patch, we will take advantage of this feature to re-purpose the valid bit for generating a translation fault even if an entry contains valid information. So we need a different way to know whether an entry contains valid information. It is possible to use the information hold in the p2m_type to know for that purpose. Indeed all entries containing valid information will have a valid p2m type (i.e p2m_type != p2m_invalid). This patch introduces a new helper p2m_is_valid, which implements that idea, and replace most of lpae_is_valid call with the new helper. The ones remaining are for TLBs handling and entries accounting. With the renaming there are 2 others changes required: - Generate table entry with a valid p2m type - Detect new mapping for proper stats accounting Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Don't open-code p2m_is_superpage --- xen/arch/arm/p2m.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 81f3107dd2..47b54c792e 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -212,17 +212,26 @@ static p2m_access_t p2m_mem_access_radix_get(struct p2m_domain *p2m, gfn_t gfn) } /* + * In the case of the P2M, the valid bit is used for other purpose. Use + * the type to check whether an entry is valid. + */ +static inline bool p2m_is_valid(lpae_t pte) +{ + return pte.p2m.type != p2m_invalid; +} + +/* * lpae_is_* helpers don't check whether the valid bit is set in the * PTE. Provide our own overlay to check the valid bit. */ static inline bool p2m_is_mapping(lpae_t pte, unsigned int level) { - return lpae_is_valid(pte) && lpae_is_mapping(pte, level); + return p2m_is_valid(pte) && lpae_is_mapping(pte, level); } static inline bool p2m_is_superpage(lpae_t pte, unsigned int level) { - return lpae_is_valid(pte) && lpae_is_superpage(pte, level); + return p2m_is_valid(pte) && lpae_is_superpage(pte, level); } #define GUEST_TABLE_MAP_FAILED 0 @@ -256,7 +265,7 @@ static int p2m_next_level(struct p2m_domain *p2m, bool read_only, entry = *table + offset; - if ( !lpae_is_valid(*entry) ) + if ( !p2m_is_valid(*entry) ) { if ( read_only ) return GUEST_TABLE_MAP_FAILED; @@ -348,7 +357,7 @@ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, entry = table[offsets[level]]; - if ( lpae_is_valid(entry) ) + if ( p2m_is_valid(entry) ) { *t = entry.p2m.type; @@ -536,8 +545,11 @@ static lpae_t page_to_p2m_table(struct page_info *page) /* * The access value does not matter because the hardware will ignore * the permission fields for table entry. + * + * We use p2m_ram_rw so the entry has a valid type. This is important + * for p2m_is_valid() to return valid on table entries. */ - return mfn_to_p2m_entry(page_to_mfn(page), p2m_invalid, p2m_access_rwx); + return mfn_to_p2m_entry(page_to_mfn(page), p2m_ram_rw, p2m_access_rwx); } static inline void p2m_write_pte(lpae_t *p, lpae_t pte, bool clean_pte) @@ -561,7 +573,7 @@ static int p2m_create_table(struct p2m_domain *p2m, lpae_t *entry) struct page_info *page; lpae_t *p; - ASSERT(!lpae_is_valid(*entry)); + ASSERT(!p2m_is_valid(*entry)); page = alloc_domheap_page(NULL, 0); if ( page == NULL ) @@ -618,7 +630,7 @@ static int p2m_mem_access_radix_set(struct p2m_domain *p2m, gfn_t gfn, */ static void p2m_put_l3_page(const lpae_t pte) { - ASSERT(lpae_is_valid(pte)); + ASSERT(p2m_is_valid(pte)); /* * TODO: Handle other p2m types @@ -646,7 +658,7 @@ static void p2m_free_entry(struct p2m_domain *p2m, struct page_info *pg; /* Nothing to do if the entry is invalid. */ - if ( !lpae_is_valid(entry) ) + if ( !p2m_is_valid(entry) ) return; /* Nothing to do but updating the stats if the entry is a super-page. */ @@ -943,7 +955,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m, else p2m->need_flush = true; } - else /* new mapping */ + else if ( !p2m_is_valid(orig_pte) ) /* new mapping */ p2m->stats.mappings[level]++; p2m_write_pte(entry, pte, p2m->clean_pte); @@ -957,7 +969,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m, * Free the entry only if the original pte was valid and the base * is different (to avoid freeing when permission is changed). */ - if ( lpae_is_valid(orig_pte) && + if ( p2m_is_valid(orig_pte) && !mfn_eq(lpae_get_mfn(*entry), lpae_get_mfn(orig_pte)) ) p2m_free_entry(p2m, orig_pte, level);