Skip to contentSkip to conversation

riscv: mm: Pre-allocate module page tables for execmem

PATCH Superseded Karl Mehltretter 3 participants 3 messages Oct 15

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: mm: Pre-allocate module page tables for execmem

RV64 pre-allocates page-table levels for late kernel mappings. The module range is guarded by CONFIG_MODULES, although execmem can use it without modules.

With CONFIG_BPF_JIT=y and CONFIG_MODULES=n, execmem adds a mapping to init_mm while the current process retains an empty PGD entry. Initializing a BPF program pack then faults:

  Unable to handle kernel paging request ...
  [ffffffff78000000] pgd=0000000000000000
  ...
  bpf_jit_fill_hole_with_zero
  bpf_prog_pack_alloc

Use CONFIG_EXECMEM for the module-range pre-allocation, as powerpc does for its execmem page-table setup. Both CONFIG_MODULES and CONFIG_BPF_JIT select it.

Fixes 2c9e5d4a0082 ("bpf: remove CONFIG_BPF_JIT dependency on CONFIG_MODULES of")
Assisted-by LLM

---

Notes:
Tested on a BeagleV Ahead with matched LLVM 18.1.3 builds based on v7.3-rc7:

- unpatched: a native XDP attach triggered the Oops above
- patched: native XDP attach and detach completed without an Oops

 arch/riscv/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/init.c +1 -1
index fb37b0b67efe..d92342c162e2 100644
@@ -1437,7 +1437,7 @@ static void __init preallocate_pgd_pages_range(unsigned long start, unsigned lon
 void __init pgtable_cache_init(void)
 {
 	preallocate_pgd_pages_range(VMALLOC_START, VMALLOC_END, "vmalloc");
-	if (IS_ENABLED(CONFIG_MODULES))
+	if (IS_ENABLED(CONFIG_EXECMEM))
 		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");
Signature · 1 line
2.43.0
Acked-by on v1 1/1
#1 lore raw
Quoted 14 lines · Karl Mehltretter

RV64 pre-allocates page-table levels for late kernel mappings. The module range is guarded by CONFIG_MODULES, although execmem can use it without modules.

With CONFIG_BPF_JIT=y and CONFIG_MODULES=n, execmem adds a mapping to init_mm while the current process retains an empty PGD entry. Initializing a BPF program pack then faults:

  Unable to handle kernel paging request ...
  [ffffffff78000000] pgd=0000000000000000
  ...
  bpf_jit_fill_hole_with_zero
  bpf_prog_pack_alloc
Quoted 3 lines

Use CONFIG_EXECMEM for the module-range pre-allocation, as powerpc does for its execmem page-table setup. Both CONFIG_MODULES and CONFIG_BPF_JIT select it.

I think the commit message should mention that BPF_JIT_REGION is inside MODULES region.

Quoted 4 lines
Fixes 2c9e5d4a0082 ("bpf: remove CONFIG_BPF_JIT dependency on CONFIG_MODULES of")
Assisted-by LLM
Quoted 28 lines

---

Notes:
Tested on a BeagleV Ahead with matched LLVM 18.1.3 builds based on v7.3-rc7:

- unpatched: a native XDP attach triggered the Oops above
- patched: native XDP attach and detach completed without an Oops

 arch/riscv/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/init.c +1 -1
index fb37b0b67efe..d92342c162e2 100644
@@ -1437,7 +1437,7 @@ static void __init preallocate_pgd_pages_range(unsigned long start, unsigned lon
 void __init pgtable_cache_init(void)
 {
 	preallocate_pgd_pages_range(VMALLOC_START, VMALLOC_END, "vmalloc");
-	if (IS_ENABLED(CONFIG_MODULES))
+	if (IS_ENABLED(CONFIG_EXECMEM))
 		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");
Signature · 1 line
2.43.0
Signature · 2 lines
Sincerely yours,
Mike.
Acked-by on v1 1/1
#2 lore raw
In reply to Karl Mehltretter
Quoted 14 lines · Karl Mehltretter

RV64 pre-allocates page-table levels for late kernel mappings. The module range is guarded by CONFIG_MODULES, although execmem can use it without modules.

With CONFIG_BPF_JIT=y and CONFIG_MODULES=n, execmem adds a mapping to init_mm while the current process retains an empty PGD entry. Initializing a BPF program pack then faults:

  Unable to handle kernel paging request ...
  [ffffffff78000000] pgd=0000000000000000
  ...
  bpf_jit_fill_hole_with_zero
  bpf_prog_pack_alloc
Quoted 8 lines

Use CONFIG_EXECMEM for the module-range pre-allocation, as powerpc does for its execmem page-table setup. Both CONFIG_MODULES and CONFIG_BPF_JIT select it.

Fixes 2c9e5d4a0082 ("bpf: remove CONFIG_BPF_JIT dependency on CONFIG_MODULES of")
Assisted-by LLM

TY!