From patchwork Mon Oct 8 18:33: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: 148428 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp3982106lji; Mon, 8 Oct 2018 11:36:18 -0700 (PDT) X-Google-Smtp-Source: ACcGV63be7uXcKdLuyVFAz3It9/8PtUA0WmOWPukdC9ZptsrTamVlBthAiYVC4JLb9roJwBOkftg X-Received: by 2002:a5e:d613:: with SMTP id w19-v6mr16896543iom.75.1539023778313; Mon, 08 Oct 2018 11:36:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539023778; cv=none; d=google.com; s=arc-20160816; b=Wv9DW4CXbYIvsHRNr4XvCS1PwPTDbswP3lwyJo/5bccswZEkvyk9G+/SIQWMANGQWX hSBxMprcn3nD4lyxgrKI0BUxvnmEdJTKWlfRcECg1admH+OGjbRnRTqnh6khigjnBumi Enokoy76Y9qZsz2FLMdMLDUcJ+diLSQXI16gRFpbm+rs4sc+OtzNMi1XA9tyoZ9qcgPX cZzVL62IQ5U4d5VEbbFfxRu/aAnbc2fI/s4HsoK8tmbmSabHH401exoAQyT8UOCYBqmc BmmlRcU0CEYWdsFO2jiN0FQCkIrz673Dgsu2HlaXVgUs9/KS5EQ/D30S1WOCbRP5yyhE 8mxA== 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=hUp7zwAdEWFYS40lUeUu/mJ0xHqB9WpceGezKZgO/6o=; b=p1ONBMH0WWX2/cTq2atzpSwpLYjmHTulU0CjMmjZ432fj/I1CpD915RVWdVgtYS9rz dWgPESV1VakxbDiLP42jiabESDmcBfxTqUZWYXC8u6iU676QwL2ewD1ub0MlF2t854M+ e68EhsRhDBr91akKLMVSSp6noSZEBJDItDsMI8UdUmqbTx3zPq+3teL88z2gDpL01A3V KDcc21WNu6cFIdyNv8Q5aaAvX2F2pynluRcimsDbPyL0UjJT4nQEu45xOXWf04UfMB5h uKRLJOpXbdaD0Y9Ajzkrgyg6IjtRVeEKh1YIhRnFEQ2Z0lKcOGh8yTITZQe0/dE2Fku2 R9oA== 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 63-v6si8590164itq.70.2018.10.08.11.36.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Oct 2018 11:36:18 -0700 (PDT) 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 1g9aM2-0005eA-66; Mon, 08 Oct 2018 18:34:06 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1g9aM1-0005e0-7i for xen-devel@lists.xen.org; Mon, 08 Oct 2018 18:34:05 +0000 X-Inumbo-ID: 60d16fe4-cb28-11e8-a8a5-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 60d16fe4-cb28-11e8-a8a5-bc764e045a96; Mon, 08 Oct 2018 20:31:31 +0200 (CEST) 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 3410515B2; Mon, 8 Oct 2018 11:34:03 -0700 (PDT) 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 49F823F5B3; Mon, 8 Oct 2018 11:34:02 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Mon, 8 Oct 2018 19:33:38 +0100 Message-Id: <20181008183352.16291-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181008183352.16291-1-julien.grall@arm.com> References: <20181008183352.16291-1-julien.grall@arm.com> Subject: [Xen-devel] [RFC 02/16] xen/arm: Introduce helpers to get/set an MFN from/to an LPAE entry 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, andre.przywara@linaro.org MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The new helpers make it easier to read the code by abstracting the way to set/get an MFN from/to an LPAE entry. The helpers are using "walk" as the bits are common across different LPAE stages. At the same time, use the new helpers to replace the various open-coding place. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- This patch was originally sent separately. --- xen/arch/arm/mm.c | 10 +++++----- xen/arch/arm/p2m.c | 19 ++++++++++--------- xen/include/asm-arm/lpae.h | 3 +++ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 7a06a33e21..0bc31b1d9b 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -238,7 +238,7 @@ void dump_pt_walk(paddr_t ttbr, paddr_t addr, /* For next iteration */ unmap_domain_page(mapping); - mapping = map_domain_page(_mfn(pte.walk.base)); + mapping = map_domain_page(lpae_get_mfn(pte)); } unmap_domain_page(mapping); @@ -323,7 +323,7 @@ static inline lpae_t mfn_to_xen_entry(mfn_t mfn, unsigned attr) ASSERT(!(mfn_to_maddr(mfn) & ~PADDR_MASK)); - e.pt.base = mfn_x(mfn); + lpae_set_mfn(e, mfn); return e; } @@ -490,7 +490,7 @@ mfn_t domain_page_map_to_mfn(const void *ptr) ASSERT(slot >= 0 && slot < DOMHEAP_ENTRIES); ASSERT(map[slot].pt.avail != 0); - return _mfn(map[slot].pt.base + offset); + return mfn_add(lpae_get_mfn(map[slot]), offset); } #endif @@ -851,7 +851,7 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, /* mfn_to_virt is not valid on the 1st 1st mfn, since it * is not within the xenheap. */ first = slot == xenheap_first_first_slot ? - xenheap_first_first : __mfn_to_virt(p->pt.base); + xenheap_first_first : mfn_to_virt(lpae_get_mfn(*p)); } else if ( xenheap_first_first_slot == -1) { @@ -1007,7 +1007,7 @@ static int create_xen_entries(enum xenmap_operation op, BUG_ON(!lpae_is_valid(*entry)); - third = __mfn_to_virt(entry->pt.base); + third = mfn_to_virt(lpae_get_mfn(*entry)); entry = &third[third_table_offset(addr)]; switch ( op ) { diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 30cfb01498..f8a2f6459e 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -265,7 +265,7 @@ static int p2m_next_level(struct p2m_domain *p2m, bool read_only, if ( lpae_is_mapping(*entry, level) ) return GUEST_TABLE_SUPER_PAGE; - mfn = _mfn(entry->p2m.base); + mfn = lpae_get_mfn(*entry); unmap_domain_page(*table); *table = map_domain_page(mfn); @@ -349,7 +349,7 @@ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, if ( a ) *a = p2m_mem_access_radix_get(p2m, gfn); - mfn = _mfn(entry.p2m.base); + mfn = lpae_get_mfn(entry); /* * The entry may point to a superpage. Find the MFN associated * to the GFN. @@ -519,7 +519,7 @@ static lpae_t mfn_to_p2m_entry(mfn_t mfn, p2m_type_t t, p2m_access_t a) ASSERT(!(mfn_to_maddr(mfn) & ~PADDR_MASK)); - e.p2m.base = mfn_x(mfn); + lpae_set_mfn(e, mfn); return e; } @@ -621,7 +621,7 @@ static void p2m_put_l3_page(const lpae_t pte) */ if ( p2m_is_foreign(pte.p2m.type) ) { - mfn_t mfn = _mfn(pte.p2m.base); + mfn_t mfn = lpae_get_mfn(pte); ASSERT(mfn_valid(mfn)); put_page(mfn_to_page(mfn)); @@ -655,7 +655,7 @@ static void p2m_free_entry(struct p2m_domain *p2m, return; } - table = map_domain_page(_mfn(entry.p2m.base)); + table = map_domain_page(lpae_get_mfn(entry)); for ( i = 0; i < LPAE_ENTRIES; i++ ) p2m_free_entry(p2m, *(table + i), level + 1); @@ -669,7 +669,7 @@ static void p2m_free_entry(struct p2m_domain *p2m, */ p2m_tlb_flush_sync(p2m); - mfn = _mfn(entry.p2m.base); + mfn = lpae_get_mfn(entry); ASSERT(mfn_valid(mfn)); pg = mfn_to_page(mfn); @@ -688,7 +688,7 @@ static bool p2m_split_superpage(struct p2m_domain *p2m, lpae_t *entry, bool rv = true; /* Convenience aliases */ - mfn_t mfn = _mfn(entry->p2m.base); + mfn_t mfn = lpae_get_mfn(*entry); unsigned int next_level = level + 1; unsigned int level_order = level_orders[next_level]; @@ -719,7 +719,7 @@ static bool p2m_split_superpage(struct p2m_domain *p2m, lpae_t *entry, * the necessary fields. So the correct permission are kept. */ pte = *entry; - pte.p2m.base = mfn_x(mfn_add(mfn, i << level_order)); + lpae_set_mfn(pte, mfn_add(mfn, i << level_order)); /* * First and second level pages set p2m.table = 0, but third @@ -952,7 +952,8 @@ 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) && entry->p2m.base != orig_pte.p2m.base ) + if ( lpae_is_valid(orig_pte) && + !mfn_eq(lpae_get_mfn(*entry), lpae_get_mfn(orig_pte)) ) p2m_free_entry(p2m, orig_pte, level); if ( need_iommu_pt_sync(p2m->domain) && diff --git a/xen/include/asm-arm/lpae.h b/xen/include/asm-arm/lpae.h index 15595cd35c..17fdc6074f 100644 --- a/xen/include/asm-arm/lpae.h +++ b/xen/include/asm-arm/lpae.h @@ -153,6 +153,9 @@ static inline bool lpae_is_superpage(lpae_t pte, unsigned int level) return (level < 3) && lpae_is_mapping(pte, level); } +#define lpae_get_mfn(pte) (_mfn((pte).walk.base)) +#define lpae_set_mfn(pte, mfn) ((pte).walk.base = mfn_x(mfn)) + /* * AArch64 supports pages with different sizes (4K, 16K, and 64K). To enable * page table walks for various configurations, the following helpers enable