Skip to contentSkip to conversation

hmp,qmp: Add commands to introspect virtio devices

PATCH Superseded Jonah Palmer 2 participants 21 messages Nov 10, 2021 – Nov 19, 2021 Arm/Amlogic Meson SoC support

v9 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

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

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

[Jonah: Rebasing previous patchset from Oct. 27 (v8). Original patches
are from Laurent Vivier from May 2020.

Rebase from v8 to v9 includes renaming of 'x-' prefixed QMP commands, adding the 'unstable' feature to 'x-' prefixed QMP commands, fixes to odd indentation in qapi/virtio.json, support for virtio-mem features, and moving HMP 'virtio' sub-commands to 'info' sub-commands.]

1. List available virtio devices in the machine

HMP Form:

info virtio

Example:

(qemu) info virtio /machine/peripheral/vsock0/virtio-backend [vhost-vsock] /machine/peripheral/crypto0/virtio-backend [virtio-crypto] /machine/peripheral-anon/device[2]/virtio-backend [virtio-scsi] /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'] }

    Example:

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

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: acknowledge, driver, features-ok, driver-ok
Guest features: event-idx, indirect-desc, version-1
Host features: protocol-features, event-idx, indirect-desc, version-1, any-layout,
notify-on-empty
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: event-idx, indirect-desc, version-1, any-layout, notify-on-empty,
log-all
Acked features: event-idx, indirect-desc, version-1
Backend features:
Protocol features:

QMP Form:

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

    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": {
                        "transport": [],
                        "type": "vhost-vsock",
                        "features": []
                    },
                    "nvqs": 2,
                    "protocol-features": {
                        "features": []
                    },
                    "vq-index": 0,
                    "log-enabled": false,
                    "acked-features": {
                        "transport": ["event-idx", "indirect-desc", "version-1"],
                        "type": "vhost-vsock",
                        "features": []
                    },
                    "features": {
                        "transport": ["event-idx", "indirect-desc", "version-1", "any-layout",
                                      "notify-on-empty"],
                        "type": "vhost-vsock",
                        "features": ["log-all"]
                    }
                },
                "backend-features": {
                    "transport": [],
                    "type": "vhost-vsock",
                    "features": []
                },
                "start-on-kick": false,
                "isr": 0,
                "broken": false,
                "status": {
                    "dev-status": ["acknowledge", "driver", "features-ok", "driver-ok"]
                },
                "num-vqs": 3,
                "guest-features": {
                    "transport": ["event-idx", "indirect-desc", "version-1"],
                    "type": "vhost-vsock",
                    "features": []
                },
                "host-features": {
                    "transport": ["protocol-features", "event-idx", "indirect-desc", "version-1",
                                  "any-layout", "notify-on-empty"],
                    "type": "vhost-vsock",
                    "features": []
                },
                "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:             27
            signalled_used:       27
            signalled_used_valid: true
            VRing:
                num:          64
                num_default:  64
                align:        4096
                desc:         0x00000001342b5000
                avail:        0x00000001342b5400
                used:         0x00000001342b54c0

QMP Form:

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

    Example:

        -> { "execute": "x-query-virtio-queue-status",
             "arguments": {
                "path": "/machine/peripheral-anon/device[1]/virtio-backend",
                "queue": 2
             }
           }
        <- { "return": {
                "signalled-used": 27,
                "inuse": 0,
                "vring-align": 4096,
                "vring-desc": 5170221056,
                "signalled-used-valid": true,
                "vring-num-default": 64,
                "vring-avail": 5170222080,
                "queue-index": 2,
                "vring-used": 5170222272,
                "used-idx": 27,
                "device-name": "virtio-net",
                "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:        0x00007f31c032c000
                desc_phys:   0x00000001340c6000
                desc_size:   4096
                avail:       0x00007f31c032d000
                avail_phys:  0x00000001340c7000
                avail_size:  518
                used:        0x00007f31c032d240
                used_phys:   0x00000001340c7240
                used_size:   2054

QMP Form:

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

    Example:

        -> { "execute": "x-query-virtio-vhost-queue-status",
             "arguments": {
                "path": "/machine/peripheral-anon/device[1]/virtio-backend",
                "queue": 1
             }
           }
        <- { "return": {
                "avail-phys": 5168197632,
                "used-phys": 5168198208,
                "avail-size": 518,
                "desc-size": 4096,
                "used-size": 2054,
                "desc": 139851654676480,
                "num": 256,
                "device-name": "virtio-net",
                "call": 0,
                "avail": 139851654680576,
                "desc-phys": 5168193536,
                "used": 139851654681152,
                "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:       125
            desc:
                ndescs:  1
                descs:   addr 0xa4f90f1d0653b5fc len 1862028160 (used, avail, next)
            avail:
                flags: 0
                idx:   2936
                ring:  125
            used:
                flags: 0
                idx:   2936

QMP Form:

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

    Example:

        -> { "execute": "x-query-virtio-queue-element",
             "arguments": {
                "path": "/machine/peripheral-anon/device[2]/virtio-backend",
                "queue": 2
             }
           }
        <- { "return": {
                "index": 125,
                "ndescs": 1,
                "device-name": "virtio-scsi",
                "descs": [
                    {
                        "flags": ["used", "avail", "next"],
                        "len": 1862028160,
                        "addr": 11887549308755752444
                    }
                ],
                "avail": {
                    "idx": 2936,
                    "flags": 0,
                    "ring": 125
                },
                "used": {
                    "idx": 2936,
                    "flags": 0
                }
             }
           }

[Jonah - Comments:
Note: for patch 8/8, checkpatch.pl gives the following error:

    ERROR: spaces required around that '*' (ctx:WxV)
    #374: FILE: hw/virtio/virtio.c:4107:
             type##FeatureList *list = features->u.field.features;
                               ^

However, adding a space between the asterisk gives a similar error telling me to change it back to the former representation... so I just left it as this.]

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

Jonah Palmer (2):
virtio: drop name parameter for virtio_init()
virtio: add vhost support for virtio devices

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                        |  218 +++++
 hw/9pfs/virtio-9p-device.c                  |    2 +-
 hw/block/vhost-user-blk.c                   |    9 +-
 hw/block/virtio-blk.c                       |   30 +-
 hw/char/virtio-serial-bus.c                 |   15 +-
 hw/display/vhost-user-gpu.c                 |    7 +
 hw/display/virtio-gpu-base.c                |   20 +-
 hw/input/vhost-user-input.c                 |    7 +
 hw/input/virtio-input.c                     |   14 +-
 hw/net/virtio-net.c                         |   58 +-
 hw/scsi/vhost-scsi.c                        |    8 +
 hw/scsi/virtio-scsi.c                       |   20 +-
 hw/virtio/meson.build                       |    2 +
 hw/virtio/vhost-user-fs.c                   |   20 +-
 hw/virtio/vhost-user-i2c.c                  |    6 +-
 hw/virtio/vhost-user-rng.c                  |    9 +-
 hw/virtio/vhost-user-vsock.c                |    2 +-
 hw/virtio/vhost-vsock-common.c              |   21 +-
 hw/virtio/vhost-vsock.c                     |    2 +-
 hw/virtio/vhost.c                           |    3 +
 hw/virtio/virtio-balloon.c                  |   17 +-
 hw/virtio/virtio-crypto.c                   |   22 +-
 hw/virtio/virtio-iommu.c                    |   17 +-
 hw/virtio/virtio-mem.c                      |   14 +-
 hw/virtio/virtio-pmem.c                     |    3 +-
 hw/virtio/virtio-rng.c                      |    2 +-
 hw/virtio/virtio-stub.c                     |   42 +
 hw/virtio/virtio.c                          |  686 ++++++++++++++-
 include/hw/virtio/vhost-vsock-common.h      |    2 +-
 include/hw/virtio/vhost.h                   |    3 +
 include/hw/virtio/virtio-gpu.h              |    3 +-
 include/hw/virtio/virtio.h                  |   25 +-
 include/monitor/hmp.h                       |    5 +
 include/standard-headers/linux/virtio_ids.h |    1 +
 monitor/hmp-cmds.c                          |  358 ++++++++
 qapi/meson.build                            |    1 +
 qapi/qapi-schema.json                       |    1 +
 qapi/virtio.json                            | 1240 +++++++++++++++++++++++++++
 tests/qtest/qmp-cmd-test.c                  |    1 +
 39 files changed, 2873 insertions(+), 43 deletions(-)
 create mode 100644 hw/virtio/virtio-stub.c
 create mode 100644 qapi/virtio.json
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v9 1/8 virtio: drop name parameter for virtio_init()

This patch drops the name parameter for the virtio_init function.

The pair between the numeric device ID and the string device ID (name) of a virtio device already exists, but not in a way that lets us map between them.

This patch will let us do this and removes the need for the name parameter in virtio_init().

---
 hw/9pfs/virtio-9p-device.c                  |  2 +-
 hw/block/vhost-user-blk.c                   |  2 +-
 hw/block/virtio-blk.c                       |  2 +-
 hw/char/virtio-serial-bus.c                 |  4 +--
 hw/display/virtio-gpu-base.c                |  2 +-
 hw/input/virtio-input.c                     |  3 +-
 hw/net/virtio-net.c                         |  2 +-
 hw/scsi/virtio-scsi.c                       |  3 +-
 hw/virtio/vhost-user-fs.c                   |  3 +-
 hw/virtio/vhost-user-i2c.c                  |  6 +---
 hw/virtio/vhost-user-rng.c                  |  2 +-
 hw/virtio/vhost-user-vsock.c                |  2 +-
 hw/virtio/vhost-vsock-common.c              |  4 +--
 hw/virtio/vhost-vsock.c                     |  2 +-
 hw/virtio/virtio-balloon.c                  |  3 +-
 hw/virtio/virtio-crypto.c                   |  2 +-
 hw/virtio/virtio-iommu.c                    |  3 +-
 hw/virtio/virtio-mem.c                      |  3 +-
 hw/virtio/virtio-pmem.c                     |  3 +-
 hw/virtio/virtio-rng.c                      |  2 +-
 hw/virtio/virtio.c                          | 45 +++++++++++++++++++++++++++--
 include/hw/virtio/vhost-vsock-common.h      |  2 +-
 include/hw/virtio/virtio-gpu.h              |  3 +-
 include/hw/virtio/virtio.h                  |  3 +-
 include/standard-headers/linux/virtio_ids.h |  1 +
 25 files changed, 68 insertions(+), 41 deletions(-)
hw/9pfs/virtio-9p-device.c +1 -1
index 54ee93b..5f522e6 100644
@@ -216,7 +216,7 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
     }
 
     v->config_size = sizeof(struct virtio_9p_config) + strlen(s->fsconf.tag);
-    virtio_init(vdev, "virtio-9p", VIRTIO_ID_9P, v->config_size);
+    virtio_init(vdev, VIRTIO_ID_9P, v->config_size);
     v->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output);
 }
 
hw/block/vhost-user-blk.c +1 -1
index ba13cb8..f61f8c1 100644
@@ -490,7 +490,7 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
+    virtio_init(vdev, VIRTIO_ID_BLOCK,
                 sizeof(struct virtio_blk_config));
 
     s->virtqs = g_new(VirtQueue *, s->num_queues);
hw/block/virtio-blk.c +1 -1
index f139cd7..505e574 100644
@@ -1213,7 +1213,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
 
     virtio_blk_set_config_size(s, s->host_features);
 
-    virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, s->config_size);
+    virtio_init(vdev, VIRTIO_ID_BLOCK, s->config_size);
 
     s->blk = conf->conf.blk;
     s->rq = NULL;
hw/char/virtio-serial-bus.c +2 -2
index f01ec21..232f4c9 100644
@@ -1044,8 +1044,8 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp)
                             VIRTIO_CONSOLE_F_EMERG_WRITE)) {
         config_size = offsetof(struct virtio_console_config, emerg_wr);
     }
-    virtio_init(vdev, "virtio-serial", VIRTIO_ID_CONSOLE,
-                config_size);
+
+    virtio_init(vdev, VIRTIO_ID_CONSOLE, config_size);
 
     /* Spawn a new virtio-serial bus on which the ports will ride as devices */
     qbus_init(&vser->bus, sizeof(vser->bus), TYPE_VIRTIO_SERIAL_BUS,
hw/display/virtio-gpu-base.c +1 -1
index c8da480..5411a7b 100644
@@ -170,7 +170,7 @@ virtio_gpu_base_device_realize(DeviceState *qdev,
     }
 
     g->virtio_config.num_scanouts = cpu_to_le32(g->conf.max_outputs);
-    virtio_init(VIRTIO_DEVICE(g), "virtio-gpu", VIRTIO_ID_GPU,
+    virtio_init(VIRTIO_DEVICE(g), VIRTIO_ID_GPU,
                 sizeof(struct virtio_gpu_config));
 
     if (virtio_gpu_virgl_enabled(g->conf)) {
hw/input/virtio-input.c +1 -2
index 54bcb46..5b5398b 100644
@@ -257,8 +257,7 @@ static void virtio_input_device_realize(DeviceState *dev, Error **errp)
     vinput->cfg_size += 8;
     assert(vinput->cfg_size <= sizeof(virtio_input_config));
 
-    virtio_init(vdev, "virtio-input", VIRTIO_ID_INPUT,
-                vinput->cfg_size);
+    virtio_init(vdev, VIRTIO_ID_INPUT, vinput->cfg_size);
     vinput->evt = virtio_add_queue(vdev, 64, virtio_input_handle_evt);
     vinput->sts = virtio_add_queue(vdev, 64, virtio_input_handle_sts);
 }
hw/net/virtio-net.c +1 -1
index f2014d5..b275acf 100644
@@ -3383,7 +3383,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
     }
 
     virtio_net_set_config_size(n, n->host_features);
-    virtio_init(vdev, "virtio-net", VIRTIO_ID_NET, n->config_size);
+    virtio_init(vdev, VIRTIO_ID_NET, n->config_size);
 
     /*
      * We set a lower limit on RX queue size to what it always was.
hw/scsi/virtio-scsi.c +1 -2
index 51fd095..ce71939 100644
@@ -972,8 +972,7 @@ void virtio_scsi_common_realize(DeviceState *dev,
     VirtIOSCSICommon *s = VIRTIO_SCSI_COMMON(dev);
     int i;
 
-    virtio_init(vdev, "virtio-scsi", VIRTIO_ID_SCSI,
-                sizeof(VirtIOSCSIConfig));
+    virtio_init(vdev, VIRTIO_ID_SCSI, sizeof(VirtIOSCSIConfig));
 
     if (s->conf.num_queues == VIRTIO_SCSI_AUTO_NUM_QUEUES) {
         s->conf.num_queues = 1;
hw/virtio/vhost-user-fs.c +1 -2
index c595957..b875640 100644
@@ -219,8 +219,7 @@ static void vuf_device_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    virtio_init(vdev, "vhost-user-fs", VIRTIO_ID_FS,
-                sizeof(struct virtio_fs_config));
+    virtio_init(vdev, VIRTIO_ID_FS, sizeof(struct virtio_fs_config));
 
     /* Hiprio queue */
     fs->hiprio_vq = virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output);
hw/virtio/vhost-user-i2c.c +1 -5
index d172632..efc6fc0 100644
@@ -14,10 +14,6 @@
 #include "qemu/error-report.h"
 #include "standard-headers/linux/virtio_ids.h"
 
-/* Remove this once the header is updated in Linux kernel */
-#ifndef VIRTIO_ID_I2C_ADAPTER
-#define VIRTIO_ID_I2C_ADAPTER                34
-#endif
 
 static void vu_i2c_start(VirtIODevice *vdev)
 {
@@ -220,7 +216,7 @@ static void vu_i2c_device_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    virtio_init(vdev, "vhost-user-i2c", VIRTIO_ID_I2C_ADAPTER, 0);
+    virtio_init(vdev, VIRTIO_ID_I2C_ADAPTER, 0);
 
     i2c->vhost_dev.nvqs = 1;
     i2c->vq = virtio_add_queue(vdev, 4, vu_i2c_handle_output);
hw/virtio/vhost-user-rng.c +1 -1
index 209ee5b..08bccba 100644
@@ -203,7 +203,7 @@ static void vu_rng_device_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    virtio_init(vdev, "vhost-user-rng", VIRTIO_ID_RNG, 0);
+    virtio_init(vdev, VIRTIO_ID_RNG, 0);
 
     rng->req_vq = virtio_add_queue(vdev, 4, vu_rng_handle_output);
     if (!rng->req_vq) {
hw/virtio/vhost-user-vsock.c +1 -1
index 52bd682..0f8ff99 100644
@@ -107,7 +107,7 @@ static void vuv_device_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    vhost_vsock_common_realize(vdev, "vhost-user-vsock");
+    vhost_vsock_common_realize(vdev);
 
     vhost_dev_set_config_notifier(&vvc->vhost_dev, &vsock_ops);
 
hw/virtio/vhost-vsock-common.c +2 -2
index 3f37712..e8f6249 100644
@@ -220,11 +220,11 @@ int vhost_vsock_common_post_load(void *opaque, int version_id)
     return 0;
 }
 
-void vhost_vsock_common_realize(VirtIODevice *vdev, const char *name)
+void vhost_vsock_common_realize(VirtIODevice *vdev)
 {
     VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev);
 
-    virtio_init(vdev, name, VIRTIO_ID_VSOCK,
+    virtio_init(vdev, VIRTIO_ID_VSOCK,
                 sizeof(struct virtio_vsock_config));
 
     /* Receive and transmit queues belong to vhost */
hw/virtio/vhost-vsock.c +1 -1
index 478c0c9..3d4ede9 100644
@@ -166,7 +166,7 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp)
         qemu_set_nonblock(vhostfd);
     }
 
-    vhost_vsock_common_realize(vdev, "vhost-vsock");
+    vhost_vsock_common_realize(vdev);
 
     ret = vhost_dev_init(&vvc->vhost_dev, (void *)(uintptr_t)vhostfd,
                          VHOST_BACKEND_TYPE_KERNEL, 0, errp);
hw/virtio/virtio-balloon.c +1 -2
index c6962fc..641a394 100644
@@ -885,8 +885,7 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
     VirtIOBalloon *s = VIRTIO_BALLOON(dev);
     int ret;
 
-    virtio_init(vdev, "virtio-balloon", VIRTIO_ID_BALLOON,
-                virtio_balloon_config_size(s));
+    virtio_init(vdev, VIRTIO_ID_BALLOON, virtio_balloon_config_size(s));
 
     ret = qemu_add_balloon_handler(virtio_balloon_to_target,
                                    virtio_balloon_stat, s);
hw/virtio/virtio-crypto.c +1 -1
index 54f9bbb..cca5237 100644
@@ -810,7 +810,7 @@ static void virtio_crypto_device_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    virtio_init(vdev, "virtio-crypto", VIRTIO_ID_CRYPTO, vcrypto->config_size);
+    virtio_init(vdev, VIRTIO_ID_CRYPTO, vcrypto->config_size);
     vcrypto->curr_queues = 1;
     vcrypto->vqs = g_malloc0(sizeof(VirtIOCryptoQueue) * vcrypto->max_queues);
     for (i = 0; i < vcrypto->max_queues; i++) {
hw/virtio/virtio-iommu.c +1 -2
index 1b23e8e..92c5eb7 100644
@@ -973,8 +973,7 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp)
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VirtIOIOMMU *s = VIRTIO_IOMMU(dev);
 
-    virtio_init(vdev, "virtio-iommu", VIRTIO_ID_IOMMU,
-                sizeof(struct virtio_iommu_config));
+    virtio_init(vdev, VIRTIO_ID_IOMMU, sizeof(struct virtio_iommu_config));
 
     memset(s->iommu_pcibus_by_bus_num, 0, sizeof(s->iommu_pcibus_by_bus_num));
 
hw/virtio/virtio-mem.c +1 -2
index d5a5781..e217520 100644
@@ -769,8 +769,7 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp)
                         vmem->block_size;
     vmem->bitmap = bitmap_new(vmem->bitmap_size);
 
-    virtio_init(vdev, TYPE_VIRTIO_MEM, VIRTIO_ID_MEM,
-                sizeof(struct virtio_mem_config));
+    virtio_init(vdev, VIRTIO_ID_MEM, sizeof(struct virtio_mem_config));
     vmem->vq = virtio_add_queue(vdev, 128, virtio_mem_handle_request);
 
     host_memory_backend_set_mapped(vmem->memdev, true);
hw/virtio/virtio-pmem.c +1 -2
index d1aeb90..8cbbd78 100644
@@ -123,8 +123,7 @@ static void virtio_pmem_realize(DeviceState *dev, Error **errp)
     }
 
     host_memory_backend_set_mapped(pmem->memdev, true);
-    virtio_init(vdev, TYPE_VIRTIO_PMEM, VIRTIO_ID_PMEM,
-                sizeof(struct virtio_pmem_config));
+    virtio_init(vdev, VIRTIO_ID_PMEM, sizeof(struct virtio_pmem_config));
     pmem->rq_vq = virtio_add_queue(vdev, 128, virtio_pmem_flush);
 }
 
hw/virtio/virtio-rng.c +1 -1
index cc8e9f7..7e12fc0 100644
@@ -215,7 +215,7 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    virtio_init(vdev, "virtio-rng", VIRTIO_ID_RNG, 0);
+    virtio_init(vdev, VIRTIO_ID_RNG, 0);
 
     vrng->vq = virtio_add_queue(vdev, 8, handle_input);
     vrng->quota_remaining = vrng->conf.max_bytes;
hw/virtio/virtio.c +42 -3

63 lines not on this page · raw message

include/hw/virtio/vhost-vsock-common.h +1 -1
index d8b565b..076b7ab 100644
@@ -44,7 +44,7 @@ int vhost_vsock_common_start(VirtIODevice *vdev);
 void vhost_vsock_common_stop(VirtIODevice *vdev);
 int vhost_vsock_common_pre_save(void *opaque);
 int vhost_vsock_common_post_load(void *opaque, int version_id);
-void vhost_vsock_common_realize(VirtIODevice *vdev, const char *name);
+void vhost_vsock_common_realize(VirtIODevice *vdev);
 void vhost_vsock_common_unrealize(VirtIODevice *vdev);
 uint64_t vhost_vsock_common_get_features(VirtIODevice *vdev, uint64_t features,
                                          Error **errp);
include/hw/virtio/virtio-gpu.h +1 -2
index acfba7c..ac487d2 100644
@@ -22,6 +22,7 @@
 #include "sysemu/vhost-user-backend.h"
 
 #include "standard-headers/linux/virtio_gpu.h"
+#include "standard-headers/linux/virtio_ids.h"
 #include "qom/object.h"
 
 #define TYPE_VIRTIO_GPU_BASE "virtio-gpu-base"
@@ -37,8 +38,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(VirtIOGPUGL, VIRTIO_GPU_GL)
 #define TYPE_VHOST_USER_GPU "vhost-user-gpu"
 OBJECT_DECLARE_SIMPLE_TYPE(VhostUserGPU, VHOST_USER_GPU)
 
-#define VIRTIO_ID_GPU 16
-
 struct virtio_gpu_simple_resource {
     uint32_t resource_id;
     uint32_t width;
include/hw/virtio/virtio.h +1 -2
index 8bab9cf..bfc73ec 100644
@@ -165,8 +165,7 @@ struct VirtioDeviceClass {
 void virtio_instance_init_common(Object *proxy_obj, void *data,
                                  size_t vdev_size, const char *vdev_name);
 
-void virtio_init(VirtIODevice *vdev, const char *name,
-                         uint16_t device_id, size_t config_size);
+void virtio_init(VirtIODevice *vdev, uint16_t device_id, size_t config_size);
 void virtio_cleanup(VirtIODevice *vdev);
 
 void virtio_error(VirtIODevice *vdev, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
include/standard-headers/linux/virtio_ids.h +1 -0
index 4fe842c..3957d11 100644
@@ -55,6 +55,7 @@
 #define VIRTIO_ID_FS			26 /* virtio filesystem */
 #define VIRTIO_ID_PMEM			27 /* virtio pmem */
 #define VIRTIO_ID_MAC80211_HWSIM	29 /* virtio mac80211-hwsim */
+#define VIRTIO_ID_I2C_ADAPTER           34 /* virtio I2C adapater */
 #define VIRTIO_ID_BT			40 /* virtio bluetooth */
 
 #endif /* _LINUX_VIRTIO_IDS_H */
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v9 2/8 virtio: add vhost support for virtio devices

In reply to Jonah Palmer

This patch adds a get_vhost() callback function for VirtIODevices that returns the device's corresponding vhost_dev structure if the vhost device is running. This patch also adds a vhost_started flag for VirtIODevices.

Previously, a VirtIODevice wouldn't be able to tell if its corresponding vhost device was active or not.

---
 hw/block/vhost-user-blk.c      |  7 +++++++
 hw/display/vhost-user-gpu.c    |  7 +++++++
 hw/input/vhost-user-input.c    |  7 +++++++
 hw/net/virtio-net.c            |  9 +++++++++
 hw/scsi/vhost-scsi.c           |  8 ++++++++
 hw/virtio/vhost-user-fs.c      |  7 +++++++
 hw/virtio/vhost-user-rng.c     |  7 +++++++
 hw/virtio/vhost-vsock-common.c |  7 +++++++
 hw/virtio/vhost.c              |  3 +++
 hw/virtio/virtio-crypto.c      | 10 ++++++++++
 hw/virtio/virtio.c             |  1 +
 include/hw/virtio/virtio.h     |  3 +++
 12 files changed, 76 insertions(+)
hw/block/vhost-user-blk.c +7 -0
index f61f8c1..b059da1 100644
@@ -568,6 +568,12 @@ static void vhost_user_blk_instance_init(Object *obj)
                                   "/disk@0,0", DEVICE(obj));
 }
 
+static struct vhost_dev *vhost_user_blk_get_vhost(VirtIODevice *vdev)
+{
+    VHostUserBlk *s = VHOST_USER_BLK(vdev);
+    return &s->dev;
+}
+
 static const VMStateDescription vmstate_vhost_user_blk = {
     .name = "vhost-user-blk",
     .minimum_version_id = 1,
@@ -602,6 +608,7 @@ static void vhost_user_blk_class_init(ObjectClass *klass, void *data)
     vdc->get_features = vhost_user_blk_get_features;
     vdc->set_status = vhost_user_blk_set_status;
     vdc->reset = vhost_user_blk_reset;
+    vdc->get_vhost = vhost_user_blk_get_vhost;
 }
 
 static const TypeInfo vhost_user_blk_info = {
hw/display/vhost-user-gpu.c +7 -0
index 49df56c..6e93b46 100644
@@ -565,6 +565,12 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error **errp)
     g->vhost_gpu_fd = -1;
 }
 
+static struct vhost_dev *vhost_user_gpu_get_vhost(VirtIODevice *vdev)
+{
+    VhostUserGPU *g = VHOST_USER_GPU(vdev);
+    return &g->vhost->dev;
+}
+
 static Property vhost_user_gpu_properties[] = {
     VIRTIO_GPU_BASE_PROPERTIES(VhostUserGPU, parent_obj.conf),
     DEFINE_PROP_END_OF_LIST(),
@@ -586,6 +592,7 @@ vhost_user_gpu_class_init(ObjectClass *klass, void *data)
     vdc->guest_notifier_pending = vhost_user_gpu_guest_notifier_pending;
     vdc->get_config = vhost_user_gpu_get_config;
     vdc->set_config = vhost_user_gpu_set_config;
+    vdc->get_vhost = vhost_user_gpu_get_vhost;
 
     device_class_set_props(dc, vhost_user_gpu_properties);
 }
hw/input/vhost-user-input.c +7 -0
index 273e96a..43d2ff3 100644
@@ -79,6 +79,12 @@ static void vhost_input_set_config(VirtIODevice *vdev,
     virtio_notify_config(vdev);
 }
 
+static struct vhost_dev *vhost_input_get_vhost(VirtIODevice *vdev)
+{
+    VHostUserInput *vhi = VHOST_USER_INPUT(vdev);
+    return &vhi->vhost->dev;
+}
+
 static const VMStateDescription vmstate_vhost_input = {
     .name = "vhost-user-input",
     .unmigratable = 1,
@@ -93,6 +99,7 @@ static void vhost_input_class_init(ObjectClass *klass, void *data)
     dc->vmsd = &vmstate_vhost_input;
     vdc->get_config = vhost_input_get_config;
     vdc->set_config = vhost_input_set_config;
+    vdc->get_vhost = vhost_input_get_vhost;
     vic->realize = vhost_input_realize;
     vic->change_active = vhost_input_change_active;
 }
hw/net/virtio-net.c +9 -0
index b275acf..2449b9c 100644
@@ -3610,6 +3610,14 @@ static bool dev_unplug_pending(void *opaque)
     return vdc->primary_unplug_pending(dev);
 }
 
+static struct vhost_dev *virtio_net_get_vhost(VirtIODevice *vdev)
+{
+    VirtIONet *n = VIRTIO_NET(vdev);
+    NetClientState *nc = qemu_get_queue(n->nic);
+    struct vhost_net *net = get_vhost_net(nc->peer);
+    return &net->dev;
+}
+
 static const VMStateDescription vmstate_virtio_net = {
     .name = "virtio-net",
     .minimum_version_id = VIRTIO_NET_VM_VERSION,
@@ -3712,6 +3720,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data)
     vdc->post_load = virtio_net_post_load_virtio;
     vdc->vmsd = &vmstate_virtio_net_device;
     vdc->primary_unplug_pending = primary_unplug_pending;
+    vdc->get_vhost = virtio_net_get_vhost;
 }
 
 static const TypeInfo virtio_net_info = {
hw/scsi/vhost-scsi.c +8 -0
index 039caf2..b0a9c45 100644
@@ -264,6 +264,13 @@ static void vhost_scsi_unrealize(DeviceState *dev)
     virtio_scsi_common_unrealize(dev);
 }
 
+static struct vhost_dev *vhost_scsi_get_vhost(VirtIODevice *vdev)
+{
+    VHostSCSI *s = VHOST_SCSI(vdev);
+    VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s);
+    return &vsc->dev;
+}
+
 static Property vhost_scsi_properties[] = {
     DEFINE_PROP_STRING("vhostfd", VirtIOSCSICommon, conf.vhostfd),
     DEFINE_PROP_STRING("wwpn", VirtIOSCSICommon, conf.wwpn),
@@ -298,6 +305,7 @@ static void vhost_scsi_class_init(ObjectClass *klass, void *data)
     vdc->get_features = vhost_scsi_common_get_features;
     vdc->set_config = vhost_scsi_common_set_config;
     vdc->set_status = vhost_scsi_set_status;
+    vdc->get_vhost = vhost_scsi_get_vhost;
     fwc->get_dev_path = vhost_scsi_common_get_fw_dev_path;
 }
 
hw/virtio/vhost-user-fs.c +7 -0
index b875640..e513e4f 100644
@@ -276,6 +276,12 @@ static void vuf_device_unrealize(DeviceState *dev)
     fs->vhost_dev.vqs = NULL;
 }
 
+static struct vhost_dev *vuf_get_vhost(VirtIODevice *vdev)
+{
+    VHostUserFS *fs = VHOST_USER_FS(vdev);
+    return &fs->vhost_dev;
+}
+
 static const VMStateDescription vuf_vmstate = {
     .name = "vhost-user-fs",
     .unmigratable = 1,
@@ -313,6 +319,7 @@ static void vuf_class_init(ObjectClass *klass, void *data)
     vdc->set_status = vuf_set_status;
     vdc->guest_notifier_mask = vuf_guest_notifier_mask;
     vdc->guest_notifier_pending = vuf_guest_notifier_pending;
+    vdc->get_vhost = vuf_get_vhost;
 }
 
 static const TypeInfo vuf_info = {
hw/virtio/vhost-user-rng.c +7 -0
index 08bccba..3a7bf8e 100644
@@ -247,6 +247,12 @@ static void vu_rng_device_unrealize(DeviceState *dev)
     vhost_user_cleanup(&rng->vhost_user);
 }
 
+static struct vhost_dev *vu_rng_get_vhost(VirtIODevice *vdev)
+{
+    VHostUserRNG *rng = VHOST_USER_RNG(vdev);
+    return &rng->vhost_dev;
+}
+
 static const VMStateDescription vu_rng_vmstate = {
     .name = "vhost-user-rng",
     .unmigratable = 1,
@@ -272,6 +278,7 @@ static void vu_rng_class_init(ObjectClass *klass, void *data)
     vdc->set_status = vu_rng_set_status;
     vdc->guest_notifier_mask = vu_rng_guest_notifier_mask;
     vdc->guest_notifier_pending = vu_rng_guest_notifier_pending;
+    vdc->get_vhost = vu_rng_get_vhost;
 }
 
 static const TypeInfo vu_rng_info = {
hw/virtio/vhost-vsock-common.c +7 -0
index e8f6249..665a0df 100644
@@ -261,6 +261,12 @@ static Property vhost_vsock_common_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
+static struct vhost_dev *vhost_vsock_common_get_vhost(VirtIODevice *vdev)
+{
+    VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev);
+    return &vvc->vhost_dev;
+}
+
 static void vhost_vsock_common_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -270,6 +276,7 @@ static void vhost_vsock_common_class_init(ObjectClass *klass, void *data)
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
     vdc->guest_notifier_mask = vhost_vsock_common_guest_notifier_mask;
     vdc->guest_notifier_pending = vhost_vsock_common_guest_notifier_pending;
+    vdc->get_vhost = vhost_vsock_common_get_vhost;
 }
 
 static const TypeInfo vhost_vsock_common_info = {
hw/virtio/vhost.c +3 -0
index 437347a..96b15a1 100644
@@ -1745,6 +1745,7 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev)
     /* should only be called after backend is connected */
     assert(hdev->vhost_ops);
 
+    vdev->vhost_started = true;
     hdev->started = true;
     hdev->vdev = vdev;
 
@@ -1821,6 +1822,7 @@ fail_mem:
 fail_features:
 
     hdev->started = false;
+    vdev->vhost_started = false;
     return r;
 }
 
@@ -1850,6 +1852,7 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev)
     }
     vhost_log_put(hdev, true);
     hdev->started = false;
+    vdev->vhost_started = false;
     hdev->vdev = NULL;
 }
 
hw/virtio/virtio-crypto.c +10 -0
index cca5237..7d63b8c 100644
@@ -961,6 +961,15 @@ static bool virtio_crypto_guest_notifier_pending(VirtIODevice *vdev, int idx)
     return cryptodev_vhost_virtqueue_pending(vdev, queue, idx);
 }
 
+static struct vhost_dev *virtio_crypto_get_vhost(VirtIODevice *vdev)
+{
+    VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev);
+    CryptoDevBackend *b = vcrypto->cryptodev;
+    CryptoDevBackendClient *cc = b->conf.peers.ccs[0];
+    CryptoDevBackendVhost *vhost_crypto = cryptodev_get_vhost(cc, b, 0);
+    return &vhost_crypto->dev;
+}
+
 static void virtio_crypto_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -977,6 +986,7 @@ static void virtio_crypto_class_init(ObjectClass *klass, void *data)
     vdc->set_status = virtio_crypto_set_status;
     vdc->guest_notifier_mask = virtio_crypto_guest_notifier_mask;
     vdc->guest_notifier_pending = virtio_crypto_guest_notifier_pending;
+    vdc->get_vhost = virtio_crypto_get_vhost;
 }
 
 static void virtio_crypto_instance_init(Object *obj)
hw/virtio/virtio.c +1 -0
index be98b4d..7050bd5 100644
@@ -3289,6 +3289,7 @@ void virtio_init(VirtIODevice *vdev, uint16_t device_id,
 
     vdev->start_on_kick = false;
     vdev->started = false;
+    vdev->vhost_started = false;
     vdev->device_id = device_id;
     vdev->status = 0;
     qatomic_set(&vdev->isr, 0);
include/hw/virtio/virtio.h +3 -0
index bfc73ec..105b98c 100644
@@ -22,6 +22,7 @@
 #include "standard-headers/linux/virtio_config.h"
 #include "standard-headers/linux/virtio_ring.h"
 #include "qom/object.h"
+#include "hw/virtio/vhost.h"
 
 /* A guest should never accept this.  It implies negotiation is broken. */
 #define VIRTIO_F_BAD_FEATURE		30
@@ -102,6 +103,7 @@ struct VirtIODevice
     bool started;
     bool start_on_kick; /* when virtio 1.0 feature has not been negotiated */
     bool disable_legacy_check;
+    bool vhost_started;
     VMChangeStateEntry *vmstate;
     char *bus_name;
     uint8_t device_endian;
@@ -160,6 +162,7 @@ struct VirtioDeviceClass {
     int (*post_load)(VirtIODevice *vdev);
     const VMStateDescription *vmsd;
     bool (*primary_unplug_pending)(void *opaque);
+    struct vhost_dev *(*get_vhost)(VirtIODevice *vdev);
 };
 
 void virtio_instance_init_common(Object *proxy_obj, void *data,
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v9 3/8 qmp: add QMP command x-query-virtio

In reply to Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command lists all the instances of VirtIODevice with their QOM paths and virtio type/name.

---
 hw/virtio/meson.build      |  2 ++
 hw/virtio/virtio-stub.c    | 14 ++++++++++++
 hw/virtio/virtio.c         | 27 +++++++++++++++++++++++
 include/hw/virtio/virtio.h |  1 +
 qapi/meson.build           |  1 +
 qapi/qapi-schema.json      |  1 +
 qapi/virtio.json           | 55 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/qtest/qmp-cmd-test.c |  1 +
 8 files changed, 102 insertions(+)
 create mode 100644 hw/virtio/virtio-stub.c
 create mode 100644 qapi/virtio.json
hw/virtio/meson.build +2 -0
index 521f7d6..d893f5f 100644
@@ -6,8 +6,10 @@ softmmu_virtio_ss.add(when: 'CONFIG_VHOST', if_false: files('vhost-stub.c'))
 
 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'))
 
 virtio_ss = ss.source_set()
 virtio_ss.add(files('virtio.c'))
hw/virtio/virtio-stub.c new file +14 -0
new file mode 100644
index 0000000..05a81ed
@@ -0,0 +1,14 @@
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-virtio.h"
+
+static void *qmp_virtio_unsupported(Error **errp)
+{
+    error_setg(errp, "Virtio is disabled");
+    return NULL;
+}
+
+VirtioInfoList *qmp_x_query_virtio(Error **errp)
+{
+    return qmp_virtio_unsupported(errp);
+}
hw/virtio/virtio.c +27 -0
index 7050bd5..aad554b 100644
@@ -13,6 +13,8 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qapi/qapi-commands-virtio.h"
+#include "qapi/qapi-visit-virtio.h"
 #include "cpu.h"
 #include "trace.h"
 #include "qemu/error-report.h"
@@ -29,6 +31,9 @@
 #include "sysemu/runstate.h"
 #include "standard-headers/linux/virtio_ids.h"
 
+/* QAPI list of 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
@@ -3709,6 +3714,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)
@@ -3723,6 +3729,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;
 }
@@ -3896,6 +3903,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)
@@ -3906,6 +3915,24 @@ 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);
+        node = g_new0(VirtioInfoList, 1);
+        node->value = g_new(VirtioInfo, 1);
+        node->value->path = g_strdup(dev->canonical_path);
+        node->value->type = g_strdup(vdev->name);
+        QAPI_LIST_PREPEND(list, node->value);
+    }
+
+    return list;
+}
+
 static const TypeInfo virtio_device_info = {
     .name = TYPE_VIRTIO_DEVICE,
     .parent = TYPE_DEVICE,
include/hw/virtio/virtio.h +1 -0
index 105b98c..eceaafc 100644
@@ -110,6 +110,7 @@ struct VirtIODevice
     bool use_guest_notifier_mask;
     AddressSpace *dma_as;
     QLIST_HEAD(, VirtQueue) *vector_queues;
+    QTAILQ_ENTRY(VirtIODevice) next;
 };
 
 struct VirtioDeviceClass {
qapi/meson.build +1 -0
index c0c49c1..e332f28 100644
@@ -48,6 +48,7 @@ qapi_all_modules = [
   'sockets',
   'trace',
   'transaction',
+  'virtio',
   'yank',
 ]
 if have_system
qapi/qapi-schema.json +1 -0
index 4912b97..1512ada 100644
@@ -93,3 +93,4 @@
 { 'include': 'audio.json' }
 { 'include': 'acpi.json' }
 { 'include': 'pci.json' }
+{ 'include': 'virtio.json' }
qapi/virtio.json new file +55 -0

55 lines not on this page · raw message

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

Re: [PATCH v9 3/8] qmp: add QMP command x-query-virtio

Quoted 6 lines · Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command lists all the instances of VirtIODevice with their QOM paths and virtio type/name.

[...]

Quoted 23 lines
qapi/qapi-schema.json +1 -0
index 4912b97..1512ada 100644
@@ -93,3 +93,4 @@
 { 'include': 'audio.json' }
 { 'include': 'acpi.json' }
 { 'include': 'pci.json' }
+{ 'include': 'virtio.json' }
qapi/virtio.json new file +8 -0
new file mode 100644
index 0000000..324ba8c
@@ -0,0 +1,55 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+#
+
+##
+# = Virtio devices
+##
+

qapi/virtio.json line 18

Quoted 10 lines
qapi/virtio.json new file +10 -0
+##
+# @VirtioInfo:
+#
+# Basic information about a given VirtIODevice
+#
+# @path: the device's canonical QOM path
+#
+# @type: VirtIO device name
+#
+# Since: 6.3

I expect the next release to be numbered 7.0.

Quoted 22 lines
qapi/virtio.json new file +22 -0
+#
+##
+{ 'struct': 'VirtioInfo',
+  'data': { 'path': 'str',
+            'type': 'str' } }
+
+##
+# @x-query-virtio:
+#
+# Returns a list of all realized VirtIO devices
+#
+# Features:
+# @unstable: This command is meant for debugging.
+#
+# Returns: list of gathered @VirtioInfo devices
+#
+# Since: 6.3
+#
+# Example:
+#
+# -> { "execute": "x-query-virtio" }
+# <- { "return": [ { "path": "/machine/peripheral-anon/device[4]/virtio-backend",

qapi/virtio.json line 50

Quoted 10 lines
qapi/virtio.json new file +10 -0
+#                    "type": "virtio-input" },
+#                  { "path": "/machine/peripheral/crypto0/virtio-backend",
+#                    "type": "virtio-crypto" },
+#                  { "path": "/machine/peripheral-anon/device[2]/virtio-backend",
+#                    "type": "virtio-scsi" },
+#                  { "path": "/machine/peripheral-anon/device[1]/virtio-backend",
+#                    "type": "virtio-net" },
+#                  { "path": "/machine/peripheral-anon/device[0]/virtio-backend",
+#                    "type": "virtio-serial" }
+#                ] }

Any particular reason for reformatting the example? For what it's worth, I'd prefer the previous version.

Aside: consistent formatting of examples would be nice. Not in this series.

Quoted 17 lines
qapi/virtio.json new file +5 -0
+#
+##
+
+{ 'command': 'x-query-virtio', 'returns': ['VirtioInfo'],
+  'features': [ 'unstable' ] }
tests/qtest/qmp-cmd-test.c +1 -0
index 7f103ea..fd00ee2 100644
@@ -103,6 +103,7 @@ static bool query_is_ignored(const char *cmd)
         "query-gic-capabilities", /* arm */
         /* Success depends on target-specific build configuration: */
         "query-pci",              /* CONFIG_PCI */
+        "x-query-virtio",         /* CONFIG_VIRTIO */
         /* Success depends on launching SEV guest */
         "query-sev-launch-measure",
         /* Success depends on Host or Hypervisor SEV support */
#5 lore raw

Re: [PATCH v9 3/8] qmp: add QMP command x-query-virtio

Quoted 36 lines · Markus Armbruster
Quoted 6 lines · Jonah Palmer

From: Laurent Vivier<[email protected]>

This new command lists all the instances of VirtIODevice with their QOM paths and virtio type/name.

[...]

Quoted 26 lines
qapi/qapi-schema.json +1 -0
index 4912b97..1512ada 100644
@@ -93,3 +93,4 @@
  { 'include': 'audio.json' }
  { 'include': 'acpi.json' }
  { 'include': 'pci.json' }
+{ 'include': 'virtio.json' }
qapi/virtio.json new file +11 -0
new file mode 100644
index 0000000..324ba8c
@@ -0,0 +1,55 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+#
+
+##
+# = Virtio devices
+##
+
+##
+# @VirtioInfo:
+#
Quoted 8 lines

qapi/virtio.json line 18

Quoted 7 lines
qapi/virtio.json new file +7 -0
+# Basic information about a given VirtIODevice
+#
+# @path: the device's canonical QOM path
+#
+# @type: VirtIO device name
+#
+# Since: 6.3

I expect the next release to be numbered 7.0.

Got it. I'll update this for next series.

Quoted 36 lines
Quoted 23 lines
qapi/virtio.json new file +22 -0
+#
+##
+{ 'struct': 'VirtioInfo',
+  'data': { 'path': 'str',
+            'type': 'str' } }
+
+##
+# @x-query-virtio:
+#
+# Returns a list of all realized VirtIO devices
+#
+# Features:
+# @unstable: This command is meant for debugging.
+#
+# Returns: list of gathered @VirtioInfo devices
+#
+# Since: 6.3
+#
+# Example:
+#
+# -> { "execute": "x-query-virtio" }
+# <- { "return": [ { "path": "/machine/peripheral-anon/device[4]/virtio-backend",

qapi/virtio.json line 50

Quoted 10 lines
qapi/virtio.json new file +10 -0
+#                    "type": "virtio-input" },
+#                  { "path": "/machine/peripheral/crypto0/virtio-backend",
+#                    "type": "virtio-crypto" },
+#                  { "path": "/machine/peripheral-anon/device[2]/virtio-backend",
+#                    "type": "virtio-scsi" },
+#                  { "path": "/machine/peripheral-anon/device[1]/virtio-backend",
+#                    "type": "virtio-net" },
+#                  { "path": "/machine/peripheral-anon/device[0]/virtio-backend",
+#                    "type": "virtio-serial" }
+#                ] }

Any particular reason for reformatting the example? For what it's worth, I'd prefer the previous version.

Quoted 2 lines

Aside: consistent formatting of examples would be nice. Not in this series.

I think I got a little too excited reformatting. I'll revert the examples back to their original format and make sure the rest of the examples throughout the entire series are consistent with each other.

Quoted 18 lines
Quoted 18 lines
qapi/virtio.json new file +5 -0
+#
+##
+
+{ 'command': 'x-query-virtio', 'returns': ['VirtioInfo'],
+  'features': [ 'unstable' ] }
tests/qtest/qmp-cmd-test.c +1 -0
index 7f103ea..fd00ee2 100644
@@ -103,6 +103,7 @@ static bool query_is_ignored(const char *cmd)
          "query-gic-capabilities", /* arm */
          /* Success depends on target-specific build configuration: */
          "query-pci",              /* CONFIG_PCI */
+        "x-query-virtio",         /* CONFIG_VIRTIO */
          /* Success depends on launching SEV guest */
          "query-sev-launch-measure",
          /* Success depends on Host or Hypervisor SEV support */
#6 lore raw

PATCH v9 4/8 qmp: add QMP command x-query-virtio-status

In reply to Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command shows the status of a VirtIODevice, including its corresponding vhost device 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.

Next patch will also suppress the vhost device field from displaying if no vhost device is active for a given VirtIODevice.

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

102 lines not on this page · raw message

qapi/virtio.json +246 -0

249 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#7 lore raw

Re: [PATCH v9 4/8] qmp: add QMP command x-query-virtio-status

Quoted 13 lines · Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command shows the status of a VirtIODevice, including its corresponding vhost device 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.

Next patch will also suppress the vhost device field from displaying if no vhost device is active for a given VirtIODevice.

[...]

Quoted 244 lines
qapi/virtio.json +236 -0
index 324ba8c..54212f2 100644
@@ -53,3 +53,249 @@
 
 { 'command': 'x-query-virtio', 'returns': ['VirtioInfo'],
   'features': [ 'unstable' ] }
+
+##
+# @VirtioStatusEndianness:
+#
+# Enumeration of endianness for VirtioDevice
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioStatusEndianness',
+  'data': [ 'unknown', 'little', 'big' ]
+}
+
+##
+# @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. This is the number of virtqueues being used
+#        by the vhost device.
+#
+# @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: 6.3
+#
+##
+
+{ '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 (e.g. DRIVER_OK,
+#          FEATURES_OK, DRIVER, etc.)
+#
+# @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
+#
+# Since: 6.3
+#
+##
+
+{ 'struct': 'VirtioStatus',
+  'data': { 'name': 'str',
+            'device-id': 'uint16',
+            'vhost-started': 'bool',
+            'guest-features': 'uint64',
+            'host-features': 'uint64',
+            'backend-features': 'uint64',
+            'device-endian': 'VirtioStatusEndianness',
+            '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: 6.3
+#
+# 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,
+#          "vhost-dev": {
+#               "n-tmp-sections": 0,
+#               "n-mem-sections": 0,
+#               "max-queues": 0,
+#               "backend-cap": 0,
+#               "log-size": 0,
+#               "backend-features": 0,
+#               "nvqs": 0,
+#               "protocol-features": 0,
+#               "vq-index": 0,
+#               "log-enabled": false,
+#               "acked-features": 0,
+#               "features": 0
+#          },
+#          "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,

qapi/virtio.json line 301

Quoted 10 lines
qapi/virtio.json +10 -0
+#          "disabled": false,
+#          "vhost-started": true,
+#          "use-started": true
+#      }
+#    }
+#
+##
+
+{ 'command': 'x-query-virtio-status', 'data': { 'path': 'str' },
+  'returns': 'VirtioStatus', 'features': [ 'unstable' ] }

There's precedence for this style, but I find

{ 'command': 'x-query-virtio-status',

     'data': { 'path': 'str' },
     'returns': 'VirtioStatus',
     'features': [ 'unstable' ] }

easier to read.

#8 lore raw

Re: [PATCH v9 4/8] qmp: add QMP command x-query-virtio-status

Quoted 273 lines · Markus Armbruster
Quoted 13 lines · Jonah Palmer

From: Laurent Vivier<[email protected]>

This new command shows the status of a VirtIODevice, including its corresponding vhost device 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.

Next patch will also suppress the vhost device field from displaying if no vhost device is active for a given VirtIODevice.

[...]

Quoted 244 lines
qapi/virtio.json +236 -0
index 324ba8c..54212f2 100644
@@ -53,3 +53,249 @@
 
  { 'command': 'x-query-virtio', 'returns': ['VirtioInfo'],
    'features': [ 'unstable' ] }
+
+##
+# @VirtioStatusEndianness:
+#
+# Enumeration of endianness for VirtioDevice
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioStatusEndianness',
+  'data': [ 'unknown', 'little', 'big' ]
+}
+
+##
+# @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. This is the number of virtqueues being used
+#        by the vhost device.
+#
+# @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: 6.3
+#
+##
+
+{ '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 (e.g. DRIVER_OK,
+#          FEATURES_OK, DRIVER, etc.)
+#
+# @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
+#
+# Since: 6.3
+#
+##
+
+{ 'struct': 'VirtioStatus',
+  'data': { 'name': 'str',
+            'device-id': 'uint16',
+            'vhost-started': 'bool',
+            'guest-features': 'uint64',
+            'host-features': 'uint64',
+            'backend-features': 'uint64',
+            'device-endian': 'VirtioStatusEndianness',
+            '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: 6.3
+#
+# 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,
+#          "vhost-dev": {
+#               "n-tmp-sections": 0,
+#               "n-mem-sections": 0,
+#               "max-queues": 0,
+#               "backend-cap": 0,
+#               "log-size": 0,
+#               "backend-features": 0,
+#               "nvqs": 0,
+#               "protocol-features": 0,
+#               "vq-index": 0,
+#               "log-enabled": false,
+#               "acked-features": 0,
+#               "features": 0
+#          },
+#          "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,

qapi/virtio.json line 301

Quoted 10 lines
qapi/virtio.json +10 -0
+#          "disabled": false,
+#          "vhost-started": true,
+#          "use-started": true
+#      }
+#    }
+#
+##
+
+{ 'command': 'x-query-virtio-status', 'data': { 'path': 'str' },
+  'returns': 'VirtioStatus', 'features': [ 'unstable' ] }

There's precedence for this style, but I find

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

easier to read.

I agree. I will format all QMP commands like so in the next series.

Jonah

Quoted 1 line
#9 lore raw

PATCH v9 5/8 qmp: decode feature & status bits in virtio-status

In reply to Jonah Palmer

From: Laurent Vivier <[email protected]>

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

Display status names instead of bitmaps for VirtIODevice.

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

Decode features according to device type. Decode status 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. Vhost device field wont show if there's no vhost active for a given VirtIODevice.

---
 hw/block/virtio-blk.c          |  28 ++
 hw/char/virtio-serial-bus.c    |  11 +
 hw/display/virtio-gpu-base.c   |  18 +-
 hw/input/virtio-input.c        |  11 +-
 hw/net/virtio-net.c            |  47 ++++
 hw/scsi/virtio-scsi.c          |  17 ++
 hw/virtio/vhost-user-fs.c      |  10 +
 hw/virtio/vhost-vsock-common.c |  10 +
 hw/virtio/virtio-balloon.c     |  14 +
 hw/virtio/virtio-crypto.c      |  10 +
 hw/virtio/virtio-iommu.c       |  14 +
 hw/virtio/virtio-mem.c         |  11 +
 hw/virtio/virtio.c             | 278 +++++++++++++++++++-
 include/hw/virtio/vhost.h      |   3 +
 include/hw/virtio/virtio.h     |  18 ++
 qapi/virtio.json               | 580 ++++++++++++++++++++++++++++++++++++++---
 16 files changed, 1035 insertions(+), 45 deletions(-)
hw/block/virtio-blk.c +28 -0
index 505e574..c2e901f 100644
@@ -13,6 +13,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qapi/qapi-visit-virtio.h"
 #include "qemu/iov.h"
 #include "qemu/module.h"
 #include "qemu/error-report.h"
@@ -32,6 +33,7 @@
 #include "hw/virtio/virtio-bus.h"
 #include "migration/qemu-file-types.h"
 #include "hw/virtio/virtio-access.h"
+#include "standard-headers/linux/vhost_types.h"
 
 /* Config size before the discard support (hide associated config fields) */
 #define VIRTIO_BLK_CFG_SIZE offsetof(struct virtio_blk_config, \
@@ -48,6 +50,32 @@ static const VirtIOFeature feature_sizes[] = {
     {}
 };
 
+qmp_virtio_feature_map_t blk_map[] = {
+#define FEATURE_ENTRY(name) \
+    { VIRTIO_BLK_F_##name, VIRTIO_BLK_FEATURE_##name }
+    FEATURE_ENTRY(SIZE_MAX),
+    FEATURE_ENTRY(SEG_MAX),
+    FEATURE_ENTRY(GEOMETRY),
+    FEATURE_ENTRY(RO),
+    FEATURE_ENTRY(BLK_SIZE),
+    FEATURE_ENTRY(TOPOLOGY),
+    FEATURE_ENTRY(MQ),
+    FEATURE_ENTRY(DISCARD),
+    FEATURE_ENTRY(WRITE_ZEROES),
+#ifndef VIRTIO_BLK_NO_LEGACY
+    FEATURE_ENTRY(BARRIER),
+    FEATURE_ENTRY(SCSI),
+    FEATURE_ENTRY(FLUSH),
+    FEATURE_ENTRY(CONFIG_WCE),
+#endif /* !VIRTIO_BLK_NO_LEGACY */
+#undef FEATURE_ENTRY
+#define FEATURE_ENTRY(name) \
+    { VHOST_F_##name, VIRTIO_BLK_FEATURE_##name }
+    FEATURE_ENTRY(LOG_ALL),
+#undef FEATURE_ENTRY
+    { -1, -1 }
+};
+
 static void virtio_blk_set_config_size(VirtIOBlock *s, uint64_t host_features)
 {
     s->config_size = MAX(VIRTIO_BLK_CFG_SIZE,
hw/char/virtio-serial-bus.c +11 -0
index 232f4c9..fa57059 100644
@@ -20,6 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qapi/qapi-visit-virtio.h"
 #include "qemu/iov.h"
 #include "qemu/main-loop.h"
 #include "qemu/module.h"
@@ -32,6 +33,16 @@
 #include "hw/virtio/virtio-serial.h"
 #include "hw/virtio/virtio-access.h"
 
+qmp_virtio_feature_map_t serial_map[] = {
+#define FEATURE_ENTRY(name) \
+    { VIRTIO_CONSOLE_F_##name, VIRTIO_SERIAL_FEATURE_##name }
+    FEATURE_ENTRY(SIZE),
+    FEATURE_ENTRY(MULTIPORT),
+    FEATURE_ENTRY(EMERG_WRITE),
+#undef FEATURE_ENTRY
+    { -1, -1 }
+};
+
 static struct VirtIOSerialDevices {
     QLIST_HEAD(, VirtIOSerial) devices;
 } vserdevices;
hw/display/virtio-gpu-base.c +17 -1
index 5411a7b..a322349 100644
@@ -12,13 +12,29 @@
  */
 
 #include "qemu/osdep.h"
-
+#include "standard-headers/linux/vhost_types.h"
 #include "hw/virtio/virtio-gpu.h"
 #include "migration/blocker.h"
 #include "qapi/error.h"
+#include "qapi/qapi-visit-virtio.h"
 #include "qemu/error-report.h"
 #include "trace.h"
 
+qmp_virtio_feature_map_t gpu_map[] = {
+#define FEATURE_ENTRY(name) \
+    { VIRTIO_GPU_F_##name, VIRTIO_GPU_FEATURE_##name }
+    FEATURE_ENTRY(VIRGL),
+    FEATURE_ENTRY(EDID),
+    FEATURE_ENTRY(RESOURCE_UUID),
+    FEATURE_ENTRY(RESOURCE_BLOB),
+#undef FEATURE_ENTRY
+#define FEATURE_ENTRY(name) \
+    { VHOST_F_##name, VIRTIO_GPU_FEATURE_##name }
+    FEATURE_ENTRY(LOG_ALL),
+#undef FEATURE_ENTRY
+    { -1, -1 }
+};
+
 void
 virtio_gpu_base_reset(VirtIOGPUBase *g)
 {
hw/input/virtio-input.c +10 -1
index 5b5398b..b4562a3 100644
@@ -6,6 +6,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qapi/qapi-visit-virtio.h"
 #include "qemu/iov.h"
 #include "qemu/module.h"
 #include "trace.h"
@@ -13,11 +14,19 @@
 #include "hw/virtio/virtio.h"
 #include "hw/qdev-properties.h"
 #include "hw/virtio/virtio-input.h"
-
+#include "standard-headers/linux/vhost_types.h"
 #include "standard-headers/linux/input.h"
 
 #define VIRTIO_INPUT_VM_VERSION 1
 
+qmp_virtio_feature_map_t input_map[] = {
+#define FEATURE_ENTRY(name) \
+    { VHOST_F_##name, VIRTIO_INPUT_FEATURE_##name }
+    FEATURE_ENTRY(LOG_ALL),
+#undef FEATURE_ENTRY
+    { -1, -1 }
+};
+
 /* ----------------------------------------------------------------- */
 
 void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event)
hw/net/virtio-net.c +47 -0

62 lines not on this page · raw message

hw/scsi/virtio-scsi.c +17 -0
index ce71939..9a62d6e 100644
@@ -15,7 +15,9 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qapi/qapi-visit-virtio.h"
 #include "standard-headers/linux/virtio_ids.h"
+#include "standard-headers/linux/vhost_types.h"
 #include "hw/virtio/virtio-scsi.h"
 #include "migration/qemu-file-types.h"
 #include "qemu/error-report.h"
@@ -29,6 +31,21 @@
 #include "hw/virtio/virtio-access.h"
 #include "trace.h"
 
+qmp_virtio_feature_map_t scsi_map[] = {
+#define FEATURE_ENTRY(name) \
+    { VIRTIO_SCSI_F_##name, VIRTIO_SCSI_FEATURE_##name }
+    FEATURE_ENTRY(INOUT),
+    FEATURE_ENTRY(HOTPLUG),
+    FEATURE_ENTRY(CHANGE),
+    FEATURE_ENTRY(T10_PI),
+#undef FEATURE_ENTRY
+#define FEATURE_ENTRY(name) \
+    { VHOST_F_##name, VIRTIO_SCSI_FEATURE_##name }
+    FEATURE_ENTRY(LOG_ALL),
+#undef FEATURE_ENTRY
+    { -1, -1 }
+};
+
 static inline int virtio_scsi_get_lun(uint8_t *lun)
 {
     return ((lun[2] << 8) | lun[3]) & 0x3FFF;
hw/virtio/vhost-user-fs.c +10 -0
index e513e4f..092c3fa 100644
@@ -15,6 +15,7 @@
 #include <sys/ioctl.h>
 #include "standard-headers/linux/virtio_fs.h"
 #include "qapi/error.h"
+#include "qapi/qapi-visit-virtio.h"
 #include "hw/qdev-properties.h"
 #include "hw/qdev-properties-system.h"
 #include "hw/virtio/virtio-bus.h"
@@ -23,6 +24,15 @@
 #include "hw/virtio/vhost-user-fs.h"
 #include "monitor/monitor.h"
 #include "sysemu/sysemu.h"
+#include "standard-headers/linux/vhost_types.h"
+
+qmp_virtio_feature_map_t fs_map[] = {
+#define FEATURE_ENTRY(name) \
+    { VHOST_F_##name, VHOST_USER_FS_FEATURE_##name }
+    FEATURE_ENTRY(LOG_ALL),
+#undef FEATURE_ENTRY
+    { -1, -1 }
+};
 
 static const int user_feature_bits[] = {
     VIRTIO_F_VERSION_1,
hw/virtio/vhost-vsock-common.c +10 -0
index 665a0df..32feb69 100644
@@ -11,12 +11,22 @@
 #include "qemu/osdep.h"
 #include "standard-headers/linux/virtio_vsock.h"
 #include "qapi/error.h"
+#include "qapi/qapi-visit-virtio.h"
 #include "hw/virtio/virtio-access.h"
 #include "qemu/error-report.h"
 #include "hw/qdev-properties.h"
 #include "hw/virtio/vhost-vsock.h"
 #include "qemu/iov.h"
 #include "monitor/monitor.h"
+#include "standard-headers/linux/vhost_types.h"
+
+qmp_virtio_feature_map_t vsock_map[] = {
+#define FEATURE_ENTRY(name) \
+    { VHOST_F_##name, VHOST_VSOCK_FEATURE_##name }
+    FEATURE_ENTRY(LOG_ALL),
+#undef FEATURE_ENTRY
+    { -1, -1 }
+};
 
 const int feature_bits[] = {
     VIRTIO_VSOCK_F_SEQPACKET,
hw/virtio/virtio-balloon.c +14 -0
index 641a394..532016c 100644
@@ -27,6 +27,7 @@
 #include "qapi/error.h"
 #include "qapi/qapi-events-machine.h"
 #include "qapi/visitor.h"
+#include "qapi/qapi-visit-virtio.h"
 #include "trace.h"
 #include "qemu/error-report.h"
 #include "migration/misc.h"
@@ -37,6 +38,19 @@
 
 #define BALLOON_PAGE_SIZE  (1 << VIRTIO_BALLOON_PFN_SHIFT)
 
+qmp_virtio_feature_map_t balloon_map[] = {
+#define FEATURE_ENTRY(name) \
+    { VIRTIO_BALLOON_F_##name, VIRTIO_BALLOON_FEATURE_##name }
+    FEATURE_ENTRY(MUST_TELL_HOST),
+    FEATURE_ENTRY(STATS_VQ),
+    FEATURE_ENTRY(DEFLATE_ON_OOM),
+    FEATURE_ENTRY(FREE_PAGE_HINT),
+    FEATURE_ENTRY(PAGE_POISON),
+    FEATURE_ENTRY(REPORTING),
+#undef FEATURE_ENTRY
+    { -1, -1 }
+};
+
 typedef struct PartiallyBalloonedPage {
     ram_addr_t base_gpa;
     unsigned long *bitmap;
hw/virtio/virtio-crypto.c +10 -0
index 7d63b8c..f626ba8 100644
@@ -16,6 +16,7 @@
 #include "qemu/main-loop.h"
 #include "qemu/module.h"
 #include "qapi/error.h"
+#include "qapi/qapi-visit-virtio.h"
 #include "qemu/error-report.h"
 
 #include "hw/virtio/virtio.h"
@@ -23,10 +24,19 @@
 #include "hw/qdev-properties.h"
 #include "hw/virtio/virtio-access.h"
 #include "standard-headers/linux/virtio_ids.h"
+#include "standard-headers/linux/vhost_types.h"
 #include "sysemu/cryptodev-vhost.h"
 
 #define VIRTIO_CRYPTO_VM_VERSION 1
 
+qmp_virtio_feature_map_t crypto_map[] = {
+#define FEATURE_ENTRY(name) \
+    { VHOST_F_##name, VIRTIO_CRYPTO_FEATURE_##name }
+    FEATURE_ENTRY(LOG_ALL),
+#undef FEATURE_ENTRY
+    { -1, -1 }
+};
+
 /*
  * Transfer virtqueue index to crypto queue index.
  * The control virtqueue is after the data virtqueues
hw/virtio/virtio-iommu.c +14 -0
index 92c5eb7..9a09293 100644
@@ -25,6 +25,7 @@
 #include "hw/virtio/virtio.h"
 #include "sysemu/kvm.h"
 #include "qapi/error.h"
+#include "qapi/qapi-visit-virtio.h"
 #include "qemu/error-report.h"
 #include "trace.h"
 
@@ -40,6 +41,19 @@
 #define VIOMMU_DEFAULT_QUEUE_SIZE 256
 #define VIOMMU_PROBE_SIZE 512
 
+qmp_virtio_feature_map_t iommu_map[] = {
+#define FEATURE_ENTRY(name) \
+    { VIRTIO_IOMMU_F_##name, VIRTIO_IOMMU_FEATURE_##name }
+    FEATURE_ENTRY(INPUT_RANGE),
+    FEATURE_ENTRY(DOMAIN_RANGE),
+    FEATURE_ENTRY(MAP_UNMAP),
+    FEATURE_ENTRY(BYPASS),
+    FEATURE_ENTRY(PROBE),
+    FEATURE_ENTRY(MMIO),
+#undef FEATURE_ENTRY
+    { -1, -1 }
+};
+
 typedef struct VirtIOIOMMUDomain {
     uint32_t id;
     GTree *mappings;
hw/virtio/virtio-mem.c +11 -0
index e217520..eb62104 100644
@@ -25,6 +25,7 @@
 #include "hw/virtio/virtio-mem.h"
 #include "qapi/error.h"
 #include "qapi/visitor.h"
+#include "qapi/qapi-visit-virtio.h"
 #include "exec/ram_addr.h"
 #include "migration/misc.h"
 #include "hw/boards.h"
@@ -46,6 +47,16 @@
 #define VIRTIO_MEM_DEFAULT_THP_SIZE VIRTIO_MEM_MIN_BLOCK_SIZE
 #endif
 
+qmp_virtio_feature_map_t mem_map[] = {
+#define FEATURE_ENTRY(name) \
+    { VIRTIO_MEM_F_##name, VIRTIO_MEM_FEATURE_##name  }
+#ifndef CONFIG_ACPI
+    FEATURE_ENTRY(ACPI_PXM),
+#endif /* CONFIG_ACPI */
+#undef FEATURE_ENTRY
+    { -1, -1  }
+};
+
 /*
  * We want to have a reasonable default block size such that
  * 1. We avoid splitting THPs when unplugging memory, which degrades
hw/virtio/virtio.c +269 -9

319 lines not on this page · raw message

include/hw/virtio/vhost.h +3 -0
index 3fa0b55..2c34cff 100644
@@ -5,6 +5,9 @@
 #include "hw/virtio/virtio.h"
 #include "exec/memory.h"
 
+#define VHOST_F_DEVICE_IOTLB 63
+#define VHOST_USER_F_PROTOCOL_FEATURES 30
+
 /* Generic structures common for any vhost based device. */
 
 struct vhost_inflight {
include/hw/virtio/virtio.h +18 -0
index eceaafc..b5f9c95 100644
@@ -71,6 +71,24 @@ typedef struct VirtQueueElement
 #define TYPE_VIRTIO_DEVICE "virtio-device"
 OBJECT_DECLARE_TYPE(VirtIODevice, VirtioDeviceClass, VIRTIO_DEVICE)
 
+typedef struct {
+    int virtio_bit;
+    int qapi_virtio_enum;
+} qmp_virtio_feature_map_t;
+
+extern qmp_virtio_feature_map_t serial_map[];
+extern qmp_virtio_feature_map_t blk_map[];
+extern qmp_virtio_feature_map_t gpu_map[];
+extern qmp_virtio_feature_map_t net_map[];
+extern qmp_virtio_feature_map_t scsi_map[];
+extern qmp_virtio_feature_map_t balloon_map[];
+extern qmp_virtio_feature_map_t iommu_map[];
+extern qmp_virtio_feature_map_t input_map[];
+extern qmp_virtio_feature_map_t fs_map[];
+extern qmp_virtio_feature_map_t vsock_map[];
+extern qmp_virtio_feature_map_t crypto_map[];
+extern qmp_virtio_feature_map_t mem_map[];
+
 enum virtio_device_endian {
     VIRTIO_DEVICE_ENDIAN_UNKNOWN,
     VIRTIO_DEVICE_ENDIAN_LITTLE,
qapi/virtio.json +546 -34

631 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#10 lore raw

Re: [PATCH v9 5/8] qmp: decode feature & status bits in virtio-status

Quoted 20 lines · Jonah Palmer

From: Laurent Vivier <[email protected]>

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

Display status names instead of bitmaps for VirtIODevice.

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

Decode features according to device type. Decode status 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. Vhost device field wont show if there's no vhost active for a given VirtIODevice.

[...]

Quoted 40 lines
qapi/virtio.json +32 -0
index 54212f2..6b11d52 100644
@@ -67,6 +67,466 @@
 }
 
 ##
+# @VirtioType:
+#
+# An enumeration of Virtio device types (or names)
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioType',
+  'data': [ 'virtio-net', 'virtio-blk', 'virtio-serial', 'virtio-rng',
+            'virtio-balloon', 'virtio-iomem', 'virtio-rpmsg',
+            'virtio-scsi', 'virtio-9p', 'virtio-mac-wlan',
+            'virtio-rproc-serial', 'virtio-caif', 'virtio-mem-balloon',
+            'virtio-gpu', 'virtio-clk', 'virtio-input', 'vhost-vsock',
+            'virtio-crypto', 'virtio-signal', 'virtio-pstore',
+            'virtio-iommu', 'virtio-mem', 'virtio-sound', 'vhost-user-fs',
+            'virtio-pmem', 'virtio-mac-hwsim', 'vhost-user-i2c',
+            'virtio-bluetooth' ]
+}
+
+##
+# @VirtioConfigStatus:
+#
+# An enumeration of Virtio device configuration statuses
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioConfigStatus',
+  'data': [ 'driver-ok', 'features-ok', 'driver', 'needs-reset',
+            'failed', 'acknowledge' ]
+}
+

qapi/virtio.json line 111

Quoted 10 lines
qapi/virtio.json +10 -0
+##
+# @VirtioDeviceStatus:
+#
+# A structure defined to list the configuration statuses of a virtio
+# device
+#
+# @dev-status: List of decoded configuration statuses of the virtio
+#              device
+#
+# @unknown-statuses: virtio device statuses bitmap that have not been decoded

Why is @dev-status singular, and @unknown-statuses plural?

Quoted 25 lines
qapi/virtio.json +25 -0
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceStatus',
+  'data': { 'dev-status': [ 'VirtioConfigStatus' ],
+            '*unknown-statuses': 'uint8' } }
+
+##
+# @VhostProtocolFeature:
+#
+# An enumeration of Vhost User protocol features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VhostProtocolFeature',
+  'data': [ 'mq', 'log-shmfd', 'rarp', 'reply-ack', 'net-mtu',
+            'slave-req', 'cross-endian', 'crypto-session', 'pagefault',
+            'config', 'slave-send-fd', 'host-notifier',
+            'inflight-shmfd', 'reset-device', 'inband-notifications',
+            'configure-mem-slots' ]
+}
+
+##

qapi/virtio.json line 146

Quoted 10 lines
qapi/virtio.json +10 -0
+# @VhostDeviceProtocols:
+#
+# A structure defined to list the vhost user protocol features of a
+# Vhost User device
+#
+# @features: 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

Why are the known protocol features called @features, and the unknown ones @unknown-protocols?

Quoted 125 lines
qapi/virtio.json +125 -0
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VhostDeviceProtocols',
+  'data': { 'features': [ 'VhostProtocolFeature' ],
+            '*unknown-protocols': 'uint64' } }
+
+##
+# @VirtioTransportFeature:
+#
+# An enumeration of Virtio device transport features, including virtio-ring
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioTransportFeature',
+  'data': [ 'notify-on-empty', 'any-layout', 'protocol-features',
+            'version-1', 'iommu-platform', 'ring-packed', 'order-platform',
+            'sr-iov', 'indirect-desc', 'event-idx' ]
+}
+
+##
+# @VirtioMemFeature:
+#
+# An enumeration of Virtio mem features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioMemFeature',
+  'data': [ 'acpi-pxm' ]
+}
+
+##
+# @VirtioSerialFeature:
+#
+# An enumeration of Virtio serial/console features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioSerialFeature',
+  'data': [ 'size', 'multiport', 'emerg-write' ]
+}
+
+##
+# @VirtioBlkFeature:
+#
+# An enumeration of Virtio block features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioBlkFeature',
+  'data': [ 'size-max', 'seg-max', 'geometry', 'ro', 'blk-size',
+            'topology', 'mq', 'discard', 'write-zeroes', 'barrier',
+            'scsi', 'flush', 'config-wce', 'log-all' ]
+}
+
+##
+# @VirtioGpuFeature:
+#
+# An enumeration of Virtio gpu features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioGpuFeature',
+  'data': [ 'virgl', 'edid', 'resource-uuid', 'resource-blob',
+            'log-all' ]
+}
+
+##
+# @VirtioNetFeature:
+#
+# An enumeration of Virtio net features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioNetFeature',
+  'data': [ 'csum', 'guest-csum', 'ctrl-guest-offloads', 'mtu', 'mac',
+            'guest-tso4', 'guest-tso6', 'guest-ecn', 'guest-ufo',
+            'host-tso4', 'host-tso6', 'host-ecn', 'host-ufo',
+            'mrg-rxbuf', 'status', 'ctrl-vq', 'ctrl-rx', 'ctrl-vlan',
+            'ctrl-rx-extra', 'guest-announce', 'mq', 'ctrl-mac-addr',
+            'hash-report', 'rss', 'rsc-ext', 'standby', 'speed-duplex',
+            'gso', 'virtio-net-hdr', 'log-all' ]
+}
+
+##
+# @VirtioScsiFeature:
+#
+# An enumeration of Virtio scsi features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioScsiFeature',
+  'data': [ 'inout', 'hotplug', 'change', 't10-pi', 'log-all' ]
+}
+
+##
+# @VirtioBalloonFeature:
+#
+# An enumeration of Virtio balloon features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioBalloonFeature',
+  'data': [ 'must-tell-host', 'stats-vq', 'deflate-on-oom',
+            'free-page-hint', 'page-poison', 'reporting' ]
+}
+
+##
+# @VirtioIommuFeature:
+#
+# An enumeration of Virtio iommu features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioIommuFeature',

qapi/virtio.json line 281

Quoted 10 lines
qapi/virtio.json +10 -0
+  'data': [ 'input-range', 'domain-range', 'map-unmap', 'bypass',
+            'probe', 'mmio' ]
+}
+
+##
+# @VirtioInputFeature:
+#
+# An enumeration of Virtio input features. Note that virtio-input
+# has no device-specific features except when its vhost is active,
+# then it may have the VHOST_F_LOG_ALL feature.

VHOST_F_LOG_ALL is talking C. Better, I think: "may have the @log-all feature. More of the same below.

Quoted 39 lines
qapi/virtio.json +39 -0
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioInputFeature',
+  'data': [ 'log-all' ]
+}
+
+##
+# @VhostUserFsFeature:
+#
+# An enumeration of vhost user FS features. Note that vhost-user-fs
+# has no device-specific features other than the vhost-common
+# VHOST_F_LOG_ALL feature.
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VhostUserFsFeature',
+  'data': [ 'log-all' ]
+}
+
+##
+# @VhostVsockFeature:
+#
+# An enumeration of vhost vsock features. Note that vhost-vsock has
+# no device-specific features other than the vhost-common
+# VHOST_F_LOG_ALL feature.
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VhostVsockFeature',
+  'data': [ 'log-all' ]
+}
+
+##
+# @VirtioCryptoFeature:
+#

qapi/virtio.json line 330

Quoted 10 lines
qapi/virtio.json +10 -0
+# An enumeration of virtio crypto features. Not that virtio-crypto
+# has no device-specific features other than when it is a vhost
+# device, then it may have the VHOST_F_LOG_ALL feature.
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioCryptoFeature',
+  'data': [ 'log-all' ]
+}

Four identical enum types... any particular reason against just one?

Quoted 7 lines
qapi/virtio.json +7 -0
+
+##
+# @VirtioDeviceFeaturesBase:
+#
+# The common fields that apply to all Virtio devices
+#
+# @type: virtio device name

qapi/virtio.json line 347

Quoted 10 lines
qapi/virtio.json +10 -0
+# @transport: the list of transport features of the virtio device
+# @unknown-features: virtio device features bitmap that have not been decoded
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesBase',
+  'data': { 'type': 'VirtioType',
+            'transport': [ 'VirtioTransportFeature' ],
+            '*unknown-features': 'uint64' } }

Pardon my virtio ignorance... are the @unknown-features unknown transport features?

Quoted 146 lines
qapi/virtio.json +146 -0
+
+##
+# @VirtioDeviceFeaturesOptionsMem:
+#
+# The options that apply to Virtio mem devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsMem',
+  'data': { 'features': [ 'VirtioMemFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsSerial:
+#
+# The options that apply to Virtio serial devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsSerial',
+  'data': { 'features': [ 'VirtioSerialFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsBlk:
+#
+# The options that apply to Virtio block devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsBlk',
+  'data': { 'features': [ 'VirtioBlkFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsGpu:
+#
+# The options that apply to Virtio GPU devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsGpu',
+  'data': { 'features': [ 'VirtioGpuFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsNet:
+#
+# The options that apply to Virtio net devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsNet',
+  'data': { 'features': [ 'VirtioNetFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsScsi:
+#
+# The options that apply to Virtio SCSI devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsScsi',
+  'data': { 'features': [ 'VirtioScsiFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsBalloon:
+#
+# The options that apply to Virtio balloon devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsBalloon',
+  'data': { 'features': [ 'VirtioBalloonFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsIommu:
+#
+# The options that apply to Virtio IOMMU devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsIommu',
+  'data': { 'features': [ 'VirtioIommuFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsInput:
+#
+# The options that apply to Virtio input devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsInput',
+  'data': { 'features': [ 'VirtioInputFeature' ] } }
+
+##
+# @VhostDeviceFeaturesOptionsFs:
+#
+# The options that apply to vhost-user-fs devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VhostDeviceFeaturesOptionsFs',
+  'data': { 'features': [ 'VhostUserFsFeature' ] } }
+
+##
+# @VhostDeviceFeaturesOptionsVsock:
+#
+# The options that apply to vhost-vsock devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VhostDeviceFeaturesOptionsVsock',
+  'data': { 'features': [ 'VhostVsockFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsCrypto:

qapi/virtio.json line 503

Quoted 10 lines
qapi/virtio.json +10 -0
+#
+# The options that apply to virtio-crypto devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsCrypto',
+  'data': { 'features': [ 'VirtioCryptoFeature' ] } }

If you replace the four identical enum types by one, you get four identical struct types here. Same treatment.

Quoted 189 lines
qapi/virtio.json +105 -34
+
+##
+# @VirtioDeviceFeatures:
+#
+# A union to define the list of features for a virtio device
+#
+# Since: 6.3
+##
+
+{ 'union': 'VirtioDeviceFeatures',
+  'base': 'VirtioDeviceFeaturesBase',
+  'discriminator': 'type',
+  'data': { 'virtio-serial': 'VirtioDeviceFeaturesOptionsSerial',
+            'virtio-blk': 'VirtioDeviceFeaturesOptionsBlk',
+            'virtio-gpu': 'VirtioDeviceFeaturesOptionsGpu',
+            'virtio-net': 'VirtioDeviceFeaturesOptionsNet',
+            'virtio-scsi': 'VirtioDeviceFeaturesOptionsScsi',
+            'virtio-balloon': 'VirtioDeviceFeaturesOptionsBalloon',
+            'virtio-iommu': 'VirtioDeviceFeaturesOptionsIommu',
+            'virtio-input': 'VirtioDeviceFeaturesOptionsInput',
+            'vhost-user-fs': 'VhostDeviceFeaturesOptionsFs',
+            'vhost-vsock': 'VhostDeviceFeaturesOptionsVsock',
+            'virtio-crypto': 'VirtioDeviceFeaturesOptionsCrypto',
+            'virtio-mem': 'VirtioDeviceFeaturesOptionsMem' } }
+
+##
 # @VhostStatus:
 #
 # Information about a vhost device. This information will only be
@@ -106,10 +566,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',
@@ -174,12 +634,12 @@
   'data': { 'name': 'str',
             'device-id': 'uint16',
             'vhost-started': 'bool',
-            'guest-features': 'uint64',
-            'host-features': 'uint64',
-            'backend-features': 'uint64',
+            'guest-features': 'VirtioDeviceFeatures',
+            'host-features': 'VirtioDeviceFeatures',
+            'backend-features': 'VirtioDeviceFeatures',
             'device-endian': 'VirtioStatusEndianness',
             'num-vqs': 'int',
-            'status': 'uint8',
+            'status': 'VirtioDeviceStatus',
             'isr': 'uint8',
             'queue-sel': 'uint16',
             'vm-running': 'bool',
@@ -191,7 +651,7 @@
             'disable-legacy-check': 'bool',
             'bus-name': 'str',
             'use-guest-notifier-mask': 'bool',
-            'vhost-dev': 'VhostStatus' } }
+            '*vhost-dev': 'VhostStatus' } }
 
 ##
 # @x-query-virtio-status:
@@ -221,28 +681,31 @@
 #          "name": "virtio-crypto",
 #          "started": true,
 #          "device-id": 20,
-#          "vhost-dev": {
-#               "n-tmp-sections": 0,
-#               "n-mem-sections": 0,
-#               "max-queues": 0,
-#               "backend-cap": 0,
-#               "log-size": 0,
-#               "backend-features": 0,
-#               "nvqs": 0,
-#               "protocol-features": 0,
-#               "vq-index": 0,
-#               "log-enabled": false,
-#               "acked-features": 0,
-#               "features": 0
+#          "backend-features": {
+#               "transport": [],
+#               "type": "virtio-crypto",
+#               "features": []
 #          },
-#          "backend-features": 0,
 #          "start-on-kick": false,
 #          "isr": 1,
 #          "broken": false,
-#          "status": 15,
+#          "status": {
+#               "dev-status": ["acknowledge", "driver", "features-ok",
+#                              "driver-ok"]
+#          },
 #          "num-vqs": 2,
-#          "guest-features": 5100273664,
-#          "host-features": 6325010432,
+#          "guest-features": {
+#               "transport": ["event-idx", "indirect-desc", "version-1"],
+#               "type": "virtio-crypto",
+#               "features": []
+#          },
+#          "host-features": {
+#               "transport": ["protocol-features", "event-idx",
+#                             "indirect-desc", "version-1", "any-layout",
+#                             "notify-on-empty"],
+#               "type": "virtio-crypto",
+#               "features": []
+#          },
 #          "use-guest-notifier-mask": true,
 #          "vm-running": true,
 #          "queue-sel": 1,
@@ -270,22 +733,71 @@
 #               "max-queues": 1,
 #               "backend-cap": 2,
 #               "log-size": 0,
-#               "backend-features": 0,
+#               "backend-features": {
+#                       "transport": [],
+#                       "type": "virtio-net",
+#                       "features": []
+#               },
 #               "nvqs": 2,
-#               "protocol-features": 0,
+#               "protocol-features": {
+#                       "features": []
+#               },
 #               "vq-index": 0,
 #               "log-enabled": false,
-#               "acked-features": 5100306432,
-#               "features": 13908344832
+#               "acked-features": {
+#                       "transport": ["event-idx", "indirect-desc", "version-1",
+#                                     "any-layout", "notify-on-empty"],
+#                       "type": "virtio-net",
+#                       "features": ["mrg-rxbuf"]
+#               },
+#               "features": {
+#                       "transport": ["event-idx", "indirect-desc",
+#                                     "iommu-platform", "version-1", "any-layout",
+#                                     "notify-on-empty"],
+#                       "type": "virtio-net",
+#                       "features": ["log-all", "mrg-rxbuf"]
+#               }
+#          },
+#          "backend-features": {
+#               "transport": ["protocol-features", "event-idx", "indirect-desc",
+#                             "version-1", "any-layout", "notify-on-empty"],
+#               "type": "virtio-net",
+#               "features": ["gso", "ctrl-mac-addr", "guest-announce", "ctrl-rx-extra",
+#                            "ctrl-vlan", "ctrl-rx", "ctrl-vq", "status", "mrg-rxbuf",
+#                            "host-ufo", "host-ecn", "host-tso6", "host-tso4",
+#                            "guest-ufo", "guest-ecn", "guest-tso6", "guest-tso4",
+#                            "mac", "ctrl-guest-offloads", "guest-csum", "csum"]
 #          },
-#          "backend-features": 6337593319,
 #          "start-on-kick": false,
 #          "isr": 1,
 #          "broken": false,
-#          "status": 15,
+#          "status": {
+#               "dev-status": ["acknowledge", "driver", "features-ok", "driver-ok"]
+#          },
 #          "num-vqs": 3,
-#          "guest-features": 5111807911,
-#          "host-features": 6337593319,
+#          "guest-features": {
+#               "transport": ["event-idx", "indirect-desc", "version-1"],
+#               "type": "virtio-net",
+#               "features": ["ctrl-mac-addr", "guest-announce", "ctrl-vlan",
+#                            "ctrl-rx", "ctrl-vq", "status", "mrg-rxbuf",
+#                            "host-ufo", "host-ecn", "host-tso6",
+#                            "host-tso4", "guest-ufo", "guest-ecn",
+#                            "guest-tso6", "guest-tso4", "mac",
+#                            "ctrl-guest-offloads", "guest-csum", "csum"]
+#          },
+#          "host-features": {
+#               "transport": ["protocol-features", "event-idx",
+#                             "indirect-desc", "version-1", "any-layout",
+#                             "notify-on-empty"],
+#               "type": "virtio-net",
+#               "features": ["gso", "ctrl-mac-addr", "guest-announce",

qapi/virtio.json line 803

Quoted 10 lines
qapi/virtio.json +7 -0
+#                            "ctrl-rx-extra", "ctrl-vlan", "ctrl-rx",
+#                            "ctrl-vq", "status", "mrg-rxbuf", "host-ufo",
+#                            "host-ecn", "host-tso6", "host-tso4",
+#                            "guest-ufo", "guest-ecn", "guest-tso6",
+#                            "guest-tso4", "mac", "ctrl-guest-offloads",
+#                            "guest-csum", "csum"]
+#          },
 #          "use-guest-notifier-mask": true,
 #          "vm-running": true,
 #          "queue-sel": 2,

Sixteen enums total.

If we replaced them by 'str', the schema would be simpler and the generated code smaller, but introspection would be less informative. I didn't check how the handwritten could would be affected.

It's a tradeoff. Can you make an argument either way?

#11 lore raw

Re: [PATCH v9 5/8] qmp: decode feature & status bits in virtio-status

Quoted 68 lines · Markus Armbruster
Quoted 20 lines · Jonah Palmer

From: Laurent Vivier<[email protected]>

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

Display status names instead of bitmaps for VirtIODevice.

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

Decode features according to device type. Decode status 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. Vhost device field wont show if there's no vhost active for a given VirtIODevice.

[...]

Quoted 44 lines
qapi/virtio.json +36 -0
index 54212f2..6b11d52 100644
@@ -67,6 +67,466 @@
  }
 
  ##
+# @VirtioType:
+#
+# An enumeration of Virtio device types (or names)
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioType',
+  'data': [ 'virtio-net', 'virtio-blk', 'virtio-serial', 'virtio-rng',
+            'virtio-balloon', 'virtio-iomem', 'virtio-rpmsg',
+            'virtio-scsi', 'virtio-9p', 'virtio-mac-wlan',
+            'virtio-rproc-serial', 'virtio-caif', 'virtio-mem-balloon',
+            'virtio-gpu', 'virtio-clk', 'virtio-input', 'vhost-vsock',
+            'virtio-crypto', 'virtio-signal', 'virtio-pstore',
+            'virtio-iommu', 'virtio-mem', 'virtio-sound', 'vhost-user-fs',
+            'virtio-pmem', 'virtio-mac-hwsim', 'vhost-user-i2c',
+            'virtio-bluetooth' ]
+}
+
+##
+# @VirtioConfigStatus:
+#
+# An enumeration of Virtio device configuration statuses
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioConfigStatus',
+  'data': [ 'driver-ok', 'features-ok', 'driver', 'needs-reset',
+            'failed', 'acknowledge' ]
+}
+
+##
+# @VirtioDeviceStatus:
+#
+# A structure defined to list the configuration statuses of a virtio
Quoted 8 lines

qapi/virtio.json line 111

Quoted 6 lines
qapi/virtio.json +6 -0
+# device
+#
+# @dev-status: List of decoded configuration statuses of the virtio
+#              device
+#
+# @unknown-statuses: virtio device statuses bitmap that have not been decoded

Why is @dev-status singular, and @unknown-statuses plural?

I'm guessing that when I wrote it I used singular here since it was one list of statuses, but the representation here does feel off. Maybe @statuses & @unknown-statuses would be a better choice?

Quoted 30 lines
Quoted 30 lines
qapi/virtio.json +29 -0
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceStatus',
+  'data': { 'dev-status': [ 'VirtioConfigStatus' ],
+            '*unknown-statuses': 'uint8' } }
+
+##
+# @VhostProtocolFeature:
+#
+# An enumeration of Vhost User protocol features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VhostProtocolFeature',
+  'data': [ 'mq', 'log-shmfd', 'rarp', 'reply-ack', 'net-mtu',
+            'slave-req', 'cross-endian', 'crypto-session', 'pagefault',
+            'config', 'slave-send-fd', 'host-notifier',
+            'inflight-shmfd', 'reset-device', 'inband-notifications',
+            'configure-mem-slots' ]
+}
+
+##
+# @VhostDeviceProtocols:
+#
+# A structure defined to list the vhost user protocol features of a
+# Vhost User device
Quoted 8 lines

qapi/virtio.json line 146

Quoted 6 lines
qapi/virtio.json +6 -0
+#
+# @features: 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

Why are the known protocol features called @features, and the unknown ones @unknown-protocols?

I agree that this is inconsistent. Maybe @protocols & @unknown-protocols would be a better choice here as well?

Quoted 130 lines
Quoted 130 lines
qapi/virtio.json +129 -0
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VhostDeviceProtocols',
+  'data': { 'features': [ 'VhostProtocolFeature' ],
+            '*unknown-protocols': 'uint64' } }
+
+##
+# @VirtioTransportFeature:
+#
+# An enumeration of Virtio device transport features, including virtio-ring
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioTransportFeature',
+  'data': [ 'notify-on-empty', 'any-layout', 'protocol-features',
+            'version-1', 'iommu-platform', 'ring-packed', 'order-platform',
+            'sr-iov', 'indirect-desc', 'event-idx' ]
+}
+
+##
+# @VirtioMemFeature:
+#
+# An enumeration of Virtio mem features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioMemFeature',
+  'data': [ 'acpi-pxm' ]
+}
+
+##
+# @VirtioSerialFeature:
+#
+# An enumeration of Virtio serial/console features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioSerialFeature',
+  'data': [ 'size', 'multiport', 'emerg-write' ]
+}
+
+##
+# @VirtioBlkFeature:
+#
+# An enumeration of Virtio block features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioBlkFeature',
+  'data': [ 'size-max', 'seg-max', 'geometry', 'ro', 'blk-size',
+            'topology', 'mq', 'discard', 'write-zeroes', 'barrier',
+            'scsi', 'flush', 'config-wce', 'log-all' ]
+}
+
+##
+# @VirtioGpuFeature:
+#
+# An enumeration of Virtio gpu features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioGpuFeature',
+  'data': [ 'virgl', 'edid', 'resource-uuid', 'resource-blob',
+            'log-all' ]
+}
+
+##
+# @VirtioNetFeature:
+#
+# An enumeration of Virtio net features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioNetFeature',
+  'data': [ 'csum', 'guest-csum', 'ctrl-guest-offloads', 'mtu', 'mac',
+            'guest-tso4', 'guest-tso6', 'guest-ecn', 'guest-ufo',
+            'host-tso4', 'host-tso6', 'host-ecn', 'host-ufo',
+            'mrg-rxbuf', 'status', 'ctrl-vq', 'ctrl-rx', 'ctrl-vlan',
+            'ctrl-rx-extra', 'guest-announce', 'mq', 'ctrl-mac-addr',
+            'hash-report', 'rss', 'rsc-ext', 'standby', 'speed-duplex',
+            'gso', 'virtio-net-hdr', 'log-all' ]
+}
+
+##
+# @VirtioScsiFeature:
+#
+# An enumeration of Virtio scsi features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioScsiFeature',
+  'data': [ 'inout', 'hotplug', 'change', 't10-pi', 'log-all' ]
+}
+
+##
+# @VirtioBalloonFeature:
+#
+# An enumeration of Virtio balloon features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioBalloonFeature',
+  'data': [ 'must-tell-host', 'stats-vq', 'deflate-on-oom',
+            'free-page-hint', 'page-poison', 'reporting' ]
+}
+
+##
+# @VirtioIommuFeature:
+#
+# An enumeration of Virtio iommu features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioIommuFeature',
+  'data': [ 'input-range', 'domain-range', 'map-unmap', 'bypass',
+            'probe', 'mmio' ]
+}
+
Quoted 8 lines

qapi/virtio.json line 281

Quoted 6 lines
qapi/virtio.json +6 -0
+##
+# @VirtioInputFeature:
+#
+# An enumeration of Virtio input features. Note that virtio-input
+# has no device-specific features except when its vhost is active,
+# then it may have the VHOST_F_LOG_ALL feature.

VHOST_F_LOG_ALL is talking C. Better, I think: "may have the @log-all feature. More of the same below.

Got it. Will fix this for all occurrences!

Quoted 43 lines
Quoted 43 lines
qapi/virtio.json +42 -0
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioInputFeature',
+  'data': [ 'log-all' ]
+}
+
+##
+# @VhostUserFsFeature:
+#
+# An enumeration of vhost user FS features. Note that vhost-user-fs
+# has no device-specific features other than the vhost-common
+# VHOST_F_LOG_ALL feature.
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VhostUserFsFeature',
+  'data': [ 'log-all' ]
+}
+
+##
+# @VhostVsockFeature:
+#
+# An enumeration of vhost vsock features. Note that vhost-vsock has
+# no device-specific features other than the vhost-common
+# VHOST_F_LOG_ALL feature.
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VhostVsockFeature',
+  'data': [ 'log-all' ]
+}
+
+##
+# @VirtioCryptoFeature:
+#
+# An enumeration of virtio crypto features. Not that virtio-crypto
+# has no device-specific features other than when it is a vhost
+# device, then it may have the VHOST_F_LOG_ALL feature.
Quoted 8 lines

qapi/virtio.json line 330

Quoted 7 lines
qapi/virtio.json +7 -0
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioCryptoFeature',
+  'data': [ 'log-all' ]
+}

Four identical enum types... any particular reason against just one?

See comment at the end.

Quoted 12 lines
Quoted 12 lines
qapi/virtio.json +11 -0
+
+##
+# @VirtioDeviceFeaturesBase:
+#
+# The common fields that apply to all Virtio devices
+#
+# @type: virtio device name
+# @transport: the list of transport features of the virtio device
+# @unknown-features: virtio device features bitmap that have not been decoded
+#
+# Since: 6.3
Quoted 8 lines

qapi/virtio.json line 347

Quoted 6 lines
qapi/virtio.json +6 -0
+##
+
+{ 'struct': 'VirtioDeviceFeaturesBase',
+  'data': { 'type': 'VirtioType',
+            'transport': [ 'VirtioTransportFeature' ],
+            '*unknown-features': 'uint64' } }

Pardon my virtio ignorance... are the @unknown-features unknown transport features?

Yes in this case they would be unknown transport features.

Quoted 361 lines
Quoted 147 lines
qapi/virtio.json +146 -0
+
+##
+# @VirtioDeviceFeaturesOptionsMem:
+#
+# The options that apply to Virtio mem devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsMem',
+  'data': { 'features': [ 'VirtioMemFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsSerial:
+#
+# The options that apply to Virtio serial devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsSerial',
+  'data': { 'features': [ 'VirtioSerialFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsBlk:
+#
+# The options that apply to Virtio block devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsBlk',
+  'data': { 'features': [ 'VirtioBlkFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsGpu:
+#
+# The options that apply to Virtio GPU devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsGpu',
+  'data': { 'features': [ 'VirtioGpuFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsNet:
+#
+# The options that apply to Virtio net devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsNet',
+  'data': { 'features': [ 'VirtioNetFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsScsi:
+#
+# The options that apply to Virtio SCSI devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsScsi',
+  'data': { 'features': [ 'VirtioScsiFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsBalloon:
+#
+# The options that apply to Virtio balloon devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsBalloon',
+  'data': { 'features': [ 'VirtioBalloonFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsIommu:
+#
+# The options that apply to Virtio IOMMU devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsIommu',
+  'data': { 'features': [ 'VirtioIommuFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsInput:
+#
+# The options that apply to Virtio input devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsInput',
+  'data': { 'features': [ 'VirtioInputFeature' ] } }
+
+##
+# @VhostDeviceFeaturesOptionsFs:
+#
+# The options that apply to vhost-user-fs devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VhostDeviceFeaturesOptionsFs',
+  'data': { 'features': [ 'VhostUserFsFeature' ] } }
+
+##
+# @VhostDeviceFeaturesOptionsVsock:
+#
+# The options that apply to vhost-vsock devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VhostDeviceFeaturesOptionsVsock',
+  'data': { 'features': [ 'VhostVsockFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsCrypto:

qapi/virtio.json line 503

Quoted 10 lines
qapi/virtio.json +10 -0
+#
+# The options that apply to virtio-crypto devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsCrypto',
+  'data': { 'features': [ 'VirtioCryptoFeature' ] } }

If you replace the four identical enum types by one, you get four identical struct types here. Same treatment.

Quoted 189 lines
qapi/virtio.json +105 -34
+
+##
+# @VirtioDeviceFeatures:
+#
+# A union to define the list of features for a virtio device
+#
+# Since: 6.3
+##
+
+{ 'union': 'VirtioDeviceFeatures',
+  'base': 'VirtioDeviceFeaturesBase',
+  'discriminator': 'type',
+  'data': { 'virtio-serial': 'VirtioDeviceFeaturesOptionsSerial',
+            'virtio-blk': 'VirtioDeviceFeaturesOptionsBlk',
+            'virtio-gpu': 'VirtioDeviceFeaturesOptionsGpu',
+            'virtio-net': 'VirtioDeviceFeaturesOptionsNet',
+            'virtio-scsi': 'VirtioDeviceFeaturesOptionsScsi',
+            'virtio-balloon': 'VirtioDeviceFeaturesOptionsBalloon',
+            'virtio-iommu': 'VirtioDeviceFeaturesOptionsIommu',
+            'virtio-input': 'VirtioDeviceFeaturesOptionsInput',
+            'vhost-user-fs': 'VhostDeviceFeaturesOptionsFs',
+            'vhost-vsock': 'VhostDeviceFeaturesOptionsVsock',
+            'virtio-crypto': 'VirtioDeviceFeaturesOptionsCrypto',
+            'virtio-mem': 'VirtioDeviceFeaturesOptionsMem' } }
+
+##
  # @VhostStatus:
  #
  # Information about a vhost device. This information will only be
@@ -106,10 +566,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',
@@ -174,12 +634,12 @@
    'data': { 'name': 'str',
              'device-id': 'uint16',
              'vhost-started': 'bool',
-            'guest-features': 'uint64',
-            'host-features': 'uint64',
-            'backend-features': 'uint64',
+            'guest-features': 'VirtioDeviceFeatures',
+            'host-features': 'VirtioDeviceFeatures',
+            'backend-features': 'VirtioDeviceFeatures',
              'device-endian': 'VirtioStatusEndianness',
              'num-vqs': 'int',
-            'status': 'uint8',
+            'status': 'VirtioDeviceStatus',
              'isr': 'uint8',
              'queue-sel': 'uint16',
              'vm-running': 'bool',
@@ -191,7 +651,7 @@
              'disable-legacy-check': 'bool',
              'bus-name': 'str',
              'use-guest-notifier-mask': 'bool',
-            'vhost-dev': 'VhostStatus' } }
+            '*vhost-dev': 'VhostStatus' } }
 
  ##
  # @x-query-virtio-status:
@@ -221,28 +681,31 @@
  #          "name": "virtio-crypto",
  #          "started": true,
  #          "device-id": 20,
-#          "vhost-dev": {
-#               "n-tmp-sections": 0,
-#               "n-mem-sections": 0,
-#               "max-queues": 0,
-#               "backend-cap": 0,
-#               "log-size": 0,
-#               "backend-features": 0,
-#               "nvqs": 0,
-#               "protocol-features": 0,
-#               "vq-index": 0,
-#               "log-enabled": false,
-#               "acked-features": 0,
-#               "features": 0
+#          "backend-features": {
+#               "transport": [],
+#               "type": "virtio-crypto",
+#               "features": []
  #          },
-#          "backend-features": 0,
  #          "start-on-kick": false,
  #          "isr": 1,
  #          "broken": false,
-#          "status": 15,
+#          "status": {
+#               "dev-status": ["acknowledge", "driver", "features-ok",
+#                              "driver-ok"]
+#          },
  #          "num-vqs": 2,
-#          "guest-features": 5100273664,
-#          "host-features": 6325010432,
+#          "guest-features": {
+#               "transport": ["event-idx", "indirect-desc", "version-1"],
+#               "type": "virtio-crypto",
+#               "features": []
+#          },
+#          "host-features": {
+#               "transport": ["protocol-features", "event-idx",
+#                             "indirect-desc", "version-1", "any-layout",
+#                             "notify-on-empty"],
+#               "type": "virtio-crypto",
+#               "features": []
+#          },
  #          "use-guest-notifier-mask": true,
  #          "vm-running": true,
  #          "queue-sel": 1,
@@ -270,22 +733,71 @@
  #               "max-queues": 1,
  #               "backend-cap": 2,
  #               "log-size": 0,
-#               "backend-features": 0,
+#               "backend-features": {
+#                       "transport": [],
+#                       "type": "virtio-net",
+#                       "features": []
+#               },
  #               "nvqs": 2,
-#               "protocol-features": 0,
+#               "protocol-features": {
+#                       "features": []
+#               },
  #               "vq-index": 0,
  #               "log-enabled": false,
-#               "acked-features": 5100306432,
-#               "features": 13908344832
+#               "acked-features": {
+#                       "transport": ["event-idx", "indirect-desc", "version-1",
+#                                     "any-layout", "notify-on-empty"],
+#                       "type": "virtio-net",
+#                       "features": ["mrg-rxbuf"]
+#               },
+#               "features": {
+#                       "transport": ["event-idx", "indirect-desc",
+#                                     "iommu-platform", "version-1", "any-layout",
+#                                     "notify-on-empty"],
+#                       "type": "virtio-net",
+#                       "features": ["log-all", "mrg-rxbuf"]
+#               }
+#          },
+#          "backend-features": {
+#               "transport": ["protocol-features", "event-idx", "indirect-desc",
+#                             "version-1", "any-layout", "notify-on-empty"],
+#               "type": "virtio-net",
+#               "features": ["gso", "ctrl-mac-addr", "guest-announce", "ctrl-rx-extra",
+#                            "ctrl-vlan", "ctrl-rx", "ctrl-vq", "status", "mrg-rxbuf",
+#                            "host-ufo", "host-ecn", "host-tso6", "host-tso4",
+#                            "guest-ufo", "guest-ecn", "guest-tso6", "guest-tso4",
+#                            "mac", "ctrl-guest-offloads", "guest-csum", "csum"]
  #          },
-#          "backend-features": 6337593319,
  #          "start-on-kick": false,
  #          "isr": 1,
  #          "broken": false,
-#          "status": 15,
+#          "status": {
+#               "dev-status": ["acknowledge", "driver", "features-ok", "driver-ok"]
+#          },
  #          "num-vqs": 3,
-#          "guest-features": 5111807911,
-#          "host-features": 6337593319,
+#          "guest-features": {
+#               "transport": ["event-idx", "indirect-desc", "version-1"],
+#               "type": "virtio-net",
+#               "features": ["ctrl-mac-addr", "guest-announce", "ctrl-vlan",
+#                            "ctrl-rx", "ctrl-vq", "status", "mrg-rxbuf",
+#                            "host-ufo", "host-ecn", "host-tso6",
+#                            "host-tso4", "guest-ufo", "guest-ecn",
+#                            "guest-tso6", "guest-tso4", "mac",
+#                            "ctrl-guest-offloads", "guest-csum", "csum"]
+#          },
+#          "host-features": {
+#               "transport": ["protocol-features", "event-idx",
+#                             "indirect-desc", "version-1", "any-layout",
+#                             "notify-on-empty"],
+#               "type": "virtio-net",
+#               "features": ["gso", "ctrl-mac-addr", "guest-announce",

qapi/virtio.json line 803

Quoted 10 lines
qapi/virtio.json +7 -0
+#                            "ctrl-rx-extra", "ctrl-vlan", "ctrl-rx",
+#                            "ctrl-vq", "status", "mrg-rxbuf", "host-ufo",
+#                            "host-ecn", "host-tso6", "host-tso4",
+#                            "guest-ufo", "guest-ecn", "guest-tso6",
+#                            "guest-tso4", "mac", "ctrl-guest-offloads",
+#                            "guest-csum", "csum"]
+#          },
  #          "use-guest-notifier-mask": true,
  #          "vm-running": true,
  #          "queue-sel": 2,

Sixteen enums total.

Quoted 5 lines

If we replaced them by 'str', the schema would be simpler and the generated code smaller, but introspection would be less informative. I didn't check how the handwritten could would be affected.

It's a tradeoff. Can you make an argument either way?

I would make the argument for keeping them as is.

One reason is that, while yes it does seem redundant, it's also a core data structure for device-specific features for this series, in a framework type of way. In other words, if / when a device gets a new feature, we would add them there.

Another reason is that the naming convention is very specific, and it should only be tied to one device type. This is because when we go to decode any features or statuses, we need to filter by device type (for the reason above) and compare that device's features bitmap to our known list of features *for that device*.

So in qmp_decode_features():

features = g_new0(VirtioDeviceFeatures, 1);
features->type = qapi_enum_parse(&VirtioType_lookup, name, -1, NULL); switch (features->type) {

case VIRTIO_TYPE_VIRTIO_SERIAL:

    features->u.virtio_serial.features =
            CONVERT_FEATURES(VirtioSerialFeatureList, serial_map, 0);
    break;

...

And sure while we could make the cases for virtio-input, vhost-user-fs, vhost-vsock, and virtio-crypto (the devices that just have the 'log-all' feature (and only in the vhost case)) homogeneous, e.g:

case VIRTIO_TYPE_VIRTIO_CRYPTO:

    features->u.devs_w_one_feature.features =
            CONVERT_FEATURES(DevsWOneFeatureList, logall_map, 0);
    break;
case VIRTIO_TYPE_VIRTIO_INPUT:
    features->u.devs_w_one_feature.features =
            CONVERT_FEATURES(DevsWOneFeatureList, logall_map, 0);
    break;

...

We would still need to create a unique enum / data structure for one of those devices if / when they get their own new feature.

Jonah

Quoted 1 line
#12 lore raw

Re: [PATCH v9 5/8] qmp: decode feature & status bits in virtio-status

Quoted 78 lines · Jonah Palmer
Quoted 68 lines · Markus Armbruster
Quoted 20 lines · Jonah Palmer

From: Laurent Vivier<[email protected]>

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

Display status names instead of bitmaps for VirtIODevice.

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

Decode features according to device type. Decode status 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. Vhost device field wont show if there's no vhost active for a given VirtIODevice.

[...]

Quoted 44 lines
qapi/virtio.json +36 -0
index 54212f2..6b11d52 100644
@@ -67,6 +67,466 @@
  }
 
 ##
+# @VirtioType:
+#
+# An enumeration of Virtio device types (or names)
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioType',
+  'data': [ 'virtio-net', 'virtio-blk', 'virtio-serial', 'virtio-rng',
+            'virtio-balloon', 'virtio-iomem', 'virtio-rpmsg',
+            'virtio-scsi', 'virtio-9p', 'virtio-mac-wlan',
+            'virtio-rproc-serial', 'virtio-caif', 'virtio-mem-balloon',
+            'virtio-gpu', 'virtio-clk', 'virtio-input', 'vhost-vsock',
+            'virtio-crypto', 'virtio-signal', 'virtio-pstore',
+            'virtio-iommu', 'virtio-mem', 'virtio-sound', 'vhost-user-fs',
+            'virtio-pmem', 'virtio-mac-hwsim', 'vhost-user-i2c',
+            'virtio-bluetooth' ]
+}
+
+##
+# @VirtioConfigStatus:
+#
+# An enumeration of Virtio device configuration statuses
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioConfigStatus',
+  'data': [ 'driver-ok', 'features-ok', 'driver', 'needs-reset',
+            'failed', 'acknowledge' ]
+}
+
+##
+# @VirtioDeviceStatus:
+#
+# A structure defined to list the configuration statuses of a virtio
Quoted 8 lines

qapi/virtio.json line 111

Quoted 6 lines
qapi/virtio.json +6 -0
+# device
+#
+# @dev-status: List of decoded configuration statuses of the virtio
+#              device
+#
+# @unknown-statuses: virtio device statuses bitmap that have not been decoded

Why is @dev-status singular, and @unknown-statuses plural?

Quoted 3 lines

I'm guessing that when I wrote it I used singular here since it was one list of statuses, but the representation here does feel off. Maybe @statuses & @unknown-statuses would be a better choice?

I figure either singular or plural would work better than using both. Beware, I'm not a native speaker.

Quoted 39 lines
Quoted 30 lines
Quoted 30 lines
qapi/virtio.json +30 -0
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceStatus',
+  'data': { 'dev-status': [ 'VirtioConfigStatus' ],
+            '*unknown-statuses': 'uint8' } }
+
+##
+# @VhostProtocolFeature:
+#
+# An enumeration of Vhost User protocol features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VhostProtocolFeature',
+  'data': [ 'mq', 'log-shmfd', 'rarp', 'reply-ack', 'net-mtu',
+            'slave-req', 'cross-endian', 'crypto-session', 'pagefault',
+            'config', 'slave-send-fd', 'host-notifier',
+            'inflight-shmfd', 'reset-device', 'inband-notifications',
+            'configure-mem-slots' ]
+}
+
+##
+# @VhostDeviceProtocols:
+#
+# A structure defined to list the vhost user protocol features of a
+# Vhost User device
+#
Quoted 8 lines

qapi/virtio.json line 146

Quoted 5 lines
qapi/virtio.json +5 -0
+# @features: 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

Why are the known protocol features called @features, and the unknown ones @unknown-protocols?

Quoted 2 lines

I agree that this is inconsistent. Maybe @protocols & @unknown-protocols would be a better choice here as well?

Makes sense to me.

Quoted 217 lines
Quoted 130 lines
Quoted 130 lines
qapi/virtio.json +130 -0
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VhostDeviceProtocols',
+  'data': { 'features': [ 'VhostProtocolFeature' ],
+            '*unknown-protocols': 'uint64' } }
+
+##
+# @VirtioTransportFeature:
+#
+# An enumeration of Virtio device transport features, including virtio-ring
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioTransportFeature',
+  'data': [ 'notify-on-empty', 'any-layout', 'protocol-features',
+            'version-1', 'iommu-platform', 'ring-packed', 'order-platform',
+            'sr-iov', 'indirect-desc', 'event-idx' ]
+}
+
+##
+# @VirtioMemFeature:
+#
+# An enumeration of Virtio mem features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioMemFeature',
+  'data': [ 'acpi-pxm' ]
+}
+
+##
+# @VirtioSerialFeature:
+#
+# An enumeration of Virtio serial/console features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioSerialFeature',
+  'data': [ 'size', 'multiport', 'emerg-write' ]
+}
+
+##
+# @VirtioBlkFeature:
+#
+# An enumeration of Virtio block features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioBlkFeature',
+  'data': [ 'size-max', 'seg-max', 'geometry', 'ro', 'blk-size',
+            'topology', 'mq', 'discard', 'write-zeroes', 'barrier',
+            'scsi', 'flush', 'config-wce', 'log-all' ]
+}
+
+##
+# @VirtioGpuFeature:
+#
+# An enumeration of Virtio gpu features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioGpuFeature',
+  'data': [ 'virgl', 'edid', 'resource-uuid', 'resource-blob',
+            'log-all' ]
+}
+
+##
+# @VirtioNetFeature:
+#
+# An enumeration of Virtio net features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioNetFeature',
+  'data': [ 'csum', 'guest-csum', 'ctrl-guest-offloads', 'mtu', 'mac',
+            'guest-tso4', 'guest-tso6', 'guest-ecn', 'guest-ufo',
+            'host-tso4', 'host-tso6', 'host-ecn', 'host-ufo',
+            'mrg-rxbuf', 'status', 'ctrl-vq', 'ctrl-rx', 'ctrl-vlan',
+            'ctrl-rx-extra', 'guest-announce', 'mq', 'ctrl-mac-addr',
+            'hash-report', 'rss', 'rsc-ext', 'standby', 'speed-duplex',
+            'gso', 'virtio-net-hdr', 'log-all' ]
+}
+
+##
+# @VirtioScsiFeature:
+#
+# An enumeration of Virtio scsi features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioScsiFeature',
+  'data': [ 'inout', 'hotplug', 'change', 't10-pi', 'log-all' ]
+}
+
+##
+# @VirtioBalloonFeature:
+#
+# An enumeration of Virtio balloon features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioBalloonFeature',
+  'data': [ 'must-tell-host', 'stats-vq', 'deflate-on-oom',
+            'free-page-hint', 'page-poison', 'reporting' ]
+}
+
+##
+# @VirtioIommuFeature:
+#
+# An enumeration of Virtio iommu features
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioIommuFeature',
+  'data': [ 'input-range', 'domain-range', 'map-unmap', 'bypass',
+            'probe', 'mmio' ]
+}
+
+##
Quoted 8 lines

qapi/virtio.json line 281

Quoted 5 lines
qapi/virtio.json +5 -0
+# @VirtioInputFeature:
+#
+# An enumeration of Virtio input features. Note that virtio-input
+# has no device-specific features except when its vhost is active,
+# then it may have the VHOST_F_LOG_ALL feature.

VHOST_F_LOG_ALL is talking C. Better, I think: "may have the @log-all feature. More of the same below.

Got it. Will fix this for all occurrences!

Quoted 43 lines
Quoted 43 lines
qapi/virtio.json +42 -0
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioInputFeature',
+  'data': [ 'log-all' ]
+}
+
+##
+# @VhostUserFsFeature:
+#
+# An enumeration of vhost user FS features. Note that vhost-user-fs
+# has no device-specific features other than the vhost-common
+# VHOST_F_LOG_ALL feature.
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VhostUserFsFeature',
+  'data': [ 'log-all' ]
+}
+
+##
+# @VhostVsockFeature:
+#
+# An enumeration of vhost vsock features. Note that vhost-vsock has
+# no device-specific features other than the vhost-common
+# VHOST_F_LOG_ALL feature.
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VhostVsockFeature',
+  'data': [ 'log-all' ]
+}
+
+##
+# @VirtioCryptoFeature:
+#
+# An enumeration of virtio crypto features. Not that virtio-crypto
+# has no device-specific features other than when it is a vhost
+# device, then it may have the VHOST_F_LOG_ALL feature.
Quoted 8 lines

qapi/virtio.json line 330

Quoted 7 lines
qapi/virtio.json +7 -0
+#
+# Since: 6.3
+##
+
+{ 'enum': 'VirtioCryptoFeature',
+  'data': [ 'log-all' ]
+}

Four identical enum types... any particular reason against just one?

See comment at the end.

Quoted 13 lines
Quoted 13 lines
qapi/virtio.json +12 -0
+
+##
+# @VirtioDeviceFeaturesBase:
+#
+# The common fields that apply to all Virtio devices
+#
+# @type: virtio device name
+# @transport: the list of transport features of the virtio device
+# @unknown-features: virtio device features bitmap that have not been decoded
+#
+# Since: 6.3
+##
Quoted 8 lines

qapi/virtio.json line 347

Quoted 5 lines
qapi/virtio.json +5 -0
+
+{ 'struct': 'VirtioDeviceFeaturesBase',
+  'data': { 'type': 'VirtioType',
+            'transport': [ 'VirtioTransportFeature' ],
+            '*unknown-features': 'uint64' } }

Pardon my virtio ignorance... are the @unknown-features unknown transport features?

Quoted 1 line

Yes in this case they would be unknown transport features.

Suggest to call them @transports and @unknown-transports then, similar to @protocols and @unknown-protocols in VhostDeviceProtocols.

Quoted 366 lines
Quoted 366 lines
Quoted 146 lines
qapi/virtio.json +146 -0
+
+##
+# @VirtioDeviceFeaturesOptionsMem:
+#
+# The options that apply to Virtio mem devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsMem',
+  'data': { 'features': [ 'VirtioMemFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsSerial:
+#
+# The options that apply to Virtio serial devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsSerial',
+  'data': { 'features': [ 'VirtioSerialFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsBlk:
+#
+# The options that apply to Virtio block devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsBlk',
+  'data': { 'features': [ 'VirtioBlkFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsGpu:
+#
+# The options that apply to Virtio GPU devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsGpu',
+  'data': { 'features': [ 'VirtioGpuFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsNet:
+#
+# The options that apply to Virtio net devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsNet',
+  'data': { 'features': [ 'VirtioNetFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsScsi:
+#
+# The options that apply to Virtio SCSI devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsScsi',
+  'data': { 'features': [ 'VirtioScsiFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsBalloon:
+#
+# The options that apply to Virtio balloon devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsBalloon',
+  'data': { 'features': [ 'VirtioBalloonFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsIommu:
+#
+# The options that apply to Virtio IOMMU devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsIommu',
+  'data': { 'features': [ 'VirtioIommuFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsInput:
+#
+# The options that apply to Virtio input devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsInput',
+  'data': { 'features': [ 'VirtioInputFeature' ] } }
+
+##
+# @VhostDeviceFeaturesOptionsFs:
+#
+# The options that apply to vhost-user-fs devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VhostDeviceFeaturesOptionsFs',
+  'data': { 'features': [ 'VhostUserFsFeature' ] } }
+
+##
+# @VhostDeviceFeaturesOptionsVsock:
+#
+# The options that apply to vhost-vsock devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VhostDeviceFeaturesOptionsVsock',
+  'data': { 'features': [ 'VhostVsockFeature' ] } }
+
+##
+# @VirtioDeviceFeaturesOptionsCrypto:

qapi/virtio.json line 503

Quoted 10 lines
qapi/virtio.json +10 -0
+#
+# The options that apply to virtio-crypto devices
+#
+# @features: List of device features
+#
+# Since: 6.3
+##
+
+{ 'struct': 'VirtioDeviceFeaturesOptionsCrypto',
+  'data': { 'features': [ 'VirtioCryptoFeature' ] } }

If you replace the four identical enum types by one, you get four identical struct types here. Same treatment.

Quoted 189 lines
qapi/virtio.json +105 -34
+
+##
+# @VirtioDeviceFeatures:
+#
+# A union to define the list of features for a virtio device
+#
+# Since: 6.3
+##
+
+{ 'union': 'VirtioDeviceFeatures',
+  'base': 'VirtioDeviceFeaturesBase',
+  'discriminator': 'type',
+  'data': { 'virtio-serial': 'VirtioDeviceFeaturesOptionsSerial',
+            'virtio-blk': 'VirtioDeviceFeaturesOptionsBlk',
+            'virtio-gpu': 'VirtioDeviceFeaturesOptionsGpu',
+            'virtio-net': 'VirtioDeviceFeaturesOptionsNet',
+            'virtio-scsi': 'VirtioDeviceFeaturesOptionsScsi',
+            'virtio-balloon': 'VirtioDeviceFeaturesOptionsBalloon',
+            'virtio-iommu': 'VirtioDeviceFeaturesOptionsIommu',
+            'virtio-input': 'VirtioDeviceFeaturesOptionsInput',
+            'vhost-user-fs': 'VhostDeviceFeaturesOptionsFs',
+            'vhost-vsock': 'VhostDeviceFeaturesOptionsVsock',
+            'virtio-crypto': 'VirtioDeviceFeaturesOptionsCrypto',
+            'virtio-mem': 'VirtioDeviceFeaturesOptionsMem' } }
+
+##
 # @VhostStatus:
 #
 # Information about a vhost device. This information will only be
@@ -106,10 +566,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',
@@ -174,12 +634,12 @@
    'data': { 'name': 'str',
              'device-id': 'uint16',
              'vhost-started': 'bool',
-            'guest-features': 'uint64',
-            'host-features': 'uint64',
-            'backend-features': 'uint64',
+            'guest-features': 'VirtioDeviceFeatures',
+            'host-features': 'VirtioDeviceFeatures',
+            'backend-features': 'VirtioDeviceFeatures',
              'device-endian': 'VirtioStatusEndianness',
              'num-vqs': 'int',
-            'status': 'uint8',
+            'status': 'VirtioDeviceStatus',
              'isr': 'uint8',
              'queue-sel': 'uint16',
              'vm-running': 'bool',
@@ -191,7 +651,7 @@
              'disable-legacy-check': 'bool',
              'bus-name': 'str',
              'use-guest-notifier-mask': 'bool',
-            'vhost-dev': 'VhostStatus' } }
+            '*vhost-dev': 'VhostStatus' } }
 
 ##
 # @x-query-virtio-status:
@@ -221,28 +681,31 @@
 #          "name": "virtio-crypto",
 #          "started": true,
 #          "device-id": 20,
-#          "vhost-dev": {
-#               "n-tmp-sections": 0,
-#               "n-mem-sections": 0,
-#               "max-queues": 0,
-#               "backend-cap": 0,
-#               "log-size": 0,
-#               "backend-features": 0,
-#               "nvqs": 0,
-#               "protocol-features": 0,
-#               "vq-index": 0,
-#               "log-enabled": false,
-#               "acked-features": 0,
-#               "features": 0
+#          "backend-features": {
+#               "transport": [],
+#               "type": "virtio-crypto",
+#               "features": []
 #          },
-#          "backend-features": 0,
 #          "start-on-kick": false,
 #          "isr": 1,
 #          "broken": false,
-#          "status": 15,
+#          "status": {
+#               "dev-status": ["acknowledge", "driver", "features-ok",
+#                              "driver-ok"]
+#          },
 #          "num-vqs": 2,
-#          "guest-features": 5100273664,
-#          "host-features": 6325010432,
+#          "guest-features": {
+#               "transport": ["event-idx", "indirect-desc", "version-1"],
+#               "type": "virtio-crypto",
+#               "features": []
+#          },
+#          "host-features": {
+#               "transport": ["protocol-features", "event-idx",
+#                             "indirect-desc", "version-1", "any-layout",
+#                             "notify-on-empty"],
+#               "type": "virtio-crypto",
+#               "features": []
+#          },
 #          "use-guest-notifier-mask": true,
 #          "vm-running": true,
 #          "queue-sel": 1,
@@ -270,22 +733,71 @@
 #               "max-queues": 1,
 #               "backend-cap": 2,
 #               "log-size": 0,
-#               "backend-features": 0,
+#               "backend-features": {
+#                       "transport": [],
+#                       "type": "virtio-net",
+#                       "features": []
+#               },
 #               "nvqs": 2,
-#               "protocol-features": 0,
+#               "protocol-features": {
+#                       "features": []
+#               },
 #               "vq-index": 0,
 #               "log-enabled": false,
-#               "acked-features": 5100306432,
-#               "features": 13908344832
+#               "acked-features": {
+#                       "transport": ["event-idx", "indirect-desc", "version-1",
+#                                     "any-layout", "notify-on-empty"],
+#                       "type": "virtio-net",
+#                       "features": ["mrg-rxbuf"]
+#               },
+#               "features": {
+#                       "transport": ["event-idx", "indirect-desc",
+#                                     "iommu-platform", "version-1", "any-layout",
+#                                     "notify-on-empty"],
+#                       "type": "virtio-net",
+#                       "features": ["log-all", "mrg-rxbuf"]
+#               }
+#          },
+#          "backend-features": {
+#               "transport": ["protocol-features", "event-idx", "indirect-desc",
+#                             "version-1", "any-layout", "notify-on-empty"],
+#               "type": "virtio-net",
+#               "features": ["gso", "ctrl-mac-addr", "guest-announce", "ctrl-rx-extra",
+#                            "ctrl-vlan", "ctrl-rx", "ctrl-vq", "status", "mrg-rxbuf",
+#                            "host-ufo", "host-ecn", "host-tso6", "host-tso4",
+#                            "guest-ufo", "guest-ecn", "guest-tso6", "guest-tso4",
+#                            "mac", "ctrl-guest-offloads", "guest-csum", "csum"]
 #          },
-#          "backend-features": 6337593319,
 #          "start-on-kick": false,
 #          "isr": 1,
 #          "broken": false,
-#          "status": 15,
+#          "status": {
+#               "dev-status": ["acknowledge", "driver", "features-ok", "driver-ok"]
+#          },
 #          "num-vqs": 3,
-#          "guest-features": 5111807911,
-#          "host-features": 6337593319,
+#          "guest-features": {
+#               "transport": ["event-idx", "indirect-desc", "version-1"],
+#               "type": "virtio-net",
+#               "features": ["ctrl-mac-addr", "guest-announce", "ctrl-vlan",
+#                            "ctrl-rx", "ctrl-vq", "status", "mrg-rxbuf",
+#                            "host-ufo", "host-ecn", "host-tso6",
+#                            "host-tso4", "guest-ufo", "guest-ecn",
+#                            "guest-tso6", "guest-tso4", "mac",
+#                            "ctrl-guest-offloads", "guest-csum", "csum"]
+#          },
+#          "host-features": {
+#               "transport": ["protocol-features", "event-idx",
+#                             "indirect-desc", "version-1", "any-layout",
+#                             "notify-on-empty"],
+#               "type": "virtio-net",
+#               "features": ["gso", "ctrl-mac-addr", "guest-announce",

qapi/virtio.json line 803

Quoted 10 lines
qapi/virtio.json +7 -0
+#                            "ctrl-rx-extra", "ctrl-vlan", "ctrl-rx",
+#                            "ctrl-vq", "status", "mrg-rxbuf", "host-ufo",
+#                            "host-ecn", "host-tso6", "host-tso4",
+#                            "guest-ufo", "guest-ecn", "guest-tso6",
+#                            "guest-tso4", "mac", "ctrl-guest-offloads",
+#                            "guest-csum", "csum"]
+#          },
 #          "use-guest-notifier-mask": true,
 #          "vm-running": true,
 #          "queue-sel": 2,

Sixteen enums total.

If we replaced them by 'str', the schema would be simpler and the generated code smaller, but introspection would be less informative. I didn't check how the handwritten could would be affected.

Quoted 8 lines
Quoted 1 line

It's a tradeoff. Can you make an argument either way?

I would make the argument for keeping them as is.

One reason is that, while yes it does seem redundant, it's also a core data structure for device-specific features for this series, in a framework type of way. In other words, if / when a device gets a new feature, we would add them there.

Yes, but what's the concrete benefit of having to add new device-specific features to an enum in the QAPI schema?

Quoted 12 lines

Another reason is that the naming convention is very specific, and it should only be tied to one device type. This is because when we go to decode any features or statuses, we need to filter by device type (for the reason above) and compare that device's features bitmap to our known list of features *for that device*.

So in qmp_decode_features():

features = g_new0(VirtioDeviceFeatures, 1);
features->type = qapi_enum_parse(&VirtioType_lookup, name, -1, NULL); switch (features->type) {

Quoted 5 lines

case VIRTIO_TYPE_VIRTIO_SERIAL:

     features->u.virtio_serial.features =
             CONVERT_FEATURES(VirtioSerialFeatureList, serial_map, 0);
     break;

...

This maps bits in @bitmap to a list of enum values. It could just as well map to a list of strings, couldn't it? What do with the list besides returning it to the QMP core?

For a "real" QMP interface, I'd certainly prefer enums to strings, not least for introspection's benefit. But this is just a debugging aid, isn't it? It's a lot of code just for debugging... Can we make it leaner?

By the way, macro CONVERT_FEATURES() uses free variable @bitmap. Passing @bitmap as parameter to the macro would be cleaner.

Quoted 13 lines

And sure while we could make the cases for virtio-input, vhost-user-fs, vhost-vsock, and virtio-crypto (the devices that just have the 'log-all' feature (and only in the vhost case)) homogeneous, e.g:

case VIRTIO_TYPE_VIRTIO_CRYPTO:

     features->u.devs_w_one_feature.features =
             CONVERT_FEATURES(DevsWOneFeatureList, logall_map, 0);
     break;
case VIRTIO_TYPE_VIRTIO_INPUT:
     features->u.devs_w_one_feature.features =
             CONVERT_FEATURES(DevsWOneFeatureList, logall_map, 0);
     break;
Quoted 4 lines

...

We would still need to create a unique enum / data structure for one of those devices if / when they get their own new feature.

Having to create them then (maybe) rather than now (surely) doesn't sound bad to me at all :)

#13 lore raw

PATCH v9 6/8 qmp: add QMP commands for virtio/vhost queue-status

In reply to Jonah Palmer

From: Laurent Vivier <[email protected]>

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

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

109 lines not on this page · raw message

qapi/virtio.json +250 -0

253 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#14 lore raw

PATCH v9 7/8 qmp: add QMP command x-query-virtio-queue-element

In reply to Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command shows the information of a VirtQueue element.

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

166 lines not on this page · raw message

qapi/virtio.json +177 -0

180 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#15 lore raw

Re: [PATCH v9 7/8] qmp: add QMP command x-query-virtio-queue-element

Quoted 5 lines · Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command shows the information of a VirtQueue element.

[...]

Quoted 85 lines
qapi/virtio.json +77 -0
index 0f65044..c57fbc5 100644
@@ -1061,3 +1061,180 @@
 { 'command': 'x-query-virtio-vhost-queue-status',
   'data': { 'path': 'str', 'queue': 'uint16' },
   'returns': 'VirtVhostQueueStatus', 'features': [ 'unstable' ] }
+
+##
+# @VirtioRingDescFlags:
+#
+# An enumeration of the virtio ring descriptor flags
+#
+# Since: 6.3
+#
+##
+
+{ 'enum': 'VirtioRingDescFlags',
+  'data': [ 'next', 'write', 'indirect', 'avail', 'used' ]
+}
+
+##
+# @VirtioRingDesc:
+#
+# Information regarding the VRing descriptor area
+#
+# @addr: guest physical address of the descriptor data
+#
+# @len: length of the descriptor data
+#
+# @flags: list of descriptor flags
+#
+# Since: 6.3
+#
+##
+
+{ 'struct': 'VirtioRingDesc',
+  'data': { 'addr': 'uint64',
+            'len': 'uint32',
+            'flags': [ 'VirtioRingDescFlags' ] } }
+
+##
+# @VirtioRingAvail:
+#
+# Information regarding the avail VRing (also known as the driver
+# area)
+#
+# @flags: VRingAvail flags
+#
+# @idx: VRingAvail index
+#
+# @ring: VRingAvail ring[] entry at provided index
+#
+# Since: 6.3
+#
+##
+
+{ 'struct': 'VirtioRingAvail',
+  'data': { 'flags': 'uint16',
+            'idx': 'uint16',
+            'ring': 'uint16' } }
+
+##
+# @VirtioRingUsed:
+#
+# Information regarding the used VRing (also known as the device
+# area)
+#
+# @flags: VRingUsed flags
+#
+# @idx: VRingUsed index
+#
+# Since: 6.3
+#
+##
+
+{ 'struct': 'VirtioRingUsed',
+  'data': { 'flags': 'uint16',
+            'idx': 'uint16' } }
+
+##
+# @VirtioQueueElement:
+#
+# Information regarding a VirtQueue VirtQueueElement including

qapi/virtio.json line 1150

Quoted 10 lines
qapi/virtio.json +10 -0
+# descriptor, driver, and device areas
+#
+# @device-name: name of the VirtIODevice which this VirtQueue belongs
+#               to (for reference)
+#
+# @index: index of the element in the queue
+#
+# @ndescs: number of descriptors
+#
+# @descs: list of the descriptors

Can @ndescs ever be not equal to the length of @descs?

If no, it's redundant.

Quoted 90 lines
qapi/virtio.json +90 -0
+#
+# @avail: VRingAvail info
+#
+# @used: VRingUsed info
+#
+# Since: 6.3
+#
+##
+
+{ 'struct': 'VirtioQueueElement',
+  'data': { 'device-name': 'str',
+            'index': 'uint32',
+            'ndescs': 'uint32',
+            'descs': [ 'VirtioRingDesc' ],
+            'avail': 'VirtioRingAvail',
+            'used': 'VirtioRingUsed' } }
+
+##
+# @x-query-virtio-queue-element:
+#
+# Return the information about a VirtQueue VirtQueueElement (by
+# default looks at the head of the queue)
+#
+# @path: VirtIODevice canonical QOM path
+#
+# @queue: VirtQueue index to examine
+#
+# @index: the index in the queue, by default head
+#
+# Features:
+# @unstable: This command is meant for debugging.
+#
+# Returns: VirtioQueueElement information
+#
+# Since: 6.3
+#
+# Examples:
+#
+# 1. Introspect on virtio-net 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,
+#         "ndescs": 1,
+#         "device-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 virtqueue 1 at head
+#
+# -> { "execute": "x-query-virtio-queue-element",
+#      "arguments": { "path": "/machine/peripheral/crypto0/virtio-backend",
+#                     "queue": 1 }
+#    }
+# <- { "return": {
+#         "index": 0,
+#         "ndescs": 1,
+#         "device-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 virtqueue 2 at head
+#
+# -> { "execute": "x-query-virtio-queue-element",
+#      "arguments": { "path": "/machine/peripheral-anon/device[2]/virtio-backend",
+#                     "queue": 2 }
+#    }
+# <- { "return": {
+#         "index": 19,
+#         "ndescs": 1,
+#         "device-name": "virtio-scsi",
+#         "descs": [ { "flags": ["used", "indirect", "write"], "len": 4099327944,
+#                      "addr": 12055409292258155293 } ],
+#         "avail": { "idx": 1147, "flags": 0, "ring": 19 },
+#         "used": { "idx": 1147, "flags": 0 } }
+#    }
+#
+##
+
+{ 'command': 'x-query-virtio-queue-element',
+  'data': { 'path': 'str', 'queue': 'uint16', '*index': 'uint16' },
+  'returns': 'VirtioQueueElement', 'features': [ 'unstable' ] }
#16 lore raw

Re: [PATCH v9 7/8] qmp: add QMP command x-query-virtio-queue-element

Quoted 106 lines · Markus Armbruster
Quoted 5 lines · Jonah Palmer

From: Laurent Vivier<[email protected]>

This new command shows the information of a VirtQueue element.

[...]

Quoted 85 lines
qapi/virtio.json +77 -0
index 0f65044..c57fbc5 100644
@@ -1061,3 +1061,180 @@
  { 'command': 'x-query-virtio-vhost-queue-status',
    'data': { 'path': 'str', 'queue': 'uint16' },
    'returns': 'VirtVhostQueueStatus', 'features': [ 'unstable' ] }
+
+##
+# @VirtioRingDescFlags:
+#
+# An enumeration of the virtio ring descriptor flags
+#
+# Since: 6.3
+#
+##
+
+{ 'enum': 'VirtioRingDescFlags',
+  'data': [ 'next', 'write', 'indirect', 'avail', 'used' ]
+}
+
+##
+# @VirtioRingDesc:
+#
+# Information regarding the VRing descriptor area
+#
+# @addr: guest physical address of the descriptor data
+#
+# @len: length of the descriptor data
+#
+# @flags: list of descriptor flags
+#
+# Since: 6.3
+#
+##
+
+{ 'struct': 'VirtioRingDesc',
+  'data': { 'addr': 'uint64',
+            'len': 'uint32',
+            'flags': [ 'VirtioRingDescFlags' ] } }
+
+##
+# @VirtioRingAvail:
+#
+# Information regarding the avail VRing (also known as the driver
+# area)
+#
+# @flags: VRingAvail flags
+#
+# @idx: VRingAvail index
+#
+# @ring: VRingAvail ring[] entry at provided index
+#
+# Since: 6.3
+#
+##
+
+{ 'struct': 'VirtioRingAvail',
+  'data': { 'flags': 'uint16',
+            'idx': 'uint16',
+            'ring': 'uint16' } }
+
+##
+# @VirtioRingUsed:
+#
+# Information regarding the used VRing (also known as the device
+# area)
+#
+# @flags: VRingUsed flags
+#
+# @idx: VRingUsed index
+#
+# Since: 6.3
+#
+##
+
+{ 'struct': 'VirtioRingUsed',
+  'data': { 'flags': 'uint16',
+            'idx': 'uint16' } }
+
+##
+# @VirtioQueueElement:
+#
+# Information regarding a VirtQueue VirtQueueElement including

qapi/virtio.json line 1150

Quoted 10 lines
qapi/virtio.json +10 -0
+# descriptor, driver, and device areas
+#
+# @device-name: name of the VirtIODevice which this VirtQueue belongs
+#               to (for reference)
+#
+# @index: index of the element in the queue
+#
+# @ndescs: number of descriptors
+#
+# @descs: list of the descriptors

Can @ndescs ever be not equal to the length of @descs?

Quoted 1 line

If no, it's redundant.

I don't believe so, no. Should I just remove @ndescs then?

Jonah

Quoted 90 lines
Quoted 90 lines
qapi/virtio.json +90 -0
+#
+# @avail: VRingAvail info
+#
+# @used: VRingUsed info
+#
+# Since: 6.3
+#
+##
+
+{ 'struct': 'VirtioQueueElement',
+  'data': { 'device-name': 'str',
+            'index': 'uint32',
+            'ndescs': 'uint32',
+            'descs': [ 'VirtioRingDesc' ],
+            'avail': 'VirtioRingAvail',
+            'used': 'VirtioRingUsed' } }
+
+##
+# @x-query-virtio-queue-element:
+#
+# Return the information about a VirtQueue VirtQueueElement (by
+# default looks at the head of the queue)
+#
+# @path: VirtIODevice canonical QOM path
+#
+# @queue: VirtQueue index to examine
+#
+# @index: the index in the queue, by default head
+#
+# Features:
+# @unstable: This command is meant for debugging.
+#
+# Returns: VirtioQueueElement information
+#
+# Since: 6.3
+#
+# Examples:
+#
+# 1. Introspect on virtio-net 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,
+#         "ndescs": 1,
+#         "device-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 virtqueue 1 at head
+#
+# -> { "execute": "x-query-virtio-queue-element",
+#      "arguments": { "path": "/machine/peripheral/crypto0/virtio-backend",
+#                     "queue": 1 }
+#    }
+# <- { "return": {
+#         "index": 0,
+#         "ndescs": 1,
+#         "device-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 virtqueue 2 at head
+#
+# -> { "execute": "x-query-virtio-queue-element",
+#      "arguments": { "path": "/machine/peripheral-anon/device[2]/virtio-backend",
+#                     "queue": 2 }
+#    }
+# <- { "return": {
+#         "index": 19,
+#         "ndescs": 1,
+#         "device-name": "virtio-scsi",
+#         "descs": [ { "flags": ["used", "indirect", "write"], "len": 4099327944,
+#                      "addr": 12055409292258155293 } ],
+#         "avail": { "idx": 1147, "flags": 0, "ring": 19 },
+#         "used": { "idx": 1147, "flags": 0 } }
+#    }
+#
+##
+
+{ 'command': 'x-query-virtio-queue-element',
+  'data': { 'path': 'str', 'queue': 'uint16', '*index': 'uint16' },
+  'returns': 'VirtioQueueElement', 'features': [ 'unstable' ] }
#17 lore raw

Re: [PATCH v9 7/8] qmp: add QMP command x-query-virtio-queue-element

Quoted 108 lines · Jonah Palmer
Quoted 107 lines · Markus Armbruster
Quoted 5 lines · Jonah Palmer

From: Laurent Vivier<[email protected]>

This new command shows the information of a VirtQueue element.

[...]

Quoted 85 lines
qapi/virtio.json +77 -0
index 0f65044..c57fbc5 100644
@@ -1061,3 +1061,180 @@
  { 'command': 'x-query-virtio-vhost-queue-status',
    'data': { 'path': 'str', 'queue': 'uint16' },
    'returns': 'VirtVhostQueueStatus', 'features': [ 'unstable' ] }
+
+##
+# @VirtioRingDescFlags:
+#
+# An enumeration of the virtio ring descriptor flags
+#
+# Since: 6.3
+#
+##
+
+{ 'enum': 'VirtioRingDescFlags',
+  'data': [ 'next', 'write', 'indirect', 'avail', 'used' ]
+}
+
+##
+# @VirtioRingDesc:
+#
+# Information regarding the VRing descriptor area
+#
+# @addr: guest physical address of the descriptor data
+#
+# @len: length of the descriptor data
+#
+# @flags: list of descriptor flags
+#
+# Since: 6.3
+#
+##
+
+{ 'struct': 'VirtioRingDesc',
+  'data': { 'addr': 'uint64',
+            'len': 'uint32',
+            'flags': [ 'VirtioRingDescFlags' ] } }
+
+##
+# @VirtioRingAvail:
+#
+# Information regarding the avail VRing (also known as the driver
+# area)
+#
+# @flags: VRingAvail flags
+#
+# @idx: VRingAvail index
+#
+# @ring: VRingAvail ring[] entry at provided index
+#
+# Since: 6.3
+#
+##
+
+{ 'struct': 'VirtioRingAvail',
+  'data': { 'flags': 'uint16',
+            'idx': 'uint16',
+            'ring': 'uint16' } }
+
+##
+# @VirtioRingUsed:
+#
+# Information regarding the used VRing (also known as the device
+# area)
+#
+# @flags: VRingUsed flags
+#
+# @idx: VRingUsed index
+#
+# Since: 6.3
+#
+##
+
+{ 'struct': 'VirtioRingUsed',
+  'data': { 'flags': 'uint16',
+            'idx': 'uint16' } }
+
+##
+# @VirtioQueueElement:
+#
+# Information regarding a VirtQueue VirtQueueElement including

qapi/virtio.json line 1150

Quoted 10 lines
qapi/virtio.json +10 -0
+# descriptor, driver, and device areas
+#
+# @device-name: name of the VirtIODevice which this VirtQueue belongs
+#               to (for reference)
+#
+# @index: index of the element in the queue
+#
+# @ndescs: number of descriptors
+#
+# @descs: list of the descriptors

Can @ndescs ever be not equal to the length of @descs?

Quoted 3 lines
Quoted 1 line

If no, it's redundant.

I don't believe so, no. Should I just remove @ndescs then?

Yes, please.

[...]

#18 lore raw

PATCH v9 8/8 hmp: add virtio commands

In reply to Jonah Palmer

From: Laurent Vivier <[email protected]>

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

---
 hmp-commands-info.hx  | 218 ++++++++++++++++++++++++++++++
 include/monitor/hmp.h |   5 +
 monitor/hmp-cmds.c    | 358 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 581 insertions(+)
hmp-commands-info.hx +218 -0
index 407a1da..6bf7359 100644
@@ -877,3 +877,221 @@ SRST
   ``info sgx``
     Show intel SGX information.
 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
+
+    Example:
+
+    List all available virtio devices in the machine::
+
+    (qemu) info virtio
+    /machine/peripheral/vsock0/virtio-backend [vhost-vsock]
+    /machine/peripheral/crypto0/virtio-backend [virtio-crypto]
+    /machine/peripheral-anon/device[2]/virtio-backend [virtio-scsi]
+    /machine/peripheral-anon/device[1]/virtio-backend [virtio-net]
+    /machine/peripheral-anon/device[0]/virtio-backend [virtio-serial]
+
+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
+
+    Example:
+
+    Dump the status of virtio-net (vhost on)::
+
+    (qemu) info virtio-status /machine/peripheral-anon/device[1]/virtio-backend
+    /machine/peripheral-anon/device[1]/virtio-backend:
+        device_name:             virtio-net (vhost)
+        device_id:               1
+        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:                     1
+        endianness:              little
+        status: acknowledge, driver, features-ok, driver-ok
+        Guest features:   event-idx, indirect-desc, version-1
+                          ctrl-mac-addr, guest-announce, ctrl-vlan, ctrl-rx, ctrl-vq, status, mrg-rxbuf,
+                          host-ufo, host-ecn, host-tso6, host-tso4, guest-ufo, guest-ecn, guest-tso6,
+                          guest-tso4, mac, ctrl-guest-offloads, guest-csum, csum
+        Host features:    protocol-features, event-idx, indirect-desc, version-1, any-layout,
+                          notify-on-empty, gso, ctrl-mac-addr, guest-announce, ctrl-rx-extra, ctrl-vlan,
+                          ctrl-rx, ctrl-vq, status, mrg-rxbuf, host-ufo, host-ecn, host-tso6, host-tso4,
+                          guest-ufo, guest-ecn, guest-tso6, guest-tso4, mac, ctrl-guest-offloads,
+                          guest-csum, csum
+        Backend features: protocol-features, event-idx, indirect-desc, version-1, any-layout,
+                          notify-on-empty, gso, ctrl-mac-addr, guest-announce, ctrl-rx-extra, ctrl-vlan,
+                          ctrl-rx, ctrl-vq, status, mrg-rxbuf, host-ufo, host-ecn, host-tso6, host-tso4,
+                          guest-ufo, guest-ecn, guest-tso6, guest-tso4, mac, ctrl-guest-offloads,
+                          guest-csum, csum
+        VHost:
+          nvqs:           2
+          vq_index:       0
+          max_queues:     1
+          n_mem_sections: 4
+          n_tmp_sections: 4
+          backend_cap:    2
+          log_enabled:    false
+          log_size:       0
+          Features:       event-idx, indirect-desc, iommu-platform, version-1, any-layout,
+                          notify-on-empty, log-all, mrg-rxbuf
+        Acked features:   event-idx, indirect-desc, version-1, mrg-rxbuf
+        Backend features:
+        Protocol features:
+
+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
+
+    Example:
+
+    Dump the status of the 6th queue of virtio-scsi::
+
+    (qemu) info virtio-queue-status /machine/peripheral-anon/device[2]/virtio-backend 5
+    /machine/peripheral-anon/device[2]/virtio-backend:
+        device_name:          virtio-scsi
+        queue_index:          5
+        inuse:                0
+        used_idx:             605
+        signalled_used:       605
+        signalled_used_valid: true
+        last_avail_idx:       605
+        shadow_avail_idx:     605
+        VRing:
+          num:          256
+          num_default:  256
+          align:        4096
+          desc:         0x000000011f0bc000
+          avail:        0x000000011f0bd000
+          used:         0x000000011f0bd240
+
+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
+
+    Example:
+
+    (qemu) info virtio-vhost-queue-status /machine/peripheral/vsock0/virtio-backend 1
+    /machine/peripheral/vsock0/virtio-backend:
+        device_name:          vhost-vsock (vhost)
+        kick:                 0
+        call:                 0
+        VRing:
+          num:         128
+          desc:        0x00007f44fe5b2000
+          desc_phys:   0x000000011f3fb000
+          desc_size:   2048
+          avail:       0x00007f44fe5b2800
+          avail_phys:  0x000000011f3fb800
+          avail_size:  262
+          used:        0x00007f44fe5b2940
+          used_phys:   0x000000011f3fb940
+          used_size:   1030
+
+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
+
+    Example:
+
+    Dump the information of the head element of the first queue of
+    virtio-net (vhost on)::
+
+    (qemu) info virtio-queue-element /machine/peripheral-anon/device[1]/virtio-backend 0
+    /machine/peripheral-anon/device[1]/virtio-backend:
+        device_name: virtio-net
+        index:       0
+        desc:
+          ndescs:  1
+          descs:   addr 0x1312c8000 len 1536 (write)
+        avail:
+          flags: 0
+          idx:   256
+          ring:  0
+        used:
+          flags: 0
+          idx:   32
+
+    Since device[1] is a virtio-net device, we can see the MAC address
+    of the NIC in the element buffer::
+
+    (qemu) xp/128bx 0x1312c8000
+    00000001312c8000: 0x01 0x00 0x00 0x00 0x00 0x00 0x22 0x00
+    00000001312c8008: 0x06 0x00 0x01 0x00 0x52 0x54 0x00 0x12
+    00000001312c8010: 0x34 0x56 0xe6 0x94 0xf2 0xc1 0x51 0x2a
+    ...
+
+    [root@guest: ~]# ip link show eth0
+    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode
+    DEFAULT group default qlen 1000
+        link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
+
+    And we can see the MAC address of the gateway immediately after::
+
+    [root@guest: ~]# arp -a
+    gateway (192.168.53.1) at e6:94:f2:c1:51:2a [ether] on eth0
+
+ERST
include/monitor/hmp.h +5 -0
index 96d0148..47446d8 100644
@@ -95,6 +95,11 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict);
 void hmp_qom_get(Monitor *mon, const QDict *qdict);
 void hmp_qom_set(Monitor *mon, const QDict *qdict);
 void hmp_info_qom_tree(Monitor *mon, const QDict *dict);
+void hmp_virtio_query(Monitor *mon, const QDict *qdict);
+void hmp_virtio_status(Monitor *mon, const QDict *qdict);
+void hmp_virtio_queue_status(Monitor *mon, const QDict *qdict);
+void hmp_vhost_queue_status(Monitor *mon, const QDict *qdict);
+void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict);
 void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
monitor/hmp-cmds.c +358 -0

367 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#19 lore raw

Re: [PATCH v9 8/8] hmp: add virtio commands

Quoted 29 lines · Jonah Palmer

From: Laurent Vivier <[email protected]>

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

---
 hmp-commands-info.hx  | 218 ++++++++++++++++++++++++++++++
 include/monitor/hmp.h |   5 +
 monitor/hmp-cmds.c    | 358 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 581 insertions(+)
hmp-commands-info.hx +10 -0
index 407a1da..6bf7359 100644
@@ -877,3 +877,221 @@ SRST
   ``info sgx``
     Show intel SGX information.
 ERST
+
+    {
+        .name      = "virtio",
+        .args_type = "",
+        .params    = "",
+        .help      = "List all available virtio devices",
+        .cmd       = hmp_virtio_query,
+        .flags     = "p",
+    },
+

hmp-commands-info.hx SRST · line 899

Quoted 10 lines
hmp-commands-info.hx +10 -0
+SRST
+  ``info virtio``
+    List all available virtio devices
+
+    Example:
+
+    List all available virtio devices in the machine::
+
+    (qemu) info virtio
+    /machine/peripheral/vsock0/virtio-backend [vhost-vsock]

I get

docs/../hmp-commands-info.hx:899:Inconsistent literal block quoting.

This is from Sphinx. I can't see what's wrong.

Quoted 6 lines
hmp-commands-info.hx +6 -0
+    /machine/peripheral/crypto0/virtio-backend [virtio-crypto]
+    /machine/peripheral-anon/device[2]/virtio-backend [virtio-scsi]
+    /machine/peripheral-anon/device[1]/virtio-backend [virtio-net]
+    /machine/peripheral-anon/device[0]/virtio-backend [virtio-serial]
+
+ERST

[...]

#20 lore raw

Re: [PATCH v9 8/8] hmp: add virtio commands

Quoted 43 lines · Markus Armbruster
Quoted 29 lines · Jonah Palmer

From: Laurent Vivier<[email protected]>

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

---
  hmp-commands-info.hx  | 218 ++++++++++++++++++++++++++++++
  include/monitor/hmp.h |   5 +
  monitor/hmp-cmds.c    | 358 ++++++++++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 581 insertions(+)
hmp-commands-info.hx +10 -0
index 407a1da..6bf7359 100644
@@ -877,3 +877,221 @@ SRST
    ``info sgx``
      Show intel SGX information.
  ERST
+
+    {
+        .name      = "virtio",
+        .args_type = "",
+        .params    = "",
+        .help      = "List all available virtio devices",
+        .cmd       = hmp_virtio_query,
+        .flags     = "p",
+    },
+

hmp-commands-info.hx SRST · line 899

Quoted 10 lines
hmp-commands-info.hx +10 -0
+SRST
+  ``info virtio``
+    List all available virtio devices
+
+    Example:
+
+    List all available virtio devices in the machine::
+
+    (qemu) info virtio
+    /machine/peripheral/vsock0/virtio-backend [vhost-vsock]

I get

Quoted 3 lines

docs/../hmp-commands-info.hx:899:Inconsistent literal block quoting.

This is from Sphinx. I can't see what's wrong.

I'll (hopefully) get this cleared up in the next series. Will run Sphinx myself to double check.

Jonah

Quoted 8 lines
Quoted 6 lines
hmp-commands-info.hx +6 -0
+    /machine/peripheral/crypto0/virtio-backend [virtio-crypto]
+    /machine/peripheral-anon/device[2]/virtio-backend [virtio-scsi]
+    /machine/peripheral-anon/device[1]/virtio-backend [virtio-net]
+    /machine/peripheral-anon/device[0]/virtio-backend [virtio-serial]
+
+ERST

[...]