diff mbox series

[RFCv2,03/15] xen/arm: p2m: Replace level_{orders, masks} arrays with LEVEL_{ORDER, MASK}

Message ID 20210425201318.15447-4-julien@xen.org (mailing list archive)
State New
Headers show
Series xen/arm: mm: Remove open-coding mappings | expand

Commit Message

Julien Grall April 25, 2021, 8:13 p.m. UTC
From: Julien Grall <jgrall@amazon.com>

The array level_orders and level_masks can be replaced with the
recently introduced macros LEVEL_ORDER and LEVEL_MASK.

Signed-off-by: Julien Grall <jgrall@amazon.com>

---
    Changes in v2:
        - New patch
---
 xen/arch/arm/p2m.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

Comments

Stefano Stabellini May 11, 2021, 10:33 p.m. UTC | #1
On Sun, 25 Apr 2021, Julien Grall wrote:
> From: Julien Grall <jgrall@amazon.com>
> 
> The array level_orders and level_masks can be replaced with the
> recently introduced macros LEVEL_ORDER and LEVEL_MASK.
> 
> Signed-off-by: Julien Grall <jgrall@amazon.com>

So you actually planned to use LEVEL_ORDER and LEVEL_MASK in the xen/
code. I take back the previous comment :-)

Is the 4KB size "hiding" (for the lack of a better word) done on purpose?

Let me rephrase. Are you trying to consolidate info about pages being
4KB in xen/include/asm-arm/lpae.h ?

In any case:

Acked-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
>     Changes in v2:
>         - New patch
> ---
>  xen/arch/arm/p2m.c | 16 +++++-----------
>  1 file changed, 5 insertions(+), 11 deletions(-)
> 
> diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
> index ac5031262061..1b04c3534439 100644
> --- a/xen/arch/arm/p2m.c
> +++ b/xen/arch/arm/p2m.c
> @@ -36,12 +36,6 @@ static unsigned int __read_mostly max_vmid = MAX_VMID_8_BIT;
>   */
>  unsigned int __read_mostly p2m_ipa_bits = 64;
>  
> -/* Helpers to lookup the properties of each level */
> -static const paddr_t level_masks[] =
> -    { ZEROETH_MASK, FIRST_MASK, SECOND_MASK, THIRD_MASK };
> -static const uint8_t level_orders[] =
> -    { ZEROETH_ORDER, FIRST_ORDER, SECOND_ORDER, THIRD_ORDER };
> -
>  static mfn_t __read_mostly empty_root_mfn;
>  
>  static uint64_t generate_vttbr(uint16_t vmid, mfn_t root_mfn)
> @@ -232,7 +226,7 @@ static lpae_t *p2m_get_root_pointer(struct p2m_domain *p2m,
>       * we can't use (P2M_ROOT_LEVEL - 1) because the root level might be
>       * 0. Yet we still want to check if all the unused bits are zeroed.
>       */
> -    root_table = gfn_x(gfn) >> (level_orders[P2M_ROOT_LEVEL] + LPAE_SHIFT);
> +    root_table = gfn_x(gfn) >> (LEVEL_ORDER(P2M_ROOT_LEVEL) + LPAE_SHIFT);
>      if ( root_table >= P2M_ROOT_PAGES )
>          return NULL;
>  
> @@ -378,7 +372,7 @@ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn,
>      if ( gfn_x(gfn) > gfn_x(p2m->max_mapped_gfn) )
>      {
>          for ( level = P2M_ROOT_LEVEL; level < 3; level++ )
> -            if ( (gfn_x(gfn) & (level_masks[level] >> PAGE_SHIFT)) >
> +            if ( (gfn_x(gfn) & (LEVEL_MASK(level) >> PAGE_SHIFT)) >
>                   gfn_x(p2m->max_mapped_gfn) )
>                  break;
>  
> @@ -421,7 +415,7 @@ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn,
>           * The entry may point to a superpage. Find the MFN associated
>           * to the GFN.
>           */
> -        mfn = mfn_add(mfn, gfn_x(gfn) & ((1UL << level_orders[level]) - 1));
> +        mfn = mfn_add(mfn, gfn_x(gfn) & ((1UL << LEVEL_ORDER(level)) - 1));
>  
>          if ( valid )
>              *valid = lpae_is_valid(entry);
> @@ -432,7 +426,7 @@ out_unmap:
>  
>  out:
>      if ( page_order )
> -        *page_order = level_orders[level];
> +        *page_order = LEVEL_ORDER(level);
>  
>      return mfn;
>  }
> @@ -806,7 +800,7 @@ static bool p2m_split_superpage(struct p2m_domain *p2m, lpae_t *entry,
>      /* Convenience aliases */
>      mfn_t mfn = lpae_get_mfn(*entry);
>      unsigned int next_level = level + 1;
> -    unsigned int level_order = level_orders[next_level];
> +    unsigned int level_order = LEVEL_ORDER(next_level);
>  
>      /*
>       * This should only be called with target != level and the entry is
> -- 
> 2.17.1
>
Julien Grall May 12, 2021, 2:39 p.m. UTC | #2
Hi Stefano,

On 11/05/2021 23:33, Stefano Stabellini wrote:
> On Sun, 25 Apr 2021, Julien Grall wrote:
>> From: Julien Grall <jgrall@amazon.com>
>>
>> The array level_orders and level_masks can be replaced with the
>> recently introduced macros LEVEL_ORDER and LEVEL_MASK.
>>
>> Signed-off-by: Julien Grall <jgrall@amazon.com>
> 
> So you actually planned to use LEVEL_ORDER and LEVEL_MASK in the xen/
> code. I take back the previous comment :-)
> 
> Is the 4KB size "hiding" (for the lack of a better word) done on purpose?
> 
> Let me rephrase. Are you trying to consolidate info about pages being
> 4KB in xen/include/asm-arm/lpae.h ?

THIRD_ORDER, SECOND_ORDER... is already not very 4KB specific :). In 
this case, what I am trying to do is completely removing the static 
arrays so they don't need to be global (or duplicated) when adding 
superpage support for Xen PT (see a follow-up patch).

This also has the added benefits to replace a with a couple of loads 
with only a few instructions working on immediates.

> 
> In any case:
> 
> Acked-by: Stefano Stabellini <sstabellini@kernel.org>

Thank you!

Cheers,
diff mbox series

Patch

diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index ac5031262061..1b04c3534439 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -36,12 +36,6 @@  static unsigned int __read_mostly max_vmid = MAX_VMID_8_BIT;
  */
 unsigned int __read_mostly p2m_ipa_bits = 64;
 
-/* Helpers to lookup the properties of each level */
-static const paddr_t level_masks[] =
-    { ZEROETH_MASK, FIRST_MASK, SECOND_MASK, THIRD_MASK };
-static const uint8_t level_orders[] =
-    { ZEROETH_ORDER, FIRST_ORDER, SECOND_ORDER, THIRD_ORDER };
-
 static mfn_t __read_mostly empty_root_mfn;
 
 static uint64_t generate_vttbr(uint16_t vmid, mfn_t root_mfn)
@@ -232,7 +226,7 @@  static lpae_t *p2m_get_root_pointer(struct p2m_domain *p2m,
      * we can't use (P2M_ROOT_LEVEL - 1) because the root level might be
      * 0. Yet we still want to check if all the unused bits are zeroed.
      */
-    root_table = gfn_x(gfn) >> (level_orders[P2M_ROOT_LEVEL] + LPAE_SHIFT);
+    root_table = gfn_x(gfn) >> (LEVEL_ORDER(P2M_ROOT_LEVEL) + LPAE_SHIFT);
     if ( root_table >= P2M_ROOT_PAGES )
         return NULL;
 
@@ -378,7 +372,7 @@  mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn,
     if ( gfn_x(gfn) > gfn_x(p2m->max_mapped_gfn) )
     {
         for ( level = P2M_ROOT_LEVEL; level < 3; level++ )
-            if ( (gfn_x(gfn) & (level_masks[level] >> PAGE_SHIFT)) >
+            if ( (gfn_x(gfn) & (LEVEL_MASK(level) >> PAGE_SHIFT)) >
                  gfn_x(p2m->max_mapped_gfn) )
                 break;
 
@@ -421,7 +415,7 @@  mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn,
          * The entry may point to a superpage. Find the MFN associated
          * to the GFN.
          */
-        mfn = mfn_add(mfn, gfn_x(gfn) & ((1UL << level_orders[level]) - 1));
+        mfn = mfn_add(mfn, gfn_x(gfn) & ((1UL << LEVEL_ORDER(level)) - 1));
 
         if ( valid )
             *valid = lpae_is_valid(entry);
@@ -432,7 +426,7 @@  out_unmap:
 
 out:
     if ( page_order )
-        *page_order = level_orders[level];
+        *page_order = LEVEL_ORDER(level);
 
     return mfn;
 }
@@ -806,7 +800,7 @@  static bool p2m_split_superpage(struct p2m_domain *p2m, lpae_t *entry,
     /* Convenience aliases */
     mfn_t mfn = lpae_get_mfn(*entry);
     unsigned int next_level = level + 1;
-    unsigned int level_order = level_orders[next_level];
+    unsigned int level_order = LEVEL_ORDER(next_level);
 
     /*
      * This should only be called with target != level and the entry is