diff --git a/hmp-commands.hx b/hmp-commands.hx index 9b4035965cd..a2c3ffc2188 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -585,6 +585,21 @@ STEXI @findex gpa2hpa Print the host physical address at which the guest's physical address @var{addr} is mapped. +ETEXI + + { + .name = "gva2gpa", + .args_type = "addr:l", + .params = "addr", + .help = "print the guest physical address corresponding to a guest virtual address", + .cmd = hmp_gva2gpa, + }, + +STEXI +@item gva2gpa @var{addr} +@findex gva2gpa +Print the guest physical address at which the guest's virtual address @var{addr} +is mapped based on the mapping for the current CPU. ETEXI { diff --git a/monitor.c b/monitor.c index 9b5f10b475c..bb48997913b 100644 --- a/monitor.c +++ b/monitor.c @@ -1673,6 +1673,28 @@ static void hmp_gpa2hva(Monitor *mon, const QDict *qdict) memory_region_unref(mr); } +static void hmp_gva2gpa(Monitor *mon, const QDict *qdict) +{ + target_ulong addr = qdict_get_int(qdict, "addr"); + MemTxAttrs attrs; + CPUState *cs = mon_get_cpu(); + hwaddr gpa; + + if (!cs) { + monitor_printf(mon, "No cpu\n"); + return; + } + + gpa = cpu_get_phys_page_attrs_debug(mon_get_cpu(), + addr & TARGET_PAGE_MASK, &attrs); + if (gpa == -1) { + monitor_printf(mon, "Unmapped\n"); + } else { + monitor_printf(mon, "gpa: %#" HWADDR_PRIx "\n", + gpa + (addr & ~TARGET_PAGE_MASK)); + } +} + #ifdef CONFIG_LINUX static uint64_t vtop(void *ptr, Error **errp) { diff --git a/tests/test-hmp.c b/tests/test-hmp.c index 54a01824dc5..e344947f7c5 100644 --- a/tests/test-hmp.c +++ b/tests/test-hmp.c @@ -39,6 +39,7 @@ static const char *hmp_cmds[] = { "dump-guest-memory /dev/null 0 4096", "dump-guest-memory /dev/null", "gdbserver", + "gva2gpa 0", "hostfwd_add tcp::43210-:43210", "hostfwd_remove tcp::43210-:43210", "i /w 0",