From: Markus Armbruster <armbru@redhat.com>
To: Laurent Vivier <lvivier@redhat.com>
Cc: Yong Huang <yong.huang@smartx.com>,
qemu-devel@nongnu.org, "Michael S . Tsirkin" <mst@redhat.com>,
Eric Blake <eblake@redhat.com>, Thomas Huth <thuth@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [RFC 1/2] qapi/virtio: introduce the "show-bits" argument for x-query-virtio-status
Date: Fri, 01 Dec 2023 16:21:41 +0100 [thread overview]
Message-ID: <87jzpyuewq.fsf@pond.sub.org> (raw)
In-Reply-To: <3d4add1a-2dcf-4a35-a3f6-c7eca0275a35@redhat.com> (Laurent Vivier's message of "Fri, 1 Dec 2023 11:41:13 +0100")
Laurent Vivier <lvivier@redhat.com> writes:
> On 11/21/23 08:58, Markus Armbruster wrote:
>> Laurent, there's a question for you at the end.
>>
>> Yong Huang <yong.huang@smartx.com> writes:
>>
>>> On Thu, Nov 16, 2023 at 10:44 PM Markus Armbruster <armbru@redhat.com>
>>> wrote:
>>>
>>>> Hyman Huang <yong.huang@smartx.com> writes:
>>>>
>>>>> 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.
>>>>>
>>>>> Signed-off-by: Hyman Huang <yong.huang@smartx.com>
[...]
>>>> 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?
>>
>> [...]
>>
>
> 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!
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?
next prev parent reply other threads:[~2023-12-01 15:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-12 13:03 [RFC 0/2] vhost-user-test: Add negotiated features check Hyman Huang
2023-11-12 13:03 ` [RFC 1/2] qapi/virtio: introduce the "show-bits" argument for x-query-virtio-status Hyman Huang
2023-11-16 14:44 ` Markus Armbruster
2023-11-17 16:12 ` Yong Huang
2023-11-21 7:58 ` Markus Armbruster
2023-11-21 10:02 ` Yong Huang
2023-12-01 10:41 ` Laurent Vivier
2023-12-01 15:21 ` Markus Armbruster [this message]
2023-12-01 15:37 ` Laurent Vivier
2023-12-06 7:35 ` Markus Armbruster
2023-12-09 5:03 ` Yong Huang
2023-11-12 13:03 ` [RFC 2/2] vhost-user-test: Add negotiated features check Hyman Huang
2023-11-16 1:01 ` [RFC 0/2] " Yong Huang
2023-11-17 10:29 ` Michael S. Tsirkin
2023-11-17 16:26 ` Yong Huang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87jzpyuewq.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=lvivier@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
--cc=yong.huang@smartx.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.