x86-64: fix 1:1 mapping init (hotplug case)
PATCH 1/1 x86-64: fix 1:1 mapping init (hotplug case)
While I don't have a hotplug capable system at hand, I think two issues need fixing:
- pud_phys (in kernel_physical_ampping_init()) would remain uninitialized in the after_bootmem case
- the locking done just around phys_pmd_{init,update}() would leave out pgd updates, and it was needlessly covering code portions that do allocations (perhaps using a more friendly gfp value in alloc_low_page() would then be possible)
--- arch/x86/mm/init_64.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-)
arch/x86/mm/init_64.c +18 -14
@@ -336,9 +336,12 @@ phys_pmd_init(pmd_t *pmd_page, unsigned }if (pmd_val (*pmd)) { -if (!pmd_large (*pmd)) +if (!pmd_large (*pmd)) { +spin_lock (&init_mm.page_table_lock); last_map_addr =phys_pte_update (pmd, address, - end); + end); +spin_unlock (&init_mm.page_table_lock); + }/* Count entries we're using from level2_ident_pgt */ if (start ==0 ) pages++;
@@ -347,8 +350,10 @@ phys_pmd_init(pmd_t *pmd_page, unsignedif (page_size_mask & (1 <<PG_LEVEL_2M )) { pages++; +spin_lock (&init_mm.page_table_lock);set_pte ((pte_t *)pmd,pfn_pte (address >>PAGE_SHIFT ,PAGE_KERNEL_LARGE )); +spin_unlock (&init_mm.page_table_lock); last_map_addr = (address &PMD_MASK ) +PMD_SIZE ;continue ; }
@@ -357,7 +362,9 @@ phys_pmd_init(pmd_t *pmd_page, unsigned last_map_addr =phys_pte_init (pte, address, end);unmap_low_page (pte); +spin_lock (&init_mm.page_table_lock);pmd_populate_kernel (&init_mm, pmd,__va (pte_phys)); +spin_unlock (&init_mm.page_table_lock); }update_page_count (PG_LEVEL_2M , pages);return last_map_addr;
@@ -370,9 +377,7 @@ phys_pmd_update(pud_t *pud, unsigned lonpmd_t *pmd =pmd_offset (pud,0 );unsigned long last_map_addr; -spin_lock (&init_mm.page_table_lock); last_map_addr =phys_pmd_init (pmd, address, end, page_size_mask); -spin_unlock (&init_mm.page_table_lock);__flush_tlb_all ();return last_map_addr; }
@@ -408,20 +413,21 @@ phys_pud_init(pud_t *pud_page, unsignedif (page_size_mask & (1 <<PG_LEVEL_1G )) { pages++; +spin_lock (&init_mm.page_table_lock);set_pte ((pte_t *)pud,pfn_pte (addr >>PAGE_SHIFT ,PAGE_KERNEL_LARGE )); +spin_unlock (&init_mm.page_table_lock); last_map_addr = (addr &PUD_MASK ) +PUD_SIZE ;continue ; } pmd =alloc_low_page (&pmd_phys); - -spin_lock (&init_mm.page_table_lock); last_map_addr =phys_pmd_init (pmd, addr, end, page_size_mask);unmap_low_page (pmd); + +spin_lock (&init_mm.page_table_lock);pud_populate (&init_mm, pud,__va (pmd_phys));spin_unlock (&init_mm.page_table_lock); - }__flush_tlb_all ();update_page_count (PG_LEVEL_1G , pages);
@@ -513,16 +519,14 @@ static unsigned long __init kernel_physicontinue ; } -if (after_bootmem) - pud =pud_offset (pgd, start &PGDIR_MASK ); -else - pud =alloc_low_page (&pud_phys); - + pud =alloc_low_page (&pud_phys); last_map_addr =phys_pud_init (pud,__pa (start),__pa (next), page_size_mask);unmap_low_page (pud); -pgd_populate (&init_mm,pgd_offset_k (start), -__va (pud_phys)); + +spin_lock (&init_mm.page_table_lock); +pgd_populate (&init_mm, pgd,__va (pud_phys)); +spin_unlock (&init_mm.page_table_lock); }return last_map_addr;
Ingo Molnar
AppliedQuoted 8 lines · Jan Beulich
While I don't have a hotplug capable system at hand, I think two issues need fixing:
-pud_phys(inkernel_physical_ampping_init()) would remain uninitialized in theafter_bootmemcase
- the locking done just around phys_pmd_{init,update}() would leave out pgd updates, and it was needlessly covering code portions that do allocations (perhaps using a more friendly gfp value inalloc_low_page()would then be possible)
applied to tip/x86/urgent. Some sort of memory hotplug simulation debug code would be nice ... [bonus points for making it run automatically during bootup, as part of the kernel init code]
it wouldnt even be all that expensive to test: we'd parts of RAM as to-be-hotplugged, we'd boot in and then hot-add those ranges. It's not full unrestricted RAM in the classic sense, but for most practical purposes it would be that.
Ingo