From nobody Fri Nov 14 21:04:54 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540500; cv=none; d=zohomail.com; s=zohoarc; b=O5CttQM+KVlfHc238onwm/sbEX0Db+fkrTOjtQVgES0EzHLc1WN3fztXzqoL364G095B+788c45DtwVnPiGdFoNLf+lop+K2Ldw6SOnoQyA5nXoneQkYNuvpR7ESKuvwWlKdn1AMEXdlHcOXjzdLK0R8wAbaY/bh7NdiQ35C6Xc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540500; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fK8Ey4GFF4THHkSMPlpLhXnp31VyGUMkqHsjojITyhU=; b=lAUFsamNltcnpKf7e33Un7aSv/B1XDC8tZ/DAdlqMB23QZeI4PyjeasPTF0CNhuUimH2TeQXJ7O92w81tv+C/YNIVT1d1DTi571X4r4mNOSls53EzUyH5GbMeP1+fitxxkl7kF/K94wX4p8hShyQD7Xv2NQDgvzEJ77T3M+9Wo4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540499972655.6247344864939; Wed, 15 Oct 2025 08:01:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xT-0007gZ-Fa; Wed, 15 Oct 2025 10:58:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xQ-0007fJ-1t for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:28 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xI-0000b1-OT for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:27 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 311ACC0682; Wed, 15 Oct 2025 17:58:18 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-qubHylAR; Wed, 15 Oct 2025 17:58:17 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540297; bh=fK8Ey4GFF4THHkSMPlpLhXnp31VyGUMkqHsjojITyhU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Wao2Pt3sOhy3jnxlnvJmutT7s3Rhp9ZTqcAClhv+ru7URkxawl9EnOGMnBQcx3mIN /DAN0WZmDPtGjuhtnM1fbxt7Fx+spWKixzawR5ulVjr+y3yPJoRj2B5U/vS45zKT7T aNq3YusZAcY4rTILJdqkVr4pJWYuFbCK17z2sJTs= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Jason Wang , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v3 06/23] vhost: make vhost_dev.features private Date: Wed, 15 Oct 2025 17:57:50 +0300 Message-ID: <20251015145808.1112843-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540502699158500 Content-Type: text/plain; charset="utf-8" It's hard to control where and how do we use this field. Let's cover all usages by getters/setters, and keep direct access to the field only in vhost.c. It will help to control migration of this field in further commits. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin --- hw/display/vhost-user-gpu.c | 7 +++---- hw/net/vhost_net.c | 18 ++++++++--------- hw/virtio/vdpa-dev.c | 2 +- hw/virtio/vhost-user-base.c | 8 ++++++-- hw/virtio/vhost-user.c | 4 ++-- hw/virtio/vhost.c | 6 +++--- hw/virtio/virtio-qmp.c | 2 +- include/hw/virtio/vhost.h | 39 +++++++++++++++++++++++++++++++++++-- net/vhost-vdpa.c | 7 +++---- 9 files changed, 65 insertions(+), 28 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 79ea64b12c..146620e0a3 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -631,17 +631,16 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Erro= r **errp) =20 /* existing backend may send DMABUF, so let's add that requirement */ g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED; - if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_VIRGL)) { + if (vhost_dev_has_feature(&g->vhost->dev, VIRTIO_GPU_F_VIRGL)) { g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED; } - if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_EDID)) { + if (vhost_dev_has_feature(&g->vhost->dev, VIRTIO_GPU_F_EDID)) { g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_EDID_ENABLED; } else { error_report("EDID requested but the backend doesn't support it."); g->parent_obj.conf.flags &=3D ~(1 << VIRTIO_GPU_FLAG_EDID_ENABLED); } - if (virtio_has_feature(g->vhost->dev.features, - VIRTIO_GPU_F_RESOURCE_UUID)) { + if (vhost_dev_has_feature(&g->vhost->dev, VIRTIO_GPU_F_RESOURCE_UUID))= { g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_RESOURCE_UUID_E= NABLED; } =20 diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index ca19983126..323d117735 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -54,8 +54,8 @@ void vhost_net_ack_features_ex(struct vhost_net *net, con= st uint64_t *features) { virtio_features_clear(net->dev.acked_features_ex); if (net->backend =3D=3D -1) { - net->dev.acked_features =3D - net->dev.features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES); + net->dev.acked_features =3D (vhost_dev_features(&net->dev) & + (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)); } else if (!qemu_has_vnet_hdr(net->nc)) { net->dev.acked_features =3D 1ULL << VHOST_NET_F_VIRTIO_NET_HDR; } @@ -282,15 +282,15 @@ struct vhost_net *vhost_net_init(VhostNetOptions *opt= ions) if (backend_kernel) { if (!qemu_has_vnet_hdr_len(options->net_backend, sizeof(struct virtio_net_hdr_mrg_rxbuf))) { - net->dev.features &=3D ~(1ULL << VIRTIO_NET_F_MRG_RXBUF); + vhost_dev_clear_feature(&net->dev, VIRTIO_NET_F_MRG_RXBUF); } =20 if (!qemu_has_vnet_hdr(options->net_backend) && - (~net->dev.features & (1ULL << VHOST_NET_F_VIRTIO_NET_HDR))) { - fprintf(stderr, "vhost lacks feature mask 0x%llx for backend\n= ", - ~net->dev.features & (1ULL << VHOST_NET_F_VIRTIO_NET_H= DR)); - goto fail; - } + !vhost_dev_has_feature(&net->dev, VHOST_NET_F_VIRTIO_NET_HDR))= { + fprintf(stderr, "vhost lacks VHOST_NET_F_VIRTIO_NET_HDR " + "feature for backend\n"); + goto fail; + } } =20 /* Set sane init value. Override when guest acks. */ @@ -298,7 +298,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *optio= ns) virtio_features_from_u64(features, options->get_acked_features(net->nc)); if (virtio_features_andnot(missing_features, features, - net->dev.features_ex)) { + vhost_dev_features_ex(&net->dev))) { fprintf(stderr, "vhost lacks feature mask 0x" VIRTIO_FEATURES_= FMT " for backend\n", VIRTIO_FEATURES_PR(missing_features)= ); goto fail; diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c index efd9f68420..e1a2ff433d 100644 --- a/hw/virtio/vdpa-dev.c +++ b/hw/virtio/vdpa-dev.c @@ -224,7 +224,7 @@ static uint64_t vhost_vdpa_device_get_features(VirtIODe= vice *vdev, Error **errp) { VhostVdpaDevice *s =3D VHOST_VDPA_DEVICE(vdev); - uint64_t backend_features =3D s->dev.features; + uint64_t backend_features =3D vhost_dev_features(&s->dev); =20 if (!virtio_has_feature(features, VIRTIO_F_IOMMU_PLATFORM)) { virtio_clear_feature(&backend_features, VIRTIO_F_IOMMU_PLATFORM); diff --git a/hw/virtio/vhost-user-base.c b/hw/virtio/vhost-user-base.c index ff67a020b4..cf311c3bfc 100644 --- a/hw/virtio/vhost-user-base.c +++ b/hw/virtio/vhost-user-base.c @@ -118,9 +118,13 @@ static uint64_t vub_get_features(VirtIODevice *vdev, uint64_t requested_features, Error **errp) { VHostUserBase *vub =3D VHOST_USER_BASE(vdev); + uint64_t backend_features =3D vhost_dev_features(&vub->vhost_dev); + /* This should be set when the vhost connection initialises */ - g_assert(vub->vhost_dev.features); - return vub->vhost_dev.features & ~(1ULL << VHOST_USER_F_PROTOCOL_FEATU= RES); + g_assert(backend_features); + virtio_clear_feature(&backend_features, VHOST_USER_F_PROTOCOL_FEATURES= ); + + return backend_features; } =20 /* diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 3fd11a3b57..9f26515fd4 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1252,7 +1252,7 @@ static int vhost_user_set_vring_enable(struct vhost_d= ev *dev, int enable) { int i; =20 - if (!virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES)= ) { + if (!vhost_dev_has_feature(dev, VHOST_USER_F_PROTOCOL_FEATURES)) { /* * For vhost-user devices, if VHOST_USER_F_PROTOCOL_FEATURES has n= ot * been negotiated, the rings start directly in the enabled state, @@ -1469,7 +1469,7 @@ static int vhost_user_set_features(struct vhost_dev *= dev, * Don't lose VHOST_USER_F_PROTOCOL_FEATURES, which is vhost-user * specific. */ - if (virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES))= { + if (vhost_dev_has_feature(dev, VHOST_USER_F_PROTOCOL_FEATURES)) { features |=3D 1ULL << VHOST_USER_F_PROTOCOL_FEATURES; } =20 diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 414a48a218..94efa409aa 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1603,7 +1603,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, } } =20 - virtio_features_copy(hdev->features_ex, features); + virtio_features_copy(hdev->_features_ex, features); =20 hdev->memory_listener =3D (MemoryListener) { .name =3D "vhost", @@ -1626,7 +1626,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, }; =20 if (hdev->migration_blocker =3D=3D NULL) { - if (!virtio_has_feature_ex(hdev->features_ex, VHOST_F_LOG_ALL)) { + if (!vhost_dev_has_feature_ex(hdev, VHOST_F_LOG_ALL)) { error_setg(&hdev->migration_blocker, "Migration disabled: vhost lacks VHOST_F_LOG_ALL fe= ature."); } else if (vhost_dev_log_is_shared(hdev) && !qemu_memfd_alloc_chec= k()) { @@ -1900,7 +1900,7 @@ void vhost_get_features_ex(struct vhost_dev *hdev, const int *bit =3D feature_bits; =20 while (*bit !=3D VHOST_INVALID_FEATURE_BIT) { - if (!virtio_has_feature_ex(hdev->features_ex, *bit)) { + if (!vhost_dev_has_feature_ex(hdev, *bit)) { virtio_clear_feature_ex(features, *bit); } bit++; diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c index 82acb6d232..33d32720e1 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -817,7 +817,7 @@ VirtioStatus *qmp_x_query_virtio_status(const char *pat= h, Error **errp) status->vhost_dev->nvqs =3D hdev->nvqs; status->vhost_dev->vq_index =3D hdev->vq_index; status->vhost_dev->features =3D - qmp_decode_features(vdev->device_id, hdev->features_ex); + qmp_decode_features(vdev->device_id, vhost_dev_features_ex(hde= v)); status->vhost_dev->acked_features =3D qmp_decode_features(vdev->device_id, hdev->acked_features_ex); =20 diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index e308bc4556..1ba1af1d86 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -98,10 +98,11 @@ struct vhost_dev { * offered by a backend which may be a subset of the total * features eventually offered to the guest. * - * @features: available features provided by the backend + * @_features: available features provided by the backend, private, + * direct access only in vhost.h/vhost.c * @acked_features: final negotiated features with front-end driver */ - VIRTIO_DECLARE_FEATURES(features); + VIRTIO_DECLARE_FEATURES(_features); VIRTIO_DECLARE_FEATURES(acked_features); =20 uint64_t max_queues; @@ -403,6 +404,40 @@ int vhost_dev_get_inflight(struct vhost_dev *dev, uint= 16_t queue_size, struct vhost_inflight *inflight); bool vhost_dev_has_iommu(struct vhost_dev *dev); =20 +static inline bool vhost_dev_has_feature(struct vhost_dev *dev, + uint64_t feature) +{ + return virtio_has_feature(dev->_features, feature); +} + +static inline bool vhost_dev_has_feature_ex(struct vhost_dev *dev, + uint64_t feature) +{ + return virtio_has_feature_ex(dev->_features_ex, feature); +} + +static inline uint64_t vhost_dev_features(struct vhost_dev *dev) +{ + return dev->_features; +} + +static inline const uint64_t *vhost_dev_features_ex(struct vhost_dev *dev) +{ + return dev->_features_ex; +} + +static inline void vhost_dev_clear_feature(struct vhost_dev *dev, + uint64_t feature) +{ + virtio_clear_feature(&dev->_features, feature); +} + +static inline void vhost_dev_clear_feature_ex(struct vhost_dev *dev, + uint64_t feature) +{ + virtio_clear_feature_ex(dev->_features_ex, feature); +} + #ifdef CONFIG_VHOST int vhost_reset_device(struct vhost_dev *hdev); #else diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 74d26a9497..0af0d3bdd3 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -256,15 +256,14 @@ static bool vhost_vdpa_get_vnet_hash_supported_types(= NetClientState *nc, { assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); - uint64_t features =3D s->vhost_vdpa.dev->features; int fd =3D s->vhost_vdpa.shared->device_fd; struct { struct vhost_vdpa_config hdr; uint32_t supported_hash_types; } config; =20 - if (!virtio_has_feature(features, VIRTIO_NET_F_HASH_REPORT) && - !virtio_has_feature(features, VIRTIO_NET_F_RSS)) { + if (!vhost_dev_has_feature(s->vhost_vdpa.dev, VIRTIO_NET_F_HASH_REPORT= ) && + !vhost_dev_has_feature(s->vhost_vdpa.dev, VIRTIO_NET_F_RSS)) { return false; } =20 @@ -585,7 +584,7 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) * If we early return in these cases SVQ will not be enabled. The migr= ation * will be blocked as long as vhost-vdpa backends will not offer _F_LO= G. */ - if (!vhost_vdpa_net_valid_svq_features(v->dev->features, NULL)) { + if (!vhost_vdpa_net_valid_svq_features(vhost_dev_features(v->dev), NUL= L)) { return 0; } =20 --=20 2.48.1