Skip to contentSkip to conversation

Adjust the output of x-query-virtio-status

PATCH Superseded Hyman Huang 3 participants 14 messages Feb 2, 2024 – Feb 21, 2024 Arm/Amlogic Meson SoC support

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Adjust the output of x-query-virtio-status

Sorry for the late post of version 3. The modifications are as follows:

v3:
- Rebase on master
- Use the refined commit message furnished by Markus for [PATCH v2 1/2]
- Drop the [PATCH v2 2/2]
- Add [PATCH v3 2/3] to declare the decoding functions to static
- Add [PATCH v3 3/3] to Define VhostDeviceProtocols and VirtioDeviceFeatures as plain C types

Since Markus inspired all of the alterations above, we would like to thank him for his contribution to this series.

Please review,
Yong

v2:
- Changing the hmp_virtio_dump_xxx function signatures to implement the bitmap decoding, suggested by Philippe.

This patchset is derived from the series:
https://lore.kernel.org/qemu-devel/[email protected]/
Please go to the link to see more background information.

The following points are what we have done in the patchset:
1. Take the policy of adding human-readable output just in HMP.
2. For the HMP output, display the human-readable information and drop the unknown bits in practice.
3. For the QMP output, remove the descriptive strings and only display bits encoded as numbers.

Hyman Huang (3):
qmp: Switch x-query-virtio-status back to numeric encoding
virtio: Declare the decoding functions to static
qapi: Define VhostDeviceProtocols and VirtioDeviceFeatures as plain C
types

 hw/virtio/meson.build       |   3 +-
 hw/virtio/virtio-hmp-cmds.c | 702 +++++++++++++++++++++++++++++++++++-
 hw/virtio/virtio-qmp.c      | 684 +----------------------------------
 hw/virtio/virtio-qmp.h      |   3 -
 qapi/virtio.json            | 231 +-----------
 5 files changed, 723 insertions(+), 900 deletions(-)
Signature · 1 line
2.31.1
#10 lore raw

PATCH v3 3/3 qapi: Define VhostDeviceProtocols and VirtioDeviceFeatures as plain C types

VhostDeviceProtocols and VirtioDeviceFeatures are only used in virtio-hmp-cmds.c. So define them as plain C types there, and drop them from the QAPI schema.

---
 hw/virtio/virtio-hmp-cmds.c | 16 +++++++++++++++
 qapi/virtio.json            | 39 -------------------------------------
 2 files changed, 16 insertions(+), 39 deletions(-)
hw/virtio/virtio-hmp-cmds.c +16 -0
index f95bad0069..045b472228 100644
@@ -29,6 +29,22 @@
 
 #include CONFIG_DEVICES
 
+typedef struct VhostDeviceProtocols VhostDeviceProtocols;
+struct VhostDeviceProtocols {
+    strList *protocols;
+    bool has_unknown_protocols;
+    uint64_t unknown_protocols;
+};
+
+typedef struct VirtioDeviceFeatures VirtioDeviceFeatures;
+struct VirtioDeviceFeatures {
+    strList *transports;
+    bool has_dev_features;
+    strList *dev_features;
+    bool has_unknown_dev_features;
+    uint64_t unknown_dev_features;
+};
+
 #define FEATURE_ENTRY(name, desc) (qmp_virtio_feature_map_t) \
     { .virtio_bit = name, .feature_desc = desc }
 
qapi/virtio.json +0 -39
index 26516fb29c..42dbc87f2f 100644
@@ -300,45 +300,6 @@
   'data': { 'statuses': [ 'str' ],
             '*unknown-statuses': 'uint8' } }
 
-##
-# @VhostDeviceProtocols:
-#
-# A structure defined to list the vhost user protocol features of a
-# Vhost User device
-#
-# @protocols: List of decoded vhost user protocol features of a vhost
-#     user device
-#
-# @unknown-protocols: Vhost user device protocol features bitmap that
-#     have not been decoded
-#
-# Since: 7.2
-##
-{ 'struct': 'VhostDeviceProtocols',
-  'data': { 'protocols': [ 'str' ],
-            '*unknown-protocols': 'uint64' } }
-
-##
-# @VirtioDeviceFeatures:
-#
-# The common fields that apply to most Virtio devices.  Some devices
-# may not have their own device-specific features (e.g. virtio-rng).
-#
-# @transports: List of transport features of the virtio device
-#
-# @dev-features: List of device-specific features (if the device has
-#     unique features)
-#
-# @unknown-dev-features: Virtio device features bitmap that have not
-#     been decoded
-#
-# Since: 7.2
-##
-{ 'struct': 'VirtioDeviceFeatures',
-  'data': { 'transports': [ 'str' ],
-            '*dev-features': [ 'str' ],
-            '*unknown-dev-features': 'uint64' } }
-
 ##
 # @VirtQueueStatus:
 #
Signature · 1 line
2.31.1
#7 lore raw

PATCH v3 2/3 virtio: Declare the decoding functions to static

In reply to Hyman Huang

qmp_decode_protocols(), qmp_decode_status(), and qmp_decode_features() are now only used in virtio-hmp-cmds.c. So move them into there, redeclare them to static, and replace the qmp_ prefix with hmp_.

---
 hw/virtio/meson.build       |   3 +-
 hw/virtio/virtio-hmp-cmds.c | 677 +++++++++++++++++++++++++++++++++++-
 hw/virtio/virtio-qmp.c      | 661 -----------------------------------
 hw/virtio/virtio-qmp.h      |   3 -
 4 files changed, 670 insertions(+), 674 deletions(-)
hw/virtio/meson.build +1 -2
index 47baf00366..6665669480 100644
@@ -9,7 +9,7 @@ system_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev.c')
 
 specific_virtio_ss = ss.source_set()
 specific_virtio_ss.add(files('virtio.c'))
-specific_virtio_ss.add(files('virtio-config-io.c', 'virtio-qmp.c'))
+specific_virtio_ss.add(files('virtio-config-io.c', 'virtio-qmp.c', 'virtio-hmp-cmds.c'))
 
 if have_vhost
   system_virtio_ss.add(files('vhost.c'))
@@ -74,7 +74,6 @@ specific_virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss)
 system_ss.add_all(when: 'CONFIG_VIRTIO', if_true: system_virtio_ss)
 system_ss.add(when: 'CONFIG_VIRTIO', if_false: files('vhost-stub.c'))
 system_ss.add(when: 'CONFIG_VIRTIO', if_false: files('virtio-stub.c'))
-system_ss.add(files('virtio-hmp-cmds.c'))
 
 specific_ss.add_all(when: 'CONFIG_VIRTIO', if_true: specific_virtio_ss)
 system_ss.add(when: 'CONFIG_ACPI', if_true: files('virtio-acpi.c'))
hw/virtio/virtio-hmp-cmds.c +669 -8

708 lines not on this page · raw message

hw/virtio/virtio-qmp.c +0 -661

667 lines not on this page · raw message

hw/virtio/virtio-qmp.h +0 -3
index 245a446a56..7aa1bb3c08 100644
@@ -16,8 +16,5 @@
 #include "hw/virtio/vhost.h"
 
 VirtIODevice *qmp_find_virtio_device(const char *path);
-VirtioDeviceStatus *qmp_decode_status(uint8_t bitmap);
-VhostDeviceProtocols *qmp_decode_protocols(uint64_t bitmap);
-VirtioDeviceFeatures *qmp_decode_features(uint16_t device_id, uint64_t bitmap);
 
 #endif
Signature · 1 line
2.31.1
#1 lore raw

PATCH v3 1/3 qmp: Switch x-query-virtio-status back to numeric encoding

In reply to Hyman Huang

x-query-virtio-status returns several sets of virtio feature and status flags. It goes back to v7.2.0.

In the initial commit 90c066cd682 (qmp: add QMP command x-query-virtio-status), we returned them as numbers, using virtio's well-known binary encoding.

The next commit f3034ad71fc (qmp: decode feature & status bits in virtio-status) replaced the numbers by objects. The objects represent bits QEMU knows symbolically, and any unknown bits numerically just like before.

Commit 8a8287981d1 (hmp: add virtio commands) the matching HMP command "info virtio" (and a few more, which aren't relevant here).

The symbolic representation uses lists of strings. The string format is undocumented. The strings look like "WELL_KNOWN_SYMBOL: human readable explanation".

This symbolic representation is nice for humans. Machines it can save the trouble of decoding virtio's well-known binary encoding.

However, we sometimes want to compare features and status bits without caring for their exact meaning. Say we want to verify the correctness of the virtio negotiation between guest, QEMU, and OVS-DPDK. We can use QMP command x-query-virtio-status to retrieve vhost-user net device features, and the "ovs-vsctl list interface" command to retrieve interface features. Without commit f3034ad71fc, we could then simply compare the numbers. With this commit, we first have to map from the strings back to the numeric encoding.

Revert the decoding for QMP, but keep it for HMP.

This makes the QMP command easier to use for use cases where we don't need to decode, like the comparison above. For use cases where we need to decode, we replace parsing undocumented strings by decoding virtio's well-known binary encoding.

Incompatible change; acceptable because x-query-virtio-status does comes without a stability promise.

---
 hw/virtio/virtio-hmp-cmds.c |  25 +++--
 hw/virtio/virtio-qmp.c      |  23 ++---
 qapi/virtio.json            | 192 ++++--------------------------------
 3 files changed, 45 insertions(+), 195 deletions(-)
hw/virtio/virtio-hmp-cmds.c +17 -8
index 477c97dea2..721c630ab0 100644
@@ -6,6 +6,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "virtio-qmp.h"
 #include "monitor/hmp.h"
 #include "monitor/monitor.h"
 #include "qapi/qapi-commands-virtio.h"
@@ -145,13 +146,17 @@ void hmp_virtio_status(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "  endianness:              %s\n",
                    s->device_endian);
     monitor_printf(mon, "  status:\n");
-    hmp_virtio_dump_status(mon, s->status);
+    hmp_virtio_dump_status(mon,
+        qmp_decode_status(s->status));
     monitor_printf(mon, "  Guest features:\n");
-    hmp_virtio_dump_features(mon, s->guest_features);
+    hmp_virtio_dump_features(mon,
+        qmp_decode_features(s->device_id, s->guest_features));
     monitor_printf(mon, "  Host features:\n");
-    hmp_virtio_dump_features(mon, s->host_features);
+    hmp_virtio_dump_features(mon,
+        qmp_decode_features(s->device_id, s->host_features));
     monitor_printf(mon, "  Backend features:\n");
-    hmp_virtio_dump_features(mon, s->backend_features);
+    hmp_virtio_dump_features(mon,
+        qmp_decode_features(s->device_id, s->backend_features));
 
     if (s->vhost_dev) {
         monitor_printf(mon, "  VHost:\n");
@@ -172,13 +177,17 @@ void hmp_virtio_status(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, "    log_size:       %"PRId64"\n",
                        s->vhost_dev->log_size);
         monitor_printf(mon, "    Features:\n");
-        hmp_virtio_dump_features(mon, s->vhost_dev->features);
+        hmp_virtio_dump_features(mon,
+            qmp_decode_features(s->device_id, s->vhost_dev->features));
         monitor_printf(mon, "    Acked features:\n");
-        hmp_virtio_dump_features(mon, s->vhost_dev->acked_features);
+        hmp_virtio_dump_features(mon,
+            qmp_decode_features(s->device_id, s->vhost_dev->acked_features));
         monitor_printf(mon, "    Backend features:\n");
-        hmp_virtio_dump_features(mon, s->vhost_dev->backend_features);
+        hmp_virtio_dump_features(mon,
+            qmp_decode_features(s->device_id, s->vhost_dev->backend_features));
         monitor_printf(mon, "    Protocol features:\n");
-        hmp_virtio_dump_protocols(mon, s->vhost_dev->protocol_features);
+        hmp_virtio_dump_protocols(mon,
+            qmp_decode_protocols(s->vhost_dev->protocol_features));
     }
 
     qapi_free_VirtioStatus(s);
hw/virtio/virtio-qmp.c +8 -15
index 1dd96ed20f..1660c17653 100644
@@ -733,12 +733,9 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
     status->name = g_strdup(vdev->name);
     status->device_id = vdev->device_id;
     status->vhost_started = vdev->vhost_started;
-    status->guest_features = qmp_decode_features(vdev->device_id,
-                                                 vdev->guest_features);
-    status->host_features = qmp_decode_features(vdev->device_id,
-                                                vdev->host_features);
-    status->backend_features = qmp_decode_features(vdev->device_id,
-                                                   vdev->backend_features);
+    status->guest_features = vdev->guest_features;
+    status->host_features = vdev->host_features;
+    status->backend_features = vdev->backend_features;
 
     switch (vdev->device_endian) {
     case VIRTIO_DEVICE_ENDIAN_LITTLE:
@@ -753,7 +750,7 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
     }
 
     status->num_vqs = virtio_get_num_queues(vdev);
-    status->status = qmp_decode_status(vdev->status);
+    status->status = vdev->status;
     status->isr = vdev->isr;
     status->queue_sel = vdev->queue_sel;
     status->vm_running = vdev->vm_running;
@@ -775,14 +772,10 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
         status->vhost_dev->n_tmp_sections = hdev->n_tmp_sections;
         status->vhost_dev->nvqs = hdev->nvqs;
         status->vhost_dev->vq_index = hdev->vq_index;
-        status->vhost_dev->features =
-            qmp_decode_features(vdev->device_id, hdev->features);
-        status->vhost_dev->acked_features =
-            qmp_decode_features(vdev->device_id, hdev->acked_features);
-        status->vhost_dev->backend_features =
-            qmp_decode_features(vdev->device_id, hdev->backend_features);
-        status->vhost_dev->protocol_features =
-            qmp_decode_protocols(hdev->protocol_features);
+        status->vhost_dev->features = hdev->features;
+        status->vhost_dev->acked_features = hdev->acked_features;
+        status->vhost_dev->backend_features = hdev->backend_features;
+        status->vhost_dev->protocol_features = hdev->protocol_features;
         status->vhost_dev->max_queues = hdev->max_queues;
         status->vhost_dev->backend_cap = hdev->backend_cap;
         status->vhost_dev->log_enabled = hdev->log_enabled;
qapi/virtio.json +20 -172

229 lines not on this page · raw message

Signature · 1 line
2.31.1
#12 lore raw
In reply to Hyman Huang
Quoted 10 lines · Hyman Huang

Sorry for the late post of version 3. The modifications are as follows:

v3:
- Rebase on master
- Use the refined commit message furnished by Markus for [PATCH v2 1/2]
- Drop the [PATCH v2 2/2]
- Add [PATCH v3 2/3] to declare the decoding functions to static
- Add [PATCH v3 3/3] to Define VhostDeviceProtocols and VirtioDeviceFeatures as plain C types

Quoted 5 lines

Since Markus inspired all of the alterations above, we would like to thank him for his contribution to this series.

Please review,
Yong

Markus do you think you can take a look at this?

Quoted 30 lines

v2:
- Changing the hmp_virtio_dump_xxx function signatures to implement the bitmap decoding, suggested by Philippe.

This patchset is derived from the series:
https://lore.kernel.org/qemu-devel/[email protected]/
Please go to the link to see more background information.

The following points are what we have done in the patchset:
1. Take the policy of adding human-readable output just in HMP.
2. For the HMP output, display the human-readable information and drop the unknown bits in practice.
3. For the QMP output, remove the descriptive strings and only display bits encoded as numbers.

Hyman Huang (3):
qmp: Switch x-query-virtio-status back to numeric encoding
virtio: Declare the decoding functions to static
qapi: Define VhostDeviceProtocols and VirtioDeviceFeatures as plain C
types

 hw/virtio/meson.build       |   3 +-
 hw/virtio/virtio-hmp-cmds.c | 702 +++++++++++++++++++++++++++++++++++-
 hw/virtio/virtio-qmp.c      | 684 +----------------------------------
 hw/virtio/virtio-qmp.h      |   3 -
 qapi/virtio.json            | 231 +-----------
 5 files changed, 723 insertions(+), 900 deletions(-)
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH v3 1/3] qmp: Switch x-query-virtio-status back to numeric encoding

In reply to Hyman Huang
Quoted 31 lines · Hyman Huang

x-query-virtio-status returns several sets of virtio feature and status flags. It goes back to v7.2.0.

In the initial commit 90c066cd682 (qmp: add QMP command x-query-virtio-status), we returned them as numbers, using virtio's well-known binary encoding.

The next commit f3034ad71fc (qmp: decode feature & status bits in virtio-status) replaced the numbers by objects. The objects represent bits QEMU knows symbolically, and any unknown bits numerically just like before.

Commit 8a8287981d1 (hmp: add virtio commands) the matching HMP command "info virtio" (and a few more, which aren't relevant here).

The symbolic representation uses lists of strings. The string format is undocumented. The strings look like "WELL_KNOWN_SYMBOL: human readable explanation".

This symbolic representation is nice for humans. Machines it can save the trouble of decoding virtio's well-known binary encoding.

However, we sometimes want to compare features and status bits without caring for their exact meaning. Say we want to verify the correctness of the virtio negotiation between guest, QEMU, and OVS-DPDK. We can use QMP command x-query-virtio-status to retrieve vhost-user net device features, and the "ovs-vsctl list interface" command to retrieve interface features. Without commit f3034ad71fc, we could then simply compare the numbers. With this commit, we first have to map from the strings back to the numeric encoding.

Quoted 1 line

Revert the decoding for QMP, but keep it for HMP.

Is there a way to maybe have both decoded and numerical one? E.g. I mostly use QMP even when I read it myself.

Quoted 358 lines

This makes the QMP command easier to use for use cases where we don't need to decode, like the comparison above. For use cases where we need to decode, we replace parsing undocumented strings by decoding virtio's well-known binary encoding.

Incompatible change; acceptable because x-query-virtio-status does comes without a stability promise.

---
 hw/virtio/virtio-hmp-cmds.c |  25 +++--
 hw/virtio/virtio-qmp.c      |  23 ++---
 qapi/virtio.json            | 192 ++++--------------------------------
 3 files changed, 45 insertions(+), 195 deletions(-)
hw/virtio/virtio-hmp-cmds.c +17 -8
index 477c97dea2..721c630ab0 100644
@@ -6,6 +6,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "virtio-qmp.h"
 #include "monitor/hmp.h"
 #include "monitor/monitor.h"
 #include "qapi/qapi-commands-virtio.h"
@@ -145,13 +146,17 @@ void hmp_virtio_status(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "  endianness:              %s\n",
                    s->device_endian);
     monitor_printf(mon, "  status:\n");
-    hmp_virtio_dump_status(mon, s->status);
+    hmp_virtio_dump_status(mon,
+        qmp_decode_status(s->status));
     monitor_printf(mon, "  Guest features:\n");
-    hmp_virtio_dump_features(mon, s->guest_features);
+    hmp_virtio_dump_features(mon,
+        qmp_decode_features(s->device_id, s->guest_features));
     monitor_printf(mon, "  Host features:\n");
-    hmp_virtio_dump_features(mon, s->host_features);
+    hmp_virtio_dump_features(mon,
+        qmp_decode_features(s->device_id, s->host_features));
     monitor_printf(mon, "  Backend features:\n");
-    hmp_virtio_dump_features(mon, s->backend_features);
+    hmp_virtio_dump_features(mon,
+        qmp_decode_features(s->device_id, s->backend_features));
 
     if (s->vhost_dev) {
         monitor_printf(mon, "  VHost:\n");
@@ -172,13 +177,17 @@ void hmp_virtio_status(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, "    log_size:       %"PRId64"\n",
                        s->vhost_dev->log_size);
         monitor_printf(mon, "    Features:\n");
-        hmp_virtio_dump_features(mon, s->vhost_dev->features);
+        hmp_virtio_dump_features(mon,
+            qmp_decode_features(s->device_id, s->vhost_dev->features));
         monitor_printf(mon, "    Acked features:\n");
-        hmp_virtio_dump_features(mon, s->vhost_dev->acked_features);
+        hmp_virtio_dump_features(mon,
+            qmp_decode_features(s->device_id, s->vhost_dev->acked_features));
         monitor_printf(mon, "    Backend features:\n");
-        hmp_virtio_dump_features(mon, s->vhost_dev->backend_features);
+        hmp_virtio_dump_features(mon,
+            qmp_decode_features(s->device_id, s->vhost_dev->backend_features));
         monitor_printf(mon, "    Protocol features:\n");
-        hmp_virtio_dump_protocols(mon, s->vhost_dev->protocol_features);
+        hmp_virtio_dump_protocols(mon,
+            qmp_decode_protocols(s->vhost_dev->protocol_features));
     }
 
     qapi_free_VirtioStatus(s);
hw/virtio/virtio-qmp.c +8 -15
index 1dd96ed20f..1660c17653 100644
@@ -733,12 +733,9 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
     status->name = g_strdup(vdev->name);
     status->device_id = vdev->device_id;
     status->vhost_started = vdev->vhost_started;
-    status->guest_features = qmp_decode_features(vdev->device_id,
-                                                 vdev->guest_features);
-    status->host_features = qmp_decode_features(vdev->device_id,
-                                                vdev->host_features);
-    status->backend_features = qmp_decode_features(vdev->device_id,
-                                                   vdev->backend_features);
+    status->guest_features = vdev->guest_features;
+    status->host_features = vdev->host_features;
+    status->backend_features = vdev->backend_features;
 
     switch (vdev->device_endian) {
     case VIRTIO_DEVICE_ENDIAN_LITTLE:
@@ -753,7 +750,7 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
     }
 
     status->num_vqs = virtio_get_num_queues(vdev);
-    status->status = qmp_decode_status(vdev->status);
+    status->status = vdev->status;
     status->isr = vdev->isr;
     status->queue_sel = vdev->queue_sel;
     status->vm_running = vdev->vm_running;
@@ -775,14 +772,10 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
         status->vhost_dev->n_tmp_sections = hdev->n_tmp_sections;
         status->vhost_dev->nvqs = hdev->nvqs;
         status->vhost_dev->vq_index = hdev->vq_index;
-        status->vhost_dev->features =
-            qmp_decode_features(vdev->device_id, hdev->features);
-        status->vhost_dev->acked_features =
-            qmp_decode_features(vdev->device_id, hdev->acked_features);
-        status->vhost_dev->backend_features =
-            qmp_decode_features(vdev->device_id, hdev->backend_features);
-        status->vhost_dev->protocol_features =
-            qmp_decode_protocols(hdev->protocol_features);
+        status->vhost_dev->features = hdev->features;
+        status->vhost_dev->acked_features = hdev->acked_features;
+        status->vhost_dev->backend_features = hdev->backend_features;
+        status->vhost_dev->protocol_features = hdev->protocol_features;
         status->vhost_dev->max_queues = hdev->max_queues;
         status->vhost_dev->backend_cap = hdev->backend_cap;
         status->vhost_dev->log_enabled = hdev->log_enabled;
qapi/virtio.json +20 -172
index 19c7c36e36..26516fb29c 100644
@@ -102,10 +102,10 @@
             'n-tmp-sections': 'int',
             'nvqs': 'uint32',
             'vq-index': 'int',
-            'features': 'VirtioDeviceFeatures',
-            'acked-features': 'VirtioDeviceFeatures',
-            'backend-features': 'VirtioDeviceFeatures',
-            'protocol-features': 'VhostDeviceProtocols',
+            'features': 'uint64',
+            'acked-features': 'uint64',
+            'backend-features': 'uint64',
+            'protocol-features': 'uint64',
             'max-queues': 'uint64',
             'backend-cap': 'uint64',
             'log-enabled': 'bool',
@@ -170,11 +170,11 @@
             'device-id': 'uint16',
             'vhost-started': 'bool',
             'device-endian': 'str',
-            'guest-features': 'VirtioDeviceFeatures',
-            'host-features': 'VirtioDeviceFeatures',
-            'backend-features': 'VirtioDeviceFeatures',
+            'guest-features': 'uint64',
+            'host-features': 'uint64',
+            'backend-features': 'uint64',
             'num-vqs': 'int',
-            'status': 'VirtioDeviceStatus',
+            'status': 'uint8',
             'isr': 'uint8',
             'queue-sel': 'uint16',
             'vm-running': 'bool',
@@ -217,41 +217,14 @@
 #          "name": "virtio-crypto",
 #          "started": true,
 #          "device-id": 20,
-#          "backend-features": {
-#              "transports": [],
-#              "dev-features": []
-#          },
+#          "backend-features": 0,
 #          "start-on-kick": false,
 #          "isr": 1,
 #          "broken": false,
-#          "status": {
-#              "statuses": [
-#                  "VIRTIO_CONFIG_S_ACKNOWLEDGE: Valid virtio device found",
-#                  "VIRTIO_CONFIG_S_DRIVER: Guest OS compatible with device",
-#                  "VIRTIO_CONFIG_S_FEATURES_OK: Feature negotiation complete",
-#                  "VIRTIO_CONFIG_S_DRIVER_OK: Driver setup and ready"
-#              ]
-#          },
+#          "status": 15,
 #          "num-vqs": 2,
-#          "guest-features": {
-#              "dev-features": [],
-#              "transports": [
-#                  "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
-#                  "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
-#                  "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)"
-#              ]
-#          },
-#          "host-features": {
-#              "unknown-dev-features": 1073741824,
-#              "dev-features": [],
-#              "transports": [
-#                  "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
-#                  "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
-#                  "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)",
-#                  "VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts",
-#                  "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ"
-#              ]
-#          },
+#          "guest-features": 5100273664,
+#          "host-features": 6325010432,
 #          "use-guest-notifier-mask": true,
 #          "vm-running": true,
 #          "queue-sel": 1,
@@ -279,147 +252,22 @@
 #              "max-queues": 1,
 #              "backend-cap": 2,
 #              "log-size": 0,
-#              "backend-features": {
-#                  "dev-features": [],
-#                  "transports": []
-#              },
+#              "backend-features": 0,
 #              "nvqs": 2,
-#              "protocol-features": {
-#                  "protocols": []
-#              },
+#              "protocol-features": 0,
 #              "vq-index": 0,
 #              "log-enabled": false,
-#              "acked-features": {
-#                  "dev-features": [
-#                      "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive buffers"
-#                  ],
-#                  "transports": [
-#                      "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
-#                      "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
-#                      "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)"
-#                  ]
-#              },
-#              "features": {
-#                  "dev-features": [
-#                      "VHOST_F_LOG_ALL: Logging write descriptors supported",
-#                      "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive buffers"
-#                  ],
-#                  "transports": [
-#                      "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
-#                      "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
-#                      "VIRTIO_F_IOMMU_PLATFORM: Device can be used on IOMMU platform",
-#                      "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)",
-#                      "VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts",
-#                      "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ"
-#                  ]
-#              }
-#          },
-#          "backend-features": {
-#              "dev-features": [
-#                  "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features negotiation supported",
-#                  "VIRTIO_NET_F_GSO: Handling GSO-type packets supported",
-#                  "VIRTIO_NET_F_CTRL_MAC_ADDR: MAC address set through control channel",
-#                  "VIRTIO_NET_F_GUEST_ANNOUNCE: Driver sending gratuitous packets supported",
-#                  "VIRTIO_NET_F_CTRL_RX_EXTRA: Extra RX mode control supported",
-#                  "VIRTIO_NET_F_CTRL_VLAN: Control channel VLAN filtering supported",
-#                  "VIRTIO_NET_F_CTRL_RX: Control channel RX mode supported",
-#                  "VIRTIO_NET_F_CTRL_VQ: Control channel available",
-#                  "VIRTIO_NET_F_STATUS: Configuration status field available",
-#                  "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive buffers",
-#                  "VIRTIO_NET_F_HOST_UFO: Device can receive UFO",
-#                  "VIRTIO_NET_F_HOST_ECN: Device can receive TSO with ECN",
-#                  "VIRTIO_NET_F_HOST_TSO6: Device can receive TSOv6",
-#                  "VIRTIO_NET_F_HOST_TSO4: Device can receive TSOv4",
-#                  "VIRTIO_NET_F_GUEST_UFO: Driver can receive UFO",
-#                  "VIRTIO_NET_F_GUEST_ECN: Driver can receive TSO with ECN",
-#                  "VIRTIO_NET_F_GUEST_TSO6: Driver can receive TSOv6",
-#                  "VIRTIO_NET_F_GUEST_TSO4: Driver can receive TSOv4",
-#                  "VIRTIO_NET_F_MAC: Device has given MAC address",
-#                  "VIRTIO_NET_F_CTRL_GUEST_OFFLOADS: Control channel offloading reconfig. supported",
-#                  "VIRTIO_NET_F_GUEST_CSUM: Driver handling packets with partial checksum supported",
-#                  "VIRTIO_NET_F_CSUM: Device handling packets with partial checksum supported"
-#              ],
-#              "transports": [
-#                  "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
-#                  "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
-#                  "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)",
-#                  "VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts",
-#                  "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ"
-#              ]
+#              "acked-features": 5100306432,
+#              "features": 13908344832,
 #          },
+#          "backend-features": 6337593319,
 #          "start-on-kick": false,
 #          "isr": 1,
 #          "broken": false,
-#          "status": {
-#              "statuses": [
-#                  "VIRTIO_CONFIG_S_ACKNOWLEDGE: Valid virtio device found",
-#                  "VIRTIO_CONFIG_S_DRIVER: Guest OS compatible with device",
-#                  "VIRTIO_CONFIG_S_FEATURES_OK: Feature negotiation complete",
-#                  "VIRTIO_CONFIG_S_DRIVER_OK: Driver setup and ready"
-#              ]
-#          },
+#          "status": 15,
 #          "num-vqs": 3,
-#          "guest-features": {
-#              "dev-features": [
-#                  "VIRTIO_NET_F_CTRL_MAC_ADDR: MAC address set through control channel",
-#                  "VIRTIO_NET_F_GUEST_ANNOUNCE: Driver sending gratuitous packets supported",
-#                  "VIRTIO_NET_F_CTRL_VLAN: Control channel VLAN filtering supported",
-#                  "VIRTIO_NET_F_CTRL_RX: Control channel RX mode supported",
-#                  "VIRTIO_NET_F_CTRL_VQ: Control channel available",
-#                  "VIRTIO_NET_F_STATUS: Configuration status field available",
-#                  "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive buffers",
-#                  "VIRTIO_NET_F_HOST_UFO: Device can receive UFO",
-#                  "VIRTIO_NET_F_HOST_ECN: Device can receive TSO with ECN",
-#                  "VIRTIO_NET_F_HOST_TSO6: Device can receive TSOv6",
-#                  "VIRTIO_NET_F_HOST_TSO4: Device can receive TSOv4",
-#                  "VIRTIO_NET_F_GUEST_UFO: Driver can receive UFO",
-#                  "VIRTIO_NET_F_GUEST_ECN: Driver can receive TSO with ECN",
-#                  "VIRTIO_NET_F_GUEST_TSO6: Driver can receive TSOv6",
-#                  "VIRTIO_NET_F_GUEST_TSO4: Driver can receive TSOv4",
-#                  "VIRTIO_NET_F_MAC: Device has given MAC address",
-#                  "VIRTIO_NET_F_CTRL_GUEST_OFFLOADS: Control channel offloading reconfig. supported",
-#                  "VIRTIO_NET_F_GUEST_CSUM: Driver handling packets with partial checksum supported",
-#                  "VIRTIO_NET_F_CSUM: Device handling packets with partial checksum supported"
-#              ],
-#              "transports": [
-#                  "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
-#                  "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
-#                  "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)"
-#             ]
-#          },
-#          "host-features": {
-#              "dev-features": [
-#                  "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features negotiation supported",
-#                  "VIRTIO_NET_F_GSO: Handling GSO-type packets supported",
-#                  "VIRTIO_NET_F_CTRL_MAC_ADDR: MAC address set through control channel",
-#                  "VIRTIO_NET_F_GUEST_ANNOUNCE: Driver sending gratuitous packets supported",
-#                  "VIRTIO_NET_F_CTRL_RX_EXTRA: Extra RX mode control supported",
-#                  "VIRTIO_NET_F_CTRL_VLAN: Control channel VLAN filtering supported",
-#                  "VIRTIO_NET_F_CTRL_RX: Control channel RX mode supported",
-#                  "VIRTIO_NET_F_CTRL_VQ: Control channel available",
-#                  "VIRTIO_NET_F_STATUS: Configuration status field available",
-#                  "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive buffers",
-#                  "VIRTIO_NET_F_HOST_UFO: Device can receive UFO",
-#                  "VIRTIO_NET_F_HOST_ECN: Device can receive TSO with ECN",
-#                  "VIRTIO_NET_F_HOST_TSO6: Device can receive TSOv6",
-#                  "VIRTIO_NET_F_HOST_TSO4: Device can receive TSOv4",
-#                  "VIRTIO_NET_F_GUEST_UFO: Driver can receive UFO",
-#                  "VIRTIO_NET_F_GUEST_ECN: Driver can receive TSO with ECN",
-#                  "VIRTIO_NET_F_GUEST_TSO6: Driver can receive TSOv6",
-#                  "VIRTIO_NET_F_GUEST_TSO4: Driver can receive TSOv4",
-#                  "VIRTIO_NET_F_MAC: Device has given MAC address",
-#                  "VIRTIO_NET_F_CTRL_GUEST_OFFLOADS: Control channel offloading reconfig. supported",
-#                  "VIRTIO_NET_F_GUEST_CSUM: Driver handling packets with partial checksum supported",
-#                  "VIRTIO_NET_F_CSUM: Device handling packets with partial checksum supported"
-#              ],
-#              "transports": [
-#                  "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled",
-#                  "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported",
-#                  "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)",
-#                  "VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts",
-#                  "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ"
-#             ]
-#          },
+#          "guest-features": 5111807911,
+#          "host-features": 6337593319,
 #          "use-guest-notifier-mask": true,
 #          "vm-running": true,
 #          "queue-sel": 2,
Signature · 1 line
2.31.1
#13 lore raw
In reply to Michael S. Tsirkin
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Hyman Huang

Sorry for the late post of version 3. The modifications are as follows:

v3:
- Rebase on master
- Use the refined commit message furnished by Markus for [PATCH v2 1/2]
- Drop the [PATCH v2 2/2]
- Add [PATCH v3 2/3] to declare the decoding functions to static
- Add [PATCH v3 3/3] to Define VhostDeviceProtocols and VirtioDeviceFeatures as plain C types

Quoted 7 lines
Quoted 5 lines

Since Markus inspired all of the alterations above, we would like to thank him for his contribution to this series.

Please review,
Yong

Markus do you think you can take a look at this?

I intend to. Sorry for the delay!

author
#3 lore raw

Re: [PATCH v3 1/3] qmp: Switch x-query-virtio-status back to numeric encoding

In reply to Michael S. Tsirkin
Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Hyman Huang

x-query-virtio-status returns several sets of virtio feature and status flags. It goes back to v7.2.0.

In the initial commit 90c066cd682 (qmp: add QMP command x-query-virtio-status), we returned them as numbers, using virtio's well-known binary encoding.

The next commit f3034ad71fc (qmp: decode feature & status bits in virtio-status) replaced the numbers by objects. The objects represent bits QEMU knows symbolically, and any unknown bits numerically just like before.

Commit 8a8287981d1 (hmp: add virtio commands) the matching HMP command "info virtio" (and a few more, which aren't relevant here).

The symbolic representation uses lists of strings. The string format is undocumented. The strings look like "WELL_KNOWN_SYMBOL: human readable explanation".

This symbolic representation is nice for humans. Machines it can save the trouble of decoding virtio's well-known binary encoding.

However, we sometimes want to compare features and status bits without caring for their exact meaning. Say we want to verify the correctness of the virtio negotiation between guest, QEMU, and OVS-DPDK. We can use QMP command x-query-virtio-status to retrieve vhost-user net device features, and the "ovs-vsctl list interface" command to retrieve interface features. Without commit f3034ad71fc, we could then simply compare the numbers. With this commit, we first have to map from the strings back to the numeric encoding.

Quoted 4 lines
Quoted 1 line

Revert the decoding for QMP, but keep it for HMP.

Is there a way to maybe have both decoded and numerical one?

What if the next patch went back to this implementation in the following patch? All you need to do is add a matching xxx_bits entry for each feature and status.

https://patchew.org/QEMU/[email protected]/3c7161a47b141af04b1f8272e8e24c5faa46ddb2.1700319559.git.yong.huang@smartx.com/

E.g. I mostly use QMP even when I read it myself.

Quoted 1 line

Thus, it is recommended that both numerical and decoded types be kept for QMP; this approach can be at odds with what was previously discussed. What do you think about this, Markus?

Quoted 447 lines

hw/virtio/virtio-hmp-cmds.c void hmp_virtio_status(Monitor *mon, const QDict

Quoted 28 lines

This makes the QMP command easier to use for use cases where we don't need to decode, like the comparison above. For use cases where we need to decode, we replace parsing undocumented strings by decoding virtio's well-known binary encoding.

Incompatible change; acceptable because x-query-virtio-status does comes without a stability promise.

---
 hw/virtio/virtio-hmp-cmds.c |  25 +++--
 hw/virtio/virtio-qmp.c      |  23 ++---
 qapi/virtio.json            | 192 ++++--------------------------------
 3 files changed, 45 insertions(+), 195 deletions(-)
hw/virtio/virtio-hmp-cmds.c +1 -0
index 477c97dea2..721c630ab0 100644
@@ -6,6 +6,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "virtio-qmp.h"
 #include "monitor/hmp.h"
 #include "monitor/monitor.h"
 #include "qapi/qapi-commands-virtio.h"
@@ -145,13 +146,17 @@ void hmp_virtio_status(Monitor *mon, const QDict

*qdict)

hw/virtio/virtio-hmp-cmds.c void hmp_virtio_status(Monitor *mon, const QDict

Quoted 22 lines
hw/virtio/virtio-hmp-cmds.c +8 -4
     monitor_printf(mon, "  endianness:              %s\n",
                    s->device_endian);
     monitor_printf(mon, "  status:\n");
-    hmp_virtio_dump_status(mon, s->status);
+    hmp_virtio_dump_status(mon,
+        qmp_decode_status(s->status));
     monitor_printf(mon, "  Guest features:\n");
-    hmp_virtio_dump_features(mon, s->guest_features);
+    hmp_virtio_dump_features(mon,
+        qmp_decode_features(s->device_id, s->guest_features));
     monitor_printf(mon, "  Host features:\n");
-    hmp_virtio_dump_features(mon, s->host_features);
+    hmp_virtio_dump_features(mon,
+        qmp_decode_features(s->device_id, s->host_features));
     monitor_printf(mon, "  Backend features:\n");
-    hmp_virtio_dump_features(mon, s->backend_features);
+    hmp_virtio_dump_features(mon,
+        qmp_decode_features(s->device_id, s->backend_features));
 
     if (s->vhost_dev) {
         monitor_printf(mon, "  VHost:\n");
@@ -172,13 +177,17 @@ void hmp_virtio_status(Monitor *mon, const QDict

*qdict)

hw/virtio/virtio-hmp-cmds.c void hmp_virtio_status(Monitor *mon, const QDict *qdict)

Quoted 10 lines
hw/virtio/virtio-hmp-cmds.c +4 -2
         monitor_printf(mon, "    log_size:       %"PRId64"\n",
                        s->vhost_dev->log_size);
         monitor_printf(mon, "    Features:\n");
-        hmp_virtio_dump_features(mon, s->vhost_dev->features);
+        hmp_virtio_dump_features(mon,
+            qmp_decode_features(s->device_id, s->vhost_dev->features));
         monitor_printf(mon, "    Acked features:\n");
-        hmp_virtio_dump_features(mon, s->vhost_dev->acked_features);
+        hmp_virtio_dump_features(mon,
+            qmp_decode_features(s->device_id,

s->vhost_dev->acked_features));

hw/virtio/virtio-hmp-cmds.c void hmp_virtio_status(Monitor *mon, const QDict *qdict)

Quoted 4 lines
hw/virtio/virtio-hmp-cmds.c +2 -1
         monitor_printf(mon, "    Backend features:\n");
-        hmp_virtio_dump_features(mon, s->vhost_dev->backend_features);
+        hmp_virtio_dump_features(mon,
+            qmp_decode_features(s->device_id,

s->vhost_dev->backend_features));

hw/virtio/virtio-qmp.c VirtioStatus *qmp_x_query_virtio_status(const char

Quoted 12 lines
hw/virtio/virtio-hmp-cmds.c +2 -1
         monitor_printf(mon, "    Protocol features:\n");
-        hmp_virtio_dump_protocols(mon, s->vhost_dev->protocol_features);
+        hmp_virtio_dump_protocols(mon,
+            qmp_decode_protocols(s->vhost_dev->protocol_features));
     }
 
     qapi_free_VirtioStatus(s);
hw/virtio/virtio-qmp.c +0 -0
index 1dd96ed20f..1660c17653 100644
@@ -733,12 +733,9 @@ VirtioStatus *qmp_x_query_virtio_status(const char

*path, Error **errp)

hw/virtio/virtio-qmp.c VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)

Quoted 9 lines
hw/virtio/virtio-qmp.c +0 -6
     status->name = g_strdup(vdev->name);
     status->device_id = vdev->device_id;
     status->vhost_started = vdev->vhost_started;
-    status->guest_features = qmp_decode_features(vdev->device_id,
-                                                 vdev->guest_features);
-    status->host_features = qmp_decode_features(vdev->device_id,
-                                                vdev->host_features);
-    status->backend_features = qmp_decode_features(vdev->device_id,
-

vdev->backend_features);

hw/virtio/virtio-qmp.c VirtioStatus *qmp_x_query_virtio_status(const char

Quoted 7 lines
hw/virtio/virtio-qmp.c +3 -0
+    status->guest_features = vdev->guest_features;
+    status->host_features = vdev->host_features;
+    status->backend_features = vdev->backend_features;
 
     switch (vdev->device_endian) {
     case VIRTIO_DEVICE_ENDIAN_LITTLE:
@@ -753,7 +750,7 @@ VirtioStatus *qmp_x_query_virtio_status(const char

*path, Error **errp)

hw/virtio/virtio-qmp.c VirtioStatus *qmp_x_query_virtio_status(const char

Quoted 9 lines
hw/virtio/virtio-qmp.c +1 -1
     }
 
     status->num_vqs = virtio_get_num_queues(vdev);
-    status->status = qmp_decode_status(vdev->status);
+    status->status = vdev->status;
     status->isr = vdev->isr;
     status->queue_sel = vdev->queue_sel;
     status->vm_running = vdev->vm_running;
@@ -775,14 +772,10 @@ VirtioStatus *qmp_x_query_virtio_status(const char

*path, Error **errp)

hw/virtio/virtio-qmp.c VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)

Quoted 9 lines
hw/virtio/virtio-qmp.c +0 -6
         status->vhost_dev->n_tmp_sections = hdev->n_tmp_sections;
         status->vhost_dev->nvqs = hdev->nvqs;
         status->vhost_dev->vq_index = hdev->vq_index;
-        status->vhost_dev->features =
-            qmp_decode_features(vdev->device_id, hdev->features);
-        status->vhost_dev->acked_features =
-            qmp_decode_features(vdev->device_id, hdev->acked_features);
-        status->vhost_dev->backend_features =
-            qmp_decode_features(vdev->device_id,

hdev->backend_features);

Quoted 49 lines
hw/virtio/virtio-qmp.c +4 -2
-        status->vhost_dev->protocol_features =
-            qmp_decode_protocols(hdev->protocol_features);
+        status->vhost_dev->features = hdev->features;
+        status->vhost_dev->acked_features = hdev->acked_features;
+        status->vhost_dev->backend_features = hdev->backend_features;
+        status->vhost_dev->protocol_features = hdev->protocol_features;
         status->vhost_dev->max_queues = hdev->max_queues;
         status->vhost_dev->backend_cap = hdev->backend_cap;
         status->vhost_dev->log_enabled = hdev->log_enabled;
qapi/virtio.json +8 -9
index 19c7c36e36..26516fb29c 100644
@@ -102,10 +102,10 @@
             'n-tmp-sections': 'int',
             'nvqs': 'uint32',
             'vq-index': 'int',
-            'features': 'VirtioDeviceFeatures',
-            'acked-features': 'VirtioDeviceFeatures',
-            'backend-features': 'VirtioDeviceFeatures',
-            'protocol-features': 'VhostDeviceProtocols',
+            'features': 'uint64',
+            'acked-features': 'uint64',
+            'backend-features': 'uint64',
+            'protocol-features': 'uint64',
             'max-queues': 'uint64',
             'backend-cap': 'uint64',
             'log-enabled': 'bool',
@@ -170,11 +170,11 @@
             'device-id': 'uint16',
             'vhost-started': 'bool',
             'device-endian': 'str',
-            'guest-features': 'VirtioDeviceFeatures',
-            'host-features': 'VirtioDeviceFeatures',
-            'backend-features': 'VirtioDeviceFeatures',
+            'guest-features': 'uint64',
+            'host-features': 'uint64',
+            'backend-features': 'uint64',
             'num-vqs': 'int',
-            'status': 'VirtioDeviceStatus',
+            'status': 'uint8',
             'isr': 'uint8',
             'queue-sel': 'uint16',
             'vm-running': 'bool',
@@ -217,41 +217,14 @@
 #          "name": "virtio-crypto",
 #          "started": true,
 #          "device-id": 20,
-#          "backend-features": {

qapi/virtio.json line 229

Quoted 10 lines
qapi/virtio.json +1 -6
-#              "transports": [],
-#              "dev-features": []
-#          },
+#          "backend-features": 0,
 #          "start-on-kick": false,
 #          "isr": 1,
 #          "broken": false,
-#          "status": {
-#              "statuses": [
-#                  "VIRTIO_CONFIG_S_ACKNOWLEDGE: Valid virtio device

found",

qapi/virtio.json line 230

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_CONFIG_S_DRIVER: Guest OS compatible with

device",

qapi/virtio.json line 231

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_CONFIG_S_FEATURES_OK: Feature negotiation

complete",

qapi/virtio.json

Quoted 9 lines
qapi/virtio.json +1 -7
-#                  "VIRTIO_CONFIG_S_DRIVER_OK: Driver setup and ready"
-#              ]
-#          },
+#          "status": 15,
 #          "num-vqs": 2,
-#          "guest-features": {
-#              "dev-features": [],
-#              "transports": [
-#                  "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields

enabled",

qapi/virtio.json line 240

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors

supported",

qapi/virtio.json line 241

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_F_VERSION_1: Device compliant for v1 spec

(legacy)"

qapi/virtio.json

Quoted 7 lines
qapi/virtio.json +0 -7
-#              ]
-#          },
-#          "host-features": {
-#              "unknown-dev-features": 1073741824,
-#              "dev-features": [],
-#              "transports": [
-#                  "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields

enabled",

qapi/virtio.json line 249

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors

supported",

qapi/virtio.json line 250

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_F_VERSION_1: Device compliant for v1 spec

(legacy)",

qapi/virtio.json line 251

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc.

layouts",

qapi/virtio.json line 252

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs

out of avail. descs. on VQ"

Quoted 16 lines
qapi/virtio.json +3 -6
-#              ]
-#          },
+#          "guest-features": 5100273664,
+#          "host-features": 6325010432,
 #          "use-guest-notifier-mask": true,
 #          "vm-running": true,
 #          "queue-sel": 1,
@@ -279,147 +252,22 @@
 #              "max-queues": 1,
 #              "backend-cap": 2,
 #              "log-size": 0,
-#              "backend-features": {
-#                  "dev-features": [],
-#                  "transports": []
-#              },
+#              "backend-features": 0,

qapi/virtio.json line 294

Quoted 10 lines
qapi/virtio.json +1 -6
 #              "nvqs": 2,
-#              "protocol-features": {
-#                  "protocols": []
-#              },
+#              "protocol-features": 0,
 #              "vq-index": 0,
 #              "log-enabled": false,
-#              "acked-features": {
-#                  "dev-features": [
-#                      "VIRTIO_NET_F_MRG_RXBUF: Driver can merge

receive buffers"

qapi/virtio.json

Quoted 3 lines
qapi/virtio.json +0 -3
-#                  ],
-#                  "transports": [
-#                      "VIRTIO_RING_F_EVENT_IDX: Used & avail. event

fields enabled",

qapi/virtio.json line 298

Quoted 1 line
qapi/virtio.json +0 -1
-#                      "VIRTIO_RING_F_INDIRECT_DESC: Indirect

descriptors supported",

qapi/virtio.json line 299

Quoted 1 line
qapi/virtio.json +0 -1
-#                      "VIRTIO_F_VERSION_1: Device compliant for v1

spec (legacy)"

qapi/virtio.json

Quoted 5 lines
qapi/virtio.json +0 -5
-#                  ]
-#              },
-#              "features": {
-#                  "dev-features": [
-#                      "VHOST_F_LOG_ALL: Logging write descriptors

supported",

qapi/virtio.json line 305

Quoted 1 line
qapi/virtio.json +0 -1
-#                      "VIRTIO_NET_F_MRG_RXBUF: Driver can merge

receive buffers"

qapi/virtio.json

Quoted 3 lines
qapi/virtio.json +0 -3
-#                  ],
-#                  "transports": [
-#                      "VIRTIO_RING_F_EVENT_IDX: Used & avail. event

fields enabled",

qapi/virtio.json line 309

Quoted 1 line
qapi/virtio.json +0 -1
-#                      "VIRTIO_RING_F_INDIRECT_DESC: Indirect

descriptors supported",

qapi/virtio.json line 310

Quoted 1 line
qapi/virtio.json +0 -1
-#                      "VIRTIO_F_IOMMU_PLATFORM: Device can be used on

IOMMU platform",

qapi/virtio.json line 311

Quoted 1 line
qapi/virtio.json +0 -1
-#                      "VIRTIO_F_VERSION_1: Device compliant for v1

spec (legacy)",

qapi/virtio.json line 312

Quoted 1 line
qapi/virtio.json +0 -1
-#                      "VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary

desc. layouts",

qapi/virtio.json line 313

Quoted 1 line
qapi/virtio.json +0 -1
-#                      "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device

runs out of avail. descs. on VQ"

qapi/virtio.json

Quoted 6 lines
qapi/virtio.json +0 -6
-#                  ]
-#              }
-#          },
-#          "backend-features": {
-#              "dev-features": [
-#                  "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol

features negotiation supported",

qapi/virtio.json line 320

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_GSO: Handling GSO-type packets

supported",

qapi/virtio.json line 321

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_CTRL_MAC_ADDR: MAC address set through

control channel",

qapi/virtio.json line 322

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_GUEST_ANNOUNCE: Driver sending

gratuitous packets supported",

qapi/virtio.json line 323

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_CTRL_RX_EXTRA: Extra RX mode control

supported",

qapi/virtio.json line 324

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_CTRL_VLAN: Control channel VLAN

filtering supported",

qapi/virtio.json line 325

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_CTRL_RX: Control channel RX mode

supported",

qapi/virtio.json line 327

Quoted 2 lines
qapi/virtio.json +0 -2
-#                  "VIRTIO_NET_F_CTRL_VQ: Control channel available",
-#                  "VIRTIO_NET_F_STATUS: Configuration status field

available",

qapi/virtio.json line 328

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive

buffers",

qapi/virtio.json line 330

Quoted 2 lines
qapi/virtio.json +0 -2
-#                  "VIRTIO_NET_F_HOST_UFO: Device can receive UFO",
-#                  "VIRTIO_NET_F_HOST_ECN: Device can receive TSO with

ECN",

qapi/virtio.json

Quoted 4 lines
qapi/virtio.json +0 -4
-#                  "VIRTIO_NET_F_HOST_TSO6: Device can receive TSOv6",
-#                  "VIRTIO_NET_F_HOST_TSO4: Device can receive TSOv4",
-#                  "VIRTIO_NET_F_GUEST_UFO: Driver can receive UFO",
-#                  "VIRTIO_NET_F_GUEST_ECN: Driver can receive TSO with

ECN",

qapi/virtio.json

Quoted 4 lines
qapi/virtio.json +0 -4
-#                  "VIRTIO_NET_F_GUEST_TSO6: Driver can receive TSOv6",
-#                  "VIRTIO_NET_F_GUEST_TSO4: Driver can receive TSOv4",
-#                  "VIRTIO_NET_F_MAC: Device has given MAC address",
-#                  "VIRTIO_NET_F_CTRL_GUEST_OFFLOADS: Control channel

offloading reconfig. supported",

qapi/virtio.json line 339

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_GUEST_CSUM: Driver handling packets

with partial checksum supported",

qapi/virtio.json line 340

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_CSUM: Device handling packets with

partial checksum supported"

qapi/virtio.json

Quoted 3 lines
qapi/virtio.json +0 -3
-#              ],
-#              "transports": [
-#                  "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields

enabled",

qapi/virtio.json line 344

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors

supported",

qapi/virtio.json line 345

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_F_VERSION_1: Device compliant for v1 spec

(legacy)",

qapi/virtio.json line 346

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc.

layouts",

qapi/virtio.json line 347

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs

out of avail. descs. on VQ"

qapi/virtio.json

Quoted 11 lines
qapi/virtio.json +3 -4
-#              ]
+#              "acked-features": 5100306432,
+#              "features": 13908344832,
 #          },
+#          "backend-features": 6337593319,
 #          "start-on-kick": false,
 #          "isr": 1,
 #          "broken": false,
-#          "status": {
-#              "statuses": [
-#                  "VIRTIO_CONFIG_S_ACKNOWLEDGE: Valid virtio device

found",

qapi/virtio.json line 356

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_CONFIG_S_DRIVER: Guest OS compatible with

device",

qapi/virtio.json line 357

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_CONFIG_S_FEATURES_OK: Feature negotiation

complete",

qapi/virtio.json

Quoted 8 lines
qapi/virtio.json +1 -6
-#                  "VIRTIO_CONFIG_S_DRIVER_OK: Driver setup and ready"
-#              ]
-#          },
+#          "status": 15,
 #          "num-vqs": 3,
-#          "guest-features": {
-#              "dev-features": [
-#                  "VIRTIO_NET_F_CTRL_MAC_ADDR: MAC address set through

control channel",

qapi/virtio.json line 365

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_GUEST_ANNOUNCE: Driver sending

gratuitous packets supported",

qapi/virtio.json line 366

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_CTRL_VLAN: Control channel VLAN

filtering supported",

qapi/virtio.json line 367

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_CTRL_RX: Control channel RX mode

supported",

qapi/virtio.json line 369

Quoted 2 lines
qapi/virtio.json +0 -2
-#                  "VIRTIO_NET_F_CTRL_VQ: Control channel available",
-#                  "VIRTIO_NET_F_STATUS: Configuration status field

available",

qapi/virtio.json line 370

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive

buffers",

qapi/virtio.json line 372

Quoted 2 lines
qapi/virtio.json +0 -2
-#                  "VIRTIO_NET_F_HOST_UFO: Device can receive UFO",
-#                  "VIRTIO_NET_F_HOST_ECN: Device can receive TSO with

ECN",

qapi/virtio.json

Quoted 4 lines
qapi/virtio.json +0 -4
-#                  "VIRTIO_NET_F_HOST_TSO6: Device can receive TSOv6",
-#                  "VIRTIO_NET_F_HOST_TSO4: Device can receive TSOv4",
-#                  "VIRTIO_NET_F_GUEST_UFO: Driver can receive UFO",
-#                  "VIRTIO_NET_F_GUEST_ECN: Driver can receive TSO with

ECN",

qapi/virtio.json

Quoted 4 lines
qapi/virtio.json +0 -4
-#                  "VIRTIO_NET_F_GUEST_TSO6: Driver can receive TSOv6",
-#                  "VIRTIO_NET_F_GUEST_TSO4: Driver can receive TSOv4",
-#                  "VIRTIO_NET_F_MAC: Device has given MAC address",
-#                  "VIRTIO_NET_F_CTRL_GUEST_OFFLOADS: Control channel

offloading reconfig. supported",

qapi/virtio.json line 381

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_GUEST_CSUM: Driver handling packets

with partial checksum supported",

qapi/virtio.json line 382

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_CSUM: Device handling packets with

partial checksum supported"

qapi/virtio.json

Quoted 3 lines
qapi/virtio.json +0 -3
-#              ],
-#              "transports": [
-#                  "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields

enabled",

qapi/virtio.json line 386

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors

supported",

qapi/virtio.json line 387

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_F_VERSION_1: Device compliant for v1 spec

(legacy)"

qapi/virtio.json

Quoted 5 lines
qapi/virtio.json +0 -5
-#             ]
-#          },
-#          "host-features": {
-#              "dev-features": [
-#                  "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol

features negotiation supported",

qapi/virtio.json line 393

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_GSO: Handling GSO-type packets

supported",

qapi/virtio.json line 394

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_CTRL_MAC_ADDR: MAC address set through

control channel",

qapi/virtio.json line 395

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_GUEST_ANNOUNCE: Driver sending

gratuitous packets supported",

qapi/virtio.json line 396

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_CTRL_RX_EXTRA: Extra RX mode control

supported",

qapi/virtio.json line 397

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_CTRL_VLAN: Control channel VLAN

filtering supported",

qapi/virtio.json line 398

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_CTRL_RX: Control channel RX mode

supported",

qapi/virtio.json line 400

Quoted 2 lines
qapi/virtio.json +0 -2
-#                  "VIRTIO_NET_F_CTRL_VQ: Control channel available",
-#                  "VIRTIO_NET_F_STATUS: Configuration status field

available",

qapi/virtio.json line 401

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive

buffers",

qapi/virtio.json line 403

Quoted 2 lines
qapi/virtio.json +0 -2
-#                  "VIRTIO_NET_F_HOST_UFO: Device can receive UFO",
-#                  "VIRTIO_NET_F_HOST_ECN: Device can receive TSO with

ECN",

qapi/virtio.json

Quoted 4 lines
qapi/virtio.json +0 -4
-#                  "VIRTIO_NET_F_HOST_TSO6: Device can receive TSOv6",
-#                  "VIRTIO_NET_F_HOST_TSO4: Device can receive TSOv4",
-#                  "VIRTIO_NET_F_GUEST_UFO: Driver can receive UFO",
-#                  "VIRTIO_NET_F_GUEST_ECN: Driver can receive TSO with

ECN",

qapi/virtio.json

Quoted 4 lines
qapi/virtio.json +0 -4
-#                  "VIRTIO_NET_F_GUEST_TSO6: Driver can receive TSOv6",
-#                  "VIRTIO_NET_F_GUEST_TSO4: Driver can receive TSOv4",
-#                  "VIRTIO_NET_F_MAC: Device has given MAC address",
-#                  "VIRTIO_NET_F_CTRL_GUEST_OFFLOADS: Control channel

offloading reconfig. supported",

qapi/virtio.json line 412

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_GUEST_CSUM: Driver handling packets

with partial checksum supported",

qapi/virtio.json line 413

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_NET_F_CSUM: Device handling packets with

partial checksum supported"

qapi/virtio.json

Quoted 3 lines
qapi/virtio.json +0 -3
-#              ],
-#              "transports": [
-#                  "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields

enabled",

qapi/virtio.json line 417

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors

supported",

qapi/virtio.json line 418

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_F_VERSION_1: Device compliant for v1 spec

(legacy)",

qapi/virtio.json line 419

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc.

layouts",

qapi/virtio.json line 420

Quoted 1 line
qapi/virtio.json +0 -1
-#                  "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs

out of avail. descs. on VQ"

Quoted 9 lines
qapi/virtio.json +2 -3
-#             ]
-#          },
+#          "guest-features": 5111807911,
+#          "host-features": 6337593319,
 #          "use-guest-notifier-mask": true,
 #          "vm-running": true,
 #          "queue-sel": 2,
--

2.31.1

Signature · 1 line
Best regards
Acked-by on v3 1/3
#6 lore raw

Re: [PATCH v3 1/3] qmp: Switch x-query-virtio-status back to numeric encoding

In reply to Hyman Huang
Quoted 7 lines · Hyman Huang

x-query-virtio-status returns several sets of virtio feature and status flags. It goes back to v7.2.0.

In the initial commit 90c066cd682 (qmp: add QMP command x-query-virtio-status), we returned them as numbers, using virtio's well-known binary encoding.

Quoted 6 lines

The next commit f3034ad71fc (qmp: decode feature & status bits in virtio-status) replaced the numbers by objects. The objects represent bits QEMU knows symbolically, and any unknown bits numerically just like before.

Commit 8a8287981d1 (hmp: add virtio commands) the matching HMP command

added the matching HMP command

Quoted 18 lines

"info virtio" (and a few more, which aren't relevant here).

The symbolic representation uses lists of strings. The string format is undocumented. The strings look like "WELL_KNOWN_SYMBOL: human readable explanation".

This symbolic representation is nice for humans. Machines it can save the trouble of decoding virtio's well-known binary encoding.

However, we sometimes want to compare features and status bits without caring for their exact meaning. Say we want to verify the correctness of the virtio negotiation between guest, QEMU, and OVS-DPDK. We can use QMP command x-query-virtio-status to retrieve vhost-user net device features, and the "ovs-vsctl list interface" command to retrieve interface features. Without commit f3034ad71fc, we could then simply compare the numbers. With this commit, we first have to map from the strings back to the numeric encoding.

Quoted 8 lines

Revert the decoding for QMP, but keep it for HMP.

This makes the QMP command easier to use for use cases where we don't need to decode, like the comparison above. For use cases where we need to decode, we replace parsing undocumented strings by decoding virtio's well-known binary encoding.

Incompatible change; acceptable because x-query-virtio-status does

Scratch "does".

Quoted 3 lines

comes without a stability promise.

#4 lore raw

Re: [PATCH v3 1/3] qmp: Switch x-query-virtio-status back to numeric encoding

In reply to Yong Huang
Quoted 45 lines · Yong Huang
Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Hyman Huang

x-query-virtio-status returns several sets of virtio feature and status flags. It goes back to v7.2.0.

In the initial commit 90c066cd682 (qmp: add QMP command x-query-virtio-status), we returned them as numbers, using virtio's well-known binary encoding.

The next commit f3034ad71fc (qmp: decode feature & status bits in virtio-status) replaced the numbers by objects. The objects represent bits QEMU knows symbolically, and any unknown bits numerically just like before.

Commit 8a8287981d1 (hmp: add virtio commands) the matching HMP command "info virtio" (and a few more, which aren't relevant here).

The symbolic representation uses lists of strings. The string format is undocumented. The strings look like "WELL_KNOWN_SYMBOL: human readable explanation".

This symbolic representation is nice for humans. Machines it can save the trouble of decoding virtio's well-known binary encoding.

However, we sometimes want to compare features and status bits without caring for their exact meaning. Say we want to verify the correctness of the virtio negotiation between guest, QEMU, and OVS-DPDK. We can use QMP command x-query-virtio-status to retrieve vhost-user net device features, and the "ovs-vsctl list interface" command to retrieve interface features. Without commit f3034ad71fc, we could then simply compare the numbers. With this commit, we first have to map from the strings back to the numeric encoding.

Quoted 3 lines
Quoted 1 line

Revert the decoding for QMP, but keep it for HMP.

Is there a way to maybe have both decoded and numerical one?

What if the next patch went back to this implementation in the following patch? All you need to do is add a matching xxx_bits entry for each feature and status.

https://patchew.org/QEMU/[email protected]/3c7161a47b141af04b1f8272e8e24c5faa46ddb2.1700319559.git.yong.huang@smartx.com/

Quoted 6 lines

E.g. I mostly use QMP even when I read it myself.

Quoted 1 line

Thus, it is recommended that both numerical and decoded types be kept for QMP; this approach can be at odds with what was previously discussed. What do you think about this, Markus?

QMP is for machines.

That said, I won't object to adding development & debugging aids meant for humans as long as

1. they're marked unstable, and

2. they either add only a modest amount of output, or the additional output is off by default.

What exactly is a "modest amount" depends on how machines use the command. If they use it all the time, even going from 8KiB to 64KiB could be too much. If they use it just once per guest, we can afford more waste.

In this particular case, we could add an unstable member of type ['str'] next to the int-valued bits. For each set bit in the int, add a string to the list. If QEMU knows the bit, use the well-known name. I'd omit the common prefix, though: use "GUEST_ANNOUNCE" or "guest-announce" instead of "VIRTIO_NET_F_GUEST_ANNOUNCE". If QEMU doesn't know the bit, you could use the bit's numeric value.

Recommend a separate patch, to avoid delaying this series.

Makes sense?

#8 lore raw

Re: [PATCH v3 2/3] virtio: Declare the decoding functions to static

In reply to Hyman Huang
Quoted 17 lines · Hyman Huang

qmp_decode_protocols(), qmp_decode_status(), and qmp_decode_features() are now only used in virtio-hmp-cmds.c. So move them into there, redeclare them to static, and replace the qmp_ prefix with hmp_.

---
 hw/virtio/meson.build       |   3 +-
 hw/virtio/virtio-hmp-cmds.c | 677 +++++++++++++++++++++++++++++++++++-
 hw/virtio/virtio-qmp.c      | 661 -----------------------------------
 hw/virtio/virtio-qmp.h      |   3 -
 4 files changed, 670 insertions(+), 674 deletions(-)
hw/virtio/meson.build +0 -0
index 47baf00366..6665669480 100644

hw/virtio/meson.build system_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev.c') · line 12

Quoted 5 lines
hw/virtio/meson.build +1 -1
@@ -9,7 +9,7 @@ system_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev.c')
 
 specific_virtio_ss = ss.source_set()
 specific_virtio_ss.add(files('virtio.c'))
-specific_virtio_ss.add(files('virtio-config-io.c', 'virtio-qmp.c'))
+specific_virtio_ss.add(files('virtio-config-io.c', 'virtio-qmp.c', 'virtio-hmp-cmds.c'))

I think you can also move virtio-qmp.c, i.e.

specific_virtio_ss.add(files('virtio-config-io.c', 'virtio-hmp-cmds.c'))

here, and ...

hw/virtio/meson.build specific_virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss) · line 77

Quoted 8 lines
hw/virtio/meson.build +0 -1
 if have_vhost
   system_virtio_ss.add(files('vhost.c'))
@@ -74,7 +74,6 @@ specific_virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss)
 system_ss.add_all(when: 'CONFIG_VIRTIO', if_true: system_virtio_ss)
 system_ss.add(when: 'CONFIG_VIRTIO', if_false: files('vhost-stub.c'))
 system_ss.add(when: 'CONFIG_VIRTIO', if_false: files('virtio-stub.c'))
-system_ss.add(files('virtio-hmp-cmds.c'))

system_ss.add(files('virtio-qmp.c'))

here.

[...]

author
#5 lore raw

Re: [PATCH v3 1/3] qmp: Switch x-query-virtio-status back to numeric encoding

In reply to Markus Armbruster
Quoted 83 lines · Markus Armbruster
Quoted 1 line · Yong Huang

On Tue, Feb 13, 2024 at 6:26 PM Michael S. Tsirkin <[email protected]>

Quoted 5 lines · wrote:
Quoted 5 lines · Hyman Huang
Quoted 3 lines

x-query-virtio-status returns several sets of virtio feature and status flags. It goes back to v7.2.0.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

In the initial commit 90c066cd682 (qmp: add QMP command x-query-virtio-status), we returned them as numbers, using virtio's well-known binary encoding.

The next commit f3034ad71fc (qmp: decode feature & status bits in virtio-status) replaced the numbers by objects. The objects represent bits QEMU knows symbolically, and any unknown bits numerically just

like

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

before.

Commit 8a8287981d1 (hmp: add virtio commands) the matching HMP command "info virtio" (and a few more, which aren't relevant here).

The symbolic representation uses lists of strings. The string format

is

Quoted 1 line
Quoted 1 line
Quoted 1 line

undocumented. The strings look like "WELL_KNOWN_SYMBOL: human

readable

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

explanation".

This symbolic representation is nice for humans. Machines it can save the trouble of decoding virtio's well-known binary encoding.

However, we sometimes want to compare features and status bits without caring for their exact meaning. Say we want to verify the correctness of the virtio negotiation between guest, QEMU, and OVS-DPDK. We can

use

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

QMP command x-query-virtio-status to retrieve vhost-user net device features, and the "ovs-vsctl list interface" command to retrieve interface features. Without commit f3034ad71fc, we could then simply compare the numbers. With this commit, we first have to map from the strings back to the numeric encoding.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Revert the decoding for QMP, but keep it for HMP.

Is there a way to maybe have both decoded and numerical one?

What if the next patch went back to this implementation in the following patch? All you need to do is add a matching xxx_bits entry for each

feature

Quoted 3 lines

and status.

https://patchew.org/QEMU/[email protected]/3c7161a47b141af04b1f8272e8e24c5faa46ddb2.1700319559.git.yong.huang@smartx.com/

Quoted 8 lines

E.g. I mostly use QMP even when I read it myself.

Quoted 1 line

Thus, it is recommended that both numerical and decoded types be kept for QMP; this approach can be at odds with what was previously discussed. What do you think about this, Markus?

QMP is for machines.

That said, I won't object to adding development & debugging aids meant for humans as long as

1. they're marked unstable, and

2. they either add only a modest amount of output, or the additional output is off by default.

What exactly is a "modest amount" depends on how machines use the command. If they use it all the time, even going from 8KiB to 64KiB could be too much. If they use it just once per guest, we can afford more waste.

In this particular case, we could add an unstable member of type ['str'] next to the int-valued bits. For each set bit in the int, add a string to the list. If QEMU knows the bit, use the well-known name. I'd omit the common prefix, though: use "GUEST_ANNOUNCE" or "guest-announce" instead of "VIRTIO_NET_F_GUEST_ANNOUNCE". If QEMU doesn't know the bit, you could use the bit's numeric value.

Quoted 5 lines

Recommend a separate patch, to avoid delaying this series.

Makes sense?

I agree, and thanks for the comments.

Yong

Signature · 1 line
Best regards
author
#9 lore raw

Re: [PATCH v3 2/3] virtio: Declare the decoding functions to static

In reply to Markus Armbruster
Quoted 38 lines · Markus Armbruster

hw/virtio/meson.build system_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV',

Quoted 17 lines · Hyman Huang

qmp_decode_protocols(), qmp_decode_status(), and qmp_decode_features() are now only used in virtio-hmp-cmds.c. So move them into there, redeclare them to static, and replace the qmp_ prefix with hmp_.

---
 hw/virtio/meson.build       |   3 +-
 hw/virtio/virtio-hmp-cmds.c | 677 +++++++++++++++++++++++++++++++++++-
 hw/virtio/virtio-qmp.c      | 661 -----------------------------------
 hw/virtio/virtio-qmp.h      |   3 -
 4 files changed, 670 insertions(+), 674 deletions(-)
hw/virtio/meson.build +0 -0
index 47baf00366..6665669480 100644
@@ -9,7 +9,7 @@ system_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV',

if_true: files('vdpa-dev.c')

hw/virtio/meson.build system_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev.c')

Quoted 5 lines
hw/virtio/meson.build +1 -1
 specific_virtio_ss = ss.source_set()
 specific_virtio_ss.add(files('virtio.c'))
-specific_virtio_ss.add(files('virtio-config-io.c', 'virtio-qmp.c'))
+specific_virtio_ss.add(files('virtio-config-io.c', 'virtio-qmp.c',

'virtio-hmp-cmds.c'))

I think you can also move virtio-qmp.c, i.e.

specific_virtio_ss.add(files('virtio-config-io.c', 'virtio-hmp-cmds.c'))

here, and ...

hw/virtio/meson.build specific_virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI',

Quoted 4 lines
hw/virtio/meson.build +0 -0
 if have_vhost
   system_virtio_ss.add(files('vhost.c'))
@@ -74,7 +74,6 @@ specific_virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI',

if_true: virtio_pci_ss)

Quoted 9 lines

hw/virtio/meson.build specific_virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss) · line 77

Quoted 4 lines
hw/virtio/meson.build +0 -1
 system_ss.add_all(when: 'CONFIG_VIRTIO', if_true: system_virtio_ss)
 system_ss.add(when: 'CONFIG_VIRTIO', if_false: files('vhost-stub.c'))
 system_ss.add(when: 'CONFIG_VIRTIO', if_false: files('virtio-stub.c'))
-system_ss.add(files('virtio-hmp-cmds.c'))
   system_ss.add(files('virtio-qmp.c'))

here.

Get it, I'll try in the next version.

Quoted 3 lines

[...]

Signature · 1 line
Best regards