diff mbox series

[2/5] x86_64/mm: map and unmap page tables in m2p_mapped

Message ID 9b46a0bae03107fcb192e6590234b9e882965f11.1584955616.git.hongyxia@amazon.com (mailing list archive)
State Superseded
Headers show
Series use new API for Xen page tables | expand

Commit Message

Hongyan Xia March 23, 2020, 9:41 a.m. UTC
From: Wei Liu <wei.liu2@citrix.com>

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Hongyan Xia <hongyxia@amazon.com>
---
 xen/arch/x86/x86_64/mm.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Comments

Jan Beulich April 1, 2020, 12:19 p.m. UTC | #1
On 23.03.2020 10:41, Hongyan Xia wrote:
> --- a/xen/arch/x86/x86_64/mm.c
> +++ b/xen/arch/x86/x86_64/mm.c
> @@ -131,27 +131,33 @@ static int m2p_mapped(unsigned long spfn)
>      unsigned long va;
>      l3_pgentry_t *l3_ro_mpt;
>      l2_pgentry_t *l2_ro_mpt;
> +    int rc = M2P_NO_MAPPED;
>  
>      va = RO_MPT_VIRT_START + spfn * sizeof(*machine_to_phys_mapping);
> -    l3_ro_mpt = l4e_to_l3e(idle_pg_table[l4_table_offset(va)]);
> +    l3_ro_mpt = map_l3t_from_l4e(idle_pg_table[l4_table_offset(va)]);

Along the lines of what I've said for patch 1 - read the l3e
here and unmap again right away. No need for converting
"return" to "goto" further down. Same for the l2e then.

Jan
diff mbox series

Patch

diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index b7ce833ffc..a440dac25e 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -131,27 +131,33 @@  static int m2p_mapped(unsigned long spfn)
     unsigned long va;
     l3_pgentry_t *l3_ro_mpt;
     l2_pgentry_t *l2_ro_mpt;
+    int rc = M2P_NO_MAPPED;
 
     va = RO_MPT_VIRT_START + spfn * sizeof(*machine_to_phys_mapping);
-    l3_ro_mpt = l4e_to_l3e(idle_pg_table[l4_table_offset(va)]);
+    l3_ro_mpt = map_l3t_from_l4e(idle_pg_table[l4_table_offset(va)]);
 
     switch ( l3e_get_flags(l3_ro_mpt[l3_table_offset(va)]) &
              (_PAGE_PRESENT |_PAGE_PSE))
     {
         case _PAGE_PSE|_PAGE_PRESENT:
-            return M2P_1G_MAPPED;
+            rc = M2P_1G_MAPPED;
+            goto out;
         /* Check for next level */
         case _PAGE_PRESENT:
             break;
         default:
-            return M2P_NO_MAPPED;
+            rc = M2P_NO_MAPPED;
+            goto out;
     }
-    l2_ro_mpt = l3e_to_l2e(l3_ro_mpt[l3_table_offset(va)]);
+    l2_ro_mpt = map_l2t_from_l3e(l3_ro_mpt[l3_table_offset(va)]);
 
     if (l2e_get_flags(l2_ro_mpt[l2_table_offset(va)]) & _PAGE_PRESENT)
-        return M2P_2M_MAPPED;
+        rc = M2P_2M_MAPPED;
+    UNMAP_DOMAIN_PAGE(l2_ro_mpt);
 
-    return M2P_NO_MAPPED;
+ out:
+    UNMAP_DOMAIN_PAGE(l3_ro_mpt);
+    return rc;
 }
 
 static int share_hotadd_m2p_table(struct mem_hotadd_info *info)