All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices
@ 2022-08-11 12:24 Jonah Palmer
  2022-08-11 12:24 ` [PATCH v15 1/6] qmp: add QMP command x-query-virtio Jonah Palmer
                   ` (6 more replies)
  0 siblings, 7 replies; 15+ messages in thread
From: Jonah Palmer @ 2022-08-11 12:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: mst, qemu_oss, kraxel, si-wei.liu, joao.m.martins, eblake,
	qemu-block, david, armbru, arei.gonglei, marcandre.lureau,
	lvivier, thuth, michael.roth, groug, dgilbert, eric.auger,
	stefanha, boris.ostrovsky, kwolf, mathieu.poirier,
	raphael.norwitz, pbonzini

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



^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v15 1/6] qmp: add QMP command x-query-virtio
  2022-08-11 12:24 [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices Jonah Palmer
@ 2022-08-11 12:24 ` Jonah Palmer
  2022-11-30 16:16   ` Philippe Mathieu-Daudé
  2022-08-11 12:24 ` [PATCH v15 2/6] qmp: add QMP command x-query-virtio-status Jonah Palmer
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 15+ messages in thread
From: Jonah Palmer @ 2022-08-11 12:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: mst, qemu_oss, kraxel, si-wei.liu, joao.m.martins, eblake,
	qemu-block, david, armbru, arei.gonglei, marcandre.lureau,
	lvivier, thuth, michael.roth, groug, dgilbert, eric.auger,
	stefanha, boris.ostrovsky, kwolf, mathieu.poirier,
	raphael.norwitz, pbonzini

From: Laurent Vivier <lvivier@redhat.com>

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.]

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
---
 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

diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build
index 7e8877fd64..e16f1b22d4 100644
--- a/hw/virtio/meson.build
+++ b/hw/virtio/meson.build
@@ -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'))
diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c
new file mode 100644
index 0000000000..05a81edc92
--- /dev/null
+++ b/hw/virtio/virtio-stub.c
@@ -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);
+}
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 5d607aeaa0..bdfa82e9c0 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -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;
+    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 */
+            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;
+}
+
 static const TypeInfo virtio_device_info = {
     .name = TYPE_VIRTIO_DEVICE,
     .parent = TYPE_DEVICE,
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index db1c0ddf6b..375eb5671b 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -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 {
diff --git a/qapi/meson.build b/qapi/meson.build
index fd5c93d643..c35ba874d2 100644
--- a/qapi/meson.build
+++ b/qapi/meson.build
@@ -49,6 +49,7 @@ qapi_all_modules = [
   'stats',
   'trace',
   'transaction',
+  'virtio',
   'yank',
 ]
 if have_system
diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json
index 92d7ecc52c..f000b90744 100644
--- a/qapi/qapi-schema.json
+++ b/qapi/qapi-schema.json
@@ -94,3 +94,4 @@
 { 'include': 'acpi.json' }
 { 'include': 'pci.json' }
 { 'include': 'stats.json' }
+{ 'include': 'virtio.json' }
diff --git a/qapi/virtio.json b/qapi/virtio.json
new file mode 100644
index 0000000000..03896e423f
--- /dev/null
+++ b/qapi/virtio.json
@@ -0,0 +1,68 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+#
+
+##
+# = Virtio devices
+##
+
+##
+# @VirtioInfo:
+#
+# Basic information about a given VirtIODevice
+#
+# @path: The VirtIODevice's canonical QOM path
+#
+# @name: Name of the VirtIODevice
+#
+# Since: 7.1
+#
+##
+{ 'struct': 'VirtioInfo',
+  'data': { 'path': 'str',
+            'name': 'str' } }
+
+##
+# @x-query-virtio:
+#
+# Returns a list of all realized VirtIODevices
+#
+# Features:
+# @unstable: This command is meant for debugging.
+#
+# Returns: List of gathered VirtIODevices
+#
+# Since: 7.1
+#
+# Example:
+#
+# -> { "execute": "x-query-virtio" }
+# <- { "return": [
+#          {
+#              "name": "virtio-input",
+#              "path": "/machine/peripheral-anon/device[4]/virtio-backend"
+#          },
+#          {
+#              "name": "virtio-crypto",
+#              "path": "/machine/peripheral/crypto0/virtio-backend"
+#          },
+#          {
+#              "name": "virtio-scsi",
+#              "path": "/machine/peripheral-anon/device[2]/virtio-backend"
+#          },
+#          {
+#              "name": "virtio-net",
+#              "path": "/machine/peripheral-anon/device[1]/virtio-backend"
+#          },
+#          {
+#              "name": "virtio-serial",
+#              "path": "/machine/peripheral-anon/device[0]/virtio-backend"
+#          }
+#      ]
+#    }
+#
+##
+
+{ 'command': 'x-query-virtio',
+  'returns': [ 'VirtioInfo' ],
+  'features': [ 'unstable' ] }
diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c
index af00712458..897e4e937b 100644
--- a/tests/qtest/qmp-cmd-test.c
+++ b/tests/qtest/qmp-cmd-test.c
@@ -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 */
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v15 2/6] qmp: add QMP command x-query-virtio-status
  2022-08-11 12:24 [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices Jonah Palmer
  2022-08-11 12:24 ` [PATCH v15 1/6] qmp: add QMP command x-query-virtio Jonah Palmer
@ 2022-08-11 12:24 ` Jonah Palmer
  2022-08-11 12:24 ` [PATCH v15 3/6] qmp: decode feature & status bits in virtio-status Jonah Palmer
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Jonah Palmer @ 2022-08-11 12:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: mst, qemu_oss, kraxel, si-wei.liu, joao.m.martins, eblake,
	qemu-block, david, armbru, arei.gonglei, marcandre.lureau,
	lvivier, thuth, michael.roth, groug, dgilbert, eric.auger,
	stefanha, boris.ostrovsky, kwolf, mathieu.poirier,
	raphael.norwitz, pbonzini

From: Laurent Vivier <lvivier@redhat.com>

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.]

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
---
 hw/virtio/virtio-stub.c |   5 +
 hw/virtio/virtio.c      | 104 +++++++++++++++++++
 qapi/virtio.json        | 222 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 331 insertions(+)

diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c
index 05a81edc92..0b432e8de7 100644
--- a/hw/virtio/virtio-stub.c
+++ b/hw/virtio/virtio-stub.c
@@ -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);
+}
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index bdfa82e9c0..3e0a484660 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -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,
diff --git a/qapi/virtio.json b/qapi/virtio.json
index 03896e423f..c86b3bc635 100644
--- a/qapi/virtio.json
+++ b/qapi/virtio.json
@@ -66,3 +66,225 @@
 { 'command': 'x-query-virtio',
   'returns': [ 'VirtioInfo' ],
   'features': [ 'unstable' ] }
+
+##
+# @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' ] }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v15 3/6] qmp: decode feature & status bits in virtio-status
  2022-08-11 12:24 [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices Jonah Palmer
  2022-08-11 12:24 ` [PATCH v15 1/6] qmp: add QMP command x-query-virtio Jonah Palmer
  2022-08-11 12:24 ` [PATCH v15 2/6] qmp: add QMP command x-query-virtio-status Jonah Palmer
@ 2022-08-11 12:24 ` Jonah Palmer
  2022-08-11 12:24 ` [PATCH v15 4/6] qmp: add QMP commands for virtio/vhost queue-status Jonah Palmer
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Jonah Palmer @ 2022-08-11 12:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: mst, qemu_oss, kraxel, si-wei.liu, joao.m.martins, eblake,
	qemu-block, david, armbru, arei.gonglei, marcandre.lureau,
	lvivier, thuth, michael.roth, groug, dgilbert, eric.auger,
	stefanha, boris.ostrovsky, kwolf, mathieu.poirier,
	raphael.norwitz, pbonzini

From: Laurent Vivier <lvivier@redhat.com>

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
]

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
---

 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(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 3e0a484660..23bdc77a95 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -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;
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index a346f23d13..1f6655e149 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -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 {
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 375eb5671b..69025f2914 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -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,
diff --git a/qapi/virtio.json b/qapi/virtio.json
index c86b3bc635..c9c8201e66 100644
--- a/qapi/virtio.json
+++ b/qapi/virtio.json
@@ -106,10 +106,10 @@
             'n-tmp-sections': 'int',
             'nvqs': 'uint32',
             'vq-index': 'int',
-            'features': 'uint64',
-            'acked-features': 'uint64',
-            'backend-features': 'uint64',
-            'protocol-features': 'uint64',
+            'features': 'VirtioDeviceFeatures',
+            'acked-features': 'VirtioDeviceFeatures',
+            'backend-features': 'VirtioDeviceFeatures',
+            'protocol-features': 'VhostDeviceProtocols',
             'max-queues': 'uint64',
             'backend-cap': 'uint64',
             'log-enabled': 'bool',
@@ -176,11 +176,11 @@
             'device-id': 'uint16',
             'vhost-started': 'bool',
             'device-endian': 'str',
-            'guest-features': 'uint64',
-            'host-features': 'uint64',
-            'backend-features': 'uint64',
+            'guest-features': 'VirtioDeviceFeatures',
+            'host-features': 'VirtioDeviceFeatures',
+            'backend-features': 'VirtioDeviceFeatures',
             'num-vqs': 'int',
-            'status': 'uint8',
+            'status': 'VirtioDeviceStatus',
             'isr': 'uint8',
             'queue-sel': 'uint16',
             'vm-running': 'bool',
@@ -222,14 +222,41 @@
 #          "name": "virtio-crypto",
 #          "started": true,
 #          "device-id": 20,
-#          "backend-features": 0,
+#          "backend-features": {
+#              "transports": [],
+#              "dev-features": []
+#          },
 #          "start-on-kick": false,
 #          "isr": 1,
 #          "broken": false,
-#          "status": 15,
+#          "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": 2,
-#          "guest-features": 5100273664,
-#          "host-features": 6325010432,
+#          "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": {
+#              "unknown-dev-features": 1073741824,
+#              "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)",
+#                  "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": 1,
@@ -257,22 +284,147 @@
 #              "max-queues": 1,
 #              "backend-cap": 2,
 #              "log-size": 0,
-#              "backend-features": 0,
+#              "backend-features": {
+#                  "dev-features": [],
+#                  "transports": []
+#              },
 #              "nvqs": 2,
-#              "protocol-features": 0,
+#              "protocol-features": {
+#                  "protocols": []
+#              },
 #              "vq-index": 0,
 #              "log-enabled": false,
-#              "acked-features": 5100306432,
-#              "features": 13908344832
+#              "acked-features": {
+#                  "dev-features": [
+#                      "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive buffers"
+#                  ],
+#                  "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",
+#                      "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive buffers"
+#                  ],
+#                  "transports": [
+#                      "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
+#                      "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
+#                      "VIRTIO_F_IOMMU_PLATFORM: Device can be used on IOMMU platform",
+#                      "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": [
+#                  "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features negotation supported",
+#                  "VIRTIO_NET_F_GSO: Handling GSO-type packets supported",
+#                  "VIRTIO_NET_F_CTRL_MAC_ADDR: MAC address set through control channel",
+#                  "VIRTIO_NET_F_GUEST_ANNOUNCE: Driver sending gratuitous packets supported",
+#                  "VIRTIO_NET_F_CTRL_RX_EXTRA: Extra RX mode control supported",
+#                  "VIRTIO_NET_F_CTRL_VLAN: Control channel VLAN filtering supported",
+#                  "VIRTIO_NET_F_CTRL_RX: Control channel RX mode supported",
+#                  "VIRTIO_NET_F_CTRL_VQ: Control channel available",
+#                  "VIRTIO_NET_F_STATUS: Configuration status field available",
+#                  "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive buffers",
+#                  "VIRTIO_NET_F_HOST_UFO: Device can receive UFO",
+#                  "VIRTIO_NET_F_HOST_ECN: Device can receive TSO with ECN",
+#                  "VIRTIO_NET_F_HOST_TSO6: Device can receive TSOv6",
+#                  "VIRTIO_NET_F_HOST_TSO4: Device can receive TSOv4",
+#                  "VIRTIO_NET_F_GUEST_UFO: Driver can receive UFO",
+#                  "VIRTIO_NET_F_GUEST_ECN: Driver can receive TSO with ECN",
+#                  "VIRTIO_NET_F_GUEST_TSO6: Driver can receive TSOv6",
+#                  "VIRTIO_NET_F_GUEST_TSO4: Driver can receive TSOv4",
+#                  "VIRTIO_NET_F_MAC: Device has given MAC address",
+#                  "VIRTIO_NET_F_CTRL_GUEST_OFFLOADS: Control channel offloading reconfig. supported",
+#                  "VIRTIO_NET_F_GUEST_CSUM: Driver handling packets with partial checksum supported",
+#                  "VIRTIO_NET_F_CSUM: Device handling packets with partial checksum 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": 6337593319,
 #          "start-on-kick": false,
 #          "isr": 1,
 #          "broken": false,
-#          "status": 15,
+#          "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": 5111807911,
-#          "host-features": 6337593319,
+#          "guest-features": {
+#              "dev-features": [
+#                  "VIRTIO_NET_F_CTRL_MAC_ADDR: MAC address set through control channel",
+#                  "VIRTIO_NET_F_GUEST_ANNOUNCE: Driver sending gratuitous packets supported",
+#                  "VIRTIO_NET_F_CTRL_VLAN: Control channel VLAN filtering supported",
+#                  "VIRTIO_NET_F_CTRL_RX: Control channel RX mode supported",
+#                  "VIRTIO_NET_F_CTRL_VQ: Control channel available",
+#                  "VIRTIO_NET_F_STATUS: Configuration status field available",
+#                  "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive buffers",
+#                  "VIRTIO_NET_F_HOST_UFO: Device can receive UFO",
+#                  "VIRTIO_NET_F_HOST_ECN: Device can receive TSO with ECN",
+#                  "VIRTIO_NET_F_HOST_TSO6: Device can receive TSOv6",
+#                  "VIRTIO_NET_F_HOST_TSO4: Device can receive TSOv4",
+#                  "VIRTIO_NET_F_GUEST_UFO: Driver can receive UFO",
+#                  "VIRTIO_NET_F_GUEST_ECN: Driver can receive TSO with ECN",
+#                  "VIRTIO_NET_F_GUEST_TSO6: Driver can receive TSOv6",
+#                  "VIRTIO_NET_F_GUEST_TSO4: Driver can receive TSOv4",
+#                  "VIRTIO_NET_F_MAC: Device has given MAC address",
+#                  "VIRTIO_NET_F_CTRL_GUEST_OFFLOADS: Control channel offloading reconfig. supported",
+#                  "VIRTIO_NET_F_GUEST_CSUM: Driver handling packets with partial checksum supported",
+#                  "VIRTIO_NET_F_CSUM: Device handling packets with partial checksum 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)"
+#             ]
+#          },
+#          "host-features": {
+#              "dev-features": [
+#                  "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features negotation supported",
+#                  "VIRTIO_NET_F_GSO: Handling GSO-type packets supported",
+#                  "VIRTIO_NET_F_CTRL_MAC_ADDR: MAC address set through control channel",
+#                  "VIRTIO_NET_F_GUEST_ANNOUNCE: Driver sending gratuitous packets supported",
+#                  "VIRTIO_NET_F_CTRL_RX_EXTRA: Extra RX mode control supported",
+#                  "VIRTIO_NET_F_CTRL_VLAN: Control channel VLAN filtering supported",
+#                  "VIRTIO_NET_F_CTRL_RX: Control channel RX mode supported",
+#                  "VIRTIO_NET_F_CTRL_VQ: Control channel available",
+#                  "VIRTIO_NET_F_STATUS: Configuration status field available",
+#                  "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive buffers",
+#                  "VIRTIO_NET_F_HOST_UFO: Device can receive UFO",
+#                  "VIRTIO_NET_F_HOST_ECN: Device can receive TSO with ECN",
+#                  "VIRTIO_NET_F_HOST_TSO6: Device can receive TSOv6",
+#                  "VIRTIO_NET_F_HOST_TSO4: Device can receive TSOv4",
+#                  "VIRTIO_NET_F_GUEST_UFO: Driver can receive UFO",
+#                  "VIRTIO_NET_F_GUEST_ECN: Driver can receive TSO with ECN",
+#                  "VIRTIO_NET_F_GUEST_TSO6: Driver can receive TSOv6",
+#                  "VIRTIO_NET_F_GUEST_TSO4: Driver can receive TSOv4",
+#                  "VIRTIO_NET_F_MAC: Device has given MAC address",
+#                  "VIRTIO_NET_F_CTRL_GUEST_OFFLOADS: Control channel offloading reconfig. supported",
+#                  "VIRTIO_NET_F_GUEST_CSUM: Driver handling packets with partial checksum supported",
+#                  "VIRTIO_NET_F_CSUM: Device handling packets with partial checksum 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,
@@ -288,3 +440,62 @@
   'data': { 'path': 'str' },
   'returns': 'VirtioStatus',
   'features': [ 'unstable' ] }
+
+##
+# @VirtioDeviceStatus:
+#
+# A structure defined to list the configuration statuses of a virtio
+# device
+#
+# @statuses: List of decoded configuration statuses of the virtio
+#            device
+#
+# @unknown-statuses: Virtio device statuses bitmap that have not been decoded
+#
+# Since: 7.1
+##
+
+{ 'struct': 'VirtioDeviceStatus',
+  'data': { 'statuses': [ 'str' ],
+            '*unknown-statuses': 'uint8' } }
+
+##
+# @VhostDeviceProtocols:
+#
+# A structure defined to list the vhost user protocol features of a
+# Vhost User device
+#
+# @protocols: List of decoded vhost user protocol features of a vhost
+#             user device
+#
+# @unknown-protocols: Vhost user device protocol features bitmap that
+#                     have not been decoded
+#
+# Since: 7.1
+##
+
+{ 'struct': 'VhostDeviceProtocols',
+  'data': { 'protocols': [ 'str' ],
+            '*unknown-protocols': 'uint64' } }
+
+##
+# @VirtioDeviceFeatures:
+#
+# The common fields that apply to most Virtio devices. Some devices
+# may not have their own device-specific features (e.g. virtio-rng).
+#
+# @transports: List of transport features of the virtio device
+#
+# @dev-features: List of device-specific features (if the device has
+#                unique features)
+#
+# @unknown-dev-features: Virtio device features bitmap that have not
+#                        been decoded
+#
+# Since: 7.1
+##
+
+{ 'struct': 'VirtioDeviceFeatures',
+  'data': { 'transports': [ 'str' ],
+            '*dev-features': [ 'str' ],
+            '*unknown-dev-features': 'uint64' } }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v15 4/6] qmp: add QMP commands for virtio/vhost queue-status
  2022-08-11 12:24 [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices Jonah Palmer
                   ` (2 preceding siblings ...)
  2022-08-11 12:24 ` [PATCH v15 3/6] qmp: decode feature & status bits in virtio-status Jonah Palmer
@ 2022-08-11 12:24 ` Jonah Palmer
  2022-08-11 12:24 ` [PATCH v15 5/6] qmp: add QMP command x-query-virtio-queue-element Jonah Palmer
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Jonah Palmer @ 2022-08-11 12:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: mst, qemu_oss, kraxel, si-wei.liu, joao.m.martins, eblake,
	qemu-block, david, armbru, arei.gonglei, marcandre.lureau,
	lvivier, thuth, michael.roth, groug, dgilbert, eric.auger,
	stefanha, boris.ostrovsky, kwolf, mathieu.poirier,
	raphael.norwitz, pbonzini

From: Laurent Vivier <lvivier@redhat.com>

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

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
---
 hw/virtio/virtio-stub.c |  14 +++
 hw/virtio/virtio.c      | 103 ++++++++++++++++
 qapi/virtio.json        | 256 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 373 insertions(+)

diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c
index 0b432e8de7..13e5f93652 100644
--- a/hw/virtio/virtio-stub.c
+++ b/hw/virtio/virtio-stub.c
@@ -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);
+}
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 23bdc77a95..dc73b82b38 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -4670,6 +4670,109 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
     return status;
 }
 
+VirtVhostQueueStatus *qmp_x_query_virtio_vhost_queue_status(const char *path,
+                                                            uint16_t queue,
+                                                            Error **errp)
+{
+    VirtIODevice *vdev;
+    VirtVhostQueueStatus *status;
+
+    vdev = virtio_device_find(path);
+    if (vdev == NULL) {
+        error_setg(errp, "Path %s is not a VirtIODevice", path);
+        return NULL;
+    }
+
+    if (!vdev->vhost_started) {
+        error_setg(errp, "Error: vhost device has not started yet");
+        return NULL;
+    }
+
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
+    struct vhost_dev *hdev = vdc->get_vhost(vdev);
+
+    if (queue < hdev->vq_index || queue >= hdev->vq_index + hdev->nvqs) {
+        error_setg(errp, "Invalid vhost virtqueue number %d", queue);
+        return NULL;
+    }
+
+    status = g_new0(VirtVhostQueueStatus, 1);
+    status->name = g_strdup(vdev->name);
+    status->kick = hdev->vqs[queue].kick;
+    status->call = hdev->vqs[queue].call;
+    status->desc = (uintptr_t)hdev->vqs[queue].desc;
+    status->avail = (uintptr_t)hdev->vqs[queue].avail;
+    status->used = (uintptr_t)hdev->vqs[queue].used;
+    status->num = hdev->vqs[queue].num;
+    status->desc_phys = hdev->vqs[queue].desc_phys;
+    status->desc_size = hdev->vqs[queue].desc_size;
+    status->avail_phys = hdev->vqs[queue].avail_phys;
+    status->avail_size = hdev->vqs[queue].avail_size;
+    status->used_phys = hdev->vqs[queue].used_phys;
+    status->used_size = hdev->vqs[queue].used_size;
+
+    return status;
+}
+
+VirtQueueStatus *qmp_x_query_virtio_queue_status(const char *path,
+                                                 uint16_t queue,
+                                                 Error **errp)
+{
+    VirtIODevice *vdev;
+    VirtQueueStatus *status;
+
+    vdev = virtio_device_find(path);
+    if (vdev == NULL) {
+        error_setg(errp, "Path %s is not a VirtIODevice", path);
+        return NULL;
+    }
+
+    if (queue >= VIRTIO_QUEUE_MAX || !virtio_queue_get_num(vdev, queue)) {
+        error_setg(errp, "Invalid virtqueue number %d", queue);
+        return NULL;
+    }
+
+    status = g_new0(VirtQueueStatus, 1);
+    status->name = g_strdup(vdev->name);
+    status->queue_index = vdev->vq[queue].queue_index;
+    status->inuse = vdev->vq[queue].inuse;
+    status->vring_num = vdev->vq[queue].vring.num;
+    status->vring_num_default = vdev->vq[queue].vring.num_default;
+    status->vring_align = vdev->vq[queue].vring.align;
+    status->vring_desc = vdev->vq[queue].vring.desc;
+    status->vring_avail = vdev->vq[queue].vring.avail;
+    status->vring_used = vdev->vq[queue].vring.used;
+    status->used_idx = vdev->vq[queue].used_idx;
+    status->signalled_used = vdev->vq[queue].signalled_used;
+    status->signalled_used_valid = vdev->vq[queue].signalled_used_valid;
+
+    if (vdev->vhost_started) {
+        VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
+        struct vhost_dev *hdev = vdc->get_vhost(vdev);
+
+        /* check if vq index exists for vhost as well  */
+        if (queue >= hdev->vq_index && queue < hdev->vq_index + hdev->nvqs) {
+            status->has_last_avail_idx = true;
+
+            int vhost_vq_index =
+                hdev->vhost_ops->vhost_get_vq_index(hdev, queue);
+            struct vhost_vring_state state = {
+                .index = vhost_vq_index,
+            };
+
+            status->last_avail_idx =
+                hdev->vhost_ops->vhost_get_vring_base(hdev, &state);
+        }
+    } else {
+        status->has_shadow_avail_idx = true;
+        status->has_last_avail_idx = true;
+        status->last_avail_idx = vdev->vq[queue].last_avail_idx;
+        status->shadow_avail_idx = vdev->vq[queue].shadow_avail_idx;
+    }
+
+    return status;
+}
+
 static const TypeInfo virtio_device_info = {
     .name = TYPE_VIRTIO_DEVICE,
     .parent = TYPE_DEVICE,
diff --git a/qapi/virtio.json b/qapi/virtio.json
index c9c8201e66..d9050f3584 100644
--- a/qapi/virtio.json
+++ b/qapi/virtio.json
@@ -499,3 +499,259 @@
   'data': { 'transports': [ 'str' ],
             '*dev-features': [ 'str' ],
             '*unknown-dev-features': 'uint64' } }
+
+##
+# @VirtQueueStatus:
+#
+# Information of a VirtIODevice VirtQueue, including most members of
+# the VirtQueue data structure.
+#
+# @name: Name of the VirtIODevice that uses this VirtQueue
+#
+# @queue-index: VirtQueue queue_index
+#
+# @inuse: VirtQueue inuse
+#
+# @vring-num: VirtQueue vring.num
+#
+# @vring-num-default: VirtQueue vring.num_default
+#
+# @vring-align: VirtQueue vring.align
+#
+# @vring-desc: VirtQueue vring.desc (descriptor area)
+#
+# @vring-avail: VirtQueue vring.avail (driver area)
+#
+# @vring-used: VirtQueue vring.used (device area)
+#
+# @last-avail-idx: VirtQueue last_avail_idx or return of vhost_dev
+#                  vhost_get_vring_base (if vhost active)
+#
+# @shadow-avail-idx: VirtQueue shadow_avail_idx
+#
+# @used-idx: VirtQueue used_idx
+#
+# @signalled-used: VirtQueue signalled_used
+#
+# @signalled-used-valid: VirtQueue signalled_used_valid flag
+#
+# Since: 7.1
+#
+##
+
+{ 'struct': 'VirtQueueStatus',
+  'data': { 'name': 'str',
+            'queue-index': 'uint16',
+            'inuse': 'uint32',
+            'vring-num': 'uint32',
+            'vring-num-default': 'uint32',
+            'vring-align': 'uint32',
+            'vring-desc': 'uint64',
+            'vring-avail': 'uint64',
+            'vring-used': 'uint64',
+            '*last-avail-idx': 'uint16',
+            '*shadow-avail-idx': 'uint16',
+            'used-idx': 'uint16',
+            'signalled-used': 'uint16',
+            'signalled-used-valid': 'bool' } }
+
+##
+# @x-query-virtio-queue-status:
+#
+# Return the status of a given VirtIODevice's VirtQueue
+#
+# @path: VirtIODevice canonical QOM path
+#
+# @queue: VirtQueue index to examine
+#
+# Features:
+# @unstable: This command is meant for debugging.
+#
+# Returns: VirtQueueStatus of the VirtQueue
+#
+# Notes: last_avail_idx will not be displayed in the case where
+#        the selected VirtIODevice has a running vhost device and
+#        the VirtIODevice VirtQueue index (queue) does not exist for
+#        the corresponding vhost device vhost_virtqueue. Also,
+#        shadow_avail_idx will not be displayed in the case where
+#        the selected VirtIODevice has a running vhost device.
+#
+# Since: 7.1
+#
+# Examples:
+#
+# 1. Get VirtQueueStatus for virtio-vsock (vhost-vsock running)
+#
+# -> { "execute": "x-query-virtio-queue-status",
+#      "arguments": { "path": "/machine/peripheral/vsock0/virtio-backend",
+#                     "queue": 1 }
+#    }
+# <- { "return": {
+#          "signalled-used": 0,
+#          "inuse": 0,
+#          "name": "vhost-vsock",
+#          "vring-align": 4096,
+#          "vring-desc": 5217370112,
+#          "signalled-used-valid": false,
+#          "vring-num-default": 128,
+#          "vring-avail": 5217372160,
+#          "queue-index": 1,
+#          "last-avail-idx": 0,
+#          "vring-used": 5217372480,
+#          "used-idx": 0,
+#          "vring-num": 128
+#      }
+#    }
+#
+# 2. Get VirtQueueStatus for virtio-serial (no vhost)
+#
+# -> { "execute": "x-query-virtio-queue-status",
+#      "arguments": { "path": "/machine/peripheral-anon/device[0]/virtio-backend",
+#                     "queue": 20 }
+#    }
+# <- { "return": {
+#          "signalled-used": 0,
+#          "inuse": 0,
+#          "name": "virtio-serial",
+#          "vring-align": 4096,
+#          "vring-desc": 5182074880,
+#          "signalled-used-valid": false,
+#          "vring-num-default": 128,
+#          "vring-avail": 5182076928,
+#          "queue-index": 20,
+#          "last-avail-idx": 0,
+#          "vring-used": 5182077248,
+#          "used-idx": 0,
+#          "shadow-avail-idx": 0,
+#          "vring-num": 128
+#      }
+#    }
+#
+##
+
+{ 'command': 'x-query-virtio-queue-status',
+  'data': { 'path': 'str', 'queue': 'uint16' },
+  'returns': 'VirtQueueStatus',
+  'features': [ 'unstable' ] }
+
+##
+# @VirtVhostQueueStatus:
+#
+# Information of a vhost device's vhost_virtqueue, including most
+# members of the vhost_dev vhost_virtqueue data structure.
+#
+# @name: Name of the VirtIODevice that uses this vhost_virtqueue
+#
+# @kick: vhost_virtqueue kick
+#
+# @call: vhost_virtqueue call
+#
+# @desc: vhost_virtqueue desc
+#
+# @avail: vhost_virtqueue avail
+#
+# @used: vhost_virtqueue used
+#
+# @num: vhost_virtqueue num
+#
+# @desc-phys: vhost_virtqueue desc_phys (descriptor area phys. addr.)
+#
+# @desc-size: vhost_virtqueue desc_size
+#
+# @avail-phys: vhost_virtqueue avail_phys (driver area phys. addr.)
+#
+# @avail-size: vhost_virtqueue avail_size
+#
+# @used-phys: vhost_virtqueue used_phys (device area phys. addr.)
+#
+# @used-size: vhost_virtqueue used_size
+#
+# Since: 7.1
+#
+##
+
+{ 'struct': 'VirtVhostQueueStatus',
+  'data': { 'name': 'str',
+            'kick': 'int',
+            'call': 'int',
+            'desc': 'uint64',
+            'avail': 'uint64',
+            'used': 'uint64',
+            'num': 'int',
+            'desc-phys': 'uint64',
+            'desc-size': 'uint32',
+            'avail-phys': 'uint64',
+            'avail-size': 'uint32',
+            'used-phys': 'uint64',
+            'used-size': 'uint32' } }
+
+##
+# @x-query-virtio-vhost-queue-status:
+#
+# Return information of a given vhost device's vhost_virtqueue
+#
+# @path: VirtIODevice canonical QOM path
+#
+# @queue: vhost_virtqueue index to examine
+#
+# Features:
+# @unstable: This command is meant for debugging.
+#
+# Returns: VirtVhostQueueStatus of the vhost_virtqueue
+#
+# Since: 7.1
+#
+# Examples:
+#
+# 1. Get vhost_virtqueue status for vhost-crypto
+#
+# -> { "execute": "x-query-virtio-vhost-queue-status",
+#      "arguments": { "path": "/machine/peripheral/crypto0/virtio-backend",
+#                     "queue": 0 }
+#    }
+# <- { "return": {
+#          "avail-phys": 5216124928,
+#          "name": "virtio-crypto",
+#          "used-phys": 5216127040,
+#          "avail-size": 2054,
+#          "desc-size": 16384,
+#          "used-size": 8198,
+#          "desc": 140141447430144,
+#          "num": 1024,
+#          "call": 0,
+#          "avail": 140141447446528,
+#          "desc-phys": 5216108544,
+#          "used": 140141447448640,
+#          "kick": 0
+#      }
+#    }
+#
+# 2. Get vhost_virtqueue status for vhost-vsock
+#
+# -> { "execute": "x-query-virtio-vhost-queue-status",
+#      "arguments": { "path": "/machine/peripheral/vsock0/virtio-backend",
+#                     "queue": 0 }
+#    }
+# <- { "return": {
+#          "avail-phys": 5182261248,
+#          "name": "vhost-vsock",
+#          "used-phys": 5182261568,
+#          "avail-size": 262,
+#          "desc-size": 2048,
+#          "used-size": 1030,
+#          "desc": 140141413580800,
+#          "num": 128,
+#          "call": 0,
+#          "avail": 140141413582848,
+#          "desc-phys": 5182259200,
+#          "used": 140141413583168,
+#          "kick": 0
+#      }
+#    }
+#
+##
+
+{ 'command': 'x-query-virtio-vhost-queue-status',
+  'data': { 'path': 'str', 'queue': 'uint16' },
+  'returns': 'VirtVhostQueueStatus',
+  'features': [ 'unstable' ] }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v15 5/6] qmp: add QMP command x-query-virtio-queue-element
  2022-08-11 12:24 [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices Jonah Palmer
                   ` (3 preceding siblings ...)
  2022-08-11 12:24 ` [PATCH v15 4/6] qmp: add QMP commands for virtio/vhost queue-status Jonah Palmer
@ 2022-08-11 12:24 ` Jonah Palmer
  2022-08-11 12:24 ` [PATCH v15 6/6] hmp: add virtio commands Jonah Palmer
  2022-09-27  8:36 ` [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices Jonah Palmer
  6 siblings, 0 replies; 15+ messages in thread
From: Jonah Palmer @ 2022-08-11 12:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: mst, qemu_oss, kraxel, si-wei.liu, joao.m.martins, eblake,
	qemu-block, david, armbru, arei.gonglei, marcandre.lureau,
	lvivier, thuth, michael.roth, groug, dgilbert, eric.auger,
	stefanha, boris.ostrovsky, kwolf, mathieu.poirier,
	raphael.norwitz, pbonzini

From: Laurent Vivier <lvivier@redhat.com>

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.).]

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
---
 hw/virtio/virtio-stub.c |   9 ++
 hw/virtio/virtio.c      | 154 +++++++++++++++++++++++++++++++
 qapi/virtio.json        | 197 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 360 insertions(+)

diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c
index 13e5f93652..7ddb22cc5e 100644
--- a/hw/virtio/virtio-stub.c
+++ b/hw/virtio/virtio-stub.c
@@ -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);
+}
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index dc73b82b38..c6e244a3c9 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -823,6 +823,19 @@ static inline void vring_used_write(VirtQueue *vq, VRingUsedElem *uelem,
     address_space_cache_invalidate(&caches->used, pa, sizeof(VRingUsedElem));
 }
 
+/* Called within rcu_read_lock(). */
+static inline uint16_t vring_used_flags(VirtQueue *vq)
+{
+    VRingMemoryRegionCaches *caches = vring_get_region_caches(vq);
+    hwaddr pa = offsetof(VRingUsed, flags);
+
+    if (!caches) {
+        return 0;
+    }
+
+    return virtio_lduw_phys_cached(vq->vdev, &caches->used, pa);
+}
+
 /* Called within rcu_read_lock().  */
 static uint16_t vring_used_idx(VirtQueue *vq)
 {
@@ -4773,6 +4786,147 @@ VirtQueueStatus *qmp_x_query_virtio_queue_status(const char *path,
     return status;
 }
 
+static strList *qmp_decode_vring_desc_flags(uint16_t flags)
+{
+    strList *list = NULL;
+    strList *node;
+    int i;
+
+    struct {
+        uint16_t flag;
+        const char *value;
+    } map[] = {
+        { VRING_DESC_F_NEXT, "next" },
+        { VRING_DESC_F_WRITE, "write" },
+        { VRING_DESC_F_INDIRECT, "indirect" },
+        { 1 << VRING_PACKED_DESC_F_AVAIL, "avail" },
+        { 1 << VRING_PACKED_DESC_F_USED, "used" },
+        { 0, "" }
+    };
+
+    for (i = 0; map[i].flag; i++) {
+        if ((map[i].flag & flags) == 0) {
+            continue;
+        }
+        node = g_malloc0(sizeof(strList));
+        node->value = g_strdup(map[i].value);
+        node->next = list;
+        list = node;
+    }
+
+    return list;
+}
+
+VirtioQueueElement *qmp_x_query_virtio_queue_element(const char *path,
+                                                     uint16_t queue,
+                                                     bool has_index,
+                                                     uint16_t index,
+                                                     Error **errp)
+{
+    VirtIODevice *vdev;
+    VirtQueue *vq;
+    VirtioQueueElement *element = NULL;
+
+    vdev = virtio_device_find(path);
+    if (vdev == NULL) {
+        error_setg(errp, "Path %s is not a VirtIO device", path);
+        return NULL;
+    }
+
+    if (queue >= VIRTIO_QUEUE_MAX || !virtio_queue_get_num(vdev, queue)) {
+        error_setg(errp, "Invalid virtqueue number %d", queue);
+        return NULL;
+    }
+    vq = &vdev->vq[queue];
+
+    if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) {
+        error_setg(errp, "Packed ring not supported");
+        return NULL;
+    } else {
+        unsigned int head, i, max;
+        VRingMemoryRegionCaches *caches;
+        MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID;
+        MemoryRegionCache *desc_cache;
+        VRingDesc desc;
+        VirtioRingDescList *list = NULL;
+        VirtioRingDescList *node;
+        int rc; int ndescs;
+
+        RCU_READ_LOCK_GUARD();
+
+        max = vq->vring.num;
+
+        if (!has_index) {
+            head = vring_avail_ring(vq, vq->last_avail_idx % vq->vring.num);
+        } else {
+            head = vring_avail_ring(vq, index % vq->vring.num);
+        }
+        i = head;
+
+        caches = vring_get_region_caches(vq);
+        if (!caches) {
+            error_setg(errp, "Region caches not initialized");
+            return NULL;
+        }
+        if (caches->desc.len < max * sizeof(VRingDesc)) {
+            error_setg(errp, "Cannot map descriptor ring");
+            return NULL;
+        }
+
+        desc_cache = &caches->desc;
+        vring_split_desc_read(vdev, &desc, desc_cache, i);
+        if (desc.flags & VRING_DESC_F_INDIRECT) {
+            int64_t len;
+            len = address_space_cache_init(&indirect_desc_cache, vdev->dma_as,
+                                           desc.addr, desc.len, false);
+            desc_cache = &indirect_desc_cache;
+            if (len < desc.len) {
+                error_setg(errp, "Cannot map indirect buffer");
+                goto done;
+            }
+
+            max = desc.len / sizeof(VRingDesc);
+            i = 0;
+            vring_split_desc_read(vdev, &desc, desc_cache, i);
+        }
+
+        element = g_new0(VirtioQueueElement, 1);
+        element->avail = g_new0(VirtioRingAvail, 1);
+        element->used = g_new0(VirtioRingUsed, 1);
+        element->name = g_strdup(vdev->name);
+        element->index = head;
+        element->avail->flags = vring_avail_flags(vq);
+        element->avail->idx = vring_avail_idx(vq);
+        element->avail->ring = head;
+        element->used->flags = vring_used_flags(vq);
+        element->used->idx = vring_used_idx(vq);
+        ndescs = 0;
+
+        do {
+            /* A buggy driver may produce an infinite loop */
+            if (ndescs >= max) {
+                break;
+            }
+            node = g_new0(VirtioRingDescList, 1);
+            node->value = g_new0(VirtioRingDesc, 1);
+            node->value->addr = desc.addr;
+            node->value->len = desc.len;
+            node->value->flags = qmp_decode_vring_desc_flags(desc.flags);
+            node->next = list;
+            list = node;
+
+            ndescs++;
+            rc = virtqueue_split_read_next_desc(vdev, &desc, desc_cache,
+                                                max, &i);
+        } while (rc == VIRTQUEUE_READ_DESC_MORE);
+        element->descs = list;
+done:
+        address_space_cache_destroy(&indirect_desc_cache);
+    }
+
+    return element;
+}
+
 static const TypeInfo virtio_device_info = {
     .name = TYPE_VIRTIO_DEVICE,
     .parent = TYPE_DEVICE,
diff --git a/qapi/virtio.json b/qapi/virtio.json
index d9050f3584..e47a8fb2e0 100644
--- a/qapi/virtio.json
+++ b/qapi/virtio.json
@@ -755,3 +755,200 @@
   'data': { 'path': 'str', 'queue': 'uint16' },
   'returns': 'VirtVhostQueueStatus',
   'features': [ 'unstable' ] }
+
+##
+# @VirtioRingDesc:
+#
+# Information regarding the vring descriptor area
+#
+# @addr: Guest physical address of the descriptor area
+#
+# @len: Length of the descriptor area
+#
+# @flags: List of descriptor flags
+#
+# Since: 7.1
+#
+##
+
+{ 'struct': 'VirtioRingDesc',
+  'data': { 'addr': 'uint64',
+            'len': 'uint32',
+            'flags': [ 'str' ] } }
+
+##
+# @VirtioRingAvail:
+#
+# Information regarding the avail vring (a.k.a. driver area)
+#
+# @flags: VRingAvail flags
+#
+# @idx: VRingAvail index
+#
+# @ring: VRingAvail ring[] entry at provided index
+#
+# Since: 7.1
+#
+##
+
+{ 'struct': 'VirtioRingAvail',
+  'data': { 'flags': 'uint16',
+            'idx': 'uint16',
+            'ring': 'uint16' } }
+
+##
+# @VirtioRingUsed:
+#
+# Information regarding the used vring (a.k.a. device area)
+#
+# @flags: VRingUsed flags
+#
+# @idx: VRingUsed index
+#
+# Since: 7.1
+#
+##
+
+{ 'struct': 'VirtioRingUsed',
+  'data': { 'flags': 'uint16',
+            'idx': 'uint16' } }
+
+##
+# @VirtioQueueElement:
+#
+# Information regarding a VirtQueue's VirtQueueElement including
+# descriptor, driver, and device areas
+#
+# @name: Name of the VirtIODevice that uses this VirtQueue
+#
+# @index: Index of the element in the queue
+#
+# @descs: List of descriptors (VirtioRingDesc)
+#
+# @avail: VRingAvail info
+#
+# @used: VRingUsed info
+#
+# Since: 7.1
+#
+##
+
+{ 'struct': 'VirtioQueueElement',
+  'data': { 'name': 'str',
+            'index': 'uint32',
+            'descs': [ 'VirtioRingDesc' ],
+            'avail': 'VirtioRingAvail',
+            'used': 'VirtioRingUsed' } }
+
+##
+# @x-query-virtio-queue-element:
+#
+# Return the information about a VirtQueue's VirtQueueElement
+#
+# @path: VirtIODevice canonical QOM path
+#
+# @queue: VirtQueue index to examine
+#
+# @index: Index of the element in the queue
+#         (default: head of the queue)
+#
+# Features:
+# @unstable: This command is meant for debugging.
+#
+# Returns: VirtioQueueElement information
+#
+# Since: 7.1
+#
+# Examples:
+#
+# 1. Introspect on virtio-net's VirtQueue 0 at index 5
+#
+# -> { "execute": "x-query-virtio-queue-element",
+#      "arguments": { "path": "/machine/peripheral-anon/device[1]/virtio-backend",
+#                     "queue": 0,
+#                     "index": 5 }
+#    }
+# <- { "return": {
+#          "index": 5,
+#          "name": "virtio-net",
+#          "descs": [
+#              {
+#                  "flags": ["write"],
+#                  "len": 1536,
+#                  "addr": 5257305600
+#              }
+#          ],
+#          "avail": {
+#              "idx": 256,
+#              "flags": 0,
+#              "ring": 5
+#          },
+#          "used": {
+#              "idx": 13,
+#              "flags": 0
+#          }
+#      }
+#    }
+#
+# 2. Introspect on virtio-crypto's VirtQueue 1 at head
+#
+# -> { "execute": "x-query-virtio-queue-element",
+#      "arguments": { "path": "/machine/peripheral/crypto0/virtio-backend",
+#                     "queue": 1 }
+#    }
+# <- { "return": {
+#          "index": 0,
+#          "name": "virtio-crypto",
+#          "descs": [
+#              {
+#                  "flags": [],
+#                  "len": 0,
+#                  "addr": 8080268923184214134
+#              }
+#          ],
+#          "avail": {
+#              "idx": 280,
+#              "flags": 0,
+#              "ring": 0
+#          },
+#          "used": {
+#              "idx": 280,
+#              "flags": 0
+#          }
+#      }
+#    }
+#
+# 3. Introspect on virtio-scsi's VirtQueue 2 at head
+#
+# -> { "execute": "x-query-virtio-queue-element",
+#      "arguments": { "path": "/machine/peripheral-anon/device[2]/virtio-backend",
+#                     "queue": 2 }
+#    }
+# <- { "return": {
+#          "index": 19,
+#          "name": "virtio-scsi",
+#          "descs": [
+#              {
+#                  "flags": ["used", "indirect", "write"],
+#                  "len": 4099327944,
+#                  "addr": 12055409292258155293
+#              }
+#          ],
+#          "avail": {
+#              "idx": 1147,
+#              "flags": 0,
+#              "ring": 19
+#          },
+#          "used": {
+#              "idx": 280,
+#              "flags": 0
+#          }
+#      }
+#    }
+#
+##
+
+{ 'command': 'x-query-virtio-queue-element',
+  'data': { 'path': 'str', 'queue': 'uint16', '*index': 'uint16' },
+  'returns': 'VirtioQueueElement',
+  'features': [ 'unstable' ] }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v15 6/6] hmp: add virtio commands
  2022-08-11 12:24 [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices Jonah Palmer
                   ` (4 preceding siblings ...)
  2022-08-11 12:24 ` [PATCH v15 5/6] qmp: add QMP command x-query-virtio-queue-element Jonah Palmer
@ 2022-08-11 12:24 ` Jonah Palmer
  2022-09-27  8:36 ` [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices Jonah Palmer
  6 siblings, 0 replies; 15+ messages in thread
From: Jonah Palmer @ 2022-08-11 12:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: mst, qemu_oss, kraxel, si-wei.liu, joao.m.martins, eblake,
	qemu-block, david, armbru, arei.gonglei, marcandre.lureau,
	lvivier, thuth, michael.roth, groug, dgilbert, eric.auger,
	stefanha, boris.ostrovsky, kwolf, mathieu.poirier,
	raphael.norwitz, pbonzini

From: Laurent Vivier <lvivier@redhat.com>

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

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

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
---
 hmp-commands-info.hx  |  70 ++++++++++
 include/monitor/hmp.h |   5 +
 monitor/hmp-cmds.c    | 310 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 385 insertions(+)

diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index 188d9ece3b..58cfa86638 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -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
diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
index a618eb1e4e..a9cf064ee8 100644
--- a/include/monitor/hmp.h
+++ b/include/monitor/hmp.h
@@ -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);
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index c6cd6f91dd..0934dbd557 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -43,6 +43,8 @@
 #include "qapi/qapi-commands-stats.h"
 #include "qapi/qapi-commands-tpm.h"
 #include "qapi/qapi-commands-ui.h"
+#include "qapi/qapi-commands-virtio.h"
+#include "qapi/qapi-visit-virtio.h"
 #include "qapi/qapi-visit-net.h"
 #include "qapi/qapi-visit-migration.h"
 #include "qapi/qmp/qdict.h"
@@ -2472,3 +2474,311 @@ exit:
 exit_no_print:
     error_free(err);
 }
+
+static void hmp_virtio_dump_protocols(Monitor *mon,
+                                      VhostDeviceProtocols *pcol)
+{
+    strList *pcol_list = pcol->protocols;
+    while (pcol_list) {
+        monitor_printf(mon, "\t%s", pcol_list->value);
+        pcol_list = pcol_list->next;
+        if (pcol_list != NULL) {
+            monitor_printf(mon, ",\n");
+        }
+    }
+    monitor_printf(mon, "\n");
+    if (pcol->has_unknown_protocols) {
+        monitor_printf(mon, "  unknown-protocols(0x%016"PRIx64")\n",
+                       pcol->unknown_protocols);
+    }
+}
+
+static void hmp_virtio_dump_status(Monitor *mon,
+                                   VirtioDeviceStatus *status)
+{
+    strList *status_list = status->statuses;
+    while (status_list) {
+        monitor_printf(mon, "\t%s", status_list->value);
+        status_list = status_list->next;
+        if (status_list != NULL) {
+            monitor_printf(mon, ",\n");
+        }
+    }
+    monitor_printf(mon, "\n");
+    if (status->has_unknown_statuses) {
+        monitor_printf(mon, "  unknown-statuses(0x%016"PRIx32")\n",
+                       status->unknown_statuses);
+    }
+}
+
+static void hmp_virtio_dump_features(Monitor *mon,
+                                     VirtioDeviceFeatures *features)
+{
+    strList *transport_list = features->transports;
+    while (transport_list) {
+        monitor_printf(mon, "\t%s", transport_list->value);
+        transport_list = transport_list->next;
+        if (transport_list != NULL) {
+            monitor_printf(mon, ",\n");
+        }
+    }
+
+    monitor_printf(mon, "\n");
+    strList *list = features->dev_features;
+    if (list) {
+        while (list) {
+            monitor_printf(mon, "\t%s", list->value);
+            list = list->next;
+            if (list != NULL) {
+                monitor_printf(mon, ",\n");
+            }
+        }
+        monitor_printf(mon, "\n");
+    }
+
+    if (features->has_unknown_dev_features) {
+        monitor_printf(mon, "  unknown-features(0x%016"PRIx64")\n",
+                       features->unknown_dev_features);
+    }
+}
+
+void hmp_virtio_query(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    VirtioInfoList *list = qmp_x_query_virtio(&err);
+    VirtioInfoList *node;
+
+    if (err != NULL) {
+        hmp_handle_error(mon, err);
+        return;
+    }
+
+    if (list == NULL) {
+        monitor_printf(mon, "No VirtIO devices\n");
+        return;
+    }
+
+    node = list;
+    while (node) {
+        monitor_printf(mon, "%s [%s]\n", node->value->path,
+                       node->value->name);
+        node = node->next;
+    }
+    qapi_free_VirtioInfoList(list);
+}
+
+void hmp_virtio_status(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    const char *path = qdict_get_try_str(qdict, "path");
+    VirtioStatus *s = qmp_x_query_virtio_status(path, &err);
+
+    if (err != NULL) {
+        hmp_handle_error(mon, err);
+        return;
+    }
+
+    monitor_printf(mon, "%s:\n", path);
+    monitor_printf(mon, "  device_name:             %s %s\n",
+                   s->name, s->has_vhost_dev ? "(vhost)" : "");
+    monitor_printf(mon, "  device_id:               %d\n", s->device_id);
+    monitor_printf(mon, "  vhost_started:           %s\n",
+                   s->vhost_started ? "true" : "false");
+    monitor_printf(mon, "  bus_name:                %s\n", s->bus_name);
+    monitor_printf(mon, "  broken:                  %s\n",
+                   s->broken ? "true" : "false");
+    monitor_printf(mon, "  disabled:                %s\n",
+                   s->disabled ? "true" : "false");
+    monitor_printf(mon, "  disable_legacy_check:    %s\n",
+                   s->disable_legacy_check ? "true" : "false");
+    monitor_printf(mon, "  started:                 %s\n",
+                   s->started ? "true" : "false");
+    monitor_printf(mon, "  use_started:             %s\n",
+                   s->use_started ? "true" : "false");
+    monitor_printf(mon, "  start_on_kick:           %s\n",
+                   s->start_on_kick ? "true" : "false");
+    monitor_printf(mon, "  use_guest_notifier_mask: %s\n",
+                   s->use_guest_notifier_mask ? "true" : "false");
+    monitor_printf(mon, "  vm_running:              %s\n",
+                   s->vm_running ? "true" : "false");
+    monitor_printf(mon, "  num_vqs:                 %"PRId64"\n", s->num_vqs);
+    monitor_printf(mon, "  queue_sel:               %d\n",
+                   s->queue_sel);
+    monitor_printf(mon, "  isr:                     %d\n", s->isr);
+    monitor_printf(mon, "  endianness:              %s\n",
+                   s->device_endian);
+    monitor_printf(mon, "  status:\n");
+    hmp_virtio_dump_status(mon, s->status);
+    monitor_printf(mon, "  Guest features:\n");
+    hmp_virtio_dump_features(mon, s->guest_features);
+    monitor_printf(mon, "  Host features:\n");
+    hmp_virtio_dump_features(mon, s->host_features);
+    monitor_printf(mon, "  Backend features:\n");
+    hmp_virtio_dump_features(mon, s->backend_features);
+
+    if (s->has_vhost_dev) {
+        monitor_printf(mon, "  VHost:\n");
+        monitor_printf(mon, "    nvqs:           %d\n",
+                       s->vhost_dev->nvqs);
+        monitor_printf(mon, "    vq_index:       %"PRId64"\n",
+                       s->vhost_dev->vq_index);
+        monitor_printf(mon, "    max_queues:     %"PRId64"\n",
+                       s->vhost_dev->max_queues);
+        monitor_printf(mon, "    n_mem_sections: %"PRId64"\n",
+                       s->vhost_dev->n_mem_sections);
+        monitor_printf(mon, "    n_tmp_sections: %"PRId64"\n",
+                       s->vhost_dev->n_tmp_sections);
+        monitor_printf(mon, "    backend_cap:    %"PRId64"\n",
+                       s->vhost_dev->backend_cap);
+        monitor_printf(mon, "    log_enabled:    %s\n",
+                       s->vhost_dev->log_enabled ? "true" : "false");
+        monitor_printf(mon, "    log_size:       %"PRId64"\n",
+                       s->vhost_dev->log_size);
+        monitor_printf(mon, "    Features:\n");
+        hmp_virtio_dump_features(mon, s->vhost_dev->features);
+        monitor_printf(mon, "    Acked features:\n");
+        hmp_virtio_dump_features(mon, s->vhost_dev->acked_features);
+        monitor_printf(mon, "    Backend features:\n");
+        hmp_virtio_dump_features(mon, s->vhost_dev->backend_features);
+        monitor_printf(mon, "    Protocol features:\n");
+        hmp_virtio_dump_protocols(mon, s->vhost_dev->protocol_features);
+    }
+
+    qapi_free_VirtioStatus(s);
+}
+
+void hmp_vhost_queue_status(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    const char *path = qdict_get_try_str(qdict, "path");
+    int queue = qdict_get_int(qdict, "queue");
+    VirtVhostQueueStatus *s =
+        qmp_x_query_virtio_vhost_queue_status(path, queue, &err);
+
+    if (err != NULL) {
+        hmp_handle_error(mon, err);
+        return;
+    }
+
+    monitor_printf(mon, "%s:\n", path);
+    monitor_printf(mon, "  device_name:          %s (vhost)\n",
+                   s->name);
+    monitor_printf(mon, "  kick:                 %"PRId64"\n", s->kick);
+    monitor_printf(mon, "  call:                 %"PRId64"\n", s->call);
+    monitor_printf(mon, "  VRing:\n");
+    monitor_printf(mon, "    num:         %"PRId64"\n", s->num);
+    monitor_printf(mon, "    desc:        0x%016"PRIx64"\n", s->desc);
+    monitor_printf(mon, "    desc_phys:   0x%016"PRIx64"\n",
+                   s->desc_phys);
+    monitor_printf(mon, "    desc_size:   %"PRId32"\n", s->desc_size);
+    monitor_printf(mon, "    avail:       0x%016"PRIx64"\n", s->avail);
+    monitor_printf(mon, "    avail_phys:  0x%016"PRIx64"\n",
+                   s->avail_phys);
+    monitor_printf(mon, "    avail_size:  %"PRId32"\n", s->avail_size);
+    monitor_printf(mon, "    used:        0x%016"PRIx64"\n", s->used);
+    monitor_printf(mon, "    used_phys:   0x%016"PRIx64"\n",
+                   s->used_phys);
+    monitor_printf(mon, "    used_size:   %"PRId32"\n", s->used_size);
+
+    qapi_free_VirtVhostQueueStatus(s);
+}
+
+void hmp_virtio_queue_status(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    const char *path = qdict_get_try_str(qdict, "path");
+    int queue = qdict_get_int(qdict, "queue");
+    VirtQueueStatus *s = qmp_x_query_virtio_queue_status(path, queue, &err);
+
+    if (err != NULL) {
+        hmp_handle_error(mon, err);
+        return;
+    }
+
+    monitor_printf(mon, "%s:\n", path);
+    monitor_printf(mon, "  device_name:          %s\n", s->name);
+    monitor_printf(mon, "  queue_index:          %d\n", s->queue_index);
+    monitor_printf(mon, "  inuse:                %d\n", s->inuse);
+    monitor_printf(mon, "  used_idx:             %d\n", s->used_idx);
+    monitor_printf(mon, "  signalled_used:       %d\n",
+                   s->signalled_used);
+    monitor_printf(mon, "  signalled_used_valid: %s\n",
+                   s->signalled_used_valid ? "true" : "false");
+    if (s->has_last_avail_idx) {
+        monitor_printf(mon, "  last_avail_idx:       %d\n",
+                       s->last_avail_idx);
+    }
+    if (s->has_shadow_avail_idx) {
+        monitor_printf(mon, "  shadow_avail_idx:     %d\n",
+                       s->shadow_avail_idx);
+    }
+    monitor_printf(mon, "  VRing:\n");
+    monitor_printf(mon, "    num:          %"PRId32"\n", s->vring_num);
+    monitor_printf(mon, "    num_default:  %"PRId32"\n",
+                   s->vring_num_default);
+    monitor_printf(mon, "    align:        %"PRId32"\n",
+                   s->vring_align);
+    monitor_printf(mon, "    desc:         0x%016"PRIx64"\n",
+                   s->vring_desc);
+    monitor_printf(mon, "    avail:        0x%016"PRIx64"\n",
+                   s->vring_avail);
+    monitor_printf(mon, "    used:         0x%016"PRIx64"\n",
+                   s->vring_used);
+
+    qapi_free_VirtQueueStatus(s);
+}
+
+void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    const char *path = qdict_get_try_str(qdict, "path");
+    int queue = qdict_get_int(qdict, "queue");
+    int index = qdict_get_try_int(qdict, "index", -1);
+    VirtioQueueElement *e;
+    VirtioRingDescList *list;
+
+    e = qmp_x_query_virtio_queue_element(path, queue, index != -1,
+                                         index, &err);
+    if (err != NULL) {
+        hmp_handle_error(mon, err);
+        return;
+    }
+
+    monitor_printf(mon, "%s:\n", path);
+    monitor_printf(mon, "  device_name: %s\n", e->name);
+    monitor_printf(mon, "  index:   %d\n", e->index);
+    monitor_printf(mon, "  desc:\n");
+    monitor_printf(mon, "    descs:\n");
+
+    list = e->descs;
+    while (list) {
+        monitor_printf(mon, "        addr 0x%"PRIx64" len %d",
+                       list->value->addr, list->value->len);
+        if (list->value->flags) {
+            strList *flag = list->value->flags;
+            monitor_printf(mon, " (");
+            while (flag) {
+                monitor_printf(mon, "%s", flag->value);
+                flag = flag->next;
+                if (flag) {
+                    monitor_printf(mon, ", ");
+                }
+            }
+            monitor_printf(mon, ")");
+        }
+        list = list->next;
+        if (list) {
+            monitor_printf(mon, ",\n");
+        }
+    }
+    monitor_printf(mon, "\n");
+    monitor_printf(mon, "  avail:\n");
+    monitor_printf(mon, "    flags: %d\n", e->avail->flags);
+    monitor_printf(mon, "    idx:   %d\n", e->avail->idx);
+    monitor_printf(mon, "    ring:  %d\n", e->avail->ring);
+    monitor_printf(mon, "  used:\n");
+    monitor_printf(mon, "    flags: %d\n", e->used->flags);
+    monitor_printf(mon, "    idx:   %d\n", e->used->idx);
+
+    qapi_free_VirtioQueueElement(e);
+}
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices
  2022-08-11 12:24 [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices Jonah Palmer
                   ` (5 preceding siblings ...)
  2022-08-11 12:24 ` [PATCH v15 6/6] hmp: add virtio commands Jonah Palmer
@ 2022-09-27  8:36 ` Jonah Palmer
  6 siblings, 0 replies; 15+ messages in thread
From: Jonah Palmer @ 2022-09-27  8:36 UTC (permalink / raw)
  To: mst, qemu-devel
  Cc: mst, qemu_oss, kraxel, Si-Wei Liu, Joao Martins, eblake,
	qemu-block, david, armbru, arei.gonglei, marcandre.lureau,
	lvivier, thuth, michael.roth, groug, dgilbert, eric.auger,
	stefanha, Boris Ostrovsky, kwolf, mathieu.poirier,
	raphael.norwitz, pbonzini

[-- Attachment #1: Type: text/plain, Size: 26922 bytes --]

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: qemu-devel@nongnu.org <qemu-devel@nongnu.org>
Cc: mst@redhat.com <mst@redhat.com>; qemu_oss@crudebyte.com <qemu_oss@crudebyte.com>; kraxel@redhat.com <kraxel@redhat.com>; Si-Wei Liu <si-wei.liu@oracle.com>; Joao Martins <joao.m.martins@oracle.com>; eblake@redhat.com <eblake@redhat.com>; qemu-block@nongnu.org <qemu-block@nongnu.org>; david@redhat.com <david@redhat.com>; armbru@redhat.com <armbru@redhat.com>; arei.gonglei@huawei.com <arei.gonglei@huawei.com>; marcandre.lureau@redhat.com <marcandre.lureau@redhat.com>; lvivier@redhat.com <lvivier@redhat.com>; thuth@redhat.com <thuth@redhat.com>; michael.roth@amd.com <michael.roth@amd.com>; groug@kaod.org <groug@kaod.org>; dgilbert@redhat.com <dgilbert@redhat.com>; eric.auger@redhat.com <eric.auger@redhat.com>; stefanha@redhat.com <stefanha@redhat.com>; Boris Ostrovsky <boris.ostrovsky@oracle.com>; kwolf@redhat.com <kwolf@redhat.com>; mathieu.poirier@linaro.org <mathieu.poirier@linaro.org>; raphael.norwitz@nutanix.com <raphael.norwitz@nutanix.com>; pbonzini@redhat.com <pbonzini@redhat.com>
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


[-- Attachment #2: Type: text/html, Size: 74391 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio
  2022-08-11 12:24 ` [PATCH v15 1/6] qmp: add QMP command x-query-virtio Jonah Palmer
@ 2022-11-30 16:16   ` Philippe Mathieu-Daudé
  2022-12-02 12:23     ` Jonah Palmer
  0 siblings, 1 reply; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2022-11-30 16:16 UTC (permalink / raw)
  To: Jonah Palmer, qemu-devel, lvivier, Alex Bennée, Markus Armbruster
  Cc: mst, qemu_oss, kraxel, si-wei.liu, joao.m.martins, eblake,
	qemu-block, david, arei.gonglei, marcandre.lureau, thuth,
	michael.roth, groug, dgilbert, eric.auger, stefanha,
	boris.ostrovsky, kwolf, mathieu.poirier, raphael.norwitz,
	pbonzini

Hi,

On 11/8/22 14:24, Jonah Palmer wrote:
> From: Laurent Vivier <lvivier@redhat.com>
> 
> 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.]
> 
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
> ---
>   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

> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 5d607aeaa0..bdfa82e9c0 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -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;
> +    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()?

> +            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;
> +}


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio
  2022-11-30 16:16   ` Philippe Mathieu-Daudé
@ 2022-12-02 12:23     ` Jonah Palmer
  2022-12-02 14:17       ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 15+ messages in thread
From: Jonah Palmer @ 2022-12-02 12:23 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé,
	qemu-devel, lvivier, Alex Bennée, Markus Armbruster
  Cc: mst, qemu_oss, kraxel, si-wei.liu, joao.m.martins, eblake,
	qemu-block, david, arei.gonglei, marcandre.lureau, thuth,
	michael.roth, groug, dgilbert, eric.auger, stefanha,
	boris.ostrovsky, kwolf, mathieu.poirier, raphael.norwitz,
	pbonzini

[-- Attachment #1: Type: text/plain, Size: 5969 bytes --]


On 11/30/22 11:16, Philippe Mathieu-Daudé wrote:
> Hi,
>
> On 11/8/22 14:24, Jonah Palmer wrote:
>> From: Laurent Vivier <lvivier@redhat.com>
>>
>> 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.]
>>
>> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
>> Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
>> ---
>>   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
>
>> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
>> index 5d607aeaa0..bdfa82e9c0 100644
>> --- a/hw/virtio/virtio.c
>> +++ b/hw/virtio/virtio.c
>> @@ -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;
>> +    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()?

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.

>
>> +            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;
>> +}

[-- Attachment #2: Type: text/html, Size: 10914 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio
  2022-12-02 12:23     ` Jonah Palmer
@ 2022-12-02 14:17       ` Philippe Mathieu-Daudé
  2022-12-02 15:21         ` Markus Armbruster
  0 siblings, 1 reply; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2022-12-02 14:17 UTC (permalink / raw)
  To: Jonah Palmer, qemu-devel, lvivier, Alex Bennée, Markus Armbruster
  Cc: mst, qemu_oss, kraxel, si-wei.liu, joao.m.martins, eblake,
	qemu-block, david, arei.gonglei, marcandre.lureau, thuth,
	michael.roth, groug, dgilbert, eric.auger, stefanha,
	boris.ostrovsky, kwolf, mathieu.poirier, raphael.norwitz,
	pbonzini

On 2/12/22 13:23, Jonah Palmer wrote:
> 
> On 11/30/22 11:16, Philippe Mathieu-Daudé wrote:
>> Hi,
>>
>> On 11/8/22 14:24, Jonah Palmer wrote:
>>> From: Laurent Vivier <lvivier@redhat.com>
>>>
>>> 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.]
>>>
>>> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
>>> Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
>>> ---
>>>   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
>>
>>> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
>>> index 5d607aeaa0..bdfa82e9c0 100644
>>> --- a/hw/virtio/virtio.c
>>> +++ b/hw/virtio/virtio.c
>>> @@ -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;
>>> +    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()?
> 
> 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/87ee6ogbiw.fsf@dusky.pond.sub.org/
v11:
https://lore.kernel.org/qemu-devel/87ee4abtdu.fsf@pond.sub.org/

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

>>
>>> +            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;
>>> +}



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio
  2022-12-02 14:17       ` Philippe Mathieu-Daudé
@ 2022-12-02 15:21         ` Markus Armbruster
  2022-12-07  8:47           ` Jonah Palmer
  0 siblings, 1 reply; 15+ messages in thread
From: Markus Armbruster @ 2022-12-02 15:21 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Jonah Palmer, qemu-devel, lvivier, Alex Bennée, mst,
	qemu_oss, kraxel, si-wei.liu, joao.m.martins, eblake, qemu-block,
	david, arei.gonglei, marcandre.lureau, thuth, michael.roth,
	groug, dgilbert, eric.auger, stefanha, boris.ostrovsky, kwolf,
	mathieu.poirier, raphael.norwitz, pbonzini

Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> On 2/12/22 13:23, Jonah Palmer wrote:
>> On 11/30/22 11:16, Philippe Mathieu-Daudé wrote:
>>> Hi,
>>>
>>> On 11/8/22 14:24, Jonah Palmer wrote:
>>>> From: Laurent Vivier <lvivier@redhat.com>
>>>>
>>>> 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).

How could this happen?

>>>>
>>>>   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.]
>>>>
>>>> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
>>>> Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
>>>> ---
>>>>   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
>>>
>>>> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
>>>> index 5d607aeaa0..bdfa82e9c0 100644
>>>> --- a/hw/virtio/virtio.c
>>>> +++ b/hw/virtio/virtio.c
>>>> @@ -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;
>>>> +    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()?
>>
>> 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?

>> 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/87ee6ogbiw.fsf@dusky.pond.sub.org/

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 ...

> v11:
> https://lore.kernel.org/qemu-devel/87ee4abtdu.fsf@pond.sub.org/
>
> 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.

[...]



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio
  2022-12-02 15:21         ` Markus Armbruster
@ 2022-12-07  8:47           ` Jonah Palmer
  2022-12-07 13:22             ` Markus Armbruster
  0 siblings, 1 reply; 15+ messages in thread
From: Jonah Palmer @ 2022-12-07  8:47 UTC (permalink / raw)
  To: Markus Armbruster, Philippe Mathieu-Daudé
  Cc: qemu-devel, lvivier, Alex Bennée, mst, qemu_oss, kraxel,
	si-wei.liu, joao.m.martins, eblake, qemu-block, david,
	arei.gonglei, marcandre.lureau, thuth, michael.roth, groug,
	dgilbert, eric.auger, stefanha, boris.ostrovsky, kwolf,
	mathieu.poirier, raphael.norwitz, pbonzini

[-- Attachment #1: Type: text/plain, Size: 8109 bytes --]


On 12/2/22 10:21, Markus Armbruster wrote:
> Philippe Mathieu-Daudé<philmd@linaro.org>  writes:
>
>> On 2/12/22 13:23, Jonah Palmer wrote:
>>> On 11/30/22 11:16, Philippe Mathieu-Daudé wrote:
>>>> Hi,
>>>>
>>>> On 11/8/22 14:24, Jonah Palmer wrote:
>>>>> From: Laurent Vivier<lvivier@redhat.com>
>>>>>
>>>>> 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).
> How could this happen?
>
>>>>>    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.]
>>>>>
>>>>> Signed-off-by: Laurent Vivier<lvivier@redhat.com>
>>>>> Signed-off-by: Jonah Palmer<jonah.palmer@oracle.com>
>>>>> ---
>>>>>    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
>>>>> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
>>>>> index 5d607aeaa0..bdfa82e9c0 100644
>>>>> --- a/hw/virtio/virtio.c
>>>>> +++ b/hw/virtio/virtio.c
>>>>> @@ -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;
>>>>> +    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()?
>>> 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.

>>> 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/87ee6ogbiw.fsf@dusky.pond.sub.org/__;!!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 ...
>
>> v11:
>> https://urldefense.com/v3/__https://lore.kernel.org/qemu-devel/87ee4abtdu.fsf@pond.sub.org/__;!!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.
>
> [...]
>

[-- Attachment #2: Type: text/html, Size: 11333 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio
  2022-12-07  8:47           ` Jonah Palmer
@ 2022-12-07 13:22             ` Markus Armbruster
  2022-12-09  8:54               ` Jonah Palmer
  0 siblings, 1 reply; 15+ messages in thread
From: Markus Armbruster @ 2022-12-07 13:22 UTC (permalink / raw)
  To: Jonah Palmer
  Cc: Philippe Mathieu-Daudé,
	qemu-devel, lvivier, Alex Bennée, mst, qemu_oss, kraxel,
	si-wei.liu, joao.m.martins, eblake, qemu-block, david,
	arei.gonglei, marcandre.lureau, thuth, michael.roth, groug,
	dgilbert, eric.auger, stefanha, boris.ostrovsky, kwolf,
	mathieu.poirier, raphael.norwitz, pbonzini

Jonah Palmer <jonah.palmer@oracle.com> writes:

> On 12/2/22 10:21, Markus Armbruster wrote:
>> Philippe Mathieu-Daudé<philmd@linaro.org>  writes:
>>
>>> On 2/12/22 13:23, Jonah Palmer wrote:
>>>> On 11/30/22 11:16, Philippe Mathieu-Daudé wrote:
>>>>> Hi,
>>>>>
>>>>> On 11/8/22 14:24, Jonah Palmer wrote:
>>>>>> From: Laurent Vivier<lvivier@redhat.com>
>>>>>>
>>>>>> 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).
>>
>> How could this happen?
>>
>>>>>>    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.]
>>>>>>
>>>>>> Signed-off-by: Laurent Vivier<lvivier@redhat.com>
>>>>>> Signed-off-by: Jonah Palmer<jonah.palmer@oracle.com>
>>>>>> ---
>>>>>>    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
>>>>>> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
>>>>>> index 5d607aeaa0..bdfa82e9c0 100644
>>>>>> --- a/hw/virtio/virtio.c
>>>>>> +++ b/hw/virtio/virtio.c
>>>>>> @@ -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;
>>>>>> +    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()?
>>>>
>>>> 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.

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

>>>> 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/87ee6ogbiw.fsf@dusky.pond.sub.org/__;!!ACWV5N9M2RV99hQ!LqeLFhE8PtTTg_qKRuP9Kgz5pyTNZLhYeRzp4a2oS8c3D5W8-irZoBW0L_Lf1ozm3qYidYhuVrjxjsAw$  

... this:

>> 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.

[...]



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio
  2022-12-07 13:22             ` Markus Armbruster
@ 2022-12-09  8:54               ` Jonah Palmer
  0 siblings, 0 replies; 15+ messages in thread
From: Jonah Palmer @ 2022-12-09  8:54 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Philippe Mathieu-Daudé,
	qemu-devel, lvivier, Alex Bennée, mst, qemu_oss, kraxel,
	si-wei.liu, joao.m.martins, eblake, qemu-block, david,
	arei.gonglei, marcandre.lureau, thuth, michael.roth, groug,
	dgilbert, eric.auger, stefanha, boris.ostrovsky, kwolf,
	mathieu.poirier, raphael.norwitz, pbonzini

[-- Attachment #1: Type: text/plain, Size: 9085 bytes --]


On 12/7/22 08:22, Markus Armbruster wrote:
> Jonah Palmer<jonah.palmer@oracle.com>  writes:
>
>> On 12/2/22 10:21, Markus Armbruster wrote:
>>> Philippe Mathieu-Daudé<philmd@linaro.org>   writes:
>>>
>>>> On 2/12/22 13:23, Jonah Palmer wrote:
>>>>> On 11/30/22 11:16, Philippe Mathieu-Daudé wrote:
>>>>>> Hi,
>>>>>>
>>>>>> On 11/8/22 14:24, Jonah Palmer wrote:
>>>>>>> From: Laurent Vivier<lvivier@redhat.com>
>>>>>>>
>>>>>>> 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).
>>> How could this happen?
>>>
>>>>>>>     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.]
>>>>>>>
>>>>>>> Signed-off-by: Laurent Vivier<lvivier@redhat.com>
>>>>>>> Signed-off-by: Jonah Palmer<jonah.palmer@oracle.com>
>>>>>>> ---
>>>>>>>     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
>>>>>>> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
>>>>>>> index 5d607aeaa0..bdfa82e9c0 100644
>>>>>>> --- a/hw/virtio/virtio.c
>>>>>>> +++ b/hw/virtio/virtio.c
>>>>>>> @@ -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;
>>>>>>> +    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()?
>>>>> 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.
> I'm not debating whether to have the command right now.  I'm debating
> the introduction of variable @virtio_list.  Please consider...
>
>>>>> 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/87ee6ogbiw.fsf@dusky.pond.sub.org/__;!!ACWV5N9M2RV99hQ!LqeLFhE8PtTTg_qKRuP9Kgz5pyTNZLhYeRzp4a2oS8c3D5W8-irZoBW0L_Lf1ozm3qYidYhuVrjxjsAw$   
> ... this:
>
>>> 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.

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

>
> [...]
>

[-- Attachment #2: Type: text/html, Size: 12210 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-12-09  8:55 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-11 12:24 [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices Jonah Palmer
2022-08-11 12:24 ` [PATCH v15 1/6] qmp: add QMP command x-query-virtio Jonah Palmer
2022-11-30 16:16   ` Philippe Mathieu-Daudé
2022-12-02 12:23     ` Jonah Palmer
2022-12-02 14:17       ` Philippe Mathieu-Daudé
2022-12-02 15:21         ` Markus Armbruster
2022-12-07  8:47           ` Jonah Palmer
2022-12-07 13:22             ` Markus Armbruster
2022-12-09  8:54               ` Jonah Palmer
2022-08-11 12:24 ` [PATCH v15 2/6] qmp: add QMP command x-query-virtio-status Jonah Palmer
2022-08-11 12:24 ` [PATCH v15 3/6] qmp: decode feature & status bits in virtio-status Jonah Palmer
2022-08-11 12:24 ` [PATCH v15 4/6] qmp: add QMP commands for virtio/vhost queue-status Jonah Palmer
2022-08-11 12:24 ` [PATCH v15 5/6] qmp: add QMP command x-query-virtio-queue-element Jonah Palmer
2022-08-11 12:24 ` [PATCH v15 6/6] hmp: add virtio commands Jonah Palmer
2022-09-27  8:36 ` [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices Jonah Palmer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.