Browse Source

hmp: gva2gpa debug command

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=ffffffff81
....
(qemu) gva2gpa 0xffffffff81c03e98
gpa: 0x1c03e98
(qemu) gpa2hva 0x1c03e98
Host virtual address for 0x1c03e98 (pc.ram) is 0x7f0599a03e98
(qemu) x/10x 0xffffffff81c03e98
ffffffff81: 0x81c03eb8 0xffffffff 0x8101ea3f 0xffffffff
ffffffff81: 0x81d27b00 0xffffffff 0x00000000 0x00000000
ffffffff81: 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: <2019041215.827-1-dgilbert@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
master
Dr. David Alan Gilbert 2 months ago
parent
commit
574d96933c
3 changed files with 38 additions and 0 deletions
  1. 15
    0
      hmp-commands.hx
  2. 22
    0
      monitor.c
  3. 1
    0
      tests/test-hmp.c

+ 15
- 0
hmp-commands.hx View File

@@ -585,6 +585,21 @@ STEXI
585 585
 @findex gpa2hpa
586 586
 Print the host physical address at which the guest's physical address @var{addr}
587 587
 is mapped.
588
+ETEXI
589
+
590
+    {
591
+        .name       = "gva2gpa",
592
+        .args_type  = "addr:l",
593
+        .params     = "addr",
594
+        .help       = "print the guest physical address corresponding to a guest virtual address",
595
+        .cmd        = hmp_gva2gpa,
596
+    },
597
+
598
+STEXI
599
+@item gva2gpa @var{addr}
600
+@findex gva2gpa
601
+Print the guest physical address at which the guest's virtual address @var{addr}
602
+is mapped based on the mapping for the current CPU.
588 603
 ETEXI
589 604
 
590 605
     {

+ 22
- 0
monitor.c View File

@@ -1673,6 +1673,28 @@ static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
1673 1673
     memory_region_unref(mr);
1674 1674
 }
1675 1675
 
1676
+static void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
1677
+{
1678
+    target_ulong addr = qdict_get_int(qdict, "addr");
1679
+    MemTxAttrs attrs;
1680
+    CPUState *cs = mon_get_cpu();
1681
+    hwaddr gpa;
1682
+
1683
+    if (!cs) {
1684
+        monitor_printf(mon, "No cpu\n");
1685
+        return;
1686
+    }
1687
+
1688
+    gpa  = cpu_get_phys_page_attrs_debug(mon_get_cpu(),
1689
+                                         addr & TARGET_PAGE_MASK, &attrs);
1690
+    if (gpa == -1) {
1691
+        monitor_printf(mon, "Unmapped\n");
1692
+    } else {
1693
+        monitor_printf(mon, "gpa: %#" HWADDR_PRIx "\n",
1694
+                       gpa + (addr & ~TARGET_PAGE_MASK));
1695
+    }
1696
+}
1697
+
1676 1698
 #ifdef CONFIG_LINUX
1677 1699
 static uint64_t vtop(void *ptr, Error **errp)
1678 1700
 {

+ 1
- 0
tests/test-hmp.c View File

@@ -39,6 +39,7 @@ static const char *hmp_cmds[] = {
39 39
     "dump-guest-memory /dev/null 0 4096",
40 40
     "dump-guest-memory /dev/null",
41 41
     "gdbserver",
42
+    "gva2gpa 0",
42 43
     "hostfwd_add tcp::43210-:43210",
43 44
     "hostfwd_remove tcp::43210-:43210",
44 45
     "i /w 0",

Loading…
Cancel
Save