Skip to contentSkip to conversation

hmp: gva2gpa debug command

PATCH In review Dr. David Alan Gilbert (git) 2 participants 4 messages Apr 12, 2019 – May 1, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hmp: gva2gpa debug command

From: "Dr. David Alan Gilbert" <[email protected]>

Add a gva2gpa command purely for debug which performs address translation on the gva, the existing gpa2hva command can then also be used to find it in the qemu userspace; e.g.

(qemu) info registers
.... RSP=ffffffff81c03e98
....
(qemu) gva2gpa 0xffffffff81c03e98
gpa: 0x1c03e98
(qemu) gpa2hva 0x1c03e98
Host virtual address for 0x1c03e98 (pc.ram) is 0x7f0599a03e98 (qemu) x/10x 0xffffffff81c03e98
ffffffff81c03e98: 0x81c03eb8 0xffffffff 0x8101ea3f 0xffffffff
ffffffff81c03ea8: 0x81d27b00 0xffffffff 0x00000000 0x00000000
ffffffff81c03eb8: 0x81c03ec8 0xffffffff

gdb -p ...qemu...
(gdb) x/10x 0x7f0599a03e98
0x7f0599a03e98: 0x81c03eb8 0xffffffff 0x8101ea3f 0xffffffff
0x7f0599a03ea8: 0x81d27b00 0xffffffff 0x00000000 0x00000000
0x7f0599a03eb8: 0x81c03ec8 0xffffffff

---
 hmp-commands.hx  | 15 +++++++++++++++
 monitor.c        | 22 ++++++++++++++++++++++
 tests/test-hmp.c |  1 +
 3 files changed, 38 insertions(+)
hmp-commands.hx +15 -0
index d3bad2fc27..ba4690b9ac 100644
@@ -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 gpa2hpa @var{addr}
+@findex gpa2hpa
+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
 
     {
monitor.c +22 -0
index 4807bbe811..2b6017b621 100644
@@ -1676,6 +1676,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)
 {
tests/test-hmp.c +1 -0
index 54a01824dc..e344947f7c 100644
@@ -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",
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Dr. David Alan Gilbert (git)
hmp-commands.hx +3 -0
index d3bad2fc27..ba4690b9ac 100644
@@ -585,6 +585,21 @@ STEXI
 @findex gpa2hpa
 Print the host physical address at which the guest's physical address @var{addr}
 is mapped.
+ETEXI
+
+    {

hmp-commands.hx STEXI · line 600

Quoted 10 lines
hmp-commands.hx +10 -0
+        .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 gpa2hpa @var{addr}
+@findex gpa2hpa

s/gpa2hpa/gva2gpa/

Aside from this:

#2 lore raw
Quoted 16 lines · * Stefan Hajnoczi ([email protected]) wrote:
Quoted 15 lines · Dr. David Alan Gilbert (git)
hmp-commands.hx +7 -0
index d3bad2fc27..ba4690b9ac 100644
@@ -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",
Quoted 8 lines

hmp-commands.hx STEXI · line 600

Quoted 6 lines
hmp-commands.hx +6 -0
+        .cmd        = hmp_gva2gpa,
+    },
+
+STEXI
+@item gpa2hpa @var{addr}
+@findex gpa2hpa

s/gpa2hpa/gva2gpa/

Oops, thanks!

Dave

Quoted 3 lines

Aside from this:

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#3 lore raw
In reply to Stefan Hajnoczi
Quoted 25 lines · * Stefan Hajnoczi ([email protected]) wrote:
Quoted 11 lines · Dr. David Alan Gilbert (git)
hmp-commands.hx +3 -0
index d3bad2fc27..ba4690b9ac 100644
@@ -585,6 +585,21 @@ STEXI
 @findex gpa2hpa
 Print the host physical address at which the guest's physical address @var{addr}
 is mapped.
+ETEXI
+
+    {

hmp-commands.hx STEXI · line 600

Quoted 10 lines
hmp-commands.hx +10 -0
+        .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 gpa2hpa @var{addr}
+@findex gpa2hpa

s/gpa2hpa/gva2gpa/

Quoted 3 lines

Aside from this:

Queued

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK