[PATCH] [5/8] Fix logic error in 64bit memory hotadd

Andi Kleen
2008-02-11T09:36:24Z

The memory hotadd code assumes that the pud always exists already, but
that might be not true. Allocate it if it isn't there.

Signed-off-by: Andi Kleen <ak@suse.de>

---
arch/x86/mm/init_64.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

Index: linux/arch/x86/mm/init_64.c
===================================================================
--- linux.orig/arch/x86/mm/init_64.c
+++ linux/arch/x86/mm/init_64.c
@@ -432,17 +432,22 @@ void __init_refok init_memory_mapping(un
unsigned long pud_phys;
pud_t *pud;

- if (after_bootmem)
+ if (after_bootmem) {
pud = pud_offset(pgd, start & PGDIR_MASK);
- else
+ if (!pud_present(*pud)) {
+ pud = (pud_t *)get_zeroed_page(GFP_ATOMIC);
+ if (!pud)
+ panic("Out of memory");
+ }
+ pud_phys = __pa(pud);
+ } else
pud = alloc_low_page(&pud_phys);

next = start + PGDIR_SIZE;
if (next > end)
next = end;
phys_pud_init(pud, __pa(start), __pa(next));
- if (!after_bootmem)
- set_pgd(pgd_offset_k(start), mk_kernel_pgd(pud_phys));
+ set_pgd(pgd_offset_k(start), mk_kernel_pgd(pud_phys));
unmap_low_page(pud);
}