x86/kasan: Prepare clear_pgds() to switch to <asm-generic/pgtable-nop4d.h>
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Fri, 17 Mar 2017 18:55:13 +0000 (21:55 +0300)
committerIngo Molnar <mingo@kernel.org>
Mon, 27 Mar 2017 06:56:41 +0000 (08:56 +0200)
With folded p4d, pgd_clear() is a nop. Change clear_pgds() to use
p4d_clear() instead.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-arch@vger.kernel.org
Cc: linux-mm@kvack.org
Link: http://lkml.kernel.org/r/20170317185515.8636-5-kirill.shutemov@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/mm/kasan_init_64.c

index 8d63d7a104c3c445805dcf24a59fff2756a17b01..7b81f01067f2a9e6164728784848ee9f7068c3d0 100644 (file)
@@ -32,8 +32,19 @@ static int __init map_range(struct range *range)
 static void __init clear_pgds(unsigned long start,
                        unsigned long end)
 {
-       for (; start < end; start += PGDIR_SIZE)
-               pgd_clear(pgd_offset_k(start));
+       pgd_t *pgd;
+
+       for (; start < end; start += PGDIR_SIZE) {
+               pgd = pgd_offset_k(start);
+               /*
+                * With folded p4d, pgd_clear() is nop, use p4d_clear()
+                * instead.
+                */
+               if (CONFIG_PGTABLE_LEVELS < 5)
+                       p4d_clear(p4d_offset(pgd, start));
+               else
+                       pgd_clear(pgd);
+       }
 }
 
 static void __init kasan_map_early_shadow(pgd_t *pgd)