Skip to contentSkip to conversation

hmp,qmp: Add some commands to introspect virtio deices

RFC Superseded Jonah Palmer 4 participants 13 messages Mar 18, 2021 – Jun 2, 2021 Arm/Amlogic Meson SoC support

v5 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v5 cover hmp,qmp: Add some commands to introspect virtio deices

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

[Jonah: Rebasing and upstreaming Laurent's qmp/hmp virtio commands from
last May (here: https://lore.kernel.org/qemu-devel/[email protected]/)
which mainly included Makefile to meson.build, minor patching, etc.

I've also added new features (since QEMU 5.0) to virtio-gpu, virtio-net, and virtio-balloon. Lastly, I've added display for the virtio device name in a few of the qmp/hmp commands as well as relative indicies for vrings (see patches 4/6, 6/6).]

1. Main command

HMP Only:

virtio [subcommand]

Example:

List all sub-commands:

(qemu) virtio
virtio query -- List all available virtio devices
virtio status path -- Display status of a given virtio device virtio queue-status path queue -- Display status of a given virtio queue virtio queue-element path queue [index] -- Display element of a given virtio queue

2. List available virtio deices in the machine

HMP Form:

virtio query

Example:

(qemu) virtio query /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-debug-query-virtio', 'returns': ['VirtioInfo']  }

    Example:

        -> { "execute": "x-debug-query-virtio"  }
        <- { "return": [
                {
                    "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"
                }
             ]
           }

3. Display status of a given virtio device

HMP Form:

virtio status <path>

Example:

(qemu) virtio status /machine/peripheral-anon/device[2]/virtio-backend /machine/peripheral-anon/device[2]/virtio-backend:
Device Id: 8
Guest features: event-idx, indirect-desc, version-1, change,
hotplug
Host features: event-idx, indirect-desc, bad-feature, version-1,
any-layout, notify-on-empty, change, hotplug
Backend features:
Endianness: little
VirtQueues: 4

QMP Form:

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

    Example:

        -> { "execute": "x-debug-virtio-status" 
             "arguments": {
                "path": "/machine/peripheral-anon/device[2]/virtio-backend"
             }
           }
        <- { "return": {
                "device-endian": "little",
                "device-id": 8,
                "backend-features": {
                    "transport": [
                    ],
                    "type": "virtio-scsi",
                    "features": [
                    ]
                },
                "num-vqs": 4,
                "guest-features": {
                    "transport": [
                        "event-idx",
                        "indirect-desc",
                        "version-1"
                    ],
                    "type": "virtio-scsi",
                    "features": [
                        "change",
                        "hotplug"
                    ]
                },
                "host-features": {
                    "transport": [
                        "event-idx",
                        "indirect-desc",
                        "bad-feature",
                        "version-1",
                        "any-layout",
                        "notify-on-empty"
                    ],
                    "type": "virtio-scsi",
                    "features": [
                        "change",
                        "hotplug"
                    ]
                }
             }
           }

4. Display status of a given virtio queue

HMP Form:

    virtio queue-status <path> <queue>

    Example:

        (qemu) virtio queue-status /machine/peripheral-anon/device[2]/virtio-backend 3
        /machine/peripheral-anon/device[2]/virtio-backend:
            device_type:            virtio-scsi
            index:                  3
            inuse:                  0
            last_avail_idx:         4174 (78 % 256)
            shadow_avail_idx:       4174 (78 % 256)
            signalled_used:         4174 (78 % 256)
            signalled_used_valid:   1
            VRing:
                num:            256
                num_default:    256
                align:          4096
                desc:           0x000000003cf9e000
                avail:          0x000000003cf9f000
                used:           0x000000003cf9f240

QMP Form:

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

    Example:

        -> { "execute": "x-debug-virtio-queue-status",
             "arguments": {
                "path": "/machine/peripheral-anon/decice[2]/virtio-backend",
                "queue": 3
             }
           }
        <- { "return": {
                "signalled-used": 4188,
                "inuse": 0,
                "vring-align": 4096,
                "vring-desc": 1023008768,
                "signalled-used-valid": 1,
                "vring-num-default": 256,
                "vring-avail": 1023012864,
                "queue-index": 3,
                "last-avail-idx": 4188,
                "vring-used": 1023013440,
                "used-idx": 4188,
                "device-type": "virtio-scsi",
                "shadow-avail-idx": 4188
                "vring-num": 256
             }
           }

5. Display element of a given virtio queue

HMP Form:

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

    Example:

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

        (qemu) virtio queue-element /machine/peripheral-anon/device[3]/virtio-backend 3
        index: 122
        ndescs: 3
        descs: addr 0x7302d000 len 4096 (write), addr 0x3c951763 len 108 (write, next), 
               addr 0x3c951728 len 51 (next)

        (qemu) xp/128x 0x7302d000
        000000007302d000: 0xce 0x14 0x56 0x77 0x78 0x7f 0x00 0x00
        000000007302d008: 0x05 0x00 0x00 0x00 0x00 0x00 0x00 0x00
        000000007302d010: 0xf9 0x00 0x00 0x00 0x00 0x00 0x00 0x00
        000000007302d018: 0x4f 0xf9 0x55 0x77 0x78 0x7f 0x00 0x00
        ...		

QMP Form:

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

    Example:

        -> { "execute": "x-debug-virtio-queue-element",
             "arguments": {
                "path": "/machine/peripheral-anon/device[2]/virtio-backend",
                "queue": 0
             }
           }
        <- { "return": {
                "index": 122,
                "ndescs": 3,
                "descs": [
                    {
                        "flags": [
                            "write"
                        ],
                        "len": 4096,
                        "addr": 1929564160
                    },
                    {
                        "flags": [
                            "write",
                            "next"
                        ],
                        "len": 108,
                        "addr": 1016403811
                    },
                    {
                        "flags": [
                            "next"
                        ],
                        "len": 51,
                        "addr": 1016403752
                    }
                ]
             }
           }

[Jonah:
Comments:

One thing worth mentioning that this patch series adds is some maintenance burden. More specifically, the following would need to be done if a new virtio device type (with features) were to be added:

- In the new */virtio-<device>.c: add #include "qapi/qapi-visit-virtio.h" and define a qmp_virtio_feature_map_t map structure with device feature entries (e.g. FEATURE_ENTRY(_FEATURE_))

- In qapi/virtio.json: define a new enumeration of Virtio<Device>Feature (including its enumerated features) and define a new VirtioDeviceFeaturesOptions<Device> and add it to VirtioDeviceFeatures

- In hw/virtio/virtio.c: add a case to switch statements in qmp_decode_features and hmp_virtio_dump_features

If you're just adding a new feature for an already existing virtio device:

- In */virtio-<device>.c: add the new FEATURE_ENTRY(_FEATURE_) in the device's qmp_virtio_feature_map_t structure

- In qapi/virtio.json: add the enumeration of the new virtio device feature in the corresponding Virtio<Device>Feature JSON structure

In the previous patch series (v4) there was a comment regarding the implementation of the switch case in hmp_virtio_dump_features. It would be nice to not need to explicitly define a case for each virtio device type (with features) here, but it's not very clear (to me) on how this could be achieved (and optimally we'd probably want something similar for qmp_decode_features as well).

The suggestion to this problem (from last May) was to do something like:

    if (features->type < something_MAX) {
        features_str = anarray[features->type];
        ...
        monitor_printf(mon, "%s", features_str(list->value));
        ...
    }

But, (1): the device type enumerations were changed to "flat" enums in v4 and, as I understand it, flat enums have no value associated with them so we wouldn't be able to use it to index anarray. And (2): not every virtio device has features (e.g. virtio-9p, virtio-input, vhost-user-fs, etc.) so we'd still need to take that into account and filter-out those devices as well.

I've looked at it for awhile but, at least to me, it wasn't obvious how this could be done.

Note: for patch 5/6, checkpatch.pl gives the following error:

ERROR: "foo * bar" should be "foo *bar"
#329: FILE: hw/virtio/virtio.c:4164

            type##FeatureList * list = features->u.field.features;

But doing both 'type##FeatureList * list = ...' and 'type##FeatureList *list = ...' give errors, so I just left it as the former representation. ]

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

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

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

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

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

 docs/system/monitor.rst      |   2 +
 hmp-commands-virtio.hx       | 162 ++++++++++++
 hmp-commands.hx              |  10 +
 hw/block/virtio-blk.c        |  23 ++
 hw/char/virtio-serial-bus.c  |  11 +
 hw/display/virtio-gpu-base.c |  10 +
 hw/net/virtio-net.c          |  35 +++
 hw/scsi/virtio-scsi.c        |  12 +
 hw/virtio/meson.build        |   2 +
 hw/virtio/virtio-balloon.c   |  13 +
 hw/virtio/virtio-iommu.c     |  14 +
 hw/virtio/virtio-stub.c      |  34 +++
 hw/virtio/virtio.c           | 574 ++++++++++++++++++++++++++++++++++++++++
 include/hw/virtio/virtio.h   |  14 +
 include/monitor/hmp.h        |   4 +
 meson.build                  |   1 +
 monitor/misc.c               |  17 ++
 qapi/meson.build             |   1 +
 qapi/qapi-schema.json        |   1 +
 qapi/virtio.json             | 600 +++++++++++++++++++++++++++++++++++++++++++
 tests/qtest/qmp-cmd-test.c   |   1 +
 21 files changed, 1541 insertions(+)
 create mode 100644 hmp-commands-virtio.hx
 create mode 100644 hw/virtio/virtio-stub.c
 create mode 100644 qapi/virtio.json
Signature · 1 line
1.8.3.1
#1 lore raw

RFC v5 1/6 qmp: add QMP command x-debug-query-virtio

From: Laurent Vivier <[email protected]>

This new command lists all the instances of VirtIODevice with their path and virtio type

---
 hw/virtio/meson.build      |  2 ++
 hw/virtio/virtio-stub.c    | 14 ++++++++++
 hw/virtio/virtio.c         | 28 +++++++++++++++++++
 include/hw/virtio/virtio.h |  1 +
 qapi/meson.build           |  1 +
 qapi/qapi-schema.json      |  1 +
 qapi/virtio.json           | 68 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/qtest/qmp-cmd-test.c |  1 +
 8 files changed, 116 insertions(+)
 create mode 100644 hw/virtio/virtio-stub.c
 create mode 100644 qapi/virtio.json
hw/virtio/meson.build +2 -0
index fbff9bc..81dc4c9 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..d4a88f5
@@ -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_debug_query_virtio(Error **errp)
+{
+    return qmp_virtio_unsupported(errp);
+}
hw/virtio/virtio.c +28 -0
index 1fd1917..0e12561 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 "exec/address-spaces.h"
@@ -30,6 +32,8 @@
 #include "sysemu/runstate.h"
 #include "standard-headers/linux/virtio_ids.h"
 
+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
@@ -3673,6 +3677,7 @@ static void virtio_device_realize(DeviceState *dev, Error **errp)
 
     vdev->listener.commit = virtio_memory_listener_commit;
     memory_listener_register(&vdev->listener, vdev->dma_as);
+    QTAILQ_INSERT_TAIL(&virtio_list, vdev, next);
 }
 
 static void virtio_device_unrealize(DeviceState *dev)
@@ -3687,6 +3692,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;
 }
@@ -3844,6 +3850,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)
@@ -3854,6 +3862,26 @@ bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
     return virtio_bus_ioeventfd_enabled(vbus);
 }
 
+VirtioInfoList *qmp_x_debug_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 = qapi_enum_parse(&VirtioType_lookup, vdev->name,
+                                            VIRTIO_TYPE_UNKNOWN, NULL);
+        node->next = list;
+        list = node;
+    }
+
+    return list;
+}
+
 static const TypeInfo virtio_device_info = {
     .name = TYPE_VIRTIO_DEVICE,
     .parent = TYPE_DEVICE,
include/hw/virtio/virtio.h +1 -0
index b7ece7a..2470e09 100644
@@ -108,6 +108,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 0652569..1ffad95 100644
@@ -43,6 +43,7 @@ qapi_all_modules = [
   'sockets',
   'trace',
   'transaction',
+  'virtio',
   'yank',
 ]
 if have_system
qapi/qapi-schema.json +1 -0
index 3441c9a..ed000ea 100644
@@ -90,5 +90,6 @@
 { 'include': 'misc.json' }
 { 'include': 'misc-target.json' }
 { 'include': 'audio.json' }
+{ 'include': 'virtio.json' }
 { 'include': 'acpi.json' }
 { 'include': 'pci.json' }
qapi/virtio.json new file +68 -0

68 lines not on this page · raw message

tests/qtest/qmp-cmd-test.c +1 -0
index 1c7186e..8f0ae20 100644
@@ -95,6 +95,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-debug-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
#2 lore raw

Re: [RFC v5 1/6] qmp: add QMP command x-debug-query-virtio

Quoted 9 lines · Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command lists all the instances of VirtIODevice with their path and virtio type

---

We've missed soft freeze for 6.0, and this feels like a new feature; therefore...

Quoted 8 lines

+++ b/hw/virtio/virtio.c

hw/virtio/virtio.c +5 -0
+VirtioInfoList *qmp_x_debug_query_virtio(Error **errp)
+{
+    VirtioInfoList *list = NULL;
+    VirtioInfoList *node;
+    VirtIODevice *vdev;

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

Quoted 10 lines
hw/virtio/virtio.c +10 -0
+
+    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 = qapi_enum_parse(&VirtioType_lookup, vdev->name,
+                                            VIRTIO_TYPE_UNKNOWN, NULL);
+        node->next = list;
+        list = node;

This should be updated to use QAPI_LIST_PREPEND rather than open coding.

Quoted 14 lines
hw/virtio/virtio.c +5 -0
+    }
+
+    return list;
+}
+
 static const TypeInfo virtio_device_info = {
     .name = TYPE_VIRTIO_DEVICE,
     .parent = TYPE_DEVICE,
include/hw/virtio/virtio.h +1 -1
index b7ece7a..2470e09 100644
--- a/include/hw/virtio/virtio.h
 
+++ b/qapi/virtio.json

include/hw/virtio/virtio.h line 10

Quoted 10 lines
include/hw/virtio/virtio.h +10 -0
@@ -0,0 +1,68 @@
+##
+# = Virtio devices
+##
+
+##
+# @VirtioType:
+#
+# An enumeration of Virtio device types.
+#
+# Since: 6.0

...this now needs to reference 6.1.

Quoted 8 lines
include/hw/virtio/virtio.h +8 -0
+##
+{ 'enum': 'VirtioType',
+  'data': [ 'unknown', 'virtio-9p', 'virtio-blk', 'virtio-serial',
+            'virtio-gpu', 'virtio-input', 'virtio-net', 'virtio-scsi',
+            'vhost-user-fs', 'vhost-vsock', 'virtio-balloon', 'virtio-crypto',
+            'virtio-iommu', 'virtio-pmem', 'virtio-rng' ]
+}
+

include/hw/virtio/virtio.h line 28

Quoted 10 lines
include/hw/virtio/virtio.h +10 -0
+##
+# @VirtioInfo:
+#
+# Information about a given VirtIODevice
+#
+# @path: VirtIO device canonical path.
+#
+# @type: VirtIO device type.
+#
+# Since: 6.0

and throughout the series (I'll quit pointing it out)

include/hw/virtio/virtio.h line 40

Quoted 12 lines
include/hw/virtio/virtio.h +12 -0
+##
+# @x-debug-query-virtio:
+#
+# Return the list of all VirtIO devices
+#
+# Returns: list of @VirtioInfo
+#
+# Since: 6.0
+#
+# Example:
+#
+# -> { "execute": "x-debug-query-virtio" }

That said, adding an 'x-' experimental feature is NOT locking us down, so if some maintainer still wants to include this in -rc1 on the grounds that it will help debugging other things, rather than pushing it out to 6.1 as a new feature, then keeping things as 6.0 is tolerable in that border-line case. (If it misses -rc1, then I will become more adamant that it does not belong in 6.0)

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#3 lore raw

Re: [RFC v5 1/6] qmp: add QMP command x-debug-query-virtio

Quoted 15 lines · Eric Blake
Quoted 9 lines · Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command lists all the instances of VirtIODevice with their path and virtio type

---

We've missed soft freeze for 6.0, and this feels like a new feature; therefore...

Quoted 2 lines

+++ b/hw/virtio/virtio.c

Quoted 16 lines
Quoted 5 lines
hw/virtio/virtio.c +5 -0
+VirtioInfoList *qmp_x_debug_query_virtio(Error **errp)
+{
+    VirtioInfoList *list = NULL;
+    VirtioInfoList *node;
+    VirtIODevice *vdev;

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

Quoted 10 lines
hw/virtio/virtio.c +10 -0
+
+    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 = qapi_enum_parse(&VirtioType_lookup, vdev->name,
+                                            VIRTIO_TYPE_UNKNOWN, NULL);
+        node->next = list;
+        list = node;

This should be updated to use QAPI_LIST_PREPEND rather than open coding.

Ok! I'll update this.

Quoted 17 lines
Quoted 17 lines
hw/virtio/virtio.c +5 -0
+    }
+
+    return list;
+}
+
  static const TypeInfo virtio_device_info = {
      .name = TYPE_VIRTIO_DEVICE,
      .parent = TYPE_DEVICE,
qapi/virtio.json renamed from include/hw/virtio/virtio.h +3 -0
index b7ece7a..2470e09 100644
@@ -0,0 +1,68 @@
+##
+# = Virtio devices
+##
Quoted 8 lines

qapi/virtio.json line 10

Quoted 7 lines
qapi/virtio.json renamed from include/hw/virtio/virtio.h +7 -0
+
+##
+# @VirtioType:
+#
+# An enumeration of Virtio device types.
+#
+# Since: 6.0

...this now needs to reference 6.1.

And these!

Quoted 31 lines
Quoted 9 lines
qapi/virtio.json renamed from include/hw/virtio/virtio.h +8 -0
+##
+{ 'enum': 'VirtioType',
+  'data': [ 'unknown', 'virtio-9p', 'virtio-blk', 'virtio-serial',
+            'virtio-gpu', 'virtio-input', 'virtio-net', 'virtio-scsi',
+            'vhost-user-fs', 'vhost-vsock', 'virtio-balloon', 'virtio-crypto',
+            'virtio-iommu', 'virtio-pmem', 'virtio-rng' ]
+}
+

qapi/virtio.json line 28

Quoted 10 lines
qapi/virtio.json renamed from include/hw/virtio/virtio.h +10 -0
+##
+# @VirtioInfo:
+#
+# Information about a given VirtIODevice
+#
+# @path: VirtIO device canonical path.
+#
+# @type: VirtIO device type.
+#
+# Since: 6.0

and throughout the series (I'll quit pointing it out)

Quoted 10 lines
qapi/virtio.json renamed from include/hw/virtio/virtio.h +10 -0
+##
+# @x-debug-query-virtio:
+#
+# Return the list of all VirtIO devices
+#
+# Returns: list of @VirtioInfo
+#
+# Since: 6.0
+#
+# Example:
Quoted 8 lines

qapi/virtio.json line 40

Quoted 2 lines
qapi/virtio.json renamed from include/hw/virtio/virtio.h +2 -0
+#
+# -> { "execute": "x-debug-query-virtio" }

That said, adding an 'x-' experimental feature is NOT locking us down, so if some maintainer still wants to include this in -rc1 on the grounds that it will help debugging other things, rather than pushing it out to 6.1 as a new feature, then keeping things as 6.0 is tolerable in that border-line case. (If it misses -rc1, then I will become more adamant that it does not belong in 6.0)

Right, this patch is not at all urgent for 6.0. I just wanted to send this out to get a review.

Best,
Jonah

Quoted 1 line
#4 lore raw

Re: [RFC v5 1/6] qmp: add QMP command x-debug-query-virtio

In reply to Jonah Palmer
Quoted 2 lines · * Jonah Palmer ([email protected]) wrote:

From: Laurent Vivier <[email protected]>

<snip>

Quoted 9 lines
qapi/virtio.json new file +6 -0
@@ -0,0 +1,68 @@
+##
+# = Virtio devices
+##
+
+##
+# @VirtioType:

qapi/virtio.json line 16

Quoted 10 lines
qapi/virtio.json new file +10 -0
+#
+# An enumeration of Virtio device types.
+#
+# Since: 6.0
+##
+{ 'enum': 'VirtioType',
+  'data': [ 'unknown', 'virtio-9p', 'virtio-blk', 'virtio-serial',
+            'virtio-gpu', 'virtio-input', 'virtio-net', 'virtio-scsi',
+            'vhost-user-fs', 'vhost-vsock', 'virtio-balloon', 'virtio-crypto',
+            'virtio-iommu', 'virtio-pmem', 'virtio-rng' ]

Can we make this be a complete list that's in the same order as include/standard-headers/linux/virtio_ids.h then if we add a few asserts somewhere to make sure we don't screwup, we
don't need to do any translation.

Dave

Quoted 67 lines
qapi/virtio.json new file +52 -0
+}
+
+##
+# @VirtioInfo:
+#
+# Information about a given VirtIODevice
+#
+# @path: VirtIO device canonical path.
+#
+# @type: VirtIO device type.
+#
+# Since: 6.0
+#
+##
+{ 'struct': 'VirtioInfo',
+  'data': {
+    'path': 'str',
+    'type': 'VirtioType'
+  }
+}
+
+##
+# @x-debug-query-virtio:
+#
+# Return the list of all VirtIO devices
+#
+# Returns: list of @VirtioInfo
+#
+# Since: 6.0
+#
+# Example:
+#
+# -> { "execute": "x-debug-query-virtio" }
+# <- { "return": [
+#        {
+#            "path": "/machine/peripheral-anon/device[3]/virtio-backend",
+#            "type": "virtio-net"
+#        },
+#        {
+#            "path": "/machine/peripheral-anon/device[1]/virtio-backend",
+#            "type": "virtio-serial"
+#        },
+#        {
+#            "path": "/machine/peripheral-anon/device[0]/virtio-backend",
+#            "type": "virtio-blk"
+#        }
+#      ]
+#    }
+#
+##
+
+{ 'command': 'x-debug-query-virtio', 'returns': ['VirtioInfo'] }
tests/qtest/qmp-cmd-test.c +1 -0
index 1c7186e..8f0ae20 100644
@@ -95,6 +95,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-debug-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
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#5 lore raw

Re: [RFC v5 1/6] qmp: add QMP command x-debug-query-virtio

Quoted 28 lines · Dr. David Alan Gilbert
Quoted 2 lines · * Jonah Palmer ([email protected]) wrote:

From: Laurent Vivier <[email protected]>

<snip>

Quoted 9 lines
qapi/virtio.json new file +6 -0
@@ -0,0 +1,68 @@
+##
+# = Virtio devices
+##
+
+##
+# @VirtioType:

qapi/virtio.json line 16

Quoted 10 lines
qapi/virtio.json new file +10 -0
+#
+# An enumeration of Virtio device types.
+#
+# Since: 6.0
+##
+{ 'enum': 'VirtioType',
+  'data': [ 'unknown', 'virtio-9p', 'virtio-blk', 'virtio-serial',
+            'virtio-gpu', 'virtio-input', 'virtio-net', 'virtio-scsi',
+            'vhost-user-fs', 'vhost-vsock', 'virtio-balloon', 'virtio-crypto',
+            'virtio-iommu', 'virtio-pmem', 'virtio-rng' ]

Can we make this be a complete list that's in the same order as include/standard-headers/linux/virtio_ids.h then if we add a few asserts somewhere to make sure we don't screwup, we
don't need to do any translation.

Quoted 1 line

Dave

Hi Dave. Just so I understand correctly, you would like me to add all of the entries in the given order? E.g. including 'virtio-rpmsg', ..., 'virtio-mac80211-wlan', etc.? Or just the supported virtio types in the order as it's shown in virtio_ids.h?

Many of these devices may not be supported for introspection.

Jonah

Quoted 68 lines
Quoted 68 lines
qapi/virtio.json new file +52 -0
+}
+
+##
+# @VirtioInfo:
+#
+# Information about a given VirtIODevice
+#
+# @path: VirtIO device canonical path.
+#
+# @type: VirtIO device type.
+#
+# Since: 6.0
+#
+##
+{ 'struct': 'VirtioInfo',
+  'data': {
+    'path': 'str',
+    'type': 'VirtioType'
+  }
+}
+
+##
+# @x-debug-query-virtio:
+#
+# Return the list of all VirtIO devices
+#
+# Returns: list of @VirtioInfo
+#
+# Since: 6.0
+#
+# Example:
+#
+# -> { "execute": "x-debug-query-virtio" }
+# <- { "return": [
+#        {
+#            "path": "/machine/peripheral-anon/device[3]/virtio-backend",
+#            "type": "virtio-net"
+#        },
+#        {
+#            "path": "/machine/peripheral-anon/device[1]/virtio-backend",
+#            "type": "virtio-serial"
+#        },
+#        {
+#            "path": "/machine/peripheral-anon/device[0]/virtio-backend",
+#            "type": "virtio-blk"
+#        }
+#      ]
+#    }
+#
+##
+
+{ 'command': 'x-debug-query-virtio', 'returns': ['VirtioInfo'] }
tests/qtest/qmp-cmd-test.c +1 -0
index 1c7186e..8f0ae20 100644
@@ -95,6 +95,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-debug-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
#6 lore raw

Re: [RFC v5 1/6] qmp: add QMP command x-debug-query-virtio

Quoted 30 lines · * Jonah Palmer ([email protected]) wrote:
Quoted 28 lines · Dr. David Alan Gilbert
Quoted 2 lines · * Jonah Palmer ([email protected]) wrote:

From: Laurent Vivier <[email protected]>

<snip>

Quoted 9 lines
qapi/virtio.json new file +6 -0
@@ -0,0 +1,68 @@
+##
+# = Virtio devices
+##
+
+##
+# @VirtioType:

qapi/virtio.json line 16

Quoted 10 lines
qapi/virtio.json new file +10 -0
+#
+# An enumeration of Virtio device types.
+#
+# Since: 6.0
+##
+{ 'enum': 'VirtioType',
+  'data': [ 'unknown', 'virtio-9p', 'virtio-blk', 'virtio-serial',
+            'virtio-gpu', 'virtio-input', 'virtio-net', 'virtio-scsi',
+            'vhost-user-fs', 'vhost-vsock', 'virtio-balloon', 'virtio-crypto',
+            'virtio-iommu', 'virtio-pmem', 'virtio-rng' ]

Can we make this be a complete list that's in the same order as include/standard-headers/linux/virtio_ids.h then if we add a few asserts somewhere to make sure we don't screwup, we
don't need to do any translation.

Quoted 7 lines
Quoted 1 line

Dave

Hi Dave. Just so I understand correctly, you would like me to add all of the entries in the given order? E.g. including 'virtio-rpmsg', ..., 'virtio-mac80211-wlan', etc.? Or just the supported virtio types in the order as it's shown in virtio_ids.h?

Many of these devices may not be supported for introspection.

Make that list all of the types, and keep it in the same order as the
header with the same gaps (including one at the start); so that that the QAPI generated enum values for 'VirtioType' match the virtio_ids constants; that way you never have
to convert between the qapi number and the header number.
(Whenever we do a convert, sooner or later we screwup the convert and
end up with numbers that don't match!)

As you say, only some have support for introspection; so you just need to check for support rather than doing a mapping.

Dave

Quoted 70 lines

Jonah

Quoted 68 lines
Quoted 68 lines
qapi/virtio.json new file +52 -0
+}
+
+##
+# @VirtioInfo:
+#
+# Information about a given VirtIODevice
+#
+# @path: VirtIO device canonical path.
+#
+# @type: VirtIO device type.
+#
+# Since: 6.0
+#
+##
+{ 'struct': 'VirtioInfo',
+  'data': {
+    'path': 'str',
+    'type': 'VirtioType'
+  }
+}
+
+##
+# @x-debug-query-virtio:
+#
+# Return the list of all VirtIO devices
+#
+# Returns: list of @VirtioInfo
+#
+# Since: 6.0
+#
+# Example:
+#
+# -> { "execute": "x-debug-query-virtio" }
+# <- { "return": [
+#        {
+#            "path": "/machine/peripheral-anon/device[3]/virtio-backend",
+#            "type": "virtio-net"
+#        },
+#        {
+#            "path": "/machine/peripheral-anon/device[1]/virtio-backend",
+#            "type": "virtio-serial"
+#        },
+#        {
+#            "path": "/machine/peripheral-anon/device[0]/virtio-backend",
+#            "type": "virtio-blk"
+#        }
+#      ]
+#    }
+#
+##
+
+{ 'command': 'x-debug-query-virtio', 'returns': ['VirtioInfo'] }
tests/qtest/qmp-cmd-test.c +1 -0
index 1c7186e..8f0ae20 100644
@@ -95,6 +95,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-debug-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
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#7 lore raw

RFC v5 2/6 qmp: add QMP command x-debug-virtio-status

In reply to Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command shows the status of a VirtIODevice (features, endianness and number of virtqueues)

Next patch will improve output by decoding feature bits.

---
 hw/virtio/virtio-stub.c |  5 ++++
 hw/virtio/virtio.c      | 50 ++++++++++++++++++++++++++++++++
 qapi/virtio.json        | 76 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 131 insertions(+)
hw/virtio/virtio-stub.c +5 -0
index d4a88f5..ddb592f 100644
@@ -12,3 +12,8 @@ VirtioInfoList *qmp_x_debug_query_virtio(Error **errp)
 {
     return qmp_virtio_unsupported(errp);
 }
+
+VirtioStatus *qmp_x_debug_virtio_status(const char* path, Error **errp)
+{
+    return qmp_virtio_unsupported(errp);
+}
hw/virtio/virtio.c +50 -0

56 lines not on this page · raw message

qapi/virtio.json +76 -0

79 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#8 lore raw

RFC v5 3/6 qmp: decode feature bits in virtio-status

In reply to Jonah Palmer

From: Laurent Vivier <[email protected]>

Display feature names instead of a features bitmap for host, guest, and backend.

Decode features according to device type, transport features are on the first line. Undecoded bits (if any) are stored in a separate field.

---
 hw/block/virtio-blk.c        |  23 ++++
 hw/char/virtio-serial-bus.c  |  11 ++
 hw/display/virtio-gpu-base.c |  12 ++
 hw/net/virtio-net.c          |  38 ++++++
 hw/scsi/virtio-scsi.c        |  12 ++
 hw/virtio/virtio-balloon.c   |  14 +++
 hw/virtio/virtio-iommu.c     |  14 +++
 hw/virtio/virtio.c           | 127 +++++++++++++++++++-
 include/hw/virtio/virtio.h   |  13 ++
 qapi/virtio.json             | 280 +++++++++++++++++++++++++++++++++++++++++--
 10 files changed, 531 insertions(+), 13 deletions(-)
hw/block/virtio-blk.c +23 -0
index e8600b0..c2858f8 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"
@@ -48,6 +49,28 @@ static 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
+#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 b200389..9791b1d 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"
@@ -33,6 +34,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 +12 -0
index 4a57350..dd8e9e7 100644
@@ -16,9 +16,21 @@
 #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
+    { -1, -1 }
+};
+
 void
 virtio_gpu_base_reset(VirtIOGPUBase *g)
 {
hw/net/virtio-net.c +38 -0
index 5150f29..e405d82 100644
@@ -35,6 +35,7 @@
 #include "hw/qdev-properties.h"
 #include "qapi/qapi-types-migration.h"
 #include "qapi/qapi-events-migration.h"
+#include "qapi/qapi-visit-virtio.h"
 #include "hw/virtio/virtio-access.h"
 #include "migration/misc.h"
 #include "standard-headers/linux/ethtool.h"
@@ -89,6 +90,43 @@
                                          VIRTIO_NET_RSS_HASH_TYPE_TCP_EX | \
                                          VIRTIO_NET_RSS_HASH_TYPE_UDP_EX)
 
+qmp_virtio_feature_map_t net_map[] = {
+#define FEATURE_ENTRY(name) \
+    { VIRTIO_NET_F_##name, VIRTIO_NET_FEATURE_##name }
+    FEATURE_ENTRY(CSUM),
+    FEATURE_ENTRY(GUEST_CSUM),
+    FEATURE_ENTRY(CTRL_GUEST_OFFLOADS),
+    FEATURE_ENTRY(MTU),
+    FEATURE_ENTRY(MAC),
+    FEATURE_ENTRY(GUEST_TSO4),
+    FEATURE_ENTRY(GUEST_TSO6),
+    FEATURE_ENTRY(GUEST_ECN),
+    FEATURE_ENTRY(GUEST_UFO),
+    FEATURE_ENTRY(HOST_TSO4),
+    FEATURE_ENTRY(HOST_TSO6),
+    FEATURE_ENTRY(HOST_ECN),
+    FEATURE_ENTRY(HOST_UFO),
+    FEATURE_ENTRY(MRG_RXBUF),
+    FEATURE_ENTRY(STATUS),
+    FEATURE_ENTRY(CTRL_VQ),
+    FEATURE_ENTRY(CTRL_RX),
+    FEATURE_ENTRY(CTRL_VLAN),
+    FEATURE_ENTRY(CTRL_RX_EXTRA),
+    FEATURE_ENTRY(GUEST_ANNOUNCE),
+    FEATURE_ENTRY(MQ),
+    FEATURE_ENTRY(CTRL_MAC_ADDR),
+    FEATURE_ENTRY(STANDBY),
+    FEATURE_ENTRY(SPEED_DUPLEX),
+    FEATURE_ENTRY(HASH_REPORT),
+    FEATURE_ENTRY(RSS),
+    FEATURE_ENTRY(RSC_EXT),
+#ifndef VIRTIO_NET_NO_LEGACY
+    FEATURE_ENTRY(GSO),
+#endif /* VIRTIO_NET_NO_LEGACY */
+#undef FEATURE_ENTRY
+    { -1, -1 }
+};
+
 static VirtIOFeature feature_sizes[] = {
     {.flags = 1ULL << VIRTIO_NET_F_MAC,
      .end = endof(struct virtio_net_config, mac)},
hw/scsi/virtio-scsi.c +12 -0
index 99ff261..904e297 100644
@@ -15,6 +15,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qapi/qapi-visit-virtio.h"
 #include "standard-headers/linux/virtio_ids.h"
 #include "hw/virtio/virtio-scsi.h"
 #include "migration/qemu-file-types.h"
@@ -29,6 +30,17 @@
 #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
+    { -1, -1 }
+};
+
 static inline int virtio_scsi_get_lun(uint8_t *lun)
 {
     return ((lun[2] << 8) | lun[3]) & 0x3FFF;
hw/virtio/virtio-balloon.c +14 -0
index e770955..11a32ad 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"
@@ -34,6 +35,19 @@
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
 
+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 }
+};
+
 #define BALLOON_PAGE_SIZE  (1 << VIRTIO_BALLOON_PFN_SHIFT)
 
 typedef struct PartiallyBalloonedPage {
hw/virtio/virtio-iommu.c +14 -0
index c2883a2..1b7c202 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"
 
@@ -36,6 +37,19 @@
 #include "hw/pci/pci_bus.h"
 #include "hw/pci/pci.h"
 
+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 }
+};
+
 /* Max size */
 #define VIOMMU_DEFAULT_QUEUE_SIZE 256
 #define VIOMMU_PROBE_SIZE 512
hw/virtio/virtio.c +124 -3

148 lines not on this page · raw message

include/hw/virtio/virtio.h +13 -0
index 2470e09..6fcb5e0 100644
@@ -163,6 +163,19 @@ struct VirtioDeviceClass {
     bool (*primary_unplug_pending)(void *opaque);
 };
 
+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[];
+
 void virtio_instance_init_common(Object *proxy_obj, void *data,
                                  size_t vdev_size, const char *vdev_name);
 
qapi/virtio.json +270 -10

303 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#9 lore raw

RFC v5 4/6 qmp: add QMP command x-debug-virtio-queue-status

In reply to Jonah Palmer

From: Laurent Vivier <[email protected]>

This new command shows internal status of a VirtQueue. (vrings and indexes).

[Jonah: Added 'device-type' field to VirtQueueStatus and qmp command x-debug-virtio-queue-status.]

---
 hw/virtio/virtio-stub.c |   6 +++
 hw/virtio/virtio.c      |  37 ++++++++++++++++++
 qapi/virtio.json        | 102 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 145 insertions(+)
hw/virtio/virtio-stub.c +6 -0
index ddb592f..3c1bf17 100644
@@ -17,3 +17,9 @@ VirtioStatus *qmp_x_debug_virtio_status(const char* path, Error **errp)
 {
     return qmp_virtio_unsupported(errp);
 }
+
+VirtQueueStatus *qmp_x_debug_virtio_queue_status(const char *path,
+                                                 uint16_t queue, Error **errp)
+{
+    return qmp_virtio_unsupported(errp);
+}
hw/virtio/virtio.c +37 -0
index 08ca635..d9b5734 100644
@@ -3919,6 +3919,43 @@ static VirtIODevice *virtio_device_find(const char *path)
     return NULL;
 }
 
+VirtQueueStatus *qmp_x_debug_virtio_queue_status(const char *path,
+                                                 uint16_t queue, Error **errp)
+{
+    VirtIODevice *vdev;
+    VirtQueueStatus *status;
+
+    vdev = virtio_device_find(path);
+    if (vdev == NULL) {
+        error_setg(errp, "Path %s is not a VirtIO device", path);
+        return NULL;
+    }
+
+    if (queue >= VIRTIO_QUEUE_MAX || !virtio_queue_get_num(vdev, queue)) {
+        error_setg(errp, "Invalid virtqueue number %d", queue);
+        return NULL;
+    }
+
+    status = g_new0(VirtQueueStatus, 1);
+    status->device_type = qapi_enum_parse(&VirtioType_lookup, vdev->name,
+                                          VIRTIO_TYPE_UNKNOWN, NULL);
+    status->queue_index = vdev->vq[queue].queue_index;
+    status->inuse = vdev->vq[queue].inuse;
+    status->vring_num = vdev->vq[queue].vring.num;
+    status->vring_num_default = vdev->vq[queue].vring.num_default;
+    status->vring_align = vdev->vq[queue].vring.align;
+    status->vring_desc = vdev->vq[queue].vring.desc;
+    status->vring_avail = vdev->vq[queue].vring.avail;
+    status->vring_used = vdev->vq[queue].vring.used;
+    status->last_avail_idx = vdev->vq[queue].last_avail_idx;
+    status->shadow_avail_idx = vdev->vq[queue].shadow_avail_idx;
+    status->used_idx = vdev->vq[queue].used_idx;
+    status->signalled_used = vdev->vq[queue].signalled_used;
+    status->signalled_used_valid = vdev->vq[queue].signalled_used_valid;
+
+    return status;
+}
+
 #define CONVERT_FEATURES(type, map)                \
     ({                                           \
         type *list = NULL;                         \
qapi/virtio.json +102 -0

105 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#10 lore raw

RFC v5 5/6 qmp: add QMP command x-debug-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      | 135 ++++++++++++++++++++++++++++++++++++++++++++++++
 qapi/virtio.json        |  94 +++++++++++++++++++++++++++++++++
 3 files changed, 238 insertions(+)
hw/virtio/virtio-stub.c +9 -0
index 3c1bf17..8275e31 100644
@@ -23,3 +23,12 @@ VirtQueueStatus *qmp_x_debug_virtio_queue_status(const char *path,
 {
     return qmp_virtio_unsupported(errp);
 }
+
+VirtioQueueElement *qmp_x_debug_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 +135 -0

141 lines not on this page · raw message

qapi/virtio.json +94 -0

97 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#11 lore raw

RFC v5 6/6 hmp: add virtio commands

In reply to Jonah Palmer

From: Laurent Vivier <[email protected]>

This patch implements HMP version of the virtio QMP commands

[Jonah: Added relative indicies, device type, and used index in HMP virtio queue-status command.]

---
 docs/system/monitor.rst |   2 +
 hmp-commands-virtio.hx  | 162 ++++++++++++++++++++++++++++++++++++++
 hmp-commands.hx         |  10 +++
 hw/virtio/virtio.c      | 204 +++++++++++++++++++++++++++++++++++++++++++++++-
 include/monitor/hmp.h   |   4 +
 meson.build             |   1 +
 monitor/misc.c          |  17 ++++
 7 files changed, 399 insertions(+), 1 deletion(-)
 create mode 100644 hmp-commands-virtio.hx
docs/system/monitor.rst +2 -0
index ff5c434..10418fc 100644
@@ -21,6 +21,8 @@ The following commands are available:
 
 .. hxtool-doc:: hmp-commands.hx
 
+.. hxtool-doc:: hmp-commands-virtio.hx
+
 .. hxtool-doc:: hmp-commands-info.hx
 
 Integer expressions
hmp-commands-virtio.hx new file +162 -0

162 lines not on this page · raw message

hmp-commands.hx +10 -0
index d4001f9..19674bf 100644
@@ -1852,6 +1852,16 @@ SRST
 ERST
 
     {
+        .name       = "virtio",
+        .args_type  = "name:S?",
+        .params     = "[cmd]",
+        .help       = "show various information about virtio",
+        .cmd        = hmp_virtio_help,
+        .sub_table  = hmp_virtio_cmds,
+        .flags      = "p",
+    },
+
+    {
         .name       = "info",
         .args_type  = "item:s?",
         .params     = "[subcommand]",
hw/virtio/virtio.c +203 -1

235 lines not on this page · raw message

include/monitor/hmp.h +4 -0
index ed2913f..7a63744 100644
@@ -98,6 +98,10 @@ 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_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);
meson.build +1 -0
index a923f24..2d836b9 100644
@@ -1695,6 +1695,7 @@ if have_system
   hx_headers += [
     ['hmp-commands.hx', 'hmp-commands.h'],
     ['hmp-commands-info.hx', 'hmp-commands-info.h'],
+    ['hmp-commands-virtio.hx', 'hmp-commands-virtio.h'],
   ]
 endif
 foreach d : hx_headers
monitor/misc.c +17 -0
index a7650ed..69542df 100644
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include CONFIG_DEVICES
 #include "monitor-internal.h"
 #include "cpu.h"
 #include "monitor/qdev.h"
@@ -220,6 +221,15 @@ static void hmp_info_help(Monitor *mon, const QDict *qdict)
     help_cmd(mon, "info");
 }
 
+static void hmp_virtio_help(Monitor *mon, const QDict *qdict)
+{
+#if defined(CONFIG_VIRTIO)
+    help_cmd(mon, "virtio");
+#else
+    monitor_printf(mon, "Virtio is disabled\n");
+#endif
+}
+
 static void monitor_init_qmp_commands(void)
 {
     /*
@@ -1654,6 +1664,13 @@ static HMPCommand hmp_info_cmds[] = {
     { NULL, NULL, },
 };
 
+static HMPCommand hmp_virtio_cmds[] = {
+#if defined(CONFIG_VIRTIO)
+#include "hmp-commands-virtio.h"
+#endif
+    { NULL, NULL, },
+};
+
 /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
 HMPCommand hmp_cmds[] = {
 #include "hmp-commands.h"
Signature · 1 line
1.8.3.1
#12 lore raw

Re: [RFC v5 0/6] hmp, qmp: Add some commands to introspect virtio deices

In reply to Jonah Palmer
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [RFC v5 0/6] hmp,qmp: Add some commands to introspect virtio deices

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
be70546 hmp: add virtio commands
e4f8190 qmp: add QMP command x-debug-virtio-queue-element 3313968 qmp: add QMP command x-debug-virtio-queue-status 8e1517f qmp: decode feature bits in virtio-status e8c80fb qmp: add QMP command x-debug-virtio-status 8b46cdd qmp: add QMP command x-debug-query-virtio

=== OUTPUT BEGIN ===
1/6 Checking commit 8b46cdd9037d (qmp: add QMP command x-debug-query-virtio)
Use of uninitialized value $acpi_testexpected in string eq at ./scripts/checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#41:
new file mode 100644

total: 0 errors, 1 warnings, 183 lines checked

Patch 1/6 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
2/6 Checking commit e8c80fb0056a (qmp: add QMP command x-debug-virtio-status) 3/6 Checking commit 8e1517f2abd7 (qmp: decode feature bits in virtio-status)
4/6 Checking commit 3313968494d6 (qmp: add QMP command x-debug-virtio-queue-status) 5/6 Checking commit e4f8190e9a24 (qmp: add QMP command x-debug-virtio-queue-element) 6/6 Checking commit be705468685f (hmp: add virtio commands)
Use of uninitialized value $acpi_testexpected in string eq at ./scripts/checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#39:
new file mode 100644

WARNING: line over 80 characters
#306: FILE: hw/virtio/virtio.c:4016:
+ monitor_printf(mon, " signalled_used_valid: %d\n", s->signalled_used_valid);

ERROR: "foo * bar" should be "foo *bar"
#330: FILE: hw/virtio/virtio.c:4164:
+ type##FeatureList * list = features->u.field.features; \

total: 1 errors, 2 warnings, 473 lines checked

Patch 6/6 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]