From: Ard Biesheuvel <ardb+git@google.com>
To: linux-kernel@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel <ardb@kernel.org>
Subject: [RFC PATCH v2 3/4] arm64: mm: Create r/o page table region that permits updates
Date: Thu, 27 Aug 2026 18:44:13 +0200 [thread overview]
Message-ID: <20260827164409.3421848-9-ardb+git@google.com> (raw)
In-Reply-To: <20260827164409.3421848-6-ardb+git@google.com>
From: Ard Biesheuvel <ardb@kernel.org>
Generalize the handling of swapper_pg_dir, and apply the fixmap fallback
for page table updates to all page tables in the .rodata..pgtbl section.
Currently, this holds only swapper_pg_dir, but this will be expanded in
subsequent patches.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/arm64/include/asm/pgtable.h | 6 -----
arch/arm64/kernel/vmlinux.lds.S | 6 +++++
arch/arm64/mm/mmu.c | 26 +++++++++++++++++---
3 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 799cd9d52c28..de0a07dae83a 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -817,12 +817,6 @@ extern pgd_t reserved_pg_dir[];
void try_set_readonly_ptval(ptval_t *ptvalp, ptval_t ptval);
-static inline bool in_swapper_pgdir(void *addr)
-{
- return ((unsigned long)addr & PAGE_MASK) ==
- ((unsigned long)swapper_pg_dir & PAGE_MASK);
-}
-
static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
{
__put_kernel_nofault(pmdp, &pmd, pmd_t, fault);
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index af1d72020976..2cda0b7c41d4 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -243,9 +243,15 @@ SECTIONS
reserved_pg_dir = .;
. += PAGE_SIZE;
+ __rodata_pgtbl_start = .;
swapper_pg_dir = .;
. += PAGE_SIZE;
+ .pgtbl.ro_after_init : ALIGN(PAGE_SIZE) {
+ *(.pgtbl.ro_after_init)
+ }
+ __rodata_pgtbl_end = .;
+
. = ALIGN(SEGMENT_ALIGN);
__init_begin = .;
__inittext_begin = .;
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index b97e4bf99ca5..dad482d66f17 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -65,17 +65,27 @@ long __section(".mmuoff.data.write") __early_cpu_boot_status;
static DEFINE_MUTEX(fixmap_lock);
+static struct range kimg_ropgtbl_range __ro_after_init;
+
void noinstr try_set_readonly_ptval(ptval_t *ptvalp, ptval_t ptval)
{
static DEFINE_SPINLOCK(lock);
+ bool is_lm = __is_lm_address(ptvalp);
+ u64 pa = is_lm ? __pa(ptvalp) : __pa_symbol(ptvalp);
- BUG_ON(!in_swapper_pgdir(ptvalp));
+ if (!range_contains(&kimg_ropgtbl_range,
+ &DEFINE_RANGE(pa, pa + sizeof(ptval_t))))
+ BUG();
/*
- * Don't bother with the fixmap if swapper_pg_dir is still mapped
+ * Don't bother with the fixmap if .rodata is still mapped
* writable in the kernel mapping.
*/
if (rodata_is_rw) {
+ /* no fault should have occurred for a kimg address */
+ BUG_ON(!is_lm);
+
+ ptvalp = (ptval_t *)__phys_to_kimg(pa);
WRITE_ONCE(*ptvalp, ptval);
dsb(ishst);
isb();
@@ -83,7 +93,7 @@ void noinstr try_set_readonly_ptval(ptval_t *ptvalp, ptval_t ptval)
}
guard(spinlock)(&lock);
- ptvalp = (ptval_t *)set_fixmap_offset(FIX_PTVAL, __pa_symbol(ptvalp));
+ ptvalp = (ptval_t *)set_fixmap_offset(FIX_PTVAL, pa);
WRITE_ONCE(*ptvalp, ptval);
/*
* We need dsb(ishst) here to ensure the page-table-walker sees
@@ -1177,6 +1187,14 @@ static inline void arm64_kfence_map_pool(void) { }
#endif /* CONFIG_KFENCE */
+static void __init record_ropgtbl_phys_range(void)
+{
+ extern const char __rodata_pgtbl_start[], __rodata_pgtbl_end[];
+
+ kimg_ropgtbl_range = DEFINE_RANGE(__pa_symbol(__rodata_pgtbl_start),
+ __pa_symbol(__rodata_pgtbl_end));
+}
+
static void __init map_mem(void)
{
static const u64 direct_map_end = _PAGE_END(VA_BITS_MIN);
@@ -1189,6 +1207,8 @@ static void __init map_mem(void)
int flags = NO_EXEC_MAPPINGS;
u64 i;
+ record_ropgtbl_phys_range();
+
/*
* Setting hierarchical PXNTable attributes on table entries covering
* the linear region is only possible if it is guaranteed that no table
--
2.55.0.887.g758fc8c411-goog
next prev parent reply other threads:[~2026-08-27 16:44 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 16:44 [RFC PATCH v2 0/4] arm64: mm: Map fixmap page tables read-only Ard Biesheuvel
2026-08-27 16:44 ` [RFC PATCH v2 1/4] arm64: mm: Map fixmap PTE tables r/o in the linear map Ard Biesheuvel
2026-09-01 9:12 ` Kevin Brodsky
2026-08-27 16:44 ` [RFC PATCH v2 2/4] arm64: mm: Use fault handler to permit swapper_pg_dir updates Ard Biesheuvel
2026-09-01 9:12 ` Kevin Brodsky
2026-08-27 16:44 ` Ard Biesheuvel [this message]
2026-08-27 16:44 ` [RFC PATCH v2 4/4] arm64: mm: Move fixmap intermediate page tables into .rodata Ard Biesheuvel
2026-09-01 9:12 ` Kevin Brodsky
2026-09-01 9:21 ` [RFC PATCH v2 0/4] arm64: mm: Map fixmap page tables read-only Kevin Brodsky
2026-09-01 15:27 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260827164409.3421848-9-ardb+git@google.com \
--to=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®