diff mbox series

[Xen-devel,13/15] xen/arm: p2m: Introduce a new variable removing_mapping in __p2m_set_entry

Message ID 20180716172712.20294-14-julien.grall@arm.com
State New
Headers show
Series xen/arm: Bunch of clean-up/improvement | expand

Commit Message

Julien Grall July 16, 2018, 5:27 p.m. UTC
This is making the code slightly easier to understand.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
---
 xen/arch/arm/p2m.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Stefano Stabellini Aug. 14, 2018, 9:37 p.m. UTC | #1
On Mon, 16 Jul 2018, Julien Grall wrote:
> This is making the code slightly easier to understand.
> 
> Signed-off-by: Julien Grall <julien.grall@linaro.org>

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


> ---
>  xen/arch/arm/p2m.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
> index 66d58fabd7..e826f57842 100644
> --- a/xen/arch/arm/p2m.c
> +++ b/xen/arch/arm/p2m.c
> @@ -792,6 +792,8 @@ static int __p2m_set_entry(struct p2m_domain *p2m,
>      unsigned int target = 3 - (page_order / LPAE_SHIFT);
>      lpae_t *entry, *table, orig_pte;
>      int rc;
> +    /* A mapping is removed if the MFN is invalid. */
> +    bool removing_mapping = mfn_eq(smfn, INVALID_MFN);
>  
>      /* Convenience aliases */
>      const unsigned int offsets[4] = {
> @@ -817,9 +819,9 @@ static int __p2m_set_entry(struct p2m_domain *p2m,
>      {
>          /*
>           * Don't try to allocate intermediate page table if the mapping
> -         * is about to be removed (i.e mfn == INVALID_MFN).
> +         * is about to be removed.
>           */
> -        rc = p2m_next_level(p2m, mfn_eq(smfn, INVALID_MFN),
> +        rc = p2m_next_level(p2m, removing_mapping,
>                              level, &table, offsets[level]);
>          if ( rc == GUEST_TABLE_MAP_FAILED )
>          {
> @@ -830,7 +832,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m,
>               * when removing a mapping as it may not exist in the
>               * page table. In this case, just ignore it.
>               */
> -            rc = mfn_eq(smfn, INVALID_MFN) ? 0 : -ENOENT;
> +            rc = removing_mapping ?  0 : -ENOENT;
>              goto out;
>          }
>          else if ( rc != GUEST_TABLE_NORMAL_PAGE )
> @@ -925,7 +927,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m,
>      if ( lpae_is_valid(orig_pte) )
>          p2m_remove_pte(entry, p2m->clean_pte);
>  
> -    if ( mfn_eq(smfn, INVALID_MFN) )
> +    if ( removing_mapping )
>          /* Flush can be deferred if the entry is removed */
>          p2m->need_flush |= !!lpae_is_valid(orig_pte);
>      else
> -- 
> 2.11.0
>
diff mbox series

Patch

diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index 66d58fabd7..e826f57842 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -792,6 +792,8 @@  static int __p2m_set_entry(struct p2m_domain *p2m,
     unsigned int target = 3 - (page_order / LPAE_SHIFT);
     lpae_t *entry, *table, orig_pte;
     int rc;
+    /* A mapping is removed if the MFN is invalid. */
+    bool removing_mapping = mfn_eq(smfn, INVALID_MFN);
 
     /* Convenience aliases */
     const unsigned int offsets[4] = {
@@ -817,9 +819,9 @@  static int __p2m_set_entry(struct p2m_domain *p2m,
     {
         /*
          * Don't try to allocate intermediate page table if the mapping
-         * is about to be removed (i.e mfn == INVALID_MFN).
+         * is about to be removed.
          */
-        rc = p2m_next_level(p2m, mfn_eq(smfn, INVALID_MFN),
+        rc = p2m_next_level(p2m, removing_mapping,
                             level, &table, offsets[level]);
         if ( rc == GUEST_TABLE_MAP_FAILED )
         {
@@ -830,7 +832,7 @@  static int __p2m_set_entry(struct p2m_domain *p2m,
              * when removing a mapping as it may not exist in the
              * page table. In this case, just ignore it.
              */
-            rc = mfn_eq(smfn, INVALID_MFN) ? 0 : -ENOENT;
+            rc = removing_mapping ?  0 : -ENOENT;
             goto out;
         }
         else if ( rc != GUEST_TABLE_NORMAL_PAGE )
@@ -925,7 +927,7 @@  static int __p2m_set_entry(struct p2m_domain *p2m,
     if ( lpae_is_valid(orig_pte) )
         p2m_remove_pte(entry, p2m->clean_pte);
 
-    if ( mfn_eq(smfn, INVALID_MFN) )
+    if ( removing_mapping )
         /* Flush can be deferred if the entry is removed */
         p2m->need_flush |= !!lpae_is_valid(orig_pte);
     else