Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

HVM-747 add dmods to get event indexes

  • Loading branch information...
commit a28b557f30616c2780163ea7a52aa72477f89ad9 1 parent bacaa89
Robert Mustacchi authored

Showing 1 changed file with 128 additions and 7 deletions. Show diff stats Hide diff stats

  1. 135  qemu_mdb.c
135  qemu_mdb.c
@@ -78,6 +78,42 @@ typedef struct RAMList {
78 78
 	QLIST_HEAD(ram, RAMBlock) blocks;
79 79
 } RAMList;
80 80
 
  81
+typedef struct VRingDesc
  82
+{
  83
+    uint64_t addr;
  84
+    uint32_t len;
  85
+    uint16_t flags;
  86
+    uint16_t next;
  87
+} VRingDesc;
  88
+
  89
+typedef struct VRingAvail
  90
+{
  91
+    uint16_t flags;
  92
+    uint16_t idx;
  93
+    uint16_t ring[0];
  94
+} VRingAvail;
  95
+
  96
+typedef struct VRingUsedElem
  97
+{
  98
+    uint32_t id;
  99
+    uint32_t len;
  100
+} VRingUsedElem;
  101
+
  102
+typedef struct VRingUsed
  103
+{
  104
+    uint16_t flags;
  105
+    uint16_t idx;
  106
+    VRingUsedElem ring[0];
  107
+} VRingUsed;
  108
+
  109
+typedef struct VRing
  110
+{
  111
+    unsigned int num;
  112
+    target_phys_addr_t desc;
  113
+    target_phys_addr_t avail;
  114
+    target_phys_addr_t used;
  115
+} VRing;
  116
+
81 117
 /*
82 118
  * NDEVICES comes from the PCIDevice structure and should be changed if this
83 119
  * does ever change.
@@ -438,7 +474,7 @@ qemu_mdb_get_ram_ptr(uintptr_t addr)
438 474
 }
439 475
 
440 476
 static int
441  
-qemu_mdb_tpa2qva(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
  477
+internal_tpa2qva(uintptr_t addr, uintptr_t *res)
442 478
 {
443 479
 	GElf_Sym sym;
444 480
 	void **lp, **p;
@@ -446,12 +482,6 @@ qemu_mdb_tpa2qva(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
446 482
 	PhysPageDesc *pdp, pd;
447 483
 	uintptr_t paddr, pfaddr, vptr;
448 484
 
449  
-	if (!(flags & DCMD_ADDRSPEC))
450  
-		return (DCMD_USAGE);
451  
-
452  
-	if (argc > 1)
453  
-		return (DCMD_USAGE);
454  
-
455 485
 	if (mdb_lookup_by_name("l1_phys_map", &sym) != 0) {
456 486
 		mdb_warn("unable to locate host_buse");
457 487
 		return (DCMD_ERR);
@@ -502,16 +532,107 @@ qemu_mdb_tpa2qva(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
502 532
 	if (vptr == 0)
503 533
 		return (DCMD_ERR);
504 534
 	vptr += addr & ~MDB_TARGET_PAGE_MASK;
  535
+	*res = vptr;
  536
+
  537
+	return (DCMD_OK);
  538
+}
  539
+
  540
+static int
  541
+qemu_mdb_tpa2qva(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
  542
+{
  543
+	uintptr_t vptr;
  544
+
  545
+	if (!(flags & DCMD_ADDRSPEC))
  546
+		return (DCMD_USAGE);
  547
+
  548
+	if (argc > 1)
  549
+		return (DCMD_USAGE);
  550
+
  551
+	if (internal_tpa2qva(addr, &vptr) != DCMD_OK)
  552
+		return (DCMD_ERR);
  553
+
505 554
 	mdb_printf("%lr\n", vptr);
506 555
 
507 556
 	return (DCMD_OK);
508 557
 }
509 558
 
  559
+static int
  560
+qemu_mdb_vrused(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
  561
+{
  562
+	VRing ring;
  563
+	uintptr_t avaddr;
  564
+	uint16_t index;
  565
+
  566
+	if (!(flags & DCMD_ADDRSPEC))
  567
+		return (DCMD_USAGE);
  568
+
  569
+	if (argc > 1)
  570
+		return (DCMD_USAGE);
  571
+
  572
+	if (mdb_vread(&ring, sizeof (ring), addr) != sizeof (ring)) {
  573
+		mdb_warn("failed to read VRing");
  574
+		return (DCMD_ERR);
  575
+	}
  576
+
  577
+	if (internal_tpa2qva(ring.avail, &avaddr) != DCMD_OK) {
  578
+		mdb_warn("failed to translate available ring to VA");
  579
+		return (DCMD_ERR);
  580
+	}
  581
+
  582
+	/* Account for offset */
  583
+	avaddr += ring.num * sizeof (uint16_t) + 0x4;
  584
+	if (mdb_vread(&index, sizeof (index), avaddr) != sizeof (index)) {
  585
+		mdb_warn("failed to read index value");
  586
+		return (DCMD_ERR);
  587
+	}
  588
+
  589
+	mdb_printf("%lr\n", index);
  590
+	return (DCMD_OK);
  591
+}
  592
+
  593
+static int
  594
+qemu_mdb_vravail(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
  595
+{
  596
+	VRing ring;
  597
+	uintptr_t avaddr;
  598
+	uint16_t index;
  599
+
  600
+	if (!(flags & DCMD_ADDRSPEC))
  601
+		return (DCMD_USAGE);
  602
+
  603
+	if (argc > 1)
  604
+		return (DCMD_USAGE);
  605
+
  606
+	if (mdb_vread(&ring, sizeof (ring), addr) != sizeof (ring)) {
  607
+		mdb_warn("failed to read VRing");
  608
+		return (DCMD_ERR);
  609
+	}
  610
+
  611
+	if (internal_tpa2qva(ring.used, &avaddr) != DCMD_OK) {
  612
+		mdb_warn("failed to translate available ring to VA");
  613
+		return (DCMD_ERR);
  614
+	}
  615
+
  616
+	/* Account for offset */
  617
+	avaddr += ring.num * sizeof (uint64_t) + 0x4;
  618
+	if (mdb_vread(&index, sizeof (index), avaddr) != sizeof (index)) {
  619
+		mdb_warn("failed to read index value");
  620
+		return (DCMD_ERR);
  621
+	}
  622
+
  623
+	mdb_printf("%lr\n", index);
  624
+	return (DCMD_OK);
  625
+}
  626
+
510 627
 static const mdb_dcmd_t qemu_dcmds[] = {
511 628
 	{ "pcidev2virtio", NULL, "translate a virtio PCI device to its "
512 629
 		"virtio equivalent", qemu_mdb_pcidev2virtio },
513 630
 	{ "qemu_tpa2qva", NULL, "translate a target physical address to a "
514 631
 		"QEMU virtual address", qemu_mdb_tpa2qva },
  632
+	{ "qemu_vrused", NULL, "Spit out the used event of the vring",
  633
+		qemu_mdb_vrused },
  634
+	{ "qemu_vravail", NULL, "Spit out the avail event of the vring",
  635
+		qemu_mdb_vravail },
515 636
 	{ NULL }
516 637
 };
517 638
 

0 notes on commit a28b557

Please sign in to comment.
Something went wrong with that request. Please try again.