Messages in this thread Patch in this message | | | Date | Wed, 27 Sep 2023 11:25:12 +0000 | Subject | [PATCH 06/11] arm64: ptdump: Register a debugfs entry for the host stage-2 page-tables | From | Sebastian Ene <> |
| |
Initialize the structures used to keep the state of the stage-2 ptdump walker. To satisfy the ptdump API for parsing no VMA regions, initialize a memory structure. Since we are going to parse a snapshot of the host stage-2 paget-tables we don't rely on the locking from the memory structure.
Signed-off-by: Sebastian Ene <sebastianene@google.com> --- arch/arm64/kvm/Kconfig | 12 ++++++++++++ arch/arm64/mm/ptdump.c | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig index 83c1e09be42e..2974bb5c4838 100644 --- a/arch/arm64/kvm/Kconfig +++ b/arch/arm64/kvm/Kconfig @@ -71,4 +71,16 @@ config PROTECTED_NVHE_STACKTRACE If unsure, or not using protected nVHE (pKVM), say N. +config NVHE_EL2_PTDUMP_DEBUGFS + bool "Present the stage-2 pagetables to debugfs" + depends on NVHE_EL2_DEBUG && PTDUMP_DEBUGFS + help + Say Y here if you want to show the pKVM host stage-2 kernel pagetable + layout in a debugfs file. This information is only useful for kernel developers + who are working in architecture specific areas of the kernel. + It is probably not a good idea to enable this feature in a production + kernel. + + If in doubt, say N. + endif # VIRTUALIZATION diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 8c4f06ca622a..25c0640e82aa 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -469,6 +469,21 @@ void ptdump_check_wx(void) pr_info("Checked W+X mappings: passed, no W+X pages found\n"); } +#ifdef CONFIG_NVHE_EL2_PTDUMP_DEBUGFS +static struct ptdump_info stage2_kernel_ptdump_info; +static struct addr_marker ipa_address_markers[] = { + { 0, "IPA start"}, + { -1, "IPA end"}, + { -1, NULL}, +}; + +/* Initialize a memory structure used by ptdump to walk the no-VMA region */ +static struct mm_struct ipa_init_mm = { + .mm_mt = MTREE_INIT_EXT(mm_mt, MM_MT_FLAGS, + ipa_init_mm.mmap_lock), +}; +#endif /* CONFIG_NVHE_EL2_PTDUMP_DEBUGFS */ + static int __init ptdump_init(void) { address_markers[PAGE_END_NR].start_address = PAGE_END; @@ -477,6 +492,17 @@ static int __init ptdump_init(void) #endif ptdump_initialize(); ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables"); + +#ifdef CONFIG_NVHE_EL2_PTDUMP_DEBUGFS + stage2_kernel_ptdump_info = (struct ptdump_info) { + .markers = ipa_address_markers, + .mm = &ipa_init_mm, + }; + + init_rwsem(&ipa_init_mm.mmap_lock); + ptdump_debugfs_register(&stage2_kernel_ptdump_info, + "host_stage2_kernel_page_tables"); +#endif return 0; } device_initcall(ptdump_init); -- 2.42.0.515.g380fc7ccd1-goog
| |