diff options
| author | Nickolai Zeldovich <nickolai@csail.mit.edu> | 2026-10-17 22:36:49 -0400 |
|---|---|---|
| committer | Paul Walmsley <pjw@kernel.org> | 2026-11-05 19:36:19 -0700 |
| commit | 551bdd6fcaba4ffc98fd95c4d969d4470eae580f (patch) | |
| tree | 7015d80be8845150e0fe5fb350075a8f6e945e81 /tools/perf/scripts/python | |
| parent | e0167a473b3e0f6388bcbf13ce2afcafe1b44b0c (diff) | |
riscv: mm: Define PAGE_KERNEL_RO
Kernel mappings that generic code creates read-only are writable on
riscv. With HugeTLB vmemmap optimization (selected by riscv and on by
default with CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON), the tail
vmemmap pages of every optimized huge page are remapped to one shared
page with PAGE_KERNEL_RO so that a stray write to a tail struct page
faults. On riscv that remap keeps _PAGE_WRITE, so such a write silently
changes the struct pages of every optimized huge page instead.
early_memremap_ro() (EFI system and configuration tables), the
firmware loader's vmap() of the loaded image, and acpi_os_ioremap() for
EFI runtime code and NOMAP regions, which asks for a read-only mapping
precisely to avoid a writable mapping of executable code, are affected
the same way.
riscv defines PAGE_KERNEL_READ but not PAGE_KERNEL_RO, so
include/linux/pgtable.h falls back to "#define PAGE_KERNEL_RO
PAGE_KERNEL". Define PAGE_KERNEL_RO as PAGE_KERNEL_READ. FIXMAP_PAGE_RO
then follows from asm-generic/fixmap.h: early_memremap_ro() now passes
0xe3 instead of 0xe7 to __early_ioremap().
Tested on QEMU virt (riscv64, defconfig with
CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON and CONFIG_PTDUMP_DEBUGFS,
booted with hugepages=8): before, every vmemmap entry in
/sys/kernel/debug/kernel_page_tables has W set; after, the 28K of tail
vmemmap of each huge page is mapped R without W.
Fixes: a3c7d6b642e4 ("riscv: mm: hugetlb: Enable ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP")
Assisted-by: LLM
Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
Acked-by: Muchun Song <muchun.song@linux.dev>
Reviewed-by: Jisheng Zhang <jszhang@kernel.org>
Link: https://patch.msgid.link/20261018023649.798595-1-nickolai@csail.mit.edu
Signed-off-by: Paul Walmsley <pjw@kernel.org>
Diffstat (limited to 'tools/perf/scripts/python')
0 files changed, 0 insertions, 0 deletions
