From nobody Sat May 30 17:45:58 2026 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=1779862636; cv=none; d=zohomail.com; s=zohoarc; b=k7eTuzOd+V4UUR9u1ugxnh75C9g/mRebW5Y2mNtmgLnZ8FjJ7Om4JRJYd8D+TYW7V/GIzk5cnrZB0SMc9kkTT4cptuEq8DaLPql97v+PILedIi6xd6wfHZ9kUtF4UtWxVd0U4ym5LiGx7kxzBPild6Rn5TaTOv7FaekMbqq3XR4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862636; 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=52WD3FWkb0j8c8h/V6OhMQSzRC7zRqnFb8vo6zNsGZg=; b=WHHpVI6OKQapdepUND744Z2fvzmj4YbtMYklmnp9ze0etabErciCPNk6SVuaIsQK3a0Ts/pGnWFkAKbsfo8/Qy7ysldOL7CUSBFWOCh+bvq23PH//YWCUN/IC5zAat75gN1oxhqzC3L+sixGSxjU1lv+Hj0NxngyOGNhRgE7J2k= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862634930499.3054092132878; Tue, 26 May 2026 23:17:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7ZJ-0003v3-JV; Wed, 27 May 2026 02:16:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZG-0003tk-Jh for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:38 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZD-0003mv-6O for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:38 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 4602B80624; Wed, 27 May 2026 09:16:29 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-SN6RR2vk; Wed, 27 May 2026 09:16:28 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862588; bh=52WD3FWkb0j8c8h/V6OhMQSzRC7zRqnFb8vo6zNsGZg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=IXGhMYp+v8/cCwR/fuQNagwu+h7G/O/vieWB64t631twH1NEprmn6xevOR5DzFHyq 9jZdMUwnecDAbRWHj7AjRARpw/cFyslZvdFqJ7cYpuQAKVDq8G/q2OKx/YC22ajWw5 AfEMyjouJCjZAxL/rDrqmo2BuQeEvlmuTqmaWrqI= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 , "Gonglei (Arei)" , zhenwei pi , Jason Wang Subject: [PATCH v7 01/22] vhost-user: rework enabling vrings Date: Wed, 27 May 2026 09:16:02 +0300 Message-ID: <20260527061625.11167-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862639116158500 Content-Type: text/plain; charset="utf-8" We call the handler almost the same way in three places: - cryptodev-vhost.c - vhost_net.c - vhost.c The only difference, is that in vhost.c we don't try to call the handler for old vhost-user (when VHOST_USER_F_PROTOCOL_FEATURES is not supported). cryptodev-vhost and vhost_net code will just fail in this case. Probably they were developed only for newer vhost-user. Anyway, it doesn't seem correct to rely on this error path, if these devices want to check, that they don't communicate to old vhost-user protocol, they should do that earlier. Let's create the common helper, to call .vhost_set_vring_enable and use in all three places. For vhost-user let's just always skip enable/disable if it's unsupported. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- backends/cryptodev-vhost.c | 8 +------- hw/net/vhost_net.c | 7 +------ hw/virtio/vhost-user.c | 7 ++++++- hw/virtio/vhost.c | 21 --------------------- include/hw/virtio/vhost.h | 9 +++++++++ 5 files changed, 17 insertions(+), 35 deletions(-) diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index 943680a23af..abdfce33afc 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -152,7 +152,6 @@ vhost_set_vring_enable(CryptoDevBackendClient *cc, { CryptoDevBackendVhost *crypto =3D cryptodev_get_vhost(cc, b, queue); - const VhostOps *vhost_ops; =20 cc->vring_enable =3D enable; =20 @@ -160,12 +159,7 @@ vhost_set_vring_enable(CryptoDevBackendClient *cc, return 0; } =20 - vhost_ops =3D crypto->dev.vhost_ops; - if (vhost_ops->vhost_set_vring_enable) { - return vhost_ops->vhost_set_vring_enable(&crypto->dev, enable); - } - - return 0; + return vhost_dev_set_vring_enable(&crypto->dev, enable); } =20 int cryptodev_vhost_start(VirtIODevice *dev, int total_queues) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index a8ee18a9126..25e9f1fd244 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -587,7 +587,6 @@ VHostNetState *get_vhost_net(NetClientState *nc) int vhost_net_set_vring_enable(NetClientState *nc, int enable) { VHostNetState *net =3D get_vhost_net(nc); - const VhostOps *vhost_ops =3D net->dev.vhost_ops; =20 /* * vhost-vdpa network devices need to enable dataplane virtqueues after @@ -601,11 +600,7 @@ int vhost_net_set_vring_enable(NetClientState *nc, int= enable) =20 nc->vring_enable =3D enable; =20 - if (vhost_ops && vhost_ops->vhost_set_vring_enable) { - return vhost_ops->vhost_set_vring_enable(&net->dev, enable); - } - - return 0; + return vhost_dev_set_vring_enable(&net->dev, enable); } =20 int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index a8907cca74e..13c73e7b178 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1230,7 +1230,12 @@ static int vhost_user_set_vring_enable(struct vhost_= dev *dev, int enable) int i; =20 if (!virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES)= ) { - return -EINVAL; + /* + * For vhost-user devices, if VHOST_USER_F_PROTOCOL_FEATURES has n= ot + * been negotiated, the rings start directly in the enabled state, + * and can't be disabled. + */ + return 0; } =20 for (i =3D 0; i < dev->nvqs; ++i) { diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index b9dc4ed13ba..b89797df95e 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -2078,27 +2078,6 @@ int vhost_dev_get_inflight(struct vhost_dev *dev, ui= nt16_t queue_size, return 0; } =20 -static int vhost_dev_set_vring_enable(struct vhost_dev *hdev, int enable) -{ - if (!hdev->vhost_ops->vhost_set_vring_enable) { - return 0; - } - - /* - * For vhost-user devices, if VHOST_USER_F_PROTOCOL_FEATURES has not - * been negotiated, the rings start directly in the enabled state, and - * .vhost_set_vring_enable callback will fail since - * VHOST_USER_SET_VRING_ENABLE is not supported. - */ - if (hdev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_USER && - !virtio_has_feature(hdev->backend_features, - VHOST_USER_F_PROTOCOL_FEATURES)) { - return 0; - } - - return hdev->vhost_ops->vhost_set_vring_enable(hdev, enable); -} - /* * Host notifiers must be enabled at this point. * diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 89817bd8486..3dfec5e15cc 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -215,6 +215,15 @@ static inline bool vhost_dev_is_started(struct vhost_d= ev *hdev) return hdev->started; } =20 +static inline int vhost_dev_set_vring_enable(struct vhost_dev *hdev, int e= nable) +{ + if (!hdev->vhost_ops->vhost_set_vring_enable) { + return 0; + } + + return hdev->vhost_ops->vhost_set_vring_enable(hdev, enable); +} + /** * vhost_dev_start() - start the vhost device * @hdev: common vhost_dev structure --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) client-ip=38.145.34.151; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=yandex-team.ru Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [38.145.34.151]) by mx.zohomail.com with SMTPS id 1779862713829744.4312802574814; Tue, 26 May 2026 23:18:33 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 4232D41B14; Wed, 27 May 2026 02:18:32 -0400 (EDT) Received: from [172.19.199.9] (unknown [10.16.107.18]) by lists.libvirt.org (Postfix) with ESMTP id D397241C2C; Wed, 27 May 2026 02:16:51 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 6C20941ABF; Wed, 27 May 2026 02:16:43 -0400 (EDT) Received: from forwardcorp1d.mail.yandex.net (forwardcorp1d.mail.yandex.net [IPv6:2a02:6b8:c41:1300:1:45:d181:df01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 9CC0A41ABB for ; Wed, 27 May 2026 02:16:39 -0400 (EDT) Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 7345081E27; Wed, 27 May 2026 09:16:31 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-yTd7ULs6; Wed, 27 May 2026 09:16:30 +0300 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=4.0.1 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862590; bh=Gkxf+me90eN6ZhWRVM0cpnIRnA6GgN0WsU3pUhxePJg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=R05O7AJfcMut7d557BYt19fy1wVI47LQlGg/DHBmS4wjbsenY0WEWrhUnAdhQQy9A KuQA1F8G/AuRGUIKjmOHqK7iBWhSFd+L4qAoZffdpch8ylKlpI9he4hAu9Ue9eGhT5 dReRv+5ek5efCjHjJvLSEcjwDt+ZtZgiURFmNnns= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Subject: [PATCH v7 02/22] vhost: drop backend_features field Date: Wed, 27 May 2026 09:16:03 +0300 Message-ID: <20260527061625.11167-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ZVNRYLMTVZW75IHMP36VOBNRFYANQ7FS X-Message-ID-Hash: ZVNRYLMTVZW75IHMP36VOBNRFYANQ7FS X-MailFrom: vsementsov@yandex-team.ru X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header 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, devel@lists.libvirt.org, Markus Armbruster , Raphael Norwitz , Raphael Norwitz , Kevin Wolf , Hanna Reitz , Jason Wang , Paolo Bonzini , Fam Zheng , Eric Blake , "open list:Block layer core" X-Mailman-Version: 3.3.10 List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1779862714347158500 Content-Type: text/plain; charset="utf-8" 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 Acked-by: Markus Armbruster Reviewed-by: Daniil Tatianin Acked-by: Raphael Norwitz --- hw/block/vhost-user-blk.c | 1 - hw/net/vhost_net.c | 26 ++++++++++++++------------ hw/scsi/vhost-scsi.c | 1 - hw/scsi/vhost-user-scsi.c | 1 - hw/virtio/vdpa-dev.c | 1 - hw/virtio/vhost-user.c | 17 ++++++++--------- hw/virtio/virtio-hmp-cmds.c | 2 -- hw/virtio/virtio-qmp.c | 4 ---- include/hw/virtio/vhost.h | 7 ------- qapi/virtio.json | 3 --- 10 files changed, 22 insertions(+), 41 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index c151e836770..dc99de02635 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -348,7 +348,6 @@ static int vhost_user_blk_connect(DeviceState *dev, Err= or **errp) s->dev.nvqs =3D s->num_queues; s->dev.vqs =3D s->vhost_vqs; s->dev.vq_index =3D 0; - s->dev.backend_features =3D 0; =20 vhost_dev_set_config_notifier(&s->dev, &blk_ops); =20 diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 25e9f1fd244..fda90e231e6 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -52,8 +52,14 @@ int vhost_net_set_config(struct vhost_net *net, const ui= nt8_t *data, =20 void vhost_net_ack_features_ex(struct vhost_net *net, const uint64_t *feat= ures) { - virtio_features_copy(net->dev.acked_features_ex, - net->dev.backend_features_ex); + 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); + } else if (!qemu_has_vnet_hdr(net->nc)) { + net->dev.acked_features =3D 1ULL << VHOST_NET_F_VIRTIO_NET_HDR; + } + vhost_ack_features_ex(&net->dev, net->feature_bits, features); } =20 @@ -258,12 +264,9 @@ struct vhost_net *vhost_net_init(VhostNetOptions *opti= ons) if (r < 0) { goto fail; } - net->dev.backend_features =3D qemu_has_vnet_hdr(options->net_backe= nd) - ? 0 : (1ULL << VHOST_NET_F_VIRTIO_NET_HDR); net->backend =3D r; net->dev.protocol_features =3D 0; } else { - virtio_features_clear(net->dev.backend_features_ex); net->dev.protocol_features =3D 0; net->backend =3D -1; =20 @@ -284,13 +287,12 @@ struct vhost_net *vhost_net_init(VhostNetOptions *opt= ions) net->dev.features &=3D ~(1ULL << VIRTIO_NET_F_MRG_RXBUF); } =20 - if (virtio_features_andnot(missing_features, - net->dev.backend_features_ex, - net->dev.features_ex)) { - fprintf(stderr, "vhost lacks feature mask 0x" VIRTIO_FEATURES_= FMT - " for backend\n", VIRTIO_FEATURES_PR(missing_features)); - goto fail; - } + 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; + } } =20 /* Set sane init value. Override when guest acks. */ diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index 699863cc109..859888fdbaf 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -275,7 +275,6 @@ static void vhost_scsi_realize(DeviceState *dev, Error = **errp) vqs =3D g_new0(struct vhost_virtqueue, vsc->dev.nvqs); vsc->dev.vqs =3D vqs; vsc->dev.vq_index =3D 0; - vsc->dev.backend_features =3D 0; =20 ret =3D vhost_dev_init(&vsc->dev, (void *)(uintptr_t)vhostfd, VHOST_BACKEND_TYPE_KERNEL, 0, errp); diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index 3612897d4b9..5070178dc28 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -159,7 +159,6 @@ static int vhost_user_scsi_connect(DeviceState *dev, Er= ror **errp) vsc->dev.nvqs =3D VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; vsc->dev.vqs =3D s->vhost_vqs; vsc->dev.vq_index =3D 0; - vsc->dev.backend_features =3D 0; =20 ret =3D vhost_dev_init(&vsc->dev, &s->vhost_user, VHOST_BACKEND_TYPE_U= SER, 0, errp); diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c index 4532d63653e..06179e402e4 100644 --- a/hw/virtio/vdpa-dev.c +++ b/hw/virtio/vdpa-dev.c @@ -104,7 +104,6 @@ static void vhost_vdpa_device_realize(DeviceState *dev,= Error **errp) v->dev.vqs =3D vqs; v->dev.vq_index =3D 0; v->dev.vq_index_end =3D v->dev.nvqs; - v->dev.backend_features =3D 0; v->started =3D false; =20 ret =3D vhost_vdpa_get_iova_range(v->vhostfd, &iova_range); diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 13c73e7b178..7ce17c5b2d8 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1465,14 +1465,15 @@ static int vhost_user_set_features(struct vhost_dev= *dev, int ret; =20 /* - * We need to include any extra backend only feature bits that - * might be needed by our device. Currently this includes the - * VHOST_USER_F_PROTOCOL_FEATURES bit for enabling protocol - * features. + * Don't lose VHOST_USER_F_PROTOCOL_FEATURES, which is vhost-user + * specific. */ - ret =3D vhost_user_set_u64(dev, VHOST_USER_SET_FEATURES, - features | dev->backend_features, - log_enabled); + if (virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES))= { + features |=3D 1ULL << VHOST_USER_F_PROTOCOL_FEATURES; + } + + 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)) { @@ -2192,8 +2193,6 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, (dev->config_ops && dev->config_ops->vhost_dev_config_notifier= ); uint64_t protocol_features; =20 - dev->backend_features |=3D 1ULL << VHOST_USER_F_PROTOCOL_FEATURES; - err =3D vhost_user_get_u64(dev, VHOST_USER_GET_PROTOCOL_FEATURES, &protocol_features); if (err < 0) { diff --git a/hw/virtio/virtio-hmp-cmds.c b/hw/virtio/virtio-hmp-cmds.c index 1daae482d37..4bf9a3109d4 100644 --- a/hw/virtio/virtio-hmp-cmds.c +++ b/hw/virtio/virtio-hmp-cmds.c @@ -176,8 +176,6 @@ void hmp_virtio_status(Monitor *mon, const QDict *qdict) hmp_virtio_dump_features(mon, s->vhost_dev->features); monitor_printf(mon, " Acked features:\n"); hmp_virtio_dump_features(mon, s->vhost_dev->acked_features); - monitor_printf(mon, " Backend features:\n"); - hmp_virtio_dump_features(mon, s->vhost_dev->backend_features); monitor_printf(mon, " Protocol features:\n"); hmp_virtio_dump_protocols(mon, s->vhost_dev->protocol_features); } diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c index f9cdca50d99..71717c56a41 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -710,8 +710,6 @@ VirtioStatus *qmp_x_query_virtio_status(const char *pat= h, Error **errp) vdev->guest_features_ex); status->host_features =3D qmp_decode_features(vdev->device_id, vdev->host_features_ex); - status->backend_features =3D qmp_decode_features(vdev->device_id, - vdev->backend_features_ex= ); =20 switch (vdev->device_endian) { case VIRTIO_DEVICE_ENDIAN_LITTLE: @@ -752,8 +750,6 @@ VirtioStatus *qmp_x_query_virtio_status(const char *pat= h, Error **errp) qmp_decode_features(vdev->device_id, hdev->features_ex); status->vhost_dev->acked_features =3D qmp_decode_features(vdev->device_id, hdev->acked_features_ex); - status->vhost_dev->backend_features =3D - qmp_decode_features(vdev->device_id, hdev->backend_features_ex= ); =20 status->vhost_dev->protocol_features =3D qmp_decode_protocols(hdev->protocol_features); diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 3dfec5e15cc..e139e059857 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -100,16 +100,9 @@ struct vhost_dev { * * @features: available features provided by the backend * @acked_features: final negotiated features with front-end driver - * - * @backend_features: this is used in a couple of places to either - * store VHOST_USER_F_PROTOCOL_FEATURES to apply to - * VHOST_USER_SET_FEATURES or VHOST_NET_F_VIRTIO_NET_HDR. Its - * future use should be discouraged and the variable retired as - * its easy to confuse with the VirtIO backend_features. */ VIRTIO_DECLARE_FEATURES(features); VIRTIO_DECLARE_FEATURES(acked_features); - VIRTIO_DECLARE_FEATURES(backend_features); =20 /** * @protocol_features: is the vhost-user only feature set by diff --git a/qapi/virtio.json b/qapi/virtio.json index 09dd0e6d05a..671f1ad793c 100644 --- a/qapi/virtio.json +++ b/qapi/virtio.json @@ -85,8 +85,6 @@ # # @acked-features: vhost_dev acked_features # -# @backend-features: vhost_dev backend_features -# # @protocol-features: vhost_dev protocol_features # # @max-queues: vhost_dev max_queues @@ -106,7 +104,6 @@ 'vq-index': 'int', 'features': 'VirtioDeviceFeatures', 'acked-features': 'VirtioDeviceFeatures', - 'backend-features': 'VirtioDeviceFeatures', 'protocol-features': 'VhostDeviceProtocols', 'max-queues': 'uint64', 'backend-cap': 'uint64', --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862704; cv=none; d=zohomail.com; s=zohoarc; b=VO8h7I07wJ7hLSXkMhtcDrSHbiUbggOY9iwVoQJGbJuGvKc8oYykqyVL6z6JMPEAzpYRYY4jRMDsvnGfK937m7iiqSASJtZA8U6i3loWlGjFK5nasn3uK8q7W73cV252mp8C/ahz35+lCQZB9BgYaNu0M0eHkKBddVuwYkIZ/k4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862704; 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=wi8hBb/FxrPq6K5pIYsFChHST4eY8LX3PmM3S/gooyY=; b=EswXwDtWP43WI+i/PQ6xEcfWZNafPG2tt0t4KnBT+TlZ+GdNNd4hIgAcGsE39PV0fUWT5g5G9y6kV4jXwwuxgmFa0MOv2zDR78EvSZhJv8FnCNxXSC3wPmZOmQuNjVvWWhpd3z8e4RksFC1tzHJShB6ZBWa2xjRnx9qNmsDkkvo= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862704795488.9290544839771; Tue, 26 May 2026 23:18:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Zj-0004CP-VE; Wed, 27 May 2026 02:17:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZI-0003uw-N0 for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:41 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300: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 1wS7ZD-0003om-Cw for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:40 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 65CD18068E; Wed, 27 May 2026 09:16:32 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-hzEEgZeP; Wed, 27 May 2026 09:16:31 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862591; bh=wi8hBb/FxrPq6K5pIYsFChHST4eY8LX3PmM3S/gooyY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=ZT0oqtWwdtvLsAbExFLxMO3s0I1TD9d1EZkILqks341MiZIAkfIMPfbvT6MhCmV+K iJq1y24LCwQsGA2M4JG8a3eXGWE/mgiCJX224MY+7DqyG/7g9Suzpy1Kku2pQ/xcN/ UUHv5s5OM7EJxQWYE08W8FHzKKefGZlBY9k1GwaE= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 v7 03/22] vhost-user: introduce vhost_user_has_protocol_feature() helper Date: Wed, 27 May 2026 09:16:04 +0300 Message-ID: <20260527061625.11167-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; 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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862706501158500 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 7ce17c5b2d8..72aeed26caa 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -267,6 +267,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; @@ -430,8 +436,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, @@ -1001,11 +1007,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) { @@ -1053,8 +1059,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, @@ -1124,8 +1131,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; } @@ -1475,8 +1483,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); } @@ -1530,8 +1537,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 @@ -1588,8 +1595,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; } @@ -1887,13 +1894,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 @@ -2141,8 +2148,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"); @@ -2240,7 +2247,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) { @@ -2258,18 +2265,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); @@ -2293,8 +2300,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."); @@ -2363,8 +2370,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) @@ -2379,8 +2386,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); @@ -2394,11 +2400,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 @@ -2458,8 +2464,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; } @@ -2502,8 +2507,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, @@ -2511,8 +2516,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 @@ -2547,8 +2551,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, @@ -2649,8 +2654,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, @@ -2695,8 +2701,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 @@ -2763,8 +2769,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 @@ -2863,8 +2869,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 @@ -2889,16 +2894,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.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862687; cv=none; d=zohomail.com; s=zohoarc; b=UGRjStYM1FEtkVMbRXp/zXroDNER9J0i2ue7uBu6f6J4Vz6t+Sn7Cj+RC6SZsc3R6aBST6Z1ii/NDuMARIQZh4TLhBmkueZroBO/NiRBpqTMGYHepcgv34DPfKGD/zHqmAwoSZsxfnnvg73niXVUdVuY7Q/WIm3Qw3oqqtoI0oY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862687; 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=WxKn5yTwqrVh0rfVhVIPo0TFywv4rXak2ThV805BI6w=; b=n6Oqx8ve3dOYRQf8t65Io0sED9HU9oLqG8zg1xwq38Yrzm0FS0V/G0ExpuY4p8ns0Pa1+heS1loqFt+z/s+VBpmVvdq490LwwKh8QUi0w8pD1+5a6JfKgrKCdFe+ZWM3jeTg2fjwVIM8nCxknz/8FGtHKz1Vdzg2WRhVIMXwA40= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862687276399.362848388502; Tue, 26 May 2026 23:18:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7ZW-00041A-0d; Wed, 27 May 2026 02:16:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZI-0003uq-Dw; Wed, 27 May 2026 02:16:40 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZD-0003tE-L8; Wed, 27 May 2026 02:16:40 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 6A6E18076D; Wed, 27 May 2026 09:16:33 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-YJPE0tiy; Wed, 27 May 2026 09:16:32 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862592; bh=WxKn5yTwqrVh0rfVhVIPo0TFywv4rXak2ThV805BI6w=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=IXBqWp8cQUTP3w2dW0ZOnxEaBv1TLxoA2vwY6YpFHo8BQXDHVm9IfH6Q7BZT3XSE4 LkIjoNhUhSsjFbZQNRzsDJ+sHcrKPfYCMQvGOEkb7KuGGI57R979Tvkm+7iKECRdze Xypbemta1dRklHF/oHqdJKIFKPlO5aCx81AO4iaw= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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, "Gonglei (Arei)" , zhenwei pi , Raphael Norwitz , Kevin Wolf , Hanna Reitz , Jason Wang , qemu-block@nongnu.org (open list:Block layer core) Subject: [PATCH v7 04/22] vhost: move protocol_features to vhost_user Date: Wed, 27 May 2026 09:16:05 +0300 Message-ID: <20260527061625.11167-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; 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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862690955154100 Content-Type: text/plain; charset="utf-8" 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 --- backends/cryptodev-vhost.c | 1 - hw/block/vhost-user-blk.c | 6 ++---- hw/net/vhost_net.c | 2 -- hw/virtio/meson.build | 1 + hw/virtio/vhost-user-stub.c | 6 ++++++ hw/virtio/vhost-user.c | 36 +++++++++++++++++++++++++++------- hw/virtio/virtio-qmp.c | 6 ++++-- include/hw/virtio/vhost-user.h | 4 ++++ include/hw/virtio/vhost.h | 8 -------- 9 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 hw/virtio/vhost-user-stub.c diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index abdfce33afc..c6069f4e5bd 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -60,7 +60,6 @@ cryptodev_vhost_init( =20 crypto->cc =3D options->cc; =20 - crypto->dev.protocol_features =3D 0; crypto->backend =3D -1; =20 /* vhost-user needs vq_index to initiate a specific queue pair */ diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index dc99de02635..2831f3c0530 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -572,10 +572,8 @@ static bool vhost_user_blk_inflight_needed(void *opaqu= e) { struct VHostUserBlk *s =3D opaque; =20 - bool inflight_migration =3D virtio_has_feature(s->dev.protocol_feature= s, - VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIG= HT); - - return inflight_migration; + return vhost_user_has_protocol_feature( + &s->dev, VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIGHT); } =20 static const VMStateDescription vmstate_vhost_user_blk_inflight =3D { diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index fda90e231e6..ca199831260 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -265,9 +265,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *optio= ns) goto fail; } net->backend =3D r; - net->dev.protocol_features =3D 0; } else { - net->dev.protocol_features =3D 0; net->backend =3D -1; =20 /* vhost-user needs vq_index to initiate a specific queue pair */ diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index e0566a60de7..0ea89d8af4c 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -94,6 +94,7 @@ system_virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_tr= ue: virtio_pci_ss) =20 system_ss.add_all(when: 'CONFIG_VIRTIO', if_true: system_virtio_ss) stub_ss.add(files('vhost-stub.c')) +stub_ss.add(files('vhost-user-stub.c')) stub_ss.add(files('virtio-stub.c')) stub_ss.add(files('virtio-md-stubs.c')) =20 diff --git a/hw/virtio/vhost-user-stub.c b/hw/virtio/vhost-user-stub.c new file mode 100644 index 00000000000..45559788dd4 --- /dev/null +++ b/hw/virtio/vhost-user-stub.c @@ -0,0 +1,6 @@ +#include "qemu/osdep.h" +#include "hw/virtio/vhost-user.h" + +void vhost_user_qmp_status(struct vhost_dev *dev, VirtioStatus *status) +{ +} diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 72aeed26caa..fc2ed1f17e5 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -11,6 +11,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "hw/virtio/virtio-dmabuf.h" +#include "hw/virtio/virtio-qmp.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-crypto.h" #include "hw/virtio/vhost-user.h" @@ -259,6 +260,14 @@ struct vhost_user { /* Our current regions */ int num_shadow_regions; struct vhost_memory_region shadow_regions[VHOST_USER_MAX_RAM_SLOTS]; + + /** + * @protocol_features: the vhost-user protocol feature set by + * VHOST_USER_SET_PROTOCOL_FEATURES. Protocol features are only + * negotiated if VHOST_USER_F_PROTOCOL_FEATURES has been offered + * by the backend (see @features). + */ + uint64_t protocol_features; }; =20 struct scrub_regions { @@ -267,10 +276,13 @@ struct scrub_regions { int fd_idx; }; =20 -static bool vhost_user_has_protocol_feature(struct vhost_dev *dev, - uint64_t feature) +bool vhost_user_has_protocol_feature(struct vhost_dev *dev, uint64_t featu= re) { - return virtio_has_feature(dev->protocol_features, feature); + struct vhost_user *u =3D dev->opaque; + + assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_USER); + + return virtio_has_feature(u->protocol_features, feature); } =20 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, int ret; int fds[VHOST_USER_MAX_RAM_SLOTS]; size_t fd_num =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); VhostUserMsg msg =3D { .hdr.request =3D request, .hdr.flags =3D VHOST_USER_VERSION, @@ -2239,8 +2251,8 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, } =20 /* final set of protocol features */ - dev->protocol_features =3D protocol_features; - err =3D vhost_user_set_protocol_features(dev, dev->protocol_featur= es); + u->protocol_features =3D protocol_features; + err =3D vhost_user_set_protocol_features(dev, u->protocol_features= ); if (err < 0) { error_setg_errno(errp, EPROTO, "vhost_backend_init failed"); return -EPROTO; @@ -3033,6 +3045,16 @@ static int vhost_user_check_device_state(struct vhos= t_dev *dev, Error **errp) return 0; } =20 +void vhost_user_qmp_status(struct vhost_dev *dev, VirtioStatus *status) +{ + struct vhost_user *u =3D dev->opaque; + + assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_USER); + + status->vhost_dev->protocol_features =3D + qmp_decode_protocols(u->protocol_features); +} + const VhostOps user_ops =3D { .backend_type =3D VHOST_BACKEND_TYPE_USER, .vhost_backend_init =3D vhost_user_backend_init, diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c index 71717c56a41..c8bf702d38d 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -751,12 +751,14 @@ VirtioStatus *qmp_x_query_virtio_status(const char *p= ath, Error **errp) status->vhost_dev->acked_features =3D qmp_decode_features(vdev->device_id, hdev->acked_features_ex); =20 - status->vhost_dev->protocol_features =3D - qmp_decode_protocols(hdev->protocol_features); status->vhost_dev->max_queues =3D hdev->max_queues; status->vhost_dev->backend_cap =3D hdev->backend_cap; status->vhost_dev->log_enabled =3D hdev->log_enabled; status->vhost_dev->log_size =3D hdev->log_size; + + if (hdev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_USER) { + vhost_user_qmp_status(hdev, status); + } } =20 return status; diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h index 53fe9966862..0e576fc5386 100644 --- a/include/hw/virtio/vhost-user.h +++ b/include/hw/virtio/vhost-user.h @@ -10,6 +10,7 @@ =20 #include "chardev/char-fe.h" #include "hw/virtio/virtio.h" +#include "qapi/qapi-types-virtio.h" =20 enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_MQ =3D 0, @@ -113,4 +114,7 @@ void vhost_user_async_close(DeviceState *d, CharFrontend *chardev, struct vhost_dev *vhost, vu_async_close_fn cb); =20 +void vhost_user_qmp_status(struct vhost_dev *dev, VirtioStatus *status); +bool vhost_user_has_protocol_feature(struct vhost_dev *dev, uint64_t featu= re); + #endif diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index e139e059857..4a9bd3effef 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -104,14 +104,6 @@ struct vhost_dev { VIRTIO_DECLARE_FEATURES(features); VIRTIO_DECLARE_FEATURES(acked_features); =20 - /** - * @protocol_features: is the vhost-user only feature set by - * VHOST_USER_SET_PROTOCOL_FEATURES. Protocol features are only - * negotiated if VHOST_USER_F_PROTOCOL_FEATURES has been offered - * by the backend (see @features). - */ - uint64_t protocol_features; - uint64_t max_queues; uint64_t backend_cap; /* @started: is the vhost device started? */ --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862634; cv=none; d=zohomail.com; s=zohoarc; b=DvmDdQG11OJ5xczLH4W/dj2YBPrjPp2Tf44Asd6C3evfq+5a2wYCniORethipXEKXDE+zlf2zr4bfURXKImTxYMS0PoEG/9NWCLkqbVg6aNlWfjg1/Nkw7CW1iIY4cBCzkrvXle8GPKIyFuN962GlAGNZrM1NkFCmz638bf5vdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862634; h=Content-Type: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=oE4T19zXNcWHHs7k9zP1+uWbN/BtlGxOB701dZNS/yI=; b=QUIS96xuvup+8QG7vrsAsakIb5vBJDRyb/rU/deVGfNX/Oa5/pJhURq/F0+HX6aoI3Fz+EZv/LNF9WmmBzVoRexesZf6BjF0cRLgNdVAT9hNXNfGXUwUJal1J6McftsCQM5OIh2lvHhHxZNhAQOzmD+YGxvTG9DKPvb9p3o8fXo= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862634399206.3934959244666; Tue, 26 May 2026 23:17:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7ZS-0003zN-7e; Wed, 27 May 2026 02:16:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZH-0003u8-EP for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:39 -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 1wS7ZD-0003wP-FW for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:39 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 305A8C01AE; Wed, 27 May 2026 09:16:34 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-t1FgTzEI; Wed, 27 May 2026 09:16:33 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862593; bh=oE4T19zXNcWHHs7k9zP1+uWbN/BtlGxOB701dZNS/yI=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=EpJPoTSr/m0dcE13Gr3CE/3D5/+qozfP0GXp9Yaegna26yXwMZe3PijU24L4EMWZq yLidawMdug8WdMuzWYdf9VLnQ9ldDlYK4i+8gFORxKKWMm/PwOy92DaR5qwqvpnAHh 654oZO2a4mUote5i04uNlYmGtHryj+IcTHbT9WCg= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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?Philippe=20Mathieu-Daud=C3=A9?= , Raphael Norwitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v7 05/22] vhost-user-gpu: drop code duplication Date: Wed, 27 May 2026 09:16:06 +0300 Message-ID: <20260527061625.11167-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=lists1p.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: qemu development 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: 1779862639198154100 Obviously, this duplicated fragment doesn't make any sense. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/display/vhost-user-gpu.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 6e5e6540a46..6f02314356d 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -644,10 +644,6 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error= **errp) VIRTIO_GPU_F_RESOURCE_UUID)) { g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_RESOURCE_UUID_E= NABLED; } - if (virtio_has_feature(g->vhost->dev.features, - VIRTIO_GPU_F_RESOURCE_UUID)) { - g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_RESOURCE_UUID_E= NABLED; - } =20 if (!virtio_gpu_base_device_realize(qdev, NULL, NULL, errp)) { return; --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862692; cv=none; d=zohomail.com; s=zohoarc; b=cjMfQYlW5l3L6scTjvWEqqFwwSzC36cuU2EKcNsOfAeF3zXXaJd6xZvPnsVvK6Icoc96UgyGQ2/nx8TVX8Fu0QDfmk7oLVjYPaT2PmGTZDP6fKklRX2L6jlR7PuLieXFdcxzqjlFw5/A9mGC8HdIm0ANE7lKC5m/zusKPXjtGHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862692; 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=4hLW4bxNN0FVNtC3VGXgonL61WblrKf+5IJ6pHJX9tg=; b=hPxoEmIXZLOT022YBTPZpe3WJcD6yjsQlEr4PfIqZlWTHKnTAfH9StXqbht/H1eAsOdd8MmJXO5i0BuvgEN3whau0umgO1FunJqu9Nz6RwMlEVdkx8TIwkUNq/hgqwL3A4DWwTQ7UCy8L0E7qYbpq62iOu16AGXVWZV+jwAfmrs= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862692169529.6716694344678; Tue, 26 May 2026 23:18:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Zf-00047p-FO; Wed, 27 May 2026 02:17:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZJ-0003v9-4k for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:41 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900: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 1wS7ZF-0003xQ-23 for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:40 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 3CCE080765; Wed, 27 May 2026 09:16:35 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-sPGVnJ00; Wed, 27 May 2026 09:16:34 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862594; bh=4hLW4bxNN0FVNtC3VGXgonL61WblrKf+5IJ6pHJX9tg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=1M9H9HNWSGhbIUOWX8eiafAizCPHyeYtnQ4n4MZQyvHl9IkWWJfdwD9qUFnI//Qf/ jHUFHhhMQBYyKp85bL8lqPge/zztxL/Vwglyjj+f89v4FzJ0hxKPR2rFgC8KXaPHaI m5+aw50c2l70t9g936RpQoQ+ShthMT8FJvGaPKO0= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 v7 06/22] vhost: make vhost_dev.features private Date: Wed, 27 May 2026 09:16:07 +0300 Message-ID: <20260527061625.11167-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862695464154100 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 6f02314356d..57360898ca0 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 ca199831260..323d1177359 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 06179e402e4..94188d37bbf 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 01ab9ca56b1..5bbf4a73679 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 fc2ed1f17e5..68dd89cd8f8 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1249,7 +1249,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, @@ -1488,7 +1488,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 b89797df95e..e39e0676e00 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1612,7 +1612,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", @@ -1635,7 +1635,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()) { @@ -1909,7 +1909,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 c8bf702d38d..51e3a42c4c4 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -747,7 +747,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 4a9bd3effef..54862f9b445 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 f1523697e20..c85956a04b8 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -257,15 +257,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 @@ -586,7 +585,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.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862726; cv=none; d=zohomail.com; s=zohoarc; b=eNBdml/jhndEWlW8JZKZC7r7sh4GXH9FQfh4OBrRM9+ihptCZFJbXFNSLWCuVzOhmTn94FrBhs6NG8/8lTIl/pWYU77yyQXkPZGpAmtBqgTMYxzxPsegDk8OxY1YJZLpvkuAX0nN8uGNqMHkDT/NycExYkv11fdawDosdfx6tEE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862726; 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=QEEwy+dN5qvPAArzLEm5d7opYjusYr6sVYsGJM8xscM=; b=XPi2lGtBPnxMvJA+tvaqPp6Bu/1jyx30vuevFg9juOluLszL71xmoi5bbfXINn5civlrxB6p74n5P4kTl+QxPsmuhCid0eWm4poTXysV8Tc0EDKpKqfVIuSsm+Lpnfe24vm04jmxvM9lwI9MJZkdv9Q99MBAsD6UviUMTbHvfxo= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862726408274.7625361974775; Tue, 26 May 2026 23:18:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Zg-00049O-LS; Wed, 27 May 2026 02:17:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZK-0003vu-Fh; Wed, 27 May 2026 02:16:45 -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 1wS7ZG-0003yV-4I; Wed, 27 May 2026 02:16:42 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 70F61C01E8; Wed, 27 May 2026 09:16:36 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-iv5HoV2E; Wed, 27 May 2026 09:16:35 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862595; bh=QEEwy+dN5qvPAArzLEm5d7opYjusYr6sVYsGJM8xscM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=NTMqlPz/W/WWY/SzYp9v2z2ga3ag8PE6LQjppuIIY+Bz0IQ+nxhshmjcaPecsPljF b8cwyaxhTtuAKIL5oiSQb3HRgScjgPPkkjSpzBUWfT09yhfJNhV0RXdwLThChBaHsE UbH6+e+vSSQm9vWP9IpBes4NXzFB14V+c1XvOjHk= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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, Eric Farman , Cornelia Huck , Halil Pasic , Richard Henderson , Ilya Leoshkevich , David Hildenbrand , Matthew Rosato , Christian Borntraeger , qemu-s390x@nongnu.org (open list:virtio-ccw) Subject: [PATCH v7 07/22] virtio: move common part of _set_guest_notifier to generic code Date: Wed, 27 May 2026 09:16:08 +0300 Message-ID: <20260527061625.11167-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.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: qemu development 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: 1779862728895154100 Content-Type: text/plain; charset="utf-8" virtio-pci, virtio-mmio and virtio-ccw handle config notifier equally but with different code (mmio adds a separate function, when pci use common function). Let's chose the more compact way (pci) and reuse it for mmio. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Eric Farman --- hw/s390x/virtio-ccw.c | 35 ++++++++++++------------- hw/virtio/virtio-mmio.c | 41 +++++------------------------ hw/virtio/virtio-pci.c | 34 +++--------------------- hw/virtio/virtio.c | 47 +++++++++++++++++++++++++++++++--- include/hw/virtio/virtio-pci.h | 3 --- include/hw/virtio/virtio.h | 15 ++++++++--- 6 files changed, 82 insertions(+), 93 deletions(-) diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index ba55bf4fe97..cdad862ec23 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -1025,20 +1025,27 @@ static int virtio_ccw_set_guest_notifier(VirtioCcwD= evice *dev, int n, VirtQueue *vq =3D virtio_get_queue(vdev, n); EventNotifier *notifier =3D virtio_queue_get_guest_notifier(vq); VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); + int r; =20 - if (assign) { - int r =3D event_notifier_init(notifier, 0); - - if (r < 0) { - return r; + if (!assign) { + if (k->guest_notifier_mask && vdev->use_guest_notifier_mask) { + k->guest_notifier_mask(vdev, n, true); } - virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd); + if (with_irqfd) { + virtio_ccw_remove_irqfd(dev, n); + } + } + + r =3D virtio_set_guest_notifier(vdev, n, assign, with_irqfd); + if (r < 0) { + return r; + } + + if (assign) { if (with_irqfd) { r =3D virtio_ccw_add_irqfd(dev, n); if (r) { - virtio_queue_set_guest_notifier_fd_handler(vq, false, - with_irqfd); - event_notifier_cleanup(notifier); + virtio_set_guest_notifier(vdev, n, false, with_irqfd); return r; } } @@ -1054,16 +1061,8 @@ static int virtio_ccw_set_guest_notifier(VirtioCcwDe= vice *dev, int n, k->guest_notifier_pending(vdev, n)) { event_notifier_set(notifier); } - } else { - if (k->guest_notifier_mask && vdev->use_guest_notifier_mask) { - k->guest_notifier_mask(vdev, n, true); - } - if (with_irqfd) { - virtio_ccw_remove_irqfd(dev, n); - } - virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd); - event_notifier_cleanup(notifier); } + return 0; } =20 diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c index 742ca3d3e4d..58c6d46aab4 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -670,18 +670,11 @@ static int virtio_mmio_set_guest_notifier(DeviceState= *d, int n, bool assign, VirtIOMMIOProxy *proxy =3D VIRTIO_MMIO(d); VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); - VirtQueue *vq =3D virtio_get_queue(vdev, n); - EventNotifier *notifier =3D virtio_queue_get_guest_notifier(vq); + int r; =20 - if (assign) { - int r =3D event_notifier_init(notifier, 0); - if (r < 0) { - return r; - } - virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd); - } else { - virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd); - event_notifier_cleanup(notifier); + r =3D virtio_set_guest_notifier(vdev, n, assign, with_irqfd); + if (r < 0) { + return r; } =20 if (vdc->guest_notifier_mask && vdev->use_guest_notifier_mask) { @@ -690,30 +683,7 @@ static int virtio_mmio_set_guest_notifier(DeviceState = *d, int n, bool assign, =20 return 0; } -static int virtio_mmio_set_config_guest_notifier(DeviceState *d, bool assi= gn, - bool with_irqfd) -{ - VirtIOMMIOProxy *proxy =3D VIRTIO_MMIO(d); - VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); - VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); - EventNotifier *notifier =3D virtio_config_get_guest_notifier(vdev); - int r =3D 0; =20 - if (assign) { - r =3D event_notifier_init(notifier, 0); - if (r < 0) { - return r; - } - virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irq= fd); - } else { - virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irq= fd); - event_notifier_cleanup(notifier); - } - if (vdc->guest_notifier_mask && vdev->use_guest_notifier_mask) { - vdc->guest_notifier_mask(vdev, VIRTIO_CONFIG_IRQ_IDX, !assign); - } - return r; -} static int virtio_mmio_set_guest_notifiers(DeviceState *d, int nvqs, bool assign) { @@ -735,7 +705,8 @@ static int virtio_mmio_set_guest_notifiers(DeviceState = *d, int nvqs, goto assign_error; } } - r =3D virtio_mmio_set_config_guest_notifier(d, assign, with_irqfd); + r =3D virtio_mmio_set_guest_notifier(d, VIRTIO_CONFIG_IRQ_IDX, assign, + with_irqfd); if (r < 0) { goto assign_error; } diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index bcab2d18b80..fd9719547f9 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1208,43 +1208,17 @@ static void virtio_pci_vector_poll(PCIDevice *dev, } } =20 -void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev, VirtQueu= e *vq, - int n, bool assign, - bool with_irqfd) -{ - if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { - virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irq= fd); - } else { - virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd); - } -} - static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assig= n, bool with_irqfd) { VirtIOPCIProxy *proxy =3D to_virtio_pci_proxy(d); VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); - VirtQueue *vq =3D NULL; - EventNotifier *notifier =3D NULL; + int r; =20 - if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { - notifier =3D virtio_config_get_guest_notifier(vdev); - } else { - vq =3D virtio_get_queue(vdev, n); - notifier =3D virtio_queue_get_guest_notifier(vq); - } - - if (assign) { - int r =3D event_notifier_init(notifier, 0); - if (r < 0) { - return r; - } - virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, true, with_i= rqfd); - } else { - virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, false, - with_irqfd); - event_notifier_cleanup(notifier); + r =3D virtio_set_guest_notifier(vdev, n, assign, with_irqfd); + if (r < 0) { + return r; } =20 if (!msix_enabled(&proxy->pci_dev) && diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 63e2faee994..3780e860391 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3835,8 +3835,10 @@ static void virtio_config_guest_notifier_read(EventN= otifier *n) virtio_notify_config(vdev); } } -void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign, - bool with_irqfd) + +static void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, + bool assign, + bool with_irqfd) { if (assign && !with_irqfd) { event_notifier_set_handler(&vq->guest_notifier, @@ -3851,7 +3853,7 @@ void virtio_queue_set_guest_notifier_fd_handler(VirtQ= ueue *vq, bool assign, } } =20 -void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev, +static void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev, bool assign, bool with_ir= qfd) { EventNotifier *n; @@ -3868,6 +3870,45 @@ void virtio_config_set_guest_notifier_fd_handler(Vir= tIODevice *vdev, } } =20 +static void virtio_set_guest_notifier_fd_handler(VirtIODevice *vdev, + VirtQueue *vq, + int n, bool assign, + bool with_irqfd) +{ + if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irq= fd); + } else { + virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd); + } +} + +int virtio_set_guest_notifier(VirtIODevice *vdev, int n, bool assign, + bool with_irqfd) +{ + VirtQueue *vq =3D NULL; + EventNotifier *notifier =3D NULL; + + if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + notifier =3D virtio_config_get_guest_notifier(vdev); + } else { + vq =3D virtio_get_queue(vdev, n); + notifier =3D virtio_queue_get_guest_notifier(vq); + } + + if (assign) { + int r =3D event_notifier_init(notifier, 0); + if (r < 0) { + return r; + } + virtio_set_guest_notifier_fd_handler(vdev, vq, n, true, with_irqfd= ); + } else { + virtio_set_guest_notifier_fd_handler(vdev, vq, n, false, with_irqf= d); + event_notifier_cleanup(notifier); + } + + return 0; +} + EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq) { return &vq->guest_notifier; diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h index 5cb20b73f62..ee50fb0d551 100644 --- a/include/hw/virtio/virtio-pci.h +++ b/include/hw/virtio/virtio-pci.h @@ -250,9 +250,6 @@ void virtio_pci_types_register(const VirtioPCIDeviceTyp= eInfo *t); * @fixed_queues. */ unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues); -void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev, VirtQueu= e *vq, - int n, bool assign, - bool with_irqfd); =20 int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, uint8_t bar, uint64_t of= fset, uint64_t length, uint8_t id); diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 6344bd7b689..d9fde425581 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -420,8 +420,6 @@ void virtio_queue_update_used_idx(VirtIODevice *vdev, i= nt n); VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n); uint16_t virtio_get_queue_index(VirtQueue *vq); EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq); -void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign, - bool with_irqfd); int virtio_device_start_ioeventfd(VirtIODevice *vdev); int virtio_device_grab_ioeventfd(VirtIODevice *vdev); void virtio_device_release_ioeventfd(VirtIODevice *vdev); @@ -435,8 +433,17 @@ void virtio_queue_aio_detach_host_notifier(VirtQueue *= vq, AioContext *ctx); VirtQueue *virtio_vector_first_queue(VirtIODevice *vdev, uint16_t vector); VirtQueue *virtio_vector_next_queue(VirtQueue *vq); EventNotifier *virtio_config_get_guest_notifier(VirtIODevice *vdev); -void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev, - bool assign, bool with_ir= qfd); + +/** + * virtio_set_guest_notifier - set/unset queue or config guest notifier + * + * @vdev: the VirtIO device + * @n: queue number, or VIRTIO_CONFIG_IRQ_IDX to set config notifer + * @assign: true to set notifier, false to unset + * @with_irqfd: irqfd enabled + */ +int virtio_set_guest_notifier(VirtIODevice *vdev, int n, bool assign, + bool with_irqfd); =20 static inline void virtio_add_feature(uint64_t *features, unsigned int fbi= t) { --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862690; cv=none; d=zohomail.com; s=zohoarc; b=jivlxAe2m46oI8gZgd5YM0YohT2j53TH/ouECA/sCAecA8lMT8X1zRyzRby34Am1OscyBnrhAtGqb9VcXkLDtG1k3i1C5T6+/OOTYoURFVU2p97Hp5WA136bHe8JlVfYXjAl2iI7aL8P3DYv/4a0YU5PjmydtvR1k3jbKZAj774= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862690; 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=f+YTC8jxqRIkRV5zuadeLcBGcoK/zFyu6bOocqT+UcM=; b=kw7QV0t4Ji7CI/FrSDSoYlzf4EtWXW1tb+35zEcWXjFKFucVQVcLadmFeaOmdJkuCLmv9cRHhUz+HzfESAZKWhc7WLU75JAvvjatqpUEBk4G/b5rX1TfLOSF1DUYsAZw+4CH5MGV7ZlqZwbEFWOem4b1LA4JHvj1O7aqIjz0Fyk= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862690080390.8907402398918; Tue, 26 May 2026 23:18:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Zg-00048g-4h; Wed, 27 May 2026 02:17:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZK-0003vq-8d for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:45 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900: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 1wS7ZH-0003ye-Ef for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:41 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 35A3180677; Wed, 27 May 2026 09:16:37 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-j39ha1xi; Wed, 27 May 2026 09:16:36 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862596; bh=f+YTC8jxqRIkRV5zuadeLcBGcoK/zFyu6bOocqT+UcM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=dMfzEqpYd2yGfhepVx0d4Co80kHX/oRK0/0xyT0VmECD+e+YC2JBy1cCsSq/DPh01 YV7a9Uc4LSdt2BuWJF2NamlN2a4mmKcNCupWP82fj5uricuJUuDm4tSnlYIuyE+/ZB uty553lS7R8tOGw3xtEtqwlFswp5xeB/97vcZ7HM= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 Subject: [PATCH v7 08/22] virtio: drop *_set_guest_notifier_fd_handler() helpers Date: Wed, 27 May 2026 09:16:09 +0300 Message-ID: <20260527061625.11167-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862692671158500 Content-Type: text/plain; charset="utf-8" Now they don't make code more readable. Let's better put the whole logic into virtio_queue_set_guest_notifier(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin --- hw/virtio/virtio.c | 75 +++++++++++----------------------------------- 1 file changed, 17 insertions(+), 58 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 3780e860391..fb7f7f0f061 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3836,73 +3836,32 @@ static void virtio_config_guest_notifier_read(Event= Notifier *n) } } =20 -static void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, - bool assign, - bool with_irqfd) -{ - if (assign && !with_irqfd) { - event_notifier_set_handler(&vq->guest_notifier, - virtio_queue_guest_notifier_read); - } else { - event_notifier_set_handler(&vq->guest_notifier, NULL); - } - if (!assign) { - /* Test and clear notifier before closing it, - * in case poll callback didn't have time to run. */ - virtio_queue_guest_notifier_read(&vq->guest_notifier); - } -} - -static void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev, - bool assign, bool with_ir= qfd) -{ - EventNotifier *n; - n =3D &vdev->config_notifier; - if (assign && !with_irqfd) { - event_notifier_set_handler(n, virtio_config_guest_notifier_read); - } else { - event_notifier_set_handler(n, NULL); - } - if (!assign) { - /* Test and clear notifier before closing it,*/ - /* in case poll callback didn't have time to run. */ - virtio_config_guest_notifier_read(n); - } -} - -static void virtio_set_guest_notifier_fd_handler(VirtIODevice *vdev, - VirtQueue *vq, - int n, bool assign, - bool with_irqfd) -{ - if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { - virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irq= fd); - } else { - virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd); - } -} - int virtio_set_guest_notifier(VirtIODevice *vdev, int n, bool assign, bool with_irqfd) { - VirtQueue *vq =3D NULL; - EventNotifier *notifier =3D NULL; - - if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { - notifier =3D virtio_config_get_guest_notifier(vdev); - } else { - vq =3D virtio_get_queue(vdev, n); - notifier =3D virtio_queue_get_guest_notifier(vq); - } + bool is_config =3D n =3D=3D VIRTIO_CONFIG_IRQ_IDX; + VirtQueue *vq =3D is_config ? NULL : virtio_get_queue(vdev, n); + EventNotifier *notifier =3D is_config ? + virtio_config_get_guest_notifier(vdev) : + virtio_queue_get_guest_notifier(vq); + EventNotifierHandler *read_fn =3D is_config ? + virtio_config_guest_notifier_read : + virtio_queue_guest_notifier_read; =20 if (assign) { int r =3D event_notifier_init(notifier, 0); if (r < 0) { return r; } - virtio_set_guest_notifier_fd_handler(vdev, vq, n, true, with_irqfd= ); - } else { - virtio_set_guest_notifier_fd_handler(vdev, vq, n, false, with_irqf= d); + } + + event_notifier_set_handler(notifier, + (assign && !with_irqfd) ? read_fn : NULL); + + if (!assign) { + /* Test and clear notifier before closing it,*/ + /* in case poll callback didn't have time to run. */ + read_fn(notifier); event_notifier_cleanup(notifier); } =20 --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862747; cv=none; d=zohomail.com; s=zohoarc; b=IAG+Gesqg2f/IaLzfk5jIfx96vKMg74My3SFIK9610FOgQEubd8WBDaP3QWO23Snci855YYzVukHyk6Mdv7855M2pi8+UZA68cvVcedhEhLeNZTSP4eulf6/FFSnULI3FQqdgKa1J4ddEABXF24VFqbYf04D4wwZ1i8HqoL9laA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862747; 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=z7NzS2BOltO1smLgMQemP3Hs/WnVs4xBnAPGQOKC/zU=; b=Fl1Xs8SAwIeN/7Z2aUW+6KRlWLkZz/K7AB+KyG9l3vruuueyi5xc6HBRHmjUdrtnPTBHxAFHWs14c1E97nrCgGrr3FjpEu2kZEH/X2iOcMber2aDzwgngBUILk0YoMLQjIiW9nORXM7CwYF7LNeVoHAzWt64jumoUYJfx3LY9rg= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862747516901.9378416475208; Tue, 26 May 2026 23:19:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7ZZ-00043a-Ml; Wed, 27 May 2026 02:16:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZK-0003vm-55 for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:44 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900: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 1wS7ZH-0003yt-9t for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:41 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id F06DD8078A; Wed, 27 May 2026 09:16:37 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-Dw12idiD; Wed, 27 May 2026 09:16:37 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862597; bh=z7NzS2BOltO1smLgMQemP3Hs/WnVs4xBnAPGQOKC/zU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=OE87RdNzfYMt4HtclF9NB7ln/2dTl70X/1sYxsBOvegxLI008c7C+zVhPB7y67O++ pEvv8dbVEgND1A57rafg+nnB9GAvXVXjpyDoW71NoeqKaJOrN5iZV+e1FKD2U+9uFL vyCLyDJZe5thhmQYrgosaPMjZ7A/5I9xhfE+JV8Y= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 v7 09/22] vhost-user: keep QIOChannelSocket for backend channel Date: Wed, 27 May 2026 09:16:10 +0300 Message-ID: <20260527061625.11167-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862749232154100 Content-Type: text/plain; charset="utf-8" Keep QIOChannelSocket pointer instead of more generic QIOChannel. No real difference for now, but it would be simpler to migrate socket fd in further commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/virtio/vhost-user.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 68dd89cd8f8..31eaf65430e 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -239,7 +239,7 @@ struct vhost_user { struct vhost_dev *dev; /* Shared between vhost devs of the same virtio device */ VhostUserState *user; - QIOChannel *backend_ioc; + QIOChannelSocket *backend_sioc; GSource *backend_src; NotifierWithReturn postcopy_notifier; struct PostCopyFD postcopy_fd; @@ -1796,8 +1796,8 @@ static void close_backend_channel(struct vhost_user *= u) g_source_destroy(u->backend_src); g_source_unref(u->backend_src); u->backend_src =3D NULL; - object_unref(OBJECT(u->backend_ioc)); - u->backend_ioc =3D NULL; + object_unref(OBJECT(u->backend_sioc)); + u->backend_sioc =3D NULL; } =20 static gboolean backend_read(QIOChannel *ioc, GIOCondition condition, @@ -1909,7 +1909,6 @@ static int vhost_setup_backend_channel(struct vhost_d= ev *dev) 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 (!vhost_user_has_protocol_feature( dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ)) { @@ -1922,15 +1921,15 @@ static int vhost_setup_backend_channel(struct vhost= _dev *dev) return -saved_errno; } =20 - ioc =3D QIO_CHANNEL(qio_channel_socket_new_fd(sv[0], &local_err)); - if (!ioc) { + u->backend_sioc =3D qio_channel_socket_new_fd(sv[0], &local_err); + if (!u->backend_sioc) { error_report_err(local_err); return -ECONNREFUSED; } - u->backend_ioc =3D ioc; - u->backend_src =3D qio_channel_add_watch_source(u->backend_ioc, - G_IO_IN | G_IO_HUP, - backend_read, dev, NULL, N= ULL); + u->backend_src =3D qio_channel_add_watch_source(QIO_CHANNEL(u->backend= _sioc), + G_IO_IN | G_IO_HUP, + backend_read, dev, + NULL, NULL); =20 if (reply_supported) { msg.hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; @@ -2350,7 +2349,7 @@ static int vhost_user_backend_cleanup(struct vhost_de= v *dev) close(u->postcopy_fd.fd); u->postcopy_fd.handler =3D NULL; } - if (u->backend_ioc) { + if (u->backend_sioc) { close_backend_channel(u); } g_free(u->region_rb); --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862787; cv=none; d=zohomail.com; s=zohoarc; b=iPW6gO7TYC3ICtEdnm+TO8Mxr5I8UNwKj49ZvmiVWABfbLIWZU6YIXPnnZjnA4yq/T6cFafiXjBR8EOgLpivq88EtaRrY0FVS1WV9iuwqzXje4UcF0dWhvRNXMDVIW2tg4i71p+KD5QE3QdYxVfWDXJ7awXDmtZsbaUpOvdmM58= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862787; 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=34scPHp2ZdybOm2yZ0WL9aJaMm2nao2xuPbVsUANPc0=; b=TM4rVWdfa2BQD6kURV6dX78BJTKZ0Ee56PGk5gIzeQ6uCARoXrZrZFJM5ZfBuX+GHpzXms3gMfgW+vV7zWTk+OYjsq1Xe6WEHwVur7/dRyI73mwb7LWPFewpGPFDo/M2DxBdD3Jis3uu2flNdil19IZtA3p3yIN1S1vcsj2tu7c= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862787768932.8857057465958; Tue, 26 May 2026 23:19:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Zl-0004DN-9d; Wed, 27 May 2026 02:17:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZK-0003w5-PS for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:46 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZI-0003z7-Rj for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:42 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id B272BC01A6; Wed, 27 May 2026 09:16:38 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-qnmqZbDU; Wed, 27 May 2026 09:16:38 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862598; bh=34scPHp2ZdybOm2yZ0WL9aJaMm2nao2xuPbVsUANPc0=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=G3bPCrIhM6aQSAvg75+Dqzk2RaTmYPDTTYFbnhIIrtnFNIMs5DZmf7+LBJN3HIZL5 a1MdBfZu/uCFCkFap0YBC0P5ikz6X7B0CGZiA/vHNvTRuAOEyldYWod+jPFTdBJ5K4 4zwiqFlKOuYY/ApZig3AXQ5WsxK+4v0YoYAx1kxA= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 v7 10/22] vhost: vhost_virtqueue_start(): fix failure path Date: Wed, 27 May 2026 09:16:11 +0300 Message-ID: <20260527061625.11167-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862789775154100 Content-Type: text/plain; charset="utf-8" We miss call to unmap in cases when vhost_memory_map() returns lenght less than requested (still we consider such cases as an error). Let's fix it in vhost_memory_map(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index e39e0676e00..131a2fbf870 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -454,11 +454,20 @@ static inline void vhost_dev_log_resize(struct vhost_= dev *dev, uint64_t size) } =20 static void *vhost_memory_map(struct vhost_dev *dev, hwaddr addr, - hwaddr *plen, bool is_write) + hwaddr len, bool is_write) { if (!vhost_dev_has_iommu(dev)) { - return address_space_map(dev->vdev->dma_as, addr, plen, is_write, - MEMTXATTRS_UNSPECIFIED); + hwaddr mapped_len =3D len; + void *res =3D address_space_map(dev->vdev->dma_as, addr, &mapped_l= en, + is_write, MEMTXATTRS_UNSPECIFIED); + if (!res) { + return NULL; + } + if (len !=3D mapped_len) { + address_space_unmap(dev->vdev->dma_as, res, mapped_len, 0, 0); + return NULL; + } + return res; } else { return (void *)(uintptr_t)addr; } @@ -1312,22 +1321,22 @@ int vhost_virtqueue_start(struct vhost_dev *dev, } =20 l =3D vq->desc_size; - vq->desc =3D vhost_memory_map(dev, vq->desc_phys, &l, false); - if (!vq->desc || l !=3D vq->desc_size) { + vq->desc =3D vhost_memory_map(dev, vq->desc_phys, l, false); + if (!vq->desc) { r =3D -ENOMEM; goto fail_alloc_desc; } =20 l =3D vq->avail_size; - vq->avail =3D vhost_memory_map(dev, vq->avail_phys, &l, false); - if (!vq->avail || l !=3D vq->avail_size) { + vq->avail =3D vhost_memory_map(dev, vq->avail_phys, l, false); + if (!vq->avail) { r =3D -ENOMEM; goto fail_alloc_avail; } =20 l =3D vq->used_size; - vq->used =3D vhost_memory_map(dev, vq->used_phys, &l, true); - if (!vq->used || l !=3D vq->used_size) { + vq->used =3D vhost_memory_map(dev, vq->used_phys, l, true); + if (!vq->used) { r =3D -ENOMEM; goto fail_alloc_used; } --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862775; cv=none; d=zohomail.com; s=zohoarc; b=Wc8hYbO8n1EE/JCOK+2izGmq724BoO0UY1F3RVlmc2sl1cEO1kYgRlZY2CUWF66TistPnvznNtsGaYpiPKeckQZRqPClPOmWh6l8U82bV1LNeDfpoNdP+t4gwMgEXrcX2+ib30W9mEBvty/zKGNCTBzpRb/0nM6OMzyrv7CVi84= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862775; 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=uXIHNL9MutPa4LnUI29ZbTfFKnQQj49Z1ngH4e7u84w=; b=g+vaihp+9wNjBar8adq4TSl0+O1CXsuVoPkjQjswFutcbLIS/Ix+RrvshmG5QX7xujLSMhB6J8PwLwXKb08VUEAm+bjMBc3THQ0feYIeu6ticpfHA8CcgMZg9wXNqQOT7U6fyG8iGgkTkR56D4XMjYXiiaP/g9DYtU+83cNQqMg= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177986277545113.22860826029057; Tue, 26 May 2026 23:19:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Zh-0004AF-6P; Wed, 27 May 2026 02:17:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZM-0003wm-Ih for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:46 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZJ-0003zJ-7R for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:43 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 78801C01AE; Wed, 27 May 2026 09:16:39 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-CHmQtpTW; Wed, 27 May 2026 09:16:38 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862598; bh=uXIHNL9MutPa4LnUI29ZbTfFKnQQj49Z1ngH4e7u84w=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=u/6smphVGLSBYb7nBZE5Q2xhENZ5Ivs8CDaSe/uGqe0tdj2wjVqX3FuVpevLl0khH xM+JYVQI9OUdoWay7/j2rAPTQ42CeSmvfmo83lg92KF6qqX3unOMcLdeZ1P7Y2dvae 0QESAmLcvirXMQFVyjSF/CbHPTOiv8nIMGa09C/Q= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 v7 11/22] vhost: make vhost_memory_unmap() null-safe Date: Wed, 27 May 2026 09:16:12 +0300 Message-ID: <20260527061625.11167-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862777787154100 Content-Type: text/plain; charset="utf-8" This helps to simplify failure paths of vhost_virtqueue_start() a lot. We also need to zero-out pointers on unmap, to not try to unmap invalid pointers. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 131a2fbf870..b9b7a984e33 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -473,14 +473,20 @@ static void *vhost_memory_map(struct vhost_dev *dev, = hwaddr addr, } } =20 -static void vhost_memory_unmap(struct vhost_dev *dev, void *buffer, +static void vhost_memory_unmap(struct vhost_dev *dev, void **buffer, hwaddr len, int is_write, hwaddr access_len) { + if (!*buffer) { + return; + } + if (!vhost_dev_has_iommu(dev)) { - address_space_unmap(dev->vdev->dma_as, buffer, len, is_write, + address_space_unmap(dev->vdev->dma_as, *buffer, len, is_write, access_len); } + + *buffer =3D NULL; } =20 static int vhost_verify_ring_part_mapping(void *ring_hva, @@ -1324,33 +1330,33 @@ int vhost_virtqueue_start(struct vhost_dev *dev, vq->desc =3D vhost_memory_map(dev, vq->desc_phys, l, false); if (!vq->desc) { r =3D -ENOMEM; - goto fail_alloc_desc; + goto fail; } =20 l =3D vq->avail_size; vq->avail =3D vhost_memory_map(dev, vq->avail_phys, l, false); if (!vq->avail) { r =3D -ENOMEM; - goto fail_alloc_avail; + goto fail; } =20 l =3D vq->used_size; vq->used =3D vhost_memory_map(dev, vq->used_phys, l, true); if (!vq->used) { r =3D -ENOMEM; - goto fail_alloc_used; + goto fail; } =20 r =3D vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabl= ed); if (r < 0) { - goto fail_alloc; + goto fail; } =20 file.fd =3D event_notifier_get_fd(virtio_queue_get_host_notifier(vvq)); r =3D dev->vhost_ops->vhost_set_vring_kick(dev, &file); if (r) { VHOST_OPS_DEBUG(r, "vhost_set_vring_kick failed"); - goto fail_kick; + goto fail; } =20 /* Clear and discard previous events if any. */ @@ -1370,24 +1376,19 @@ int vhost_virtqueue_start(struct vhost_dev *dev, file.fd =3D -1; r =3D dev->vhost_ops->vhost_set_vring_call(dev, &file); if (r) { - goto fail_vector; + goto fail; } } =20 return 0; =20 -fail_vector: -fail_kick: -fail_alloc: - vhost_memory_unmap(dev, vq->used, virtio_queue_get_used_size(vdev, idx= ), +fail: + vhost_memory_unmap(dev, &vq->used, virtio_queue_get_used_size(vdev, id= x), 0, 0); -fail_alloc_used: - vhost_memory_unmap(dev, vq->avail, virtio_queue_get_avail_size(vdev, i= dx), + vhost_memory_unmap(dev, &vq->avail, virtio_queue_get_avail_size(vdev, = idx), 0, 0); -fail_alloc_avail: - vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx= ), + vhost_memory_unmap(dev, &vq->desc, virtio_queue_get_desc_size(vdev, id= x), 0, 0); -fail_alloc_desc: return r; } =20 @@ -1434,11 +1435,11 @@ static int do_vhost_virtqueue_stop(struct vhost_dev= *dev, vhost_vq_index); } =20 - vhost_memory_unmap(dev, vq->used, virtio_queue_get_used_size(vdev, idx= ), + vhost_memory_unmap(dev, &vq->used, virtio_queue_get_used_size(vdev, id= x), 1, virtio_queue_get_used_size(vdev, idx)); - vhost_memory_unmap(dev, vq->avail, virtio_queue_get_avail_size(vdev, i= dx), + vhost_memory_unmap(dev, &vq->avail, virtio_queue_get_avail_size(vdev, = idx), 0, virtio_queue_get_avail_size(vdev, idx)); - vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx= ), + vhost_memory_unmap(dev, &vq->desc, virtio_queue_get_desc_size(vdev, id= x), 0, virtio_queue_get_desc_size(vdev, idx)); return r; } --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862812; cv=none; d=zohomail.com; s=zohoarc; b=CUzA5Ybv/orwkrvLR87YBkEoXWWxpZrwBWQRmsaiT4SEHtOhQ0W0FGisQ9b1JdzOmlbjmLoGSR74tm/YB/FbceNyLTTccA0w3mBafahb6/xObZCZyEOGsBDLChepg+BtmZjPPC4c0ZA82AzlPQgZ6JjSnE+lwqJU5xG1eK286dc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862812; 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=DVN2E1fV05CJbMdBv0cpyI66en0JLWifnhyATE8IemA=; b=Q46hZnJGz2vMmCGzk5ApRTlW8SDKVurbnGQ3p4c7gEBRxVeb0qSzGNQ4JA/D8pPZanD2nsv2y83Tpiyh3HSk0fm+BkjbU42kvkCM9ZgOxwKCePxZptrV12vHohpGAnGHaOn3ZZe+tNJS24o6+73wpDshggWlETYIEi5ChOPJEkw= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862812140373.0592478573967; Tue, 26 May 2026 23:20:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Zg-00049H-KM; Wed, 27 May 2026 02:17:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZM-0003wg-IY for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:46 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZJ-00040Q-KI for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:43 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 2CC4180773; Wed, 27 May 2026 09:16:40 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-1QA2gkap; Wed, 27 May 2026 09:16:39 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862599; bh=DVN2E1fV05CJbMdBv0cpyI66en0JLWifnhyATE8IemA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=A7iMHsEkVqfYC45zlXHib4ZECklDO4L5Y/dP+r6WuIkHmZUdVczumxxRPkzTUEiUR VBCG6DDTnkoB2eaTlAWVzR/v+7IX/U2FdYDpREE6oiw/SH8nhzOsg7HkT9ZnsLVuIu Zo4uj4ytOcfhBt9yJ0zfsGFFsuzINTBMER8KqrHY= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 v7 12/22] vhost: simplify calls to vhost_memory_unmap() Date: Wed, 27 May 2026 09:16:13 +0300 Message-ID: <20260527061625.11167-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; 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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862812576158500 Content-Type: text/plain; charset="utf-8" No reason to calculate memory size again, as we have corresponding variable for each vring. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index b9b7a984e33..f43e563f0de 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1383,12 +1383,9 @@ int vhost_virtqueue_start(struct vhost_dev *dev, return 0; =20 fail: - vhost_memory_unmap(dev, &vq->used, virtio_queue_get_used_size(vdev, id= x), - 0, 0); - vhost_memory_unmap(dev, &vq->avail, virtio_queue_get_avail_size(vdev, = idx), - 0, 0); - vhost_memory_unmap(dev, &vq->desc, virtio_queue_get_desc_size(vdev, id= x), - 0, 0); + vhost_memory_unmap(dev, &vq->used, vq->used_size, 0, 0); + vhost_memory_unmap(dev, &vq->avail, vq->avail_size, 0, 0); + vhost_memory_unmap(dev, &vq->desc, vq->desc_size, 0, 0); return r; } =20 @@ -1435,12 +1432,9 @@ static int do_vhost_virtqueue_stop(struct vhost_dev = *dev, vhost_vq_index); } =20 - vhost_memory_unmap(dev, &vq->used, virtio_queue_get_used_size(vdev, id= x), - 1, virtio_queue_get_used_size(vdev, idx)); - vhost_memory_unmap(dev, &vq->avail, virtio_queue_get_avail_size(vdev, = idx), - 0, virtio_queue_get_avail_size(vdev, idx)); - vhost_memory_unmap(dev, &vq->desc, virtio_queue_get_desc_size(vdev, id= x), - 0, virtio_queue_get_desc_size(vdev, idx)); + vhost_memory_unmap(dev, &vq->used, vq->used_size, 1, vq->used_size); + vhost_memory_unmap(dev, &vq->avail, vq->avail_size, 0, vq->avail_size); + vhost_memory_unmap(dev, &vq->desc, vq->desc_size, 0, vq->desc_size); return r; } =20 --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862788; cv=none; d=zohomail.com; s=zohoarc; b=d04bIp3tC6PvpmXrc2B9kmYPcX90v12sSrF7btFkM16u/PE9DjpHkYa1XpWk0q0ie+Ke8OYbAyxvjbRz1QUMaTBVBRC7FZBeg5321tPZM9GFEMEFqAVHielepk1+2lf+Gkt3Czh296xTiU/WB1M96IkTeUPt9HgIKig7XZ2AHS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862788; 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=XocdcTcecnBxB/Sds6p3bzMTQMvxaXfbHbggfQ8XQGg=; b=J46eGl+8ju2SR+b8nT5VjYgAZZB/M2Q2aCtFOUuYwMxx9oZAUAKqfA/6b2k3edNQiTj20tPZ/pX2JCF0yqgd/oLF+YiJ3wJ33mSCKXgnxOcEcKgOhwfNJLWTyvxVrOHD8ErzeZh+Vv+mKRXQpklMVdWTa8ksTMTGM3N8izyGTfQ= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862788450223.83418290043494; Tue, 26 May 2026 23:19:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Zg-00048a-2m; Wed, 27 May 2026 02:17:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZM-0003wl-Ig for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:46 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZK-00041q-9D for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:43 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id E34EB80604; Wed, 27 May 2026 09:16:40 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-OyVLrbmF; Wed, 27 May 2026 09:16:40 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862600; bh=XocdcTcecnBxB/Sds6p3bzMTQMvxaXfbHbggfQ8XQGg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=eaGKdDrsokQlEN6a9iKATpI2Ud3xmho6Yzwbt9+J8M0OHQLrJT7zrH1VGX65KBAYw MVPLyRXPI/owlv2oZRC1m2ub66wA+rMWYIqhDIE711KG0ipZ/GsMlloLUzM2nCNu5T 5xgKRuj3Lxvum1Ueww0Qdlrg3nFjLvpPSi7EZB9M= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 v7 13/22] vhost: move vrings mapping to the top of vhost_virtqueue_start() Date: Wed, 27 May 2026 09:16:14 +0300 Message-ID: <20260527061625.11167-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862790473158500 Content-Type: text/plain; charset="utf-8" This simplifies further refactoring and final introduction of vhost backend live migration. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/virtio/vhost.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index f43e563f0de..d5bafbcc4b3 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1303,29 +1303,6 @@ int vhost_virtqueue_start(struct vhost_dev *dev, return 0; } =20 - vq->num =3D state.num =3D virtio_queue_get_num(vdev, idx); - r =3D dev->vhost_ops->vhost_set_vring_num(dev, &state); - if (r) { - VHOST_OPS_DEBUG(r, "vhost_set_vring_num failed"); - return r; - } - - state.num =3D virtio_queue_get_last_avail_idx(vdev, idx); - r =3D dev->vhost_ops->vhost_set_vring_base(dev, &state); - if (r) { - VHOST_OPS_DEBUG(r, "vhost_set_vring_base failed"); - return r; - } - - if (vhost_needs_vring_endian(vdev)) { - r =3D vhost_virtqueue_set_vring_endian_legacy(dev, - virtio_vdev_is_big_end= ian(vdev), - vhost_vq_index); - if (r) { - return r; - } - } - l =3D vq->desc_size; vq->desc =3D vhost_memory_map(dev, vq->desc_phys, l, false); if (!vq->desc) { @@ -1347,6 +1324,28 @@ int vhost_virtqueue_start(struct vhost_dev *dev, goto fail; } =20 + vq->num =3D state.num =3D virtio_queue_get_num(vdev, idx); + r =3D dev->vhost_ops->vhost_set_vring_num(dev, &state); + if (r) { + VHOST_OPS_DEBUG(r, "vhost_set_vring_num failed"); + goto fail; + } + + state.num =3D virtio_queue_get_last_avail_idx(vdev, idx); + r =3D dev->vhost_ops->vhost_set_vring_base(dev, &state); + if (r) { + VHOST_OPS_DEBUG(r, "vhost_set_vring_base failed"); + goto fail; + } + + if (vhost_needs_vring_endian(vdev)) { + r =3D vhost_virtqueue_set_vring_endian_legacy( + dev, virtio_vdev_is_big_endian(vdev), vhost_vq_index); + if (r) { + goto fail; + } + } + r =3D vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabl= ed); if (r < 0) { goto fail; --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862766; cv=none; d=zohomail.com; s=zohoarc; b=G28V01kx/P+T5xyvPRwJmOJ1Sa0FnpkawAsRZeVMsT9uhbskWqO304qMARnQMhDjsm3kaB6OWIaq016ugT5J7h/wbspN3vvfnoNZnrwCyzMBuRGMYgqkvKvV0bqZ+ugle7mCFbf0J8qYoOO5JmHzLUZ9wDPPtahAfcY6A9/BRiE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862766; 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=p7Mm9GudtPAeqe5zCfAh27owVpQGvscwVTdaF2yAkKc=; b=G59QVHa8II318dw6DdDke8UIwi4tgD9BTO4NRMlsNuaTeGh3Pb1kyWqxPsENaTqb7ZqaeapDCjacCVqJM7+XJMGb+HvR6JwjlW12UDyFv0vnSshxPX5bc/rjJh2KEJ0hKHcvP2Sc7zpmCxCl3oS+y5zngBuVW4ZMXuH7gZM66xA= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862766553346.45897010075544; Tue, 26 May 2026 23:19:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Ze-00047T-F1; Wed, 27 May 2026 02:17:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZO-0003x8-1i for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:47 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZL-000430-1A for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:44 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id A5F8880765; Wed, 27 May 2026 09:16:41 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-LXI6GsnN; Wed, 27 May 2026 09:16:41 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862601; bh=p7Mm9GudtPAeqe5zCfAh27owVpQGvscwVTdaF2yAkKc=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=buFFtxz9C3zw5t1YSwjIDEvEpUXveR6D0tZ6KjNWN8Lhku7MQBn/hHrzrby4YUa7g 8rc+nCjGxElXdGtGEqN7JT2UwWBWsh2OwpPFroQeiD5Y/WaA10aOeZ2/69MdQEIQs6 z1qHqWylI646WtWfN7vGAZ2oGssyYaKlHMRyT6TU= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 v7 14/22] vhost: vhost_virtqueue_start(): drop extra local variables Date: Wed, 27 May 2026 09:16:15 +0300 Message-ID: <20260527061625.11167-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862768409158500 Content-Type: text/plain; charset="utf-8" One letter named variables doesn't really help to read the code, and they simply duplicate structure fields. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index d5bafbcc4b3..a3bf7e5a9b8 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1277,7 +1277,6 @@ int vhost_virtqueue_start(struct vhost_dev *dev, BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); VirtioBusState *vbus =3D VIRTIO_BUS(qbus); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); - hwaddr l; int r; int vhost_vq_index =3D dev->vhost_ops->vhost_get_vq_index(dev, idx); struct vhost_vring_file file =3D { @@ -1302,23 +1301,17 @@ int vhost_virtqueue_start(struct vhost_dev *dev, /* Queue might not be ready for start */ return 0; } - - l =3D vq->desc_size; - vq->desc =3D vhost_memory_map(dev, vq->desc_phys, l, false); + vq->desc =3D vhost_memory_map(dev, vq->desc_phys, vq->desc_size, false= ); if (!vq->desc) { r =3D -ENOMEM; goto fail; } - - l =3D vq->avail_size; - vq->avail =3D vhost_memory_map(dev, vq->avail_phys, l, false); + vq->avail =3D vhost_memory_map(dev, vq->avail_phys, vq->avail_size, fa= lse); if (!vq->avail) { r =3D -ENOMEM; goto fail; } - - l =3D vq->used_size; - vq->used =3D vhost_memory_map(dev, vq->used_phys, l, true); + vq->used =3D vhost_memory_map(dev, vq->used_phys, vq->used_size, true); if (!vq->used) { r =3D -ENOMEM; goto fail; --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862707; cv=none; d=zohomail.com; s=zohoarc; b=G/FZzyS48E2w/B14ROgde6zYrSAMg68LKVTaINo8rJ6n+44obeMwpUoRjQf5FqTjMPqdc2oveSJpKdsBAGzJOpDht0ZCdS9kxYF2ZGIP25nJwwA+YmlbGyhFIta6s2Jxt6y9OpZU8k5VzwoJSphuDBLS8FQ9Edsi0SjiB4RCbKI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862707; 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=8EIeZvm1CKDsTOi9FWm63RbYAd44Mkvf/dqAC7eZxQg=; b=cyMwX76Nn/13dVY1cqWx2JbvCnCUubx0WpfZKxHTapQt7vtx/AbPwt9eT3GSDhsOwuQuILTLaS/s9tzHLvzIIA1A9BFj4HhpoHHn8s6etnQx62Z/4G9mQEVDyWQnjs4iYKdUqZdvSv6Yyh971a6n7jsFrxuLfXbfkAiW/Ak18eo= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862707841365.3842738872245; Tue, 26 May 2026 23:18:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7ZZ-00043e-Mn; Wed, 27 May 2026 02:16:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZP-0003xl-KY for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:48 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZM-000441-AF for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:47 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 6D260C01EF; Wed, 27 May 2026 09:16:42 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-a2DJtXIn; Wed, 27 May 2026 09:16:41 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862601; bh=8EIeZvm1CKDsTOi9FWm63RbYAd44Mkvf/dqAC7eZxQg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=zwiWMPxqF6rBQ7yIk9GHG5bDRkKsxf3Z239KTFM2sZiw7o3dryykiNV4K7JpP9SGO ej2sNvQIEB+UrpWK3kOpQz+Nt6tPOYkiQNPKU4OJJxR2dj1s5rpObgFlY8NdmFlRZX xVCjKoBmhdcB9GsDjVVN4xm5sdYzPQV5KF4uLmho= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 v7 15/22] vhost: final refactoring of vhost vrings map/unmap Date: Wed, 27 May 2026 09:16:16 +0300 Message-ID: <20260527061625.11167-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862710716158500 Content-Type: text/plain; charset="utf-8" Introduce helper functions vhost_vrings_map() and vhost_vrings_unmap() and use them. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 89 +++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index a3bf7e5a9b8..c71b18cfc8d 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -489,6 +489,56 @@ static void vhost_memory_unmap(struct vhost_dev *dev, = void **buffer, *buffer =3D NULL; } =20 +static void vhost_vrings_unmap(struct vhost_dev *dev, + struct vhost_virtqueue *vq, bool touched) +{ + vhost_memory_unmap(dev, &vq->used, vq->used_size, touched, + touched ? vq->used_size : 0); + vhost_memory_unmap(dev, &vq->avail, vq->avail_size, 0, + touched ? vq->avail_size : 0); + vhost_memory_unmap(dev, &vq->desc, vq->desc_size, 0, + touched ? vq->desc_size : 0); +} + +static int vhost_vrings_map(struct vhost_dev *dev, + struct VirtIODevice *vdev, + struct vhost_virtqueue *vq, + unsigned idx) +{ + vq->desc_size =3D virtio_queue_get_desc_size(vdev, idx); + vq->desc_phys =3D virtio_queue_get_desc_addr(vdev, idx); + vq->desc =3D NULL; + vq->avail_size =3D virtio_queue_get_avail_size(vdev, idx); + vq->avail_phys =3D virtio_queue_get_avail_addr(vdev, idx); + vq->avail =3D NULL; + vq->used_size =3D virtio_queue_get_used_size(vdev, idx); + vq->used_phys =3D virtio_queue_get_used_addr(vdev, idx); + vq->used =3D NULL; + + if (vq->desc_phys =3D=3D 0) { + /* Queue might not be ready for start */ + return 0; + } + vq->desc =3D vhost_memory_map(dev, vq->desc_phys, vq->desc_size, false= ); + if (!vq->desc) { + goto fail; + } + vq->avail =3D vhost_memory_map(dev, vq->avail_phys, vq->avail_size, fa= lse); + if (!vq->avail) { + goto fail; + } + vq->used =3D vhost_memory_map(dev, vq->used_phys, vq->used_size, true); + if (!vq->used) { + goto fail; + } + + return 1; + +fail: + vhost_vrings_unmap(dev, vq, false); + return -ENOMEM; +} + static int vhost_verify_ring_part_mapping(void *ring_hva, uint64_t ring_gpa, uint64_t ring_size, @@ -1287,34 +1337,9 @@ int vhost_virtqueue_start(struct vhost_dev *dev, }; struct VirtQueue *vvq =3D virtio_get_queue(vdev, idx); =20 - vq->desc_size =3D virtio_queue_get_desc_size(vdev, idx); - vq->desc_phys =3D virtio_queue_get_desc_addr(vdev, idx); - vq->desc =3D NULL; - vq->avail_size =3D virtio_queue_get_avail_size(vdev, idx); - vq->avail_phys =3D virtio_queue_get_avail_addr(vdev, idx); - vq->avail =3D NULL; - vq->used_size =3D virtio_queue_get_used_size(vdev, idx); - vq->used_phys =3D virtio_queue_get_used_addr(vdev, idx); - vq->used =3D NULL; - - if (vq->desc_phys =3D=3D 0) { - /* Queue might not be ready for start */ - return 0; - } - vq->desc =3D vhost_memory_map(dev, vq->desc_phys, vq->desc_size, false= ); - if (!vq->desc) { - r =3D -ENOMEM; - goto fail; - } - vq->avail =3D vhost_memory_map(dev, vq->avail_phys, vq->avail_size, fa= lse); - if (!vq->avail) { - r =3D -ENOMEM; - goto fail; - } - vq->used =3D vhost_memory_map(dev, vq->used_phys, vq->used_size, true); - if (!vq->used) { - r =3D -ENOMEM; - goto fail; + r =3D vhost_vrings_map(dev, vdev, vq, idx); + if (r <=3D 0) { + return r; } =20 vq->num =3D state.num =3D virtio_queue_get_num(vdev, idx); @@ -1375,9 +1400,7 @@ int vhost_virtqueue_start(struct vhost_dev *dev, return 0; =20 fail: - vhost_memory_unmap(dev, &vq->used, vq->used_size, 0, 0); - vhost_memory_unmap(dev, &vq->avail, vq->avail_size, 0, 0); - vhost_memory_unmap(dev, &vq->desc, vq->desc_size, 0, 0); + vhost_vrings_unmap(dev, vq, false); return r; } =20 @@ -1424,9 +1447,7 @@ static int do_vhost_virtqueue_stop(struct vhost_dev *= dev, vhost_vq_index); } =20 - vhost_memory_unmap(dev, &vq->used, vq->used_size, 1, vq->used_size); - vhost_memory_unmap(dev, &vq->avail, vq->avail_size, 0, vq->avail_size); - vhost_memory_unmap(dev, &vq->desc, vq->desc_size, 0, vq->desc_size); + vhost_vrings_unmap(dev, vq, true); return r; } =20 --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862731; cv=none; d=zohomail.com; s=zohoarc; b=VZjRTRl9bpYqYur7JEG7RhrAkgORctc9DIUdmud9AymcemIhSdTB0v7dnDbsp8iczs6BGehEqi+/bch17V+qLpphab9CJY8re/nCZ5+ullNo8PN7ZzEcO0TILllT8+exsJkILkPOXUIg325QfAv5aU3U4etG+zh5OR+epTktW4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862731; 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=LWaZ2xUEjmtd/ow6Imr4cQ0Z/NL5RAS13aeCcPFAeGQ=; b=mVtqR+HP0jagi0fDrnVQInURaX1/igPLYXaT1luSobfpMfawLD8CXDgzpR3p6wII16GoYKLfrrWrrnw/X5A0dqr/6Alwj7XMlt+cgYS9RaCnhDA3amNwkfZ4/rDaVw7gK2NwoEZHqIta2KSDPhwVulBo+/t+i4b4fCIypAOmv5E= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862731471455.0429552357051; Tue, 26 May 2026 23:18:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Zo-0004Eo-8f; Wed, 27 May 2026 02:17:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZS-000401-6D for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:50 -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 1wS7ZN-000472-PI for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:48 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 25D9BC01A6; Wed, 27 May 2026 09:16:43 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-RRPqbTcS; Wed, 27 May 2026 09:16:42 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862602; bh=LWaZ2xUEjmtd/ow6Imr4cQ0Z/NL5RAS13aeCcPFAeGQ=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=y5QP+uhuGaTSvKFO/KwuQYLx0rtqrPeRnlybyROVY3trdbYQwdbYAA9BKFumu4KIl /2ZwU6HF5LLB7q+b61Bw9OCFQ7KdmdEOONIeONbW8haY6qaKsGZK/pmACmNVGrl9UP GbZOvmVEAKUmhlqxhCrsICwrKrI8mxNy6+BS48Vg= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 v7 16/22] vhost: simplify vhost_dev_init() error-path Date: Wed, 27 May 2026 09:16:17 +0300 Message-ID: <20260527061625.11167-17-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.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: qemu development 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: 1779862734250158500 Content-Type: text/plain; charset="utf-8" No reason to rollback setting up busyloop timeout on failure. We don't do such rollback for other things we setup in backend. Also, look at vhost_net_init() in hw/net/vhost_net.c: we may fail after successfully called vhost_dev_init(), and in this case we'll just call vhost_dev_cleanup(), which doesn't rollback busyloop timeout. So, let's keep it simple. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/virtio/vhost.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index c71b18cfc8d..7f370f393e9 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1624,7 +1624,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, busyloop_timeout); if (r < 0) { error_setg_errno(errp, -r, "Failed to set busyloop timeout= "); - goto fail_busyloop; + goto fail; } } } @@ -1664,7 +1664,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, if (hdev->migration_blocker !=3D NULL) { r =3D migrate_add_blocker_normal(&hdev->migration_blocker, errp); if (r < 0) { - goto fail_busyloop; + goto fail; } } =20 @@ -1696,17 +1696,11 @@ int vhost_dev_init(struct vhost_dev *hdev, void *op= aque, " than current number of used (%d) and reserved (%d)" " memory slots for memory devices.", limit, used, reser= ved); r =3D -EINVAL; - goto fail_busyloop; + goto fail; } =20 return 0; =20 -fail_busyloop: - if (busyloop_timeout) { - while (--i >=3D 0) { - vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i,= 0); - } - } fail: hdev->nvqs =3D n_initialized_vqs; vhost_dev_cleanup(hdev); --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862747; cv=none; d=zohomail.com; s=zohoarc; b=gnRNOQyHuuxv4RfqXLYgQpZjE31be0N4Bcdd7FOUPbt2hI3pdf3KehROylLr+9hSqb34T3PSvM5xxCtV9wNRkJCsb1U9YAPc/O0YFQQouIZsG4ZMVZCq0kCt0z89KssVEQvrQSTuXE5WHHHoMA21/1H7z2OYDWDHSkjitBxmEi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862747; 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=9H42VfdWXv4YR9fUBy+45ZxRHJLalt72HE6C4geWja4=; b=WZNci/dnqD5T5FwlOkksbQfdfnre+RwCE09WZfQAXR2jQkXQfOx73dNnofo9bwRjCJH1/Gtg9taELJZkUyK+oydCOGUGRMwjohyy2DVIr9FYCABXVOGn+TmNmvrtoxsFr+4zDxtC23z7f08fkNeYRcbd++l2IOF97D19Hp76T8E= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862747648950.7377526732731; Tue, 26 May 2026 23:19:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Zl-0004Da-OZ; Wed, 27 May 2026 02:17:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZS-000400-5z for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:50 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZN-00048J-PR for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:48 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id CD96880661; Wed, 27 May 2026 09:16:43 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-NKKMs96A; Wed, 27 May 2026 09:16:43 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862603; bh=9H42VfdWXv4YR9fUBy+45ZxRHJLalt72HE6C4geWja4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=1Fzh4u4PtRCtaRFWGTikZD5sG/JJUg6oFhbkOKBZKfDSJnvqVgKL3vzY9dWUnNPtq PVLSQfNpl8rDlPlzwN5Df5yzSyApSieAx78dXBaYzaRpk88tCl8oDwlkwzJwRvnzDy VP7wGR/333myZktNIU0br8JvUoCoD88/YtqwoPqk= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 v7 17/22] vhost: move busyloop timeout initialization to vhost_virtqueue_init() Date: Wed, 27 May 2026 09:16:18 +0300 Message-ID: <20260527061625.11167-18-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862748283158500 Content-Type: text/plain; charset="utf-8" Let's all per-virtqueue initializations be in one place. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/virtio/vhost.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 7f370f393e9..55ce7ae977f 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1496,7 +1496,8 @@ static void vhost_virtqueue_error_notifier(EventNotif= ier *n) } =20 static int vhost_virtqueue_init(struct vhost_dev *dev, - struct vhost_virtqueue *vq, int n) + struct vhost_virtqueue *vq, int n, + bool busyloop_timeout) { int vhost_vq_index =3D dev->vhost_ops->vhost_get_vq_index(dev, n); struct vhost_vring_file file =3D { @@ -1533,6 +1534,14 @@ static int vhost_virtqueue_init(struct vhost_dev *de= v, vhost_virtqueue_error_notifier); } =20 + if (busyloop_timeout) { + r =3D vhost_virtqueue_set_busyloop_timeout(dev, n, busyloop_timeou= t); + if (r < 0) { + VHOST_OPS_DEBUG(r, "Failed to set busyloop timeout"); + goto fail_err; + } + } + return 0; =20 fail_err: @@ -1611,24 +1620,14 @@ int vhost_dev_init(struct vhost_dev *hdev, void *op= aque, } =20 for (i =3D 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { - r =3D vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i= ); + r =3D vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i, + busyloop_timeout); if (r < 0) { error_setg_errno(errp, -r, "Failed to initialize virtqueue %d"= , i); goto fail; } } =20 - if (busyloop_timeout) { - for (i =3D 0; i < hdev->nvqs; ++i) { - r =3D vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_inde= x + i, - busyloop_timeout); - if (r < 0) { - error_setg_errno(errp, -r, "Failed to set busyloop timeout= "); - goto fail; - } - } - } - virtio_features_copy(hdev->_features_ex, features); =20 hdev->memory_listener =3D (MemoryListener) { --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862798; cv=none; d=zohomail.com; s=zohoarc; b=jlHEPb/VxovhJqvY2bruCKY2Tmo5pGjXuVFeC6SbRylvuw0x5hs3YFWbv9Qq0KaOJ6z0MAHhkN7KqJmcvQWp8BXgVX0lsjZbs29u4lVOAJWmdpiZo5FOVnV8AUxCz2LwwI7FqnkyqAcaapnbOR2qbNpkNqbhPekShQebqLYlZvk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862798; 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=vyElk3FXLNKWSELumKfi8IPDAq8aQq0zwO2Sd49gLCs=; b=ACzPQe21abu5AjSUjYdCyU8GaC7kFsL9otpGGhJTiHvJYzRSbD8cBPWZ9lhYc+baP1exWke7N/mQ9lBX2jzXClqdrZRrpFk4rOH0ZoKPm9TlJRGN/cQqGkz7xSSnRwRIKR1Fclr83byeOC186r3t7j643qWitAevbC2YbDtoZ5s= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862798883614.5877581565699; Tue, 26 May 2026 23:19:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Zf-00047h-2L; Wed, 27 May 2026 02:17:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZS-000403-6s for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:51 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900: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 1wS7ZN-00049D-T0 for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:49 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 84DBD80604; Wed, 27 May 2026 09:16:44 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-GUOagDyy; Wed, 27 May 2026 09:16:43 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862604; bh=vyElk3FXLNKWSELumKfi8IPDAq8aQq0zwO2Sd49gLCs=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=L1/MVGxLAusx91VHG0s3HpIt3lNNnz1fwtB+apHiRTNuQZ7n19lxBXt8841wjdMSx Q96DMLaprYuBecvD+I+AlEDpHk9F4cHY6U3ScLfbIRuRNHogrYI6xkw6VRxgro0Vys KYnaV82Tk3Y7FLG0lEdPOYBZ+BruU7tcXPYyy8so= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 v7 18/22] vhost: vhost_dev_init(): simplify features initialization Date: Wed, 27 May 2026 09:16:19 +0300 Message-ID: <20260527061625.11167-19-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862800554158500 Content-Type: text/plain; charset="utf-8" Drop extra variable and extra function parameter passing, initialize dev._features directly. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 55ce7ae977f..93c6a5f5e9a 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1560,18 +1560,17 @@ static void vhost_virtqueue_cleanup(struct vhost_vi= rtqueue *vq) } } =20 -static int vhost_dev_get_features(struct vhost_dev *hdev, - uint64_t *features) +static int vhost_dev_init_features(struct vhost_dev *hdev) { uint64_t features64; int r; =20 if (hdev->vhost_ops->vhost_get_features_ex) { - return hdev->vhost_ops->vhost_get_features_ex(hdev, features); + return hdev->vhost_ops->vhost_get_features_ex(hdev, hdev->_feature= s_ex); } =20 r =3D hdev->vhost_ops->vhost_get_features(hdev, &features64); - virtio_features_from_u64(features, features64); + virtio_features_from_u64(hdev->_features_ex, features64); return r; } =20 @@ -1579,7 +1578,6 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, VhostBackendType backend_type, uint32_t busyloop_timeou= t, Error **errp) { - uint64_t features[VIRTIO_FEATURES_NU64S]; unsigned int used, reserved, limit; int i, r, n_initialized_vqs =3D 0; =20 @@ -1600,9 +1598,9 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, goto fail; } =20 - r =3D vhost_dev_get_features(hdev, features); + r =3D vhost_dev_init_features(hdev); if (r < 0) { - error_setg_errno(errp, -r, "vhost_get_features failed"); + error_setg_errno(errp, -r, "vhost_init_features failed"); goto fail; } =20 @@ -1628,8 +1626,6 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, } } =20 - virtio_features_copy(hdev->_features_ex, features); - hdev->memory_listener =3D (MemoryListener) { .name =3D "vhost", .begin =3D vhost_begin, --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862777; cv=none; d=zohomail.com; s=zohoarc; b=Z/HRV/b4mKc4C5zXi8ND4v2TPHzryJAiKoPYF8lceeKWJCrfgovvxSjX8jGm07TTCd0x/hTKMMXSAyBGFsXJ+vW3jT+YJTC/3/sRt9lJzPrUr/a4zNp1DPSSEGitFfdiz5FiNGWHiIkNTmJJf19jNzEdFyfsc7azeCJBLhW29YA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862777; h=Content-Type: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=Cy9Kfz7LJW3sOr7QWA68FHIr1PIHJhZFd5ELVkaKPk4=; b=UCBI531nG202uPBJwNJEGQVOn6g3hiiL6TC7YicLeL97oIIR69sBUBwvydQM4fsg0zWEbXu48rsoeZc7dZbLesl/pUFI/Kr6v5RrQUQ9194EEYbmfEMTjjmgZSa0zAsxP4FvsIxNl3Uddfng7je5gWbIC2U0FCjcK6ValItTkPE= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862777912706.5262222624392; Tue, 26 May 2026 23:19:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Zf-00048G-TP; Wed, 27 May 2026 02:17:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZS-000402-6K for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:50 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900: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 1wS7ZO-0004AL-In for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:49 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 4C7AB8079E; Wed, 27 May 2026 09:16:45 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-8s5ShDpq; Wed, 27 May 2026 09:16:44 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862604; bh=Cy9Kfz7LJW3sOr7QWA68FHIr1PIHJhZFd5ELVkaKPk4=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=gmcTzbF6UIeQw4sEOcPvApPUjYqk9tuS4+5Kz18a9Bg0aqxCzjGAE8fZLMwZNl9SH 219YDiLzvMuOuCdHDgBr25dqrmokp+jrVmeUtwdVNlcbE1gIHwNKwsujolbjPHsVoL 5M9JD6EhLOi3G9jDyKqRZQYwM79P7Q77XyDXedxI= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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?Philippe=20Mathieu-Daud=C3=A9?= , Raphael Norwitz Subject: [PATCH v7 19/22] hw/virtio/virtio-bus: refactor virtio_bus_set_host_notifier() Date: Wed, 27 May 2026 09:16:20 +0300 Message-ID: <20260527061625.11167-20-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862780453158500 The logic kept as is. Refactor to simplify further changes. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/virtio/virtio-bus.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index cef944e0158..9b545acda31 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -298,20 +298,18 @@ int virtio_bus_set_host_notifier(VirtioBusState *bus,= int n, bool assign) __func__, strerror(-r), r); return r; } - r =3D k->ioeventfd_assign(proxy, notifier, n, true); - if (r < 0) { - error_report("%s: unable to assign ioeventfd: %d", __func__, r= ); - virtio_bus_cleanup_host_notifier(bus, n); - } - } else { - k->ioeventfd_assign(proxy, notifier, n, false); } =20 - if (r =3D=3D 0) { - virtio_queue_set_host_notifier_enabled(vq, assign); + r =3D k->ioeventfd_assign(proxy, notifier, n, assign); + if (r < 0 && assign) { + error_report("%s: unable to assign ioeventfd: %d", __func__, r); + virtio_bus_cleanup_host_notifier(bus, n); + return r; } =20 - return r; + virtio_queue_set_host_notifier_enabled(vq, assign); + + return 0; } =20 void virtio_bus_cleanup_host_notifier(VirtioBusState *bus, int n) --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862786; cv=none; d=zohomail.com; s=zohoarc; b=BuJkTxHCSin2Kg0d6oxSMyY83YkQYa0e6aiofZg376WNC4wNizBNdx+fYbO5AuB8SvMuGrz/0Ng7cVCbboWPheiV12aOud+cEWtUkQEhn9sanIp0ge4UOgL+Bk6h+7jX2AfofCQrpD7LY8jsgL7sLYjdDQ8Qas6F13pLPFLYjSE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862786; 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=dU9wUhXlCE3BAJRpC9u2OYkNwoLoZDEIRrhVKwfUBGc=; b=P9hdgLiQpXf35exppt8upfi/bwoVtCFjV5ouT2Iub/KKyItO5qSmlYqIF0jky7GGnn7ZajM5HatyafVWrtSch31+paXed2emMaqe2hQhgUkh0BFlF0xzCUQorQuNQBVka9QgOR+cNz9vPChFcDhXN0bj+2IBh6f8nosSxmCbCnY= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862786507503.4482751534724; Tue, 26 May 2026 23:19:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Zo-0004Ep-8l; Wed, 27 May 2026 02:17:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZW-00042X-F5 for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:55 -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 1wS7ZP-0004Ay-Tf for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:51 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 21F1BC01F0; Wed, 27 May 2026 09:16:46 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-QsKZ4p08; Wed, 27 May 2026 09:16:45 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862605; bh=dU9wUhXlCE3BAJRpC9u2OYkNwoLoZDEIRrhVKwfUBGc=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=B1vuMp75BPo2ZdEt2LJHHKqfbFO1jtHdNjY8g+HGJQQvRi94Qs2YK/HKA35m8RYNR yLd7IECKYtUsLqlSxungw08TEslQ94zktQmNDik7cNpAIBDnzIckd7bmcqyoTlvsUv F2Zm5SVXW64cRdBFUMsm4tcTXDKksk+qIPmwqJvA= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 v7 20/22] vhost-user: make trace events more readable Date: Wed, 27 May 2026 09:16:21 +0300 Message-ID: <20260527061625.11167-21-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.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: qemu development 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: 1779862788580158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz --- hw/virtio/trace-events | 4 +-- hw/virtio/vhost-user.c | 63 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 658cc365e70..aa1ffa5e949 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -25,8 +25,8 @@ vhost_user_set_mem_table_withfd(int index, const char *na= me, uint64_t memory_siz vhost_user_postcopy_waker(const char *rb, uint64_t rb_offset) "%s + 0x%"PR= Ix64 vhost_user_postcopy_waker_found(uint64_t client_addr) "0x%"PRIx64 vhost_user_postcopy_waker_nomatch(const char *rb, uint64_t rb_offset) "%s = + 0x%"PRIx64 -vhost_user_read(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32"" -vhost_user_write(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32"" +vhost_user_read(uint32_t req, const char *req_name, uint32_t flags) "req:%= d (%s) flags:0x%"PRIx32"" +vhost_user_write(uint32_t req, const char *req_name, uint32_t flags) "req:= %d (%s) flags:0x%"PRIx32"" vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" =20 # vhost-vdpa.c diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 31eaf65430e..4fb136b7b37 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -114,6 +114,63 @@ typedef enum VhostUserBackendRequest { VHOST_USER_BACKEND_MAX } VhostUserBackendRequest; =20 +#define VHOST_USER_CASE(name) \ + case VHOST_USER_##name: \ + return #name; + +static const char *vhost_req_name(VhostUserRequest req) +{ + switch (req) { + VHOST_USER_CASE(NONE) + VHOST_USER_CASE(GET_FEATURES) + VHOST_USER_CASE(SET_FEATURES) + VHOST_USER_CASE(SET_OWNER) + VHOST_USER_CASE(RESET_OWNER) + VHOST_USER_CASE(SET_MEM_TABLE) + VHOST_USER_CASE(SET_LOG_BASE) + VHOST_USER_CASE(SET_LOG_FD) + VHOST_USER_CASE(SET_VRING_NUM) + VHOST_USER_CASE(SET_VRING_ADDR) + VHOST_USER_CASE(SET_VRING_BASE) + VHOST_USER_CASE(GET_VRING_BASE) + VHOST_USER_CASE(SET_VRING_KICK) + VHOST_USER_CASE(SET_VRING_CALL) + VHOST_USER_CASE(SET_VRING_ERR) + VHOST_USER_CASE(GET_PROTOCOL_FEATURES) + VHOST_USER_CASE(SET_PROTOCOL_FEATURES) + VHOST_USER_CASE(GET_QUEUE_NUM) + VHOST_USER_CASE(SET_VRING_ENABLE) + VHOST_USER_CASE(SEND_RARP) + VHOST_USER_CASE(NET_SET_MTU) + VHOST_USER_CASE(SET_BACKEND_REQ_FD) + VHOST_USER_CASE(IOTLB_MSG) + VHOST_USER_CASE(SET_VRING_ENDIAN) + VHOST_USER_CASE(GET_CONFIG) + VHOST_USER_CASE(SET_CONFIG) + VHOST_USER_CASE(CREATE_CRYPTO_SESSION) + VHOST_USER_CASE(CLOSE_CRYPTO_SESSION) + VHOST_USER_CASE(POSTCOPY_ADVISE) + VHOST_USER_CASE(POSTCOPY_LISTEN) + VHOST_USER_CASE(POSTCOPY_END) + VHOST_USER_CASE(GET_INFLIGHT_FD) + VHOST_USER_CASE(SET_INFLIGHT_FD) + VHOST_USER_CASE(GPU_SET_SOCKET) + VHOST_USER_CASE(RESET_DEVICE) + VHOST_USER_CASE(GET_MAX_MEM_SLOTS) + VHOST_USER_CASE(ADD_MEM_REG) + VHOST_USER_CASE(REM_MEM_REG) + VHOST_USER_CASE(SET_STATUS) + VHOST_USER_CASE(GET_STATUS) + VHOST_USER_CASE(GET_SHARED_OBJECT) + VHOST_USER_CASE(SET_DEVICE_STATE_FD) + VHOST_USER_CASE(CHECK_DEVICE_STATE) + default: + return ""; + } +} + +#undef VHOST_USER_CASE + typedef struct VhostUserMemoryRegion { uint64_t guest_phys_addr; uint64_t memory_size; @@ -308,7 +365,8 @@ static int vhost_user_read_header(struct vhost_dev *dev= , VhostUserMsg *msg) return -EPROTO; } =20 - trace_vhost_user_read(msg->hdr.request, msg->hdr.flags); + trace_vhost_user_read(msg->hdr.request, + vhost_req_name(msg->hdr.request), msg->hdr.flags= ); =20 return 0; } @@ -428,7 +486,8 @@ static int vhost_user_write(struct vhost_dev *dev, Vhos= tUserMsg *msg, return ret < 0 ? -saved_errno : -EIO; } =20 - trace_vhost_user_write(msg->hdr.request, msg->hdr.flags); + trace_vhost_user_write(msg->hdr.request, vhost_req_name(msg->hdr.reque= st), + msg->hdr.flags); =20 return 0; } --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862734; cv=none; d=zohomail.com; s=zohoarc; b=cZqAjM+HTIUgBPlep3xRoN3g+s0tTdhHOCmJr1A4jcpyNlfjz6PKqrEBLRE6npGrACU9dpfk1rtC8+S2KX5Ew+K24Jlwq/qqwyioIn0HtPqGCXiAGv9J9rYRjpOPJnFDCNZcSxzH/SKK7ZIytE/enrfUKvRdVFkmH3KWEoqo4dU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862734; 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=QRCDo8FBCZVffKxPT5McAWTtvtWm+UKlIvG2NlKOFHw=; b=hTjtpQt+T2RW1urrrq10AkOzSP1LFydGOPWj09sQA3BFvt8MsRcfj/hzSb4MpEABxEIzdzUayah2t6e0sgeJ+QV+4YF0cgBOIw+zX487uudq8tuHXVaqkvkE8rGFTE9qjww4QNSzPC9qltkMROzZ5ebD4X3hSFiS2VXOLhirzsQ= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862734770191.7383765397875; Tue, 26 May 2026 23:18:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Ze-00047a-OT; Wed, 27 May 2026 02:17:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZX-00042v-Pn; Wed, 27 May 2026 02:16:55 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300: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 1wS7ZS-0004BQ-1i; Wed, 27 May 2026 02:16:52 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id EDFBB80773; Wed, 27 May 2026 09:16:46 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-1IEMv1bz; Wed, 27 May 2026 09:16:46 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862606; bh=QRCDo8FBCZVffKxPT5McAWTtvtWm+UKlIvG2NlKOFHw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=y0Y2E8ClWWMCYKDq2JtdCbynfvuqoGv28P4a58yGwfuSpHoHfgYEWOnAnU963XpdW xZcL3NX8Q1ZeB+q/E2L2xjDIPTYw4ObPIH8r0LTim75TaXWAblCtl1PIHtV2KxWqWd YYkA8iZ8wzXIvvbZ3yTt44STH/dAMg7mVGcpMbfk= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 , Kevin Wolf , Hanna Reitz , Raphael Norwitz , qemu-block@nongnu.org (open list:Block layer core) Subject: [PATCH v7 21/22] vhost-user-blk: add some useful trace-points Date: Wed, 27 May 2026 09:16:22 +0300 Message-ID: <20260527061625.11167-22-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; 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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862738231158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/block/trace-events | 10 ++++++++++ hw/block/vhost-user-blk.c | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/hw/block/trace-events b/hw/block/trace-events index cc9a9f24603..dbaa5ca6cb2 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -58,6 +58,16 @@ virtio_blk_handle_zone_mgmt(void *vdev, void *req, uint8= _t op, int64_t sector, i virtio_blk_handle_zone_reset_all(void *vdev, void *req, int64_t sector, in= t64_t len) "vdev %p req %p sector 0x%" PRIx64 " cap 0x%" PRIx64 "" virtio_blk_handle_zone_append(void *vdev, void *req, int64_t sector) "vdev= %p req %p, append sector 0x%" PRIx64 "" =20 +# vhost-user-blk.c +vhost_user_blk_start_in(void *vdev) "vdev %p" +vhost_user_blk_start_out(void *vdev) "vdev %p" +vhost_user_blk_stop_in(void *vdev) "vdev %p" +vhost_user_blk_stop_out(void *vdev) "vdev %p" +vhost_user_blk_connect_in(void *vdev) "vdev %p" +vhost_user_blk_connect_out(void *vdev) "vdev %p" +vhost_user_blk_device_realize_in(void *vdev) "vdev %p" +vhost_user_blk_device_realize_out(void *vdev) "vdev %p" + # hd-geometry.c hd_geometry_lchs_guess(void *blk, int cyls, int heads, int secs) "blk %p L= CHS %d %d %d" hd_geometry_guess(void *blk, uint32_t cyls, uint32_t heads, uint32_t secs,= int trans) "blk %p CHS %u %u %u trans %d" diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 2831f3c0530..530f44ab520 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -31,6 +31,7 @@ #include "hw/virtio/virtio-access.h" #include "system/system.h" #include "system/runstate.h" +#include "trace.h" =20 static const int user_feature_bits[] =3D { VIRTIO_BLK_F_SIZE_MAX, @@ -137,6 +138,8 @@ static int vhost_user_blk_start(VirtIODevice *vdev, Err= or **errp) VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); int i, ret; =20 + trace_vhost_user_blk_start_in(vdev); + if (!k->set_guest_notifiers) { error_setg(errp, "binding does not support guest notifiers"); return -ENOSYS; @@ -192,6 +195,8 @@ static int vhost_user_blk_start(VirtIODevice *vdev, Err= or **errp) } s->started_vu =3D true; =20 + trace_vhost_user_blk_start_out(vdev); + return ret; =20 err_guest_notifiers: @@ -212,6 +217,8 @@ static int vhost_user_blk_stop(VirtIODevice *vdev) int ret; bool force_stop =3D false; =20 + trace_vhost_user_blk_stop_in(vdev); + if (!s->started_vu) { return 0; } @@ -233,6 +240,9 @@ static int vhost_user_blk_stop(VirtIODevice *vdev) } =20 vhost_dev_disable_notifiers(&s->dev, vdev); + + trace_vhost_user_blk_stop_out(vdev); + return ret; } =20 @@ -340,6 +350,8 @@ static int vhost_user_blk_connect(DeviceState *dev, Err= or **errp) VHostUserBlk *s =3D VHOST_USER_BLK(vdev); int ret =3D 0; =20 + trace_vhost_user_blk_connect_in(vdev); + if (s->connected) { return 0; } @@ -366,6 +378,8 @@ static int vhost_user_blk_connect(DeviceState *dev, Err= or **errp) ret =3D vhost_user_blk_start(vdev, errp); } =20 + trace_vhost_user_blk_connect_out(vdev); + return ret; } =20 @@ -456,6 +470,8 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) int retries; int i, ret; =20 + trace_vhost_user_blk_device_realize_in(vdev); + if (!s->chardev.chr) { error_setg(errp, "chardev is mandatory"); return; @@ -515,6 +531,9 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, vhost_user_blk_event, NULL, (void *)dev, NULL, true); + + trace_vhost_user_blk_device_realize_out(vdev); + return; =20 virtio_err: --=20 2.52.0 From nobody Sat May 30 17:45:58 2026 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=1779862727; cv=none; d=zohomail.com; s=zohoarc; b=bmxz9p9zMJ/+IaIJ7WJXugsaZ4BrcFLy+G84aADsBInZE3SaegM7Fmd++sXuWOxrDsgcQoZdn4MBJycgbQC+ranxByTydC034HcJ+kwXOFdD5qzyxaRB6jhKB2dLOVNbpScz3ikLCvNg/Eljy40rjG4JztOUfF2jefA/shg0c3Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779862727; 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=cHNUGQYHpBInLb95ZLOID6Q1Am1IdFzgTlHbpH702Ng=; b=LqpyK5ON1Xj7jOMgbhK5aMkBrdA1BMS797kN9tEMHnDxrOyCiVyJ82yjcrwrFLDQNFA02psH2gg5CV5Wz+kk2pVCbpQDLNFefRLLtSyX15hsLlbwL+6pCp5glj+PF2LOWiG6D/fA1EFteaLtZXUKpYtZ9UJTYtR52QSaTqH5BOk= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779862726858229.12203947875037; Tue, 26 May 2026 23:18:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wS7Zh-0004Az-OW; Wed, 27 May 2026 02:17:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZW-00042b-Lt for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:55 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wS7ZR-0004Ed-Ka for qemu-devel@nongnu.org; Wed, 27 May 2026 02:16:51 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2925:0:640:1f39:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id BEAE380765; Wed, 27 May 2026 09:16:47 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:69::1:d]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp) with ESMTPSA id QGSCNG0ZtGk0-eN3Skkiq; Wed, 27 May 2026 09:16:47 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1779862607; bh=cHNUGQYHpBInLb95ZLOID6Q1Am1IdFzgTlHbpH702Ng=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=upEw5rfwWv+/CDsdBP93AwYQUj4ovxUsaMUu0xJb5NWHZyUwkEWIxnyqi5zTI3HSt SgAZuJDiRXYFGF385eAsYk6EiYATagnbO/ZetS2PsufNJgaL9vbvkGeYs3BHsG5W50 aaB4wCX7e9JcEEPPaGi0lXAk6HKZGhARjT1M5bBo= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 v7 22/22] vhost: add some useful trace-points Date: Wed, 27 May 2026 09:16:23 +0300 Message-ID: <20260527061625.11167-23-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527061625.11167-1-vsementsov@yandex-team.ru> References: <20260527061625.11167-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=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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: 1779862728441158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/virtio/trace-events | 12 ++++++++++-- hw/virtio/vhost.c | 20 ++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index aa1ffa5e949..2a57edc21e3 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -9,8 +9,16 @@ vhost_section(const char *name) "%s" vhost_reject_section(const char *name, int d) "%s:%d" vhost_iotlb_miss(void *dev, int step) "%p step %d" vhost_dev_cleanup(void *dev) "%p" -vhost_dev_start(void *dev, const char *name, bool vrings) "%p:%s vrings:%d" -vhost_dev_stop(void *dev, const char *name, bool vrings) "%p:%s vrings:%d" +vhost_dev_start_in(void *dev, const char *name, bool vrings) "%p:%s vrings= :%d" +vhost_dev_start_out(void *dev, const char *name) "%p:%s" +vhost_dev_stop_in(void *dev, const char *name, bool vrings) "%p:%s vrings:= %d" +vhost_dev_stop_out(void *dev, const char *name) "%p:%s" +vhost_virtqueue_start_in(void *dev, const char *name, int idx) "%p:%s %d" +vhost_virtqueue_start_out(void *dev, const char *name, int idx) "%p:%s %d" +vhost_virtqueue_stop_in(void *dev, const char *name, int idx) "%p:%s %d" +vhost_virtqueue_stop_out(void *dev, const char *name, int idx) "%p:%s %d" +vhost_dev_init_in(void *dev) "%p" +vhost_dev_init_out(void *dev) "%p" =20 =20 # vhost-user.c diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 93c6a5f5e9a..c610007e812 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1337,6 +1337,8 @@ int vhost_virtqueue_start(struct vhost_dev *dev, }; struct VirtQueue *vvq =3D virtio_get_queue(vdev, idx); =20 + trace_vhost_virtqueue_start_in(dev, vdev->name, idx); + r =3D vhost_vrings_map(dev, vdev, vq, idx); if (r <=3D 0) { return r; @@ -1397,6 +1399,8 @@ int vhost_virtqueue_start(struct vhost_dev *dev, } } =20 + trace_vhost_virtqueue_start_out(dev, vdev->name, idx); + return 0; =20 fail: @@ -1415,6 +1419,8 @@ static int do_vhost_virtqueue_stop(struct vhost_dev *= dev, }; int r =3D 0; =20 + trace_vhost_virtqueue_stop_in(dev, vdev->name, idx); + if (virtio_queue_get_desc_addr(vdev, idx) =3D=3D 0) { /* Don't stop the virtqueue which might have not been started */ return 0; @@ -1448,6 +1454,8 @@ static int do_vhost_virtqueue_stop(struct vhost_dev *= dev, } =20 vhost_vrings_unmap(dev, vq, true); + + trace_vhost_virtqueue_stop_out(dev, vdev->name, idx); return r; } =20 @@ -1581,6 +1589,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, unsigned int used, reserved, limit; int i, r, n_initialized_vqs =3D 0; =20 + trace_vhost_dev_init_in(hdev); + hdev->vdev =3D NULL; hdev->migration_blocker =3D NULL; =20 @@ -1694,6 +1704,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, goto fail; } =20 + trace_vhost_dev_init_out(hdev); + return 0; =20 fail: @@ -2098,7 +2110,7 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODev= ice *vdev, bool vrings) /* should only be called after backend is connected */ assert(hdev->vhost_ops); =20 - trace_vhost_dev_start(hdev, vdev->name, vrings); + trace_vhost_dev_start_in(hdev, vdev->name, vrings); =20 vdev->vhost_started =3D true; hdev->started =3D true; @@ -2183,6 +2195,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODev= ice *vdev, bool vrings) } } vhost_start_config_intr(hdev); + + trace_vhost_dev_start_out(hdev, vdev->name); return 0; fail_iotlb: if (vhost_dev_has_iommu(hdev) && @@ -2232,7 +2246,7 @@ static int do_vhost_dev_stop(struct vhost_dev *hdev, = VirtIODevice *vdev, event_notifier_cleanup( &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier); =20 - trace_vhost_dev_stop(hdev, vdev->name, vrings); + trace_vhost_dev_stop_in(hdev, vdev->name, vrings); =20 if (hdev->vhost_ops->vhost_dev_start) { hdev->vhost_ops->vhost_dev_start(hdev, false); @@ -2262,6 +2276,8 @@ static int do_vhost_dev_stop(struct vhost_dev *hdev, = VirtIODevice *vdev, hdev->started =3D false; vdev->vhost_started =3D false; hdev->vdev =3D NULL; + + trace_vhost_dev_stop_out(hdev, vdev->name); return rc; } =20 --=20 2.52.0