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=1760540561; cv=none; d=zohomail.com; s=zohoarc; b=VGgn1qw4v3k9cFS/6R8jS8Ngu3bcT4pgylRzUR057UVLnTyiTai8b/SbXbD9WfOQChI0OMKWRpT8ol7QQMc8kAxTT6EseeW/ppM72C9LgXk+g9E1RpmnztkKvaYJ1c8XyehZCThodHNsPtw4VKMqskw5FzXhh3YPk92UrUqmdhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540561; 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=uJnRGLW978ZbzYp4OH98EKpuSnli27gjDhigwEbVLmw=; b=mx7rH/DyZxiGaRr02leBqwrjYCvEzcs1Dp66/6Ei5KRhMD3zakFGxsrJ+yEFfRisqcISW2ykwWb0lKEA27Gj/bP7Rok7WZdC2kZlF9KUB3IT/wbW8pyeHC1NwM3niL2N6Ah3MU1xP+ItVLSVcpIUQu/QaiI7oi1/bmgUB+jCiJo= 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 1760540561432629.7652482522545; Wed, 15 Oct 2025 08:02:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xS-0007fv-1b; Wed, 15 Oct 2025 10:58:30 -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-0007fM-DE 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 1v92xH-0000aQ-VW for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:28 -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 8E9B7C067C; Wed, 15 Oct 2025 17:58:15 +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-m1FsGBOj; Wed, 15 Oct 2025 17:58:14 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540294; bh=uJnRGLW978ZbzYp4OH98EKpuSnli27gjDhigwEbVLmw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=SQLmsVegbIqJKs60zejD5V0TJ2d6VfdluRRdhbRbWsrF6Sm3MCADpbAstFux/FSZb N1QFeocl7zOelg2BQbnEzx2oJM4V9l2m9PV8m7gue7TNCca/DEpHy4/Y0SRTLN72DF ynT1rpcENVslEDmGGYiASbIoo2TQaJBum8cQUU58= 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, Raphael Norwitz Subject: [PATCH v3 03/23] vhost-user: introduce vhost_user_has_protocol_feature() helper Date: Wed, 15 Oct 2025 17:57:47 +0300 Message-ID: <20251015145808.1112843-4-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, T_SPF_TEMPERROR=0.01 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: 1760540567761158500 Content-Type: text/plain; charset="utf-8" Make all protocol feature checks in the same way. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/virtio/vhost-user.c | 120 +++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 58 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index b80174f489..b8231dcbcf 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -272,6 +272,12 @@ struct scrub_regions { int fd_idx; }; =20 +static bool vhost_user_has_protocol_feature(struct vhost_dev *dev, + uint64_t feature) +{ + return virtio_has_feature(dev->protocol_features, feature); +} + static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg) { struct vhost_user *u =3D dev->opaque; @@ -435,8 +441,8 @@ static int vhost_user_set_log_base(struct vhost_dev *de= v, uint64_t base, { int fds[VHOST_USER_MAX_RAM_SLOTS]; size_t fd_num =3D 0; - bool shmfd =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_LOG_SHMFD); + bool shmfd =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_LOG_SHM= FD); int ret; VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_LOG_BASE, @@ -1006,11 +1012,11 @@ static int vhost_user_set_mem_table(struct vhost_de= v *dev, int fds[VHOST_MEMORY_BASELINE_NREGIONS]; size_t fd_num =3D 0; bool do_postcopy =3D u->postcopy_listen && u->postcopy_fd.handler; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); bool config_mem_slots =3D - virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS); + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS); int ret; =20 if (do_postcopy) { @@ -1058,8 +1064,9 @@ static int vhost_user_set_mem_table(struct vhost_dev = *dev, static int vhost_user_set_vring_endian(struct vhost_dev *dev, struct vhost_vring_state *ring) { - bool cross_endian =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CROSS_END= IAN); + bool cross_endian =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CROSS_ENDIAN); VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_VRING_ENDIAN, .hdr.flags =3D VHOST_USER_VERSION, @@ -1129,8 +1136,9 @@ static int vhost_user_write_sync(struct vhost_dev *de= v, VhostUserMsg *msg, int ret; =20 if (wait_for_reply) { - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_REPLY_ACK); if (reply_supported) { msg->hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; } @@ -1458,8 +1466,7 @@ static int vhost_user_set_features(struct vhost_dev *= dev, ret =3D vhost_user_set_u64(dev, VHOST_USER_SET_FEATURES, features, log_enabled); =20 - if (virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_STATUS)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_STATUS)= ) { if (!ret) { return vhost_user_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); } @@ -1513,8 +1520,8 @@ static int vhost_user_reset_device(struct vhost_dev *= dev) * Historically, reset was not implemented so only reset devices * that are expecting it. */ - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_RESET_DEVICE)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_RESET_DEVICE)) { return -ENOSYS; } =20 @@ -1571,8 +1578,8 @@ static int vhost_user_backend_handle_vring_host_notif= ier(struct vhost_dev *dev, void *addr; char *name; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) || + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) || vdev =3D=3D NULL || queue_idx >=3D virtio_get_num_queues(vdev)) { return -EINVAL; } @@ -1884,13 +1891,13 @@ static int vhost_setup_backend_channel(struct vhost= _dev *dev) }; struct vhost_user *u =3D dev->opaque; int sv[2], ret =3D 0; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); Error *local_err =3D NULL; QIOChannel *ioc; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_BACKEND_REQ)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ)) { return 0; } =20 @@ -2138,8 +2145,8 @@ static int vhost_user_postcopy_notifier(NotifierWithR= eturn *notifier, =20 switch (pnd->reason) { case POSTCOPY_NOTIFY_PROBE: - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_PAGEFAULT)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_PAGEFAULT)) { /* TODO: Get the device name into this error somehow */ error_setg(errp, "vhost-user backend not capable of postcopy"); @@ -2230,7 +2237,7 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, } =20 /* query the max queues we support if backend supports Multiple Qu= eue */ - if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_MQ)= ) { err =3D vhost_user_get_u64(dev, VHOST_USER_GET_QUEUE_NUM, &dev->max_queues); if (err < 0) { @@ -2248,18 +2255,18 @@ static int vhost_user_backend_init(struct vhost_dev= *dev, void *opaque, } =20 if (virtio_has_feature(features, VIRTIO_F_IOMMU_PLATFORM) && - !(virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_BACKEND_REQ) && - virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_ACK))) { + !(vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ) && + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_REPLY_ACK))) { error_setg(errp, "IOMMU support requires reply-ack and " "backend-req protocol features."); return -EINVAL; } =20 /* get max memory regions if backend supports configurable RAM slo= ts */ - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS)= ) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS)) { u->user->memory_slots =3D VHOST_MEMORY_BASELINE_NREGIONS; } else { err =3D vhost_user_get_max_memslots(dev, &ram_slots); @@ -2281,8 +2288,8 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, } =20 if (dev->migration_blocker =3D=3D NULL && - !virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_LOG_SHMFD)) { + !vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_LOG_SHMFD)) { error_setg(&dev->migration_blocker, "Migration disabled: vhost-user backend lacks " "VHOST_USER_PROTOCOL_F_LOG_SHMFD feature."); @@ -2351,8 +2358,8 @@ static bool vhost_user_requires_shm_log(struct vhost_= dev *dev) { assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_USER); =20 - return virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_LOG_SHMFD); + return vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_LOG_SHMFD); } =20 static int vhost_user_migration_done(struct vhost_dev *dev, char* mac_addr) @@ -2367,8 +2374,7 @@ static int vhost_user_migration_done(struct vhost_dev= *dev, char* mac_addr) } =20 /* if backend supports VHOST_USER_PROTOCOL_F_RARP ask it to send the R= ARP */ - if (virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_RARP)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_RARP)) { msg.hdr.request =3D VHOST_USER_SEND_RARP; msg.hdr.flags =3D VHOST_USER_VERSION; memcpy((char *)&msg.payload.u64, mac_addr, 6); @@ -2382,11 +2388,11 @@ static int vhost_user_migration_done(struct vhost_d= ev *dev, char* mac_addr) static int vhost_user_net_set_mtu(struct vhost_dev *dev, uint16_t mtu) { VhostUserMsg msg; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); int ret; =20 - if (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_NET_MTU)= )) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_NET_MT= U)) { return 0; } =20 @@ -2446,8 +2452,7 @@ static int vhost_user_get_config(struct vhost_dev *de= v, uint8_t *config, .hdr.size =3D VHOST_USER_CONFIG_HDR_SIZE + config_len, }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIG)) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_CONFIG= )) { error_setg(errp, "VHOST_USER_PROTOCOL_F_CONFIG not supported"); return -EINVAL; } @@ -2490,8 +2495,8 @@ static int vhost_user_set_config(struct vhost_dev *de= v, const uint8_t *data, { int ret; uint8_t *p; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); =20 VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_CONFIG, @@ -2499,8 +2504,7 @@ static int vhost_user_set_config(struct vhost_dev *de= v, const uint8_t *data, .hdr.size =3D VHOST_USER_CONFIG_HDR_SIZE + size, }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIG)) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_CONFIG= )) { return -ENOTSUP; } =20 @@ -2535,8 +2539,9 @@ static int vhost_user_crypto_create_session(struct vh= ost_dev *dev, uint64_t *session_id) { int ret; - bool crypto_session =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CRYPTO_SESSIO= N); + bool crypto_session =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CRYPTO_SESSION); CryptoDevBackendSessionInfo *backend_info =3D session_info; VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_CREATE_CRYPTO_SESSION, @@ -2637,8 +2642,9 @@ static int vhost_user_crypto_close_session(struct vhost_dev *dev, uint64_t session_id) { int ret; - bool crypto_session =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CRYPTO_SESSIO= N); + bool crypto_session =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CRYPTO_SESSION); VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_CLOSE_CRYPTO_SESSION, .hdr.flags =3D VHOST_USER_VERSION, @@ -2683,8 +2689,8 @@ static int vhost_user_get_inflight_fd(struct vhost_de= v *dev, .hdr.size =3D sizeof(msg.payload.inflight), }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { return 0; } =20 @@ -2751,8 +2757,8 @@ static int vhost_user_set_inflight_fd(struct vhost_de= v *dev, .hdr.size =3D sizeof(msg.payload.inflight), }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { return 0; } =20 @@ -2851,8 +2857,7 @@ void vhost_user_async_close(DeviceState *d, =20 static int vhost_user_dev_start(struct vhost_dev *dev, bool started) { - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_STATUS)) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_STATUS= )) { return 0; } =20 @@ -2877,16 +2882,15 @@ static void vhost_user_reset_status(struct vhost_de= v *dev) return; } =20 - if (virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_STATUS)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_STATUS)= ) { vhost_user_set_status(dev, 0); } } =20 static bool vhost_user_supports_device_state(struct vhost_dev *dev) { - return virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_DEVICE_STATE); + return vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_DEVICE_STATE); } =20 static int vhost_user_set_device_state_fd(struct vhost_dev *dev, --=20 2.48.1