Skip to contentSkip to conversation

use new API for Xen page tables

PATCH Superseded Hongyan Xia 3 participants 19 messages Mar 23, 2020 – Apr 8, 2020

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover use new API for Xen page tables

From: Hongyan Xia <[email protected]>

This small series is basically just rewriting functions using the new API to map and unmap PTEs. Each patch is independent.

Apart from mapping and unmapping page tables, no other functional change intended.

Wei Liu (5):
x86/shim: map and unmap page tables in replace_va_mapping x86_64/mm: map and unmap page tables in m2p_mapped x86_64/mm: map and unmap page tables in share_hotadd_m2p_table x86_64/mm: map and unmap page tables in destroy_compat_m2p_mapping x86_64/mm: map and unmap page tables in destroy_m2p_mapping

 xen/arch/x86/pv/shim.c     | 10 ++++---
 xen/arch/x86/x86_64/mm.c   | 55 +++++++++++++++++++++++++-------------
 xen/include/asm-x86/page.h | 18 +++++++++++++
 3 files changed, 62 insertions(+), 21 deletions(-)
Signature · 7 lines
2.24.1.AMZN


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 1/5 x86/shim: map and unmap page tables in replace_va_mapping

From: Wei Liu <[email protected]>

---
 xen/arch/x86/pv/shim.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
xen/arch/x86/pv/shim.c +7 -3
index ed2ece8a8a..1229d5ffb3 100644
@@ -169,15 +169,19 @@ static void __init replace_va_mapping(struct domain *d, l4_pgentry_t *l4start,
                                       unsigned long va, mfn_t mfn)
 {
     l4_pgentry_t *pl4e = l4start + l4_table_offset(va);
-    l3_pgentry_t *pl3e = l4e_to_l3e(*pl4e) + l3_table_offset(va);
-    l2_pgentry_t *pl2e = l3e_to_l2e(*pl3e) + l2_table_offset(va);
-    l1_pgentry_t *pl1e = l2e_to_l1e(*pl2e) + l1_table_offset(va);
+    l3_pgentry_t *pl3e = map_l3t_from_l4e(*pl4e) + l3_table_offset(va);
+    l2_pgentry_t *pl2e = map_l2t_from_l3e(*pl3e) + l2_table_offset(va);
+    l1_pgentry_t *pl1e = map_l1t_from_l2e(*pl2e) + l1_table_offset(va);
     struct page_info *page = mfn_to_page(l1e_get_mfn(*pl1e));
 
     put_page_and_type(page);
 
     *pl1e = l1e_from_mfn(mfn, (!is_pv_32bit_domain(d) ? L1_PROT
                                                       : COMPAT_L1_PROT));
+
+    UNMAP_DOMAIN_PAGE(pl1e);
+    UNMAP_DOMAIN_PAGE(pl2e);
+    UNMAP_DOMAIN_PAGE(pl3e);
 }
 
 static void evtchn_reserve(struct domain *d, unsigned int port)
Signature · 7 lines
2.24.1.AMZN


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

Re: [PATCH 1/5] x86/shim: map and unmap page tables in replace_va_mapping

Quoted 13 lines · Hongyan Xia
xen/arch/x86/pv/shim.c +3 -3
@@ -169,15 +169,19 @@ static void __init replace_va_mapping(struct domain *d, l4_pgentry_t *l4start,
                                       unsigned long va, mfn_t mfn)
 {
     l4_pgentry_t *pl4e = l4start + l4_table_offset(va);
-    l3_pgentry_t *pl3e = l4e_to_l3e(*pl4e) + l3_table_offset(va);
-    l2_pgentry_t *pl2e = l3e_to_l2e(*pl3e) + l2_table_offset(va);
-    l1_pgentry_t *pl1e = l2e_to_l1e(*pl2e) + l1_table_offset(va);
+    l3_pgentry_t *pl3e = map_l3t_from_l4e(*pl4e) + l3_table_offset(va);
+    l2_pgentry_t *pl2e = map_l2t_from_l3e(*pl3e) + l2_table_offset(va);
+    l1_pgentry_t *pl1e = map_l1t_from_l2e(*pl2e) + l1_table_offset(va);
     struct page_info *page = mfn_to_page(l1e_get_mfn(*pl1e));

xen/arch/x86/pv/shim.c static void __init replace_va_mapping(struct domain *d, l4_pgentry_t *l4start, · line 185

Quoted 10 lines
xen/arch/x86/pv/shim.c +4 -0
 
     put_page_and_type(page);
 
     *pl1e = l1e_from_mfn(mfn, (!is_pv_32bit_domain(d) ? L1_PROT
                                                       : COMPAT_L1_PROT));
+
+    UNMAP_DOMAIN_PAGE(pl1e);
+    UNMAP_DOMAIN_PAGE(pl2e);
+    UNMAP_DOMAIN_PAGE(pl3e);
 }

I disagree to an approach like this: Why have three pending mappings when one at a time will do? Map-read/write-unmap three times is what you want here, even if this is more code churn.

Jan

#3 lore raw

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

In reply to Hongyan Xia

From: Wei Liu <[email protected]>

---
 xen/arch/x86/x86_64/mm.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
xen/arch/x86/x86_64/mm.c +12 -6
index b7ce833ffc..a440dac25e 100644
@@ -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)
Signature · 7 lines
2.24.1.AMZN


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#4 lore raw

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

xen/arch/x86/x86_64/mm.c static int m2p_mapped(unsigned long spfn) · line 137

Quoted 11 lines · Hongyan Xia
xen/arch/x86/x86_64/mm.c +2 -1
@@ -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

#5 lore raw

PATCH 3/5 x86_64/mm: map and unmap page tables in share_hotadd_m2p_table

In reply to Hongyan Xia

From: Wei Liu <[email protected]>

Fetch lYe by mapping and unmapping lXe instead of using the direct map, which is now done via the new lYe_from_lXe() helpers.

---
 xen/arch/x86/x86_64/mm.c   | 12 ++++++------
 xen/include/asm-x86/page.h | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+), 6 deletions(-)
xen/arch/x86/x86_64/mm.c +6 -6
index a440dac25e..2680173fab 100644
@@ -173,14 +173,14 @@ static int share_hotadd_m2p_table(struct mem_hotadd_info *info)
           v += n << PAGE_SHIFT )
     {
         n = L2_PAGETABLE_ENTRIES * L1_PAGETABLE_ENTRIES;
-        l3e = l4e_to_l3e(idle_pg_table[l4_table_offset(v)])[
-            l3_table_offset(v)];
+        l3e = l3e_from_l4e(idle_pg_table[l4_table_offset(v)],
+                           l3_table_offset(v));
         if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) )
             continue;
         if ( !(l3e_get_flags(l3e) & _PAGE_PSE) )
         {
             n = L1_PAGETABLE_ENTRIES;
-            l2e = l3e_to_l2e(l3e)[l2_table_offset(v)];
+            l2e = l2e_from_l3e(l3e, l2_table_offset(v));
             if ( !(l2e_get_flags(l2e) & _PAGE_PRESENT) )
                 continue;
             m2p_start_mfn = l2e_get_mfn(l2e);
@@ -201,11 +201,11 @@ static int share_hotadd_m2p_table(struct mem_hotadd_info *info)
           v != RDWR_COMPAT_MPT_VIRT_END;
           v += 1 << L2_PAGETABLE_SHIFT )
     {
-        l3e = l4e_to_l3e(idle_pg_table[l4_table_offset(v)])[
-            l3_table_offset(v)];
+        l3e = l3e_from_l4e(idle_pg_table[l4_table_offset(v)],
+                           l3_table_offset(v));
         if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) )
             continue;
-        l2e = l3e_to_l2e(l3e)[l2_table_offset(v)];
+        l2e = l2e_from_l3e(l3e, l2_table_offset(v));
         if ( !(l2e_get_flags(l2e) & _PAGE_PRESENT) )
             continue;
         m2p_start_mfn = l2e_get_mfn(l2e);
xen/include/asm-x86/page.h +18 -0
index c98d8f5ede..d4752a5925 100644
@@ -196,6 +196,24 @@ static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags)
 #define map_l2t_from_l3e(x)        (l2_pgentry_t *)map_domain_page(l3e_get_mfn(x))
 #define map_l3t_from_l4e(x)        (l3_pgentry_t *)map_domain_page(l4e_get_mfn(x))
 
+#define l1e_from_l2e(l2e, off) ({                   \
+        l1_pgentry_t *l1t = map_l1t_from_l2e(l2e);  \
+        l1_pgentry_t l1e = l1t[off];                \
+        UNMAP_DOMAIN_PAGE(l1t);                     \
+        l1e; })
+
+#define l2e_from_l3e(l3e, off) ({                   \
+        l2_pgentry_t *l2t = map_l2t_from_l3e(l3e);  \
+        l2_pgentry_t l2e = l2t[off];                \
+        UNMAP_DOMAIN_PAGE(l2t);                     \
+        l2e; })
+
+#define l3e_from_l4e(l4e, off) ({                   \
+        l3_pgentry_t *l3t = map_l3t_from_l4e(l4e);  \
+        l3_pgentry_t l3e = l3t[off];                \
+        UNMAP_DOMAIN_PAGE(l3t);                     \
+        l3e; })
+
 /* Given a virtual address, get an entry offset into a page table. */
 #define l1_table_offset(a)         \
     (((a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
Signature · 7 lines
2.24.1.AMZN


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#6 lore raw

Re: [PATCH 3/5] x86_64/mm: map and unmap page tables in share_hotadd_m2p_table

Quoted 13 lines · Hongyan Xia
xen/include/asm-x86/page.h +7 -0
@@ -196,6 +196,24 @@ static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags)
 #define map_l2t_from_l3e(x)        (l2_pgentry_t *)map_domain_page(l3e_get_mfn(x))
 #define map_l3t_from_l4e(x)        (l3_pgentry_t *)map_domain_page(l4e_get_mfn(x))
 
+#define l1e_from_l2e(l2e, off) ({                   \
+        l1_pgentry_t *l1t = map_l1t_from_l2e(l2e);  \
+        l1_pgentry_t l1e = l1t[off];                \
+        UNMAP_DOMAIN_PAGE(l1t);                     \
+        l1e; })
+
+#define l2e_from_l3e(l3e, off) ({                   \

xen/include/asm-x86/page.h static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags) · line 215

Quoted 10 lines
xen/include/asm-x86/page.h +10 -0
+        l2_pgentry_t *l2t = map_l2t_from_l3e(l3e);  \
+        l2_pgentry_t l2e = l2t[off];                \
+        UNMAP_DOMAIN_PAGE(l2t);                     \
+        l2e; })
+
+#define l3e_from_l4e(l4e, off) ({                   \
+        l3_pgentry_t *l3t = map_l3t_from_l4e(l4e);  \
+        l3_pgentry_t l3e = l3t[off];                \
+        UNMAP_DOMAIN_PAGE(l3t);                     \
+        l3e; })

There's a reason these are macros rather than inline functions, I assume? (This reason would be nice to be stated in the description.)

I don't see why you use UNMAP_DOMAIN_PAGE() rather than unmap_domain_page() here - the variables in question go out of scope right afterwards, so the storing of NULL into them is pointless (and very likely to be eliminated by the compiler anyway).

Finally the pointers should each be "to const", as you're only reading through them.

Jan

#7 lore raw

Re: [PATCH 3/5] x86_64/mm: map and unmap page tables in share_hotadd_m2p_table

Quoted 23 lines · Jan Beulich
Quoted 22 lines · Hongyan Xia
xen/include/asm-x86/page.h +13 -0
@@ -196,6 +196,24 @@ static inline l4_pgentry_t
 l4e_from_paddr(paddr_t pa, unsigned int flags)
 #define map_l2t_from_l3e(x)        (l2_pgentry_t
 *)map_domain_page(l3e_get_mfn(x))
 #define map_l3t_from_l4e(x)        (l3_pgentry_t
 *)map_domain_page(l4e_get_mfn(x))
 
+#define l1e_from_l2e(l2e, off) ({                   \
+        l1_pgentry_t *l1t = map_l1t_from_l2e(l2e);  \
+        l1_pgentry_t l1e = l1t[off];                \
+        UNMAP_DOMAIN_PAGE(l1t);                     \
+        l1e; })
+
+#define l2e_from_l3e(l3e, off) ({                   \
+        l2_pgentry_t *l2t = map_l2t_from_l3e(l3e);  \
+        l2_pgentry_t l2e = l2t[off];                \
+        UNMAP_DOMAIN_PAGE(l2t);                     \
+        l2e; })
+
+#define l3e_from_l4e(l4e, off) ({                   \
Quoted 8 lines

xen/include/asm-x86/page.h static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags) · line 215

Quoted 4 lines
xen/include/asm-x86/page.h +4 -0
+        l3_pgentry_t *l3t = map_l3t_from_l4e(l4e);  \
+        l3_pgentry_t l3e = l3t[off];                \
+        UNMAP_DOMAIN_PAGE(l3t);                     \
+        l3e; })

There's a reason these are macros rather than inline functions, I assume? (This reason would be nice to be stated in the description.)

Actually no specific reasons, just to keep them as macros to be consistent with other helpers above. Fairly trivial to convert them into inline functions if this is desired.

Quoted 5 lines

I don't see why you use UNMAP_DOMAIN_PAGE() rather than unmap_domain_page() here - the variables in question go out of scope right afterwards, so the storing of NULL into them is pointless (and very likely to be eliminated by the compiler anyway).

My intention is to just avoid using the lower case one altogether, so that one day when we need to expand any function or macros we do not need to look back at the code and worry about whether any lower case ones need to be converted to upper case (sometimes for large functions this may not be trivial), and the compiler can deal with the extra nullification anyway.

Quoted 2 lines

Finally the pointers should each be "to const", as you're only reading through them.

Good point. Will const qualify in next revision.

Thanks,
Hongyan

#8 lore raw

Re: [PATCH 3/5] x86_64/mm: map and unmap page tables in share_hotadd_m2p_table

Quoted 33 lines · Hongyan Xia
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Hongyan Xia
xen/include/asm-x86/page.h +13 -0
@@ -196,6 +196,24 @@ static inline l4_pgentry_t
 l4e_from_paddr(paddr_t pa, unsigned int flags)
 #define map_l2t_from_l3e(x)        (l2_pgentry_t
 *)map_domain_page(l3e_get_mfn(x))
 #define map_l3t_from_l4e(x)        (l3_pgentry_t
 *)map_domain_page(l4e_get_mfn(x))
 
+#define l1e_from_l2e(l2e, off) ({                   \
+        l1_pgentry_t *l1t = map_l1t_from_l2e(l2e);  \
+        l1_pgentry_t l1e = l1t[off];                \
+        UNMAP_DOMAIN_PAGE(l1t);                     \
+        l1e; })
+
+#define l2e_from_l3e(l3e, off) ({                   \
+        l2_pgentry_t *l2t = map_l2t_from_l3e(l3e);  \
+        l2_pgentry_t l2e = l2t[off];                \
+        UNMAP_DOMAIN_PAGE(l2t);                     \
+        l2e; })
+
+#define l3e_from_l4e(l4e, off) ({                   \
Quoted 8 lines

xen/include/asm-x86/page.h static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags) · line 215

Quoted 4 lines
xen/include/asm-x86/page.h +4 -0
+        l3_pgentry_t *l3t = map_l3t_from_l4e(l4e);  \
+        l3_pgentry_t l3e = l3t[off];                \
+        UNMAP_DOMAIN_PAGE(l3t);                     \
+        l3e; })

There's a reason these are macros rather than inline functions, I assume? (This reason would be nice to be stated in the description.)

Quoted 3 lines

Actually no specific reasons, just to keep them as macros to be consistent with other helpers above. Fairly trivial to convert them into inline functions if this is desired.

Where possible this would be the preferred route for new helpers.

Quoted 6 lines
Quoted 5 lines

I don't see why you use UNMAP_DOMAIN_PAGE() rather than unmap_domain_page() here - the variables in question go out of scope right afterwards, so the storing of NULL into them is pointless (and very likely to be eliminated by the compiler anyway).

Quoted 6 lines

My intention is to just avoid using the lower case one altogether, so that one day when we need to expand any function or macros we do not need to look back at the code and worry about whether any lower case ones need to be converted to upper case (sometimes for large functions this may not be trivial), and the compiler can deal with the extra nullification anyway.

I don't agree with this goal; perhaps others on Cc have an opinion?

Jan

#9 lore raw

Re: [PATCH 3/5] x86_64/mm: map and unmap page tables in share_hotadd_m2p_table

In reply to Jan Beulich
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Hongyan Xia
xen/include/asm-x86/page.h +13 -0
@@ -196,6 +196,24 @@ static inline l4_pgentry_t
 l4e_from_paddr(paddr_t pa, unsigned int flags)
 #define map_l2t_from_l3e(x)        (l2_pgentry_t
 *)map_domain_page(l3e_get_mfn(x))
 #define map_l3t_from_l4e(x)        (l3_pgentry_t
 *)map_domain_page(l4e_get_mfn(x))
 
+#define l1e_from_l2e(l2e, off) ({                   \
+        l1_pgentry_t *l1t = map_l1t_from_l2e(l2e);  \
+        l1_pgentry_t l1e = l1t[off];                \
+        UNMAP_DOMAIN_PAGE(l1t);                     \
+        l1e; })
+
+#define l2e_from_l3e(l3e, off) ({                   \
+        l2_pgentry_t *l2t = map_l2t_from_l3e(l3e);  \
+        l2_pgentry_t l2e = l2t[off];                \
+        UNMAP_DOMAIN_PAGE(l2t);                     \
+        l2e; })
+
+#define l3e_from_l4e(l4e, off) ({                   \
Quoted 8 lines

xen/include/asm-x86/page.h static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags) · line 215

Quoted 4 lines
xen/include/asm-x86/page.h +4 -0
+        l3_pgentry_t *l3t = map_l3t_from_l4e(l4e);  \
+        l3_pgentry_t l3e = l3t[off];                \
+        UNMAP_DOMAIN_PAGE(l3t);                     \
+        l3e; })

There's a reason these are macros rather than inline functions, I assume? (This reason would be nice to be stated in the description.)

While converting them into inline functions, I realised I cannot do that due to the header mess. Converting into inline functions needs the domain_page.h header, which opens a can of worms if I include it here (page.h). Keeping them as macros works around this issue.

I will add this in the description.

Hongyan

#10 lore raw

PATCH 4/5 x86_64/mm: map and unmap page tables in destroy_compat_m2p_mapping

In reply to Hongyan Xia

From: Wei Liu <[email protected]>

---
 xen/arch/x86/x86_64/mm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
xen/arch/x86/x86_64/mm.c +7 -2
index 2680173fab..71c84ac593 100644
@@ -235,11 +235,13 @@ static void destroy_compat_m2p_mapping(struct mem_hotadd_info *info)
     if ( emap > ((RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) >> 2) )
         emap = (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) >> 2;
 
-    l3_ro_mpt = l4e_to_l3e(idle_pg_table[l4_table_offset(HIRO_COMPAT_MPT_VIRT_START)]);
+    l3_ro_mpt = map_l3t_from_l4e(idle_pg_table[
+                    l4_table_offset(HIRO_COMPAT_MPT_VIRT_START)]);
 
     ASSERT(l3e_get_flags(l3_ro_mpt[l3_table_offset(HIRO_COMPAT_MPT_VIRT_START)]) & _PAGE_PRESENT);
 
-    l2_ro_mpt = l3e_to_l2e(l3_ro_mpt[l3_table_offset(HIRO_COMPAT_MPT_VIRT_START)]);
+    l2_ro_mpt = map_l2t_from_l3e(
+                    l3_ro_mpt[l3_table_offset(HIRO_COMPAT_MPT_VIRT_START)]);
 
     for ( i = smap; i < emap; )
     {
@@ -261,6 +263,9 @@ static void destroy_compat_m2p_mapping(struct mem_hotadd_info *info)
         i += 1UL << (L2_PAGETABLE_SHIFT - 2);
     }
 
+    UNMAP_DOMAIN_PAGE(l2_ro_mpt);
+    UNMAP_DOMAIN_PAGE(l3_ro_mpt);
+
     return;
 }
 
Signature · 7 lines
2.24.1.AMZN


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#11 lore raw

PATCH 5/5 x86_64/mm: map and unmap page tables in destroy_m2p_mapping

In reply to Hongyan Xia

From: Wei Liu <[email protected]>

---
 xen/arch/x86/x86_64/mm.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
xen/arch/x86/x86_64/mm.c +12 -4
index 71c84ac593..6a0ffe088b 100644
@@ -275,7 +275,8 @@ static void destroy_m2p_mapping(struct mem_hotadd_info *info)
     unsigned long i, va, rwva;
     unsigned long smap = info->spfn, emap = info->epfn;
 
-    l3_ro_mpt = l4e_to_l3e(idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)]);
+    l3_ro_mpt = map_l3t_from_l4e(
+                    idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)]);
 
     /*
      * No need to clean m2p structure existing before the hotplug
@@ -297,26 +298,33 @@ static void destroy_m2p_mapping(struct mem_hotadd_info *info)
             continue;
         }
 
-        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))
         {
             i = ( i & ~((1UL << (L2_PAGETABLE_SHIFT - 3)) - 1)) +
                     (1UL << (L2_PAGETABLE_SHIFT - 3)) ;
+            UNMAP_DOMAIN_PAGE(l2_ro_mpt);
             continue;
         }
 
         pt_pfn = l2e_get_pfn(l2_ro_mpt[l2_table_offset(va)]);
         if ( hotadd_mem_valid(pt_pfn, info) )
         {
+            l2_pgentry_t *l2t;
+
             destroy_xen_mappings(rwva, rwva + (1UL << L2_PAGETABLE_SHIFT));
 
-            l2_ro_mpt = l3e_to_l2e(l3_ro_mpt[l3_table_offset(va)]);
-            l2e_write(&l2_ro_mpt[l2_table_offset(va)], l2e_empty());
+            l2t = map_l2t_from_l3e(l3_ro_mpt[l3_table_offset(va)]);
+            l2e_write(&l2t[l2_table_offset(va)], l2e_empty());
+            UNMAP_DOMAIN_PAGE(l2t);
         }
         i = ( i & ~((1UL << (L2_PAGETABLE_SHIFT - 3)) - 1)) +
               (1UL << (L2_PAGETABLE_SHIFT - 3));
+        UNMAP_DOMAIN_PAGE(l2_ro_mpt);
     }
 
+    UNMAP_DOMAIN_PAGE(l3_ro_mpt);
+
     destroy_compat_m2p_mapping(info);
 
     /* Brute-Force flush all TLB */
Signature · 7 lines
2.24.1.AMZN


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#12 lore raw

Re: [PATCH 5/5] x86_64/mm: map and unmap page tables in destroy_m2p_mapping

Quoted 14 lines · Hongyan Xia
xen/arch/x86/x86_64/mm.c +2 -1
@@ -297,26 +298,33 @@ static void destroy_m2p_mapping(struct mem_hotadd_info *info)
             continue;
         }
 
-        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))
         {
             i = ( i & ~((1UL << (L2_PAGETABLE_SHIFT - 3)) - 1)) +
                     (1UL << (L2_PAGETABLE_SHIFT - 3)) ;
+            UNMAP_DOMAIN_PAGE(l2_ro_mpt);
             continue;
         }
 

xen/arch/x86/x86_64/mm.c static void destroy_m2p_mapping(struct mem_hotadd_info *info) · line 317

Quoted 10 lines
xen/arch/x86/x86_64/mm.c +3 -2
         pt_pfn = l2e_get_pfn(l2_ro_mpt[l2_table_offset(va)]);
         if ( hotadd_mem_valid(pt_pfn, info) )
         {
+            l2_pgentry_t *l2t;
+
             destroy_xen_mappings(rwva, rwva + (1UL << L2_PAGETABLE_SHIFT));
 
-            l2_ro_mpt = l3e_to_l2e(l3_ro_mpt[l3_table_offset(va)]);
-            l2e_write(&l2_ro_mpt[l2_table_offset(va)], l2e_empty());
+            l2t = map_l2t_from_l3e(l3_ro_mpt[l3_table_offset(va)]);

Why a 2nd mapping of the same L3 entry that you've already mapped into l2_ro_mpt?

xen/arch/x86/x86_64/mm.c static void destroy_m2p_mapping(struct mem_hotadd_info *info) · line 319

Quoted 2 lines
xen/arch/x86/x86_64/mm.c +2 -0
+            l2e_write(&l2t[l2_table_offset(va)], l2e_empty());
+            UNMAP_DOMAIN_PAGE(l2t);

If this then weren't to go away, it should again be the lowercase variant imo, as the variable's scope ends here.

Jan

#13 lore raw

Re: [PATCH 5/5] x86_64/mm: map and unmap page tables in destroy_m2p_mapping

Quoted 35 lines · Jan Beulich
Quoted 21 lines · Hongyan Xia
xen/arch/x86/x86_64/mm.c +3 -1
@@ -297,26 +298,33 @@ static void destroy_m2p_mapping(struct
 mem_hotadd_info *info)
             continue;
         }
 
-        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))
         {
             i = ( i & ~((1UL << (L2_PAGETABLE_SHIFT - 3)) - 1)) +
                     (1UL << (L2_PAGETABLE_SHIFT - 3)) ;
+            UNMAP_DOMAIN_PAGE(l2_ro_mpt);
             continue;
         }
 
         pt_pfn = l2e_get_pfn(l2_ro_mpt[l2_table_offset(va)]);
         if ( hotadd_mem_valid(pt_pfn, info) )
         {
+            l2_pgentry_t *l2t;

xen/arch/x86/x86_64/mm.c static void destroy_m2p_mapping(struct · line 324

Quoted 10 lines
xen/arch/x86/x86_64/mm.c +2 -2
+
             destroy_xen_mappings(rwva, rwva + (1UL <<
 L2_PAGETABLE_SHIFT));
 
-            l2_ro_mpt =
 l3e_to_l2e(l3_ro_mpt[l3_table_offset(va)]);
-            l2e_write(&l2_ro_mpt[l2_table_offset(va)],
 l2e_empty());
+            l2t =
 map_l2t_from_l3e(l3_ro_mpt[l3_table_offset(va)]);

Why a 2nd mapping of the same L3 entry that you've already mapped into l2_ro_mpt?

Quoted 5 lines

xen/arch/x86/x86_64/mm.c static void destroy_m2p_mapping(struct mem_hotadd_info *info) · line 319

Quoted 2 lines
xen/arch/x86/x86_64/mm.c +2 -0
+            l2e_write(&l2t[l2_table_offset(va)], l2e_empty());
+            UNMAP_DOMAIN_PAGE(l2t);

If this then weren't to go away, it should again be the lowercase variant imo, as the variable's scope ends here.

Hmm, I don't see a reason why l2_ro_mpt needs to be mapped again either (and don't see why it was re-derived in the original code), so yes, I think the map and unmap can just be dropped. Will revise.

Hongyan

#14 lore raw
In reply to Hongyan Xia
Quoted 8 lines · Hongyan Xia

From: Hongyan Xia <[email protected]>

This small series is basically just rewriting functions using the new API to map and unmap PTEs. Each patch is independent.

Apart from mapping and unmapping page tables, no other functional change intended.

The code looks correct to me.

I do wonder if you should've put your SoB instead of Rb in some of the patches.

Wei.

#15 lore raw
Quoted 12 lines · Wei Liu
Quoted 10 lines · Hongyan Xia

From: Hongyan Xia <[email protected]>

This small series is basically just rewriting functions using the new
API to map and unmap PTEs. Each patch is independent.

Apart from mapping and unmapping page tables, no other functional change
intended.

Quoted 5 lines

The code looks correct to me.

I do wonder if you should've put your SoB instead of Rb in some of the
patches.

I am not exactly sure what the policy is. For a couple of the patches, I did not touch anything but just cherry-picked from your tree, and what I did was just looking at the code and double checking, so I put an Rb there. Will change to SoB if this is not how we do things.

Hongyan

#16 lore raw
In reply to Hongyan Xia

Ping.

Quoted 22 lines · Hongyan Xia

From: Hongyan Xia <[email protected]>

This small series is basically just rewriting functions using the new API to map and unmap PTEs. Each patch is independent.

Apart from mapping and unmapping page tables, no other functional change
intended.

Wei Liu (5):
x86/shim: map and unmap page tables in replace_va_mapping x86_64/mm: map and unmap page tables in m2p_mapped x86_64/mm: map and unmap page tables in share_hotadd_m2p_table x86_64/mm: map and unmap page tables in destroy_compat_m2p_mapping x86_64/mm: map and unmap page tables in destroy_m2p_mapping

 xen/arch/x86/pv/shim.c     | 10 ++++---
 xen/arch/x86/x86_64/mm.c   | 55 +++++++++++++++++++++++++-----------
--
 xen/include/asm-x86/page.h | 18 +++++++++++++
 3 files changed, 62 insertions(+), 21 deletions(-)
#17 lore raw
Quoted 1 line · Hongyan Xia

Ping.

Does this somehow imply you didn't get my replies sent on the 1st?

Jan

Quoted 24 lines · Hongyan Xia
Quoted 22 lines

From: Hongyan Xia <[email protected]>

This small series is basically just rewriting functions using the new API to map and unmap PTEs. Each patch is independent.

Apart from mapping and unmapping page tables, no other functional change
intended.

Wei Liu (5):
x86/shim: map and unmap page tables in replace_va_mapping x86_64/mm: map and unmap page tables in m2p_mapped x86_64/mm: map and unmap page tables in share_hotadd_m2p_table x86_64/mm: map and unmap page tables in destroy_compat_m2p_mapping x86_64/mm: map and unmap page tables in destroy_m2p_mapping

 xen/arch/x86/pv/shim.c     | 10 ++++---
 xen/arch/x86/x86_64/mm.c   | 55 +++++++++++++++++++++++++-----------
--
 xen/include/asm-x86/page.h | 18 +++++++++++++
 3 files changed, 62 insertions(+), 21 deletions(-)
#18 lore raw
Quoted 6 lines · Jan Beulich
Quoted 1 line · Hongyan Xia

Ping.

Does this somehow imply you didn't get my replies sent on the 1st?

Jan

Apologies. Somehow your replies ended up in a separate thread. There is a problem with my email client.

Hongyan