@samitouri / QOSamiQemu / commits / f9a8f58126

vhost: move protocol_features to vhost_user

As comment says: it's only for vhost-user. So, let's move it to corresponding vhost backend realization. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260420200339.708640-5-vsementsov@yandex-team.ru>

Vladimir Sementsov-Ogievskiy committed Apr 20, 2026 at 23:03 UTC f9a8f5812607b6076c0412439f1d569391131e33
9 files changed +46 -24
backends/cryptodev-vhost.c
-1
@@ -60,7 +60,6 @@ cryptodev_vhost_init(
60
61 crypto->cc = options->cc;
62
63 - crypto->dev.protocol_features = 0;
63 crypto->backend = -1;
64
65 /* vhost-user needs vq_index to initiate a specific queue pair */
hw/block/vhost-user-blk.c
+2 -4
@@ -572,10 +572,8 @@ static bool vhost_user_blk_inflight_needed(void *opaque)
572 {
573 struct VHostUserBlk *s = opaque;
574
575 - bool inflight_migration = virtio_has_feature(s->dev.protocol_features,
576 - VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIGHT);
577 -
578 - return inflight_migration;
575 + return vhost_user_has_protocol_feature(
576 + &s->dev, VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIGHT);
577 }
578
579 static const VMStateDescription vmstate_vhost_user_blk_inflight = {
hw/net/vhost_net.c
-2
@@ -265,9 +265,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
265 goto fail;
266 }
267 net->backend = r;
268 - net->dev.protocol_features = 0;
268 } else {
270 - net->dev.protocol_features = 0;
269 net->backend = -1;
270
271 /* vhost-user needs vq_index to initiate a specific queue pair */
hw/virtio/meson.build
+1
@@ -94,6 +94,7 @@ system_virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_true: virtio_pci_ss)
94
95 system_ss.add_all(when: 'CONFIG_VIRTIO', if_true: system_virtio_ss)
96 stub_ss.add(files('vhost-stub.c'))
97 +stub_ss.add(files('vhost-user-stub.c'))
98 stub_ss.add(files('virtio-stub.c'))
99 stub_ss.add(files('virtio-md-stubs.c'))
100
hw/virtio/vhost-user-stub.c new
+6
@@ -0,0 +1,6 @@
1 +#include "qemu/osdep.h"
2 +#include "hw/virtio/vhost-user.h"
3 +
4 +void vhost_user_qmp_status(struct vhost_dev *dev, VirtioStatus *status)
5 +{
6 +}
hw/virtio/vhost-user.c
+29 -7
@@ -11,6 +11,7 @@
11 #include "qemu/osdep.h"
12 #include "qapi/error.h"
13 #include "hw/virtio/virtio-dmabuf.h"
14 +#include "hw/virtio/virtio-qmp.h"
15 #include "hw/virtio/vhost.h"
16 #include "hw/virtio/virtio-crypto.h"
17 #include "hw/virtio/vhost-user.h"
@@ -259,6 +260,14 @@ struct vhost_user {
260 /* Our current regions */
261 int num_shadow_regions;
262 struct vhost_memory_region shadow_regions[VHOST_USER_MAX_RAM_SLOTS];
263 +
264 + /**
265 + * @protocol_features: the vhost-user protocol feature set by
266 + * VHOST_USER_SET_PROTOCOL_FEATURES. Protocol features are only
267 + * negotiated if VHOST_USER_F_PROTOCOL_FEATURES has been offered
268 + * by the backend (see @features).
269 + */
270 + uint64_t protocol_features;
271 };
272
273 struct scrub_regions {
@@ -267,10 +276,13 @@ struct scrub_regions {
276 int fd_idx;
277 };
278
270 -static bool vhost_user_has_protocol_feature(struct vhost_dev *dev,
271 - uint64_t feature)
279 +bool vhost_user_has_protocol_feature(struct vhost_dev *dev, uint64_t feature)
280 {
273 - return virtio_has_feature(dev->protocol_features, feature);
281 + struct vhost_user *u = dev->opaque;
282 +
283 + assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
284 +
285 + return virtio_has_feature(u->protocol_features, feature);
286 }
287
288 static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg)
@@ -1338,8 +1350,8 @@ static int vhost_set_vring_file(struct vhost_dev *dev,
1350 int ret;
1351 int fds[VHOST_USER_MAX_RAM_SLOTS];
1352 size_t fd_num = 0;
1341 - bool reply_supported = virtio_has_feature(dev->protocol_features,
1342 - VHOST_USER_PROTOCOL_F_REPLY_ACK);
1353 + bool reply_supported =
1354 + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK);
1355 VhostUserMsg msg = {
1356 .hdr.request = request,
1357 .hdr.flags = VHOST_USER_VERSION,
@@ -2239,8 +2251,8 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque,
2251 }
2252
2253 /* final set of protocol features */
2242 - dev->protocol_features = protocol_features;
2243 - err = vhost_user_set_protocol_features(dev, dev->protocol_features);
2254 + u->protocol_features = protocol_features;
2255 + err = vhost_user_set_protocol_features(dev, u->protocol_features);
2256 if (err < 0) {
2257 error_setg_errno(errp, EPROTO, "vhost_backend_init failed");
2258 return -EPROTO;
@@ -3033,6 +3045,16 @@ static int vhost_user_check_device_state(struct vhost_dev *dev, Error **errp)
3045 return 0;
3046 }
3047
3048 +void vhost_user_qmp_status(struct vhost_dev *dev, VirtioStatus *status)
3049 +{
3050 + struct vhost_user *u = dev->opaque;
3051 +
3052 + assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
3053 +
3054 + status->vhost_dev->protocol_features =
3055 + qmp_decode_protocols(u->protocol_features);
3056 +}
3057 +
3058 const VhostOps user_ops = {
3059 .backend_type = VHOST_BACKEND_TYPE_USER,
3060 .vhost_backend_init = vhost_user_backend_init,
hw/virtio/virtio-qmp.c
+4 -2
@@ -751,12 +751,14 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
751 status->vhost_dev->acked_features =
752 qmp_decode_features(vdev->device_id, hdev->acked_features_ex);
753
754 - status->vhost_dev->protocol_features =
755 - qmp_decode_protocols(hdev->protocol_features);
754 status->vhost_dev->max_queues = hdev->max_queues;
755 status->vhost_dev->backend_cap = hdev->backend_cap;
756 status->vhost_dev->log_enabled = hdev->log_enabled;
757 status->vhost_dev->log_size = hdev->log_size;
758 +
759 + if (hdev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER) {
760 + vhost_user_qmp_status(hdev, status);
761 + }
762 }
763
764 return status;
include/hw/virtio/vhost-user.h
+4
@@ -10,6 +10,7 @@
10
11 #include "chardev/char-fe.h"
12 #include "hw/virtio/virtio.h"
13 +#include "qapi/qapi-types-virtio.h"
14
15 enum VhostUserProtocolFeature {
16 VHOST_USER_PROTOCOL_F_MQ = 0,
@@ -113,4 +114,7 @@ void vhost_user_async_close(DeviceState *d,
114 CharFrontend *chardev, struct vhost_dev *vhost,
115 vu_async_close_fn cb);
116
117 +void vhost_user_qmp_status(struct vhost_dev *dev, VirtioStatus *status);
118 +bool vhost_user_has_protocol_feature(struct vhost_dev *dev, uint64_t feature);
119 +
120 #endif
include/hw/virtio/vhost.h
-8
@@ -104,14 +104,6 @@ struct vhost_dev {
104 VIRTIO_DECLARE_FEATURES(features);
105 VIRTIO_DECLARE_FEATURES(acked_features);
106
107 - /**
108 - * @protocol_features: is the vhost-user only feature set by
109 - * VHOST_USER_SET_PROTOCOL_FEATURES. Protocol features are only
110 - * negotiated if VHOST_USER_F_PROTOCOL_FEATURES has been offered
111 - * by the backend (see @features).
112 - */
113 - uint64_t protocol_features;
114 -
107 uint64_t max_queues;
108 uint64_t backend_cap;
109 /* @started: is the vhost device started? */