Skip to content

Commit 6667309

Browse files
bjorn-rivospalmer-dabbelt
authored andcommitted
riscv: mm: Pre-allocate vmemmap/direct map/kasan PGD entries
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 <[email protected]> Signed-off-by: Björn Töpel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent e3ecf2f commit 6667309

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

arch/riscv/include/asm/kasan.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
#ifndef __ASSEMBLY__
88

9-
#ifdef CONFIG_KASAN
10-
119
/*
1210
* The following comment was copied from arm64:
1311
* KASAN_SHADOW_START: beginning of the kernel virtual addresses.
@@ -34,6 +32,8 @@
3432
*/
3533
#define KASAN_SHADOW_START ((KASAN_SHADOW_END - KASAN_SHADOW_SIZE) & PGDIR_MASK)
3634
#define KASAN_SHADOW_END MODULES_LOWEST_VADDR
35+
36+
#ifdef CONFIG_KASAN
3737
#define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL)
3838

3939
void kasan_init(void);

arch/riscv/mm/init.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include <asm/fixmap.h>
3030
#include <asm/io.h>
31+
#include <asm/kasan.h>
3132
#include <asm/numa.h>
3233
#include <asm/pgtable.h>
3334
#include <asm/sections.h>
@@ -1492,11 +1493,19 @@ static void __init preallocate_pgd_pages_range(unsigned long start, unsigned lon
14921493
panic("Failed to pre-allocate %s pages for %s area\n", lvl, area);
14931494
}
14941495

1496+
#define PAGE_END KASAN_SHADOW_START
1497+
14951498
void __init pgtable_cache_init(void)
14961499
{
14971500
preallocate_pgd_pages_range(VMALLOC_START, VMALLOC_END, "vmalloc");
14981501
if (IS_ENABLED(CONFIG_MODULES))
14991502
preallocate_pgd_pages_range(MODULES_VADDR, MODULES_END, "bpf/modules");
1503+
if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) {
1504+
preallocate_pgd_pages_range(VMEMMAP_START, VMEMMAP_END, "vmemmap");
1505+
preallocate_pgd_pages_range(PAGE_OFFSET, PAGE_END, "direct map");
1506+
if (IS_ENABLED(CONFIG_KASAN))
1507+
preallocate_pgd_pages_range(KASAN_SHADOW_START, KASAN_SHADOW_END, "kasan");
1508+
}
15001509
}
15011510
#endif
15021511

0 commit comments

Comments
 (0)