[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH RFC for-next] x86/mm: introduce and use virt_to_xen_l4e



Avoid open-coding in a lot of places.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
Is this patch useful or is open-coding preferred?
---
 xen/arch/x86/mm.c          | 14 +++++++-------
 xen/arch/x86/x86_64/mm.c   | 36 +++++++++++++++++-------------------
 xen/include/asm-x86/page.h |  5 +++++
 3 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index a20fdcaea4..cd70aba60c 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -363,7 +363,7 @@ void __init arch_init_memory(void)
                 if ( l3tab )
                 {
                     const l3_pgentry_t *l3idle =
-                        l4e_to_l3e(idle_pg_table[l4_table_offset(split_va)]);
+                        l4e_to_l3e(*virt_to_xen_l4e(split_va));
 
                     for ( i = 0; i < l3_table_offset(split_va); ++i )
                         l3tab[i] = l3idle[i];
@@ -1575,12 +1575,12 @@ void init_xen_l4_slots(l4_pgentry_t *l4t, mfn_t l4mfn,
 
     /* Slot 256: RO M2P (if applicable). */
     l4t[l4_table_offset(RO_MPT_VIRT_START)] =
-        ro_mpt ? idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)]
+        ro_mpt ? *virt_to_xen_l4e(RO_MPT_VIRT_START)
                : l4e_empty();
 
     /* Slot 257: PCI MMCFG. */
     l4t[l4_table_offset(PCI_MCFG_VIRT_START)] =
-        idle_pg_table[l4_table_offset(PCI_MCFG_VIRT_START)];
+        *virt_to_xen_l4e(PCI_MCFG_VIRT_START);
 
     /* Slot 258: Self linear mappings. */
     ASSERT(!mfn_eq(l4mfn, INVALID_MFN));
@@ -1609,7 +1609,7 @@ void init_xen_l4_slots(l4_pgentry_t *l4t, mfn_t l4mfn,
         l4_pgentry_t *next;
 
         memcpy(&l4t[l4_table_offset(XEN_VIRT_START)],
-               &idle_pg_table[l4_table_offset(XEN_VIRT_START)],
+               virt_to_xen_l4e(XEN_VIRT_START),
                (ROOT_PAGETABLE_FIRST_XEN_SLOT + root_pgt_pv_xen_slots -
                 l4_table_offset(XEN_VIRT_START)) * sizeof(*l4t));
 
@@ -1629,7 +1629,7 @@ void init_xen_l4_slots(l4_pgentry_t *l4t, mfn_t l4mfn,
                               : ROOT_PAGETABLE_XEN_SLOTS);
 
         memcpy(&l4t[l4_table_offset(XEN_VIRT_START)],
-               &idle_pg_table[l4_table_offset(XEN_VIRT_START)],
+               virt_to_xen_l4e(XEN_VIRT_START),
                (ROOT_PAGETABLE_FIRST_XEN_SLOT + slots -
                 l4_table_offset(XEN_VIRT_START)) * sizeof(*l4t));
     }
@@ -1643,7 +1643,7 @@ bool fill_ro_mpt(mfn_t mfn)
     if ( !l4e_get_intpte(l4tab[l4_table_offset(RO_MPT_VIRT_START)]) )
     {
         l4tab[l4_table_offset(RO_MPT_VIRT_START)] =
-            idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)];
+            *virt_to_xen_l4e(RO_MPT_VIRT_START);
         ret = true;
     }
     unmap_domain_page(l4tab);
@@ -4476,7 +4476,7 @@ static l3_pgentry_t *virt_to_xen_l3e(unsigned long v)
 {
     l4_pgentry_t *pl4e;
 
-    pl4e = &idle_pg_table[l4_table_offset(v)];
+    pl4e = virt_to_xen_l4e(v);
     if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) )
     {
         bool locking = system_state > SYS_STATE_boot;
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 34cd8457cf..87edfe0a7e 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -133,7 +133,7 @@ static int m2p_mapped(unsigned long spfn)
     l2_pgentry_t *l2_ro_mpt;
 
     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 = l4e_to_l3e(*virt_to_xen_l4e(va));
 
     switch ( l3e_get_flags(l3_ro_mpt[l3_table_offset(va)]) &
              (_PAGE_PRESENT |_PAGE_PSE))
@@ -166,7 +166,7 @@ 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)])[
+        l3e = l4e_to_l3e(*virt_to_xen_l4e(v))[
             l3_table_offset(v)];
         if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) )
             continue;
@@ -193,7 +193,7 @@ 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)])[
+        l3e = l4e_to_l3e(*virt_to_xen_l4e(v))[
             l3_table_offset(v)];
         if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) )
             continue;
@@ -226,7 +226,7 @@ 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 = l4e_to_l3e(*virt_to_xen_l4e(HIRO_COMPAT_MPT_VIRT_START));
 
     
ASSERT(l3e_get_flags(l3_ro_mpt[l3_table_offset(HIRO_COMPAT_MPT_VIRT_START)]) & 
_PAGE_PRESENT);
 
@@ -261,7 +261,7 @@ 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 = l4e_to_l3e(*virt_to_xen_l4e(RO_MPT_VIRT_START));
 
     /*
      * No need to clean m2p structure existing before the hotplug
@@ -340,7 +340,7 @@ static int setup_compat_m2p_table(struct mem_hotadd_info 
*info)
 
     va = HIRO_COMPAT_MPT_VIRT_START +
          smap * sizeof(*compat_machine_to_phys_mapping);
-    l3_ro_mpt = l4e_to_l3e(idle_pg_table[l4_table_offset(va)]);
+    l3_ro_mpt = l4e_to_l3e(*virt_to_xen_l4e(va));
 
     ASSERT(l3e_get_flags(l3_ro_mpt[l3_table_offset(va)]) & _PAGE_PRESENT);
 
@@ -397,9 +397,9 @@ static int setup_m2p_table(struct mem_hotadd_info *info)
     l3_pgentry_t *l3_ro_mpt = NULL;
     int ret = 0;
 
-    ASSERT(l4e_get_flags(idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)])
+    ASSERT(l4e_get_flags(*virt_to_xen_l4e(RO_MPT_VIRT_START))
             & _PAGE_PRESENT);
-    l3_ro_mpt = l4e_to_l3e(idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)]);
+    l3_ro_mpt = l4e_to_l3e(*virt_to_xen_l4e(RO_MPT_VIRT_START));
 
     smap = (info->spfn & (~((1UL << (L2_PAGETABLE_SHIFT - 3)) -1)));
     emap = ((info->epfn + ((1UL << (L2_PAGETABLE_SHIFT - 3)) - 1 )) &
@@ -504,15 +504,14 @@ void __init paging_init(void)
           va < DIRECTMAP_VIRT_END && (void *)va < __va(mem_hotplug);
           va += (1UL << L4_PAGETABLE_SHIFT) )
     {
-        if ( !(l4e_get_flags(idle_pg_table[l4_table_offset(va)]) &
-              _PAGE_PRESENT) )
+        if ( !(l4e_get_flags(*virt_to_xen_l4e(va)) & _PAGE_PRESENT) )
         {
             l3_pgentry_t *pl3t = alloc_xen_pagetable();
 
             if ( !pl3t )
                 goto nomem;
             clear_page(pl3t);
-            l4e_write(&idle_pg_table[l4_table_offset(va)],
+            l4e_write(virt_to_xen_l4e(va),
                       l4e_from_paddr(__pa(pl3t), __PAGE_HYPERVISOR_RW));
         }
     }
@@ -521,7 +520,7 @@ void __init paging_init(void)
     if ( (l3_ro_mpt = alloc_xen_pagetable()) == NULL )
         goto nomem;
     clear_page(l3_ro_mpt);
-    l4e_write(&idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)],
+    l4e_write(virt_to_xen_l4e(RO_MPT_VIRT_START),
               l4e_from_paddr(__pa(l3_ro_mpt), __PAGE_HYPERVISOR_RO | 
_PAGE_USER));
 
     /*
@@ -624,8 +623,7 @@ void __init paging_init(void)
     /* Create user-accessible L2 directory to map the MPT for compat guests. */
     BUILD_BUG_ON(l4_table_offset(RDWR_MPT_VIRT_START) !=
                  l4_table_offset(HIRO_COMPAT_MPT_VIRT_START));
-    l3_ro_mpt = l4e_to_l3e(idle_pg_table[l4_table_offset(
-        HIRO_COMPAT_MPT_VIRT_START)]);
+    l3_ro_mpt = l4e_to_l3e(*virt_to_xen_l4e(HIRO_COMPAT_MPT_VIRT_START));
     if ( (l2_ro_mpt = alloc_xen_pagetable()) == NULL )
         goto nomem;
     compat_idle_pg_table_l2 = l2_ro_mpt;
@@ -675,7 +673,7 @@ void __init paging_init(void)
     machine_to_phys_mapping_valid = 1;
 
     /* Set up linear page table mapping. */
-    l4e_write(&idle_pg_table[l4_table_offset(LINEAR_PT_VIRT_START)],
+    l4e_write(virt_to_xen_l4e(LINEAR_PT_VIRT_START),
               l4e_from_paddr(__pa(idle_pg_table), __PAGE_HYPERVISOR_RW));
     return;
 
@@ -729,7 +727,7 @@ static void cleanup_frame_table(struct mem_hotadd_info 
*info)
 
     while (sva < eva)
     {
-        l3e = l4e_to_l3e(idle_pg_table[l4_table_offset(sva)])[
+        l3e = l4e_to_l3e(*virt_to_xen_l4e(sva))[
           l3_table_offset(sva)];
         if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) ||
              (l3e_get_flags(l3e) & _PAGE_PSE) )
@@ -843,7 +841,7 @@ void __init subarch_init_memory(void)
           v += n << PAGE_SHIFT )
     {
         n = L2_PAGETABLE_ENTRIES * L1_PAGETABLE_ENTRIES;
-        l3e = l4e_to_l3e(idle_pg_table[l4_table_offset(v)])[
+        l3e = l4e_to_l3e(*virt_to_xen_l4e(v))[
             l3_table_offset(v)];
         if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) )
             continue;
@@ -871,7 +869,7 @@ void __init subarch_init_memory(void)
           v != RDWR_COMPAT_MPT_VIRT_END;
           v += 1 << L2_PAGETABLE_SHIFT )
     {
-        l3e = l4e_to_l3e(idle_pg_table[l4_table_offset(v)])[
+        l3e = l4e_to_l3e(*virt_to_xen_l4e(v))[
             l3_table_offset(v)];
         if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) )
             continue;
@@ -927,7 +925,7 @@ long subarch_memory_op(unsigned long cmd, 
XEN_GUEST_HANDLE_PARAM(void) arg)
               (v < (unsigned long)(machine_to_phys_mapping + max_page));
               i++, v += 1UL << L2_PAGETABLE_SHIFT )
         {
-            l3e = l4e_to_l3e(idle_pg_table[l4_table_offset(v)])[
+            l3e = l4e_to_l3e(*virt_to_xen_l4e(v))[
                 l3_table_offset(v)];
             if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) )
                 mfn = last_mfn;
diff --git a/xen/include/asm-x86/page.h b/xen/include/asm-x86/page.h
index 45ca742678..0a663b298d 100644
--- a/xen/include/asm-x86/page.h
+++ b/xen/include/asm-x86/page.h
@@ -299,6 +299,11 @@ extern l2_pgentry_t l2_identmap[4*L2_PAGETABLE_ENTRIES];
 extern l1_pgentry_t l1_fixmap[L1_PAGETABLE_ENTRIES];
 void paging_init(void);
 void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t);
+
+static inline l4_pgentry_t *virt_to_xen_l4e(unsigned long va)
+{
+    return &idle_pg_table[l4_table_offset(va)];
+}
 #endif /* !defined(__ASSEMBLY__) */
 
 #define _PAGE_NONE     _AC(0x000,U)
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.