diff mbox

x86: correct boot time page table setup

Message ID 590C9644020000780015730C@prv-mh.provo.novell.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Beulich May 5, 2017, 1:12 p.m. UTC
While using alloc_domheap_pages() and assuming the allocated memory is
directly accessible is okay at boot time (as we run on the idle page
tables there), memory hotplug code too assumes it can access the
resulting page tables without using map_domain_page() or alike, and
hence we need to obtain memory suitable for ordinary page table use
here.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
x86: correct boot time page table setup

While using alloc_domheap_pages() and assuming the allocated memory is
directly accessible is okay at boot time (as we run on the idle page
tables there), memory hotplug code too assumes it can access the
resulting page tables without using map_domain_page() or alike, and
hence we need to obtain memory suitable for ordinary page table use
here.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -496,7 +496,7 @@ void __init paging_init(void)
     unsigned int n, memflags;
     l3_pgentry_t *l3_ro_mpt;
     l2_pgentry_t *l2_ro_mpt = NULL;
-    struct page_info *l1_pg, *l2_pg, *l3_pg;
+    struct page_info *l1_pg;
 
     /*
      * We setup the L3s for 1:1 mapping if host support memory hotplug
@@ -509,23 +509,22 @@ void __init paging_init(void)
         if ( !(l4e_get_flags(idle_pg_table[l4_table_offset(va)]) &
               _PAGE_PRESENT) )
         {
-            l3_pg = alloc_domheap_page(NULL, 0);
-            if ( !l3_pg )
+            l3_pgentry_t *pl3t = alloc_xen_pagetable();
+
+            if ( !pl3t )
                 goto nomem;
-            l3_ro_mpt = page_to_virt(l3_pg);
-            clear_page(l3_ro_mpt);
+            clear_page(pl3t);
             l4e_write(&idle_pg_table[l4_table_offset(va)],
-                      l4e_from_page(l3_pg, __PAGE_HYPERVISOR_RW));
+                      l4e_from_paddr(__pa(pl3t), __PAGE_HYPERVISOR_RW));
         }
     }
 
     /* Create user-accessible L2 directory to map the MPT for guests. */
-    if ( (l3_pg = alloc_domheap_page(NULL, 0)) == NULL )
+    if ( (l3_ro_mpt = alloc_xen_pagetable()) == NULL )
         goto nomem;
-    l3_ro_mpt = page_to_virt(l3_pg);
     clear_page(l3_ro_mpt);
     l4e_write(&idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)],
-              l4e_from_page(l3_pg, __PAGE_HYPERVISOR_RO | _PAGE_USER));
+              l4e_from_paddr(__pa(l3_ro_mpt), __PAGE_HYPERVISOR_RO | _PAGE_USER));
 
     /*
      * Allocate and map the machine-to-phys table.
@@ -607,12 +606,12 @@ void __init paging_init(void)
         }
         if ( !((unsigned long)l2_ro_mpt & ~PAGE_MASK) )
         {
-            if ( (l2_pg = alloc_domheap_page(NULL, memflags)) == NULL )
+            if ( (l2_ro_mpt = alloc_xen_pagetable()) == NULL )
                 goto nomem;
-            l2_ro_mpt = page_to_virt(l2_pg);
             clear_page(l2_ro_mpt);
             l3e_write(&l3_ro_mpt[l3_table_offset(va)],
-                      l3e_from_page(l2_pg, __PAGE_HYPERVISOR_RO | _PAGE_USER));
+                      l3e_from_paddr(__pa(l2_ro_mpt),
+                                     __PAGE_HYPERVISOR_RO | _PAGE_USER));
             ASSERT(!l2_table_offset(va));
         }
         /* NB. Cannot be GLOBAL: guest user mode should not see it. */

Comments

Andrew Cooper May 5, 2017, 3:08 p.m. UTC | #1
On 05/05/17 14:12, Jan Beulich wrote:
> While using alloc_domheap_pages() and assuming the allocated memory is
> directly accessible is okay at boot time (as we run on the idle page
> tables there), memory hotplug code too assumes it can access the
> resulting page tables without using map_domain_page() or alike, and
> hence we need to obtain memory suitable for ordinary page table use
> here.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Julien Grall May 8, 2017, 12:16 p.m. UTC | #2
Hi,

On 05/05/17 16:08, Andrew Cooper wrote:
> On 05/05/17 14:12, Jan Beulich wrote:
>> While using alloc_domheap_pages() and assuming the allocated memory is
>> directly accessible is okay at boot time (as we run on the idle page
>> tables there), memory hotplug code too assumes it can access the
>> resulting page tables without using map_domain_page() or alike, and
>> hence we need to obtain memory suitable for ordinary page table use
>> here.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>
> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

Release-acked-by: Julien Grall <julien.grall@arm.com>

Cheers,
diff mbox

Patch

--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -496,7 +496,7 @@  void __init paging_init(void)
     unsigned int n, memflags;
     l3_pgentry_t *l3_ro_mpt;
     l2_pgentry_t *l2_ro_mpt = NULL;
-    struct page_info *l1_pg, *l2_pg, *l3_pg;
+    struct page_info *l1_pg;
 
     /*
      * We setup the L3s for 1:1 mapping if host support memory hotplug
@@ -509,23 +509,22 @@  void __init paging_init(void)
         if ( !(l4e_get_flags(idle_pg_table[l4_table_offset(va)]) &
               _PAGE_PRESENT) )
         {
-            l3_pg = alloc_domheap_page(NULL, 0);
-            if ( !l3_pg )
+            l3_pgentry_t *pl3t = alloc_xen_pagetable();
+
+            if ( !pl3t )
                 goto nomem;
-            l3_ro_mpt = page_to_virt(l3_pg);
-            clear_page(l3_ro_mpt);
+            clear_page(pl3t);
             l4e_write(&idle_pg_table[l4_table_offset(va)],
-                      l4e_from_page(l3_pg, __PAGE_HYPERVISOR_RW));
+                      l4e_from_paddr(__pa(pl3t), __PAGE_HYPERVISOR_RW));
         }
     }
 
     /* Create user-accessible L2 directory to map the MPT for guests. */
-    if ( (l3_pg = alloc_domheap_page(NULL, 0)) == NULL )
+    if ( (l3_ro_mpt = alloc_xen_pagetable()) == NULL )
         goto nomem;
-    l3_ro_mpt = page_to_virt(l3_pg);
     clear_page(l3_ro_mpt);
     l4e_write(&idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)],
-              l4e_from_page(l3_pg, __PAGE_HYPERVISOR_RO | _PAGE_USER));
+              l4e_from_paddr(__pa(l3_ro_mpt), __PAGE_HYPERVISOR_RO | _PAGE_USER));
 
     /*
      * Allocate and map the machine-to-phys table.
@@ -607,12 +606,12 @@  void __init paging_init(void)
         }
         if ( !((unsigned long)l2_ro_mpt & ~PAGE_MASK) )
         {
-            if ( (l2_pg = alloc_domheap_page(NULL, memflags)) == NULL )
+            if ( (l2_ro_mpt = alloc_xen_pagetable()) == NULL )
                 goto nomem;
-            l2_ro_mpt = page_to_virt(l2_pg);
             clear_page(l2_ro_mpt);
             l3e_write(&l3_ro_mpt[l3_table_offset(va)],
-                      l3e_from_page(l2_pg, __PAGE_HYPERVISOR_RO | _PAGE_USER));
+                      l3e_from_paddr(__pa(l2_ro_mpt),
+                                     __PAGE_HYPERVISOR_RO | _PAGE_USER));
             ASSERT(!l2_table_offset(va));
         }
         /* NB. Cannot be GLOBAL: guest user mode should not see it. */