]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
riscv: mm: Pre-allocate vmemmap/direct map/kasan PGD entries
authorBjörn Töpel <bjorn@rivosinc.com>
Wed, 5 Jun 2024 11:40:45 +0000 (13:40 +0200)
committerPalmer Dabbelt <palmer@rivosinc.com>
Wed, 26 Jun 2024 15:42:39 +0000 (08:42 -0700)
The RISC-V port copies the PGD table from init_mm/swapper_pg_dir to
all userland page tables, which means that if the PGD level table is
changed, other page tables has to be updated as well.

Instead of having the PGD changes ripple out to all tables, the
synchronization can be avoided by pre-allocating the PGD entries/pages
at boot, avoiding the synchronization all together.

This is currently done for the bpf/modules, and vmalloc PGD regions.
Extend this scheme for the PGD regions touched by memory hotplugging.

Prepare the RISC-V port for memory hotplug by pre-allocate
vmemmap/direct map/kasan entries at the PGD level. This will roughly
waste ~128 (plus 32 if KASAN is enabled) worth of 4K pages when memory
hotplugging is enabled in the kernel configuration.

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
Link: https://lore.kernel.org/r/20240605114100.315918-3-bjorn@kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/include/asm/kasan.h
arch/riscv/mm/init.c

index 0b85e363e778c9fb15fd4f1052049f54b4b1a4e4..e6a0071bdb56c4105d37f4e41ad912429e81ba58 100644 (file)
@@ -6,8 +6,6 @@
 
 #ifndef __ASSEMBLY__
 
-#ifdef CONFIG_KASAN
-
 /*
  * The following comment was copied from arm64:
  * KASAN_SHADOW_START: beginning of the kernel virtual addresses.
@@ -34,6 +32,8 @@
  */
 #define KASAN_SHADOW_START     ((KASAN_SHADOW_END - KASAN_SHADOW_SIZE) & PGDIR_MASK)
 #define KASAN_SHADOW_END       MODULES_LOWEST_VADDR
+
+#ifdef CONFIG_KASAN
 #define KASAN_SHADOW_OFFSET    _AC(CONFIG_KASAN_SHADOW_OFFSET, UL)
 
 void kasan_init(void);
index ecd4e716c9953bfe7dc582ccc6c86ea7e0043a72..85f076b80a12d52887598094858a07ca66715562 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <asm/fixmap.h>
 #include <asm/io.h>
+#include <asm/kasan.h>
 #include <asm/numa.h>
 #include <asm/pgtable.h>
 #include <asm/sections.h>
@@ -1492,11 +1493,19 @@ failed:
        panic("Failed to pre-allocate %s pages for %s area\n", lvl, area);
 }
 
+#define PAGE_END KASAN_SHADOW_START
+
 void __init pgtable_cache_init(void)
 {
        preallocate_pgd_pages_range(VMALLOC_START, VMALLOC_END, "vmalloc");
        if (IS_ENABLED(CONFIG_MODULES))
                preallocate_pgd_pages_range(MODULES_VADDR, MODULES_END, "bpf/modules");
+       if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) {
+               preallocate_pgd_pages_range(VMEMMAP_START, VMEMMAP_END, "vmemmap");
+               preallocate_pgd_pages_range(PAGE_OFFSET, PAGE_END, "direct map");
+               if (IS_ENABLED(CONFIG_KASAN))
+                       preallocate_pgd_pages_range(KASAN_SHADOW_START, KASAN_SHADOW_END, "kasan");
+       }
 }
 #endif