From: Paolo Abeni <pabeni@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>,
Jason Wang <jasowang@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Stefano Garzarella <sgarzare@redhat.com>,
Cornelia Huck <cohuck@redhat.com>, Eric Blake <eblake@redhat.com>,
Markus Armbruster <armbru@redhat.com>
Subject: [PATCH v5 09/13] vhost-backend: implement extended features support
Date: Wed, 13 Aug 2025 12:28:22 +0200 [thread overview]
Message-ID: <4361056cae3adf74132d6d24a4b8afe895e2f31a.1755080614.git.pabeni@redhat.com> (raw)
In-Reply-To: <cover.1755080613.git.pabeni@redhat.com>
Leverage the kernel extended features manipulation ioctls(), if
available, and fallback to old ops otherwise. Error out when setting
extended features but kernel support is not available.
Note that extended support for get/set backend features is not needed,
as the only feature that can be changed belongs to the 64 bit range.
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
v3 -> v4:
- use new virtio_features macro names
v1 -> v2:
- synced with kernel ioctl changes
---
hw/virtio/vhost-backend.c | 62 ++++++++++++++++++++++++++++++++-------
1 file changed, 51 insertions(+), 11 deletions(-)
diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 833804dd40..4367db0d95 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -20,6 +20,11 @@
#include <linux/vhost.h>
#include <sys/ioctl.h>
+struct vhost_features {
+ uint64_t count;
+ uint64_t features[VIRTIO_FEATURES_NU64S];
+};
+
static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int request,
void *arg)
{
@@ -182,12 +187,6 @@ static int vhost_kernel_get_vring_worker(struct vhost_dev *dev,
return vhost_kernel_call(dev, VHOST_GET_VRING_WORKER, worker);
}
-static int vhost_kernel_set_features(struct vhost_dev *dev,
- uint64_t features)
-{
- return vhost_kernel_call(dev, VHOST_SET_FEATURES, &features);
-}
-
static int vhost_kernel_set_backend_cap(struct vhost_dev *dev)
{
uint64_t features;
@@ -210,10 +209,51 @@ static int vhost_kernel_set_backend_cap(struct vhost_dev *dev)
return 0;
}
-static int vhost_kernel_get_features(struct vhost_dev *dev,
- uint64_t *features)
+static int vhost_kernel_set_features(struct vhost_dev *dev,
+ const uint64_t *features)
{
- return vhost_kernel_call(dev, VHOST_GET_FEATURES, features);
+ struct vhost_features farray;
+ bool extended_in_use;
+ int r;
+
+ farray.count = VIRTIO_FEATURES_NU64S;
+ virtio_features_copy(farray.features, features);
+ extended_in_use = virtio_features_use_ex(farray.features);
+
+ /*
+ * Can't check for ENOTTY: for unknown ioctls the kernel interprets
+ * the argument as a virtio queue id and most likely errors out validating
+ * such id, instead of reporting an unknown operation.
+ */
+ r = vhost_kernel_call(dev, VHOST_SET_FEATURES_ARRAY, &farray);
+ if (!r) {
+ return 0;
+ }
+
+ if (extended_in_use) {
+ error_report("Trying to set extended features without kernel support");
+ return -EINVAL;
+ }
+ return vhost_kernel_call(dev, VHOST_SET_FEATURES, &farray.features[0]);
+}
+
+static int vhost_kernel_get_features(struct vhost_dev *dev, uint64_t *features)
+{
+ struct vhost_features farray;
+ int r;
+
+ farray.count = VIRTIO_FEATURES_NU64S;
+ r = vhost_kernel_call(dev, VHOST_GET_FEATURES_ARRAY, &farray);
+ if (r) {
+ memset(&farray, 0, sizeof(farray));
+ r = vhost_kernel_call(dev, VHOST_GET_FEATURES, &farray.features[0]);
+ }
+ if (r) {
+ return r;
+ }
+
+ virtio_features_copy(features, farray.features);
+ return 0;
}
static int vhost_kernel_set_owner(struct vhost_dev *dev)
@@ -341,8 +381,8 @@ const VhostOps kernel_ops = {
.vhost_attach_vring_worker = vhost_kernel_attach_vring_worker,
.vhost_new_worker = vhost_kernel_new_worker,
.vhost_free_worker = vhost_kernel_free_worker,
- .vhost_set_features = vhost_kernel_set_features,
- .vhost_get_features = vhost_kernel_get_features,
+ .vhost_set_features_ex = vhost_kernel_set_features,
+ .vhost_get_features_ex = vhost_kernel_get_features,
.vhost_set_backend_cap = vhost_kernel_set_backend_cap,
.vhost_set_owner = vhost_kernel_set_owner,
.vhost_get_vq_index = vhost_kernel_get_vq_index,
--
2.50.1
next prev parent reply other threads:[~2025-08-13 10:30 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-13 10:28 [PATCH v5 00/13] virtio: introduce support for GSO over UDP tunnel Paolo Abeni
2025-08-13 10:28 ` [PATCH v5 01/13] linux-headers: deal with counted_by annotation Paolo Abeni
2025-08-13 10:28 ` [PATCH v5 02/13] linux-headers: Update to Linux v6.17-rc1 Paolo Abeni
2025-08-13 10:28 ` [PATCH v5 03/13] virtio: introduce extended features type Paolo Abeni
2025-08-13 10:28 ` [PATCH v5 04/13] virtio: serialize extended features state Paolo Abeni
2025-08-13 10:28 ` [PATCH v5 05/13] virtio: add support for negotiating extended features Paolo Abeni
2025-08-13 10:28 ` [PATCH v5 06/13] virtio-pci: implement support for " Paolo Abeni
2025-08-13 10:28 ` [PATCH v5 07/13] vhost: add support for negotiating " Paolo Abeni
2025-08-13 10:28 ` [PATCH v5 08/13] qmp: update virtio features map to support " Paolo Abeni
2025-08-30 8:05 ` Markus Armbruster
2025-08-13 10:28 ` Paolo Abeni [this message]
2025-08-13 10:28 ` [PATCH v5 10/13] vhost-net: implement extended features support Paolo Abeni
2025-08-13 10:28 ` [PATCH v5 11/13] virtio-net: " Paolo Abeni
2025-08-13 10:28 ` [PATCH v5 12/13] net: implement tunnel probing Paolo Abeni
2025-08-13 10:28 ` [PATCH v5 13/13] net: implement UDP tunnel features offloading Paolo Abeni
2025-08-14 3:26 ` [PATCH v5 00/13] virtio: introduce support for GSO over UDP tunnel Lei Yang
2025-08-22 7:45 ` Paolo Abeni
2025-08-28 1:47 ` Akihiko Odaki
2025-09-01 2:47 ` Jason Wang
2025-09-01 6:44 ` Paolo Abeni
2025-09-02 9:08 ` Jason Wang
2025-09-02 9:51 ` Michael S. Tsirkin
2025-09-01 14:54 ` Stefano Garzarella
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=4361056cae3adf74132d6d24a4b8afe895e2f31a.1755080614.git.pabeni@redhat.com \
--to=pabeni@redhat.com \
--cc=armbru@redhat.com \
--cc=cohuck@redhat.com \
--cc=eblake@redhat.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).