x86/mm/vmalloc: Add 5-level paging support
authorKirill A. Shutemov <[email protected]>
Mon, 13 Mar 2017 14:33:08 +0000 (17:33 +0300)
committerIngo Molnar <[email protected]>
Tue, 14 Mar 2017 07:45:08 +0000 (08:45 +0100)
Modify vmalloc_fault() to handle additional page table level.

With 4-level paging, copying happens on p4d level, as we have pgd_none()
always false if p4d_t is folded.

Signed-off-by: Kirill A. Shutemov <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Denys Vlasenko <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Josh Poimboeuf <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: [email protected]
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
arch/x86/mm/fault.c

index 605fd5e8e048d012a7ea507a5baff83f5bf96350..8ad91a01cbc88ff9e53d79ef9a2fd299b8558995 100644 (file)
@@ -435,6 +435,7 @@ void vmalloc_sync_all(void)
 static noinline int vmalloc_fault(unsigned long address)
 {
        pgd_t *pgd, *pgd_ref;
+       p4d_t *p4d, *p4d_ref;
        pud_t *pud, *pud_ref;
        pmd_t *pmd, *pmd_ref;
        pte_t *pte, *pte_ref;
@@ -458,17 +459,37 @@ static noinline int vmalloc_fault(unsigned long address)
        if (pgd_none(*pgd)) {
                set_pgd(pgd, *pgd_ref);
                arch_flush_lazy_mmu_mode();
-       } else {
+       } else if (CONFIG_PGTABLE_LEVELS > 4) {
+               /*
+                * With folded p4d, pgd_none() is always false, so the pgd may
+                * point to an empty page table entry and pgd_page_vaddr()
+                * will return garbage.
+                *
+                * We will do the correct sanity check on the p4d level.
+                */
                BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
        }
 
+       /* With 4-level paging, copying happens on the p4d level. */
+       p4d = p4d_offset(pgd, address);
+       p4d_ref = p4d_offset(pgd_ref, address);
+       if (p4d_none(*p4d_ref))
+               return -1;
+
+       if (p4d_none(*p4d)) {
+               set_p4d(p4d, *p4d_ref);
+               arch_flush_lazy_mmu_mode();
+       } else {
+               BUG_ON(p4d_pfn(*p4d) != p4d_pfn(*p4d_ref));
+       }
+
        /*
         * Below here mismatches are bugs because these lower tables
         * are shared:
         */
 
-       pud = pud_offset(pgd, address);
-       pud_ref = pud_offset(pgd_ref, address);
+       pud = pud_offset(p4d, address);
+       pud_ref = pud_offset(p4d_ref, address);
        if (pud_none(*pud_ref))
                return -1;