[PATCH 11/11] arm64: ptdump: Fix format output during stage-2 pagetable dumping

From: Sebastian Ene
Date: Wed Sep 27 2023 - 07:26:44 EST


Fix two issues where the printed address range from debugfs was not showing
out correctly when trying to read from
/sys/kernel/debug/host_stage2_kernel_page_tables entry.

The first issue was printing to debugfs the following:
0x0000010000000000-0x0000000000000000 16777215T PGD

If the st->start_address was larger than the current addr the delta
variable used to display the size of the address range was overflowing.
The second issue was printing the following wrong IPA range:
0x0000000000000000-0x0000000000000000 0E PGD

Validate the current address range before printing it from the debugfs
entry.

Signed-off-by: Sebastian Ene <sebastianene@xxxxxxxxxx>
---
arch/arm64/mm/ptdump.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
index 45ff4ebae01a..2c21ba9b47d1 100644
--- a/arch/arm64/mm/ptdump.c
+++ b/arch/arm64/mm/ptdump.c
@@ -430,6 +430,9 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
const char *unit = units;
unsigned long delta;

+ if (st->start_address >= addr)
+ goto update_state;
+
if (st->current_prot) {
note_prot_uxn(st, addr);
note_prot_wx(st, addr);
@@ -455,6 +458,7 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name);
}

+update_state:
st->start_address = addr;
st->current_prot = prot;
st->level = level;
--
2.42.0.515.g380fc7ccd1-goog