From 99db3f57397b5fdcc1bf062d3f9939391cb755c9 Mon Sep 17 00:00:00 2001 From: Johannes Wikner Date: Thu, 30 Nov 2023 18:21:11 +0100 Subject: [PATCH] dump_pagetables: Avoid incorrect BUG_ON condition. The recursion should stop at level 0, since at this level table is not a page table anymore. This would otherwise trigger a panic when dumping page tables. Signed-off-by: Johannes Wikner --- arch/x86/pagetables.c | 3 +++ tests/unittests.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/arch/x86/pagetables.c b/arch/x86/pagetables.c index 1a83d98a..e095146f 100644 --- a/arch/x86/pagetables.c +++ b/arch/x86/pagetables.c @@ -101,6 +101,9 @@ static inline bool is_canon_va(const void *va) { static void dump_pagetable(mfn_t table, int level) { pte_t *pt; + if (level == 0) + return; + BUG_ON(mfn_invalid(table)); pt = tmp_map_mfn(table); BUG_ON(!pt); diff --git a/tests/unittests.c b/tests/unittests.c index 04837823..b1a1cb15 100644 --- a/tests/unittests.c +++ b/tests/unittests.c @@ -189,6 +189,8 @@ int unit_tests(void *_unused) { cpu_freq_expect("Prototyp Amazing Foo One @ 1GHz", 1000000000); cpu_freq_expect("Prototyp Amazing Foo Two @ 1.00GHz", 1000000000); + dump_pagetables(&cr3); + map_pagetables(&cr3, NULL); map_pagetables(&cr3, &user_cr3); pte_t *pte = get_pte(unit_tests);