{"id":2225312,"url":"http://patchwork.ozlabs.org/api/patches/2225312/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260420200339.708640-7-vsementsov@yandex-team.ru/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260420200339.708640-7-vsementsov@yandex-team.ru>","list_archive_url":null,"date":"2026-04-20T20:03:21","name":"[v6,06/22] vhost: make vhost_dev.features private","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"230348124a8dfef4e79b0ff83056384da39b5489","submitter":{"id":84116,"url":"http://patchwork.ozlabs.org/api/people/84116/?format=json","name":"Vladimir Sementsov-Ogievskiy","email":"vsementsov@yandex-team.ru"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260420200339.708640-7-vsementsov@yandex-team.ru/mbox/","series":[{"id":500672,"url":"http://patchwork.ozlabs.org/api/series/500672/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=500672","date":"2026-04-20T20:03:18","name":"vhost refactoring and fixes","version":6,"mbox":"http://patchwork.ozlabs.org/series/500672/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2225312/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225312/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=yandex-team.ru header.i=@yandex-team.ru\n header.a=rsa-sha256 header.s=default header.b=DEMlqPe+;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)","mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net;\n dkim=pass header.i=@yandex-team.ru"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fzxMz1Rsfz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 21 Apr 2026 06:06:55 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wEuqy-0001cP-Jh; Mon, 20 Apr 2026 16:04:20 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <vsementsov@yandex-team.ru>)\n id 1wEuqi-0001L9-S6\n for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:07 -0400","from forwardcorp1d.mail.yandex.net\n ([2a02:6b8:c41:1300:1:45:d181:df01])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <vsementsov@yandex-team.ru>)\n id 1wEuqe-0001me-Po\n for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:03 -0400","from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net\n (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net\n [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0])\n by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id D049380778;\n Mon, 20 Apr 2026 23:03:57 +0300 (MSK)","from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34])\n by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA\n id f3YMX10K1Sw0-1FRJDOrQ; Mon, 20 Apr 2026 23:03:56 +0300"],"Precedence":"bulk","X-Yandex-Fwd":"1","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru;\n s=default; t=1776715437;\n bh=+axeZ2TTYr0f20W8V8FaxxcfZODhNBsnjsiwjpJ0gkc=;\n h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From;\n b=DEMlqPe+J9iFCP688fteB8G4Y2P8MvEH4X209DXbsXIwHDTa48O0SpG616TdJMBwh\n f0rxAHOP/Fj4Q39PkdRdi+myVv8ht0Y/40SiojGBennFP/z44Qqb6sUW2P3Ysy1wHW\n fN6/hfLDbCfYS66zZctO6dpFSqjCpnBGuXG6NZO8=","From":"Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>","To":"mst@redhat.com","Cc":"sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org,\n vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru,\n\t=?utf-8?q?Marc-Andr=C3=A9_Lureau?= <marcandre.lureau@redhat.com>,\n Jason Wang <jasowang@redhat.com>,\n =?utf-8?q?Alex_Benn=C3=A9e?= <alex.bennee@linaro.org>","Subject":"[PATCH v6 06/22] vhost: make vhost_dev.features private","Date":"Mon, 20 Apr 2026 23:03:21 +0300","Message-ID":"<20260420200339.708640-7-vsementsov@yandex-team.ru>","X-Mailer":"git-send-email 2.52.0","In-Reply-To":"<20260420200339.708640-1-vsementsov@yandex-team.ru>","References":"<20260420200339.708640-1-vsementsov@yandex-team.ru>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01;\n envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net","X-Spam_score_int":"-20","X-Spam_score":"-2.1","X-Spam_bar":"--","X-Spam_report":"(-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001,\n SPF_PASS=-0.001 autolearn=ham autolearn_force=no","X-Spam_action":"no action","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.29","List-Id":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"It's hard to control where and how do we use this field. Let's\ncover all usages by getters/setters, and keep direct access to the\nfield only in vhost.c. It will help to control migration of this\nfield in further commits.\n\nSigned-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>\nReviewed-by: Daniil Tatianin <d-tatianin@yandex-team.ru>\n---\n hw/display/vhost-user-gpu.c |  7 +++----\n hw/net/vhost_net.c          | 18 ++++++++---------\n hw/virtio/vdpa-dev.c        |  2 +-\n hw/virtio/vhost-user-base.c |  8 ++++++--\n hw/virtio/vhost-user.c      |  4 ++--\n hw/virtio/vhost.c           |  6 +++---\n hw/virtio/virtio-qmp.c      |  2 +-\n include/hw/virtio/vhost.h   | 39 +++++++++++++++++++++++++++++++++++--\n net/vhost-vdpa.c            |  7 +++----\n 9 files changed, 65 insertions(+), 28 deletions(-)","diff":"diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c\nindex 8911b2a72f7..3566e49a1aa 100644\n--- a/hw/display/vhost-user-gpu.c\n+++ b/hw/display/vhost-user-gpu.c\n@@ -631,17 +631,16 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error **errp)\n \n     /* existing backend may send DMABUF, so let's add that requirement */\n     g->parent_obj.conf.flags |= 1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED;\n-    if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_VIRGL)) {\n+    if (vhost_dev_has_feature(&g->vhost->dev, VIRTIO_GPU_F_VIRGL)) {\n         g->parent_obj.conf.flags |= 1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED;\n     }\n-    if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_EDID)) {\n+    if (vhost_dev_has_feature(&g->vhost->dev, VIRTIO_GPU_F_EDID)) {\n         g->parent_obj.conf.flags |= 1 << VIRTIO_GPU_FLAG_EDID_ENABLED;\n     } else {\n         error_report(\"EDID requested but the backend doesn't support it.\");\n         g->parent_obj.conf.flags &= ~(1 << VIRTIO_GPU_FLAG_EDID_ENABLED);\n     }\n-    if (virtio_has_feature(g->vhost->dev.features,\n-        VIRTIO_GPU_F_RESOURCE_UUID)) {\n+    if (vhost_dev_has_feature(&g->vhost->dev, VIRTIO_GPU_F_RESOURCE_UUID)) {\n         g->parent_obj.conf.flags |= 1 << VIRTIO_GPU_FLAG_RESOURCE_UUID_ENABLED;\n     }\n \ndiff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c\nindex ca199831260..323d1177359 100644\n--- a/hw/net/vhost_net.c\n+++ b/hw/net/vhost_net.c\n@@ -54,8 +54,8 @@ void vhost_net_ack_features_ex(struct vhost_net *net, const uint64_t *features)\n {\n     virtio_features_clear(net->dev.acked_features_ex);\n     if (net->backend == -1) {\n-        net->dev.acked_features =\n-           net->dev.features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES);\n+        net->dev.acked_features = (vhost_dev_features(&net->dev) &\n+            (1ULL << VHOST_USER_F_PROTOCOL_FEATURES));\n     } else if (!qemu_has_vnet_hdr(net->nc)) {\n         net->dev.acked_features = 1ULL << VHOST_NET_F_VIRTIO_NET_HDR;\n     }\n@@ -282,15 +282,15 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)\n     if (backend_kernel) {\n         if (!qemu_has_vnet_hdr_len(options->net_backend,\n                                sizeof(struct virtio_net_hdr_mrg_rxbuf))) {\n-            net->dev.features &= ~(1ULL << VIRTIO_NET_F_MRG_RXBUF);\n+            vhost_dev_clear_feature(&net->dev, VIRTIO_NET_F_MRG_RXBUF);\n         }\n \n         if (!qemu_has_vnet_hdr(options->net_backend) &&\n-            (~net->dev.features & (1ULL << VHOST_NET_F_VIRTIO_NET_HDR))) {\n-            fprintf(stderr, \"vhost lacks feature mask 0x%llx for backend\\n\",\n-                    ~net->dev.features & (1ULL << VHOST_NET_F_VIRTIO_NET_HDR));\n-             goto fail;\n-         }\n+            !vhost_dev_has_feature(&net->dev, VHOST_NET_F_VIRTIO_NET_HDR)) {\n+            fprintf(stderr, \"vhost lacks VHOST_NET_F_VIRTIO_NET_HDR \"\n+                    \"feature for backend\\n\");\n+            goto fail;\n+        }\n     }\n \n     /* Set sane init value. Override when guest acks. */\n@@ -298,7 +298,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)\n         virtio_features_from_u64(features,\n                                  options->get_acked_features(net->nc));\n         if (virtio_features_andnot(missing_features, features,\n-                                   net->dev.features_ex)) {\n+                                   vhost_dev_features_ex(&net->dev))) {\n             fprintf(stderr, \"vhost lacks feature mask 0x\" VIRTIO_FEATURES_FMT\n                     \" for backend\\n\", VIRTIO_FEATURES_PR(missing_features));\n             goto fail;\ndiff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c\nindex 06179e402e4..94188d37bbf 100644\n--- a/hw/virtio/vdpa-dev.c\n+++ b/hw/virtio/vdpa-dev.c\n@@ -224,7 +224,7 @@ static uint64_t vhost_vdpa_device_get_features(VirtIODevice *vdev,\n                                                Error **errp)\n {\n     VhostVdpaDevice *s = VHOST_VDPA_DEVICE(vdev);\n-    uint64_t backend_features = s->dev.features;\n+    uint64_t backend_features = vhost_dev_features(&s->dev);\n \n     if (!virtio_has_feature(features, VIRTIO_F_IOMMU_PLATFORM)) {\n         virtio_clear_feature(&backend_features, VIRTIO_F_IOMMU_PLATFORM);\ndiff --git a/hw/virtio/vhost-user-base.c b/hw/virtio/vhost-user-base.c\nindex 01ab9ca56b1..5bbf4a73679 100644\n--- a/hw/virtio/vhost-user-base.c\n+++ b/hw/virtio/vhost-user-base.c\n@@ -118,9 +118,13 @@ static uint64_t vub_get_features(VirtIODevice *vdev,\n                                  uint64_t requested_features, Error **errp)\n {\n     VHostUserBase *vub = VHOST_USER_BASE(vdev);\n+    uint64_t backend_features = vhost_dev_features(&vub->vhost_dev);\n+\n     /* This should be set when the vhost connection initialises */\n-    g_assert(vub->vhost_dev.features);\n-    return vub->vhost_dev.features & ~(1ULL << VHOST_USER_F_PROTOCOL_FEATURES);\n+    g_assert(backend_features);\n+    virtio_clear_feature(&backend_features, VHOST_USER_F_PROTOCOL_FEATURES);\n+\n+    return backend_features;\n }\n \n /*\ndiff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c\nindex fc2ed1f17e5..68dd89cd8f8 100644\n--- a/hw/virtio/vhost-user.c\n+++ b/hw/virtio/vhost-user.c\n@@ -1249,7 +1249,7 @@ static int vhost_user_set_vring_enable(struct vhost_dev *dev, int enable)\n {\n     int i;\n \n-    if (!virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES)) {\n+    if (!vhost_dev_has_feature(dev, VHOST_USER_F_PROTOCOL_FEATURES)) {\n         /*\n          * For vhost-user devices, if VHOST_USER_F_PROTOCOL_FEATURES has not\n          * been negotiated, the rings start directly in the enabled state,\n@@ -1488,7 +1488,7 @@ static int vhost_user_set_features(struct vhost_dev *dev,\n      * Don't lose VHOST_USER_F_PROTOCOL_FEATURES, which is vhost-user\n      * specific.\n      */\n-    if (virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES)) {\n+    if (vhost_dev_has_feature(dev, VHOST_USER_F_PROTOCOL_FEATURES)) {\n         features |= 1ULL << VHOST_USER_F_PROTOCOL_FEATURES;\n     }\n \ndiff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c\nindex b89797df95e..e39e0676e00 100644\n--- a/hw/virtio/vhost.c\n+++ b/hw/virtio/vhost.c\n@@ -1612,7 +1612,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,\n         }\n     }\n \n-    virtio_features_copy(hdev->features_ex, features);\n+    virtio_features_copy(hdev->_features_ex, features);\n \n     hdev->memory_listener = (MemoryListener) {\n         .name = \"vhost\",\n@@ -1635,7 +1635,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,\n     };\n \n     if (hdev->migration_blocker == NULL) {\n-        if (!virtio_has_feature_ex(hdev->features_ex, VHOST_F_LOG_ALL)) {\n+        if (!vhost_dev_has_feature_ex(hdev, VHOST_F_LOG_ALL)) {\n             error_setg(&hdev->migration_blocker,\n                        \"Migration disabled: vhost lacks VHOST_F_LOG_ALL feature.\");\n         } else if (vhost_dev_log_is_shared(hdev) && !qemu_memfd_alloc_check()) {\n@@ -1909,7 +1909,7 @@ void vhost_get_features_ex(struct vhost_dev *hdev,\n     const int *bit = feature_bits;\n \n     while (*bit != VHOST_INVALID_FEATURE_BIT) {\n-        if (!virtio_has_feature_ex(hdev->features_ex, *bit)) {\n+        if (!vhost_dev_has_feature_ex(hdev, *bit)) {\n             virtio_clear_feature_ex(features, *bit);\n         }\n         bit++;\ndiff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c\nindex c8bf702d38d..51e3a42c4c4 100644\n--- a/hw/virtio/virtio-qmp.c\n+++ b/hw/virtio/virtio-qmp.c\n@@ -747,7 +747,7 @@ VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)\n         status->vhost_dev->nvqs = hdev->nvqs;\n         status->vhost_dev->vq_index = hdev->vq_index;\n         status->vhost_dev->features =\n-            qmp_decode_features(vdev->device_id, hdev->features_ex);\n+            qmp_decode_features(vdev->device_id, vhost_dev_features_ex(hdev));\n         status->vhost_dev->acked_features =\n             qmp_decode_features(vdev->device_id, hdev->acked_features_ex);\n \ndiff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h\nindex 4a9bd3effef..54862f9b445 100644\n--- a/include/hw/virtio/vhost.h\n+++ b/include/hw/virtio/vhost.h\n@@ -98,10 +98,11 @@ struct vhost_dev {\n      * offered by a backend which may be a subset of the total\n      * features eventually offered to the guest.\n      *\n-     * @features: available features provided by the backend\n+     * @_features: available features provided by the backend, private,\n+     *             direct access only in vhost.h/vhost.c\n      * @acked_features: final negotiated features with front-end driver\n      */\n-    VIRTIO_DECLARE_FEATURES(features);\n+    VIRTIO_DECLARE_FEATURES(_features);\n     VIRTIO_DECLARE_FEATURES(acked_features);\n \n     uint64_t max_queues;\n@@ -403,6 +404,40 @@ int vhost_dev_get_inflight(struct vhost_dev *dev, uint16_t queue_size,\n                            struct vhost_inflight *inflight);\n bool vhost_dev_has_iommu(struct vhost_dev *dev);\n \n+static inline bool vhost_dev_has_feature(struct vhost_dev *dev,\n+                                         uint64_t feature)\n+{\n+    return virtio_has_feature(dev->_features, feature);\n+}\n+\n+static inline bool vhost_dev_has_feature_ex(struct vhost_dev *dev,\n+                                            uint64_t feature)\n+{\n+    return virtio_has_feature_ex(dev->_features_ex, feature);\n+}\n+\n+static inline uint64_t vhost_dev_features(struct vhost_dev *dev)\n+{\n+    return dev->_features;\n+}\n+\n+static inline const uint64_t *vhost_dev_features_ex(struct vhost_dev *dev)\n+{\n+    return dev->_features_ex;\n+}\n+\n+static inline void vhost_dev_clear_feature(struct vhost_dev *dev,\n+                                           uint64_t feature)\n+{\n+    virtio_clear_feature(&dev->_features, feature);\n+}\n+\n+static inline void vhost_dev_clear_feature_ex(struct vhost_dev *dev,\n+                                              uint64_t feature)\n+{\n+    virtio_clear_feature_ex(dev->_features_ex, feature);\n+}\n+\n #ifdef CONFIG_VHOST\n int vhost_reset_device(struct vhost_dev *hdev);\n #else\ndiff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c\nindex 3df6091274e..ed402ff8aaf 100644\n--- a/net/vhost-vdpa.c\n+++ b/net/vhost-vdpa.c\n@@ -257,15 +257,14 @@ static bool vhost_vdpa_get_vnet_hash_supported_types(NetClientState *nc,\n {\n     assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA);\n     VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);\n-    uint64_t features = s->vhost_vdpa.dev->features;\n     int fd = s->vhost_vdpa.shared->device_fd;\n     struct {\n         struct vhost_vdpa_config hdr;\n         uint32_t supported_hash_types;\n     } config;\n \n-    if (!virtio_has_feature(features, VIRTIO_NET_F_HASH_REPORT) &&\n-        !virtio_has_feature(features, VIRTIO_NET_F_RSS)) {\n+    if (!vhost_dev_has_feature(s->vhost_vdpa.dev, VIRTIO_NET_F_HASH_REPORT) &&\n+        !vhost_dev_has_feature(s->vhost_vdpa.dev, VIRTIO_NET_F_RSS)) {\n         return false;\n     }\n \n@@ -586,7 +585,7 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc)\n      * If we early return in these cases SVQ will not be enabled. The migration\n      * will be blocked as long as vhost-vdpa backends will not offer _F_LOG.\n      */\n-    if (!vhost_vdpa_net_valid_svq_features(v->dev->features, NULL)) {\n+    if (!vhost_vdpa_net_valid_svq_features(vhost_dev_features(v->dev), NULL)) {\n         return 0;\n     }\n \n","prefixes":["v6","06/22"]}