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

Message ID 20230927112517.2631674-12-sebastianene@google.com
State New
Headers
Series arm64: ptdump: View the host stage-2 page-tables |

Commit Message

Sebastian Ene Sept. 27, 2023, 11:25 a.m. UTC
  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@google.com>
---
 arch/arm64/mm/ptdump.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Patch

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;