All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@arm.com>
To: xen-devel@lists.xenproject.org
Cc: Julien Grall <julien.grall@arm.com>, sstabellini@kernel.org
Subject: [PATCH 10/15] xen/arm: Introduce helpers to get/set an MFN from/to an LPAE entry
Date: Mon, 16 Jul 2018 18:27:07 +0100	[thread overview]
Message-ID: <20180716172712.20294-11-julien.grall@arm.com> (raw)
In-Reply-To: <20180716172712.20294-1-julien.grall@arm.com>

The new helpers make easier to read the code by abstracting the way to
set/get an MFN from/to an LPAE entry. The helpers is using "walk" as the
bits are common for accross different LPAE stage.

At the same time, use the new helpers to replace the various open-coding
place.

Signed-off-by: Julien Grall <julien.grall@arm.com>
---
 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 de9b965d2f..e3dafe5fd7 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_to_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_to_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_to_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_to_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 a80ac301c5..ec3fdcb554 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_to_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_to_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_to_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_to_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_to_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_to_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
@@ -950,7 +950,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_to_mfn(*entry), lpae_to_mfn(orig_pte)) )
         p2m_free_entry(p2m, orig_pte, level);
 
     if ( need_iommu(p2m->domain) &&
diff --git a/xen/include/asm-arm/lpae.h b/xen/include/asm-arm/lpae.h
index 15595cd35c..05c87a8f48 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_to_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
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2018-07-16 17:27 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-16 17:26 [PATCH 00/15] xen/arm: Bunch of clean-up/improvement Julien Grall
2018-07-16 17:26 ` [PATCH 01/15] xen/arm: cpregs: Allow HSR_CPREG* to receive more than 1 parameter Julien Grall
2018-08-14 21:47   ` Stefano Stabellini
2018-07-16 17:26 ` [PATCH 02/15] xen/arm: cpregs: Fix typo in the documentation of TTBCR Julien Grall
2018-08-14 20:39   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 03/15] xen/arm: Introduce helpers to clear/flags flags in HCR_EL2 Julien Grall
2018-08-14 20:46   ` Stefano Stabellini
2018-08-14 21:23     ` Julien Grall
2018-08-14 21:49       ` Stefano Stabellini
2018-08-14 22:53         ` Julien Grall
2018-08-14 23:03           ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 04/15] xen/arm: p2m: Reduce the locking section in get_page_from_gva Julien Grall
2018-08-14 20:49   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 05/15] xen/arm: p2m: Limit call to mem access code use " Julien Grall
2018-07-17  9:54   ` Razvan Cojocaru
2018-08-14 20:59   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 06/15] xen/arm: Rework lpae_mapping Julien Grall
2018-08-14 21:04   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 07/15] xen/arm: Rework lpae_table Julien Grall
2018-08-14 21:07   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 08/15] xen/arm: Rename lpae_valid to lpae_is_valid Julien Grall
2018-08-14 21:09   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 09/15] xen/arm: guest_walk: Use lpae_is_mapping to simplify the code Julien Grall
2018-08-14 21:14   ` Stefano Stabellini
2018-07-16 17:27 ` Julien Grall [this message]
2018-08-14 21:25   ` [PATCH 10/15] xen/arm: Introduce helpers to get/set an MFN from/to an LPAE entry Stefano Stabellini
2018-07-16 17:27 ` [PATCH 11/15] xen/arm: Allow lpae_is_{table, mapping} helpers to work on invalid entry Julien Grall
2018-08-14 21:33   ` Stefano Stabellini
2018-08-14 22:51     ` Julien Grall
2018-08-15 19:13       ` Stefano Stabellini
2018-08-16  8:51         ` Julien Grall
2018-07-16 17:27 ` [PATCH 12/15] xen/arm: p2m: Rename ret to mfn in p2m_lookup Julien Grall
2018-08-14 21:35   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 13/15] xen/arm: p2m: Introduce a new variable removing_mapping in __p2m_set_entry Julien Grall
2018-08-14 21:37   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 14/15] xen/arm: guest_walk_tables: Switch the return to bool Julien Grall
2018-08-14 21:41   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 15/15] xen/arm: traps: Move the implementation of GUEST_BUG_ON in traps.h Julien Grall
2018-08-14 21:43   ` Stefano Stabellini
2018-08-16  8:54     ` Julien Grall
2018-08-16 18:17       ` Stefano Stabellini
2018-08-20  9:17         ` Julien Grall
2018-08-20 22:02           ` Stefano Stabellini
2018-07-23 17:12 ` [PATCH 00/15] xen/arm: Bunch of clean-up/improvement Julien Grall
2018-08-22 15:45 ` Julien Grall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180716172712.20294-11-julien.grall@arm.com \
    --to=julien.grall@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.