Skip to contentSkip to conversation

vhost-user-test: Add negotiated features check

RFC Superseded Hyman Huang 4 participants 15 messages Nov 12, 2023 – Dec 9, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover vhost-user-test: Add negotiated features check

The patchset "Fix the virtio features negotiation flaw" fix a vhost-user negotiation flaw:
c9bdc449f9 vhost-user: Fix the virtio features negotiation flaw bebcac052a vhost-user: Refactor the chr_closed_bh 937b7d96e4 vhost-user: Refactor vhost acked features saving

While the test case remain unmerged, the detail reference:
https://lore.kernel.org/qemu-devel/[email protected]/

Since Michael pointed out that the info virtio makes sense to query the negotiation feature, this patchset uses the x-query-virtio-status to retrieve the features instead of exporting netdev capabilities and information as we did in the previous patchset to aid in confirming the negotiation's validity.

To do that, we first introduce an "show-bits" argument for x-query-virtio-status such that the feature bits can be used directly, and then implement the test case for negotiated features check. As we post, the code is divided into two patches.

Please review, thanks,
Yong

Hyman Huang (2):
qapi/virtio: introduce the "show-bits" argument for
x-query-virtio-status
vhost-user-test: Add negotiated features check

 hw/virtio/virtio-hmp-cmds.c   |   2 +-
 hw/virtio/virtio-qmp.c        |  21 ++++++-
 qapi/virtio.json              |  49 ++++++++++++++++-
 tests/qtest/vhost-user-test.c | 100 ++++++++++++++++++++++++++++++++++
 4 files changed, 167 insertions(+), 5 deletions(-)
Signature · 1 line
2.39.1
#1 lore raw

RFC 1/2 qapi/virtio: introduce the "show-bits" argument for x-query-virtio-status

This patch allows to display feature and status bits in virtio-status.

An optional argument is introduced: show-bits. For example:
{"execute": "x-query-virtio-status",
"arguments": {"path": "/machine/peripheral-anon/device[1]/virtio-backend",

               "show-bits": true}

Features and status bits could be helpful for applications to compare directly. For instance, when an upper application aims to ensure the virtio negotiation correctness between guest, QEMU, and OVS-DPDK, it use the "ovs-vsctl list interface" command to retrieve interface features (in number format) and the QMP command x-query-virtio-status to retrieve vhost-user net device features. If "show-bits" is added, the application can compare the two features directly; No need to encoding the features returned by the QMP command.

This patch also serves as a preparation for the next one, which implements a vhost-user test case about acked features of vhost-user protocol.

Note that since the matching HMP command is typically used for human, leave it unchanged.

---
 hw/virtio/virtio-hmp-cmds.c |  2 +-
 hw/virtio/virtio-qmp.c      | 21 +++++++++++++++-
 qapi/virtio.json            | 49 ++++++++++++++++++++++++++++++++++---
 3 files changed, 67 insertions(+), 5 deletions(-)
hw/virtio/virtio-hmp-cmds.c +1 -1
index 477c97dea2..3774f3d4bf 100644
@@ -108,7 +108,7 @@ void hmp_virtio_status(Monitor *mon, const QDict *qdict)
 {
     Error *err = NULL;
     const char *path = qdict_get_try_str(qdict, "path");
-    VirtioStatus *s = qmp_x_query_virtio_status(path, &err);
+    VirtioStatus *s = qmp_x_query_virtio_status(path, false, false, &err);
 
     if (err != NULL) {
         hmp_handle_error(mon, err);
hw/virtio/virtio-qmp.c +20 -1
index 1dd96ed20f..2e92bf28ac 100644
@@ -718,10 +718,15 @@ VirtIODevice *qmp_find_virtio_device(const char *path)
     return VIRTIO_DEVICE(dev);
 }
 
-VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
+VirtioStatus *qmp_x_query_virtio_status(const char *path,
+                                        bool has_show_bits,
+                                        bool show_bits,
+                                        Error **errp)
 {
     VirtIODevice *vdev;
     VirtioStatus *status;
+    bool display_bits =
+        has_show_bits ? show_bits : false;
 
     vdev = qmp_find_virtio_device(path);
     if (vdev == NULL) {
@@ -733,6 +738,11 @@ 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;
+    if (display_bits) {
+        status->guest_features_bits = vdev->guest_features;
+        status->host_features_bits = vdev->host_features;
+        status->backend_features_bits = vdev->backend_features;
+    }
     status->guest_features = qmp_decode_features(vdev->device_id,
                                                  vdev->guest_features);
     status->host_features = qmp_decode_features(vdev->device_id,
@@ -753,6 +763,9 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
     }
 
     status->num_vqs = virtio_get_num_queues(vdev);
+    if (display_bits) {
+        status->status_bits = vdev->status;
+    }
     status->status = qmp_decode_status(vdev->status);
     status->isr = vdev->isr;
     status->queue_sel = vdev->queue_sel;
@@ -775,6 +788,12 @@ 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;
+        if (display_bits) {
+            status->vhost_dev->features_bits = hdev->features;
+            status->vhost_dev->acked_features_bits = hdev->acked_features;
+            status->vhost_dev->backend_features_bits = hdev->backend_features;
+            status->vhost_dev->protocol_features_bits = hdev->protocol_features;
+        }
         status->vhost_dev->features =
             qmp_decode_features(vdev->device_id, hdev->features);
         status->vhost_dev->acked_features =
qapi/virtio.json +46 -3

179 lines not on this page · raw message

Signature · 1 line
2.39.1
#2 lore raw

Re: [RFC 1/2] qapi/virtio: introduce the "show-bits" argument for x-query-virtio-status

Quoted 50 lines · Hyman Huang

This patch allows to display feature and status bits in virtio-status.

An optional argument is introduced: show-bits. For example:
{"execute": "x-query-virtio-status",
"arguments": {"path": "/machine/peripheral-anon/device[1]/virtio-backend",

               "show-bits": true}

Features and status bits could be helpful for applications to compare directly. For instance, when an upper application aims to ensure the virtio negotiation correctness between guest, QEMU, and OVS-DPDK, it use the "ovs-vsctl list interface" command to retrieve interface features (in number format) and the QMP command x-query-virtio-status to retrieve vhost-user net device features. If "show-bits" is added, the application can compare the two features directly; No need to encoding the features returned by the QMP command.

This patch also serves as a preparation for the next one, which implements a vhost-user test case about acked features of vhost-user protocol.

Note that since the matching HMP command is typically used for human, leave it unchanged.

---
 hw/virtio/virtio-hmp-cmds.c |  2 +-
 hw/virtio/virtio-qmp.c      | 21 +++++++++++++++-
 qapi/virtio.json            | 49 ++++++++++++++++++++++++++++++++++---
 3 files changed, 67 insertions(+), 5 deletions(-)
hw/virtio/virtio-hmp-cmds.c +1 -1
index 477c97dea2..3774f3d4bf 100644
@@ -108,7 +108,7 @@ void hmp_virtio_status(Monitor *mon, const QDict *qdict)
 {
     Error *err = NULL;
     const char *path = qdict_get_try_str(qdict, "path");
-    VirtioStatus *s = qmp_x_query_virtio_status(path, &err);
+    VirtioStatus *s = qmp_x_query_virtio_status(path, false, false, &err);
 
     if (err != NULL) {
         hmp_handle_error(mon, err);
hw/virtio/virtio-qmp.c +0 -0
index 1dd96ed20f..2e92bf28ac 100644
@@ -718,10 +718,15 @@ VirtIODevice *qmp_find_virtio_device(const char *path)
     return VIRTIO_DEVICE(dev);
 }
 

hw/virtio/virtio-qmp.c VirtIODevice *qmp_find_virtio_device(const char *path) · line 729

Quoted 10 lines
hw/virtio/virtio-qmp.c +6 -1
-VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
+VirtioStatus *qmp_x_query_virtio_status(const char *path,
+                                        bool has_show_bits,
+                                        bool show_bits,
+                                        Error **errp)
 {
     VirtIODevice *vdev;
     VirtioStatus *status;
+    bool display_bits =
+        has_show_bits ? show_bits : false;

Since !has_show_bits implies !show_bits, you can simply use if (show_bits).

Quoted 43 lines
hw/virtio/virtio-qmp.c +14 -0
     vdev = qmp_find_virtio_device(path);
     if (vdev == NULL) {
@@ -733,6 +738,11 @@ 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;
+    if (display_bits) {
+        status->guest_features_bits = vdev->guest_features;
+        status->host_features_bits = vdev->host_features;
+        status->backend_features_bits = vdev->backend_features;
+    }
     status->guest_features = qmp_decode_features(vdev->device_id,
                                                  vdev->guest_features);
     status->host_features = qmp_decode_features(vdev->device_id,
@@ -753,6 +763,9 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
     }
 
     status->num_vqs = virtio_get_num_queues(vdev);
+    if (display_bits) {
+        status->status_bits = vdev->status;
+    }
     status->status = qmp_decode_status(vdev->status);
     status->isr = vdev->isr;
     status->queue_sel = vdev->queue_sel;
@@ -775,6 +788,12 @@ 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;
+        if (display_bits) {
+            status->vhost_dev->features_bits = hdev->features;
+            status->vhost_dev->acked_features_bits = hdev->acked_features;
+            status->vhost_dev->backend_features_bits = hdev->backend_features;
+            status->vhost_dev->protocol_features_bits = hdev->protocol_features;
+        }
         status->vhost_dev->features =
             qmp_decode_features(vdev->device_id, hdev->features);
         status->vhost_dev->acked_features =
qapi/virtio.json +0 -0
index e6dcee7b83..608b841a89 100644

qapi/virtio.json line 82

Quoted 4 lines
qapi/virtio.json +1 -0
@@ -79,12 +79,20 @@
 #
 # @vq-index: vhost_dev vq_index
 #
+# @features-bits: vhost_dev features in decimal format

Say "encoded as a number". The number is decimal just because the transport is JSON. We could have another transport some day. Or language bindings wrapping around the JSON transport.

qapi/virtio.json line 84

Quoted 2 lines
qapi/virtio.json +1 -0
+#
 # @features: vhost_dev features

Double-checking... @feature-bits provides the exact same information as @features, only in another encoding. Correct?

Same for all the other new -bits. Correct?

Quoted 71 lines
qapi/virtio.json +23 -0
 #
+# @acked-features-bits: vhost_dev acked_features in decimal format
+#
 # @acked-features: vhost_dev acked_features
 #
+# @backend-features-bits: vhost_dev backend_features in decimal format
+#
 # @backend-features: vhost_dev backend_features
 #
+# @protocol-features-bits: vhost_dev protocol_features in decimal format
+#
 # @protocol-features: vhost_dev protocol_features
 #
 # @max-queues: vhost_dev max_queues
@@ -102,9 +110,13 @@
             'n-tmp-sections': 'int',
             'nvqs': 'uint32',
             'vq-index': 'int',
+            'features-bits': 'uint64',
             'features': 'VirtioDeviceFeatures',
+            'acked-features-bits': 'uint64',
             'acked-features': 'VirtioDeviceFeatures',
+            'backend-features-bits': 'uint64',
             'backend-features': 'VirtioDeviceFeatures',
+            'protocol-features-bits': 'uint64',
             'protocol-features': 'VhostDeviceProtocols',
             'max-queues': 'uint64',
             'backend-cap': 'uint64',
@@ -124,10 +136,16 @@
 #
 # @vhost-started: VirtIODevice vhost_started flag
 #
+# @guest-features-bits: VirtIODevice guest_features in decimal format
+#
 # @guest-features: VirtIODevice guest_features
 #
+# @host-features-bits: VirtIODevice host_features in decimal format
+#
 # @host-features: VirtIODevice host_features
 #
+# @backend-features-bits: VirtIODevice backend_features in decimal format
+#
 # @backend-features: VirtIODevice backend_features
 #
 # @device-endian: VirtIODevice device_endian
@@ -135,6 +153,9 @@
 # @num-vqs: VirtIODevice virtqueue count.  This is the number of
 #     active virtqueues being used by the VirtIODevice.
 #
+# @status-bits: VirtIODevice configuration status in decimal format
+#     (VirtioDeviceStatus)
+#
 # @status: VirtIODevice configuration status (VirtioDeviceStatus)
 #
 # @isr: VirtIODevice ISR
@@ -170,10 +191,14 @@
             'device-id': 'uint16',
             'vhost-started': 'bool',
             'device-endian': 'str',
+            'guest-features-bits': 'uint64',
             'guest-features': 'VirtioDeviceFeatures',
+            'host-features-bits': 'uint64',
             'host-features': 'VirtioDeviceFeatures',
+            'backend-features-bits': 'uint64',
             'backend-features': 'VirtioDeviceFeatures',
             'num-vqs': 'int',
+            'status-bits': 'uint8',
             'status': 'VirtioDeviceStatus',
             'isr': 'uint8',
             'queue-sel': 'uint16',

qapi/virtio.json line 224

Quoted 5 lines
qapi/virtio.json +2 -0
@@ -195,6 +220,9 @@
 #
 # @path: Canonical QOM path of the VirtIODevice
 #
+# @show-bits: Whether to display the feature & status bits.
+#     Default is disabled. (Since 8.2)

This makes the new members opt-in. Why not include them always?

Quoted 112 lines
qapi/virtio.json +19 -3
+#
 # Features:
 #
 # @unstable: This command is meant for debugging.
@@ -208,7 +236,8 @@
 # 1. Poll for the status of virtio-crypto (no vhost-crypto active)
 #
 # -> { "execute": "x-query-virtio-status",
-#      "arguments": { "path": "/machine/peripheral/crypto0/virtio-backend" }
+#      "arguments": { "path": "/machine/peripheral/crypto0/virtio-backend",
+#                     "show-bits": true }
 #    }
 # <- { "return": {
 #          "device-endian": "little",
@@ -216,6 +245,7 @@
 #          "disable-legacy-check": false,
 #          "name": "virtio-crypto",
 #          "started": true,
+#          "guest-features-bits": 5100273664,
 #          "device-id": 20,
 #          "backend-features": {
 #              "transports": [],
@@ -241,6 +271,7 @@
 #                  "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)"
 #              ]
 #          },
+#          "host-features-bits": 6325010432,
 #          "host-features": {
 #              "unknown-dev-features": 1073741824,
 #              "dev-features": [],
@@ -252,9 +283,11 @@
 #                  "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ"
 #              ]
 #          },
+#          "backend-features-bits": 0,
 #          "use-guest-notifier-mask": true,
 #          "vm-running": true,
 #          "queue-sel": 1,
+#          "status-bits": 15,
 #          "disabled": false,
 #          "vhost-started": false,
 #          "use-started": true
@@ -264,7 +297,8 @@
 # 2. Poll for the status of virtio-net (vhost-net is active)
 #
 # -> { "execute": "x-query-virtio-status",
-#      "arguments": { "path": "/machine/peripheral-anon/device[1]/virtio-backend" }
+#      "arguments": { "path": "/machine/peripheral-anon/device[1]/virtio-backend",
+#                     "show-bits": true }
 #    }
 # <- { "return": {
 #          "device-endian": "little",
@@ -272,11 +306,13 @@
 #          "disabled-legacy-check": false,
 #          "name": "virtio-net",
 #          "started": true,
+#          "guest-features-bits": 5111807911,
 #          "device-id": 1,
 #          "vhost-dev": {
 #              "n-tmp-sections": 4,
 #              "n-mem-sections": 4,
 #              "max-queues": 1,
+#              "features-bits": 13908344832
 #              "backend-cap": 2,
 #              "log-size": 0,
 #              "backend-features": {
@@ -284,6 +320,8 @@
 #                  "transports": []
 #              },
 #              "nvqs": 2,
+#              "acked-features-bits": 5100306432,
+#              "backend-features-bits": 0,
 #              "protocol-features": {
 #                  "protocols": []
 #              },
@@ -299,6 +337,7 @@
 #                      "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)"
 #                  ]
 #              },
+#              "protocol-features-bits": 0,
 #              "features": {
 #                  "dev-features": [
 #                      "VHOST_F_LOG_ALL: Logging write descriptors supported",
@@ -387,6 +426,7 @@
 #                  "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)"
 #             ]
 #          },
+#          "host-features-bits": 6337593319,
 #          "host-features": {
 #              "dev-features": [
 #                  "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features negotiation supported",
@@ -420,9 +460,11 @@
 #                  "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ"
 #             ]
 #          },
+#          "backend-features-bits": 6337593319,
 #          "use-guest-notifier-mask": true,
 #          "vm-running": true,
 #          "queue-sel": 2,
+#          "status-bits": 15,
 #          "disabled": false,
 #          "vhost-started": true,
 #          "use-started": true
@@ -430,7 +472,8 @@
 #    }
 ##
 { 'command': 'x-query-virtio-status',
-  'data': { 'path': 'str' },
+  'data': { 'path': 'str',
+            '*show-bits': 'bool'},
   'returns': 'VirtioStatus',
   'features': [ 'unstable' ] }
author
#3 lore raw

Re: [RFC 1/2] qapi/virtio: introduce the "show-bits" argument for x-query-virtio-status

Quoted 57 lines · Markus Armbruster
Quoted 5 lines · Hyman Huang

This patch allows to display feature and status bits in virtio-status.

An optional argument is introduced: show-bits. For example:
{"execute": "x-query-virtio-status",
"arguments": {"path":

"/machine/peripheral-anon/device[1]/virtio-backend",

Quoted 11 lines
               "show-bits": true}

Features and status bits could be helpful for applications to compare directly. For instance, when an upper application aims to ensure the virtio negotiation correctness between guest, QEMU, and OVS-DPDK, it use the "ovs-vsctl list interface" command to retrieve interface features (in number format) and the QMP command x-query-virtio-status to retrieve vhost-user net device features. If "show-bits" is added, the application can compare the two features directly; No need to encoding the features returned by the QMP command.

Quoted 1 line

This patch also serves as a preparation for the next one, which

implements

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

Quoted 17 lines

a vhost-user test case about acked features of vhost-user protocol.

Note that since the matching HMP command is typically used for human, leave it unchanged.

---
 hw/virtio/virtio-hmp-cmds.c |  2 +-
 hw/virtio/virtio-qmp.c      | 21 +++++++++++++++-
 qapi/virtio.json            | 49 ++++++++++++++++++++++++++++++++++---
 3 files changed, 67 insertions(+), 5 deletions(-)
hw/virtio/virtio-hmp-cmds.c +0 -0
index 477c97dea2..3774f3d4bf 100644
@@ -108,7 +108,7 @@ 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 5 lines
hw/virtio/virtio-hmp-cmds.c +1 -1
 {
     Error *err = NULL;
     const char *path = qdict_get_try_str(qdict, "path");
-    VirtioStatus *s = qmp_x_query_virtio_status(path, &err);
+    VirtioStatus *s = qmp_x_query_virtio_status(path, false, false,

&err);

hw/virtio/virtio-qmp.c VirtIODevice *qmp_find_virtio_device(const char

Quoted 8 lines
hw/virtio/virtio-hmp-cmds.c +0 -0
     if (err != NULL) {
         hmp_handle_error(mon, err);
hw/virtio/virtio-qmp.c +0 -0
index 1dd96ed20f..2e92bf28ac 100644
@@ -718,10 +718,15 @@ VirtIODevice *qmp_find_virtio_device(const char

*path)

Quoted 3 lines
hw/virtio/virtio-qmp.c +0 -0
     return VIRTIO_DEVICE(dev);
 }
 
Quoted 14 lines

hw/virtio/virtio-qmp.c VirtIODevice *qmp_find_virtio_device(const char *path) · line 729

Quoted 10 lines
hw/virtio/virtio-qmp.c +6 -1
-VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
+VirtioStatus *qmp_x_query_virtio_status(const char *path,
+                                        bool has_show_bits,
+                                        bool show_bits,
+                                        Error **errp)
 {
     VirtIODevice *vdev;
     VirtioStatus *status;
+    bool display_bits =
+        has_show_bits ? show_bits : false;

Since !has_show_bits implies !show_bits, you can simply use if (show_bits).

Ok

Quoted 59 lines

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

Quoted 5 lines
hw/virtio/virtio-qmp.c +0 -0
     vdev = qmp_find_virtio_device(path);
     if (vdev == NULL) {
@@ -733,6 +738,11 @@ 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 12 lines
hw/virtio/virtio-qmp.c +5 -0
     status->name = g_strdup(vdev->name);
     status->device_id = vdev->device_id;
     status->vhost_started = vdev->vhost_started;
+    if (display_bits) {
+        status->guest_features_bits = vdev->guest_features;
+        status->host_features_bits = vdev->host_features;
+        status->backend_features_bits = vdev->backend_features;
+    }
     status->guest_features = qmp_decode_features(vdev->device_id,
                                                  vdev->guest_features);
     status->host_features = qmp_decode_features(vdev->device_id,
@@ -753,6 +763,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

Quoted 10 lines
hw/virtio/virtio-qmp.c +3 -0
     }
 
     status->num_vqs = virtio_get_num_queues(vdev);
+    if (display_bits) {
+        status->status_bits = vdev->status;
+    }
     status->status = qmp_decode_status(vdev->status);
     status->isr = vdev->isr;
     status->queue_sel = vdev->queue_sel;
@@ -775,6 +788,12 @@ 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 6 lines
hw/virtio/virtio-qmp.c +3 -0
         status->vhost_dev->n_tmp_sections = hdev->n_tmp_sections;
         status->vhost_dev->nvqs = hdev->nvqs;
         status->vhost_dev->vq_index = hdev->vq_index;
+        if (display_bits) {
+            status->vhost_dev->features_bits = hdev->features;
+            status->vhost_dev->acked_features_bits =

hdev->acked_features;

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

Quoted 1 line
hw/virtio/virtio-qmp.c +1 -0
+            status->vhost_dev->backend_features_bits =

hdev->backend_features;

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

Quoted 1 line
hw/virtio/virtio-qmp.c +1 -0
+            status->vhost_dev->protocol_features_bits =

hdev->protocol_features;

qapi/virtio.json line 82

Quoted 13 lines
hw/virtio/virtio-qmp.c +1 -0
+        }
         status->vhost_dev->features =
             qmp_decode_features(vdev->device_id, hdev->features);
         status->vhost_dev->acked_features =
qapi/virtio.json +1 -0
index e6dcee7b83..608b841a89 100644
@@ -79,12 +79,20 @@
 #
 # @vq-index: vhost_dev vq_index
 #
+# @features-bits: vhost_dev features in decimal format

Say "encoded as a number". The number is decimal just because the transport is JSON. We could have another transport some day. Or language bindings wrapping around the JSON transport.

Quoted 8 lines

qapi/virtio.json line 84

Quoted 2 lines
qapi/virtio.json +1 -0
+#
 # @features: vhost_dev features

Double-checking... @feature-bits provides the exact same information as @features, only in another encoding. Correct?

Same for all the other new -bits. Correct?

Yes, all the new fields are only about providing another encoding.

Quoted 72 lines
Quoted 32 lines
qapi/virtio.json +10 -0
 #
+# @acked-features-bits: vhost_dev acked_features in decimal format
+#
 # @acked-features: vhost_dev acked_features
 #
+# @backend-features-bits: vhost_dev backend_features in decimal format
+#
 # @backend-features: vhost_dev backend_features
 #
+# @protocol-features-bits: vhost_dev protocol_features in decimal format
+#
 # @protocol-features: vhost_dev protocol_features
 #
 # @max-queues: vhost_dev max_queues
@@ -102,9 +110,13 @@
             'n-tmp-sections': 'int',
             'nvqs': 'uint32',
             'vq-index': 'int',
+            'features-bits': 'uint64',
             'features': 'VirtioDeviceFeatures',
+            'acked-features-bits': 'uint64',
             'acked-features': 'VirtioDeviceFeatures',
+            'backend-features-bits': 'uint64',
             'backend-features': 'VirtioDeviceFeatures',
+            'protocol-features-bits': 'uint64',
             'protocol-features': 'VhostDeviceProtocols',
             'max-queues': 'uint64',
             'backend-cap': 'uint64',
@@ -124,10 +136,16 @@
 #
 # @vhost-started: VirtIODevice vhost_started flag

qapi/virtio.json line 147

Quoted 10 lines
qapi/virtio.json +5 -0
 #
+# @guest-features-bits: VirtIODevice guest_features in decimal format
+#
 # @guest-features: VirtIODevice guest_features
 #
+# @host-features-bits: VirtIODevice host_features in decimal format
+#
 # @host-features: VirtIODevice host_features
 #
+# @backend-features-bits: VirtIODevice backend_features in decimal

format

Quoted 29 lines
qapi/virtio.json +8 -0
+#
 # @backend-features: VirtIODevice backend_features
 #
 # @device-endian: VirtIODevice device_endian
@@ -135,6 +153,9 @@
 # @num-vqs: VirtIODevice virtqueue count.  This is the number of
 #     active virtqueues being used by the VirtIODevice.
 #
+# @status-bits: VirtIODevice configuration status in decimal format
+#     (VirtioDeviceStatus)
+#
 # @status: VirtIODevice configuration status (VirtioDeviceStatus)
 #
 # @isr: VirtIODevice ISR
@@ -170,10 +191,14 @@
             'device-id': 'uint16',
             'vhost-started': 'bool',
             'device-endian': 'str',
+            'guest-features-bits': 'uint64',
             'guest-features': 'VirtioDeviceFeatures',
+            'host-features-bits': 'uint64',
             'host-features': 'VirtioDeviceFeatures',
+            'backend-features-bits': 'uint64',
             'backend-features': 'VirtioDeviceFeatures',
             'num-vqs': 'int',
+            'status-bits': 'uint8',
             'status': 'VirtioDeviceStatus',
             'isr': 'uint8',
             'queue-sel': 'uint16',
Quoted 9 lines

qapi/virtio.json line 224

Quoted 6 lines
qapi/virtio.json +2 -0
@@ -195,6 +220,9 @@
 #
 # @path: Canonical QOM path of the VirtIODevice
 #
+# @show-bits: Whether to display the feature & status bits.
+#     Default is disabled. (Since 8.2)

This makes the new members opt-in. Why not include them always?

Agree, this makes things simple.

Quoted 116 lines

qapi/virtio.json line 211

Quoted 10 lines
qapi/virtio.json +1 -1
+#
 # Features:
 #
 # @unstable: This command is meant for debugging.
@@ -208,7 +236,8 @@
 # 1. Poll for the status of virtio-crypto (no vhost-crypto active)
 #
 # -> { "execute": "x-query-virtio-status",
-#      "arguments": { "path":

"/machine/peripheral/crypto0/virtio-backend" }

qapi/virtio.json line 239

Quoted 1 line
qapi/virtio.json +1 -0
+#      "arguments": { "path":

"/machine/peripheral/crypto0/virtio-backend",

Quoted 13 lines
qapi/virtio.json +2 -0
+#                     "show-bits": true }
 #    }
 # <- { "return": {
 #          "device-endian": "little",
@@ -216,6 +245,7 @@
 #          "disable-legacy-check": false,
 #          "name": "virtio-crypto",
 #          "started": true,
+#          "guest-features-bits": 5100273664,
 #          "device-id": 20,
 #          "backend-features": {
 #              "transports": [],

qapi/virtio.json line 271

Quoted 1 line
qapi/virtio.json +0 -0
@@ -241,6 +271,7 @@
 #                  "VIRTIO_F_VERSION_1: Device compliant for v1 spec

(legacy)"

qapi/virtio.json line 283

Quoted 8 lines
qapi/virtio.json +1 -0
 #              ]
 #          },
+#          "host-features-bits": 6325010432,
 #          "host-features": {
 #              "unknown-dev-features": 1073741824,
 #              "dev-features": [],
@@ -252,9 +283,11 @@
 #                  "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs

out of avail. descs. on VQ"

Quoted 11 lines
qapi/virtio.json +2 -0
 #              ]
 #          },
+#          "backend-features-bits": 0,
 #          "use-guest-notifier-mask": true,
 #          "vm-running": true,
 #          "queue-sel": 1,
+#          "status-bits": 15,
 #          "disabled": false,
 #          "vhost-started": false,
 #          "use-started": true

qapi/virtio.json line 267

Quoted 4 lines
qapi/virtio.json +0 -1
@@ -264,7 +297,8 @@
 # 2. Poll for the status of virtio-net (vhost-net is active)
 #
 # -> { "execute": "x-query-virtio-status",
-#      "arguments": { "path":

"/machine/peripheral-anon/device[1]/virtio-backend" }

qapi/virtio.json line 300

Quoted 1 line
qapi/virtio.json +1 -0
+#      "arguments": { "path":

"/machine/peripheral-anon/device[1]/virtio-backend",

Quoted 28 lines
qapi/virtio.json +5 -0
+#                     "show-bits": true }
 #    }
 # <- { "return": {
 #          "device-endian": "little",
@@ -272,11 +306,13 @@
 #          "disabled-legacy-check": false,
 #          "name": "virtio-net",
 #          "started": true,
+#          "guest-features-bits": 5111807911,
 #          "device-id": 1,
 #          "vhost-dev": {
 #              "n-tmp-sections": 4,
 #              "n-mem-sections": 4,
 #              "max-queues": 1,
+#              "features-bits": 13908344832
 #              "backend-cap": 2,
 #              "log-size": 0,
 #              "backend-features": {
@@ -284,6 +320,8 @@
 #                  "transports": []
 #              },
 #              "nvqs": 2,
+#              "acked-features-bits": 5100306432,
+#              "backend-features-bits": 0,
 #              "protocol-features": {
 #                  "protocols": []
 #              },

qapi/virtio.json line 337

Quoted 1 line
qapi/virtio.json +0 -0
@@ -299,6 +337,7 @@
 #                      "VIRTIO_F_VERSION_1: Device compliant for v1

spec (legacy)"

qapi/virtio.json

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

supported",

qapi/virtio.json line 426

Quoted 2 lines
qapi/virtio.json +0 -0
@@ -387,6 +426,7 @@
 #                  "VIRTIO_F_VERSION_1: Device compliant for v1 spec

(legacy)"

qapi/virtio.json

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

features negotiation supported",

qapi/virtio.json line 460

Quoted 2 lines
qapi/virtio.json +0 -0
@@ -420,9 +460,11 @@
 #                  "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs

out of avail. descs. on VQ"

Quoted 11 lines
qapi/virtio.json +2 -0
 #             ]
 #          },
+#          "backend-features-bits": 6337593319,
 #          "use-guest-notifier-mask": true,
 #          "vm-running": true,
 #          "queue-sel": 2,
+#          "status-bits": 15,
 #          "disabled": false,
 #          "vhost-started": true,
 #          "use-started": true
@@ -430,7 +472,8 @@
Quoted 10 lines

qapi/virtio.json line 478

Quoted 8 lines
qapi/virtio.json +2 -1
 #    }
 ##
 { 'command': 'x-query-virtio-status',
-  'data': { 'path': 'str' },
+  'data': { 'path': 'str',
+            '*show-bits': 'bool'},
   'returns': 'VirtioStatus',
   'features': [ 'unstable' ] }

Yong

Signature · 1 line
Best regards
#4 lore raw

Re: [RFC 1/2] qapi/virtio: introduce the "show-bits" argument for x-query-virtio-status

Laurent, there's a question for you at the end.

Quoted 127 lines · Yong Huang
Quoted 52 lines · Markus Armbruster
Quoted 50 lines · Hyman Huang

This patch allows to display feature and status bits in virtio-status.

An optional argument is introduced: show-bits. For example:
{"execute": "x-query-virtio-status",
"arguments": {"path": "/machine/peripheral-anon/device[1]/virtio-backend",

               "show-bits": true}

Features and status bits could be helpful for applications to compare directly. For instance, when an upper application aims to ensure the virtio negotiation correctness between guest, QEMU, and OVS-DPDK, it use the "ovs-vsctl list interface" command to retrieve interface features (in number format) and the QMP command x-query-virtio-status to retrieve vhost-user net device features. If "show-bits" is added, the application can compare the two features directly; No need to encoding the features returned by the QMP command.

This patch also serves as a preparation for the next one, which implements a vhost-user test case about acked features of vhost-user protocol.

Note that since the matching HMP command is typically used for human, leave it unchanged.

---
 hw/virtio/virtio-hmp-cmds.c |  2 +-
 hw/virtio/virtio-qmp.c      | 21 +++++++++++++++-
 qapi/virtio.json            | 49 ++++++++++++++++++++++++++++++++++---
 3 files changed, 67 insertions(+), 5 deletions(-)
hw/virtio/virtio-hmp-cmds.c +1 -1
index 477c97dea2..3774f3d4bf 100644
@@ -108,7 +108,7 @@ void hmp_virtio_status(Monitor *mon, const QDict *qdict)
 {
     Error *err = NULL;
     const char *path = qdict_get_try_str(qdict, "path");
-    VirtioStatus *s = qmp_x_query_virtio_status(path, &err);
+    VirtioStatus *s = qmp_x_query_virtio_status(path, false, false, &err);
 
     if (err != NULL) {
         hmp_handle_error(mon, err);
hw/virtio/virtio-qmp.c +0 -0
index 1dd96ed20f..2e92bf28ac 100644
@@ -718,10 +718,15 @@ VirtIODevice *qmp_find_virtio_device(const char *path)
     return VIRTIO_DEVICE(dev);
 }
 
Quoted 14 lines

hw/virtio/virtio-qmp.c VirtIODevice *qmp_find_virtio_device(const char *path) · line 729

Quoted 10 lines
hw/virtio/virtio-qmp.c +6 -1
-VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
+VirtioStatus *qmp_x_query_virtio_status(const char *path,
+                                        bool has_show_bits,
+                                        bool show_bits,
+                                        Error **errp)
 {
     VirtIODevice *vdev;
     VirtioStatus *status;
+    bool display_bits =
+        has_show_bits ? show_bits : false;

Since !has_show_bits implies !show_bits, you can simply use if (show_bits).

Ok

Quoted 56 lines
Quoted 44 lines
hw/virtio/virtio-qmp.c +14 -0
     vdev = qmp_find_virtio_device(path);
     if (vdev == NULL) {
@@ -733,6 +738,11 @@ 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;
+    if (display_bits) {
+        status->guest_features_bits = vdev->guest_features;
+        status->host_features_bits = vdev->host_features;
+        status->backend_features_bits = vdev->backend_features;
+    }
     status->guest_features = qmp_decode_features(vdev->device_id,
                                                  vdev->guest_features);
     status->host_features = qmp_decode_features(vdev->device_id,
@@ -753,6 +763,9 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
     }
 
     status->num_vqs = virtio_get_num_queues(vdev);
+    if (display_bits) {
+        status->status_bits = vdev->status;
+    }
     status->status = qmp_decode_status(vdev->status);
     status->isr = vdev->isr;
     status->queue_sel = vdev->queue_sel;
@@ -775,6 +788,12 @@ 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;
+        if (display_bits) {
+            status->vhost_dev->features_bits = hdev->features;
+            status->vhost_dev->acked_features_bits = hdev->acked_features;
+            status->vhost_dev->backend_features_bits = hdev->backend_features;
+            status->vhost_dev->protocol_features_bits = hdev->protocol_features;
+        }
         status->vhost_dev->features =
             qmp_decode_features(vdev->device_id, hdev->features);
         status->vhost_dev->acked_features =
qapi/virtio.json +0 -0
index e6dcee7b83..608b841a89 100644

qapi/virtio.json line 82

Quoted 4 lines
qapi/virtio.json +1 -0
@@ -79,12 +79,20 @@
 #
 # @vq-index: vhost_dev vq_index
 #
+# @features-bits: vhost_dev features in decimal format

Say "encoded as a number". The number is decimal just because the transport is JSON. We could have another transport some day. Or language bindings wrapping around the JSON transport.

Quoted 2 lines
qapi/virtio.json +1 -0
+#
 # @features: vhost_dev features
Quoted 7 lines
Quoted 5 lines

Double-checking... @feature-bits provides the exact same information as @features, only in another encoding. Correct?

Same for all the other new -bits. Correct?

Yes, all the new fields are only about providing another encoding.

Why do we want to return the same information in two different encodings? I figure the commit message tries to answer this question:

Features and status bits could be helpful for applications to compare directly. For instance, when an upper application aims to ensure the virtio negotiation correctness between guest, QEMU, and OVS-DPDK, it use the "ovs-vsctl list interface" command to retrieve interface features (in number format) and the QMP command x-query-virtio-status to retrieve vhost-user net device features. If "show-bits" is added, the application can compare the two features directly; No need to encoding the features returned by the QMP command.

This patch also serves as a preparation for the next one, which implements a vhost-user test case about acked features of vhost-user protocol.

I guess you're trying to simplify use cases where the QMP client wants to compare entire feature sets without caring for individual features.

The comparison is easy if both sets are represented the same way, e.g. both are numbers, or both are lists of symbols.

With different representations, we first have to map to a common representation. Unfortunately, the design of x-query-virtio-status makes this harder than it should be.

We use QAPI types VirtioDeviceStatus, VhostDeviceProtocols, VirtioDeviceFeatures to represent feature sets. They all work the same
way: array of strings plus a number. For each bit QEMU knows, there's a string in the array. Any remaining bits go into the number.

The format of the string is undocumented. They look like

"WELL_KNOWN_SYMBOL: human readable explanation"

Mapping from bit to this string in a client would require duplicating QEMU's code exactly.

Mapping both bit and string to just "WELL_KNOWN_SYMBOL" could perhaps be done.

The mapping between symbols and bits is not visible in QMP. Mapping from string to bit requires exploiting the undocumented format: extract the well-known symbol and decode it.

This encoding of feature sets goes back to commit f3034ad71fc (qmp:
decode feature & status bits in virtio-status) v7.2. Before that, the command returned the bits as a number.

For example, return value "member "status":

    Before f3034ad71fc:

        "status": 15,

    Since f3034ad71fc:

        "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"
            ]},

    With your patch:

        "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-bits": 15,

Looks like commit f3034ad71fc improved one use case at the expense of another, and your patch tries to revert the damage. Which one exactly it improved is unclear; the commit message doesn't tell. Laurent?

[...]

author
#5 lore raw

Re: [RFC 1/2] qapi/virtio: introduce the "show-bits" argument for x-query-virtio-status

Quoted 177 lines · Markus Armbruster

Laurent, there's a question for you at the end.

Quoted 10 lines · Yong Huang
Quoted 7 lines · Markus Armbruster
Quoted 5 lines · Hyman Huang

This patch allows to display feature and status bits in virtio-status.

An optional argument is introduced: show-bits. For example:
{"execute": "x-query-virtio-status",
"arguments": {"path":

"/machine/peripheral-anon/device[1]/virtio-backend",

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
               "show-bits": true}

Features and status bits could be helpful for applications to compare directly. For instance, when an upper application aims to ensure the virtio negotiation correctness between guest, QEMU, and OVS-DPDK, it

use

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

the "ovs-vsctl list interface" command to retrieve interface features (in number format) and the QMP command x-query-virtio-status to

retrieve

Quoted 1 line
Quoted 1 line
Quoted 1 line

vhost-user net device features. If "show-bits" is added, the

application

Quoted 1 line
Quoted 1 line
Quoted 1 line

can compare the two features directly; No need to encoding the

features

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

returned by the QMP command.

This patch also serves as a preparation for the next one, which

implements

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

a vhost-user test case about acked features of vhost-user protocol.

Note that since the matching HMP command is typically used for human, leave it unchanged.

---
 hw/virtio/virtio-hmp-cmds.c |  2 +-
 hw/virtio/virtio-qmp.c      | 21 +++++++++++++++-
 qapi/virtio.json            | 49

++++++++++++++++++++++++++++++++++---

Quoted 7 lines
Quoted 7 lines

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

Quoted 7 lines
 3 files changed, 67 insertions(+), 5 deletions(-)
hw/virtio/virtio-hmp-cmds.c +0 -0
index 477c97dea2..3774f3d4bf 100644
@@ -108,7 +108,7 @@ void hmp_virtio_status(Monitor *mon, const QDict

*qdict)

Quoted 5 lines
Quoted 5 lines

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

Quoted 5 lines
hw/virtio/virtio-hmp-cmds.c +1 -1
 {
     Error *err = NULL;
     const char *path = qdict_get_try_str(qdict, "path");
-    VirtioStatus *s = qmp_x_query_virtio_status(path, &err);
+    VirtioStatus *s = qmp_x_query_virtio_status(path, false, false,

&err);

Quoted 8 lines
Quoted 8 lines

hw/virtio/virtio-qmp.c VirtIODevice *qmp_find_virtio_device(const char

Quoted 8 lines
hw/virtio/virtio-hmp-cmds.c +0 -0
     if (err != NULL) {
         hmp_handle_error(mon, err);
hw/virtio/virtio-qmp.c +0 -0
index 1dd96ed20f..2e92bf28ac 100644
@@ -718,10 +718,15 @@ VirtIODevice *qmp_find_virtio_device(const char

*path)

Quoted 4 lines
Quoted 4 lines

hw/virtio/virtio-qmp.c VirtIODevice *qmp_find_virtio_device(const char *path)

Quoted 4 lines
hw/virtio/virtio-qmp.c +0 -1
     return VIRTIO_DEVICE(dev);
 }
 
-VirtioStatus *qmp_x_query_virtio_status(const char *path, Error

**errp)

Quoted 13 lines
Quoted 10 lines

hw/virtio/virtio-qmp.c VirtIODevice *qmp_find_virtio_device(const char *path) · line 729

Quoted 9 lines
hw/virtio/virtio-qmp.c +6 -0
+VirtioStatus *qmp_x_query_virtio_status(const char *path,
+                                        bool has_show_bits,
+                                        bool show_bits,
+                                        Error **errp)
 {
     VirtIODevice *vdev;
     VirtioStatus *status;
+    bool display_bits =
+        has_show_bits ? show_bits : false;
Quoted 3 lines

Since !has_show_bits implies !show_bits, you can simply use if (show_bits).

Quoted 7 lines

Ok

Quoted 5 lines

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

Quoted 5 lines
hw/virtio/virtio-qmp.c +0 -0
     vdev = qmp_find_virtio_device(path);
     if (vdev == NULL) {
@@ -733,6 +738,11 @@ VirtioStatus *qmp_x_query_virtio_status(const

char *path, Error **errp)

Quoted 10 lines
Quoted 10 lines

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

Quoted 10 lines
hw/virtio/virtio-qmp.c +5 -0
     status->name = g_strdup(vdev->name);
     status->device_id = vdev->device_id;
     status->vhost_started = vdev->vhost_started;
+    if (display_bits) {
+        status->guest_features_bits = vdev->guest_features;
+        status->host_features_bits = vdev->host_features;
+        status->backend_features_bits = vdev->backend_features;
+    }
     status->guest_features = qmp_decode_features(vdev->device_id,
 

vdev->guest_features);

Quoted 2 lines
Quoted 2 lines

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

Quoted 2 lines
hw/virtio/virtio-qmp.c +0 -0
     status->host_features = qmp_decode_features(vdev->device_id,
@@ -753,6 +763,9 @@ VirtioStatus *qmp_x_query_virtio_status(const

char *path, Error **errp)

Quoted 10 lines
Quoted 10 lines

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

Quoted 10 lines
hw/virtio/virtio-qmp.c +3 -0
     }
 
     status->num_vqs = virtio_get_num_queues(vdev);
+    if (display_bits) {
+        status->status_bits = vdev->status;
+    }
     status->status = qmp_decode_status(vdev->status);
     status->isr = vdev->isr;
     status->queue_sel = vdev->queue_sel;
@@ -775,6 +788,12 @@ VirtioStatus *qmp_x_query_virtio_status(const

char *path, Error **errp)

Quoted 6 lines
Quoted 6 lines

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

Quoted 6 lines
hw/virtio/virtio-qmp.c +3 -0
         status->vhost_dev->n_tmp_sections = hdev->n_tmp_sections;
         status->vhost_dev->nvqs = hdev->nvqs;
         status->vhost_dev->vq_index = hdev->vq_index;
+        if (display_bits) {
+            status->vhost_dev->features_bits = hdev->features;
+            status->vhost_dev->acked_features_bits =

hdev->acked_features;

Quoted 1 line
Quoted 1 line

hw/virtio/virtio-qmp.c VirtioStatus *qmp_x_query_virtio_status(const · line 794

Quoted 1 line
hw/virtio/virtio-qmp.c +1 -0
+            status->vhost_dev->backend_features_bits =

hdev->backend_features;

Quoted 1 line
Quoted 1 line

hw/virtio/virtio-qmp.c VirtioStatus *qmp_x_query_virtio_status(const · line 795

Quoted 1 line
hw/virtio/virtio-qmp.c +1 -0
+            status->vhost_dev->protocol_features_bits =

hdev->protocol_features;

Quoted 21 lines
Quoted 21 lines

qapi/virtio.json line 82

Quoted 13 lines
hw/virtio/virtio-qmp.c +1 -0
+        }
         status->vhost_dev->features =
             qmp_decode_features(vdev->device_id, hdev->features);
         status->vhost_dev->acked_features =
qapi/virtio.json +1 -0
index e6dcee7b83..608b841a89 100644
@@ -79,12 +79,20 @@
 #
 # @vq-index: vhost_dev vq_index
 #
+# @features-bits: vhost_dev features in decimal format

Say "encoded as a number". The number is decimal just because the transport is JSON. We could have another transport some day. Or language bindings wrapping around the JSON transport.

Quoted 2 lines
qapi/virtio.json +1 -0
+#
 # @features: vhost_dev features
Quoted 7 lines
Quoted 5 lines

Double-checking... @feature-bits provides the exact same information as @features, only in another encoding. Correct?

Same for all the other new -bits. Correct?

Yes, all the new fields are only about providing another encoding.

Why do we want to return the same information in two different encodings? I figure the commit message tries to answer this question:

Features and status bits could be helpful for applications to compare directly. For instance, when an upper application aims to ensure the virtio negotiation correctness between guest, QEMU, and OVS-DPDK, it
use
the "ovs-vsctl list interface" command to retrieve interface features (in number format) and the QMP command x-query-virtio-status to
retrieve
vhost-user net device features. If "show-bits" is added, the
application
can compare the two features directly; No need to encoding the
features
returned by the QMP command.

This patch also serves as a preparation for the next one, which
implements
a vhost-user test case about acked features of vhost-user protocol.

Quoted 5 lines

I guess you're trying to simplify use cases where the QMP client wants to compare entire feature sets without caring for individual features.

The comparison is easy if both sets are represented the same way, e.g. both are numbers, or both are lists of symbols.

Yes, quite correct, this patch just aims to keep the unencoded bits for easy comparison.

Quoted 66 lines

With different representations, we first have to map to a common representation. Unfortunately, the design of x-query-virtio-status makes this harder than it should be.

We use QAPI types VirtioDeviceStatus, VhostDeviceProtocols, VirtioDeviceFeatures to represent feature sets. They all work the same
way: array of strings plus a number. For each bit QEMU knows, there's a string in the array. Any remaining bits go into the number.

The format of the string is undocumented. They look like

"WELL_KNOWN_SYMBOL: human readable explanation"

Mapping from bit to this string in a client would require duplicating QEMU's code exactly.

Mapping both bit and string to just "WELL_KNOWN_SYMBOL" could perhaps be done.

The mapping between symbols and bits is not visible in QMP. Mapping from string to bit requires exploiting the undocumented format: extract the well-known symbol and decode it.

This encoding of feature sets goes back to commit f3034ad71fc (qmp:
decode feature & status bits in virtio-status) v7.2. Before that, the command returned the bits as a number.

For example, return value "member "status":

    Before f3034ad71fc:

        "status": 15,

    Since f3034ad71fc:

        "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"
]},

With your patch:

"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-bits": 15,

Looks like commit f3034ad71fc improved one use case at the expense of another, and your patch tries to revert the damage. Which one exactly it improved is unclear; the commit message doesn't tell. Laurent?

[...]

Signature · 1 line
Best regards
#6 lore raw

Re: [RFC 1/2] qapi/virtio: introduce the "show-bits" argument for x-query-virtio-status

In reply to Markus Armbruster
Quoted 214 lines · Markus Armbruster

Laurent, there's a question for you at the end.

Quoted 127 lines · Yong Huang
Quoted 52 lines · Markus Armbruster
Quoted 50 lines · Hyman Huang

This patch allows to display feature and status bits in virtio-status.

An optional argument is introduced: show-bits. For example:
{"execute": "x-query-virtio-status",
"arguments": {"path": "/machine/peripheral-anon/device[1]/virtio-backend",

                "show-bits": true}

Features and status bits could be helpful for applications to compare directly. For instance, when an upper application aims to ensure the virtio negotiation correctness between guest, QEMU, and OVS-DPDK, it use the "ovs-vsctl list interface" command to retrieve interface features (in number format) and the QMP command x-query-virtio-status to retrieve vhost-user net device features. If "show-bits" is added, the application can compare the two features directly; No need to encoding the features returned by the QMP command.

This patch also serves as a preparation for the next one, which implements a vhost-user test case about acked features of vhost-user protocol.

Note that since the matching HMP command is typically used for human, leave it unchanged.

---
  hw/virtio/virtio-hmp-cmds.c |  2 +-
  hw/virtio/virtio-qmp.c      | 21 +++++++++++++++-
  qapi/virtio.json            | 49 ++++++++++++++++++++++++++++++++++---
  3 files changed, 67 insertions(+), 5 deletions(-)
hw/virtio/virtio-hmp-cmds.c +1 -1
index 477c97dea2..3774f3d4bf 100644
@@ -108,7 +108,7 @@ void hmp_virtio_status(Monitor *mon, const QDict *qdict)
  {
      Error *err = NULL;
      const char *path = qdict_get_try_str(qdict, "path");
-    VirtioStatus *s = qmp_x_query_virtio_status(path, &err);
+    VirtioStatus *s = qmp_x_query_virtio_status(path, false, false, &err);
 
      if (err != NULL) {
          hmp_handle_error(mon, err);
hw/virtio/virtio-qmp.c +0 -0
index 1dd96ed20f..2e92bf28ac 100644
@@ -718,10 +718,15 @@ VirtIODevice *qmp_find_virtio_device(const char *path)
      return VIRTIO_DEVICE(dev);
  }
 
Quoted 14 lines

hw/virtio/virtio-qmp.c VirtIODevice *qmp_find_virtio_device(const char *path) · line 729

Quoted 10 lines
hw/virtio/virtio-qmp.c +6 -1
-VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
+VirtioStatus *qmp_x_query_virtio_status(const char *path,
+                                        bool has_show_bits,
+                                        bool show_bits,
+                                        Error **errp)
  {
      VirtIODevice *vdev;
      VirtioStatus *status;
+    bool display_bits =
+        has_show_bits ? show_bits : false;

Since !has_show_bits implies !show_bits, you can simply use if (show_bits).

Ok

Quoted 56 lines
Quoted 44 lines
hw/virtio/virtio-qmp.c +14 -0
      vdev = qmp_find_virtio_device(path);
      if (vdev == NULL) {
@@ -733,6 +738,11 @@ 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;
+    if (display_bits) {
+        status->guest_features_bits = vdev->guest_features;
+        status->host_features_bits = vdev->host_features;
+        status->backend_features_bits = vdev->backend_features;
+    }
      status->guest_features = qmp_decode_features(vdev->device_id,
                                                   vdev->guest_features);
      status->host_features = qmp_decode_features(vdev->device_id,
@@ -753,6 +763,9 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
      }
 
      status->num_vqs = virtio_get_num_queues(vdev);
+    if (display_bits) {
+        status->status_bits = vdev->status;
+    }
      status->status = qmp_decode_status(vdev->status);
      status->isr = vdev->isr;
      status->queue_sel = vdev->queue_sel;
@@ -775,6 +788,12 @@ 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;
+        if (display_bits) {
+            status->vhost_dev->features_bits = hdev->features;
+            status->vhost_dev->acked_features_bits = hdev->acked_features;
+            status->vhost_dev->backend_features_bits = hdev->backend_features;
+            status->vhost_dev->protocol_features_bits = hdev->protocol_features;
+        }
          status->vhost_dev->features =
              qmp_decode_features(vdev->device_id, hdev->features);
          status->vhost_dev->acked_features =
qapi/virtio.json +0 -0
index e6dcee7b83..608b841a89 100644

qapi/virtio.json line 82

Quoted 4 lines
qapi/virtio.json +1 -0
@@ -79,12 +79,20 @@
  #
  # @vq-index: vhost_dev vq_index
  #
+# @features-bits: vhost_dev features in decimal format

Say "encoded as a number". The number is decimal just because the transport is JSON. We could have another transport some day. Or language bindings wrapping around the JSON transport.

Quoted 2 lines
qapi/virtio.json +1 -0
+#
  # @features: vhost_dev features
Quoted 7 lines
Quoted 5 lines

Double-checking... @feature-bits provides the exact same information as @features, only in another encoding. Correct?

Same for all the other new -bits. Correct?

Yes, all the new fields are only about providing another encoding.

Why do we want to return the same information in two different encodings? I figure the commit message tries to answer this question:

Features and status bits could be helpful for applications to compare directly. For instance, when an upper application aims to ensure the virtio negotiation correctness between guest, QEMU, and OVS-DPDK, it use the "ovs-vsctl list interface" command to retrieve interface features (in number format) and the QMP command x-query-virtio-status to retrieve vhost-user net device features. If "show-bits" is added, the application can compare the two features directly; No need to encoding the features returned by the QMP command.

This patch also serves as a preparation for the next one, which implements a vhost-user test case about acked features of vhost-user protocol.

I guess you're trying to simplify use cases where the QMP client wants to compare entire feature sets without caring for individual features.

The comparison is easy if both sets are represented the same way, e.g. both are numbers, or both are lists of symbols.

With different representations, we first have to map to a common representation. Unfortunately, the design of x-query-virtio-status makes this harder than it should be.

We use QAPI types VirtioDeviceStatus, VhostDeviceProtocols, VirtioDeviceFeatures to represent feature sets. They all work the same
way: array of strings plus a number. For each bit QEMU knows, there's a string in the array. Any remaining bits go into the number.

The format of the string is undocumented. They look like

"WELL_KNOWN_SYMBOL: human readable explanation"

Mapping from bit to this string in a client would require duplicating QEMU's code exactly.

Mapping both bit and string to just "WELL_KNOWN_SYMBOL" could perhaps be done.

The mapping between symbols and bits is not visible in QMP. Mapping from string to bit requires exploiting the undocumented format: extract the well-known symbol and decode it.

This encoding of feature sets goes back to commit f3034ad71fc (qmp:
decode feature & status bits in virtio-status) v7.2. Before that, the command returned the bits as a number.

For example, return value "member "status":

     Before f3034ad71fc:

         "status": 15,

     Since f3034ad71fc:

         "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"
             ]},

     With your patch:

         "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-bits": 15,
Quoted 6 lines

Looks like commit f3034ad71fc improved one use case at the expense of another, and your patch tries to revert the damage. Which one exactly it improved is unclear; the commit message doesn't tell. Laurent?

[...]

The first idea of the series "hmp,qmp: Add commands to introspect virtio devices" including commit f3034ad71fc was to help developer to debug virtio devices, so for this purpose it was interesting to display the status in a human readable manner.

Of course, if you want to run automatic tests and be able to compare the result to have the status bits result seems to be better.

As these are two different use cases, it's understandable to have two different representations of the same information.

Thanks,
Laurent

#7 lore raw

Re: [RFC 1/2] qapi/virtio: introduce the "show-bits" argument for x-query-virtio-status

Quoted 33 lines · Laurent Vivier
Quoted 32 lines · Markus Armbruster

Laurent, there's a question for you at the end.

Quoted 28 lines · Yong Huang
Quoted 25 lines · Markus Armbruster
Quoted 23 lines · Hyman Huang

This patch allows to display feature and status bits in virtio-status.

An optional argument is introduced: show-bits. For example:
{"execute": "x-query-virtio-status",
"arguments": {"path": "/machine/peripheral-anon/device[1]/virtio-backend",

                "show-bits": true}

Features and status bits could be helpful for applications to compare directly. For instance, when an upper application aims to ensure the virtio negotiation correctness between guest, QEMU, and OVS-DPDK, it use the "ovs-vsctl list interface" command to retrieve interface features (in number format) and the QMP command x-query-virtio-status to retrieve vhost-user net device features. If "show-bits" is added, the application can compare the two features directly; No need to encoding the features returned by the QMP command.

This patch also serves as a preparation for the next one, which implements a vhost-user test case about acked features of vhost-user protocol.

Note that since the matching HMP command is typically used for human, leave it unchanged.

[...]

Quoted 94 lines
Quoted 83 lines
Quoted 7 lines
Quoted 5 lines

Double-checking... @feature-bits provides the exact same information as @features, only in another encoding. Correct?

Same for all the other new -bits. Correct?

Yes, all the new fields are only about providing another encoding.

Why do we want to return the same information in two different encodings? I figure the commit message tries to answer this question:

Features and status bits could be helpful for applications to compare directly. For instance, when an upper application aims to ensure the virtio negotiation correctness between guest, QEMU, and OVS-DPDK, it use the "ovs-vsctl list interface" command to retrieve interface features (in number format) and the QMP command x-query-virtio-status to retrieve vhost-user net device features. If "show-bits" is added, the application can compare the two features directly; No need to encoding the features returned by the QMP command.

This patch also serves as a preparation for the next one, which implements a vhost-user test case about acked features of vhost-user protocol.

I guess you're trying to simplify use cases where the QMP client wants to compare entire feature sets without caring for individual features.

The comparison is easy if both sets are represented the same way, e.g. both are numbers, or both are lists of symbols.

With different representations, we first have to map to a common representation. Unfortunately, the design of x-query-virtio-status makes this harder than it should be.

We use QAPI types VirtioDeviceStatus, VhostDeviceProtocols, VirtioDeviceFeatures to represent feature sets. They all work the same
way: array of strings plus a number. For each bit QEMU knows, there's a string in the array. Any remaining bits go into the number.

The format of the string is undocumented. They look like

"WELL_KNOWN_SYMBOL: human readable explanation"

Mapping from bit to this string in a client would require duplicating QEMU's code exactly.

Mapping both bit and string to just "WELL_KNOWN_SYMBOL" could perhaps be done.

The mapping between symbols and bits is not visible in QMP. Mapping from string to bit requires exploiting the undocumented format: extract the well-known symbol and decode it.

This encoding of feature sets goes back to commit f3034ad71fc (qmp:
decode feature & status bits in virtio-status) v7.2. Before that, the command returned the bits as a number.

For example, return value "member "status":

     Before f3034ad71fc:

         "status": 15,

     Since f3034ad71fc:

         "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"
             ]},

     With your patch:

         "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-bits": 15,
Quoted 6 lines

Looks like commit f3034ad71fc improved one use case at the expense of another, and your patch tries to revert the damage. Which one exactly it improved is unclear; the commit message doesn't tell. Laurent?

[...]

The first idea of the series "hmp,qmp: Add commands to introspect virtio devices" including commit f3034ad71fc was to help developer to debug virtio devices, so for this purpose it was interesting to display the status in a human readable manner.

Quoted 5 lines

Of course, if you want to run automatic tests and be able to compare the result to have the status bits result seems to be better.

As these are two different use cases, it's understandable to have two different representations of the same information.

Thanks!

Both use cases are valid, but I dislike both the existing and the proposed interface.

We can change it: x-query-virtio-status isn't stable (it's for debugging and testing). But even unstable interfaces should only be changed for good, clear reasons.

I feel the change from "bits encoded as a number" to "bits as list of descriptive strings plus number for the unknown ones" fell short. Let me explain.

The initial version of the command had "bits encoded as number". Unless we understand why that was done, we should assume it was done for a reason. We now know it was: Hyman Huang posted a patch to get it back.

Instead of "bits as list of descriptive strings plus number for the unknown ones", we could have done "bits encoded as number, plus list of descriptive strings", or plus some other human-readable encoding.

QMP output of the form "WELL_KNOWN_SYMBOL: human readable explanation" smells of encoding structured information in strings, which is a no-no.

Perhaps we could have added human-readable output just in HMP. That's what we normally do.

Here are a few possible alternatives to Hyman Huang's patch:

1. Revert commit f3034ad71fc for QMP, keep it for HMP.

2. Replace @unknown-FOO (just the unknown bits) by @FOO-bits (all bits).

3. Add @FOO-bits next to @unknown-FOO, deprecate @unknown-FOO.

4. Create a QAPI enum for the known bits. Clients can use introspection to learn the mapping between symbols and bits. Requires dumbing down the descriptive strings to just the symbols. This feels both overengineered and cumbersome to use.

For 2 and 3, I'd prefer to also dumb down the descriptive strings to just the symbols.

Thoughts?

#8 lore raw

Re: [RFC 1/2] qapi/virtio: introduce the "show-bits" argument for x-query-virtio-status

Quoted 178 lines · Markus Armbruster
Quoted 33 lines · Laurent Vivier
Quoted 32 lines · Markus Armbruster

Laurent, there's a question for you at the end.

Quoted 28 lines · Yong Huang
Quoted 25 lines · Markus Armbruster
Quoted 23 lines · Hyman Huang

This patch allows to display feature and status bits in virtio-status.

An optional argument is introduced: show-bits. For example:
{"execute": "x-query-virtio-status",
"arguments": {"path": "/machine/peripheral-anon/device[1]/virtio-backend",

                 "show-bits": true}

Features and status bits could be helpful for applications to compare directly. For instance, when an upper application aims to ensure the virtio negotiation correctness between guest, QEMU, and OVS-DPDK, it use the "ovs-vsctl list interface" command to retrieve interface features (in number format) and the QMP command x-query-virtio-status to retrieve vhost-user net device features. If "show-bits" is added, the application can compare the two features directly; No need to encoding the features returned by the QMP command.

This patch also serves as a preparation for the next one, which implements a vhost-user test case about acked features of vhost-user protocol.

Note that since the matching HMP command is typically used for human, leave it unchanged.

[...]

Quoted 94 lines
Quoted 83 lines
Quoted 7 lines
Quoted 5 lines

Double-checking... @feature-bits provides the exact same information as @features, only in another encoding. Correct?

Same for all the other new -bits. Correct?

Yes, all the new fields are only about providing another encoding.

Why do we want to return the same information in two different encodings? I figure the commit message tries to answer this question:

Features and status bits could be helpful for applications to compare directly. For instance, when an upper application aims to ensure the virtio negotiation correctness between guest, QEMU, and OVS-DPDK, it use the "ovs-vsctl list interface" command to retrieve interface features (in number format) and the QMP command x-query-virtio-status to retrieve vhost-user net device features. If "show-bits" is added, the application can compare the two features directly; No need to encoding the features returned by the QMP command.

This patch also serves as a preparation for the next one, which implements a vhost-user test case about acked features of vhost-user protocol.

I guess you're trying to simplify use cases where the QMP client wants to compare entire feature sets without caring for individual features.

The comparison is easy if both sets are represented the same way, e.g. both are numbers, or both are lists of symbols.

With different representations, we first have to map to a common representation. Unfortunately, the design of x-query-virtio-status makes this harder than it should be.

We use QAPI types VirtioDeviceStatus, VhostDeviceProtocols, VirtioDeviceFeatures to represent feature sets. They all work the same
way: array of strings plus a number. For each bit QEMU knows, there's a string in the array. Any remaining bits go into the number.

The format of the string is undocumented. They look like

"WELL_KNOWN_SYMBOL: human readable explanation"

Mapping from bit to this string in a client would require duplicating QEMU's code exactly.

Mapping both bit and string to just "WELL_KNOWN_SYMBOL" could perhaps be done.

The mapping between symbols and bits is not visible in QMP. Mapping from string to bit requires exploiting the undocumented format: extract the well-known symbol and decode it.

This encoding of feature sets goes back to commit f3034ad71fc (qmp:
decode feature & status bits in virtio-status) v7.2. Before that, the command returned the bits as a number.

For example, return value "member "status":

      Before f3034ad71fc:

          "status": 15,

      Since f3034ad71fc:

          "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"
              ]},

      With your patch:

          "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-bits": 15,
Quoted 6 lines

Looks like commit f3034ad71fc improved one use case at the expense of another, and your patch tries to revert the damage. Which one exactly it improved is unclear; the commit message doesn't tell. Laurent?

[...]

The first idea of the series "hmp,qmp: Add commands to introspect virtio devices" including commit f3034ad71fc was to help developer to debug virtio devices, so for this purpose it was interesting to display the status in a human readable manner.

Quoted 5 lines

Of course, if you want to run automatic tests and be able to compare the result to have the status bits result seems to be better.

As these are two different use cases, it's understandable to have two different representations of the same information.

Thanks!

Both use cases are valid, but I dislike both the existing and the proposed interface.

We can change it: x-query-virtio-status isn't stable (it's for debugging and testing). But even unstable interfaces should only be changed for good, clear reasons.

I feel the change from "bits encoded as a number" to "bits as list of descriptive strings plus number for the unknown ones" fell short. Let me explain.

The initial version of the command had "bits encoded as number". Unless we understand why that was done, we should assume it was done for a reason. We now know it was: Hyman Huang posted a patch to get it back.

Instead of "bits as list of descriptive strings plus number for the unknown ones", we could have done "bits encoded as number, plus list of descriptive strings", or plus some other human-readable encoding.

QMP output of the form "WELL_KNOWN_SYMBOL: human readable explanation" smells of encoding structured information in strings, which is a no-no.

Perhaps we could have added human-readable output just in HMP. That's what we normally do.

Here are a few possible alternatives to Hyman Huang's patch:

1. Revert commit f3034ad71fc for QMP, keep it for HMP.

2. Replace @unknown-FOO (just the unknown bits) by @FOO-bits (all bits).

3. Add @FOO-bits next to @unknown-FOO, deprecate @unknown-FOO.

4. Create a QAPI enum for the known bits. Clients can use introspection to learn the mapping between symbols and bits. Requires dumbing down the descriptive strings to just the symbols. This feels both overengineered and cumbersome to use.

Quoted 5 lines

For 2 and 3, I'd prefer to also dumb down the descriptive strings to just the symbols.

Thoughts?

I agree with you. As x-CMD are unstable, perhaps we can go directly to 2?
(and of course to remove the descriptive strings. Is it easily possible to keep them for the HMP version?)

Thanks,
Laurent

#9 lore raw

Re: [RFC 1/2] qapi/virtio: introduce the "show-bits" argument for x-query-virtio-status

Quoted 1 line · Laurent Vivier

On 12/1/23 16:21, Markus Armbruster wrote:

[...]

Quoted 38 lines
Quoted 38 lines

Both use cases are valid, but I dislike both the existing and the proposed interface.

We can change it: x-query-virtio-status isn't stable (it's for debugging and testing). But even unstable interfaces should only be changed for good, clear reasons.

I feel the change from "bits encoded as a number" to "bits as list of descriptive strings plus number for the unknown ones" fell short. Let me explain.

The initial version of the command had "bits encoded as number". Unless we understand why that was done, we should assume it was done for a reason. We now know it was: Hyman Huang posted a patch to get it back.

Instead of "bits as list of descriptive strings plus number for the unknown ones", we could have done "bits encoded as number, plus list of descriptive strings", or plus some other human-readable encoding.

QMP output of the form "WELL_KNOWN_SYMBOL: human readable explanation" smells of encoding structured information in strings, which is a no-no.

Perhaps we could have added human-readable output just in HMP. That's what we normally do.

Here are a few possible alternatives to Hyman Huang's patch:

1. Revert commit f3034ad71fc for QMP, keep it for HMP.

2. Replace @unknown-FOO (just the unknown bits) by @FOO-bits (all bits).

3. Add @FOO-bits next to @unknown-FOO, deprecate @unknown-FOO.

4. Create a QAPI enum for the known bits. Clients can use introspection to learn the mapping between symbols and bits. Requires dumbing down the descriptive strings to just the symbols. This feels both overengineered and cumbersome to use.

Quoted 7 lines
Quoted 5 lines

For 2 and 3, I'd prefer to also dumb down the descriptive strings to just the symbols.

Thoughts?

I agree with you. As x-CMD are unstable, perhaps we can go directly to 2?

We can. It might incovenience existing users of @unknown-FOO.

Quoted 1 line

(and of course to remove the descriptive strings. Is it easily possible to keep them for the HMP version?)

We could change qmp_virtio_feature_map_t to

    typedef struct {
        int virtio_bit;
        const char *feature_name;
        const char *feature_desc;
    } qmp_virtio_feature_map_t;

and FEATURE_ENTRY() to

    #define FEATURE_ENTRY(bit, name, desc) (qmp_virtio_feature_map_t) \
        { .virtio_bit = (bit), .feature_name = (name), .feature_desc = (desc) }

Aside: POSIX reserves names ending with _t. An actual clash is of course vanishingly unlikely. But avoiding _t suffix is a good habit.

qmp_x_query_virtio_status() could then convert bits to a list of known names using .feature_name.

To keep the descriptions in HMP, simply print the bits using .feature_name and .feature_desc, ignoring list of known names returned by qmp_x_query_virtio_status().

Alternatively, make the code to convert bits to list of strings flexible enough to be usable in both places.

If qmp_virtio_feature_map_t is still only used in virtio-qmp.c, move its there.

author
#10 lore raw

Re: [RFC 1/2] qapi/virtio: introduce the "show-bits" argument for x-query-virtio-status

In reply to Laurent Vivier
Quoted 219 lines · Laurent Vivier
Quoted 7 lines · Markus Armbruster
Quoted 5 lines · Laurent Vivier
Quoted 4 lines · Markus Armbruster

Laurent, there's a question for you at the end.

Yong Huang <[email protected]> writes:

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

On Thu, Nov 16, 2023 at 10:44 PM Markus Armbruster <[email protected]

Quoted 3 lines · wrote:
Quoted 1 line · Hyman Huang

This patch allows to display feature and status bits in

virtio-status.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

An optional argument is introduced: show-bits. For example:
{"execute": "x-query-virtio-status",
"arguments": {"path":

"/machine/peripheral-anon/device[1]/virtio-backend",

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
                 "show-bits": true}

Features and status bits could be helpful for applications to

compare

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

directly. For instance, when an upper application aims to ensure the virtio negotiation correctness between guest, QEMU, and OVS-DPDK,

it use

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

the "ovs-vsctl list interface" command to retrieve interface

features

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

(in number format) and the QMP command x-query-virtio-status to

retrieve

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

vhost-user net device features. If "show-bits" is added, the

application

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

can compare the two features directly; No need to encoding the

features

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

returned by the QMP command.

This patch also serves as a preparation for the next one, which

implements

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

a vhost-user test case about acked features of vhost-user protocol.

Note that since the matching HMP command is typically used for

human,

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

leave it unchanged.

[...]

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Double-checking... @feature-bits provides the exact same

information as

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines

@features, only in another encoding. Correct?

Same for all the other new -bits. Correct?

Yes, all the new fields are only about providing another encoding.

Why do we want to return the same information in two different encodings? I figure the commit message tries to answer this question:

Features and status bits could be helpful for applications to

compare

Quoted 1 line
Quoted 1 line
Quoted 1 line

directly. For instance, when an upper application aims to

ensure the

Quoted 1 line
Quoted 1 line
Quoted 1 line

virtio negotiation correctness between guest, QEMU, and

OVS-DPDK, it use

Quoted 1 line
Quoted 1 line
Quoted 1 line

the "ovs-vsctl list interface" command to retrieve interface

features

Quoted 1 line
Quoted 1 line
Quoted 1 line

(in number format) and the QMP command x-query-virtio-status to

retrieve

Quoted 1 line
Quoted 1 line
Quoted 1 line

vhost-user net device features. If "show-bits" is added, the

application

Quoted 1 line
Quoted 1 line
Quoted 1 line

can compare the two features directly; No need to encoding the

features

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

returned by the QMP command.

This patch also serves as a preparation for the next one, which

implements

Quoted 1 line
Quoted 1 line
Quoted 1 line

a vhost-user test case about acked features of vhost-user

protocol.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

I guess you're trying to simplify use cases where the QMP client wants to compare entire feature sets without caring for individual features.

The comparison is easy if both sets are represented the same way, e.g. both are numbers, or both are lists of symbols.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

With different representations, we first have to map to a common representation. Unfortunately, the design of x-query-virtio-status makes this harder than it should be.

We use QAPI types VirtioDeviceStatus, VhostDeviceProtocols, VirtioDeviceFeatures to represent feature sets. They all work the same
way: array of strings plus a number. For each bit QEMU knows, there's

a

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

string in the array. Any remaining bits go into the number.

The format of the string is undocumented. They look like

"WELL_KNOWN_SYMBOL: human readable explanation"

Mapping from bit to this string in a client would require duplicating QEMU's code exactly.

Mapping both bit and string to just "WELL_KNOWN_SYMBOL" could perhaps

be

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

done.

The mapping between symbols and bits is not visible in QMP. Mapping from string to bit requires exploiting the undocumented format: extract the well-known symbol and decode it.

This encoding of feature sets goes back to commit f3034ad71fc (qmp:
decode feature & status bits in virtio-status) v7.2. Before that, the command returned the bits as a number.

For example, return value "member "status":

      Before f3034ad71fc:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
          "status": 15,

      Since f3034ad71fc:

          "status": {
              "statuses": [
                  "VIRTIO_CONFIG_S_ACKNOWLEDGE: Valid virtio device

found",

Quoted 1 line
Quoted 1 line
Quoted 1 line

"VIRTIO_CONFIG_S_DRIVER: Guest OS compatible with

device",

Quoted 1 line
Quoted 1 line
Quoted 1 line

"VIRTIO_CONFIG_S_FEATURES_OK: Feature negotiation

complete",

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

"VIRTIO_CONFIG_S_DRIVER_OK: Driver setup and ready"
]},

With your patch:

"status": {
"statuses": [
"VIRTIO_CONFIG_S_ACKNOWLEDGE: Valid virtio device

found",

Quoted 1 line
Quoted 1 line
Quoted 1 line

"VIRTIO_CONFIG_S_DRIVER: Guest OS compatible with

device",

Quoted 1 line
Quoted 1 line
Quoted 1 line

"VIRTIO_CONFIG_S_FEATURES_OK: Feature negotiation

complete",

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
                  "VIRTIO_CONFIG_S_DRIVER_OK: Driver setup and ready"
              ]},
          "status-bits": 15,
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

Looks like commit f3034ad71fc improved one use case at the expense of another, and your patch tries to revert the damage. Which one exactly it improved is unclear; the commit message doesn't tell. Laurent?

[...]

The first idea of the series "hmp,qmp: Add commands to introspect

virtio devices"

Quoted 1 line
Quoted 1 line

including commit f3034ad71fc was to help developer to debug virtio

devices, so for this

Quoted 1 line
Quoted 1 line

purpose it was interesting to display the status in a human readable

manner.

Quoted 2 lines
Quoted 2 lines

Of course, if you want to run automatic tests and be able to compare

the result to have

Quoted 3 lines
Quoted 3 lines

the status bits result seems to be better.

As these are two different use cases, it's understandable to have two

different

Quoted 42 lines
Quoted 1 line

representations of the same information.

Thanks!

Both use cases are valid, but I dislike both the existing and the proposed interface.

We can change it: x-query-virtio-status isn't stable (it's for debugging and testing). But even unstable interfaces should only be changed for good, clear reasons.

I feel the change from "bits encoded as a number" to "bits as list of descriptive strings plus number for the unknown ones" fell short. Let me explain.

The initial version of the command had "bits encoded as number". Unless we understand why that was done, we should assume it was done for a reason. We now know it was: Hyman Huang posted a patch to get it back.

Instead of "bits as list of descriptive strings plus number for the unknown ones", we could have done "bits encoded as number, plus list of descriptive strings", or plus some other human-readable encoding.

QMP output of the form "WELL_KNOWN_SYMBOL: human readable explanation" smells of encoding structured information in strings, which is a no-no.

Perhaps we could have added human-readable output just in HMP. That's what we normally do.

Here are a few possible alternatives to Hyman Huang's patch:

1. Revert commit f3034ad71fc for QMP, keep it for HMP.

2. Replace @unknown-FOO (just the unknown bits) by @FOO-bits (all bits).

3. Add @FOO-bits next to @unknown-FOO, deprecate @unknown-FOO.

4. Create a QAPI enum for the known bits. Clients can use introspection to learn the mapping between symbols and bits. Requires dumbing down the descriptive strings to just the symbols. This feels both overengineered and cumbersome to use.

Quoted 5 lines

For 2 and 3, I'd prefer to also dumb down the descriptive strings to just the symbols.

Thoughts?

Quoted 9 lines

I agree with you. As x-CMD are unstable, perhaps we can go directly to 2? (and of course to remove the descriptive strings. Is it easily possible to keep them for
the HMP version?)

Thanks,
Laurent

Sorry for the late reply. :(

Let me make a conclusion about our discussion, if i misunderstand something,
point that out please:

1. we take the policy of adding human-readable output just in HMP.

2. For the HMP output, we display the human-readable information and drop the unknown bits in practice.

3. For the QMP output, we remove the descriptive strings and only display bits encoded as numbers.

I'll do that in the next version and make the PATCH 1/2 apart from the PATCH 2/2
since it could be handled in an independent context.

Signature · 1 line
Best regards
#11 lore raw

RFC 2/2 vhost-user-test: Add negotiated features check

In reply to Hyman Huang

When a vhost-user network device is restored from an unexpected failure, the acked_features could be used as input for the VHOST_USER_SET_FEATURES command because QEMU internally backups the final features as acked_features after the guest acknowledges features during virtio-net driver initialization.

The negotiated features check verifies whether the features in the Vhost slave device and the acked_features in QEMU are identical.

Through the usage of the vhost-user protocol, the test case seeks to verify that the vhost-user network device is correctly negotiating.

---
 tests/qtest/vhost-user-test.c | 100 ++++++++++++++++++++++++++++++++++
 1 file changed, 100 insertions(+)
tests/qtest/vhost-user-test.c +100 -0
index d4e437265f..14df89f823 100644
@@ -13,6 +13,7 @@
 #include "libqtest-single.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qlist.h"
 #include "qemu/config-file.h"
 #include "qemu/option.h"
 #include "qemu/range.h"
@@ -169,6 +170,7 @@ typedef struct TestServer {
     int test_flags;
     int queues;
     struct vhost_user_ops *vu_ops;
+    uint64_t features;
 } TestServer;
 
 struct vhost_user_ops {
@@ -1020,6 +1022,100 @@ static void test_multiqueue(void *obj, void *arg, QGuestAllocator *alloc)
 }
 
 
+static QDict *query_virtio(QTestState *who)
+{
+    QDict *rsp;
+
+    rsp = qtest_qmp(who, "{ 'execute': 'x-query-virtio'}");
+    g_assert(!qdict_haskey(rsp, "error"));
+    g_assert(qdict_haskey(rsp, "return"));
+
+    return rsp;
+}
+
+static QDict *query_virtio_status(QTestState *who, const char *path)
+{
+    QDict *rsp;
+
+    rsp = qtest_qmp(who, "{ 'execute': 'x-query-virtio-status', "
+        "'arguments': { 'path': %s, 'show-bits': true} }", path);
+
+    g_assert(!qdict_haskey(rsp, "error"));
+    g_assert(qdict_haskey(rsp, "return"));
+
+    return rsp;
+}
+
+static uint64_t get_acked_features(QTestState *who)
+{
+    QDict *rsp_return, *status, *vhost_info, *dev;
+    QList *dev_list;
+    const QListEntry *entry;
+    const char *name;
+    char *path;
+    uint64_t acked_features;
+
+    /* query the virtio devices */
+    rsp_return = query_virtio(who);
+    g_assert(rsp_return);
+
+    dev_list = qdict_get_qlist(rsp_return, "return");
+    g_assert(dev_list && !qlist_empty(dev_list));
+
+    /* fetch the first and the sole device */
+    entry = qlist_first(dev_list);
+    g_assert(entry);
+
+    dev = qobject_to(QDict, qlist_entry_obj(entry));
+    g_assert(dev);
+
+    name = qdict_get_try_str(dev, "name");
+    g_assert_cmpstr(name, ==, "virtio-net");
+
+    path = g_strdup(qdict_get_try_str(dev, "path"));
+    g_assert(path);
+    qobject_unref(rsp_return);
+    rsp_return = NULL;
+
+    /* fetch the status of the virtio-net device by QOM path */
+    rsp_return = query_virtio_status(who, path);
+    g_assert(rsp_return);
+
+    status = qdict_get_qdict(rsp_return, "return");
+    g_assert(status);
+
+    vhost_info = qdict_get_qdict(status, "vhost-dev");
+    g_assert(vhost_info);
+
+    acked_features = qdict_get_try_int(vhost_info, "acked-features-bits", 0);
+
+    qobject_unref(rsp_return);
+    g_free(path);
+
+    return acked_features;
+}
+
+static void acked_features_check(QTestState *qts, TestServer *s)
+{
+    uint64_t acked_features;
+
+    acked_features = get_acked_features(qts);
+    g_assert_cmpint(acked_features, ==, s->features);
+}
+
+static void test_acked_features(void *obj,
+                                     void *arg,
+                                     QGuestAllocator *alloc)
+{
+    TestServer *server = arg;
+
+    if (!wait_for_fds(server)) {
+        return;
+    }
+
+    acked_features_check(global_qtest, server);
+}
+
 static uint64_t vu_net_get_features(TestServer *s)
 {
     uint64_t features = 0x1ULL << VHOST_F_LOG_ALL |
@@ -1040,6 +1136,7 @@ static void vu_net_set_features(TestServer *s, CharBackend *chr,
         qemu_chr_fe_disconnect(chr);
         s->test_flags = TEST_FLAGS_BAD;
     }
+    s->features = msg->payload.u64;
 }
 
 static void vu_net_get_protocol_features(TestServer *s, CharBackend *chr,
@@ -1109,6 +1206,9 @@ static void register_vhost_user_test(void)
     qos_add_test("vhost-user/multiqueue",
                  "virtio-net",
                  test_multiqueue, &opts);
+    qos_add_test("vhost-user/read_acked_features",
+                 "virtio-net",
+                 test_acked_features, &opts);
 }
 libqos_init(register_vhost_user_test);
 
Signature · 1 line
2.39.1
author
#12 lore raw
In reply to Hyman Huang

ping

Quoted 39 lines · Hyman Huang

The patchset "Fix the virtio features negotiation flaw" fix a vhost-user negotiation flaw:
c9bdc449f9 vhost-user: Fix the virtio features negotiation flaw bebcac052a vhost-user: Refactor the chr_closed_bh 937b7d96e4 vhost-user: Refactor vhost acked features saving

While the test case remain unmerged, the detail reference:

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

Since Michael pointed out that the info virtio makes sense to query the negotiation feature, this patchset uses the x-query-virtio-status to retrieve the features instead of exporting netdev capabilities and information as we did in the previous patchset to aid in confirming the negotiation's validity.

To do that, we first introduce an "show-bits" argument for x-query-virtio-status such that the feature bits can be used directly, and then implement the test case for negotiated features check. As we post, the code is divided into two patches.

Please review, thanks,
Yong

Hyman Huang (2):
qapi/virtio: introduce the "show-bits" argument for
x-query-virtio-status
vhost-user-test: Add negotiated features check

 hw/virtio/virtio-hmp-cmds.c   |   2 +-
 hw/virtio/virtio-qmp.c        |  21 ++++++-
 qapi/virtio.json              |  49 ++++++++++++++++-
 tests/qtest/vhost-user-test.c | 100 ++++++++++++++++++++++++++++++++++
 4 files changed, 167 insertions(+), 5 deletions(-)

--
2.39.1

Signature · 1 line
Best regards
#13 lore raw
Quoted 1 line · Yong Huang

ping

Sit tight pls it's only been a couple of days. But if you want to, address comments by Markus pls.

author
#14 lore raw
Quoted 7 lines · Michael S. Tsirkin
Quoted 1 line · Yong Huang

ping

Sit tight pls it's only been a couple of days. But if you want to, address comments by Markus pls.

I'm happy to do that, of course, and thank you also for the reminder. :)

Signature · 1 line
Best regards