@samitouri / QOSamiQemu / commits / 1ee0bc0c9b

vhost: drop backend_features field

This field is mostly unused and sometimes confusing. We even have a TODO-like comment to drop it, the comment is removed in this commit. The field is used to held VHOST_USER_F_PROTOCOL_FEATURES for vhost-user and/or VHOST_NET_F_VIRTIO_NET_HDR for vhost-net (which may be vhost-user-net). But we can simply recalculate these two flags in place from hdev->features, and from net-client for VHOST_NET_F_VIRTIO_NET_HDR. Note: removing field from x-query-virtio-status result is incompatible change. We can do it because the command is unstable. Cc: devel@lists.libvirt.org Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Acked-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Daniil Tatianin <d-tatianin@yandex-team.ru> Acked-by: Raphael Norwitz <raphael.s.norwitz@gmail.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Tested-by: Lei Yang <leiyang@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260420200339.708640-3-vsementsov@yandex-team.ru>

Vladimir Sementsov-Ogievskiy committed Apr 20, 2026 at 23:03 UTC 1ee0bc0c9bf006a1ea9afeae67b6b7a0b57a4783
10 files changed +22 -41
hw/block/vhost-user-blk.c
-1
@@ -348,7 +348,6 @@ static int vhost_user_blk_connect(DeviceState *dev, Error **errp)
348 s->dev.nvqs = s->num_queues;
349 s->dev.vqs = s->vhost_vqs;
350 s->dev.vq_index = 0;
351 - s->dev.backend_features = 0;
351
352 vhost_dev_set_config_notifier(&s->dev, &blk_ops);
353
hw/net/vhost_net.c
+14 -12
@@ -52,8 +52,14 @@ int vhost_net_set_config(struct vhost_net *net, const uint8_t *data,
52
53 void vhost_net_ack_features_ex(struct vhost_net *net, const uint64_t *features)
54 {
55 - virtio_features_copy(net->dev.acked_features_ex,
56 - net->dev.backend_features_ex);
55 + virtio_features_clear(net->dev.acked_features_ex);
56 + if (net->backend == -1) {
57 + net->dev.acked_features =
58 + net->dev.features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES);
59 + } else if (!qemu_has_vnet_hdr(net->nc)) {
60 + net->dev.acked_features = 1ULL << VHOST_NET_F_VIRTIO_NET_HDR;
61 + }
62 +
63 vhost_ack_features_ex(&net->dev, net->feature_bits, features);
64 }
65
@@ -258,12 +264,9 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
264 if (r < 0) {
265 goto fail;
266 }
261 - net->dev.backend_features = qemu_has_vnet_hdr(options->net_backend)
262 - ? 0 : (1ULL << VHOST_NET_F_VIRTIO_NET_HDR);
267 net->backend = r;
268 net->dev.protocol_features = 0;
269 } else {
266 - virtio_features_clear(net->dev.backend_features_ex);
270 net->dev.protocol_features = 0;
271 net->backend = -1;
272
@@ -284,13 +287,12 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
287 net->dev.features &= ~(1ULL << VIRTIO_NET_F_MRG_RXBUF);
288 }
289
287 - if (virtio_features_andnot(missing_features,
288 - net->dev.backend_features_ex,
289 - net->dev.features_ex)) {
290 - fprintf(stderr, "vhost lacks feature mask 0x" VIRTIO_FEATURES_FMT
291 - " for backend\n", VIRTIO_FEATURES_PR(missing_features));
292 - goto fail;
293 - }
290 + if (!qemu_has_vnet_hdr(options->net_backend) &&
291 + (~net->dev.features & (1ULL << VHOST_NET_F_VIRTIO_NET_HDR))) {
292 + fprintf(stderr, "vhost lacks feature mask 0x%llx for backend\n",
293 + ~net->dev.features & (1ULL << VHOST_NET_F_VIRTIO_NET_HDR));
294 + goto fail;
295 + }
296 }
297
298 /* Set sane init value. Override when guest acks. */
hw/scsi/vhost-scsi.c
-1
@@ -275,7 +275,6 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp)
275 vqs = g_new0(struct vhost_virtqueue, vsc->dev.nvqs);
276 vsc->dev.vqs = vqs;
277 vsc->dev.vq_index = 0;
278 - vsc->dev.backend_features = 0;
278
279 ret = vhost_dev_init(&vsc->dev, (void *)(uintptr_t)vhostfd,
280 VHOST_BACKEND_TYPE_KERNEL, 0, errp);
hw/scsi/vhost-user-scsi.c
-1
@@ -159,7 +159,6 @@ static int vhost_user_scsi_connect(DeviceState *dev, Error **errp)
159 vsc->dev.nvqs = VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues;
160 vsc->dev.vqs = s->vhost_vqs;
161 vsc->dev.vq_index = 0;
162 - vsc->dev.backend_features = 0;
162
163 ret = vhost_dev_init(&vsc->dev, &s->vhost_user, VHOST_BACKEND_TYPE_USER, 0,
164 errp);
hw/virtio/vdpa-dev.c
-1
@@ -104,7 +104,6 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp)
104 v->dev.vqs = vqs;
105 v->dev.vq_index = 0;
106 v->dev.vq_index_end = v->dev.nvqs;
107 - v->dev.backend_features = 0;
107 v->started = false;
108
109 ret = vhost_vdpa_get_iova_range(v->vhostfd, &iova_range);
hw/virtio/vhost-user.c
+8 -9
@@ -1465,14 +1465,15 @@ static int vhost_user_set_features(struct vhost_dev *dev,
1465 int ret;
1466
1467 /*
1468 - * We need to include any extra backend only feature bits that
1469 - * might be needed by our device. Currently this includes the
1470 - * VHOST_USER_F_PROTOCOL_FEATURES bit for enabling protocol
1471 - * features.
1468 + * Don't lose VHOST_USER_F_PROTOCOL_FEATURES, which is vhost-user
1469 + * specific.
1470 */
1473 - ret = vhost_user_set_u64(dev, VHOST_USER_SET_FEATURES,
1474 - features | dev->backend_features,
1475 - log_enabled);
1471 + if (virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES)) {
1472 + features |= 1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
1473 + }
1474 +
1475 + ret = vhost_user_set_u64(dev, VHOST_USER_SET_FEATURES, features,
1476 + log_enabled);
1477
1478 if (virtio_has_feature(dev->protocol_features,
1479 VHOST_USER_PROTOCOL_F_STATUS)) {
@@ -2192,8 +2193,6 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque,
2193 (dev->config_ops && dev->config_ops->vhost_dev_config_notifier);
2194 uint64_t protocol_features;
2195
2195 - dev->backend_features |= 1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
2196 -
2196 err = vhost_user_get_u64(dev, VHOST_USER_GET_PROTOCOL_FEATURES,
2197 &protocol_features);
2198 if (err < 0) {
hw/virtio/virtio-hmp-cmds.c
-2
@@ -176,8 +176,6 @@ void hmp_virtio_status(Monitor *mon, const QDict *qdict)
176 hmp_virtio_dump_features(mon, s->vhost_dev->features);
177 monitor_printf(mon, " Acked features:\n");
178 hmp_virtio_dump_features(mon, s->vhost_dev->acked_features);
179 - monitor_printf(mon, " Backend features:\n");
180 - hmp_virtio_dump_features(mon, s->vhost_dev->backend_features);
179 monitor_printf(mon, " Protocol features:\n");
180 hmp_virtio_dump_protocols(mon, s->vhost_dev->protocol_features);
181 }
hw/virtio/virtio-qmp.c
-4
@@ -710,8 +710,6 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
710 vdev->guest_features_ex);
711 status->host_features = qmp_decode_features(vdev->device_id,
712 vdev->host_features_ex);
713 - status->backend_features = qmp_decode_features(vdev->device_id,
714 - vdev->backend_features_ex);
713
714 switch (vdev->device_endian) {
715 case VIRTIO_DEVICE_ENDIAN_LITTLE:
@@ -752,8 +750,6 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
750 qmp_decode_features(vdev->device_id, hdev->features_ex);
751 status->vhost_dev->acked_features =
752 qmp_decode_features(vdev->device_id, hdev->acked_features_ex);
755 - status->vhost_dev->backend_features =
756 - qmp_decode_features(vdev->device_id, hdev->backend_features_ex);
753
754 status->vhost_dev->protocol_features =
755 qmp_decode_protocols(hdev->protocol_features);
include/hw/virtio/vhost.h
-7
@@ -100,16 +100,9 @@ struct vhost_dev {
100 *
101 * @features: available features provided by the backend
102 * @acked_features: final negotiated features with front-end driver
103 - *
104 - * @backend_features: this is used in a couple of places to either
105 - * store VHOST_USER_F_PROTOCOL_FEATURES to apply to
106 - * VHOST_USER_SET_FEATURES or VHOST_NET_F_VIRTIO_NET_HDR. Its
107 - * future use should be discouraged and the variable retired as
108 - * its easy to confuse with the VirtIO backend_features.
103 */
104 VIRTIO_DECLARE_FEATURES(features);
105 VIRTIO_DECLARE_FEATURES(acked_features);
112 - VIRTIO_DECLARE_FEATURES(backend_features);
106
107 /**
108 * @protocol_features: is the vhost-user only feature set by
qapi/virtio.json
-3
@@ -85,8 +85,6 @@
85 #
86 # @acked-features: vhost_dev acked_features
87 #
88 -# @backend-features: vhost_dev backend_features
89 -#
88 # @protocol-features: vhost_dev protocol_features
89 #
90 # @max-queues: vhost_dev max_queues
@@ -106,7 +104,6 @@
104 'vq-index': 'int',
105 'features': 'VirtioDeviceFeatures',
106 'acked-features': 'VirtioDeviceFeatures',
109 - 'backend-features': 'VirtioDeviceFeatures',
107 'protocol-features': 'VhostDeviceProtocols',
108 'max-queues': 'uint64',
109 'backend-cap': 'uint64',