[PATCH v3 53/60] arm64: ptdump: Disregard unaddressable VA space

From: Ard Biesheuvel
Date: Tue Mar 07 2023 - 09:13:45 EST


Configurations built with support for 52-bit virtual addressing can also
run on CPUs that only support 48 bits of VA space, in which case only
that part of swapper_pg_dir that represents the 48-bit addressable
region is relevant, and everything else is ignored by the hardware.

Our software pagetable walker has little in the way of input address
validation, and so it will happily start a walk from an address that is
not representable by the number of paging levels that are actually
active, resulting in lots of bogus output from the page table dumper
unless we take care to start at a valid address.

Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
---
arch/arm64/mm/ptdump.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
index 8f37d6d8b5216473..8aee5d25f3d8cbe6 100644
--- a/arch/arm64/mm/ptdump.c
+++ b/arch/arm64/mm/ptdump.c
@@ -345,7 +345,7 @@ static void __init ptdump_initialize(void)
pg_level[i].mask |= pg_level[i].bits[j].mask;
}

-static struct ptdump_info kernel_ptdump_info = {
+static struct ptdump_info kernel_ptdump_info __ro_after_init = {
.mm = &init_mm,
.markers = address_markers,
.base_addr = PAGE_OFFSET,
@@ -364,7 +364,7 @@ void ptdump_check_wx(void)
.ptdump = {
.note_page = note_page,
.range = (struct ptdump_range[]) {
- {PAGE_OFFSET, ~0UL},
+ {_PAGE_OFFSET(vabits_actual), ~0UL},
{0, 0}
}
}
@@ -388,8 +388,9 @@ static int __init ptdump_init(void)
address_markers[VMALLOC_END_NR].start_address = VMALLOC_END;
ptdump_initialize();
if (vabits_actual < VA_BITS) {
+ kernel_ptdump_info.base_addr = _PAGE_OFFSET(vabits_actual);
address_markers[VMEMMAP_START_NR].start_address =
- (unsigned long)virt_to_page(_PAGE_OFFSET(vabits_actual));
+ (unsigned long)virt_to_page(kernel_ptdump_info.base_addr);
}
ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables");
return 0;
--
2.39.2