Skip to contentSkip to conversation

hmp,qmp: Add commands to introspect virtio devices

PATCH In review Jonah Palmer 5 participants 21 messages Aug 11, 2022 – May 8, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v15 cover hmp,qmp: Add commands to introspect virtio devices

This series introduces new QMP/HMP commands to dump the status of a virtio device at different levels.

[Jonah: Rebasing from previous patchset from Apr. 1 (v14). Original patches
are by Laurent Vivier from May 2020.

I sincerely apologize for the *massive* delay in getting this latest v15 series out. It was a perferct storm of other more pressing issues, time off, and trying to understand why I was seeing this 30 feature bit in my PCI virtio devices. Please see patch 3/6 for more explanation on this issue.

Rebase from v14 to v15 includes: adding the missing sign-off-by from the poster, renaming & moving all virtio device feature map definitions to hw/virtio/virtio.c, including brief descriptions for all status & feature bits, a new virtio device feature map defined for virtio-rng, and mappings for virtio/vhost-vsock, virtio-iommu, virtio-mem, and virtio transport features updated with their newest feature bits. Most of these changes can be found in patch 3/6.

And again, sorry for the long wait on this.]

1. List available virtio devices in the machine

HMP Form:

info virtio

Example:

(qemu) info virtio /machine/peripheral-anon/device[2]/virtio-backend [virtio-scsi] /machine/peripheral/vsock0/virtio-backend [vhost-vsock] /machine/peripheral/crypto0/virtio-backend [virtio-crypto] /machine/peripheral-anon/device[1]/virtio-backend [virtio-net] /machine/peripheral-anon/device[0]/virtio-backend [virtio-serial]

QMP Form:

    { 'command': 'x-query-virtio',
      'returns': ['VirtioInfo'],
      'features': [ 'unstable' ] }

    Example:

        -> { "execute": "x-query-virtio" }
        <- { "return": [
                 {
                     "name": "virtio-scsi",
                     "path": "/machine/peripheral-anon/device[2]/virtio-backend"
                 },
                 {
                     "name": "vhost-vsock",
                     "path": "/machine/peripheral/vsock0/virtio-backend"
                 },
                 {
                     "name": "virtio-crypto",
                     "path": "/machine/peripheral/crypto0/virtio-backend"
                 },
                 {
                     "name": "virtio-net",
                     "path": "/machine/peripheral-anon/device[1]/virtio-backend"
                 },
                 {
                     "name": "virtio-serial",
                     "path": "/machine/peripheral-anon/device[0]/virtio-backend"
                 }
             ]
           }

2. Display status of a given virtio device

HMP Form:

info virtio-status <path>

Example:

(qemu) info virtio-status /machine/peripheral/vsock0/virtio-backend /machine/peripheral/vsock0/virtio-backend:
device_name: vhost-vsock (vhost)
device_id: 19
vhost_started: true
bus_name: (null)
broken: false
disabled: false
disable_legacy_check: false
started: true
use_started: true
start_on_kick: false
use_guest_notifier_mask: true
vm_running: true
num_vqs: 3
queue_sel: 2
isr: 0
endianness: little
status:
VIRTIO_CONFIG_S_ACKNOWLEDGE: Valid virtio device found,
VIRTIO_CONFIG_S_DRIVER: Guest OS compatible with device, VIRTIO_CONFIG_S_FEATURES_OK: Feature negotiation complete,
VIRTIO_CONFIG_S_DRIVER_OK: Driver setup and ready
Guest features:
VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled, VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported,
VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)
Host features:
VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled, VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported,
VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy),
VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts,
VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features negotiation supported
Backend features:

VHost:
nvqs: 2
vq_index: 0
max_queues: 0
n_mem_sections: 4
n_tmp_sections: 4
backend_cap: 0
log_enabled: false
log_size: 0
Features:
VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled, VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported,
VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy),
VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts,
VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ
VHOST_F_LOG_ALL: Logging write descriptors supported
Acked features:
VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled, VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported,
VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)
Backend features:

Protocol features:

QMP Form:

    { 'command': 'x-query-virtio-status',
      'data': { 'path': 'str' },
      'returns': 'VirtioStatus',
      'features': [ 'unstable' ] }

    Example:

        -> { "execute": "x-query-virtio-status",
             "arguments": { "path": "/machine/peripheral/vsock0/virtio-backend" }
           }
        <- { "return": {
                 "device-endian": "little",
                 "bus-name": "",
                 "disable-legacy-check": false,
                 "name": "vhost-vsock",
                 "started": true,
                 "device-id": 19,
                 "vhost-dev": {
                     "n-tmp-sections": 4,
                     "n-mem-sections": 4,
                     "max-queues": 0,
                     "backend-cap": 0,
                     "log-size": 0,
                     "backend-features": {
                         "dev-features": [
                         ],
                         "transports": [
                         ]
                     },
                     "nvqs": 2,
                     "protocol-features": {
                         "protocols": [
                         ]
                     },
                     "vq-index": 0,
                     "log-enabled": false,
                     "acked-features": {
                         "dev-features": [
                         ],
                         "transports": [
                             "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
                             "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
                             "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)"
                         ]
                     },
                     "features": {
                         "dev-features": [
                             "VHOST_F_LOG_ALL: Logging write descriptors supported"
                         ],
                         "transports": [
                             "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
                             "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
                             "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)",
                             "VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts",
                             "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ"
                         ]
                     }
                 },
                 "backend-features": {
                     "dev-features": [
                     ],
                     "transports": [
                     ]
                 },
                 "start-on-kick": false,
                 "isr": 0,
                 "broken": false,
                 "status": {
                     "statuses": [
                         "VIRTIO_CONFIG_S_ACKNOWLEDGE: Valid virtio device found",
                         "VIRTIO_CONFIG_S_DRIVER: Guest OS compatible with device",
                         "VIRTIO_CONFIG_S_FEATURES_OK: Feature negotiation complete",
                         "VIRTIO_CONFIG_S_DRIVER_OK: Driver setup and ready"
                     ]
                 },
                 "num-vqs": 3,
                 "guest-features": {
                     "dev-features": [
                     ],
                     "transports": [
                         "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
                         "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
                         "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)"
                     ]
                 },
                 "host-features": {
                     "dev-features": [
                         "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features negotiation supported"
                     ],
                     "transports": [
                         "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
                         "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
                         "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)",
                         "VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts",
                         "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ"
                     ]
                 },
                 "use-guest-notifier-mask": true,
                 "vm-running": true,
                 "queue-sel": 2,
                 "disabled": false,
                 "vhost-started": true,
                 "use-started": true
             }
           }

3. Display status of a given virtio queue

HMP Form:

    info virtio-queue-status <path> <queue>

    Example:

        (qemu) info virtio-queue-status /machine/peripheral-anon/device[1]/virtio-backend 2
        /machine/peripheral-anon/device[1]/virtio-backend:
          device_name:          virtio-net
          queue_index:          2
          inuse:                0
          used_idx:             15
          signalled_used:       15
          signalled_used_valid: true
          VRing:
            num:          64
            num_default:  64
            align:        4096
            desc:         0x000000011e15c000
            avail:        0x000000011e15c400
            used:         0x000000011e15c4c0

QMP Form:

    { 'command': 'x-query-virtio-queue-status',
      'data': { 'path': 'str', 'queue': 'uint16' },
      'returns': 'VirtQueueStatus',
      'features': [ 'unstable' ] }

    Example:

        -> { "execute": "x-query-virtio-queue-status",
             "arguments": { "path": "/machine/peripheral-anon/device[1]/virtio-backend",
                            "queue": 2 }
           }
        <- { "return": {
                 "signalled-used": 15,
                 "inuse": 0,
                 "name": "virtio-net",
                 "vring-align": 4096,
                 "vring-desc": 4814004224,
                 "signalled-used-valid": true,
                 "vring-num-default": 64,
                 "vring-avail": 4814005248,
                 "queue-index": 2,
                 "vring-used": 4814005440,
                 "used-idx": 15,
                 "vring-num": 64
             }
           }

4. Display status of a given vhost queue

HMP Form:

    info virtio-vhost-queue-status <path> <queue>

    Example:

        (qemu) info virtio-vhost-queue-status /machine/peripheral-anon/device[1]/virtio-backend 1
        /machine/peripheral-anon/device[1]/virtio-backend:
          device_name:          virtio-net (vhost)
          kick:                 0
          call:                 0
          VRing:
            num:         256
            desc:        0x00007f804df5a000
            desc_phys:   0x000000013315a000
            desc_size:   4096
            avail:       0x00007f804df5b000
            avail_phys:  0x000000013315b000
            avail_size:  518
            used:        0x00007f804df5b240
            used_phys:   0x000000013315b240
            used_size:   2054

QMP Form:

    { 'command': 'x-query-virtio-vhost-queue-status',
      'data': { 'path': 'str', 'queue': 'uint16' },
      'returns': 'VirtVhostQueueStatus',
      'features': [ 'unstable' ] }

    Example:

        -> { "execute": "x-query-virtio-vhost-queue-status",
             "arguments": { "path": "/machine/peripheral-anon/device[1]/virtio-backend",
                            "queue": 1 }
           }
        <- { "return": {
                 "avail-phys": 4803538944,
                 "name": "virtio-net",
                 "used-phys": 4803539520,
                 "avail-size": 518,
                 "desc-size": 4096,
                 "used-size": 2054,
                 "desc": 140186477404160,
                 "num": 256,
                 "call": 0,
                 "avail": 140186477408256,
                 "desc-phys": 4803534848,
                 "used": 140186477408832,
                 "kick": 0
             }
           }

5. Display an element of a given virtio queue

HMP Form:

    info virtio-queue-element <path> <queue> [index]

    Example:

        Dump the information of the head element of the third queue of virtio-scsi:

        (qemu) info virtio-queue-element /machine/peripheral-anon/device[2]/virtio-backend 2
        /machine/peripheral-anon/device[2]/virtio-backend:
          device_name: virtio-scsi
          index:   0
          desc:
            descs:
                addr 0x128890000 len 12288 (write),
                addr 0x128880000 len 65536 (write, next),
                addr 0x128870000 len 65536 (write, next),
                addr 0x128860000 len 65536 (write, next),
                addr 0x128850000 len 65536 (write, next),
                addr 0x128840000 len 65536 (write, next),
                addr 0x128830000 len 65536 (write, next),
                addr 0x128820000 len 65536 (write, next),
                addr 0x128810000 len 65536 (write, next),
                addr 0x128800000 len 65536 (write, next),
                addr 0x116bf3000 len 53248 (write, next),
                addr 0x116be3000 len 65536 (write, next),
                addr 0x116bd3000 len 65536 (write, next),
                addr 0x116bc3000 len 65536 (write, next),
                addr 0x116bb3000 len 65536 (write, next),
                addr 0x116ba3000 len 65536 (write, next),
                addr 0x116b93000 len 65536 (write, next),
                addr 0x116b83000 len 65536 (write, next),
                addr 0x116b73000 len 65536 (write, next),
                addr 0x116b63000 len 65536 (write, next),
                addr 0x116b53000 len 65536 (write, next),
                addr 0x126e9763b len 108 (write, next),
                addr 0x9af8dae7222881a2 len 51 (next)
          avail:
            flags: 0
            idx:   600
            ring:  0
          used:
            flags: 0
            idx:   600

QMP Form:

    { 'command': 'x-query-virtio-queue-element',
      'data': { 'path': 'str', 'queue': 'uint16', '*index': 'uint16' },
      'returns': 'VirtioQueueElement',
      'features': [ 'unstable' ] }

    Example:

        -> { "execute": "x-query-virtio-queue-element",
             "arguments": { "path": "/machine/peripheral-anon/device[2]/virtio-backend",
                            "queue": 2 }
           }
        <- { "return": {
                 "index": 1,
                 "name": "virtio-scsi",
                 "descs": [
                     {
                         "flags": ["write"],
                         "len": 65536,
                         "addr": 4852740096
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852674560
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852609024
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852543488
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852477952
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852412416
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852346880
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852281344
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852215808
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852150272
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852084736
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852019200
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851953664
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851888128
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851822592
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851757056
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851691520
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851625984
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851560448
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851494912
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 108,
                         "addr": 4801325435
                     },
                     {
                         "flags": ["next"],
                         "len": 51,
                         "addr": 12075758188190198449
                     }
                 ],
                 "avail": {
                     "idx": 922,
                     "flags": 0,
                     "ring": 1
                 },
                 "used": {
                     "idx": 922,
                     "flags": 0
                 }
             }
           }

v15: added missing sign-off in patches
rebased for upstream (Qemu 7.1)
minor reformatting to examples in qapi/virtio.json virtio device feature maps moved to hw/virtio/virtio.c virtio device feature maps renamed (less generic) virtio device feature maps now include brief description of feature virtio device status map now include brief description of status new feature bits added to mappings for virtio/vhost-vsock, virtio-iommu, & virtio-mem
new virtio transport feature bit added to mapping
new virtio device feature map defined for virtio-rng

v14: move definition of 'gpu_map' to virtio-gpu.c
add new 'context-init' virtio-gpu feature created new feature map 'i2c_map' for vhost-user-i2c fixed casting error for cross-Win64 builds

v13: minor text edit in qapi/virtio.json

v12: minor reformatting for monitor/hmp-cmds.c
use PRI types in virtio hmp monitor printfs

v11: minor reformatting in virtio.json
added synchronicity check when querying virtio devices

v10: rebased for upstream (Qemu 7.0)
reformat virtio.json for better consistency
removed all enums from virtio.json; replaced with string literals removed @ndescs from VirtioQueueElement
removed examples in hmp-commands-info.hx (to fix 'inconsistent literal block quoting' error from Sphinx)

v9: rebased for upstream (Qemu 6.3)
change QMP command prefixes from 'x-debug-virtio' to 'x-query-virtio'
add 'unstable' feature to all 'x-query-virtio' prefixed QMP commands
fix odd indentation for qapi/virtio.json device features support for virtio-mem
move HMP sub-commands under 'virtio' top level to 'info' top level

v8: add assert in virtio_id_to_name() to make sure we're
not returning NULL
minor documentation additions to qapi/virtio.json add virtio introspection support for vhost-user-rng

v7: rebased for upstream (Qemu 6.2)
add ability to map between numberic device ID and string device ID (name) for virtio devices add get_vhost() callback function for VirtIODevices expose more fields of VirtIODevice
expose fields of vhost devices
decode vhost user protocol features
decode VirtIODevice configuration statuses vhost support for displaying virtio queue statuses vhost support for displaying vhost queue statuses expose driver and device areas when introspecting a virtio queue element
changed patch attribution

v6: rebased for upstream (Qemu 6.1)
add all virtio/vhost types in same order as include/standard-headers/linux/virtio_ids.h
use QAPI_LIST_PREPEND in qmp_x_debug_query_virtio rather than open coding

v5: rebased for upstream
add device name, used index, and relative indicies to virtio queue-status HMP command
add device name to virtio queue-status QMP command
add new virtio device features

v4: re-send series as v3 didn't reach qemu-devel

v3: use qapi_free_VirtioInfoList() on the head of the list, not on the tail.
Prefix the QMP commands with 'x-debug-'

v2: introduce VirtioType enum
use an enum for the endianness
change field names to stick to naming convertions (s/_/-/) add a patch to decode feature bits
don't check if the queue is empty to allow display of old elements use enum for desc flags
manage indirect desc
decode device features in the HMP command

Laurent Vivier (6):
qmp: add QMP command x-query-virtio
qmp: add QMP command x-query-virtio-status
qmp: decode feature & status bits in virtio-status
qmp: add QMP commands for virtio/vhost queue-status
qmp: add QMP command x-query-virtio-queue-element
hmp: add virtio commands

 hmp-commands-info.hx       |   70 +++
 hw/virtio/meson.build      |    2 +
 hw/virtio/virtio-stub.c    |   42 ++
 hw/virtio/virtio.c         | 1032 ++++++++++++++++++++++++++++++++++++
 include/hw/virtio/vhost.h  |    3 +
 include/hw/virtio/virtio.h |    6 +
 include/monitor/hmp.h      |    5 +
 monitor/hmp-cmds.c         |  310 +++++++++++
 qapi/meson.build           |    1 +
 qapi/qapi-schema.json      |    1 +
 qapi/virtio.json           |  954 +++++++++++++++++++++++++++++++++
 tests/qtest/qmp-cmd-test.c |    1 +
 12 files changed, 2427 insertions(+)
 create mode 100644 hw/virtio/virtio-stub.c
 create mode 100644 qapi/virtio.json
Signature · 1 line
2.31.1
#1 lore raw

PATCH v15 1/6 qmp: add QMP command x-query-virtio

From: Laurent Vivier <[email protected]>

This new command lists all the instances of VirtIODevices with their canonical QOM path and name.

[Jonah: @virtio_list duplicates information that already exists in
the QOM composition tree. However, extracting necessary information from this tree seems to be a bit convoluted.

Instead, we still create our own list of realized virtio devices but use @qmp_qom_get with the device's canonical QOM path to confirm that the device exists and is realized. If the device exists but is actually not realized, then we remove it from our list (for synchronicity to the QOM composition tree).

Also, the QMP command @x-query-virtio is redundant as @qom-list and @qom-get are sufficient to search '/machine/' for realized virtio devices. However, @x-query-virtio is much more convenient in listing realized virtio devices.]

---
 hw/virtio/meson.build      |  2 ++
 hw/virtio/virtio-stub.c    | 14 ++++++++
 hw/virtio/virtio.c         | 44 ++++++++++++++++++++++++
 include/hw/virtio/virtio.h |  1 +
 qapi/meson.build           |  1 +
 qapi/qapi-schema.json      |  1 +
 qapi/virtio.json           | 68 ++++++++++++++++++++++++++++++++++++++
 tests/qtest/qmp-cmd-test.c |  1 +
 8 files changed, 132 insertions(+)
 create mode 100644 hw/virtio/virtio-stub.c
 create mode 100644 qapi/virtio.json
hw/virtio/meson.build +2 -0
index 7e8877fd64..e16f1b22d4 100644
@@ -60,4 +60,6 @@ virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss)
 specific_ss.add_all(when: 'CONFIG_VIRTIO', if_true: virtio_ss)
 softmmu_ss.add_all(when: 'CONFIG_VIRTIO', if_true: softmmu_virtio_ss)
 softmmu_ss.add(when: 'CONFIG_VIRTIO', if_false: files('vhost-stub.c'))
+softmmu_ss.add(when: 'CONFIG_VIRTIO', if_false: files('virtio-stub.c'))
 softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-stub.c'))
+softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('virtio-stub.c'))
hw/virtio/virtio-stub.c new file +14 -0
new file mode 100644
index 0000000000..05a81edc92
@@ -0,0 +1,14 @@
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-virtio.h"
+
+static void *qmp_virtio_unsupported(Error **errp)
+{
+    error_setg(errp, "Virtio is disabled");
+    return NULL;
+}
+
+VirtioInfoList *qmp_x_query_virtio(Error **errp)
+{
+    return qmp_virtio_unsupported(errp);
+}
hw/virtio/virtio.c +44 -0

86 lines not on this page · raw message

include/hw/virtio/virtio.h +1 -0
index db1c0ddf6b..375eb5671b 100644
@@ -110,6 +110,7 @@ struct VirtIODevice
     bool use_guest_notifier_mask;
     AddressSpace *dma_as;
     QLIST_HEAD(, VirtQueue) *vector_queues;
+    QTAILQ_ENTRY(VirtIODevice) next;
 };
 
 struct VirtioDeviceClass {
qapi/meson.build +1 -0
index fd5c93d643..c35ba874d2 100644
@@ -49,6 +49,7 @@ qapi_all_modules = [
   'stats',
   'trace',
   'transaction',
+  'virtio',
   'yank',
 ]
 if have_system
qapi/qapi-schema.json +1 -0
index 92d7ecc52c..f000b90744 100644
@@ -94,3 +94,4 @@
 { 'include': 'acpi.json' }
 { 'include': 'pci.json' }
 { 'include': 'stats.json' }
+{ 'include': 'virtio.json' }
qapi/virtio.json new file +68 -0

68 lines not on this page · raw message

tests/qtest/qmp-cmd-test.c +1 -0
index af00712458..897e4e937b 100644
@@ -103,6 +103,7 @@ static bool query_is_ignored(const char *cmd)
         "query-gic-capabilities", /* arm */
         /* Success depends on target-specific build configuration: */
         "query-pci",              /* CONFIG_PCI */
+        "x-query-virtio",         /* CONFIG_VIRTIO */
         /* Success depends on launching SEV guest */
         "query-sev-launch-measure",
         /* Success depends on Host or Hypervisor SEV support */
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio

Hi,

Quoted 101 lines · Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command lists all the instances of VirtIODevices with their canonical QOM path and name.

[Jonah: @virtio_list duplicates information that already exists in
the QOM composition tree. However, extracting necessary information from this tree seems to be a bit convoluted.

Instead, we still create our own list of realized virtio devices but use @qmp_qom_get with the device's canonical QOM path to confirm that the device exists and is realized. If the device exists but is actually not realized, then we remove it from our list (for synchronicity to the QOM composition tree).

Also, the QMP command @x-query-virtio is redundant as @qom-list and @qom-get are sufficient to search '/machine/' for realized virtio devices. However, @x-query-virtio is much more convenient in listing realized virtio devices.]

---
  hw/virtio/meson.build      |  2 ++
  hw/virtio/virtio-stub.c    | 14 ++++++++
  hw/virtio/virtio.c         | 44 ++++++++++++++++++++++++
  include/hw/virtio/virtio.h |  1 +
  qapi/meson.build           |  1 +
  qapi/qapi-schema.json      |  1 +
  qapi/virtio.json           | 68 ++++++++++++++++++++++++++++++++++++++
  tests/qtest/qmp-cmd-test.c |  1 +
  8 files changed, 132 insertions(+)

create mode 100644 hw/virtio/virtio-stub.c
create mode 100644 qapi/virtio.json

hw/virtio/virtio.c +17 -0
index 5d607aeaa0..bdfa82e9c0 100644
@@ -13,12 +13,18 @@
 
  #include "qemu/osdep.h"
  #include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/qapi-commands-virtio.h"
+#include "qapi/qapi-commands-qom.h"
+#include "qapi/qapi-visit-virtio.h"
+#include "qapi/qmp/qjson.h"
  #include "cpu.h"
  #include "trace.h"
  #include "qemu/error-report.h"
  #include "qemu/log.h"
  #include "qemu/main-loop.h"
  #include "qemu/module.h"
+#include "qom/object_interfaces.h"
  #include "hw/virtio/virtio.h"
  #include "migration/qemu-file-types.h"
  #include "qemu/atomic.h"
@@ -29,6 +35,9 @@
  #include "sysemu/runstate.h"
  #include "standard-headers/linux/virtio_ids.h"
 
+/* QAPI list of realized VirtIODevices */
+static QTAILQ_HEAD(, VirtIODevice) virtio_list;
+
  /*
   * The alignment to use between consumer and producer parts of vring.
   * x86 pagesize again. This is the default, used by transports like PCI
@@ -3698,6 +3707,7 @@ static void virtio_device_realize(DeviceState *dev, Error **errp)
      vdev->listener.commit = virtio_memory_listener_commit;
      vdev->listener.name = "virtio";
      memory_listener_register(&vdev->listener, vdev->dma_as);
+    QTAILQ_INSERT_TAIL(&virtio_list, vdev, next);
  }
 
  static void virtio_device_unrealize(DeviceState *dev)
@@ -3712,6 +3722,7 @@ static void virtio_device_unrealize(DeviceState *dev)
          vdc->unrealize(dev);
      }
 
+    QTAILQ_REMOVE(&virtio_list, vdev, next);
      g_free(vdev->bus_name);
      vdev->bus_name = NULL;
  }
@@ -3885,6 +3896,8 @@ static void virtio_device_class_init(ObjectClass *klass, void *data)
      vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl;
 
      vdc->legacy_features |= VIRTIO_LEGACY_FEATURES;
+
+    QTAILQ_INIT(&virtio_list);
  }
 
  bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
@@ -3895,6 +3908,37 @@ bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
      return virtio_bus_ioeventfd_enabled(vbus);
  }
 
+VirtioInfoList *qmp_x_query_virtio(Error **errp)
+{
+    VirtioInfoList *list = NULL;
+    VirtioInfoList *node;

hw/virtio/virtio.c bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev) · line 3924

Quoted 10 lines
hw/virtio/virtio.c +10 -0
+    VirtIODevice *vdev;
+
+    QTAILQ_FOREACH(vdev, &virtio_list, next) {
+        DeviceState *dev = DEVICE(vdev);
+        Error *err = NULL;
+        QObject *obj = qmp_qom_get(dev->canonical_path, "realized", &err);
+
+        if (err == NULL) {
+            GString *is_realized = qobject_to_json_pretty(obj, true);
+            /* virtio device is NOT realized, remove it from list */

Why not check dev->realized instead of calling qmp_qom_get() & qobject_to_json_pretty()?

Quoted 16 lines
hw/virtio/virtio.c +16 -0
+            if (!strncmp(is_realized->str, "false", 4)) {
+                QTAILQ_REMOVE(&virtio_list, vdev, next);
+            } else {
+                node = g_new0(VirtioInfoList, 1);
+                node->value = g_new(VirtioInfo, 1);
+                node->value->path = g_strdup(dev->canonical_path);
+                node->value->name = g_strdup(vdev->name);
+                QAPI_LIST_PREPEND(list, node->value);
+            }
+           g_string_free(is_realized, true);
+        }
+        qobject_unref(obj);
+    }
+
+    return list;
+}
#3 lore raw

Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio

Quoted 106 lines · Philippe Mathieu-Daudé

Hi,

Quoted 103 lines · Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command lists all the instances of VirtIODevices with their canonical QOM path and name.

[Jonah: @virtio_list duplicates information that already exists in the QOM composition tree. However, extracting necessary information from this tree seems to be a bit convoluted.

  Instead, we still create our own list of realized virtio devices but use @qmp_qom_get with the device's canonical QOM path to confirm that the device exists and is realized. If the device exists but is actually not realized, then we remove it from our list (for synchronicity to the QOM composition tree).

  Also, the QMP command @x-query-virtio is redundant as @qom-list and @qom-get are sufficient to search '/machine/' for realized virtio devices. However, @x-query-virtio is much more convenient in listing realized virtio devices.]

---
  hw/virtio/meson.build      |  2 ++
  hw/virtio/virtio-stub.c    | 14 ++++++++ hw/virtio/virtio.c         | 44 ++++++++++++++++++++++++ include/hw/virtio/virtio.h |  1 +
  qapi/meson.build           |  1 +
  qapi/qapi-schema.json      |  1 +
  qapi/virtio.json           | 68 ++++++++++++++++++++++++++++++++++++++ tests/qtest/qmp-cmd-test.c |  1 +

  8 files changed, 132 insertions(+)

  create mode 100644 hw/virtio/virtio-stub.c
  create mode 100644 qapi/virtio.json

hw/virtio/virtio.c +6 -0
index 5d607aeaa0..bdfa82e9c0 100644
@@ -13,12 +13,18 @@
     #include "qemu/osdep.h"
   #include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/qapi-commands-virtio.h"
+#include "qapi/qapi-commands-qom.h"
+#include "qapi/qapi-visit-virtio.h"
+#include "qapi/qmp/qjson.h"
   #include "cpu.h"
   #include "trace.h"
   #include "qemu/error-report.h"
   #include "qemu/log.h"
   #include "qemu/main-loop.h"
   #include "qemu/module.h"
+#include "qom/object_interfaces.h"
   #include "hw/virtio/virtio.h"
   #include "migration/qemu-file-types.h"
   #include "qemu/atomic.h"
@@ -29,6 +35,9 @@
   #include "sysemu/runstate.h"
   #include "standard-headers/linux/virtio_ids.h"

  +/* QAPI list of realized VirtIODevices */

hw/virtio/virtio.c +2 -0
+static QTAILQ_HEAD(, VirtIODevice) virtio_list;
+

  /*
   * The alignment to use between consumer and producer parts of vring.
   * x86 pagesize again. This is the default, used by transports like PCI

hw/virtio/virtio.c +1 -0
@@ -3698,6 +3707,7 @@ static void virtio_device_realize(DeviceState 
 *dev, Error **errp)
       vdev->listener.commit = virtio_memory_listener_commit;
       vdev->listener.name = "virtio";
       memory_listener_register(&vdev->listener, vdev->dma_as);
+    QTAILQ_INSERT_TAIL(&virtio_list, vdev, next);
   }
     static void virtio_device_unrealize(DeviceState *dev)
@@ -3712,6 +3722,7 @@ static void virtio_device_unrealize(DeviceState 
 *dev)
           vdc->unrealize(dev);
       }
   +    QTAILQ_REMOVE(&virtio_list, vdev, next);
       g_free(vdev->bus_name);
       vdev->bus_name = NULL;

  }

hw/virtio/virtio.c +10 -0
@@ -3885,6 +3896,8 @@ static void 
 virtio_device_class_init(ObjectClass *klass, void *data)
       vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl;
         vdc->legacy_features |= VIRTIO_LEGACY_FEATURES;
+
+    QTAILQ_INIT(&virtio_list);
   }
     bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
@@ -3895,6 +3908,37 @@ bool 
 virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
       return virtio_bus_ioeventfd_enabled(vbus);
   }
   +VirtioInfoList *qmp_x_query_virtio(Error **errp)
+{
+    VirtioInfoList *list = NULL;
+    VirtioInfoList *node;
+    VirtIODevice *vdev;
+
+    QTAILQ_FOREACH(vdev, &virtio_list, next) {
+        DeviceState *dev = DEVICE(vdev);
+        Error *err = NULL;
Quoted 8 lines

hw/virtio/virtio.c bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev) · line 3924

Quoted 6 lines
hw/virtio/virtio.c +5 -0
+        QObject *obj = qmp_qom_get(dev->canonical_path, "realized", 
 &err);
+
+        if (err == NULL) {
+            GString *is_realized = qobject_to_json_pretty(obj, true);
+            /* virtio device is NOT realized, remove it from list */

Why not check dev->realized instead of calling qmp_qom_get() & qobject_to_json_pretty()?

This check queries the QOM composition tree to check that the device actually exists and is realized. In other words, we just want to confirm with the QOM composition tree for the device.

This was done to have some kind of synchronicity between @virtio_list and the QOM composition tree, since the list duplicates information that already exists in the tree.

This check was recommended in v10 and added in v11 of this patch series.

Quoted 17 lines
Quoted 17 lines
hw/virtio/virtio.c +16 -0
+            if (!strncmp(is_realized->str, "false", 4)) {
+                QTAILQ_REMOVE(&virtio_list, vdev, next);
+            } else {
+                node = g_new0(VirtioInfoList, 1);
+                node->value = g_new(VirtioInfo, 1);
+                node->value->path = g_strdup(dev->canonical_path);
+                node->value->name = g_strdup(vdev->name);
+                QAPI_LIST_PREPEND(list, node->value);
+            }
+           g_string_free(is_realized, true);
+        }
+        qobject_unref(obj);
+    }
+
+    return list;
+}
#4 lore raw

Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio

Quoted 117 lines · Jonah Palmer
Quoted 106 lines · Philippe Mathieu-Daudé

Hi,

Quoted 103 lines · Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command lists all the instances of VirtIODevices with their canonical QOM path and name.

[Jonah: @virtio_list duplicates information that already exists in the QOM composition tree. However, extracting necessary information from this tree seems to be a bit convoluted.

  Instead, we still create our own list of realized virtio devices but use @qmp_qom_get with the device's canonical QOM path to confirm that the device exists and is realized. If the device exists but is actually not realized, then we remove it from our list (for synchronicity to the QOM composition tree).

  Also, the QMP command @x-query-virtio is redundant as @qom-list and @qom-get are sufficient to search '/machine/' for realized virtio devices. However, @x-query-virtio is much more convenient in listing realized virtio devices.]

---
  hw/virtio/meson.build      |  2 ++
  hw/virtio/virtio-stub.c    | 14 ++++++++ hw/virtio/virtio.c         | 44 ++++++++++++++++++++++++ include/hw/virtio/virtio.h |  1 +
  qapi/meson.build           |  1 +
  qapi/qapi-schema.json      |  1 +
  qapi/virtio.json           | 68 ++++++++++++++++++++++++++++++++++++++ tests/qtest/qmp-cmd-test.c |  1 +

  8 files changed, 132 insertions(+)

  create mode 100644 hw/virtio/virtio-stub.c
  create mode 100644 qapi/virtio.json

hw/virtio/virtio.c +6 -0
index 5d607aeaa0..bdfa82e9c0 100644
@@ -13,12 +13,18 @@
     #include "qemu/osdep.h"
   #include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/qapi-commands-virtio.h"
+#include "qapi/qapi-commands-qom.h"
+#include "qapi/qapi-visit-virtio.h"
+#include "qapi/qmp/qjson.h"
   #include "cpu.h"
   #include "trace.h"
   #include "qemu/error-report.h"
   #include "qemu/log.h"
   #include "qemu/main-loop.h"
   #include "qemu/module.h"
+#include "qom/object_interfaces.h"
   #include "hw/virtio/virtio.h"
   #include "migration/qemu-file-types.h"
   #include "qemu/atomic.h"
@@ -29,6 +35,9 @@
   #include "sysemu/runstate.h"
   #include "standard-headers/linux/virtio_ids.h"

  +/* QAPI list of realized VirtIODevices */

hw/virtio/virtio.c +2 -0
+static QTAILQ_HEAD(, VirtIODevice) virtio_list;
+

  /*
   * The alignment to use between consumer and producer parts of vring.
   * x86 pagesize again. This is the default, used by transports like PCI

hw/virtio/virtio.c +1 -0
@@ -3698,6 +3707,7 @@ static void virtio_device_realize(DeviceState 
 *dev, Error **errp)
       vdev->listener.commit = virtio_memory_listener_commit;
       vdev->listener.name = "virtio";
       memory_listener_register(&vdev->listener, vdev->dma_as);
+    QTAILQ_INSERT_TAIL(&virtio_list, vdev, next);
   }
     static void virtio_device_unrealize(DeviceState *dev)
@@ -3712,6 +3722,7 @@ static void virtio_device_unrealize(DeviceState 
 *dev)
           vdc->unrealize(dev);
       }
   +    QTAILQ_REMOVE(&virtio_list, vdev, next);
       g_free(vdev->bus_name);
       vdev->bus_name = NULL;

  }

hw/virtio/virtio.c +10 -0
@@ -3885,6 +3896,8 @@ static void 
 virtio_device_class_init(ObjectClass *klass, void *data)
       vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl;
         vdc->legacy_features |= VIRTIO_LEGACY_FEATURES;
+
+    QTAILQ_INIT(&virtio_list);
   }
     bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
@@ -3895,6 +3908,37 @@ bool 
 virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
       return virtio_bus_ioeventfd_enabled(vbus);
   }
   +VirtioInfoList *qmp_x_query_virtio(Error **errp)
+{
+    VirtioInfoList *list = NULL;
+    VirtioInfoList *node;
+    VirtIODevice *vdev;
+
+    QTAILQ_FOREACH(vdev, &virtio_list, next) {
+        DeviceState *dev = DEVICE(vdev);
+        Error *err = NULL;
Quoted 8 lines

hw/virtio/virtio.c bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev) · line 3924

Quoted 6 lines
hw/virtio/virtio.c +5 -0
+        QObject *obj = qmp_qom_get(dev->canonical_path, "realized", 
 &err);
+
+        if (err == NULL) {
+            GString *is_realized = qobject_to_json_pretty(obj, true);
+            /* virtio device is NOT realized, remove it from list */

Why not check dev->realized instead of calling qmp_qom_get() & qobject_to_json_pretty()?

Quoted 7 lines

This check queries the QOM composition tree to check that the device actually exists and is realized. In other words, we just want to confirm with the QOM composition tree for the device.

This was done to have some kind of synchronicity between @virtio_list and the QOM composition tree, since the list duplicates information that already exists in the tree.

This check was recommended in v10 and added in v11 of this patch series.

Thanks, I found Markus comments:

v10:
https://lore.kernel.org/qemu-devel/[email protected]/
v11:
https://lore.kernel.org/qemu-devel/[email protected]/

Having the justification from v11 in the code rather than the commit description could help.

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
hw/virtio/virtio.c +16 -0
+            if (!strncmp(is_realized->str, "false", 4)) {
+                QTAILQ_REMOVE(&virtio_list, vdev, next);
+            } else {
+                node = g_new0(VirtioInfoList, 1);
+                node->value = g_new(VirtioInfo, 1);
+                node->value->path = g_strdup(dev->canonical_path);
+                node->value->name = g_strdup(vdev->name);
+                QAPI_LIST_PREPEND(list, node->value);
+            }
+           g_string_free(is_realized, true);
+        }
+        qobject_unref(obj);
+    }
+
+    return list;
+}
#5 lore raw

Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio

Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Jonah Palmer
Quoted 12 lines · Philippe Mathieu-Daudé

Hi,

Quoted 9 lines · Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command lists all the instances of VirtIODevices with their canonical QOM path and name.

[Jonah: @virtio_list duplicates information that already exists in the QOM composition tree. However, extracting necessary information from this tree seems to be a bit convoluted.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

  Instead, we still create our own list of realized virtio devices but use @qmp_qom_get with the device's canonical QOM path to confirm that the device exists and is realized. If the device exists but is actually not realized, then we remove it from our list (for synchronicity to the QOM composition tree).

How could this happen?

Quoted 93 lines
Quoted 93 lines
Quoted 92 lines
Quoted 80 lines

  Also, the QMP command @x-query-virtio is redundant as @qom-list and @qom-get are sufficient to search '/machine/' for realized virtio devices. However, @x-query-virtio is much more convenient in listing realized virtio devices.]

---
  hw/virtio/meson.build      |  2 ++
  hw/virtio/virtio-stub.c    | 14 ++++++++ hw/virtio/virtio.c         | 44 ++++++++++++++++++++++++ include/hw/virtio/virtio.h |  1 +
  qapi/meson.build           |  1 +
  qapi/qapi-schema.json      |  1 +
  qapi/virtio.json           | 68 ++++++++++++++++++++++++++++++++++++++ tests/qtest/qmp-cmd-test.c |  1 +

  8 files changed, 132 insertions(+)

  create mode 100644 hw/virtio/virtio-stub.c
  create mode 100644 qapi/virtio.json

hw/virtio/virtio.c +6 -0
index 5d607aeaa0..bdfa82e9c0 100644
@@ -13,12 +13,18 @@
     #include "qemu/osdep.h"
   #include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/qapi-commands-virtio.h"
+#include "qapi/qapi-commands-qom.h"
+#include "qapi/qapi-visit-virtio.h"
+#include "qapi/qmp/qjson.h"
   #include "cpu.h"
   #include "trace.h"
   #include "qemu/error-report.h"
   #include "qemu/log.h"
   #include "qemu/main-loop.h"
   #include "qemu/module.h"
+#include "qom/object_interfaces.h"
   #include "hw/virtio/virtio.h"
   #include "migration/qemu-file-types.h"
   #include "qemu/atomic.h"
@@ -29,6 +35,9 @@
   #include "sysemu/runstate.h"
   #include "standard-headers/linux/virtio_ids.h"

  +/* QAPI list of realized VirtIODevices */

hw/virtio/virtio.c +2 -0
+static QTAILQ_HEAD(, VirtIODevice) virtio_list;
+

  /*
   * The alignment to use between consumer and producer parts of vring.
   * x86 pagesize again. This is the default, used by transports like PCI

hw/virtio/virtio.c +6 -0
@@ -3698,6 +3707,7 @@ static void virtio_device_realize(DeviceState *dev, Error **errp)
       vdev->listener.commit = virtio_memory_listener_commit;
       vdev->listener.name = "virtio";
       memory_listener_register(&vdev->listener, vdev->dma_as);
+    QTAILQ_INSERT_TAIL(&virtio_list, vdev, next);
   }
     static void virtio_device_unrealize(DeviceState *dev)
@@ -3712,6 +3722,7 @@ static void virtio_device_unrealize(DeviceState *dev)
           vdc->unrealize(dev);
       }
   +    QTAILQ_REMOVE(&virtio_list, vdev, next);
       g_free(vdev->bus_name);
       vdev->bus_name = NULL;
   }
@@ -3885,6 +3896,8 @@ static void virtio_device_class_init(ObjectClass *klass, void *data)
       vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl;
         vdc->legacy_features |= VIRTIO_LEGACY_FEATURES;
+
+    QTAILQ_INIT(&virtio_list);
   }
     bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
@@ -3895,6 +3908,37 @@ bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
       return virtio_bus_ioeventfd_enabled(vbus);
   }
   +VirtioInfoList *qmp_x_query_virtio(Error **errp)
+{
+    VirtioInfoList *list = NULL;
+    VirtioInfoList *node;

hw/virtio/virtio.c bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev) · line 3923

Quoted 10 lines
hw/virtio/virtio.c +10 -0
+    VirtIODevice *vdev;
+
+    QTAILQ_FOREACH(vdev, &virtio_list, next) {
+        DeviceState *dev = DEVICE(vdev);
+        Error *err = NULL;
+        QObject *obj = qmp_qom_get(dev->canonical_path, "realized", &err);
+
+        if (err == NULL) {
+            GString *is_realized = qobject_to_json_pretty(obj, true);
+            /* virtio device is NOT realized, remove it from list */

Why not check dev->realized instead of calling qmp_qom_get() & qobject_to_json_pretty()?

Quoted 2 lines
Quoted 2 lines

This check queries the QOM composition tree to check that the device actually exists and is realized. In other words, we just want to confirm with the QOM composition tree for the device.

Again, how could this happen?

If @virtio_list isn't reliable, why have it in the first place?

Quoted 8 lines
Quoted 3 lines

This was done to have some kind of synchronicity between @virtio_list and the QOM composition tree, since the list duplicates information that already exists in the tree. This check was recommended in v10 and added in v11 of this patch series.

Thanks, I found Markus comments:

v10:
https://lore.kernel.org/qemu-devel/[email protected]/

My recommendation there was to *delete* virtio_list and search the QOM composition tree instead:

@virtio_list duplicates information that exists in the QOM composition tree. It needs to stay in sync. You could search the composition tree instead.

The QOM composition tree is the source of truth.

This above is about the command's implementation, and ...

Quoted 5 lines

v11:
https://lore.kernel.org/qemu-devel/[email protected]/

Having the justification from v11 in the code rather than the commit description could help.

... this part is about why the command could be useful.

[...]

#6 lore raw

Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio

Quoted 112 lines · Markus Armbruster
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Jonah Palmer
Quoted 12 lines · Philippe Mathieu-Daudé

Hi,

Quoted 9 lines · Jonah Palmer

From: Laurent Vivier<[email protected]>

This new command lists all the instances of VirtIODevices with their canonical QOM path and name.

[Jonah: @virtio_list duplicates information that already exists in
  the QOM composition tree. However, extracting necessary information from this tree seems to be a bit convoluted.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

  Instead, we still create our own list of realized virtio devices but use @qmp_qom_get with the device's canonical QOM path to confirm that the device exists and is realized. If the device exists but is actually not realized, then we remove it from our list (for synchronicity to the QOM composition tree).

How could this happen?

Quoted 89 lines
Quoted 89 lines
Quoted 89 lines
Quoted 78 lines

  Also, the QMP command @x-query-virtio is redundant as @qom-list and @qom-get are sufficient to search '/machine/' for realized virtio devices. However, @x-query-virtio is much more convenient in listing realized virtio devices.]

---
   hw/virtio/meson.build      |  2 ++
   hw/virtio/virtio-stub.c    | 14 ++++++++
   hw/virtio/virtio.c         | 44 ++++++++++++++++++++++++
   include/hw/virtio/virtio.h |  1 +
   qapi/meson.build           |  1 +
   qapi/qapi-schema.json      |  1 +
   qapi/virtio.json           | 68 ++++++++++++++++++++++++++++++++++++++
   tests/qtest/qmp-cmd-test.c |  1 +
   8 files changed, 132 insertions(+)

  create mode 100644 hw/virtio/virtio-stub.c
  create mode 100644 qapi/virtio.json

hw/virtio/virtio.c +14 -0
index 5d607aeaa0..bdfa82e9c0 100644
@@ -13,12 +13,18 @@
     #include "qemu/osdep.h"
   #include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/qapi-commands-virtio.h"
+#include "qapi/qapi-commands-qom.h"
+#include "qapi/qapi-visit-virtio.h"
+#include "qapi/qmp/qjson.h"
   #include "cpu.h"
   #include "trace.h"
   #include "qemu/error-report.h"
   #include "qemu/log.h"
   #include "qemu/main-loop.h"
   #include "qemu/module.h"
+#include "qom/object_interfaces.h"
   #include "hw/virtio/virtio.h"
   #include "migration/qemu-file-types.h"
   #include "qemu/atomic.h"
@@ -29,6 +35,9 @@
   #include "sysemu/runstate.h"
   #include "standard-headers/linux/virtio_ids.h"
   +/* QAPI list of realized VirtIODevices */
+static QTAILQ_HEAD(, VirtIODevice) virtio_list;
+
   /*
    * The alignment to use between consumer and producer parts of vring.
    * x86 pagesize again. This is the default, used by transports like PCI
@@ -3698,6 +3707,7 @@ static void virtio_device_realize(DeviceState *dev, Error **errp)
       vdev->listener.commit = virtio_memory_listener_commit;
       vdev->listener.name = "virtio";
       memory_listener_register(&vdev->listener, vdev->dma_as);
+    QTAILQ_INSERT_TAIL(&virtio_list, vdev, next);
   }
     static void virtio_device_unrealize(DeviceState *dev)
@@ -3712,6 +3722,7 @@ static void virtio_device_unrealize(DeviceState *dev)
           vdc->unrealize(dev);
       }
   +    QTAILQ_REMOVE(&virtio_list, vdev, next);
       g_free(vdev->bus_name);
       vdev->bus_name = NULL;
   }
@@ -3885,6 +3896,8 @@ static void virtio_device_class_init(ObjectClass *klass, void *data)
       vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl;
         vdc->legacy_features |= VIRTIO_LEGACY_FEATURES;
+
+    QTAILQ_INIT(&virtio_list);
   }
     bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
@@ -3895,6 +3908,37 @@ bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
       return virtio_bus_ioeventfd_enabled(vbus);
   }
   +VirtioInfoList *qmp_x_query_virtio(Error **errp)
+{
+    VirtioInfoList *list = NULL;
+    VirtioInfoList *node;

hw/virtio/virtio.c bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev) · line 3923

Quoted 10 lines
hw/virtio/virtio.c +10 -0
+    VirtIODevice *vdev;
+
+    QTAILQ_FOREACH(vdev, &virtio_list, next) {
+        DeviceState *dev = DEVICE(vdev);
+        Error *err = NULL;
+        QObject *obj = qmp_qom_get(dev->canonical_path, "realized", &err);
+
+        if (err == NULL) {
+            GString *is_realized = qobject_to_json_pretty(obj, true);
+            /* virtio device is NOT realized, remove it from list */

Why not check dev->realized instead of calling qmp_qom_get() & qobject_to_json_pretty()?

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

This check queries the QOM composition tree to check that the device actually exists and is realized. In other words, we just want to confirm with the QOM composition tree for the device.

Again, how could this happen?

If @virtio_list isn't reliable, why have it in the first place?

Honestly, I'm not sure how this even could happen, since the @virtio_list is managed at the realization
and unrealization of a virtio device. Given this, I do feel as though the list is reliable, although
this might just benaïve of me to say. After giving this a second look, the @virtio_list is only really needed to provide a nice list of all realized virtio devices on the system, along with their full canonical paths. If the user can find the canonical path of a virtio device by searching the QOM composition tree, and assuming we can get a @VirtioDevice object (in code) from this canonical path, then the rest of the QMP/HMP features of these patches could be done by solely by searching the QOM composition tree. However, I think having this list of realized virtio devices as a subset of the QOM composition tree is worth its weight, since the user no longer has to search the entire tree to find virtio devices and piece together their canonical paths. Of course, if we're somehow able to generate a similar list in code by searching the QOM composition tree, then there would be no need for this @virtio_list. However, it's really not clear how, or if, such a list could be generated by parsing the QOM composition tree.

Quoted 27 lines
Quoted 7 lines
Quoted 3 lines

This was done to have some kind of synchronicity between @virtio_list and the QOM composition tree, since the list duplicates information that already exists in the tree. This check was recommended in v10 and added in v11 of this patch series.

Thanks, I found Markus comments:

v10:

https://urldefense.com/v3/__https://lore.kernel.org/qemu-devel/[email protected]/__;!!ACWV5N9M2RV99hQ!LqeLFhE8PtTTg_qKRuP9Kgz5pyTNZLhYeRzp4a2oS8c3D5W8-irZoBW0L_Lf1ozm3qYidYhuVrjxjsAw$  

My recommendation there was to *delete* virtio_list and search the QOM composition tree instead:

@virtio_list duplicates information that exists in the QOM composition tree. It needs to stay in sync. You could search the composition tree instead.

The QOM composition tree is the source of truth.

This above is about the command's implementation, and ...

Quoted 5 lines

v11:

https://urldefense.com/v3/__https://lore.kernel.org/qemu-devel/[email protected]/__;!!ACWV5N9M2RV99hQ!LqeLFhE8PtTTg_qKRuP9Kgz5pyTNZLhYeRzp4a2oS8c3D5W8-irZoBW0L_Lf1ozm3qYidYhuVmVCuHjV$  

Having the justification from v11 in the code rather than the commit description could help.

... this part is about why the command could be useful.

[...]

#7 lore raw

Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio

Quoted 123 lines · Jonah Palmer
Quoted 115 lines · Markus Armbruster
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Jonah Palmer
Quoted 12 lines · Philippe Mathieu-Daudé

Hi,

Quoted 9 lines · Jonah Palmer

From: Laurent Vivier<[email protected]>

This new command lists all the instances of VirtIODevices with their canonical QOM path and name.

[Jonah: @virtio_list duplicates information that already exists in
  the QOM composition tree. However, extracting necessary information from this tree seems to be a bit convoluted.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

  Instead, we still create our own list of realized virtio devices but use @qmp_qom_get with the device's canonical QOM path to confirm that the device exists and is realized. If the device exists but is actually not realized, then we remove it from our list (for synchronicity to the QOM composition tree).

How could this happen?

Quoted 91 lines
Quoted 91 lines
Quoted 90 lines
Quoted 78 lines

  Also, the QMP command @x-query-virtio is redundant as @qom-list and @qom-get are sufficient to search '/machine/' for realized virtio devices. However, @x-query-virtio is much more convenient in listing realized virtio devices.]

---
   hw/virtio/meson.build      |  2 ++
   hw/virtio/virtio-stub.c    | 14 ++++++++
   hw/virtio/virtio.c         | 44 ++++++++++++++++++++++++
   include/hw/virtio/virtio.h |  1 +
   qapi/meson.build           |  1 +
   qapi/qapi-schema.json      |  1 +
   qapi/virtio.json           | 68 ++++++++++++++++++++++++++++++++++++++
   tests/qtest/qmp-cmd-test.c |  1 +
   8 files changed, 132 insertions(+)

  create mode 100644 hw/virtio/virtio-stub.c
  create mode 100644 qapi/virtio.json

hw/virtio/virtio.c +14 -0
index 5d607aeaa0..bdfa82e9c0 100644
@@ -13,12 +13,18 @@
     #include "qemu/osdep.h"
   #include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/qapi-commands-virtio.h"
+#include "qapi/qapi-commands-qom.h"
+#include "qapi/qapi-visit-virtio.h"
+#include "qapi/qmp/qjson.h"
   #include "cpu.h"
   #include "trace.h"
   #include "qemu/error-report.h"
   #include "qemu/log.h"
   #include "qemu/main-loop.h"
   #include "qemu/module.h"
+#include "qom/object_interfaces.h"
   #include "hw/virtio/virtio.h"
   #include "migration/qemu-file-types.h"
   #include "qemu/atomic.h"
@@ -29,6 +35,9 @@
   #include "sysemu/runstate.h"
   #include "standard-headers/linux/virtio_ids.h"
   +/* QAPI list of realized VirtIODevices */
+static QTAILQ_HEAD(, VirtIODevice) virtio_list;
+
   /*
    * The alignment to use between consumer and producer parts of vring.
    * x86 pagesize again. This is the default, used by transports like PCI
@@ -3698,6 +3707,7 @@ static void virtio_device_realize(DeviceState *dev, Error **errp)
       vdev->listener.commit = virtio_memory_listener_commit;
       vdev->listener.name = "virtio";
       memory_listener_register(&vdev->listener, vdev->dma_as);
+    QTAILQ_INSERT_TAIL(&virtio_list, vdev, next);
   }
     static void virtio_device_unrealize(DeviceState *dev)
@@ -3712,6 +3722,7 @@ static void virtio_device_unrealize(DeviceState *dev)
           vdc->unrealize(dev);
       }
   +    QTAILQ_REMOVE(&virtio_list, vdev, next);
       g_free(vdev->bus_name);
       vdev->bus_name = NULL;
   }
@@ -3885,6 +3896,8 @@ static void virtio_device_class_init(ObjectClass *klass, void *data)
       vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl;
         vdc->legacy_features |= VIRTIO_LEGACY_FEATURES;
+
+    QTAILQ_INIT(&virtio_list);
   }
     bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
@@ -3895,6 +3908,37 @@ bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
       return virtio_bus_ioeventfd_enabled(vbus);
   }
   +VirtioInfoList *qmp_x_query_virtio(Error **errp)
+{
+    VirtioInfoList *list = NULL;
+    VirtioInfoList *node;

hw/virtio/virtio.c bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev) · line 3923

Quoted 10 lines
hw/virtio/virtio.c +10 -0
+    VirtIODevice *vdev;
+
+    QTAILQ_FOREACH(vdev, &virtio_list, next) {
+        DeviceState *dev = DEVICE(vdev);
+        Error *err = NULL;
+        QObject *obj = qmp_qom_get(dev->canonical_path, "realized", &err);
+
+        if (err == NULL) {
+            GString *is_realized = qobject_to_json_pretty(obj, true);
+            /* virtio device is NOT realized, remove it from list */

Why not check dev->realized instead of calling qmp_qom_get() & qobject_to_json_pretty()?

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

This check queries the QOM composition tree to check that the device actually exists and is realized. In other words, we just want to confirm with the QOM composition tree for the device.

Again, how could this happen?

If @virtio_list isn't reliable, why have it in the first place?

Quoted 10 lines

Honestly, I'm not sure how this even could happen, since the @virtio_list is managed at the realization
and unrealization of a virtio device. Given this, I do feel as though the list is reliable, although
this might just benaïve of me to say. After giving this a second look, the @virtio_list is only really needed to provide a nice list of all realized virtio devices on the system, along with their full canonical paths. If the user can find the canonical path of a virtio device by searching the QOM composition tree, and assuming we can get a @VirtioDevice object (in code) from this canonical path, then the rest of the QMP/HMP features of these patches could be done by solely by searching the QOM composition tree. However, I think having this list of realized virtio devices as a subset of the QOM composition tree is worth its weight, since the user no longer has to search the entire tree to find virtio devices and piece together their canonical paths. Of course, if we're somehow able to generate a similar list in code by searching the QOM composition tree, then there would be no need for this @virtio_list. However, it's really not clear how, or if, such a list could be generated by parsing the QOM composition tree.

I'm not debating whether to have the command right now. I'm debating the introduction of variable @virtio_list. Please consider...

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

This was done to have some kind of synchronicity between @virtio_list and the QOM composition tree, since the list duplicates information that already exists in the tree. This check was recommended in v10 and added in v11 of this patch series.

Thanks, I found Markus comments:

v10:

https://urldefense.com/v3/__https://lore.kernel.org/qemu-devel/[email protected]/__;!!ACWV5N9M2RV99hQ!LqeLFhE8PtTTg_qKRuP9Kgz5pyTNZLhYeRzp4a2oS8c3D5W8-irZoBW0L_Lf1ozm3qYidYhuVrjxjsAw$  

... this:

Quoted 8 lines
Quoted 8 lines

My recommendation there was to *delete* virtio_list and search the QOM composition tree instead:

@virtio_list duplicates information that exists in the QOM composition tree. It needs to stay in sync. You could search the composition tree instead.

The QOM composition tree is the source of truth.

Let me tell you a tale of two patches.

One created a niche QMP command. It also modified core infrastructure to keep additional state. State that needed to be kept consistent with existing state forever. Consistency was not entirely obvious. The command examined this new state. The examination was simple.

The other one created a niche QMP command, and nothing more. The command examined state without changing it. The examination was less simple.

One of the two patches had a much easier time in review. Which one could it be...

Please give the other approach a serious try.

[...]

#8 lore raw

Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio

Quoted 157 lines · Markus Armbruster
Quoted 118 lines · Jonah Palmer
Quoted 112 lines · Markus Armbruster
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Jonah Palmer
Quoted 12 lines · Philippe Mathieu-Daudé

Hi,

Quoted 9 lines · Jonah Palmer

From: Laurent Vivier<[email protected]>

This new command lists all the instances of VirtIODevices with their canonical QOM path and name.

[Jonah: @virtio_list duplicates information that already exists in
  the QOM composition tree. However, extracting necessary information from this tree seems to be a bit convoluted.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

  Instead, we still create our own list of realized virtio devices but use @qmp_qom_get with the device's canonical QOM path to confirm that the device exists and is realized. If the device exists but is actually not realized, then we remove it from our list (for synchronicity to the QOM composition tree).

How could this happen?

Quoted 89 lines
Quoted 89 lines
Quoted 89 lines
Quoted 78 lines

  Also, the QMP command @x-query-virtio is redundant as @qom-list and @qom-get are sufficient to search '/machine/' for realized virtio devices. However, @x-query-virtio is much more convenient in listing realized virtio devices.]

---
    hw/virtio/meson.build      |  2 ++
    hw/virtio/virtio-stub.c    | 14 ++++++++
    hw/virtio/virtio.c         | 44 ++++++++++++++++++++++++
    include/hw/virtio/virtio.h |  1 +
    qapi/meson.build           |  1 +
    qapi/qapi-schema.json      |  1 +
    qapi/virtio.json           | 68 ++++++++++++++++++++++++++++++++++++++
    tests/qtest/qmp-cmd-test.c |  1 +
    8 files changed, 132 insertions(+)

  create mode 100644 hw/virtio/virtio-stub.c
  create mode 100644 qapi/virtio.json

hw/virtio/virtio.c +14 -0
index 5d607aeaa0..bdfa82e9c0 100644
@@ -13,12 +13,18 @@
      #include "qemu/osdep.h"
    #include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/qapi-commands-virtio.h"
+#include "qapi/qapi-commands-qom.h"
+#include "qapi/qapi-visit-virtio.h"
+#include "qapi/qmp/qjson.h"
    #include "cpu.h"
    #include "trace.h"
    #include "qemu/error-report.h"
    #include "qemu/log.h"
    #include "qemu/main-loop.h"
    #include "qemu/module.h"
+#include "qom/object_interfaces.h"
    #include "hw/virtio/virtio.h"
    #include "migration/qemu-file-types.h"
    #include "qemu/atomic.h"
@@ -29,6 +35,9 @@
    #include "sysemu/runstate.h"
    #include "standard-headers/linux/virtio_ids.h"
    +/* QAPI list of realized VirtIODevices */
+static QTAILQ_HEAD(, VirtIODevice) virtio_list;
+
    /*
     * The alignment to use between consumer and producer parts of vring.
     * x86 pagesize again. This is the default, used by transports like PCI
@@ -3698,6 +3707,7 @@ static void virtio_device_realize(DeviceState *dev, Error **errp)
        vdev->listener.commit = virtio_memory_listener_commit;
        vdev->listener.name = "virtio";
        memory_listener_register(&vdev->listener, vdev->dma_as);
+    QTAILQ_INSERT_TAIL(&virtio_list, vdev, next);
    }
      static void virtio_device_unrealize(DeviceState *dev)
@@ -3712,6 +3722,7 @@ static void virtio_device_unrealize(DeviceState *dev)
            vdc->unrealize(dev);
        }
    +    QTAILQ_REMOVE(&virtio_list, vdev, next);
        g_free(vdev->bus_name);
        vdev->bus_name = NULL;
    }
@@ -3885,6 +3896,8 @@ static void virtio_device_class_init(ObjectClass *klass, void *data)
        vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl;
          vdc->legacy_features |= VIRTIO_LEGACY_FEATURES;
+
+    QTAILQ_INIT(&virtio_list);
    }
      bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
@@ -3895,6 +3908,37 @@ bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
        return virtio_bus_ioeventfd_enabled(vbus);
    }
    +VirtioInfoList *qmp_x_query_virtio(Error **errp)
+{
+    VirtioInfoList *list = NULL;
+    VirtioInfoList *node;

hw/virtio/virtio.c bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev) · line 3923

Quoted 10 lines
hw/virtio/virtio.c +10 -0
+    VirtIODevice *vdev;
+
+    QTAILQ_FOREACH(vdev, &virtio_list, next) {
+        DeviceState *dev = DEVICE(vdev);
+        Error *err = NULL;
+        QObject *obj = qmp_qom_get(dev->canonical_path, "realized", &err);
+
+        if (err == NULL) {
+            GString *is_realized = qobject_to_json_pretty(obj, true);
+            /* virtio device is NOT realized, remove it from list */

Why not check dev->realized instead of calling qmp_qom_get() & qobject_to_json_pretty()?

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

This check queries the QOM composition tree to check that the device actually exists and is realized. In other words, we just want to confirm with the QOM composition tree for the device.

Again, how could this happen?

If @virtio_list isn't reliable, why have it in the first place?

Quoted 10 lines

Honestly, I'm not sure how this even could happen, since the @virtio_list is managed at the realization
and unrealization of a virtio device. Given this, I do feel as though the list is reliable, although
this might just benaïve of me to say. After giving this a second look, the @virtio_list is only really needed to provide a nice list of all realized virtio devices on the system, along with their full canonical paths. If the user can find the canonical path of a virtio device by searching the QOM composition tree, and assuming we can get a @VirtioDevice object (in code) from this canonical path, then the rest of the QMP/HMP features of these patches could be done by solely by searching the QOM composition tree. However, I think having this list of realized virtio devices as a subset of the QOM composition tree is worth its weight, since the user no longer has to search the entire tree to find virtio devices and piece together their canonical paths. Of course, if we're somehow able to generate a similar list in code by searching the QOM composition tree, then there would be no need for this @virtio_list. However, it's really not clear how, or if, such a list could be generated by parsing the QOM composition tree.

I'm not debating whether to have the command right now. I'm debating the introduction of variable @virtio_list. Please consider...

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

This was done to have some kind of synchronicity between @virtio_list and the QOM composition tree, since the list duplicates information that already exists in the tree. This check was recommended in v10 and added in v11 of this patch series.

Thanks, I found Markus comments:

v10:

https://urldefense.com/v3/__https://lore.kernel.org/qemu-devel/[email protected]/__;!!ACWV5N9M2RV99hQ!LqeLFhE8PtTTg_qKRuP9Kgz5pyTNZLhYeRzp4a2oS8c3D5W8-irZoBW0L_Lf1ozm3qYidYhuVrjxjsAw$   

... this:

Quoted 8 lines
Quoted 8 lines

My recommendation there was to *delete* virtio_list and search the QOM composition tree instead:

@virtio_list duplicates information that exists in the QOM composition tree. It needs to stay in sync. You could search the composition tree instead.

The QOM composition tree is the source of truth.

Let me tell you a tale of two patches.

One created a niche QMP command. It also modified core infrastructure to keep additional state. State that needed to be kept consistent with existing state forever. Consistency was not entirely obvious. The command examined this new state. The examination was simple.

Quoted 8 lines

The other one created a niche QMP command, and nothing more. The command examined state without changing it. The examination was less simple.

One of the two patches had a much easier time in review. Which one could it be...

Please give the other approach a serious try.

Ah, okay. I see where you're getting at.

Sure, I can give this approach a try and see what I can do with it. Just FYI, I wont be able to get to this right away until sometime early next year.

Jonah

Quoted 3 lines

[...]

#9 lore raw

Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio

Quoted 154 lines · Jonah Palmer
Quoted 152 lines · Markus Armbruster
Quoted 118 lines · Jonah Palmer
Quoted 112 lines · Markus Armbruster
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Jonah Palmer
Quoted 12 lines · Philippe Mathieu-Daudé

Hi,

Quoted 9 lines · Jonah Palmer

From: Laurent Vivier<[email protected]>

This new command lists all the instances of VirtIODevices with their canonical QOM path and name.

[Jonah: @virtio_list duplicates information that already exists in
  the QOM composition tree. However, extracting necessary information from this tree seems to be a bit convoluted.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

  Instead, we still create our own list of realized virtio devices but use @qmp_qom_get with the device's canonical QOM path to confirm that the device exists and is realized. If the device exists but is actually not realized, then we remove it from our list (for synchronicity to the QOM composition tree).

How could this happen?

Quoted 89 lines
Quoted 89 lines
Quoted 89 lines
Quoted 78 lines

  Also, the QMP command @x-query-virtio is redundant as @qom-list and @qom-get are sufficient to search '/machine/' for realized virtio devices. However, @x-query-virtio is much more convenient in listing realized virtio devices.]

---
    hw/virtio/meson.build      |  2 ++
    hw/virtio/virtio-stub.c    | 14 ++++++++
    hw/virtio/virtio.c         | 44 ++++++++++++++++++++++++
    include/hw/virtio/virtio.h |  1 +
    qapi/meson.build           |  1 +
    qapi/qapi-schema.json      |  1 +
    qapi/virtio.json           | 68 ++++++++++++++++++++++++++++++++++++++
    tests/qtest/qmp-cmd-test.c |  1 +
    8 files changed, 132 insertions(+)

  create mode 100644 hw/virtio/virtio-stub.c
  create mode 100644 qapi/virtio.json

hw/virtio/virtio.c +14 -0
index 5d607aeaa0..bdfa82e9c0 100644
@@ -13,12 +13,18 @@
      #include "qemu/osdep.h"
    #include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/qapi-commands-virtio.h"
+#include "qapi/qapi-commands-qom.h"
+#include "qapi/qapi-visit-virtio.h"
+#include "qapi/qmp/qjson.h"
    #include "cpu.h"
    #include "trace.h"
    #include "qemu/error-report.h"
    #include "qemu/log.h"
    #include "qemu/main-loop.h"
    #include "qemu/module.h"
+#include "qom/object_interfaces.h"
    #include "hw/virtio/virtio.h"
    #include "migration/qemu-file-types.h"
    #include "qemu/atomic.h"
@@ -29,6 +35,9 @@
    #include "sysemu/runstate.h"
    #include "standard-headers/linux/virtio_ids.h"
    +/* QAPI list of realized VirtIODevices */
+static QTAILQ_HEAD(, VirtIODevice) virtio_list;
+
    /*
     * The alignment to use between consumer and producer parts of vring.
     * x86 pagesize again. This is the default, used by transports like PCI
@@ -3698,6 +3707,7 @@ static void virtio_device_realize(DeviceState *dev, Error **errp)
        vdev->listener.commit = virtio_memory_listener_commit;
        vdev->listener.name = "virtio";
        memory_listener_register(&vdev->listener, vdev->dma_as);
+    QTAILQ_INSERT_TAIL(&virtio_list, vdev, next);
    }
      static void virtio_device_unrealize(DeviceState *dev)
@@ -3712,6 +3722,7 @@ static void virtio_device_unrealize(DeviceState *dev)
            vdc->unrealize(dev);
        }
    +    QTAILQ_REMOVE(&virtio_list, vdev, next);
        g_free(vdev->bus_name);
        vdev->bus_name = NULL;
    }
@@ -3885,6 +3896,8 @@ static void virtio_device_class_init(ObjectClass *klass, void *data)
        vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl;
          vdc->legacy_features |= VIRTIO_LEGACY_FEATURES;
+
+    QTAILQ_INIT(&virtio_list);
    }
      bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
@@ -3895,6 +3908,37 @@ bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
        return virtio_bus_ioeventfd_enabled(vbus);
    }
    +VirtioInfoList *qmp_x_query_virtio(Error **errp)
+{
+    VirtioInfoList *list = NULL;
+    VirtioInfoList *node;

hw/virtio/virtio.c bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev) · line 3923

Quoted 10 lines
hw/virtio/virtio.c +10 -0
+    VirtIODevice *vdev;
+
+    QTAILQ_FOREACH(vdev, &virtio_list, next) {
+        DeviceState *dev = DEVICE(vdev);
+        Error *err = NULL;
+        QObject *obj = qmp_qom_get(dev->canonical_path, "realized", &err);
+
+        if (err == NULL) {
+            GString *is_realized = qobject_to_json_pretty(obj, true);
+            /* virtio device is NOT realized, remove it from list */

Why not check dev->realized instead of calling qmp_qom_get() & qobject_to_json_pretty()?

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

This check queries the QOM composition tree to check that the device actually exists and is realized. In other words, we just want to confirm with the QOM composition tree for the device.

Again, how could this happen?

If @virtio_list isn't reliable, why have it in the first place?

Quoted 10 lines

Honestly, I'm not sure how this even could happen, since the @virtio_list is managed at the realization
and unrealization of a virtio device. Given this, I do feel as though the list is reliable, although
this might just benaïve of me to say. After giving this a second look, the @virtio_list is only really needed to provide a nice list of all realized virtio devices on the system, along with their full canonical paths. If the user can find the canonical path of a virtio device by searching the QOM composition tree, and assuming we can get a @VirtioDevice object (in code) from this canonical path, then the rest of the QMP/HMP features of these patches could be done by solely by searching the QOM composition tree. However, I think having this list of realized virtio devices as a subset of the QOM composition tree is worth its weight, since the user no longer has to search the entire tree to find virtio devices and piece together their canonical paths. Of course, if we're somehow able to generate a similar list in code by searching the QOM composition tree, then there would be no need for this @virtio_list. However, it's really not clear how, or if, such a list could be generated by parsing the QOM composition tree.

I'm not debating whether to have the command right now. I'm debating the introduction of variable @virtio_list. Please consider...

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

This was done to have some kind of synchronicity between @virtio_list and the QOM composition tree, since the list duplicates information that already exists in the tree. This check was recommended in v10 and added in v11 of this patch series.

Thanks, I found Markus comments:

v10:
https://urldefense.com/v3/__https://lore.kernel.org/qemu- devel/[email protected]/__;!!ACWV5N9M2RV99hQ! LqeLFhE8PtTTg_qKRuP9Kgz5pyTNZLhYeRzp4a2oS8c3D5W8- irZoBW0L_Lf1ozm3qYidYhuVrjxjsAw$

... this:

Quoted 8 lines
Quoted 8 lines

My recommendation there was to *delete* virtio_list and search the QOM composition tree instead:

@virtio_list duplicates information that exists in the QOM composition tree. It needs to stay in sync. You could search the composition tree instead.

The QOM composition tree is the source of truth.

Let me tell you a tale of two patches.

Quoted 8 lines
Quoted 8 lines

One created a niche QMP command. It also modified core infrastructure to keep additional state. State that needed to be kept consistent with existing state forever. Consistency was not entirely obvious. The command examined this new state. The examination was simple.

The other one created a niche QMP command, and nothing more. The command examined state without changing it. The examination was less simple.

And 3 years later I hit this niche command while trying to remove a legacy field...

commit 4987e5bf2e9262094fd89d2b8e4d5bd6c4c7312f

+ /**

+     * @use_started: true if the @started flag should be used to check
+     * the current state of the VirtIO device. Otherwise status bits
+     * should be checked for a current status of the device.
+     * @use_started is only set via QMP and defaults to true for all
+     * modern machines (since 4.1).
+     */

(we are removing all machines up to 4.0)

Quoted 16 lines
Quoted 5 lines

One of the two patches had a much easier time in review. Which one could it be...

Please give the other approach a serious try.

Ah, okay. I see where you're getting at.

Sure, I can give this approach a try and see what I can do with it. Just FYI, I wont be able to get to this right away until sometime early next year.

Jonah

Quoted 2 lines

[...]

#10 lore raw

PATCH v15 2/6 qmp: add QMP command x-query-virtio-status

In reply to Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command shows the status of a VirtIODevice, including its corresponding vhost device's status (if active).

Next patch will improve output by decoding feature bits, including vhost device's feature bits (backend, protocol, acked, and features). Also will decode status bits of a VirtIODevice.

[Jonah: From patch v12; added a check to @virtio_device_find to ensure
synchronicity between @virtio_list and the devices in the QOM composition tree.]

---
 hw/virtio/virtio-stub.c |   5 +
 hw/virtio/virtio.c      | 104 +++++++++++++++++++
 qapi/virtio.json        | 222 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 331 insertions(+)
hw/virtio/virtio-stub.c +5 -0
index 05a81edc92..0b432e8de7 100644
@@ -12,3 +12,8 @@ VirtioInfoList *qmp_x_query_virtio(Error **errp)
 {
     return qmp_virtio_unsupported(errp);
 }
+
+VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
+{
+    return qmp_virtio_unsupported(errp);
+}
hw/virtio/virtio.c +104 -0

110 lines not on this page · raw message

qapi/virtio.json +222 -0

225 lines not on this page · raw message

Signature · 1 line
2.31.1
#11 lore raw

Re: [PATCH v15 2/6] qmp: add QMP command x-query-virtio-status

Hello,

(patch merged as commit 90c066cd682).

Quoted 154 lines · Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command shows the status of a VirtIODevice, including its corresponding vhost device's status (if active).

Next patch will improve output by decoding feature bits, including vhost device's feature bits (backend, protocol, acked, and features). Also will decode status bits of a VirtIODevice.

[Jonah: From patch v12; added a check to @virtio_device_find to ensure
synchronicity between @virtio_list and the devices in the QOM composition tree.]

---
  hw/virtio/virtio-stub.c |   5 +
  hw/virtio/virtio.c      | 104 +++++++++++++++++++
  qapi/virtio.json        | 222 ++++++++++++++++++++++++++++++++++++++++
  3 files changed, 331 insertions(+)
hw/virtio/virtio-stub.c +5 -0
index 05a81edc92..0b432e8de7 100644
@@ -12,3 +12,8 @@ VirtioInfoList *qmp_x_query_virtio(Error **errp)
  {
      return qmp_virtio_unsupported(errp);
  }
+
+VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
+{
+    return qmp_virtio_unsupported(errp);
+}
hw/virtio/virtio.c +104 -0
index bdfa82e9c0..3e0a484660 100644
@@ -3939,6 +3939,110 @@ VirtioInfoList *qmp_x_query_virtio(Error **errp)
      return list;
  }
 
+static VirtIODevice *virtio_device_find(const char *path)
+{
+    VirtIODevice *vdev;
+
+    QTAILQ_FOREACH(vdev, &virtio_list, next) {
+        DeviceState *dev = DEVICE(vdev);
+
+        if (strcmp(dev->canonical_path, path) != 0) {
+            continue;
+        }
+
+        Error *err = NULL;
+        QObject *obj = qmp_qom_get(dev->canonical_path, "realized", &err);
+        if (err == NULL) {
+            GString *is_realized = qobject_to_json_pretty(obj, true);
+            /* virtio device is NOT realized, remove it from list */
+            if (!strncmp(is_realized->str, "false", 4)) {
+                g_string_free(is_realized, true);
+                qobject_unref(obj);
+                QTAILQ_REMOVE(&virtio_list, vdev, next);
+                return NULL;
+            }
+            g_string_free(is_realized, true);
+        } else {
+            /* virtio device doesn't exist in QOM tree */
+            QTAILQ_REMOVE(&virtio_list, vdev, next);
+            qobject_unref(obj);
+            return NULL;
+        }
+        /* device exists in QOM tree & is realized */
+        qobject_unref(obj);
+        return vdev;
+    }
+    return NULL;
+}
+
+VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
+{
+    VirtIODevice *vdev;
+    VirtioStatus *status;
+
+    vdev = virtio_device_find(path);
+    if (vdev == NULL) {
+        error_setg(errp, "Path %s is not a VirtIODevice", path);
+        return NULL;
+    }
+
+    status = g_new0(VirtioStatus, 1);
+    status->name = g_strdup(vdev->name);
+    status->device_id = vdev->device_id;
+    status->vhost_started = vdev->vhost_started;
+    status->guest_features = vdev->guest_features;
+    status->host_features = vdev->host_features;
+    status->backend_features = vdev->backend_features;
+
+    switch (vdev->device_endian) {
+    case VIRTIO_DEVICE_ENDIAN_LITTLE:
+        status->device_endian = g_strdup("little");
+        break;
+    case VIRTIO_DEVICE_ENDIAN_BIG:
+        status->device_endian = g_strdup("big");
+        break;
+    default:
+        status->device_endian = g_strdup("unknown");
+        break;
+    }
+
+    status->num_vqs = virtio_get_num_queues(vdev);
+    status->status = vdev->status;
+    status->isr = vdev->isr;
+    status->queue_sel = vdev->queue_sel;
+    status->vm_running = vdev->vm_running;
+    status->broken = vdev->broken;
+    status->disabled = vdev->disabled;
+    status->use_started = vdev->use_started;
+    status->started = vdev->started;
+    status->start_on_kick = vdev->start_on_kick;
+    status->disable_legacy_check = vdev->disable_legacy_check;
+    status->bus_name = g_strdup(vdev->bus_name);
+    status->use_guest_notifier_mask = vdev->use_guest_notifier_mask;
+    status->has_vhost_dev = vdev->vhost_started;
+
+    if (vdev->vhost_started) {
+        VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
+        struct vhost_dev *hdev = vdc->get_vhost(vdev);
+
+        status->vhost_dev = g_new0(VhostStatus, 1);
+        status->vhost_dev->n_mem_sections = hdev->n_mem_sections;
+        status->vhost_dev->n_tmp_sections = hdev->n_tmp_sections;
+        status->vhost_dev->nvqs = hdev->nvqs;
+        status->vhost_dev->vq_index = hdev->vq_index;
+        status->vhost_dev->features = hdev->features;
+        status->vhost_dev->acked_features = hdev->acked_features;
+        status->vhost_dev->backend_features = hdev->backend_features;
+        status->vhost_dev->protocol_features = hdev->protocol_features;
+        status->vhost_dev->max_queues = hdev->max_queues;
+        status->vhost_dev->backend_cap = hdev->backend_cap;
+        status->vhost_dev->log_enabled = hdev->log_enabled;
+        status->vhost_dev->log_size = hdev->log_size;
+    }
+
+    return status;
+}
+
  static const TypeInfo virtio_device_info = {
      .name = TYPE_VIRTIO_DEVICE,
      .parent = TYPE_DEVICE,
qapi/virtio.json +0 -0
index 03896e423f..c86b3bc635 100644

qapi/virtio.json line 68

Quoted 3 lines
qapi/virtio.json +0 -0
@@ -66,3 +66,225 @@
  { 'command': 'x-query-virtio',
    'returns': [ 'VirtioInfo' ],
    'features': [ 'unstable' ] }

When a structure is only used by an unstable command, is it considered unstable too? IOW is it OK to modify it?

Quoted 222 lines
qapi/virtio.json +222 -0
+
+##
+# @VhostStatus:
+#
+# Information about a vhost device. This information will only be
+# displayed if the vhost device is active.
+#
+# @n-mem-sections: vhost_dev n_mem_sections
+#
+# @n-tmp-sections: vhost_dev n_tmp_sections
+#
+# @nvqs: vhost_dev nvqs (number of virtqueues being used)
+#
+# @vq-index: vhost_dev vq_index
+#
+# @features: vhost_dev features
+#
+# @acked-features: vhost_dev acked_features
+#
+# @backend-features: vhost_dev backend_features
+#
+# @protocol-features: vhost_dev protocol_features
+#
+# @max-queues: vhost_dev max_queues
+#
+# @backend-cap: vhost_dev backend_cap
+#
+# @log-enabled: vhost_dev log_enabled flag
+#
+# @log-size: vhost_dev log_size
+#
+# Since: 7.1
+#
+##
+
+{ 'struct': 'VhostStatus',
+  'data': { 'n-mem-sections': 'int',
+            'n-tmp-sections': 'int',
+            'nvqs': 'uint32',
+            'vq-index': 'int',
+            'features': 'uint64',
+            'acked-features': 'uint64',
+            'backend-features': 'uint64',
+            'protocol-features': 'uint64',
+            'max-queues': 'uint64',
+            'backend-cap': 'uint64',
+            'log-enabled': 'bool',
+            'log-size': 'uint64' } }
+
+##
+# @VirtioStatus:
+#
+# Full status of the virtio device with most VirtIODevice members.
+# Also includes the full status of the corresponding vhost device
+# if the vhost device is active.
+#
+# @name: VirtIODevice name
+#
+# @device-id: VirtIODevice ID
+#
+# @vhost-started: VirtIODevice vhost_started flag
+#
+# @guest-features: VirtIODevice guest_features
+#
+# @host-features: VirtIODevice host_features
+#
+# @backend-features: VirtIODevice backend_features
+#
+# @device-endian: VirtIODevice device_endian
+#
+# @num-vqs: VirtIODevice virtqueue count. This is the number of active
+#           virtqueues being used by the VirtIODevice.
+#
+# @status: VirtIODevice configuration status (VirtioDeviceStatus)
+#
+# @isr: VirtIODevice ISR
+#
+# @queue-sel: VirtIODevice queue_sel
+#
+# @vm-running: VirtIODevice vm_running flag
+#
+# @broken: VirtIODevice broken flag
+#
+# @disabled: VirtIODevice disabled flag
+#
+# @use-started: VirtIODevice use_started flag
+#
+# @started: VirtIODevice started flag
+#
+# @start-on-kick: VirtIODevice start_on_kick flag
+#
+# @disable-legacy-check: VirtIODevice disabled_legacy_check flag
+#
+# @bus-name: VirtIODevice bus_name
+#
+# @use-guest-notifier-mask: VirtIODevice use_guest_notifier_mask flag
+#
+# @vhost-dev: Corresponding vhost device info for a given VirtIODevice.
+#             Present if the given VirtIODevice has an active vhost
+#             device.
+#
+# Since: 7.1
+#
+##
+
+{ 'struct': 'VirtioStatus',
+  'data': { 'name': 'str',
+            'device-id': 'uint16',
+            'vhost-started': 'bool',
+            'device-endian': 'str',
+            'guest-features': 'uint64',
+            'host-features': 'uint64',
+            'backend-features': 'uint64',
+            'num-vqs': 'int',
+            'status': 'uint8',
+            'isr': 'uint8',
+            'queue-sel': 'uint16',
+            'vm-running': 'bool',
+            'broken': 'bool',
+            'disabled': 'bool',
+            'use-started': 'bool',
+            'started': 'bool',
+            'start-on-kick': 'bool',
+            'disable-legacy-check': 'bool',
+            'bus-name': 'str',
+            'use-guest-notifier-mask': 'bool',
+            '*vhost-dev': 'VhostStatus' } }
+
+##
+# @x-query-virtio-status:
+#
+# Poll for a comprehensive status of a given virtio device
+#
+# @path: Canonical QOM path of the VirtIODevice
+#
+# Features:
+# @unstable: This command is meant for debugging.
+#
+# Returns: VirtioStatus of the virtio device
+#
+# Since: 7.1
+#
+# Examples:
+#
+# 1. Poll for the status of virtio-crypto (no vhost-crypto active)
+#
+# -> { "execute": "x-query-virtio-status",
+#      "arguments": { "path": "/machine/peripheral/crypto0/virtio-backend" }
+#    }
+# <- { "return": {
+#          "device-endian": "little",
+#          "bus-name": "",
+#          "disable-legacy-check": false,
+#          "name": "virtio-crypto",
+#          "started": true,
+#          "device-id": 20,
+#          "backend-features": 0,
+#          "start-on-kick": false,
+#          "isr": 1,
+#          "broken": false,
+#          "status": 15,
+#          "num-vqs": 2,
+#          "guest-features": 5100273664,
+#          "host-features": 6325010432,
+#          "use-guest-notifier-mask": true,
+#          "vm-running": true,
+#          "queue-sel": 1,
+#          "disabled": false,
+#          "vhost-started": false,
+#          "use-started": true
+#      }
+#    }
+#
+# 2. Poll for the status of virtio-net (vhost-net is active)
+#
+# -> { "execute": "x-query-virtio-status",
+#      "arguments": { "path": "/machine/peripheral-anon/device[1]/virtio-backend" }
+#    }
+# <- { "return": {
+#          "device-endian": "little",
+#          "bus-name": "",
+#          "disabled-legacy-check": false,
+#          "name": "virtio-net",
+#          "started": true,
+#          "device-id": 1,
+#          "vhost-dev": {
+#              "n-tmp-sections": 4,
+#              "n-mem-sections": 4,
+#              "max-queues": 1,
+#              "backend-cap": 2,
+#              "log-size": 0,
+#              "backend-features": 0,
+#              "nvqs": 2,
+#              "protocol-features": 0,
+#              "vq-index": 0,
+#              "log-enabled": false,
+#              "acked-features": 5100306432,
+#              "features": 13908344832
+#          },
+#          "backend-features": 6337593319,
+#          "start-on-kick": false,
+#          "isr": 1,
+#          "broken": false,
+#          "status": 15,
+#          "num-vqs": 3,
+#          "guest-features": 5111807911,
+#          "host-features": 6337593319,
+#          "use-guest-notifier-mask": true,
+#          "vm-running": true,
+#          "queue-sel": 2,
+#          "disabled": false,
+#          "vhost-started": true,
+#          "use-started": true
+#      }
+#    }
+#
+##
+
+{ 'command': 'x-query-virtio-status',
+  'data': { 'path': 'str' },
+  'returns': 'VirtioStatus',
+  'features': [ 'unstable' ] }
#12 lore raw

Re: [PATCH v15 2/6] qmp: add QMP command x-query-virtio-status

Quoted 156 lines · Philippe Mathieu-Daudé

Hello,

(patch merged as commit 90c066cd682).

Quoted 151 lines · Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command shows the status of a VirtIODevice, including its corresponding vhost device's status (if active).

Next patch will improve output by decoding feature bits, including vhost device's feature bits (backend, protocol, acked, and features). Also will decode status bits of a VirtIODevice.

[Jonah: From patch v12; added a check to @virtio_device_find to ensure synchronicity between @virtio_list and the devices in the QOM composition tree.]

---
  hw/virtio/virtio-stub.c |   5 +
  hw/virtio/virtio.c      | 104 +++++++++++++++++++ qapi/virtio.json        | 222 ++++++++++++++++++++++++++++++++++++++++

  3 files changed, 331 insertions(+)
hw/virtio/virtio-stub.c +5 -0
index 05a81edc92..0b432e8de7 100644
@@ -12,3 +12,8 @@ VirtioInfoList *qmp_x_query_virtio(Error **errp)
   {
       return qmp_virtio_unsupported(errp);
   }
+
+VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
+{
+    return qmp_virtio_unsupported(errp);
+}
hw/virtio/virtio.c +104 -0
index bdfa82e9c0..3e0a484660 100644
@@ -3939,6 +3939,110 @@ VirtioInfoList *qmp_x_query_virtio(Error **errp)
       return list;
   }
+static VirtIODevice *virtio_device_find(const char *path)
+{
+    VirtIODevice *vdev;
+
+    QTAILQ_FOREACH(vdev, &virtio_list, next) {
+        DeviceState *dev = DEVICE(vdev);
+
+        if (strcmp(dev->canonical_path, path) != 0) {
+            continue;
+        }
+
+        Error *err = NULL;
+        QObject *obj = qmp_qom_get(dev->canonical_path, "realized", &err);
+        if (err == NULL) {
+            GString *is_realized = qobject_to_json_pretty(obj, true);
+            /* virtio device is NOT realized, remove it from list */
+            if (!strncmp(is_realized->str, "false", 4)) {
+                g_string_free(is_realized, true);
+                qobject_unref(obj);
+                QTAILQ_REMOVE(&virtio_list, vdev, next);
+                return NULL;
+            }
+            g_string_free(is_realized, true);
+        } else {
+            /* virtio device doesn't exist in QOM tree */
+            QTAILQ_REMOVE(&virtio_list, vdev, next);
+            qobject_unref(obj);
+            return NULL;
+        }
+        /* device exists in QOM tree & is realized */
+        qobject_unref(obj);
+        return vdev;
+    }
+    return NULL;
+}
+
+VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
+{
+    VirtIODevice *vdev;
+    VirtioStatus *status;
+
+    vdev = virtio_device_find(path);
+    if (vdev == NULL) {
+        error_setg(errp, "Path %s is not a VirtIODevice", path);
+        return NULL;
+    }
+
+    status = g_new0(VirtioStatus, 1);
+    status->name = g_strdup(vdev->name);
+    status->device_id = vdev->device_id;
+    status->vhost_started = vdev->vhost_started;
+    status->guest_features = vdev->guest_features;
+    status->host_features = vdev->host_features;
+    status->backend_features = vdev->backend_features;
+
+    switch (vdev->device_endian) {
+    case VIRTIO_DEVICE_ENDIAN_LITTLE:
+        status->device_endian = g_strdup("little");
+        break;
+    case VIRTIO_DEVICE_ENDIAN_BIG:
+        status->device_endian = g_strdup("big");
+        break;
+    default:
+        status->device_endian = g_strdup("unknown");
+        break;
+    }
+
+    status->num_vqs = virtio_get_num_queues(vdev);
+    status->status = vdev->status;
+    status->isr = vdev->isr;
+    status->queue_sel = vdev->queue_sel;
+    status->vm_running = vdev->vm_running;
+    status->broken = vdev->broken;
+    status->disabled = vdev->disabled;
+    status->use_started = vdev->use_started;
+    status->started = vdev->started;
+    status->start_on_kick = vdev->start_on_kick;
+    status->disable_legacy_check = vdev->disable_legacy_check;
+    status->bus_name = g_strdup(vdev->bus_name);
+    status->use_guest_notifier_mask = vdev->use_guest_notifier_mask;
+    status->has_vhost_dev = vdev->vhost_started;
+
+    if (vdev->vhost_started) {
+        VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
+        struct vhost_dev *hdev = vdc->get_vhost(vdev);
+
+        status->vhost_dev = g_new0(VhostStatus, 1);
+        status->vhost_dev->n_mem_sections = hdev->n_mem_sections;
+        status->vhost_dev->n_tmp_sections = hdev->n_tmp_sections;
+        status->vhost_dev->nvqs = hdev->nvqs;
+        status->vhost_dev->vq_index = hdev->vq_index;
+        status->vhost_dev->features = hdev->features;
+        status->vhost_dev->acked_features = hdev->acked_features;
+        status->vhost_dev->backend_features = hdev->backend_features;
+        status->vhost_dev->protocol_features = hdev->protocol_features;
+        status->vhost_dev->max_queues = hdev->max_queues;
+        status->vhost_dev->backend_cap = hdev->backend_cap;
+        status->vhost_dev->log_enabled = hdev->log_enabled;
+        status->vhost_dev->log_size = hdev->log_size;
+    }
+
+    return status;
+}
+
   static const TypeInfo virtio_device_info = {
       .name = TYPE_VIRTIO_DEVICE,
       .parent = TYPE_DEVICE,
qapi/virtio.json +0 -1
index 03896e423f..c86b3bc635 100644
--- a/qapi/virtio.json
Quoted 8 lines

qapi/virtio.json line 68

Quoted 5 lines

+++ b/qapi/virtio.json

qapi/virtio.json +0 -0
@@ -66,3 +66,225 @@
   { 'command': 'x-query-virtio',
     'returns': [ 'VirtioInfo' ],
     'features': [ 'unstable' ] }

When a structure is only used by an unstable command, is it considered unstable too? IOW is it OK to modify it?

IMHO yes. If there is no other user of the struct, why should it considered to be stable if the only command that uses it is unstable?

Thomas

#13 lore raw

Re: [PATCH v15 2/6] qmp: add QMP command x-query-virtio-status

Quoted 166 lines · Thomas Huth
Quoted 156 lines · Philippe Mathieu-Daudé

Hello,

(patch merged as commit 90c066cd682).

Quoted 151 lines · Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command shows the status of a VirtIODevice, including its corresponding vhost device's status (if active).

Next patch will improve output by decoding feature bits, including vhost device's feature bits (backend, protocol, acked, and features). Also will decode status bits of a VirtIODevice.

[Jonah: From patch v12; added a check to @virtio_device_find to ensure synchronicity between @virtio_list and the devices in the QOM composition tree.]

---
  hw/virtio/virtio-stub.c |   5 +
  hw/virtio/virtio.c      | 104 +++++++++++++++++++ qapi/virtio.json        | 222 ++++++++++++++++++++++++++++++++++++++++

  3 files changed, 331 insertions(+)
hw/virtio/virtio-stub.c +5 -0
index 05a81edc92..0b432e8de7 100644
@@ -12,3 +12,8 @@ VirtioInfoList *qmp_x_query_virtio(Error **errp)
   {
       return qmp_virtio_unsupported(errp);
   }
+
+VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
+{
+    return qmp_virtio_unsupported(errp);
+}
hw/virtio/virtio.c +104 -0
index bdfa82e9c0..3e0a484660 100644
@@ -3939,6 +3939,110 @@ VirtioInfoList *qmp_x_query_virtio(Error **errp)
       return list;
   }
+static VirtIODevice *virtio_device_find(const char *path)
+{
+    VirtIODevice *vdev;
+
+    QTAILQ_FOREACH(vdev, &virtio_list, next) {
+        DeviceState *dev = DEVICE(vdev);
+
+        if (strcmp(dev->canonical_path, path) != 0) {
+            continue;
+        }
+
+        Error *err = NULL;
+        QObject *obj = qmp_qom_get(dev->canonical_path, "realized", &err);
+        if (err == NULL) {
+            GString *is_realized = qobject_to_json_pretty(obj, true);
+            /* virtio device is NOT realized, remove it from list */
+            if (!strncmp(is_realized->str, "false", 4)) {
+                g_string_free(is_realized, true);
+                qobject_unref(obj);
+                QTAILQ_REMOVE(&virtio_list, vdev, next);
+                return NULL;
+            }
+            g_string_free(is_realized, true);
+        } else {
+            /* virtio device doesn't exist in QOM tree */
+            QTAILQ_REMOVE(&virtio_list, vdev, next);
+            qobject_unref(obj);
+            return NULL;
+        }
+        /* device exists in QOM tree & is realized */
+        qobject_unref(obj);
+        return vdev;
+    }
+    return NULL;
+}
+
+VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
+{
+    VirtIODevice *vdev;
+    VirtioStatus *status;
+
+    vdev = virtio_device_find(path);
+    if (vdev == NULL) {
+        error_setg(errp, "Path %s is not a VirtIODevice", path);
+        return NULL;
+    }
+
+    status = g_new0(VirtioStatus, 1);
+    status->name = g_strdup(vdev->name);
+    status->device_id = vdev->device_id;
+    status->vhost_started = vdev->vhost_started;
+    status->guest_features = vdev->guest_features;
+    status->host_features = vdev->host_features;
+    status->backend_features = vdev->backend_features;
+
+    switch (vdev->device_endian) {
+    case VIRTIO_DEVICE_ENDIAN_LITTLE:
+        status->device_endian = g_strdup("little");
+        break;
+    case VIRTIO_DEVICE_ENDIAN_BIG:
+        status->device_endian = g_strdup("big");
+        break;
+    default:
+        status->device_endian = g_strdup("unknown");
+        break;
+    }
+
+    status->num_vqs = virtio_get_num_queues(vdev);
+    status->status = vdev->status;
+    status->isr = vdev->isr;
+    status->queue_sel = vdev->queue_sel;
+    status->vm_running = vdev->vm_running;
+    status->broken = vdev->broken;
+    status->disabled = vdev->disabled;
+    status->use_started = vdev->use_started;
+    status->started = vdev->started;
+    status->start_on_kick = vdev->start_on_kick;
+    status->disable_legacy_check = vdev->disable_legacy_check;
+    status->bus_name = g_strdup(vdev->bus_name);
+    status->use_guest_notifier_mask = vdev->use_guest_notifier_mask;
+    status->has_vhost_dev = vdev->vhost_started;
+
+    if (vdev->vhost_started) {
+        VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
+        struct vhost_dev *hdev = vdc->get_vhost(vdev);
+
+        status->vhost_dev = g_new0(VhostStatus, 1);
+        status->vhost_dev->n_mem_sections = hdev->n_mem_sections;
+        status->vhost_dev->n_tmp_sections = hdev->n_tmp_sections;
+        status->vhost_dev->nvqs = hdev->nvqs;
+        status->vhost_dev->vq_index = hdev->vq_index;
+        status->vhost_dev->features = hdev->features;
+        status->vhost_dev->acked_features = hdev->acked_features;
+        status->vhost_dev->backend_features = hdev->backend_features;
+        status->vhost_dev->protocol_features = hdev->protocol_features;
+        status->vhost_dev->max_queues = hdev->max_queues;
+        status->vhost_dev->backend_cap = hdev->backend_cap;
+        status->vhost_dev->log_enabled = hdev->log_enabled;
+        status->vhost_dev->log_size = hdev->log_size;
+    }
+
+    return status;
+}
+
   static const TypeInfo virtio_device_info = {
       .name = TYPE_VIRTIO_DEVICE,
       .parent = TYPE_DEVICE,
qapi/virtio.json +0 -1
index 03896e423f..c86b3bc635 100644
--- a/qapi/virtio.json
Quoted 8 lines

qapi/virtio.json line 68

Quoted 5 lines

+++ b/qapi/virtio.json

qapi/virtio.json +0 -0
@@ -66,3 +66,225 @@
   { 'command': 'x-query-virtio',
     'returns': [ 'VirtioInfo' ],
     'features': [ 'unstable' ] }

When a structure is only used by an unstable command, is it considered unstable too? IOW is it OK to modify it?

Quoted 1 line

IMHO yes. If there is no other user of the struct, why should it considered to be stable if the only command that uses it is unstable?

In my mind, "x-query-virtio" is only a debugging purpose command and must not be used to provide production feature. So yes.

Thanks,
Laurent

#14 lore raw

Re: [PATCH v15 2/6] qmp: add QMP command x-query-virtio-status

In reply to Philippe Mathieu-Daudé

Philippe Mathieu-Daudé <[email protected]> writes:

[...]

Quoted 2 lines

When a structure is only used by an unstable command, is it considered unstable too? IOW is it OK to modify it?

Yes.

docs/devel/qapi-code-gen.rst:

Special features
~~~~~~~~~~~~~~~~

[...]

Feature "unstable" marks a command, event, enum value, or struct member as unstable. It is not supported elsewhere so far. Interfaces so marked may be withdrawn or changed incompatibly in future releases.

We support "unstable" exactly where we need it to mark parts of the external interface unstable:

* Commands and events, because these *are* the external interface.

* Struct members, because they can be arguments / results of commands / events.

* Enum values, because these can be values of arguments / results.

* Not types. Not needed, and would enable inconsistencies, like stable member with an unstable type.

Questions?

[...]

#15 lore raw

Re: [PATCH v15 2/6] qmp: add QMP command x-query-virtio-status

Quoted 28 lines · Markus Armbruster

Philippe Mathieu-Daudé <[email protected]> writes:

[...]

Quoted 2 lines

When a structure is only used by an unstable command, is it considered unstable too? IOW is it OK to modify it?

Yes.

docs/devel/qapi-code-gen.rst:

Special features
~~~~~~~~~~~~~~~~

[...]

Feature "unstable" marks a command, event, enum value, or struct member as unstable. It is not supported elsewhere so far. Interfaces so marked may be withdrawn or changed incompatibly in future releases.

We support "unstable" exactly where we need it to mark parts of the external interface unstable:

* Commands and events, because these *are* the external interface.

* Struct members, because they can be arguments / results of commands / events.

Quoted 6 lines

* Enum values, because these can be values of arguments / results.

* Not types. Not needed, and would enable inconsistencies, like stable member with an unstable type.

Questions?

None, thank you!

#16 lore raw

PATCH v15 3/6 qmp: decode feature & status bits in virtio-status

In reply to Jonah Palmer

From: Laurent Vivier <[email protected]>

Display feature names instead of bitmaps for host, guest, and backend for VirtIODevices.

Display status names instead of bitmaps for VirtIODevices.

Display feature names instead of bitmaps for backend, protocol, acked, and features (hdev->features) for vhost devices.

Decode features according to device ID. Decode statuses according to configuration status bitmap (config_status_map). Decode vhost user protocol features according to vhost user protocol bitmap (vhost_user_protocol_map).

Transport features are on the first line. Undecoded bits (if any) are stored in a separate field.

[Jonah: Several changes made to this patch from prev. version (v14):
- Moved all device features mappings to hw/virtio/virtio.c
- Renamed device features mappings (less generic)
- Generalized @FEATURE_ENTRY macro for all device mappings
- Virtio device feature map definitions include descriptions of feature bits
- Moved @VHOST_USER_F_PROTOCOL_FEATURES feature bit from transport feature map to vhost-user-supported device feature mappings (blk, fs, i2c, rng, net, gpu, input, scsi, vsock)
- New feature bit added for virtio-vsock: @VIRTIO_VSOCK_F_SEQPACKET
- New feature bit added for virtio-iommu: @VIRTIO_IOMMU_F_BYPASS_CONFIG
- New feature bit added for virtio-mem: @VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE
- New virtio transport feature bit added: @VIRTIO_F_IN_ORDER
- Added device feature map definition for virtio-rng
]

---

As mentioned in the cover letter, there's a bit of confusion for me here regarding a 30 feature bit that I've been seeing in all of the PCI virtio devices that I've defined when bringing up a guest. The only 30 feature bits that are defined are @VHOST_USER_F_PROTOCOL_FEATURES & @VIRTIO_F_BAD_FEATURE.

Initially, I thought that this must be the vhost-user 'protocol-features' feature bit (since the 'bad-feature' bit would mean negotiation is broken), but I noticed that this bit was still being set on devices that don't even have vhost-user support (e.g. virtio-serial), nor was I using vhost-user on any of my virtio devices.

On closer inspection, with a little printf debugging, I confirmed my suspicion that every PCI virtio device *is* in fact having this 'bad-feature' feature set. Futhermore, *none* of my devices actually set the 'protocol-features' feature (which makes sense since I wasn't using vhost-user).

What doesn't make sense to me though is why this 'bad-feature' bit is being set at all, as it implies that negotiation has failed for the device.

In short, I've left out defining the 'bad-feature' feature bit in the transport features map to avoid confusion. However, I'm afraid that this may cause even more confusion since (1) non-vhost-user-supported devices will show 'unknown-dev-features' (e.g. virtio-serial) and (2) vhost-user-supported devices (e.g. virtio-net) *not* using vhost-user will show @VHOST_USER_F_PROTOCOL_FEATURES when in reality it's @VIRTIO_F_BAD_FEATURE.

Please let me know how you would like me to address this. Thanks.

 hw/virtio/virtio.c         | 643 ++++++++++++++++++++++++++++++++++++-
 include/hw/virtio/vhost.h  |   3 +
 include/hw/virtio/virtio.h |   5 +
 qapi/virtio.json           | 251 +++++++++++++--
 4 files changed, 874 insertions(+), 28 deletions(-)
hw/virtio/virtio.c +635 -8
index 3e0a484660..23bdc77a95 100644
@@ -34,10 +34,433 @@
 #include "sysemu/dma.h"
 #include "sysemu/runstate.h"
 #include "standard-headers/linux/virtio_ids.h"
+#include "standard-headers/linux/vhost_types.h"
+#include "standard-headers/linux/virtio_blk.h"
+#include "standard-headers/linux/virtio_console.h"
+#include "standard-headers/linux/virtio_gpu.h"
+#include "standard-headers/linux/virtio_net.h"
+#include "standard-headers/linux/virtio_scsi.h"
+#include "standard-headers/linux/virtio_i2c.h"
+#include "standard-headers/linux/virtio_balloon.h"
+#include "standard-headers/linux/virtio_iommu.h"
+#include "standard-headers/linux/virtio_mem.h"
+#include "standard-headers/linux/virtio_vsock.h"
+#include CONFIG_DEVICES
 
 /* QAPI list of realized VirtIODevices */
 static QTAILQ_HEAD(, VirtIODevice) virtio_list;
 
+/*
+ * Maximum size of virtio device config space
+ */
+#define VHOST_USER_MAX_CONFIG_SIZE 256
+
+#define FEATURE_ENTRY(name, desc) (qmp_virtio_feature_map_t) \
+    { .virtio_bit = name, .feature_desc = desc }
+
+enum VhostUserProtocolFeature {
+    VHOST_USER_PROTOCOL_F_MQ = 0,
+    VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1,
+    VHOST_USER_PROTOCOL_F_RARP = 2,
+    VHOST_USER_PROTOCOL_F_REPLY_ACK = 3,
+    VHOST_USER_PROTOCOL_F_NET_MTU = 4,
+    VHOST_USER_PROTOCOL_F_SLAVE_REQ = 5,
+    VHOST_USER_PROTOCOL_F_CROSS_ENDIAN = 6,
+    VHOST_USER_PROTOCOL_F_CRYPTO_SESSION = 7,
+    VHOST_USER_PROTOCOL_F_PAGEFAULT = 8,
+    VHOST_USER_PROTOCOL_F_CONFIG = 9,
+    VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD = 10,
+    VHOST_USER_PROTOCOL_F_HOST_NOTIFIER = 11,
+    VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD = 12,
+    VHOST_USER_PROTOCOL_F_RESET_DEVICE = 13,
+    VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS = 14,
+    VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS = 15,
+    VHOST_USER_PROTOCOL_F_MAX
+};
+
+/* Virtio transport features mapping */
+static qmp_virtio_feature_map_t virtio_transport_map[] = {
+    /* Virtio device transport features */
+#ifndef VIRTIO_CONFIG_NO_LEGACY
+    FEATURE_ENTRY(VIRTIO_F_NOTIFY_ON_EMPTY, \
+            "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. "
+            "descs. on VQ"),
+    FEATURE_ENTRY(VIRTIO_F_ANY_LAYOUT, \
+            "VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts"),
+#endif /* !VIRTIO_CONFIG_NO_LEGACY */
+    FEATURE_ENTRY(VIRTIO_F_VERSION_1, \
+            "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)"),
+    FEATURE_ENTRY(VIRTIO_F_IOMMU_PLATFORM, \
+            "VIRTIO_F_IOMMU_PLATFORM: Device can be used on IOMMU platform"),
+    FEATURE_ENTRY(VIRTIO_F_RING_PACKED, \
+            "VIRTIO_F_RING_PACKED: Device supports packed VQ layout"),
+    FEATURE_ENTRY(VIRTIO_F_IN_ORDER, \
+            "VIRTIO_F_IN_ORDER: Device uses buffers in same order as made "
+            "available by driver"),
+    FEATURE_ENTRY(VIRTIO_F_ORDER_PLATFORM, \
+            "VIRTIO_F_ORDER_PLATFORM: Memory accesses ordered by platform"),
+    FEATURE_ENTRY(VIRTIO_F_SR_IOV, \
+            "VIRTIO_F_SR_IOV: Device supports single root I/O virtualization"),
+    /* Virtio ring transport features */
+    FEATURE_ENTRY(VIRTIO_RING_F_INDIRECT_DESC, \
+            "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported"),
+    FEATURE_ENTRY(VIRTIO_RING_F_EVENT_IDX, \
+            "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled"),
+    { -1, "" }
+};
+
+/* Vhost-user protocol features mapping */
+static qmp_virtio_feature_map_t vhost_user_protocol_map[] = {
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_MQ, \
+            "VHOST_USER_PROTOCOL_F_MQ: Multiqueue protocol supported"),
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_LOG_SHMFD, \
+            "VHOST_USER_PROTOCOL_F_LOG_SHMFD: Shared log memory fd supported"),
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_RARP, \
+            "VHOST_USER_PROTOCOL_F_RARP: Vhost-user back-end RARP broadcasting "
+            "supported"),
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_REPLY_ACK, \
+            "VHOST_USER_PROTOCOL_F_REPLY_ACK: Requested operation status ack. "
+            "supported"),
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_NET_MTU, \
+            "VHOST_USER_PROTOCOL_F_NET_MTU: Expose host MTU to guest supported"),
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_SLAVE_REQ, \
+            "VHOST_USER_PROTOCOL_F_SLAVE_REQ: Socket fd for back-end initiated "
+            "requests supported"),
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_CROSS_ENDIAN, \
+            "VHOST_USER_PROTOCOL_F_CROSS_ENDIAN: Endianness of VQs for legacy "
+            "devices supported"),
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_CRYPTO_SESSION, \
+            "VHOST_USER_PROTOCOL_F_CRYPTO_SESSION: Session creation for crypto "
+            "operations supported"),
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_PAGEFAULT, \
+            "VHOST_USER_PROTOCOL_F_PAGEFAULT: Request servicing on userfaultfd "
+            "for accessed pages supported"),
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_CONFIG, \
+            "VHOST_USER_PROTOCOL_F_CONFIG: Vhost-user messaging for virtio "
+            "device configuration space supported"),
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD, \
+            "VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD: Slave fd communication "
+            "channel supported"),
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_HOST_NOTIFIER, \
+            "VHOST_USER_PROTOCOL_F_HOST_NOTIFIER: Host notifiers for specified "
+            "VQs supported"),
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD, \
+            "VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD: Shared inflight I/O buffers "
+            "supported"),
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_RESET_DEVICE, \
+            "VHOST_USER_PROTOCOL_F_RESET_DEVICE: Disabling all rings and "
+            "resetting internal device state supported"),
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS, \
+            "VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS: In-band messaging "
+            "supported"),
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS, \
+            "VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS: Configuration for "
+            "memory slots supported"),
+    { -1, "" }
+};
+
+/* virtio device configuration statuses */
+static qmp_virtio_feature_map_t virtio_config_status_map[] = {
+    FEATURE_ENTRY(VIRTIO_CONFIG_S_DRIVER_OK, \
+            "VIRTIO_CONFIG_S_DRIVER_OK: Driver setup and ready"),
+    FEATURE_ENTRY(VIRTIO_CONFIG_S_FEATURES_OK, \
+            "VIRTIO_CONFIG_S_FEATURES_OK: Feature negotiation complete"),
+    FEATURE_ENTRY(VIRTIO_CONFIG_S_DRIVER, \
+            "VIRTIO_CONFIG_S_DRIVER: Guest OS compatible with device"),
+    FEATURE_ENTRY(VIRTIO_CONFIG_S_NEEDS_RESET, \
+            "VIRTIO_CONFIG_S_NEEDS_RESET: Irrecoverable error, device needs "
+            "reset"),
+    FEATURE_ENTRY(VIRTIO_CONFIG_S_FAILED, \
+            "VIRTIO_CONFIG_S_FAILED: Error in guest, device failed"),
+    FEATURE_ENTRY(VIRTIO_CONFIG_S_ACKNOWLEDGE, \
+            "VIRTIO_CONFIG_S_ACKNOWLEDGE: Valid virtio device found"),
+    { -1, "" }
+};
+
+/* virtio-blk features mapping */
+qmp_virtio_feature_map_t virtio_blk_feature_map[] = {
+    FEATURE_ENTRY(VIRTIO_BLK_F_SIZE_MAX, \
+            "VIRTIO_BLK_F_SIZE_MAX: Max segment size is size_max"),
+    FEATURE_ENTRY(VIRTIO_BLK_F_SEG_MAX, \
+            "VIRTIO_BLK_F_SEG_MAX: Max segments in a request is seg_max"),
+    FEATURE_ENTRY(VIRTIO_BLK_F_GEOMETRY, \
+            "VIRTIO_BLK_F_GEOMETRY: Legacy geometry available"),
+    FEATURE_ENTRY(VIRTIO_BLK_F_RO, \
+            "VIRTIO_BLK_F_RO: Device is read-only"),
+    FEATURE_ENTRY(VIRTIO_BLK_F_BLK_SIZE, \
+            "VIRTIO_BLK_F_BLK_SIZE: Block size of disk available"),
+    FEATURE_ENTRY(VIRTIO_BLK_F_TOPOLOGY, \
+            "VIRTIO_BLK_F_TOPOLOGY: Topology information available"),
+    FEATURE_ENTRY(VIRTIO_BLK_F_MQ, \
+            "VIRTIO_BLK_F_MQ: Multiqueue supported"),
+    FEATURE_ENTRY(VIRTIO_BLK_F_DISCARD, \
+            "VIRTIO_BLK_F_DISCARD: Discard command supported"),
+    FEATURE_ENTRY(VIRTIO_BLK_F_WRITE_ZEROES, \
+            "VIRTIO_BLK_F_WRITE_ZEROES: Write zeroes command supported"),
+#ifndef VIRTIO_BLK_NO_LEGACY
+    FEATURE_ENTRY(VIRTIO_BLK_F_BARRIER, \
+            "VIRTIO_BLK_F_BARRIER: Request barriers supported"),
+    FEATURE_ENTRY(VIRTIO_BLK_F_SCSI, \
+            "VIRTIO_BLK_F_SCSI: SCSI packet commands supported"),
+    FEATURE_ENTRY(VIRTIO_BLK_F_FLUSH, \
+            "VIRTIO_BLK_F_FLUSH: Flush command supported"),
+    FEATURE_ENTRY(VIRTIO_BLK_F_CONFIG_WCE, \
+            "VIRTIO_BLK_F_CONFIG_WCE: Cache writeback and writethrough modes "
+            "supported"),
+#endif /* !VIRTIO_BLK_NO_LEGACY */
+    FEATURE_ENTRY(VHOST_F_LOG_ALL, \
+            "VHOST_F_LOG_ALL: Logging write descriptors supported"),
+    FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
+            "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
+            "negotiation supported"),
+    { -1, "" }
+};
+
+/* virtio-serial features mapping */
+qmp_virtio_feature_map_t virtio_serial_feature_map[] = {
+    FEATURE_ENTRY(VIRTIO_CONSOLE_F_SIZE, \
+            "VIRTIO_CONSOLE_F_SIZE: Host providing console size"),
+    FEATURE_ENTRY(VIRTIO_CONSOLE_F_MULTIPORT, \
+            "VIRTIO_CONSOLE_F_MULTIPORT: Multiple ports for device supported"),
+    FEATURE_ENTRY(VIRTIO_CONSOLE_F_EMERG_WRITE, \
+            "VIRTIO_CONSOLE_F_EMERG_WRITE: Emergency write supported"),
+    { -1, "" }
+};
+
+/* virtio-gpu features mapping */
+qmp_virtio_feature_map_t virtio_gpu_feature_map[] = {
+    FEATURE_ENTRY(VIRTIO_GPU_F_VIRGL, \
+            "VIRTIO_GPU_F_VIRGL: Virgl 3D mode supported"),
+    FEATURE_ENTRY(VIRTIO_GPU_F_EDID, \
+            "VIRTIO_GPU_F_EDID: EDID metadata supported"),
+    FEATURE_ENTRY(VIRTIO_GPU_F_RESOURCE_UUID, \
+            "VIRTIO_GPU_F_RESOURCE_UUID: Resource UUID assigning supported"),
+    FEATURE_ENTRY(VIRTIO_GPU_F_RESOURCE_BLOB, \
+            "VIRTIO_GPU_F_RESOURCE_BLOB: Size-based blob resources supported"),
+    FEATURE_ENTRY(VIRTIO_GPU_F_CONTEXT_INIT, \
+            "VIRTIO_GPU_F_CONTEXT_INIT: Context types and synchronization "
+            "timelines supported"),
+    FEATURE_ENTRY(VHOST_F_LOG_ALL, \
+            "VHOST_F_LOG_ALL: Logging write descriptors supported"),
+    FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
+            "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
+            "negotiation supported"),
+    { -1, "" }
+};
+
+/* virtio-input features mapping */
+qmp_virtio_feature_map_t virtio_input_feature_map[] = {
+    FEATURE_ENTRY(VHOST_F_LOG_ALL, \
+            "VHOST_F_LOG_ALL: Logging write descriptors supported"),
+    FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
+            "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
+            "negotiation supported"),
+    { -1, "" }
+};
+
+/* virtio-net features mapping */
+qmp_virtio_feature_map_t virtio_net_feature_map[] = {
+    FEATURE_ENTRY(VIRTIO_NET_F_CSUM, \
+            "VIRTIO_NET_F_CSUM: Device handling packets with partial checksum "
+            "supported"),
+    FEATURE_ENTRY(VIRTIO_NET_F_GUEST_CSUM, \
+            "VIRTIO_NET_F_GUEST_CSUM: Driver handling packets with partial "
+            "checksum supported"),
+    FEATURE_ENTRY(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, \
+            "VIRTIO_NET_F_CTRL_GUEST_OFFLOADS: Control channel offloading "
+            "reconfig. supported"),
+    FEATURE_ENTRY(VIRTIO_NET_F_MTU, \
+            "VIRTIO_NET_F_MTU: Device max MTU reporting supported"),
+    FEATURE_ENTRY(VIRTIO_NET_F_MAC, \
+            "VIRTIO_NET_F_MAC: Device has given MAC address"),
+    FEATURE_ENTRY(VIRTIO_NET_F_GUEST_TSO4, \
+            "VIRTIO_NET_F_GUEST_TSO4: Driver can receive TSOv4"),
+    FEATURE_ENTRY(VIRTIO_NET_F_GUEST_TSO6, \
+            "VIRTIO_NET_F_GUEST_TSO6: Driver can receive TSOv6"),
+    FEATURE_ENTRY(VIRTIO_NET_F_GUEST_ECN, \
+            "VIRTIO_NET_F_GUEST_ECN: Driver can receive TSO with ECN"),
+    FEATURE_ENTRY(VIRTIO_NET_F_GUEST_UFO, \
+            "VIRTIO_NET_F_GUEST_UFO: Driver can receive UFO"),
+    FEATURE_ENTRY(VIRTIO_NET_F_HOST_TSO4, \
+            "VIRTIO_NET_F_HOST_TSO4: Device can receive TSOv4"),
+    FEATURE_ENTRY(VIRTIO_NET_F_HOST_TSO6, \
+            "VIRTIO_NET_F_HOST_TSO6: Device can receive TSOv6"),
+    FEATURE_ENTRY(VIRTIO_NET_F_HOST_ECN, \
+            "VIRTIO_NET_F_HOST_ECN: Device can receive TSO with ECN"),
+    FEATURE_ENTRY(VIRTIO_NET_F_HOST_UFO, \
+            "VIRTIO_NET_F_HOST_UFO: Device can receive UFO"),
+    FEATURE_ENTRY(VIRTIO_NET_F_MRG_RXBUF, \
+            "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive buffers"),
+    FEATURE_ENTRY(VIRTIO_NET_F_STATUS, \
+            "VIRTIO_NET_F_STATUS: Configuration status field available"),
+    FEATURE_ENTRY(VIRTIO_NET_F_CTRL_VQ, \
+            "VIRTIO_NET_F_CTRL_VQ: Control channel available"),
+    FEATURE_ENTRY(VIRTIO_NET_F_CTRL_RX, \
+            "VIRTIO_NET_F_CTRL_RX: Control channel RX mode supported"),
+    FEATURE_ENTRY(VIRTIO_NET_F_CTRL_VLAN, \
+            "VIRTIO_NET_F_CTRL_VLAN: Control channel VLAN filtering supported"),
+    FEATURE_ENTRY(VIRTIO_NET_F_CTRL_RX_EXTRA, \
+            "VIRTIO_NET_F_CTRL_RX_EXTRA: Extra RX mode control supported"),
+    FEATURE_ENTRY(VIRTIO_NET_F_GUEST_ANNOUNCE, \
+            "VIRTIO_NET_F_GUEST_ANNOUNCE: Driver sending gratuitous packets "
+            "supported"),
+    FEATURE_ENTRY(VIRTIO_NET_F_MQ, \
+            "VIRTIO_NET_F_MQ: Multiqueue with automatic receive steering "
+            "supported"),
+    FEATURE_ENTRY(VIRTIO_NET_F_CTRL_MAC_ADDR, \
+            "VIRTIO_NET_F_CTRL_MAC_ADDR: MAC address set through control "
+            "channel"),
+    FEATURE_ENTRY(VIRTIO_NET_F_HASH_REPORT, \
+            "VIRTIO_NET_F_HASH_REPORT: Hash reporting supported"),
+    FEATURE_ENTRY(VIRTIO_NET_F_RSS, \
+            "VIRTIO_NET_F_RSS: RSS RX steering supported"),
+    FEATURE_ENTRY(VIRTIO_NET_F_RSC_EXT, \
+            "VIRTIO_NET_F_RSC_EXT: Extended coalescing info supported"),
+    FEATURE_ENTRY(VIRTIO_NET_F_STANDBY, \
+            "VIRTIO_NET_F_STANDBY: Device acting as standby for primary "
+            "device with same MAC addr. supported"),
+    FEATURE_ENTRY(VIRTIO_NET_F_SPEED_DUPLEX, \
+            "VIRTIO_NET_F_SPEED_DUPLEX: Device set linkspeed and duplex"),
+#ifndef VIRTIO_NET_NO_LEGACY
+    FEATURE_ENTRY(VIRTIO_NET_F_GSO, \
+            "VIRTIO_NET_F_GSO: Handling GSO-type packets supported"),
+#endif /* !VIRTIO_NET_NO_LEGACY */
+    FEATURE_ENTRY(VHOST_NET_F_VIRTIO_NET_HDR, \
+            "VHOST_NET_F_VIRTIO_NET_HDR: Virtio-net headers for RX and TX "
+            "packets supported"),
+    FEATURE_ENTRY(VHOST_F_LOG_ALL, \
+            "VHOST_F_LOG_ALL: Logging write descriptors supported"),
+    FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
+            "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
+            "negotiation supported"),
+    { -1, "" }
+};
+
+/* virtio-scsi features mapping */
+qmp_virtio_feature_map_t virtio_scsi_feature_map[] = {
+    FEATURE_ENTRY(VIRTIO_SCSI_F_INOUT, \
+            "VIRTIO_SCSI_F_INOUT: Requests including read and writable data "
+            "buffers suppoted"),
+    FEATURE_ENTRY(VIRTIO_SCSI_F_HOTPLUG, \
+            "VIRTIO_SCSI_F_HOTPLUG: Reporting and handling hot-plug events "
+            "supported"),
+    FEATURE_ENTRY(VIRTIO_SCSI_F_CHANGE, \
+            "VIRTIO_SCSI_F_CHANGE: Reporting and handling LUN changes "
+            "supported"),
+    FEATURE_ENTRY(VIRTIO_SCSI_F_T10_PI, \
+            "VIRTIO_SCSI_F_T10_PI: T10 info included in request header"),
+    FEATURE_ENTRY(VHOST_F_LOG_ALL, \
+            "VHOST_F_LOG_ALL: Logging write descriptors supported"),
+    FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
+            "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
+            "negotiation supported"),
+    { -1, "" }
+};
+
+/* virtio/vhost-user-fs features mapping */
+qmp_virtio_feature_map_t virtio_fs_feature_map[] = {
+    FEATURE_ENTRY(VHOST_F_LOG_ALL, \
+            "VHOST_F_LOG_ALL: Logging write descriptors supported"),
+    FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
+            "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
+            "negotiation supported"),
+    { -1, "" }
+};
+
+/* virtio/vhost-user-i2c features mapping */
+qmp_virtio_feature_map_t virtio_i2c_feature_map[] = {
+    FEATURE_ENTRY(VIRTIO_I2C_F_ZERO_LENGTH_REQUEST, \
+            "VIRTIO_I2C_F_ZERO_LEGNTH_REQUEST: Zero length requests supported"),
+    FEATURE_ENTRY(VHOST_F_LOG_ALL, \
+            "VHOST_F_LOG_ALL: Logging write descriptors supported"),
+    FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
+            "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
+            "negotiation supported"),
+    { -1, "" }
+};
+
+/* virtio/vhost-vsock features mapping */
+qmp_virtio_feature_map_t virtio_vsock_feature_map[] = {
+    FEATURE_ENTRY(VIRTIO_VSOCK_F_SEQPACKET, \
+            "VIRTIO_VSOCK_F_SEQPACKET: SOCK_SEQPACKET supported"),
+    FEATURE_ENTRY(VHOST_F_LOG_ALL, \
+            "VHOST_F_LOG_ALL: Logging write descriptors supported"),
+    FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
+            "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
+            "negotiation supported"),
+    { -1, "" }
+};
+
+/* virtio-balloon features mapping */
+qmp_virtio_feature_map_t virtio_balloon_feature_map[] = {
+    FEATURE_ENTRY(VIRTIO_BALLOON_F_MUST_TELL_HOST, \
+            "VIRTIO_BALLOON_F_MUST_TELL_HOST: Tell host before reclaiming "
+            "pages"),
+    FEATURE_ENTRY(VIRTIO_BALLOON_F_STATS_VQ, \
+            "VIRTIO_BALLOON_F_STATS_VQ: Guest memory stats VQ available"),
+    FEATURE_ENTRY(VIRTIO_BALLOON_F_DEFLATE_ON_OOM, \
+            "VIRTIO_BALLOON_F_DEFLATE_ON_OOM: Deflate balloon when guest OOM"),
+    FEATURE_ENTRY(VIRTIO_BALLOON_F_FREE_PAGE_HINT, \
+            "VIRTIO_BALLOON_F_FREE_PAGE_HINT: VQ reporting free pages enabled"),
+    FEATURE_ENTRY(VIRTIO_BALLOON_F_PAGE_POISON, \
+            "VIRTIO_BALLOON_F_PAGE_POISON: Guest page poisoning enabled"),
+    FEATURE_ENTRY(VIRTIO_BALLOON_F_REPORTING, \
+            "VIRTIO_BALLOON_F_REPORTING: Page reporting VQ enabled"),
+    { -1, "" }
+};
+
+/* virtio-crypto features mapping */
+qmp_virtio_feature_map_t virtio_crypto_feature_map[] = {
+    FEATURE_ENTRY(VHOST_F_LOG_ALL, \
+            "VHOST_F_LOG_ALL: Logging write descriptors supported"),
+    { -1, "" }
+};
+
+/* virtio-iommu features mapping */
+qmp_virtio_feature_map_t virtio_iommu_feature_map[] = {
+    FEATURE_ENTRY(VIRTIO_IOMMU_F_INPUT_RANGE, \
+            "VIRTIO_IOMMU_F_INPUT_RANGE: Range of available virtual addrs. "
+            "available"),
+    FEATURE_ENTRY(VIRTIO_IOMMU_F_DOMAIN_RANGE, \
+            "VIRTIO_IOMMU_F_DOMAIN_RANGE: Number of supported domains "
+            "available"),
+    FEATURE_ENTRY(VIRTIO_IOMMU_F_MAP_UNMAP, \
+            "VIRTIO_IOMMU_F_MAP_UNMAP: Map and unmap requests available"),
+    FEATURE_ENTRY(VIRTIO_IOMMU_F_BYPASS, \
+            "VIRTIO_IOMMU_F_BYPASS: Endpoints not attached to domains are in "
+            "bypass mode"),
+    FEATURE_ENTRY(VIRTIO_IOMMU_F_PROBE, \
+            "VIRTIO_IOMMU_F_PROBE: Probe requests available"),
+    FEATURE_ENTRY(VIRTIO_IOMMU_F_MMIO, \
+            "VIRTIO_IOMMU_F_MMIO: VIRTIO_IOMMU_MAP_F_MMIO flag available"),
+    FEATURE_ENTRY(VIRTIO_IOMMU_F_BYPASS_CONFIG, \
+            "VIRTIO_IOMMU_F_BYPASS_CONFIG: Bypass field of IOMMU config "
+            "available"),
+    { -1, "" }
+};
+
+/* virtio-mem features mapping */
+qmp_virtio_feature_map_t virtio_mem_feature_map[] = {
+#ifndef CONFIG_ACPI
+    FEATURE_ENTRY(VIRTIO_MEM_F_ACPI_PXM, \
+            "VIRTIO_MEM_F_ACPI_PXM: node_id is an ACPI PXM and is valid"),
+#endif /* !CONFIG_ACPI */
+    FEATURE_ENTRY(VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE, \
+            "VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE: Unplugged memory cannot be "
+            "accessed"),
+    { -1, "" }
+};
+
+/* virtio-rng features mapping */
+qmp_virtio_feature_map_t virtio_rng_feature_map[] = {
+    FEATURE_ENTRY(VHOST_F_LOG_ALL, \
+            "VHOST_F_LOG_ALL: Logging write descriptors supported"),
+    FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
+            "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
+            "negotiation supported"),
+    { -1, "" }
+};
+
 /*
  * The alignment to use between consumer and producer parts of vring.
  * x86 pagesize again. This is the default, used by transports like PCI
@@ -3975,6 +4398,203 @@ static VirtIODevice *virtio_device_find(const char *path)
     return NULL;
 }
 
+#define CONVERT_FEATURES(type, map, is_status, bitmap)   \
+    ({                                                   \
+        type *list = NULL;                               \
+        type *node;                                      \
+        for (i = 0; map[i].virtio_bit != -1; i++) {      \
+            if (is_status) {                             \
+                bit = map[i].virtio_bit;                 \
+            }                                            \
+            else {                                       \
+                bit = 1ULL << map[i].virtio_bit;         \
+            }                                            \
+            if ((bitmap & bit) == 0) {                   \
+                continue;                                \
+            }                                            \
+            node = g_new0(type, 1);                      \
+            node->value = g_strdup(map[i].feature_desc); \
+            node->next = list;                           \
+            list = node;                                 \
+            bitmap ^= bit;                               \
+        }                                                \
+        list;                                            \
+    })
+
+static VirtioDeviceStatus *qmp_decode_status(uint8_t bitmap)
+{
+    VirtioDeviceStatus *status;
+    uint8_t bit;
+    int i;
+
+    status = g_new0(VirtioDeviceStatus, 1);
+    status->statuses = CONVERT_FEATURES(strList, virtio_config_status_map,
+                                        1, bitmap);
+    status->has_unknown_statuses = bitmap != 0;
+    if (status->has_unknown_statuses) {
+        status->unknown_statuses = bitmap;
+    }
+
+    return status;
+}
+
+static VhostDeviceProtocols *qmp_decode_protocols(uint64_t bitmap)
+{
+    VhostDeviceProtocols *vhu_protocols;
+    uint64_t bit;
+    int i;
+
+    vhu_protocols = g_new0(VhostDeviceProtocols, 1);
+    vhu_protocols->protocols =
+                    CONVERT_FEATURES(strList,
+                                     vhost_user_protocol_map, 0, bitmap);
+    vhu_protocols->has_unknown_protocols = bitmap != 0;
+    if (vhu_protocols->has_unknown_protocols) {
+        vhu_protocols->unknown_protocols = bitmap;
+    }
+
+    return vhu_protocols;
+}
+
+static VirtioDeviceFeatures *qmp_decode_features(uint16_t device_id,
+                                                 uint64_t bitmap)
+{
+    VirtioDeviceFeatures *features;
+    uint64_t bit;
+    int i;
+
+    features = g_new0(VirtioDeviceFeatures, 1);
+    features->has_dev_features = true;
+
+    /* transport features */
+    features->transports = CONVERT_FEATURES(strList, virtio_transport_map, 0,
+                                            bitmap);
+
+    /* device features */
+    switch (device_id) {
+#ifdef CONFIG_VIRTIO_SERIAL
+    case VIRTIO_ID_CONSOLE:
+        features->dev_features =
+            CONVERT_FEATURES(strList, virtio_serial_feature_map, 0, bitmap);
+        break;
+#endif
+#ifdef CONFIG_VIRTIO_BLK
+    case VIRTIO_ID_BLOCK:
+        features->dev_features =
+            CONVERT_FEATURES(strList, virtio_blk_feature_map, 0, bitmap);
+        break;
+#endif
+#ifdef CONFIG_VIRTIO_GPU
+    case VIRTIO_ID_GPU:
+        features->dev_features =
+            CONVERT_FEATURES(strList, virtio_gpu_feature_map, 0, bitmap);
+        break;
+#endif
+#ifdef CONFIG_VIRTIO_NET
+    case VIRTIO_ID_NET:
+        features->dev_features =
+            CONVERT_FEATURES(strList, virtio_net_feature_map, 0, bitmap);
+        break;
+#endif
+#ifdef CONFIG_VIRTIO_SCSI
+    case VIRTIO_ID_SCSI:
+        features->dev_features =
+            CONVERT_FEATURES(strList, virtio_scsi_feature_map, 0, bitmap);
+        break;
+#endif
+#ifdef CONFIG_VIRTIO_BALLOON
+    case VIRTIO_ID_BALLOON:
+        features->dev_features =
+            CONVERT_FEATURES(strList, virtio_balloon_feature_map, 0, bitmap);
+        break;
+#endif
+#ifdef CONFIG_VIRTIO_IOMMU
+    case VIRTIO_ID_IOMMU:
+        features->dev_features =
+            CONVERT_FEATURES(strList, virtio_iommu_feature_map, 0, bitmap);
+        break;
+#endif
+#ifdef CONFIG_VIRTIO_INPUT
+    case VIRTIO_ID_INPUT:
+        features->dev_features =
+            CONVERT_FEATURES(strList, virtio_input_feature_map, 0, bitmap);
+        break;
+#endif
+#ifdef CONFIG_VHOST_USER_FS
+    case VIRTIO_ID_FS:
+        features->dev_features =
+            CONVERT_FEATURES(strList, virtio_fs_feature_map, 0, bitmap);
+        break;
+#endif
+#ifdef CONFIG_VHOST_VSOCK
+    case VIRTIO_ID_VSOCK:
+        features->dev_features =
+            CONVERT_FEATURES(strList, virtio_vsock_feature_map, 0, bitmap);
+        break;
+#endif
+#ifdef CONFIG_VIRTIO_CRYPTO
+    case VIRTIO_ID_CRYPTO:
+        features->dev_features =
+            CONVERT_FEATURES(strList, virtio_crypto_feature_map, 0, bitmap);
+        break;
+#endif
+#ifdef CONFIG_VIRTIO_MEM
+    case VIRTIO_ID_MEM:
+        features->dev_features =
+            CONVERT_FEATURES(strList, virtio_mem_feature_map, 0, bitmap);
+        break;
+#endif
+#ifdef CONFIG_VIRTIO_I2C_ADAPTER
+    case VIRTIO_ID_I2C_ADAPTER:
+        features->dev_features =
+            CONVERT_FEATURES(strList, virtio_i2c_feature_map, 0, bitmap);
+        break;
+#endif
+#ifdef CONFIG_VIRTIO_RNG
+    case VIRTIO_ID_RNG:
+        features->dev_features =
+            CONVERT_FEATURES(strList, virtio_rng_feature_map, 0, bitmap);
+        break;
+#endif
+    /* No features */
+    case VIRTIO_ID_9P:
+    case VIRTIO_ID_PMEM:
+    case VIRTIO_ID_IOMEM:
+    case VIRTIO_ID_RPMSG:
+    case VIRTIO_ID_CLOCK:
+    case VIRTIO_ID_MAC80211_WLAN:
+    case VIRTIO_ID_MAC80211_HWSIM:
+    case VIRTIO_ID_RPROC_SERIAL:
+    case VIRTIO_ID_MEMORY_BALLOON:
+    case VIRTIO_ID_CAIF:
+    case VIRTIO_ID_SIGNAL_DIST:
+    case VIRTIO_ID_PSTORE:
+    case VIRTIO_ID_SOUND:
+    case VIRTIO_ID_BT:
+    case VIRTIO_ID_RPMB:
+    case VIRTIO_ID_VIDEO_ENCODER:
+    case VIRTIO_ID_VIDEO_DECODER:
+    case VIRTIO_ID_SCMI:
+    case VIRTIO_ID_NITRO_SEC_MOD:
+    case VIRTIO_ID_WATCHDOG:
+    case VIRTIO_ID_CAN:
+    case VIRTIO_ID_DMABUF:
+    case VIRTIO_ID_PARAM_SERV:
+    case VIRTIO_ID_AUDIO_POLICY:
+    case VIRTIO_ID_GPIO:
+        break;
+    default:
+        g_assert_not_reached();
+    }
+
+    features->has_unknown_dev_features = bitmap != 0;
+    if (features->has_unknown_dev_features) {
+        features->unknown_dev_features = bitmap;
+    }
+
+    return features;
+}
+
 VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
 {
     VirtIODevice *vdev;
@@ -3990,9 +4610,12 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
     status->name = g_strdup(vdev->name);
     status->device_id = vdev->device_id;
     status->vhost_started = vdev->vhost_started;
-    status->guest_features = vdev->guest_features;
-    status->host_features = vdev->host_features;
-    status->backend_features = vdev->backend_features;
+    status->guest_features = qmp_decode_features(vdev->device_id,
+                                                 vdev->guest_features);
+    status->host_features = qmp_decode_features(vdev->device_id,
+                                                vdev->host_features);
+    status->backend_features = qmp_decode_features(vdev->device_id,
+                                                   vdev->backend_features);
 
     switch (vdev->device_endian) {
     case VIRTIO_DEVICE_ENDIAN_LITTLE:
@@ -4007,7 +4630,7 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
     }
 
     status->num_vqs = virtio_get_num_queues(vdev);
-    status->status = vdev->status;
+    status->status = qmp_decode_status(vdev->status);
     status->isr = vdev->isr;
     status->queue_sel = vdev->queue_sel;
     status->vm_running = vdev->vm_running;
@@ -4030,10 +4653,14 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
         status->vhost_dev->n_tmp_sections = hdev->n_tmp_sections;
         status->vhost_dev->nvqs = hdev->nvqs;
         status->vhost_dev->vq_index = hdev->vq_index;
-        status->vhost_dev->features = hdev->features;
-        status->vhost_dev->acked_features = hdev->acked_features;
-        status->vhost_dev->backend_features = hdev->backend_features;
-        status->vhost_dev->protocol_features = hdev->protocol_features;
+        status->vhost_dev->features =
+            qmp_decode_features(vdev->device_id, hdev->features);
+        status->vhost_dev->acked_features =
+            qmp_decode_features(vdev->device_id, hdev->acked_features);
+        status->vhost_dev->backend_features =
+            qmp_decode_features(vdev->device_id, hdev->backend_features);
+        status->vhost_dev->protocol_features =
+            qmp_decode_protocols(hdev->protocol_features);
         status->vhost_dev->max_queues = hdev->max_queues;
         status->vhost_dev->backend_cap = hdev->backend_cap;
         status->vhost_dev->log_enabled = hdev->log_enabled;
include/hw/virtio/vhost.h +3 -0
index a346f23d13..1f6655e149 100644
@@ -5,6 +5,9 @@
 #include "hw/virtio/virtio.h"
 #include "exec/memory.h"
 
+#define VHOST_F_DEVICE_IOTLB 63
+#define VHOST_USER_F_PROTOCOL_FEATURES 30
+
 /* Generic structures common for any vhost based device. */
 
 struct vhost_inflight {
include/hw/virtio/virtio.h +5 -0
index 375eb5671b..69025f2914 100644
@@ -71,6 +71,11 @@ typedef struct VirtQueueElement
 #define TYPE_VIRTIO_DEVICE "virtio-device"
 OBJECT_DECLARE_TYPE(VirtIODevice, VirtioDeviceClass, VIRTIO_DEVICE)
 
+typedef struct {
+    int virtio_bit;
+    const char *feature_desc;
+} qmp_virtio_feature_map_t;
+
 enum virtio_device_endian {
     VIRTIO_DEVICE_ENDIAN_UNKNOWN,
     VIRTIO_DEVICE_ENDIAN_LITTLE,
qapi/virtio.json +231 -20

291 lines not on this page · raw message

Signature · 1 line
2.31.1
#17 lore raw

PATCH v15 4/6 qmp: add QMP commands for virtio/vhost queue-status

In reply to Jonah Palmer

From: Laurent Vivier <[email protected]>

These new commands show the internal status of a VirtIODevice's VirtQueue and a vhost device's vhost_virtqueue (if active).

---
 hw/virtio/virtio-stub.c |  14 +++
 hw/virtio/virtio.c      | 103 ++++++++++++++++
 qapi/virtio.json        | 256 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 373 insertions(+)
hw/virtio/virtio-stub.c +14 -0
index 0b432e8de7..13e5f93652 100644
@@ -17,3 +17,17 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
 {
     return qmp_virtio_unsupported(errp);
 }
+
+VirtVhostQueueStatus *qmp_x_query_virtio_vhost_queue_status(const char *path,
+                                                            uint16_t queue,
+                                                            Error **errp)
+{
+    return qmp_virtio_unsupported(errp);
+}
+
+VirtQueueStatus *qmp_x_query_virtio_queue_status(const char *path,
+                                                 uint16_t queue,
+                                                 Error **errp)
+{
+    return qmp_virtio_unsupported(errp);
+}
hw/virtio/virtio.c +103 -0

109 lines not on this page · raw message

qapi/virtio.json +256 -0

259 lines not on this page · raw message

Signature · 1 line
2.31.1
#18 lore raw

PATCH v15 5/6 qmp: add QMP command x-query-virtio-queue-element

In reply to Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command shows the information of a VirtQueue element.

[Note: Up until v10 of this patch series, virtio.json had many (15+)
enums defined (e.g. decoded device features, statuses, etc.). In v10 most of these enums were removed and replaced with string literals. By doing this we get (1) simpler schema, (2) smaller generated code, and (3) less maintenance burden for when new things are added (e.g. devices, device features, etc.).]

---
 hw/virtio/virtio-stub.c |   9 ++
 hw/virtio/virtio.c      | 154 +++++++++++++++++++++++++++++++
 qapi/virtio.json        | 197 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 360 insertions(+)
hw/virtio/virtio-stub.c +9 -0
index 13e5f93652..7ddb22cc5e 100644
@@ -31,3 +31,12 @@ VirtQueueStatus *qmp_x_query_virtio_queue_status(const char *path,
 {
     return qmp_virtio_unsupported(errp);
 }
+
+VirtioQueueElement *qmp_x_query_virtio_queue_element(const char *path,
+                                                     uint16_t queue,
+                                                     bool has_index,
+                                                     uint16_t index,
+                                                     Error **errp)
+{
+    return qmp_virtio_unsupported(errp);
+}
hw/virtio/virtio.c +154 -0

166 lines not on this page · raw message

qapi/virtio.json +197 -0

200 lines not on this page · raw message

Signature · 1 line
2.31.1
#19 lore raw

PATCH v15 6/6 hmp: add virtio commands

In reply to Jonah Palmer

From: Laurent Vivier <[email protected]>

This patch implements the HMP versions of the virtio QMP commands.

[Jonah: Adjusted hmp monitor output format for features / statuses
with their descriptions.]

---
 hmp-commands-info.hx  |  70 ++++++++++
 include/monitor/hmp.h |   5 +
 monitor/hmp-cmds.c    | 310 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 385 insertions(+)
hmp-commands-info.hx +70 -0
index 188d9ece3b..58cfa86638 100644
@@ -921,3 +921,73 @@ SRST
   ``stats``
     Show runtime-collected statistics
 ERST
+
+    {
+        .name      = "virtio",
+        .args_type = "",
+        .params    = "",
+        .help      = "List all available virtio devices",
+        .cmd       = hmp_virtio_query,
+        .flags     = "p",
+    },
+
+SRST
+  ``info virtio``
+    List all available virtio devices
+ERST
+
+    {
+        .name      = "virtio-status",
+        .args_type = "path:s",
+        .params    = "path",
+        .help      = "Display status of a given virtio device",
+        .cmd       = hmp_virtio_status,
+        .flags     = "p",
+    },
+
+SRST
+  ``info virtio-status`` *path*
+    Display status of a given virtio device
+ERST
+
+    {
+        .name      = "virtio-queue-status",
+        .args_type = "path:s,queue:i",
+        .params    = "path queue",
+        .help      = "Display status of a given virtio queue",
+        .cmd       = hmp_virtio_queue_status,
+        .flags     = "p",
+    },
+
+SRST
+  ``info virtio-queue-status`` *path* *queue*
+    Display status of a given virtio queue
+ERST
+
+    {
+        .name      = "virtio-vhost-queue-status",
+        .args_type = "path:s,queue:i",
+        .params    = "path queue",
+        .help      = "Display status of a given vhost queue",
+        .cmd       = hmp_vhost_queue_status,
+        .flags     = "p",
+    },
+
+SRST
+  ``info virtio-vhost-queue-status`` *path* *queue*
+    Display status of a given vhost queue
+ERST
+
+    {
+        .name       = "virtio-queue-element",
+        .args_type  = "path:s,queue:i,index:i?",
+        .params     = "path queue [index]",
+        .help       = "Display element of a given virtio queue",
+        .cmd        = hmp_virtio_queue_element,
+        .flags      = "p",
+    },
+
+SRST
+  ``info virtio-queue-element`` *path* *queue* [*index*]
+    Display element of a given virtio queue
+ERST
include/monitor/hmp.h +5 -0
index a618eb1e4e..a9cf064ee8 100644
@@ -95,6 +95,11 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict);
 void hmp_qom_get(Monitor *mon, const QDict *qdict);
 void hmp_qom_set(Monitor *mon, const QDict *qdict);
 void hmp_info_qom_tree(Monitor *mon, const QDict *dict);
+void hmp_virtio_query(Monitor *mon, const QDict *qdict);
+void hmp_virtio_status(Monitor *mon, const QDict *qdict);
+void hmp_virtio_queue_status(Monitor *mon, const QDict *qdict);
+void hmp_vhost_queue_status(Monitor *mon, const QDict *qdict);
+void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict);
 void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
monitor/hmp-cmds.c +310 -0

319 lines not on this page · raw message

Signature · 1 line
2.31.1
#20 lore raw
In reply to Jonah Palmer

Hey Michael, when you get the chance, could you review these patches for me? Specifically patch 3/6, as that has the majority of the changes made for this series. Thanks!

Jonah
________________________________
From: Jonah Palmer
Sent: Thursday, August 11, 2022 8:26 AM
To: [email protected] <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Si-Wei Liu <[email protected]>; Joao Martins <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Boris Ostrovsky <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Subject: [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices

This series introduces new QMP/HMP commands to dump the status of a virtio device at different levels.

[Jonah: Rebasing from previous patchset from Apr. 1 (v14). Original patches
are by Laurent Vivier from May 2020.

I sincerely apologize for the *massive* delay in getting this latest v15 series out. It was a perferct storm of other more pressing issues, time off, and trying to understand why I was seeing this 30 feature bit in my PCI virtio devices. Please see patch 3/6 for more explanation on this issue.

Rebase from v14 to v15 includes: adding the missing sign-off-by from the poster, renaming & moving all virtio device feature map definitions to hw/virtio/virtio.c, including brief descriptions for all status & feature bits, a new virtio device feature map defined for virtio-rng, and mappings for virtio/vhost-vsock, virtio-iommu, virtio-mem, and virtio transport features updated with their newest feature bits. Most of these changes can be found in patch 3/6.

And again, sorry for the long wait on this.]

1. List available virtio devices in the machine

HMP Form:

info virtio

Example:

(qemu) info virtio /machine/peripheral-anon/device[2]/virtio-backend [virtio-scsi] /machine/peripheral/vsock0/virtio-backend [vhost-vsock] /machine/peripheral/crypto0/virtio-backend [virtio-crypto] /machine/peripheral-anon/device[1]/virtio-backend [virtio-net] /machine/peripheral-anon/device[0]/virtio-backend [virtio-serial]

QMP Form:

    { 'command': 'x-query-virtio',
      'returns': ['VirtioInfo'],
      'features': [ 'unstable' ] }

    Example:

        -> { "execute": "x-query-virtio" }
        <- { "return": [
                 {
                     "name": "virtio-scsi",
                     "path": "/machine/peripheral-anon/device[2]/virtio-backend"
                 },
                 {
                     "name": "vhost-vsock",
                     "path": "/machine/peripheral/vsock0/virtio-backend"
                 },
                 {
                     "name": "virtio-crypto",
                     "path": "/machine/peripheral/crypto0/virtio-backend"
                 },
                 {
                     "name": "virtio-net",
                     "path": "/machine/peripheral-anon/device[1]/virtio-backend"
                 },
                 {
                     "name": "virtio-serial",
                     "path": "/machine/peripheral-anon/device[0]/virtio-backend"
                 }
             ]
           }

2. Display status of a given virtio device

HMP Form:

info virtio-status <path>

Example:

(qemu) info virtio-status /machine/peripheral/vsock0/virtio-backend /machine/peripheral/vsock0/virtio-backend:
device_name: vhost-vsock (vhost)
device_id: 19
vhost_started: true
bus_name: (null)
broken: false
disabled: false
disable_legacy_check: false
started: true
use_started: true
start_on_kick: false
use_guest_notifier_mask: true
vm_running: true
num_vqs: 3
queue_sel: 2
isr: 0
endianness: little
status:
VIRTIO_CONFIG_S_ACKNOWLEDGE: Valid virtio device found,
VIRTIO_CONFIG_S_DRIVER: Guest OS compatible with device, VIRTIO_CONFIG_S_FEATURES_OK: Feature negotiation complete,
VIRTIO_CONFIG_S_DRIVER_OK: Driver setup and ready
Guest features:
VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled, VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported,
VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)
Host features:
VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled, VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported,
VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy),
VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts,
VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features negotiation supported
Backend features:

VHost:
nvqs: 2
vq_index: 0
max_queues: 0
n_mem_sections: 4
n_tmp_sections: 4
backend_cap: 0
log_enabled: false
log_size: 0
Features:
VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled, VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported,
VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy),
VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts,
VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ
VHOST_F_LOG_ALL: Logging write descriptors supported
Acked features:
VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled, VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported,
VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)
Backend features:

Protocol features:

QMP Form:

    { 'command': 'x-query-virtio-status',
      'data': { 'path': 'str' },
      'returns': 'VirtioStatus',
      'features': [ 'unstable' ] }

    Example:

        -> { "execute": "x-query-virtio-status",
             "arguments": { "path": "/machine/peripheral/vsock0/virtio-backend" }
           }
        <- { "return": {
                 "device-endian": "little",
                 "bus-name": "",
                 "disable-legacy-check": false,
                 "name": "vhost-vsock",
                 "started": true,
                 "device-id": 19,
                 "vhost-dev": {
                     "n-tmp-sections": 4,
                     "n-mem-sections": 4,
                     "max-queues": 0,
                     "backend-cap": 0,
                     "log-size": 0,
                     "backend-features": {
                         "dev-features": [
                         ],
                         "transports": [
                         ]
                     },
                     "nvqs": 2,
                     "protocol-features": {
                         "protocols": [
                         ]
                     },
                     "vq-index": 0,
                     "log-enabled": false,
                     "acked-features": {
                         "dev-features": [
                         ],
                         "transports": [
                             "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
                             "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
                             "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)"
                         ]
                     },
                     "features": {
                         "dev-features": [
                             "VHOST_F_LOG_ALL: Logging write descriptors supported"
                         ],
                         "transports": [
                             "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
                             "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
                             "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)",
                             "VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts",
                             "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ"
                         ]
                     }
                 },
                 "backend-features": {
                     "dev-features": [
                     ],
                     "transports": [
                     ]
                 },
                 "start-on-kick": false,
                 "isr": 0,
                 "broken": false,
                 "status": {
                     "statuses": [
                         "VIRTIO_CONFIG_S_ACKNOWLEDGE: Valid virtio device found",
                         "VIRTIO_CONFIG_S_DRIVER: Guest OS compatible with device",
                         "VIRTIO_CONFIG_S_FEATURES_OK: Feature negotiation complete",
                         "VIRTIO_CONFIG_S_DRIVER_OK: Driver setup and ready"
                     ]
                 },
                 "num-vqs": 3,
                 "guest-features": {
                     "dev-features": [
                     ],
                     "transports": [
                         "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
                         "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
                         "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)"
                     ]
                 },
                 "host-features": {
                     "dev-features": [
                         "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features negotiation supported"
                     ],
                     "transports": [
                         "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
                         "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
                         "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)",
                         "VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts",
                         "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ"
                     ]
                 },
                 "use-guest-notifier-mask": true,
                 "vm-running": true,
                 "queue-sel": 2,
                 "disabled": false,
                 "vhost-started": true,
                 "use-started": true
             }
           }

3. Display status of a given virtio queue

HMP Form:

    info virtio-queue-status <path> <queue>

    Example:

        (qemu) info virtio-queue-status /machine/peripheral-anon/device[1]/virtio-backend 2
        /machine/peripheral-anon/device[1]/virtio-backend:
          device_name:          virtio-net
          queue_index:          2
          inuse:                0
          used_idx:             15
          signalled_used:       15
          signalled_used_valid: true
          VRing:
            num:          64
            num_default:  64
            align:        4096
            desc:         0x000000011e15c000
            avail:        0x000000011e15c400
            used:         0x000000011e15c4c0

QMP Form:

    { 'command': 'x-query-virtio-queue-status',
      'data': { 'path': 'str', 'queue': 'uint16' },
      'returns': 'VirtQueueStatus',
      'features': [ 'unstable' ] }

    Example:

        -> { "execute": "x-query-virtio-queue-status",
             "arguments": { "path": "/machine/peripheral-anon/device[1]/virtio-backend",
                            "queue": 2 }
           }
        <- { "return": {
                 "signalled-used": 15,
                 "inuse": 0,
                 "name": "virtio-net",
                 "vring-align": 4096,
                 "vring-desc": 4814004224,
                 "signalled-used-valid": true,
                 "vring-num-default": 64,
                 "vring-avail": 4814005248,
                 "queue-index": 2,
                 "vring-used": 4814005440,
                 "used-idx": 15,
                 "vring-num": 64
             }
           }

4. Display status of a given vhost queue

HMP Form:

    info virtio-vhost-queue-status <path> <queue>

    Example:

        (qemu) info virtio-vhost-queue-status /machine/peripheral-anon/device[1]/virtio-backend 1
        /machine/peripheral-anon/device[1]/virtio-backend:
          device_name:          virtio-net (vhost)
          kick:                 0
          call:                 0
          VRing:
            num:         256
            desc:        0x00007f804df5a000
            desc_phys:   0x000000013315a000
            desc_size:   4096
            avail:       0x00007f804df5b000
            avail_phys:  0x000000013315b000
            avail_size:  518
            used:        0x00007f804df5b240
            used_phys:   0x000000013315b240
            used_size:   2054

QMP Form:

    { 'command': 'x-query-virtio-vhost-queue-status',
      'data': { 'path': 'str', 'queue': 'uint16' },
      'returns': 'VirtVhostQueueStatus',
      'features': [ 'unstable' ] }

    Example:

        -> { "execute": "x-query-virtio-vhost-queue-status",
             "arguments": { "path": "/machine/peripheral-anon/device[1]/virtio-backend",
                            "queue": 1 }
           }
        <- { "return": {
                 "avail-phys": 4803538944,
                 "name": "virtio-net",
                 "used-phys": 4803539520,
                 "avail-size": 518,
                 "desc-size": 4096,
                 "used-size": 2054,
                 "desc": 140186477404160,
                 "num": 256,
                 "call": 0,
                 "avail": 140186477408256,
                 "desc-phys": 4803534848,
                 "used": 140186477408832,
                 "kick": 0
             }
           }

5. Display an element of a given virtio queue

HMP Form:

    info virtio-queue-element <path> <queue> [index]

    Example:

        Dump the information of the head element of the third queue of virtio-scsi:

        (qemu) info virtio-queue-element /machine/peripheral-anon/device[2]/virtio-backend 2
        /machine/peripheral-anon/device[2]/virtio-backend:
          device_name: virtio-scsi
          index:   0
          desc:
            descs:
                addr 0x128890000 len 12288 (write),
                addr 0x128880000 len 65536 (write, next),
                addr 0x128870000 len 65536 (write, next),
                addr 0x128860000 len 65536 (write, next),
                addr 0x128850000 len 65536 (write, next),
                addr 0x128840000 len 65536 (write, next),
                addr 0x128830000 len 65536 (write, next),
                addr 0x128820000 len 65536 (write, next),
                addr 0x128810000 len 65536 (write, next),
                addr 0x128800000 len 65536 (write, next),
                addr 0x116bf3000 len 53248 (write, next),
                addr 0x116be3000 len 65536 (write, next),
                addr 0x116bd3000 len 65536 (write, next),
                addr 0x116bc3000 len 65536 (write, next),
                addr 0x116bb3000 len 65536 (write, next),
                addr 0x116ba3000 len 65536 (write, next),
                addr 0x116b93000 len 65536 (write, next),
                addr 0x116b83000 len 65536 (write, next),
                addr 0x116b73000 len 65536 (write, next),
                addr 0x116b63000 len 65536 (write, next),
                addr 0x116b53000 len 65536 (write, next),
                addr 0x126e9763b len 108 (write, next),
                addr 0x9af8dae7222881a2 len 51 (next)
          avail:
            flags: 0
            idx:   600
            ring:  0
          used:
            flags: 0
            idx:   600

QMP Form:

    { 'command': 'x-query-virtio-queue-element',
      'data': { 'path': 'str', 'queue': 'uint16', '*index': 'uint16' },
      'returns': 'VirtioQueueElement',
      'features': [ 'unstable' ] }

    Example:

        -> { "execute": "x-query-virtio-queue-element",
             "arguments": { "path": "/machine/peripheral-anon/device[2]/virtio-backend",
                            "queue": 2 }
           }
        <- { "return": {
                 "index": 1,
                 "name": "virtio-scsi",
                 "descs": [
                     {
                         "flags": ["write"],
                         "len": 65536,
                         "addr": 4852740096
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852674560
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852609024
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852543488
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852477952
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852412416
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852346880
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852281344
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852215808
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852150272
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852084736
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4852019200
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851953664
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851888128
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851822592
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851757056
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851691520
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851625984
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851560448
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 65536,
                         "addr": 4851494912
                     },
                     {
                         "flags": ["write", "next"],
                         "len": 108,
                         "addr": 4801325435
                     },
                     {
                         "flags": ["next"],
                         "len": 51,
                         "addr": 12075758188190198449
                     }
                 ],
                 "avail": {
                     "idx": 922,
                     "flags": 0,
                     "ring": 1
                 },
                 "used": {
                     "idx": 922,
                     "flags": 0
                 }
             }
           }

v15: added missing sign-off in patches
rebased for upstream (Qemu 7.1)
minor reformatting to examples in qapi/virtio.json virtio device feature maps moved to hw/virtio/virtio.c virtio device feature maps renamed (less generic) virtio device feature maps now include brief description of feature virtio device status map now include brief description of status new feature bits added to mappings for virtio/vhost-vsock, virtio-iommu, & virtio-mem
new virtio transport feature bit added to mapping
new virtio device feature map defined for virtio-rng

v14: move definition of 'gpu_map' to virtio-gpu.c
add new 'context-init' virtio-gpu feature created new feature map 'i2c_map' for vhost-user-i2c fixed casting error for cross-Win64 builds

v13: minor text edit in qapi/virtio.json

v12: minor reformatting for monitor/hmp-cmds.c
use PRI types in virtio hmp monitor printfs

v11: minor reformatting in virtio.json
added synchronicity check when querying virtio devices

v10: rebased for upstream (Qemu 7.0)
reformat virtio.json for better consistency
removed all enums from virtio.json; replaced with string literals removed @ndescs from VirtioQueueElement
removed examples in hmp-commands-info.hx (to fix 'inconsistent literal block quoting' error from Sphinx)

v9: rebased for upstream (Qemu 6.3)
change QMP command prefixes from 'x-debug-virtio' to 'x-query-virtio'
add 'unstable' feature to all 'x-query-virtio' prefixed QMP commands
fix odd indentation for qapi/virtio.json device features support for virtio-mem
move HMP sub-commands under 'virtio' top level to 'info' top level

v8: add assert in virtio_id_to_name() to make sure we're
not returning NULL
minor documentation additions to qapi/virtio.json add virtio introspection support for vhost-user-rng

v7: rebased for upstream (Qemu 6.2)
add ability to map between numberic device ID and string device ID (name) for virtio devices add get_vhost() callback function for VirtIODevices expose more fields of VirtIODevice
expose fields of vhost devices
decode vhost user protocol features
decode VirtIODevice configuration statuses vhost support for displaying virtio queue statuses vhost support for displaying vhost queue statuses expose driver and device areas when introspecting a virtio queue element
changed patch attribution

v6: rebased for upstream (Qemu 6.1)
add all virtio/vhost types in same order as include/standard-headers/linux/virtio_ids.h
use QAPI_LIST_PREPEND in qmp_x_debug_query_virtio rather than open coding

v5: rebased for upstream
add device name, used index, and relative indicies to virtio queue-status HMP command
add device name to virtio queue-status QMP command
add new virtio device features

v4: re-send series as v3 didn't reach qemu-devel

v3: use qapi_free_VirtioInfoList() on the head of the list, not on the tail.
Prefix the QMP commands with 'x-debug-'

v2: introduce VirtioType enum
use an enum for the endianness
change field names to stick to naming convertions (s/_/-/) add a patch to decode feature bits
don't check if the queue is empty to allow display of old elements use enum for desc flags
manage indirect desc
decode device features in the HMP command

Laurent Vivier (6):
qmp: add QMP command x-query-virtio
qmp: add QMP command x-query-virtio-status
qmp: decode feature & status bits in virtio-status
qmp: add QMP commands for virtio/vhost queue-status
qmp: add QMP command x-query-virtio-queue-element
hmp: add virtio commands

 hmp-commands-info.hx       |   70 +++
 hw/virtio/meson.build      |    2 +
 hw/virtio/virtio-stub.c    |   42 ++
 hw/virtio/virtio.c         | 1032 ++++++++++++++++++++++++++++++++++++
 include/hw/virtio/vhost.h  |    3 +
 include/hw/virtio/virtio.h |    6 +
 include/monitor/hmp.h      |    5 +
 monitor/hmp-cmds.c         |  310 +++++++++++
 qapi/meson.build           |    1 +
 qapi/qapi-schema.json      |    1 +
 qapi/virtio.json           |  954 +++++++++++++++++++++++++++++++++
 tests/qtest/qmp-cmd-test.c |    1 +
 12 files changed, 2427 insertions(+)
 create mode 100644 hw/virtio/virtio-stub.c
 create mode 100644 qapi/virtio.json

--
2.31.1