]> git.proxmox.com Git - mirror_qemu.git/commitdiff
hmp: gva2gpa debug command
authorDr. David Alan Gilbert <dgilbert@redhat.com>
Fri, 12 Apr 2019 15:26:52 +0000 (16:26 +0100)
committerDr. David Alan Gilbert <dgilbert@redhat.com>
Wed, 1 May 2019 09:46:59 +0000 (10:46 +0100)
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

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <20190412152652.827-1-dgilbert@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
hmp-commands.hx
monitor.c
tests/test-hmp.c

index 9b4035965cddcdb78a78d2dd45c48a901571f647..a2c3ffc21884e7cfd28b9e7457c5cb413f5a259c 100644 (file)
@@ -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
 
     {
index 9b5f10b475cb7728ba7535fa4f5ebddfe81a2169..bb48997913b5ea1135197af87278b576c6e46e77 100644 (file)
--- 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)
 {
index 54a01824dc53325d353bcbe0ce9254a601f755e1..e344947f7c580c7dcd09127d919dc0375ab406ce 100644 (file)
@@ -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",