Skip to contentSkip to conversation

Adjust the output of x-query-virtio-status

PATCH In review Hyman Huang 3 participants 13 messages Feb 21, 2024 – Mar 15, 2024 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

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

v4:
- Rebase on master
- Fix the syntax mistake within the commit message of [PATCH v3 1/3]
- Adjust the linking file in hw/virtio/meson.build suggested by Markus

Please review,
Yong

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

229 lines not on this page · raw message

Signature · 1 line
2.39.3
#2 lore raw

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

In reply to Hyman Huang

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

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

708 lines not on this page · raw message

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

667 lines not on this page · raw message

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

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

In reply to Hyman Huang

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

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

v4:
- Rebase on master
- Fix the syntax mistake within the commit message of [PATCH v3 1/3]
- Adjust the linking file in hw/virtio/meson.build suggested by Markus

Please review,
Yong

I'm still not excited about this.
For one this will not scale when we add more than 64 feature bits.

As long as we are changing this let's address this please. I would also suggest just keeping the name in there, so a decoded feature will be
[0, NAME]
and a non-decoded will be just
[23]

will make for a smaller change.

Quoted 38 lines

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

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

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

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

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

 hw/virtio/meson.build       |   4 +-
 hw/virtio/virtio-hmp-cmds.c | 702 +++++++++++++++++++++++++++++++++++-
 hw/virtio/virtio-qmp.c      | 684 +----------------------------------
 hw/virtio/virtio-qmp.h      |   3 -
 qapi/virtio.json            | 231 +-----------
 5 files changed, 724 insertions(+), 900 deletions(-)
Signature · 1 line
2.39.3
#6 lore raw
Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines · Hyman Huang

v4:
- Rebase on master
- Fix the syntax mistake within the commit message of [PATCH v3 1/3]
- Adjust the linking file in hw/virtio/meson.build suggested by Markus

Please review,
Yong

I'm still not excited about this.
For one this will not scale when we add more than 64 feature bits.

x-query-virtio-status is meant to be a low effort, low level debugging aid. Its feature set members correspond 1:1 to uint64_t members of the C struct, which I figure correspond 1:1 to 64-bit words in the binary virtio interface.

If we run out of bits in the binary virtio interface, I guess we'd add another 64-bit word. The C struct acquires another uint64_t member, and so does x-query-virtio-status.

What's wrong with that?

Quoted 8 lines

As long as we are changing this let's address this please. I would also suggest just keeping the name in there, so a decoded feature will be
[0, NAME]
and a non-decoded will be just
[23]

will make for a smaller change.

I'm not sure I understand your suggestion.

[...]

#7 lore raw
Quoted 22 lines · Markus Armbruster
Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines · Hyman Huang

v4:
- Rebase on master
- Fix the syntax mistake within the commit message of [PATCH v3 1/3]
- Adjust the linking file in hw/virtio/meson.build suggested by Markus

Please review,
Yong

I'm still not excited about this.
For one this will not scale when we add more than 64 feature bits.

x-query-virtio-status is meant to be a low effort, low level debugging aid. Its feature set members correspond 1:1 to uint64_t members of the C struct, which I figure correspond 1:1 to 64-bit words in the binary virtio interface.
If we run out of bits in the binary virtio interface, I guess we'd add another 64-bit word. The C struct acquires another uint64_t member, and so does x-query-virtio-status.

Quoted 1 line

What's wrong with that?

Nope, that last part about virtio binary interface is wrong. virtio does not have a 64-bit word in it's ABI, it has an array of bits represented, depending on a transport, as a dynamically sized array of 32-bit words (PCI, MMIO) or a dynamically sized array of bytes (CCW).

We are beginning to get closer to filling up 64 bits for some devices so I'm already looking at not baking 64 bit in new code.

Quoted 8 lines
Quoted 8 lines

As long as we are changing this let's address this please. I would also suggest just keeping the name in there, so a decoded feature will be
[0, NAME]
and a non-decoded will be just
[23]

Quoted 5 lines
Quoted 1 line

will make for a smaller change.

I'm not sure I understand your suggestion.

[...]

For example, for the balloon device:

instead of e.g. 0x201 as this patch would do,
I propose [ [{0, "VIRTIO_BALLOON_F_MUST_TELL_HOST" }, {9, ""}] ].

Signature · 1 line
MST
#8 lore raw
Quoted 23 lines · Michael S. Tsirkin
Quoted 22 lines · Markus Armbruster
Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines · Hyman Huang

v4:
- Rebase on master
- Fix the syntax mistake within the commit message of [PATCH v3 1/3]
- Adjust the linking file in hw/virtio/meson.build suggested by Markus

Please review,
Yong

I'm still not excited about this.
For one this will not scale when we add more than 64 feature bits.

x-query-virtio-status is meant to be a low effort, low level debugging aid. Its feature set members correspond 1:1 to uint64_t members of the C struct, which I figure correspond 1:1 to 64-bit words in the binary virtio interface.
If we run out of bits in the binary virtio interface, I guess we'd add another 64-bit word. The C struct acquires another uint64_t member, and so does x-query-virtio-status.

Quoted 6 lines
Quoted 1 line

What's wrong with that?

Nope, that last part about virtio binary interface is wrong. virtio does not have a 64-bit word in it's ABI, it has an array of bits represented, depending on a transport, as a dynamically sized array of 32-bit words (PCI, MMIO) or a dynamically sized array of bytes (CCW).

Then have x-query-virtio-status return a suitable array of unsigned numbers. Look ma, no invention!

Quoted 13 lines

We are beginning to get closer to filling up 64 bits for some devices so I'm already looking at not baking 64 bit in new code.

Quoted 10 lines
Quoted 9 lines

As long as we are changing this let's address this please. I would also suggest just keeping the name in there, so a decoded feature will be
[0, NAME]
and a non-decoded will be just
[23]

will make for a smaller change.

Quoted 8 lines
Quoted 3 lines

I'm not sure I understand your suggestion.

[...]

For example, for the balloon device:

instead of e.g. 0x201 as this patch would do,
I propose [ [{0, "VIRTIO_BALLOON_F_MUST_TELL_HOST" }, {9, ""}] ].

Syntactially invalid. I guess you mean something like

    [{"bit": 0, "name": "VIRTIO_BALLOON_F_MUST_TELL_HOST"},
     {"bit": 9, "name": ""}]

or with optional @name

    [{"bit": 0, "name": "VIRTIO_BALLOON_F_MUST_TELL_HOST"},
     {"bit": 9}]

This is an awfully verbose encoding of an n-bit number, even if we omit "VIRTIO_BALLOON_F_" as noise.

I could be awkward for the use case described in PATCH 1's commit message:

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

It next describes the patch's solution:

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

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

Since this is not a stable interface, instead of a perfect (and to my subjective self overengineered) solution at some future point, I'd prefer to get in a simple one *now*, even if we may have to evolve it later.

#9 lore raw
Quoted 27 lines · Markus Armbruster
Quoted 25 lines · Michael S. Tsirkin
Quoted 23 lines · Markus Armbruster
Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines · Hyman Huang

v4:
- Rebase on master
- Fix the syntax mistake within the commit message of [PATCH v3 1/3]
- Adjust the linking file in hw/virtio/meson.build suggested by Markus

Please review,
Yong

I'm still not excited about this.
For one this will not scale when we add more than 64 feature bits.

x-query-virtio-status is meant to be a low effort, low level debugging aid. Its feature set members correspond 1:1 to uint64_t members of the C struct, which I figure correspond 1:1 to 64-bit words in the binary virtio interface.
If we run out of bits in the binary virtio interface, I guess we'd add another 64-bit word. The C struct acquires another uint64_t member, and so does x-query-virtio-status.

What's wrong with that?

Quoted 7 lines
Quoted 4 lines

Nope, that last part about virtio binary interface is wrong. virtio does not have a 64-bit word in it's ABI, it has an array of bits represented, depending on a transport, as a dynamically sized array of 32-bit words (PCI, MMIO) or a dynamically sized array of bytes (CCW).

Then have x-query-virtio-status return a suitable array of unsigned numbers. Look ma, no invention!

Then with bit 53 in spec user has to squint hard and do okay 53/32=1 so array entry 1 and 53%32=21 so bit 21 there. And for ccw it's just completely weird they have a byte array. No one wants these words everyone works with bit #s this is what's in spec.

Quoted 60 lines
Quoted 13 lines

We are beginning to get closer to filling up 64 bits for some devices so I'm already looking at not baking 64 bit in new code.

Quoted 10 lines
Quoted 9 lines

As long as we are changing this let's address this please. I would also suggest just keeping the name in there, so a decoded feature will be
[0, NAME]
and a non-decoded will be just
[23]

will make for a smaller change.

Quoted 8 lines
Quoted 3 lines

I'm not sure I understand your suggestion.

[...]

For example, for the balloon device:

instead of e.g. 0x201 as this patch would do,
I propose [ [{0, "VIRTIO_BALLOON_F_MUST_TELL_HOST" }, {9, ""}] ].

Syntactially invalid. I guess you mean something like

    [{"bit": 0, "name": "VIRTIO_BALLOON_F_MUST_TELL_HOST"},
     {"bit": 9, "name": ""}]

or with optional @name

    [{"bit": 0, "name": "VIRTIO_BALLOON_F_MUST_TELL_HOST"},
     {"bit": 9}]

This is an awfully verbose encoding of an n-bit number, even if we omit "VIRTIO_BALLOON_F_" as noise.

I could be awkward for the use case described in PATCH 1's commit message:

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

It next describes the patch's solution:

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

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

Since this is not a stable interface, instead of a perfect (and to my subjective self overengineered) solution at some future point, I'd prefer to get in a simple one *now*, even if we may have to evolve it later.

#10 lore raw
In reply to Markus Armbruster
Quoted 11 lines · Markus Armbruster

I could be awkward for the use case described in PATCH 1's commit message:

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

So, consider how guest kernel presents features then. Do you happen to know? It's actually a binary string:

static ssize_t features_show(struct device *_d,
struct device_attribute *attr, char *buf)

{
        struct virtio_device *dev = dev_to_virtio(_d);
        unsigned int i;
        ssize_t len = 0;

        /* We actually represent this as a bitstring, as it could be
         * arbitrary length in future. */
        for (i = 0; i < sizeof(dev->features)*8; i++)
                len += sysfs_emit_at(buf, len, "%c",
                               __virtio_test_bit(dev, i) ? '1' : '0');
        len += sysfs_emit_at(buf, len, "\n");
        return len;
}

static DEVICE_ATTR_RO(features);

Signature · 1 line
MST
#11 lore raw
Quoted 31 lines · Michael S. Tsirkin
Quoted 11 lines · Markus Armbruster

I could be awkward for the use case described in PATCH 1's commit message:

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

So, consider how guest kernel presents features then. Do you happen to know? It's actually a binary string:

static ssize_t features_show(struct device *_d,
struct device_attribute *attr, char *buf)

{
        struct virtio_device *dev = dev_to_virtio(_d);
        unsigned int i;
        ssize_t len = 0;

        /* We actually represent this as a bitstring, as it could be
         * arbitrary length in future. */
        for (i = 0; i < sizeof(dev->features)*8; i++)
                len += sysfs_emit_at(buf, len, "%c",
                               __virtio_test_bit(dev, i) ? '1' : '0');
        len += sysfs_emit_at(buf, len, "\n");
        return len;
}
Quoted 1 line

static DEVICE_ATTR_RO(features);

I'm willing to accept any reasonably compact representation of the bits that is easy to use for the comparison use case.

I strongly prefer integers as long as their width suffices.

Since out integers are limited to 64 bits, and you want us to design for more, we need something else.

I'm fine with array of integers, but you don't like it.

We generally avoid encoding stuff in strings, but using strings for "overwide" integers isn't as bad as using them for structured data. I guess I'd be okay with it.

I'd use decimal simply to keep these "overwide" integers as close as possible to regular ones.

If using base 2 enables string compare for the comparison use case, that's an argument for base 2.

Hyman Huang, can you show us example output of "ovs-vsctl list interface"?

author
#12 lore raw
Quoted 55 lines · Markus Armbruster
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Markus Armbruster

I could be awkward for the use case described in PATCH 1's commit message:

However, we sometimes want to compare features and status bits

without

Quoted 1 line
Quoted 1 line

caring for their exact meaning. Say we want to verify the

correctness

Quoted 1 line
Quoted 1 line

of the virtio negotiation between guest, QEMU, and OVS-DPDK. We

can use

Quoted 3 lines
Quoted 3 lines

QMP command x-query-virtio-status to retrieve vhost-user net device features, and the "ovs-vsctl list interface" command to retrieve interface features. Without commit f3034ad71fc, we could then

simply

Quoted 1 line
Quoted 1 line

compare the numbers. With this commit, we first have to map from

the

Quoted 3 lines
Quoted 1 line

strings back to the numeric encoding.

So, consider how guest kernel presents features then. Do you happen to

know?

Quoted 17 lines

It's actually a binary string:

static ssize_t features_show(struct device *_d,
struct device_attribute *attr, char *buf)

{
        struct virtio_device *dev = dev_to_virtio(_d);
        unsigned int i;
        ssize_t len = 0;

        /* We actually represent this as a bitstring, as it could be
         * arbitrary length in future. */
        for (i = 0; i < sizeof(dev->features)*8; i++)
                len += sysfs_emit_at(buf, len, "%c",
                               __virtio_test_bit(dev, i) ? '1' : '0');
        len += sysfs_emit_at(buf, len, "\n");
        return len;
}
Quoted 1 line

static DEVICE_ATTR_RO(features);

I'm willing to accept any reasonably compact representation of the bits that is easy to use for the comparison use case.

I strongly prefer integers as long as their width suffices.

Since out integers are limited to 64 bits, and you want us to design for more, we need something else.

I'm fine with array of integers, but you don't like it.

We generally avoid encoding stuff in strings, but using strings for "overwide" integers isn't as bad as using them for structured data. I guess I'd be okay with it.

Quoted 10 lines

I'd use decimal simply to keep these "overwide" integers as close as possible to regular ones.

If using base 2 enables string compare for the comparison use case, that's an argument for base 2.

Hyman Huang, can you show us example output of "ovs-vsctl list interface"?

Here is the output of an active interface enable the dpdk feature:

# ovs-vsctl list interface port-testvm2pn8

_uuid: xxxx
admin_state: up
name: port-testvm2pn8
......
status: {features="0x000000017060a782", mode=client,
num_of_vrings="4"......}

Yong

Signature · 1 line
Best regards