Skip to contentSkip to conversation

hw/nvme: add monitor commands for inspecting state

PATCH In review Mateusz Nowicki 2 participants 4 messages Jun 30 – Jul 2 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#1 lore raw

PATCH v4 1/2 hw/nvme: add 'info nvme' HMP command

In reply to Mateusz Nowicki

Add an 'info nvme' HMP command for inspecting emulated NVMe controllers from the QEMU monitor.

For each NVMe controller in the QOM tree the command prints:

- PCI BDF, vendor/device ID and BAR0 base address;
- Identify Controller fields visible to the host driver: SN, MN, FR

    and CNTLID;

- the CC, CSTS and AQA registers (raw 32-bit values);
- the number of admin and active I/O submission/completion queues.

Useful when debugging the Linux NVMe driver against the QEMU emulation without attaching gdb to the QEMU process.

Example:

(qemu) info nvme
/machine/peripheral-anon/device[0]

    PCI:    BDF 00:04.0  VID=8086 DID=5845  BAR0=0x00000000feb50000
    ID:     SN=NVME0001  MN=QEMU NVMe Ctrl  FR=...  CNTLID=0x0000
    CC:     0x00460001
    CSTS:   0x00000001
    AQA:    0x001f001f

Queues: 1 admin + 4 IO SQ / 4 IO CQ

---
 hmp-commands-info.hx   | 13 ++++++++
 hw/nvme/meson.build    |  4 ++-
 hw/nvme/monitor-stub.c | 15 +++++++++
 hw/nvme/monitor.c      | 76 ++++++++++++++++++++++++++++++++++++++++++
 qapi/machine.json      | 17 ++++++++++
 5 files changed, 124 insertions(+), 1 deletion(-)
 create mode 100644 hw/nvme/monitor-stub.c
 create mode 100644 hw/nvme/monitor.c
hmp-commands-info.hx +13 -0
index 82134eb6c2..b984691c3c 100644
@@ -340,6 +340,19 @@ SRST
     Show guest USB devices.
 ERST
 
+    {
+        .name       = "nvme",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show emulated NVMe controllers",
+        .cmd_info_hrt = qmp_x_query_nvme,
+    },
+
+SRST
+  ``info nvme``
+    Show emulated NVMe controllers.
+ERST
+
     {
         .name       = "usbhost",
         .args_type  = "",
hw/nvme/meson.build +3 -1
index 7d5caa53c2..99f336399e 100644
@@ -1 +1,3 @@
-system_ss.add(when: 'CONFIG_NVME_PCI', if_true: files('ctrl.c', 'dif.c', 'ns.c', 'subsys.c', 'nguid.c'))
\ No newline at end of file
+system_ss.add(when: 'CONFIG_NVME_PCI',
+              if_true: files('ctrl.c', 'dif.c', 'monitor.c', 'nguid.c', 'ns.c', 'subsys.c'),
+              if_false: files('monitor-stub.c'))
hw/nvme/monitor-stub.c new file +15 -0
new file mode 100644
index 0000000000..5eb9f04c8d
@@ -0,0 +1,15 @@
+/*
+ * QEMU NVMe Controller monitor command stubs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-machine.h"
+
+HumanReadableText *qmp_x_query_nvme(Error **errp)
+{
+    error_setg(errp, "NVMe support is not compiled in");
+    return NULL;
+}
hw/nvme/monitor.c new file +76 -0

76 lines not on this page · raw message

qapi/machine.json +17 -0
index 685e4e29b8..d4a589e768 100644
@@ -1772,6 +1772,23 @@
   'returns': 'HumanReadableText',
   'features': [ 'unstable' ] }
 
+##
+# @x-query-nvme:
+#
+# Query state of emulated NVMe controllers.
+#
+# Features:
+#
+# @unstable: This command is meant for debugging.
+#
+# Returns: NVMe controller state as human-readable text
+#
+# Since: 11.1
+##
+{ 'command': 'x-query-nvme',
+  'returns': 'HumanReadableText',
+  'features': [ 'unstable' ] }
+
 ##
 # @SmbiosEntryPointType:
 #
Signature · 1 line
2.53.0
#0 lore raw

v4 cover hw/nvme: add monitor commands for inspecting state

Add two HMP commands for inspecting emulated NVMe controllers from the QEMU monitor without attaching gdb to the QEMU process:

- 'info nvme' - per-controller summary (PCI, identify
fields, CC/CSTS/AQA, queue counts)
- 'info nvme-queues' - per-queue listing of admin and I/O SQ/CQ (size, head/tail, PRP1, doorbell offset, phase tag)

Useful for verifying queue setup, doorbell rings, AERs held in the admin SQ and similar driver/controller interaction details from a running QEMU monitor.

Changes in v4:
- Drop the v3 attempt to gate the new commands with 'if': 'CONFIG_NVME_PCI'. CONFIG_NVME_PCI is a device symbol and is poisoned in common code, so the generated qapi-introspect.c failed to build (reported by Klaus Jensen). Instead the x-query commands stay unconditional and hw/nvme/monitor-stub.c provides qmp_x_query_nvme[_queues]() stubs, built when CONFIG_NVME_PCI is not set, so targets without NVMe (e.g. riscv64-softmmu) link.

Changes in v3:
- hw/nvme/meson.build: keep the source file list alphabetically sorted (Markus).

Changes in v2:
- hw/nvme/meson.build: add the missing trailing newline (Markus).
- Pick up Acked-by tags from Dr. David Alan Gilbert and Markus Armbruster on both patches.

v3: https://lore.kernel.org/qemu-devel/[email protected]/
v2: https://lore.kernel.org/qemu-devel/[email protected]/
v1: https://lore.kernel.org/qemu-devel/[email protected]/

Mateusz Nowicki (2):
hw/nvme: add 'info nvme' HMP command
hw/nvme: add 'info nvme-queues' HMP command

 hmp-commands-info.hx   |  28 +++++++++
 hw/nvme/meson.build    |   4 +-
 hw/nvme/monitor-stub.c |  21 +++++++
 hw/nvme/monitor.c      | 139 +++++++++++++++++++++++++++++++++++++++++
 qapi/machine.json      |  34 ++++++++++
 5 files changed, 225 insertions(+), 1 deletion(-)
 create mode 100644 hw/nvme/monitor-stub.c
 create mode 100644 hw/nvme/monitor.c
Signature · 1 line
2.53.0
#2 lore raw

PATCH v4 2/2 hw/nvme: add 'info nvme-queues' HMP command

Add an 'info nvme-queues' HMP command that lists, for every emulated NVMe controller, the admin SQ/CQ and every active I/O SQ/CQ.

For each queue the command prints:

- the ring size, head and tail indices;
- the associated CQ id (for SQ) or interrupt vector (for CQ);
- the queue's PRP1 (DMA base address of the ring);
- the BAR0-relative doorbell offset (SQyTDBL / CQyHDBL);
- the current CQ phase tag.

The doorbell offsets are computed from CAP.DSTRD so they remain correct if the emulation ever exposes a non-zero stride.

Useful when debugging the Linux NVMe driver against the QEMU emulation - queue setup, doorbell rings, AERs held in the admin SQ etc. - without attaching gdb to the QEMU process.

Example, with the long PRP1 ring address and BAR0-relative doorbell offset replaced by '...'; phase tag column omitted for brevity:

(qemu) info nvme-queues
/machine/peripheral-anon/device[0]

  SQ 0  size=32    head=9     tail=9     cqid=0    prp1=...  SQTDBL=...
  CQ 0  size=32    head=8     tail=8     iv=0      prp1=...  CQHDBL=...
  SQ 1  size=1024  head=2     tail=2     cqid=1    prp1=...  SQTDBL=...
  CQ 1  size=1024  head=2     tail=2     iv=1      prp1=...  CQHDBL=...
---
 hmp-commands-info.hx   | 15 ++++++++++
 hw/nvme/monitor-stub.c |  6 ++++
 hw/nvme/monitor.c      | 63 ++++++++++++++++++++++++++++++++++++++++++
 qapi/machine.json      | 17 ++++++++++++
 4 files changed, 101 insertions(+)
hmp-commands-info.hx +15 -0
index b984691c3c..874c1e1970 100644
@@ -353,6 +353,21 @@ SRST
     Show emulated NVMe controllers.
 ERST
 
+    {
+        .name       = "nvme-queues",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show active NVMe queues and their doorbells",
+        .cmd_info_hrt = qmp_x_query_nvme_queues,
+    },
+
+SRST
+  ``info nvme-queues``
+    Show all active NVMe submission and completion queues, including
+    head/tail, DMA address of the ring and BAR0-relative doorbell
+    offset.
+ERST
+
     {
         .name       = "usbhost",
         .args_type  = "",
hw/nvme/monitor-stub.c +6 -0
index 5eb9f04c8d..489cc4a5c7 100644
@@ -13,3 +13,9 @@ HumanReadableText *qmp_x_query_nvme(Error **errp)
     error_setg(errp, "NVMe support is not compiled in");
     return NULL;
 }
+
+HumanReadableText *qmp_x_query_nvme_queues(Error **errp)
+{
+    error_setg(errp, "NVMe support is not compiled in");
+    return NULL;
+}
hw/nvme/monitor.c +63 -0

66 lines not on this page · raw message

qapi/machine.json +17 -0
index d4a589e768..c21b128e0a 100644
@@ -1789,6 +1789,23 @@
   'returns': 'HumanReadableText',
   'features': [ 'unstable' ] }
 
+##
+# @x-query-nvme-queues:
+#
+# Query state of all active SQ/CQ for emulated NVMe controllers.
+#
+# Features:
+#
+# @unstable: This command is meant for debugging.
+#
+# Returns: per-queue state as human-readable text
+#
+# Since: 11.1
+##
+{ 'command': 'x-query-nvme-queues',
+  'returns': 'HumanReadableText',
+  'features': [ 'unstable' ] }
+
 ##
 # @SmbiosEntryPointType:
 #
Signature · 1 line
2.53.0
#3 lore raw
In reply to Mateusz Nowicki
Quoted 39 lines · Mateusz Nowicki

Add two HMP commands for inspecting emulated NVMe controllers from the QEMU monitor without attaching gdb to the QEMU process:

- 'info nvme' - per-controller summary (PCI, identify
fields, CC/CSTS/AQA, queue counts)
- 'info nvme-queues' - per-queue listing of admin and I/O SQ/CQ (size, head/tail, PRP1, doorbell offset, phase tag)

Useful for verifying queue setup, doorbell rings, AERs held in the admin SQ and similar driver/controller interaction details from a running QEMU monitor.

Changes in v4:
- Drop the v3 attempt to gate the new commands with 'if': 'CONFIG_NVME_PCI'. CONFIG_NVME_PCI is a device symbol and is poisoned in common code, so the generated qapi-introspect.c failed to build (reported by Klaus Jensen). Instead the x-query commands stay unconditional and hw/nvme/monitor-stub.c provides qmp_x_query_nvme[_queues]() stubs, built when CONFIG_NVME_PCI is not set, so targets without NVMe (e.g. riscv64-softmmu) link.

Changes in v3:
- hw/nvme/meson.build: keep the source file list alphabetically sorted (Markus).

Changes in v2:
- hw/nvme/meson.build: add the missing trailing newline (Markus).
- Pick up Acked-by tags from Dr. David Alan Gilbert and Markus Armbruster on both patches.

v3: https://lore.kernel.org/qemu-devel/[email protected]/
v2: https://lore.kernel.org/qemu-devel/[email protected]/
v1: https://lore.kernel.org/qemu-devel/[email protected]/

Mateusz Nowicki (2):
hw/nvme: add 'info nvme' HMP command
hw/nvme: add 'info nvme-queues' HMP command

Quoted 13 lines
 hmp-commands-info.hx   |  28 +++++++++
 hw/nvme/meson.build    |   4 +-
 hw/nvme/monitor-stub.c |  21 +++++++
 hw/nvme/monitor.c      | 139 +++++++++++++++++++++++++++++++++++++++++
 qapi/machine.json      |  34 ++++++++++
 5 files changed, 225 insertions(+), 1 deletion(-)
 create mode 100644 hw/nvme/monitor-stub.c
 create mode 100644 hw/nvme/monitor.c
Signature · 1 line
2.53.0

Thanks for the fix, back in nvme.next :)