On Thu, Jun 06, 2024 at 10:02:48AM -0400, Don Porter wrote: > The new "info pg" monitor command prints the current page table, > including virtual address ranges, flag bits, and snippets of physical > page numbers. Completely filled regions of the page table with > compatible flags are "folded", with the result that the complete > output for a freshly booted x86-64 Linux VM can fit in a single > terminal window. The output looks like this: > > VPN range Entry Flags Physical page > [7f0000000-7f0000000] PML4[0fe] ---DA--UWP > [7f28c0000-7f28fffff] PDP[0a3] ---DA--UWP > [7f28c4600-7f28c47ff] PDE[023] ---DA--UWP > [7f28c4655-7f28c4656] PTE[055-056] X--D---U-P 0000007f14-0000007f15 > [7f28c465b-7f28c465b] PTE[05b] ----A--U-P 0000001cfc > ... > [ff8000000-ff8000000] PML4[1ff] ---DA--UWP > [ffff80000-ffffbffff] PDP[1fe] ---DA---WP > [ffff81000-ffff81dff] PDE[008-00e] -GSDA---WP 0000001000-0000001dff > [ffffc0000-fffffffff] PDP[1ff] ---DA--UWP > [ffffff400-ffffff5ff] PDE[1fa] ---DA--UWP > [ffffff5fb-ffffff5fc] PTE[1fb-1fc] XG-DACT-WP 00000fec00 00000fee00 > [ffffff600-ffffff7ff] PDE[1fb] ---DA--UWP > [ffffff600-ffffff600] PTE[000] -G-DA--U-P 0000001467 > > This draws heavy inspiration from Austin Clements' original patch. > > This also adds a generic page table walker, which other monitor > and execution commands will be migrated to in subsequent patches. > > Signed-off-by: Don Porter <por...@cs.unc.edu> > --- > hmp-commands-info.hx | 13 ++ > hw/core/cpu-sysemu.c | 140 ++++++++++++ > include/hw/core/cpu.h | 34 ++- > include/hw/core/sysemu-cpu-ops.h | 156 +++++++++++++ > include/monitor/hmp-target.h | 1 + > monitor/hmp-cmds-target.c | 198 +++++++++++++++++ > target/i386/arch_memory_mapping.c | 351 +++++++++++++++++++++++++++++- > target/i386/cpu.c | 11 + > target/i386/cpu.h | 15 ++ > target/i386/monitor.c | 165 ++++++++++++++ > 10 files changed, 1082 insertions(+), 2 deletions(-) > + > +void hmp_info_pg(Monitor *mon, const QDict *qdict) > +{ > + struct mem_print_state state; > + > + CPUState *cs = mon_get_cpu(mon); > + if (!cs) { > + monitor_printf(mon, "Unable to get CPUState. Internal error\n"); > + return; > + } > + > + CPUClass *cc = CPU_GET_CLASS(cs); > + > + if ((!cc->sysemu_ops->pte_child) > + || (!cc->sysemu_ops->pte_leaf) > + || (!cc->sysemu_ops->pte_leaf_page_size) > + || (!cc->sysemu_ops->page_table_entries_per_node) > + || (!cc->sysemu_ops->pte_flags) > + || (!cc->sysemu_ops->mon_init_page_table_iterator) > + || (!cc->sysemu_ops->mon_info_pg_print_header) > + || (!cc->sysemu_ops->mon_flush_page_print_state)) { > + monitor_printf(mon, "Info pg unsupported on this ISA\n"); > + return; > + } > + > + if (!cc->sysemu_ops->mon_init_page_table_iterator(mon, &state)) { > + monitor_printf(mon, "Unable to initialize page table iterator\n"); > + return; > + } > + > + state.flush_interior = true; > + state.require_physical_contiguity = true; > + state.flusher = cc->sysemu_ops->mon_flush_page_print_state; > + > + cc->sysemu_ops->mon_info_pg_print_header(mon, &state); > + > + /* > + * We must visit interior entries to get the hierarchy, but > + * can skip not present mappings > + */ > + for_each_pte(cs, &compressing_iterator, &state, true, false); > + > + /* Print last entry, if one present */ > + cc->sysemu_ops->mon_flush_page_print_state(cs, &state); > +}
Please don't add new HMP commands that don't have a QMP equivalent. This should be adding an 'x-query-pg' QMP command, which returns HumanReadableText, and then call that from the HMP There is guidance on this here: https://www.qemu.org/docs/master/devel/writing-monitor-commands.html#writing-a-debugging-aid-returning-unstructured-text If you need more real examples, look at the various 'x-query-XXXX' commands in qapi/machine.json and their impl. With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|