From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540596; cv=none; d=zohomail.com; s=zohoarc; b=IN8s3Nd9770xD8A/Na+O44onzJF6GxCx9bvhZK0AKbBQ/AxJ6tF2fzynEN/IKL2zVN5xEGYrDtS5kt1jXO1j/CcmT+nmL4pJk2AtIeZHA6lCDUIvfpYOCaeNhwzVoRk/CANFMrocFxkCzGxzCV6sckH0ZFfHLrk/K65Pbuxx45g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540596; 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=Cc4fro7LMqaYMZ5I3F9f9KBUdUTKDXhLsBEoX+i+vMw=; b=FMxT5wUwJD1JDW3SWEQ5TwRy4BIXtyzIoBHWwwEEM04Iy7Jx9x7lKRpCFZ56UviX5dH7e2NmlK0zqKaKBq2d+Kw2yFNrhdIvB90thQR1pyQcW3QjB2uLsEu/AHqT9Sk9nmDq/g1m5SHNg9HFEgjwiKlK4P1giJMmEKDHC3RBpFk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540596000575.1509494270476; Wed, 15 Oct 2025 08:03:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xP-0007ej-8D; Wed, 15 Oct 2025 10:58:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xN-0007eO-KI for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:25 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xH-0000aB-9c for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:25 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id C78C7C050E; Wed, 15 Oct 2025 17:58:12 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-oQDO0m51; Wed, 15 Oct 2025 17:58:12 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540292; bh=Cc4fro7LMqaYMZ5I3F9f9KBUdUTKDXhLsBEoX+i+vMw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=w2DFPtx0BKSIMZAjTZpImHwRd1AuhdEl10ceHDRmyf4qJaNmxBiVYAFA4uVn7tpaU 47ZbzMEvKjHpFPMAt+N2XNGWHOB9rPeqDz/eRxoA4FSXUPNGmWZJXa53HjK+vXjp5r ZX0gjcR1INpFf+5q0RngWfEYBvBSnARI+YgeBDp8= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz , "Gonglei (Arei)" , Zhenwei Pi , Jason Wang Subject: [PATCH v3 01/23] vhost-user: rework enabling vrings Date: Wed, 15 Oct 2025 17:57:45 +0300 Message-ID: <20251015145808.1112843-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540598127154100 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 Tested-by: Lei Yang --- 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 943680a23a..abdfce33af 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 a8ee18a912..25e9f1fd24 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 36c9c2e04d..f367ce06ce 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1235,7 +1235,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 266a11514a..414a48a218 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -2013,27 +2013,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 08bbb4dfe9..1ee639dd7e 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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; 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 8.43.85.245 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 [8.43.85.245]) by mx.zohomail.com with SMTPS id 17605403651191020.543166739003; Wed, 15 Oct 2025 07:59:25 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 456CA41BB7; Wed, 15 Oct 2025 10:59:24 -0400 (EDT) Received: from [172.19.199.20] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 51EC043EC0; Wed, 15 Oct 2025 10:58:30 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 08F8841A38; Wed, 15 Oct 2025 10:58:23 -0400 (EDT) Received: from forwardcorp1a.mail.yandex.net (forwardcorp1a.mail.yandex.net [178.154.239.72]) (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 0B6C341B59 for ; Wed, 15 Oct 2025 10:58:20 -0400 (EDT) Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 89088C0678; Wed, 15 Oct 2025 17:58:14 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-Bv8IVGLD; Wed, 15 Oct 2025 17:58:13 +0300 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS 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=1760540293; bh=f9uxlUmTRFGegLrg7kIzYCZISTICbH/uBHeNah7NvrY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=j39blGLqQWpOFHLhUtL9iT3oGo0YG1Vzv+amvNYqSDGD47vAQH9IqgF7e29wkzKWT NIx9l6kLQfxLPKbFKjDiq17+PQb+8gam804Rlw1fd84LX//7NLJhynHnE0AMjRm4EQ x7qgWwmL7yjj1Nl96FEV36zFAVdl/l0B68b3nULU= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Subject: [PATCH v3 02/23] vhost: drop backend_features field Date: Wed, 15 Oct 2025 17:57:46 +0300 Message-ID: <20251015145808.1112843-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: QK4FMX2SESTXJQYEQXYNRC6I2YF2Q2H7 X-Message-ID-Hash: QK4FMX2SESTXJQYEQXYNRC6I2YF2Q2H7 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 , 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: 1760540367845154100 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 Tested-by: Lei Yang --- 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 c0cc5f6942..de7a810c93 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 25e9f1fd24..fda90e231e 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 cdf405b0f8..d694a25fe2 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -276,7 +276,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 25f2d894e7..0c80a271d8 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 4a7b970976..efd9f68420 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 f367ce06ce..b80174f489 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1448,14 +1448,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)) { @@ -2189,8 +2190,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 1daae482d3..4bf9a3109d 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 b338344c6c..dd1a38e792 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -780,8 +780,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: @@ -822,8 +820,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 1ee639dd7e..3e69e47833 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 05295ab665..b995a5bb6d 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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540561; cv=none; d=zohomail.com; s=zohoarc; b=VGgn1qw4v3k9cFS/6R8jS8Ngu3bcT4pgylRzUR057UVLnTyiTai8b/SbXbD9WfOQChI0OMKWRpT8ol7QQMc8kAxTT6EseeW/ppM72C9LgXk+g9E1RpmnztkKvaYJ1c8XyehZCThodHNsPtw4VKMqskw5FzXhh3YPk92UrUqmdhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540561; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uJnRGLW978ZbzYp4OH98EKpuSnli27gjDhigwEbVLmw=; b=mx7rH/DyZxiGaRr02leBqwrjYCvEzcs1Dp66/6Ei5KRhMD3zakFGxsrJ+yEFfRisqcISW2ykwWb0lKEA27Gj/bP7Rok7WZdC2kZlF9KUB3IT/wbW8pyeHC1NwM3niL2N6Ah3MU1xP+ItVLSVcpIUQu/QaiI7oi1/bmgUB+jCiJo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540561432629.7652482522545; Wed, 15 Oct 2025 08:02:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xS-0007fv-1b; Wed, 15 Oct 2025 10:58:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xQ-0007fM-DE for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:28 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xH-0000aQ-VW for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:28 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 8E9B7C067C; Wed, 15 Oct 2025 17:58:15 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-m1FsGBOj; Wed, 15 Oct 2025 17:58:14 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540294; bh=uJnRGLW978ZbzYp4OH98EKpuSnli27gjDhigwEbVLmw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=SQLmsVegbIqJKs60zejD5V0TJ2d6VfdluRRdhbRbWsrF6Sm3MCADpbAstFux/FSZb N1QFeocl7zOelg2BQbnEzx2oJM4V9l2m9PV8m7gue7TNCca/DEpHy4/Y0SRTLN72DF ynT1rpcENVslEDmGGYiASbIoo2TQaJBum8cQUU58= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v3 03/23] vhost-user: introduce vhost_user_has_protocol_feature() helper Date: Wed, 15 Oct 2025 17:57:47 +0300 Message-ID: <20251015145808.1112843-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540567761158500 Content-Type: text/plain; charset="utf-8" Make all protocol feature checks in the same way. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz Tested-by: Lei Yang --- hw/virtio/vhost-user.c | 120 +++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 58 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index b80174f489..b8231dcbcf 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -272,6 +272,12 @@ struct scrub_regions { int fd_idx; }; =20 +static bool vhost_user_has_protocol_feature(struct vhost_dev *dev, + uint64_t feature) +{ + return virtio_has_feature(dev->protocol_features, feature); +} + static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg) { struct vhost_user *u =3D dev->opaque; @@ -435,8 +441,8 @@ static int vhost_user_set_log_base(struct vhost_dev *de= v, uint64_t base, { int fds[VHOST_USER_MAX_RAM_SLOTS]; size_t fd_num =3D 0; - bool shmfd =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_LOG_SHMFD); + bool shmfd =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_LOG_SHM= FD); int ret; VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_LOG_BASE, @@ -1006,11 +1012,11 @@ static int vhost_user_set_mem_table(struct vhost_de= v *dev, int fds[VHOST_MEMORY_BASELINE_NREGIONS]; size_t fd_num =3D 0; bool do_postcopy =3D u->postcopy_listen && u->postcopy_fd.handler; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); bool config_mem_slots =3D - virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS); + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS); int ret; =20 if (do_postcopy) { @@ -1058,8 +1064,9 @@ static int vhost_user_set_mem_table(struct vhost_dev = *dev, static int vhost_user_set_vring_endian(struct vhost_dev *dev, struct vhost_vring_state *ring) { - bool cross_endian =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CROSS_END= IAN); + bool cross_endian =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CROSS_ENDIAN); VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_VRING_ENDIAN, .hdr.flags =3D VHOST_USER_VERSION, @@ -1129,8 +1136,9 @@ static int vhost_user_write_sync(struct vhost_dev *de= v, VhostUserMsg *msg, int ret; =20 if (wait_for_reply) { - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_REPLY_ACK); if (reply_supported) { msg->hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; } @@ -1458,8 +1466,7 @@ static int vhost_user_set_features(struct vhost_dev *= dev, ret =3D vhost_user_set_u64(dev, VHOST_USER_SET_FEATURES, features, log_enabled); =20 - if (virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_STATUS)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_STATUS)= ) { if (!ret) { return vhost_user_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); } @@ -1513,8 +1520,8 @@ static int vhost_user_reset_device(struct vhost_dev *= dev) * Historically, reset was not implemented so only reset devices * that are expecting it. */ - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_RESET_DEVICE)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_RESET_DEVICE)) { return -ENOSYS; } =20 @@ -1571,8 +1578,8 @@ static int vhost_user_backend_handle_vring_host_notif= ier(struct vhost_dev *dev, void *addr; char *name; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) || + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) || vdev =3D=3D NULL || queue_idx >=3D virtio_get_num_queues(vdev)) { return -EINVAL; } @@ -1884,13 +1891,13 @@ static int vhost_setup_backend_channel(struct vhost= _dev *dev) }; struct vhost_user *u =3D dev->opaque; int sv[2], ret =3D 0; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); Error *local_err =3D NULL; QIOChannel *ioc; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_BACKEND_REQ)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ)) { return 0; } =20 @@ -2138,8 +2145,8 @@ static int vhost_user_postcopy_notifier(NotifierWithR= eturn *notifier, =20 switch (pnd->reason) { case POSTCOPY_NOTIFY_PROBE: - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_PAGEFAULT)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_PAGEFAULT)) { /* TODO: Get the device name into this error somehow */ error_setg(errp, "vhost-user backend not capable of postcopy"); @@ -2230,7 +2237,7 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, } =20 /* query the max queues we support if backend supports Multiple Qu= eue */ - if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_MQ)= ) { err =3D vhost_user_get_u64(dev, VHOST_USER_GET_QUEUE_NUM, &dev->max_queues); if (err < 0) { @@ -2248,18 +2255,18 @@ static int vhost_user_backend_init(struct vhost_dev= *dev, void *opaque, } =20 if (virtio_has_feature(features, VIRTIO_F_IOMMU_PLATFORM) && - !(virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_BACKEND_REQ) && - virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_ACK))) { + !(vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ) && + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_REPLY_ACK))) { error_setg(errp, "IOMMU support requires reply-ack and " "backend-req protocol features."); return -EINVAL; } =20 /* get max memory regions if backend supports configurable RAM slo= ts */ - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS)= ) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS)) { u->user->memory_slots =3D VHOST_MEMORY_BASELINE_NREGIONS; } else { err =3D vhost_user_get_max_memslots(dev, &ram_slots); @@ -2281,8 +2288,8 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, } =20 if (dev->migration_blocker =3D=3D NULL && - !virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_LOG_SHMFD)) { + !vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_LOG_SHMFD)) { error_setg(&dev->migration_blocker, "Migration disabled: vhost-user backend lacks " "VHOST_USER_PROTOCOL_F_LOG_SHMFD feature."); @@ -2351,8 +2358,8 @@ static bool vhost_user_requires_shm_log(struct vhost_= dev *dev) { assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_USER); =20 - return virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_LOG_SHMFD); + return vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_LOG_SHMFD); } =20 static int vhost_user_migration_done(struct vhost_dev *dev, char* mac_addr) @@ -2367,8 +2374,7 @@ static int vhost_user_migration_done(struct vhost_dev= *dev, char* mac_addr) } =20 /* if backend supports VHOST_USER_PROTOCOL_F_RARP ask it to send the R= ARP */ - if (virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_RARP)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_RARP)) { msg.hdr.request =3D VHOST_USER_SEND_RARP; msg.hdr.flags =3D VHOST_USER_VERSION; memcpy((char *)&msg.payload.u64, mac_addr, 6); @@ -2382,11 +2388,11 @@ static int vhost_user_migration_done(struct vhost_d= ev *dev, char* mac_addr) static int vhost_user_net_set_mtu(struct vhost_dev *dev, uint16_t mtu) { VhostUserMsg msg; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); int ret; =20 - if (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_NET_MTU)= )) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_NET_MT= U)) { return 0; } =20 @@ -2446,8 +2452,7 @@ static int vhost_user_get_config(struct vhost_dev *de= v, uint8_t *config, .hdr.size =3D VHOST_USER_CONFIG_HDR_SIZE + config_len, }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIG)) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_CONFIG= )) { error_setg(errp, "VHOST_USER_PROTOCOL_F_CONFIG not supported"); return -EINVAL; } @@ -2490,8 +2495,8 @@ static int vhost_user_set_config(struct vhost_dev *de= v, const uint8_t *data, { int ret; uint8_t *p; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); =20 VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_CONFIG, @@ -2499,8 +2504,7 @@ static int vhost_user_set_config(struct vhost_dev *de= v, const uint8_t *data, .hdr.size =3D VHOST_USER_CONFIG_HDR_SIZE + size, }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIG)) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_CONFIG= )) { return -ENOTSUP; } =20 @@ -2535,8 +2539,9 @@ static int vhost_user_crypto_create_session(struct vh= ost_dev *dev, uint64_t *session_id) { int ret; - bool crypto_session =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CRYPTO_SESSIO= N); + bool crypto_session =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CRYPTO_SESSION); CryptoDevBackendSessionInfo *backend_info =3D session_info; VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_CREATE_CRYPTO_SESSION, @@ -2637,8 +2642,9 @@ static int vhost_user_crypto_close_session(struct vhost_dev *dev, uint64_t session_id) { int ret; - bool crypto_session =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CRYPTO_SESSIO= N); + bool crypto_session =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CRYPTO_SESSION); VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_CLOSE_CRYPTO_SESSION, .hdr.flags =3D VHOST_USER_VERSION, @@ -2683,8 +2689,8 @@ static int vhost_user_get_inflight_fd(struct vhost_de= v *dev, .hdr.size =3D sizeof(msg.payload.inflight), }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { return 0; } =20 @@ -2751,8 +2757,8 @@ static int vhost_user_set_inflight_fd(struct vhost_de= v *dev, .hdr.size =3D sizeof(msg.payload.inflight), }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { return 0; } =20 @@ -2851,8 +2857,7 @@ void vhost_user_async_close(DeviceState *d, =20 static int vhost_user_dev_start(struct vhost_dev *dev, bool started) { - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_STATUS)) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_STATUS= )) { return 0; } =20 @@ -2877,16 +2882,15 @@ static void vhost_user_reset_status(struct vhost_de= v *dev) return; } =20 - if (virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_STATUS)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_STATUS)= ) { vhost_user_set_status(dev, 0); } } =20 static bool vhost_user_supports_device_state(struct vhost_dev *dev) { - return virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_DEVICE_STATE); + return vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_DEVICE_STATE); } =20 static int vhost_user_set_device_state_fd(struct vhost_dev *dev, --=20 2.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540752; cv=none; d=zohomail.com; s=zohoarc; b=ZWgyRRTo/MHT6rBrvoZJ26tMPozqrUO3cS4HighmRvY72VW/Ul4LaiYpJfbAapP53+/p4ZTId8ixtjBWlysNEtutR8DVDf8ayggNQMss/wpjNfb5QlYP17wlsT0N/v2hHSIl3gUHFC7HEECJIM2vB/htkolGhsLOwca7s4whT9o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540752; 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=nzQymKtvEuinC1MLaSekDhWcC59jdFn2tR2BWWdG/ts=; b=jWc2SJK52J4xF8b1sAItM+d5ODsSj5qziR6bFPTcZZQIqw+QKX9N4ast4NIekA31fWdG/HGyhAXslEia6mJRZ0KR7JVawyO9VgbD7tZWx5CVNKymCF2TcaPT5Syf05uBz2iFCkeId7eTjp/DJH+pm/XIYVivEOMW9dgTISPjLWo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540752922279.83893797021506; Wed, 15 Oct 2025 08:05:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xR-0007fd-8C; Wed, 15 Oct 2025 10:58:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xP-0007ev-3T for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:27 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xH-0000ae-CY for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:26 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 778ADC067B; Wed, 15 Oct 2025 17:58:16 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-W67XlB8z; Wed, 15 Oct 2025 17:58:15 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540295; bh=nzQymKtvEuinC1MLaSekDhWcC59jdFn2tR2BWWdG/ts=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=di5O7jbpnYyddznFhsfZFFY6Ms1V147VVt/YQ5lfCupcrt1Ks+XuGN99mMBqqVKMl rlgeOXwUUmwW6+GhrUWeEuoQ+xJJ4XBXoo6aFfnbGZTjHgCuNdr9Myj3cDprd+Zgk1 LbklLpVUgqPyN29KQ/0TlcwlBOd9OTQX354VxL74= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz , "Gonglei (Arei)" , Zhenwei Pi , Jason Wang Subject: [PATCH v3 04/23] vhost: move protocol_features to vhost_user Date: Wed, 15 Oct 2025 17:57:48 +0300 Message-ID: <20251015145808.1112843-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540753850154100 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 Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz Tested-by: Lei Yang --- backends/cryptodev-vhost.c | 1 - hw/net/vhost_net.c | 2 -- hw/virtio/vhost-user.c | 26 +++++++++++++++++++++++--- hw/virtio/virtio-qmp.c | 6 ++++-- include/hw/virtio/vhost-user.h | 3 +++ include/hw/virtio/vhost.h | 8 -------- 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index abdfce33af..c6069f4e5b 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/net/vhost_net.c b/hw/net/vhost_net.c index fda90e231e..ca19983126 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/vhost-user.c b/hw/virtio/vhost-user.c index b8231dcbcf..3fd11a3b57 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" @@ -264,6 +265,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 { @@ -275,7 +284,8 @@ struct scrub_regions { static bool vhost_user_has_protocol_feature(struct vhost_dev *dev, uint64_t feature) { - return virtio_has_feature(dev->protocol_features, feature); + struct vhost_user *u =3D dev->opaque; + return virtio_has_feature(u->protocol_features, feature); } =20 static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg) @@ -2229,8 +2239,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; @@ -3021,6 +3031,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 dd1a38e792..82acb6d232 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -821,12 +821,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 9a3f238b43..36d96296a3 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, @@ -111,4 +112,6 @@ void vhost_user_async_close(DeviceState *d, CharBackend *chardev, struct vhost_dev *vhost, vu_async_close_fn cb); =20 +void vhost_user_qmp_status(struct vhost_dev *dev, VirtioStatus *status); + #endif diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 3e69e47833..e308bc4556 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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540460; cv=none; d=zohomail.com; s=zohoarc; b=K5tcvAzBYUuEG0/AkT/nNdpx+kR0WEbk9dOsizKuSjb8Qivzbub35EsXEtCMTU1ssUTbyBC/YjAunhmfma4scqluAMeEczeu+QBYE7wdUY9tpEev5qHEk2xvI7j20BFn88v7NPy2LIf7RueRBwxCtZCQKcHj/K9bmmXClvUS/8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540460; 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=INKR99pB7UpCUkfYYkXxbgcR1IRFbZqmlRezvtKlTvI=; b=LfkJilv+WDNm1WTIQikf8oYDCQ/W15IqD2cw0zycQ06oV5rS6kyXQZ0hGEt3QnBjAj1R0KI7V5CKlk5TLqiWuf0vb8NFvAfUsCGhQDxFX382rmggt9WzB7HvkZ1wLBo2os33bRm9qCfliZIRak2ScJ7PfozWSjsGdc668r00wWM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540459811165.82472801321285; Wed, 15 Oct 2025 08:00:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xV-0007hS-GJ; Wed, 15 Oct 2025 10:58:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xS-0007gA-Bv for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:30 -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 1v92xJ-0000ar-KB for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:29 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 33073C0680; Wed, 15 Oct 2025 17:58:17 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-qP3pZ3a9; Wed, 15 Oct 2025 17:58:16 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540296; bh=INKR99pB7UpCUkfYYkXxbgcR1IRFbZqmlRezvtKlTvI=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=fP7X1tkwocwePiGF/iVEPDLYk8jm5SQ8z47TzAMxkvpiKjiJ7VDDKsmB7cCd/tcx8 5q5HeFe9ufdzsUeh1/jVXtzio7nyevBTL3sFBPvRCNWq8oo3DgccX0zHlmpeCEQxo2 ML7lM3Y3sdGfpD7L56Etn8Jg+5zC2u/FjG+Wp+tk= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Raphael Norwitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v3 05/23] vhost-user-gpu: drop code duplication Date: Wed, 15 Oct 2025 17:57:49 +0300 Message-ID: <20251015145808.1112843-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-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=lists.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, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540464026158500 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 Tested-by: Lei Yang --- 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 9fc6bbcd2c..79ea64b12c 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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540500; cv=none; d=zohomail.com; s=zohoarc; b=O5CttQM+KVlfHc238onwm/sbEX0Db+fkrTOjtQVgES0EzHLc1WN3fztXzqoL364G095B+788c45DtwVnPiGdFoNLf+lop+K2Ldw6SOnoQyA5nXoneQkYNuvpR7ESKuvwWlKdn1AMEXdlHcOXjzdLK0R8wAbaY/bh7NdiQ35C6Xc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540500; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fK8Ey4GFF4THHkSMPlpLhXnp31VyGUMkqHsjojITyhU=; b=lAUFsamNltcnpKf7e33Un7aSv/B1XDC8tZ/DAdlqMB23QZeI4PyjeasPTF0CNhuUimH2TeQXJ7O92w81tv+C/YNIVT1d1DTi571X4r4mNOSls53EzUyH5GbMeP1+fitxxkl7kF/K94wX4p8hShyQD7Xv2NQDgvzEJ77T3M+9Wo4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540499972655.6247344864939; Wed, 15 Oct 2025 08:01:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xT-0007gZ-Fa; Wed, 15 Oct 2025 10:58:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xQ-0007fJ-1t for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:28 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xI-0000b1-OT for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:27 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 311ACC0682; Wed, 15 Oct 2025 17:58:18 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-qubHylAR; Wed, 15 Oct 2025 17:58:17 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540297; bh=fK8Ey4GFF4THHkSMPlpLhXnp31VyGUMkqHsjojITyhU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Wao2Pt3sOhy3jnxlnvJmutT7s3Rhp9ZTqcAClhv+ru7URkxawl9EnOGMnBQcx3mIN /DAN0WZmDPtGjuhtnM1fbxt7Fx+spWKixzawR5ulVjr+y3yPJoRj2B5U/vS45zKT7T aNq3YusZAcY4rTILJdqkVr4pJWYuFbCK17z2sJTs= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Jason Wang , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v3 06/23] vhost: make vhost_dev.features private Date: Wed, 15 Oct 2025 17:57:50 +0300 Message-ID: <20251015145808.1112843-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540502699158500 Content-Type: text/plain; charset="utf-8" It's hard to control where and how do we use this field. Let's cover all usages by getters/setters, and keep direct access to the field only in vhost.c. It will help to control migration of this field in further commits. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Tested-by: Lei Yang --- hw/display/vhost-user-gpu.c | 7 +++---- hw/net/vhost_net.c | 18 ++++++++--------- hw/virtio/vdpa-dev.c | 2 +- hw/virtio/vhost-user-base.c | 8 ++++++-- hw/virtio/vhost-user.c | 4 ++-- hw/virtio/vhost.c | 6 +++--- hw/virtio/virtio-qmp.c | 2 +- include/hw/virtio/vhost.h | 39 +++++++++++++++++++++++++++++++++++-- net/vhost-vdpa.c | 7 +++---- 9 files changed, 65 insertions(+), 28 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 79ea64b12c..146620e0a3 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -631,17 +631,16 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Erro= r **errp) =20 /* existing backend may send DMABUF, so let's add that requirement */ g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED; - if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_VIRGL)) { + if (vhost_dev_has_feature(&g->vhost->dev, VIRTIO_GPU_F_VIRGL)) { g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED; } - if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_EDID)) { + if (vhost_dev_has_feature(&g->vhost->dev, VIRTIO_GPU_F_EDID)) { g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_EDID_ENABLED; } else { error_report("EDID requested but the backend doesn't support it."); g->parent_obj.conf.flags &=3D ~(1 << VIRTIO_GPU_FLAG_EDID_ENABLED); } - if (virtio_has_feature(g->vhost->dev.features, - VIRTIO_GPU_F_RESOURCE_UUID)) { + if (vhost_dev_has_feature(&g->vhost->dev, VIRTIO_GPU_F_RESOURCE_UUID))= { g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_RESOURCE_UUID_E= NABLED; } =20 diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index ca19983126..323d117735 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -54,8 +54,8 @@ void vhost_net_ack_features_ex(struct vhost_net *net, con= st uint64_t *features) { virtio_features_clear(net->dev.acked_features_ex); if (net->backend =3D=3D -1) { - net->dev.acked_features =3D - net->dev.features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES); + net->dev.acked_features =3D (vhost_dev_features(&net->dev) & + (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)); } else if (!qemu_has_vnet_hdr(net->nc)) { net->dev.acked_features =3D 1ULL << VHOST_NET_F_VIRTIO_NET_HDR; } @@ -282,15 +282,15 @@ struct vhost_net *vhost_net_init(VhostNetOptions *opt= ions) if (backend_kernel) { if (!qemu_has_vnet_hdr_len(options->net_backend, sizeof(struct virtio_net_hdr_mrg_rxbuf))) { - net->dev.features &=3D ~(1ULL << VIRTIO_NET_F_MRG_RXBUF); + vhost_dev_clear_feature(&net->dev, VIRTIO_NET_F_MRG_RXBUF); } =20 if (!qemu_has_vnet_hdr(options->net_backend) && - (~net->dev.features & (1ULL << VHOST_NET_F_VIRTIO_NET_HDR))) { - fprintf(stderr, "vhost lacks feature mask 0x%llx for backend\n= ", - ~net->dev.features & (1ULL << VHOST_NET_F_VIRTIO_NET_H= DR)); - goto fail; - } + !vhost_dev_has_feature(&net->dev, VHOST_NET_F_VIRTIO_NET_HDR))= { + fprintf(stderr, "vhost lacks VHOST_NET_F_VIRTIO_NET_HDR " + "feature for backend\n"); + goto fail; + } } =20 /* Set sane init value. Override when guest acks. */ @@ -298,7 +298,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *optio= ns) virtio_features_from_u64(features, options->get_acked_features(net->nc)); if (virtio_features_andnot(missing_features, features, - net->dev.features_ex)) { + vhost_dev_features_ex(&net->dev))) { fprintf(stderr, "vhost lacks feature mask 0x" VIRTIO_FEATURES_= FMT " for backend\n", VIRTIO_FEATURES_PR(missing_features)= ); goto fail; diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c index efd9f68420..e1a2ff433d 100644 --- a/hw/virtio/vdpa-dev.c +++ b/hw/virtio/vdpa-dev.c @@ -224,7 +224,7 @@ static uint64_t vhost_vdpa_device_get_features(VirtIODe= vice *vdev, Error **errp) { VhostVdpaDevice *s =3D VHOST_VDPA_DEVICE(vdev); - uint64_t backend_features =3D s->dev.features; + uint64_t backend_features =3D vhost_dev_features(&s->dev); =20 if (!virtio_has_feature(features, VIRTIO_F_IOMMU_PLATFORM)) { virtio_clear_feature(&backend_features, VIRTIO_F_IOMMU_PLATFORM); diff --git a/hw/virtio/vhost-user-base.c b/hw/virtio/vhost-user-base.c index ff67a020b4..cf311c3bfc 100644 --- a/hw/virtio/vhost-user-base.c +++ b/hw/virtio/vhost-user-base.c @@ -118,9 +118,13 @@ static uint64_t vub_get_features(VirtIODevice *vdev, uint64_t requested_features, Error **errp) { VHostUserBase *vub =3D VHOST_USER_BASE(vdev); + uint64_t backend_features =3D vhost_dev_features(&vub->vhost_dev); + /* This should be set when the vhost connection initialises */ - g_assert(vub->vhost_dev.features); - return vub->vhost_dev.features & ~(1ULL << VHOST_USER_F_PROTOCOL_FEATU= RES); + g_assert(backend_features); + virtio_clear_feature(&backend_features, VHOST_USER_F_PROTOCOL_FEATURES= ); + + return backend_features; } =20 /* diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 3fd11a3b57..9f26515fd4 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1252,7 +1252,7 @@ static int vhost_user_set_vring_enable(struct vhost_d= ev *dev, int enable) { int i; =20 - if (!virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES)= ) { + if (!vhost_dev_has_feature(dev, VHOST_USER_F_PROTOCOL_FEATURES)) { /* * For vhost-user devices, if VHOST_USER_F_PROTOCOL_FEATURES has n= ot * been negotiated, the rings start directly in the enabled state, @@ -1469,7 +1469,7 @@ static int vhost_user_set_features(struct vhost_dev *= dev, * Don't lose VHOST_USER_F_PROTOCOL_FEATURES, which is vhost-user * specific. */ - if (virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES))= { + if (vhost_dev_has_feature(dev, VHOST_USER_F_PROTOCOL_FEATURES)) { features |=3D 1ULL << VHOST_USER_F_PROTOCOL_FEATURES; } =20 diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 414a48a218..94efa409aa 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1603,7 +1603,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, } } =20 - virtio_features_copy(hdev->features_ex, features); + virtio_features_copy(hdev->_features_ex, features); =20 hdev->memory_listener =3D (MemoryListener) { .name =3D "vhost", @@ -1626,7 +1626,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, }; =20 if (hdev->migration_blocker =3D=3D NULL) { - if (!virtio_has_feature_ex(hdev->features_ex, VHOST_F_LOG_ALL)) { + if (!vhost_dev_has_feature_ex(hdev, VHOST_F_LOG_ALL)) { error_setg(&hdev->migration_blocker, "Migration disabled: vhost lacks VHOST_F_LOG_ALL fe= ature."); } else if (vhost_dev_log_is_shared(hdev) && !qemu_memfd_alloc_chec= k()) { @@ -1900,7 +1900,7 @@ void vhost_get_features_ex(struct vhost_dev *hdev, const int *bit =3D feature_bits; =20 while (*bit !=3D VHOST_INVALID_FEATURE_BIT) { - if (!virtio_has_feature_ex(hdev->features_ex, *bit)) { + if (!vhost_dev_has_feature_ex(hdev, *bit)) { virtio_clear_feature_ex(features, *bit); } bit++; diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c index 82acb6d232..33d32720e1 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -817,7 +817,7 @@ VirtioStatus *qmp_x_query_virtio_status(const char *pat= h, Error **errp) status->vhost_dev->nvqs =3D hdev->nvqs; status->vhost_dev->vq_index =3D hdev->vq_index; status->vhost_dev->features =3D - qmp_decode_features(vdev->device_id, hdev->features_ex); + qmp_decode_features(vdev->device_id, vhost_dev_features_ex(hde= v)); status->vhost_dev->acked_features =3D qmp_decode_features(vdev->device_id, hdev->acked_features_ex); =20 diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index e308bc4556..1ba1af1d86 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -98,10 +98,11 @@ struct vhost_dev { * offered by a backend which may be a subset of the total * features eventually offered to the guest. * - * @features: available features provided by the backend + * @_features: available features provided by the backend, private, + * direct access only in vhost.h/vhost.c * @acked_features: final negotiated features with front-end driver */ - VIRTIO_DECLARE_FEATURES(features); + VIRTIO_DECLARE_FEATURES(_features); VIRTIO_DECLARE_FEATURES(acked_features); =20 uint64_t max_queues; @@ -403,6 +404,40 @@ int vhost_dev_get_inflight(struct vhost_dev *dev, uint= 16_t queue_size, struct vhost_inflight *inflight); bool vhost_dev_has_iommu(struct vhost_dev *dev); =20 +static inline bool vhost_dev_has_feature(struct vhost_dev *dev, + uint64_t feature) +{ + return virtio_has_feature(dev->_features, feature); +} + +static inline bool vhost_dev_has_feature_ex(struct vhost_dev *dev, + uint64_t feature) +{ + return virtio_has_feature_ex(dev->_features_ex, feature); +} + +static inline uint64_t vhost_dev_features(struct vhost_dev *dev) +{ + return dev->_features; +} + +static inline const uint64_t *vhost_dev_features_ex(struct vhost_dev *dev) +{ + return dev->_features_ex; +} + +static inline void vhost_dev_clear_feature(struct vhost_dev *dev, + uint64_t feature) +{ + virtio_clear_feature(&dev->_features, feature); +} + +static inline void vhost_dev_clear_feature_ex(struct vhost_dev *dev, + uint64_t feature) +{ + virtio_clear_feature_ex(dev->_features_ex, feature); +} + #ifdef CONFIG_VHOST int vhost_reset_device(struct vhost_dev *hdev); #else diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 74d26a9497..0af0d3bdd3 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -256,15 +256,14 @@ static bool vhost_vdpa_get_vnet_hash_supported_types(= NetClientState *nc, { assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); - uint64_t features =3D s->vhost_vdpa.dev->features; int fd =3D s->vhost_vdpa.shared->device_fd; struct { struct vhost_vdpa_config hdr; uint32_t supported_hash_types; } config; =20 - if (!virtio_has_feature(features, VIRTIO_NET_F_HASH_REPORT) && - !virtio_has_feature(features, VIRTIO_NET_F_RSS)) { + if (!vhost_dev_has_feature(s->vhost_vdpa.dev, VIRTIO_NET_F_HASH_REPORT= ) && + !vhost_dev_has_feature(s->vhost_vdpa.dev, VIRTIO_NET_F_RSS)) { return false; } =20 @@ -585,7 +584,7 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) * If we early return in these cases SVQ will not be enabled. The migr= ation * will be blocked as long as vhost-vdpa backends will not offer _F_LO= G. */ - if (!vhost_vdpa_net_valid_svq_features(v->dev->features, NULL)) { + if (!vhost_vdpa_net_valid_svq_features(vhost_dev_features(v->dev), NUL= L)) { return 0; } =20 --=20 2.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540841; cv=none; d=zohomail.com; s=zohoarc; b=E2LECwxMZ+9ykmmvoWIEzwcjNzp30WAKX9o4i2OunzvUZBT089QUgAYZ/FjhThqB6PRqg9taKsJzEWbT/LM1yqczAvtLKVfD8nuKF5YP2guHK7eND3kQXK/A9Qrd/PVE6EHXaXXmxhWMmb/7fSLbg0gHWzBDZFqd4KOFeD/xzaA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540841; 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=uJsVeXl+pVtxv1CsC7v1nVVbb3oRH5lkHyewMQwnhsY=; b=LhlqYi2BuThzG9IO69YMgSoUHPyj12usFKsZk7z2cpLFwIQm13HBkPQKEUyeMH83VtJUwmgweKDNDhdgNXyv/zJC2xCsYPpn2E9fwoqY5G9x/iHaaA/lIm3FTIDNJkiP/WbzRhg26tcHZC391I3A8qemMuRRfA49t7z2/OQZXSk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176054084140571.20663475513572; Wed, 15 Oct 2025 08:07:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xb-0007jd-5V; Wed, 15 Oct 2025 10:58:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xW-0007iE-UE for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:34 -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 1v92xK-0000bN-4K for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:34 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 0D7A5C0688; Wed, 15 Oct 2025 17:58:19 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-Wza5RtZQ; Wed, 15 Oct 2025 17:58:18 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540298; bh=uJsVeXl+pVtxv1CsC7v1nVVbb3oRH5lkHyewMQwnhsY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=f7gRLewX+erAIIL8FUTnLRA0NTYYIJvMCW6BvAZZGPiIalDSVfSkjMtXm5MSRbYay l92uzMAdAB57rDkC0zY1Gkhn1wc7L7hePw6H2fAZ6aZu61wuyaHgLBB2SFZyRHGtVq c68mbkOG6MClH2F7vfYqpfhwzSRAol8RG/T2nqT8= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v3 07/23] virtio: move common part of _set_guest_notifier to generic code Date: Wed, 15 Oct 2025 17:57:51 +0300 Message-ID: <20251015145808.1112843-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540844351158500 Content-Type: text/plain; charset="utf-8" virtio-pci and virtio-mmio 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 Reviewed-by: Daniil Tatianin Tested-by: Lei Yang --- hw/virtio/virtio-mmio.c | 41 +++++------------------------ hw/virtio/virtio-pci.c | 34 +++--------------------- hw/virtio/virtio.c | 48 +++++++++++++++++++++++++++++++--- include/hw/virtio/virtio-pci.h | 3 --- include/hw/virtio/virtio.h | 16 +++++++++--- 5 files changed, 67 insertions(+), 75 deletions(-) diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c index fb58c36452..1f1d96129b 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -659,18 +659,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_queue_set_guest_notifier(vdev, n, assign, with_irqfd); + if (r < 0) { + return r; } =20 if (vdc->guest_notifier_mask && vdev->use_guest_notifier_mask) { @@ -679,30 +672,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) { @@ -724,7 +694,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 937e22f08a..6c4576a17f 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1197,43 +1197,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_queue_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 153ee0a0cf..704bc7943f 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3803,8 +3803,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, @@ -3819,7 +3821,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; @@ -3836,6 +3838,46 @@ void virtio_config_set_guest_notifier_fd_handler(Vir= tIODevice *vdev, } } =20 +static void virtio_pci_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_queue_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_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); + } + + 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 639752977e..2a5b65f374 100644 --- a/include/hw/virtio/virtio-pci.h +++ b/include/hw/virtio/virtio-pci.h @@ -263,9 +263,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 d97529c3f1..7db8046766 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,18 @@ 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_queue_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_queue_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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540427; cv=none; d=zohomail.com; s=zohoarc; b=dnsCW/WZWrK0H7CZ06iTE7I3MzuojWCYe9P39j40TXHV3SFW3mc6K7ViSt+IRicnaJCrpfJFNi9Yl0l4iApXFZDT2qhF/F3u9RuJPk4miJkJO3EZwBgA51ecP8bTufMheWFOpEiHCMa+D4rOKNFAQXZd1Ywp5wqNMpYhTBIGuvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540427; 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=alqbx58EES1ZCWM4lr+qmhdbJNW3cz+TCgNRWd5Bg2c=; b=ld3QAPCCa6K6wMuyGuH5q5SDeCu3AUrPB/VcIvw4/c438sSdGquOciZaUuYzBWBY9yT5Tt5BCHDu3OtNqB+I8luz1VYv2nMWNBGb7iIxLhQ/dKzwC8lfGTftTxku1q1ckNTD4O6eN4Tgu0i8mMZK48dMrkroXvJ+a6QNcsqCXIY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176054042766462.307589077766465; Wed, 15 Oct 2025 08:00:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xV-0007hT-Fv; Wed, 15 Oct 2025 10:58:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xT-0007ga-DU for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:31 -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 1v92xL-0000bZ-B9 for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:31 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id C6F5DC068A; Wed, 15 Oct 2025 17:58:19 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-tOrzNGIV; Wed, 15 Oct 2025 17:58:19 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540299; bh=alqbx58EES1ZCWM4lr+qmhdbJNW3cz+TCgNRWd5Bg2c=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=VBdJUtd5pboDXxF/armVhIbFVBpNrOO2dYHYF/F8Rmk4wOXykzhAqK7tz2a7Vh7Gx SqEnijPVmGSZMEtvnfpZwralRPWH8MLstCqfvaQWeOshQs4MGWInuFUyS0z5HIakER 0iY5GVGpWAsDfNh9J78XdSv0L0UhXED1uQJBlorc= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v3 08/23] virtio: drop *_set_guest_notifier_fd_handler() helpers Date: Wed, 15 Oct 2025 17:57:52 +0300 Message-ID: <20251015145808.1112843-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540430807154100 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 Tested-by: Lei Yang --- hw/virtio/virtio.c | 76 +++++++++++----------------------------------- 1 file changed, 17 insertions(+), 59 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 704bc7943f..4184aff75c 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3804,74 +3804,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_pci_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_queue_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_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_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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540450; cv=none; d=zohomail.com; s=zohoarc; b=ZlCvQmuC93KoCu2ZvstmiTEGDvf8e24f0oyNYP8HT+RspUBnRP9cYIvlhibDXjxZxCfK0/rF/GM8Duh5vwjcjIDD5YbnlcCRa5mdtztrJtdsW6aaZdPbKJdDI8ny/3C2F1mdg9C0u9pxoYOrFZP1Urm4X0RxHzb0drPQrEYZ4tI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540450; 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=0WvtXm5zhPzg1uhEHyeny8uF69LB/bnsvzIY9vwSMfs=; b=QE6CYRG4C9X2u8Knec436i8IyhpxjWU2julSaX3DsROGLwF5yYD4NnmbQDkb8lu1P0mi/2G6LX8BacBsJ/SqC9uIGLTQqBZHfoa1/hpa08teHdCdx4az5W3LMkCFvqswZ9xwD3ryMIGZFFPIUO1BQe9XwOuRQ25B1vY/RoTb2yg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540450416365.54167669181084; Wed, 15 Oct 2025 08:00:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xX-0007iZ-VW; Wed, 15 Oct 2025 10:58:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xV-0007hV-LD for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:33 -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 1v92xL-0000bx-1H for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:33 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 855D2C068F; Wed, 15 Oct 2025 17:58:20 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-I73i0aRu; Wed, 15 Oct 2025 17:58:20 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540300; bh=0WvtXm5zhPzg1uhEHyeny8uF69LB/bnsvzIY9vwSMfs=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=fOqrgsXKZGlXQ/obHZyD36ovnfWPJCQYtOyRv+2qDM2ogbi32KNL1SHlNVrBr5WkY hhxSRuDHQ1BI4tILDRhCkom21iN5mk12+R4uG6AxEJECDBHul+c5P0gGCyFZhUmJgJ SpiGTd/2mnDweERCDJg1WOzA8k8x8ZouoInp2cgQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v3 09/23] vhost-user: keep QIOChannelSocket for backend channel Date: Wed, 15 Oct 2025 17:57:53 +0300 Message-ID: <20251015145808.1112843-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540452424154100 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 Tested-by: Lei Yang --- 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 9f26515fd4..23e7c12b16 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -244,7 +244,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, @@ -1904,7 +1904,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)) { @@ -1917,15 +1916,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; @@ -2336,7 +2335,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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540560; cv=none; d=zohomail.com; s=zohoarc; b=JlE/tlTtR44FyYnzIc+cJ9rFkoJzCiiH1XsDmH4BhN/vPkqqQQ32Lwa+MIfM9rHsKo+xM8dTaXqQVYGReny+3IYad0ixuDJ5GqlPB7GQ5+wWHAfz9kbArw7+moYYs+MKDDfBtdJPaOc1vLgzpKSO13accrs/e85BUifiWDvaPhU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540560; 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=SceKWQQRrTlKM0LfcLs3FwmbxHLRhewCw2hJI6i85uw=; b=WYKoEaG6GxUebnxxT7B+b/SMlOrz0Kr6ILwJA4vUnbW/We6AHTPu0m4wVwdHwQYzEY0OxktcVJcOSGXtdjAuzkf+qT1JsT7FD7cziKQgIQCLvZ65ZloR8AOHbVovvCLmLXdOeI90GsTyTJOtHx8CwYke7DNkQLM8xsWUEhxboSg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540560405171.30936347655188; Wed, 15 Oct 2025 08:02:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xd-0007ki-9s; Wed, 15 Oct 2025 10:58:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xY-0007it-Pm for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:36 -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 1v92xQ-0000dC-3b for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:36 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 3BD0DC0691; Wed, 15 Oct 2025 17:58:21 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-zEhavspA; Wed, 15 Oct 2025 17:58:20 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540300; bh=SceKWQQRrTlKM0LfcLs3FwmbxHLRhewCw2hJI6i85uw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=vVawY5HkR6h6eNKebWyF6hWMyR0Y7n7D/Gs54+6gAg1mqoJZk/j7jNeDFfcqFx1tX N79L1abFpwd2dIpaybpNW6VSPhmSKb7x4pNTtBQAcnMHXVJEMD/XRJ1TSccgS+LXoo KFZTEMOhcrjo4USor/NJZX45cnviquM5twdGoSxU= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v3 10/23] vhost: vhost_virtqueue_start(): fix failure path Date: Wed, 15 Oct 2025 17:57:54 +0300 Message-ID: <20251015145808.1112843-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540563509154100 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: Daniil Tatianin Reviewed-by: Raphael Norwitz Tested-by: Lei Yang --- hw/virtio/vhost.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 94efa409aa..be2245cc7e 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -453,11 +453,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; } @@ -1261,7 +1270,7 @@ 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 s, l, a; + hwaddr l, a; int r; int vhost_vq_index =3D dev->vhost_ops->vhost_get_vq_index(dev, idx); struct vhost_vring_file file =3D { @@ -1301,24 +1310,24 @@ int vhost_virtqueue_start(struct vhost_dev *dev, } } =20 - vq->desc_size =3D s =3D l =3D virtio_queue_get_desc_size(vdev, idx); + vq->desc_size =3D l =3D virtio_queue_get_desc_size(vdev, idx); vq->desc_phys =3D a; - vq->desc =3D vhost_memory_map(dev, a, &l, false); - if (!vq->desc || l !=3D s) { + vq->desc =3D vhost_memory_map(dev, a, l, false); + if (!vq->desc) { r =3D -ENOMEM; goto fail_alloc_desc; } - vq->avail_size =3D s =3D l =3D virtio_queue_get_avail_size(vdev, idx); + vq->avail_size =3D l =3D virtio_queue_get_avail_size(vdev, idx); vq->avail_phys =3D a =3D virtio_queue_get_avail_addr(vdev, idx); - vq->avail =3D vhost_memory_map(dev, a, &l, false); - if (!vq->avail || l !=3D s) { + vq->avail =3D vhost_memory_map(dev, a, l, false); + if (!vq->avail) { r =3D -ENOMEM; goto fail_alloc_avail; } - vq->used_size =3D s =3D l =3D virtio_queue_get_used_size(vdev, idx); + vq->used_size =3D l =3D virtio_queue_get_used_size(vdev, idx); vq->used_phys =3D a =3D virtio_queue_get_used_addr(vdev, idx); - vq->used =3D vhost_memory_map(dev, a, &l, true); - if (!vq->used || l !=3D s) { + vq->used =3D vhost_memory_map(dev, a, l, true); + if (!vq->used) { r =3D -ENOMEM; goto fail_alloc_used; } --=20 2.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540720; cv=none; d=zohomail.com; s=zohoarc; b=EvYlU/J61xRgP2sFMAwGtHCbygUNh6CI99r0omVxLxTmDuXDSlaHROEEY4NWa8PKzZ/FZBx7o76gDfUvuFSA4q8U+B3d7ceutsd2PTfq6DZTO/IxQehHElc2yP5r9qDNoLv9EdCQzb1/Cf3U+BaSEDs6U/2bndNvDHbAmaM+zFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540720; 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=ZXMrzcbIowlzXAQ2kQUJmxrXvoog9SldUHDJaCCwYU4=; b=ca8+NZiU47XXy0XqAozfY0inD59tY0nntoXaxZEZSwjo2lJpQiDkxp1YAr05uUl6Q/xTJIgjHptqDDbnB4AQKAtNhFvCoqxtkZjOQGu/piaBHUR6whRWoBauKFP5eg0qHruLbAQ9jEGkgrUn3qRof6m2v8rIhdRpqr8z8aK/yMY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540720805952.5527026394258; Wed, 15 Oct 2025 08:05:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xf-0007lD-0R; Wed, 15 Oct 2025 10:58:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xd-0007kV-2F for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:41 -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 1v92xP-0000dD-Sl for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:40 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id E4328C0692; Wed, 15 Oct 2025 17:58:21 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-4Z1Orgpw; Wed, 15 Oct 2025 17:58:21 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540301; bh=ZXMrzcbIowlzXAQ2kQUJmxrXvoog9SldUHDJaCCwYU4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=nYyHZRQrgHwcj+UojtqdSQ1P5ij0OozYhCkdmObBXM9ArfI6mXF03vpUC6t+6UD6D ukygVurLbcYsaLyhbRvh+D7tBEcOydZWDYUlLAcw/9WFWaLJHK6AZ7hXb/I64NWKqv NBOdRxT5k3s3jaLivsJXEAguoyd3lKEstvIhkvWU= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v3 11/23] vhost: make vhost_memory_unmap() null-safe Date: Wed, 15 Oct 2025 17:57:55 +0300 Message-ID: <20251015145808.1112843-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540723430154100 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 Tested-by: Lei Yang --- 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 be2245cc7e..db6ea42f9b 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -472,14 +472,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, @@ -1315,33 +1321,33 @@ int vhost_virtqueue_start(struct vhost_dev *dev, vq->desc =3D vhost_memory_map(dev, a, l, false); if (!vq->desc) { r =3D -ENOMEM; - goto fail_alloc_desc; + goto fail; } vq->avail_size =3D l =3D virtio_queue_get_avail_size(vdev, idx); vq->avail_phys =3D a =3D virtio_queue_get_avail_addr(vdev, idx); vq->avail =3D vhost_memory_map(dev, a, l, false); if (!vq->avail) { r =3D -ENOMEM; - goto fail_alloc_avail; + goto fail; } vq->used_size =3D l =3D virtio_queue_get_used_size(vdev, idx); vq->used_phys =3D a =3D virtio_queue_get_used_addr(vdev, idx); vq->used =3D vhost_memory_map(dev, a, 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. */ @@ -1361,24 +1367,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 @@ -1425,11 +1426,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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540569; cv=none; d=zohomail.com; s=zohoarc; b=EZotDQ4QgmTBJzeo6bJX8gxk6n1XmJEGgMNGnBavW1guZVcQQzEA4gVMXGsqzlfS7+7IgeFn4lnU1pyv8NFta80XY2CorJd5tBT/Q1R3qFV2t4udLiq7ink7y7qlVoByeHeRE1aq1S4B2zwzR2zZ1xL70eu5k73Q7WKAtVcutOs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540569; 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=DtS7aYhuIPmXoDGIMfa+XR3bFruQl93D0gkp4S2BFVE=; b=myb35BB2oUPfG3WlagN85vQQ4WH4UuLBBNoGM51edFAvCHABtEG3zZgM/smBbIoA6QEVt4qWCVaA3cG9Z1Oj3+FWozL4O6mG+LJ//ntlahYSoNfupHRnxa8sIA9uS4FQylPCAvITeYSS1J141+qHT0mFKyewARNMC8bB25+E0QM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540569357402.6065032632845; Wed, 15 Oct 2025 08:02:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xa-0007j9-Ce; Wed, 15 Oct 2025 10:58:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xW-0007hz-Nb for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:34 -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 1v92xQ-0000db-IC for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:34 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 9790EC0693; Wed, 15 Oct 2025 17:58:22 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-oyAHFRgd; Wed, 15 Oct 2025 17:58:22 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540302; bh=DtS7aYhuIPmXoDGIMfa+XR3bFruQl93D0gkp4S2BFVE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=fPH/Seqt7VVhrFxEByDuBjvKZ6ETu1t4rgsWpNi0sxSkr7Fp8TU4Xpyf7+YWeqxeL t+JD3qSI00e2yc3mmv0ytkY/xo6nroZ9kwi3m3hohzmeM2Z4jxA2Jrbem9qftM1yNM y8uXfCVZsJ9Jzt4S1q++wdMA9xfzdlxt4JymorKQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v3 12/23] vhost: simplify calls to vhost_memory_unmap() Date: Wed, 15 Oct 2025 17:57:56 +0300 Message-ID: <20251015145808.1112843-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540571811154100 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 Tested-by: Lei Yang --- 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 db6ea42f9b..c8ec6b4911 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1374,12 +1374,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 @@ -1426,12 +1423,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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540476; cv=none; d=zohomail.com; s=zohoarc; b=cXKogXACgDnOQWMSQgmtLGSnQqEs1KO1I28TEtz6PtgvcoII6jlOmShhsarPiEqvSKF4DJb8OBAZxq5AJ6EIQ2bdFkWpPsCFH5bHCt7gEzauOj56dRnHLHkjvkoW8OO43VVUyYfJ4YDQzPxbvCFbCK02ClhPC+9E+QnHOzPJ/54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540476; 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=Zn2ruQ+ylWQSJvvrnKTYr451ZPn/rZw3F/HGccRpHf0=; b=IIIIfs5KNtLnRl6Z0/EaOR+37goo9RIGrNJ3YQn0QKScKSHd+nMh2bAGbrbKVcDWNivdOdPTIzjbWJgRkDLzd1yvoJTqcFoZp1EDpNsFd/ZNJlENbWCF5LXzCT8u5OK3IYc/FTDY9excONeF1tHA5c5PcRyMMW0RMEvmTtKF3lY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540476352859.3915259139446; Wed, 15 Oct 2025 08:01:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xc-0007k4-VW; Wed, 15 Oct 2025 10:58:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xZ-0007j2-J8 for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:37 -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 1v92xR-0000dc-Dx for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:37 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 3C3A4C0696; Wed, 15 Oct 2025 17:58:23 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-P4BuoXCB; Wed, 15 Oct 2025 17:58:22 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540302; bh=Zn2ruQ+ylWQSJvvrnKTYr451ZPn/rZw3F/HGccRpHf0=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=ByVQemZrc9VIGtkYiATwbbGC2rH3ilD5KnvusmNU7BnlY4ZFclOsGHt0mPim3f/T6 Bomxk/Y+KzsOplS924k+3W88RY8zZCrnvDNYnm2rT6A5NcjbyeeLgRwcO1UOPab+lx 7A0M2iHz2ZZ+TPLmDnQ3f7c6w/CtilQQtWhHzUsA= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v3 13/23] vhost: move vrings mapping to the top of vhost_virtqueue_start() Date: Wed, 15 Oct 2025 17:57:57 +0300 Message-ID: <20251015145808.1112843-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540478950154100 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 Tested-by: Lei Yang --- hw/virtio/vhost.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index c8ec6b4911..db93b93fb1 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1292,30 +1292,6 @@ int vhost_virtqueue_start(struct vhost_dev *dev, /* Queue might not be ready for start */ return 0; } - - 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_is_big_endian(v= dev), - vhost_vq_index); - if (r) { - return r; - } - } - vq->desc_size =3D l =3D virtio_queue_get_desc_size(vdev, idx); vq->desc_phys =3D a; vq->desc =3D vhost_memory_map(dev, a, l, false); @@ -1338,6 +1314,29 @@ 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_is_big_endian(v= dev), + 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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540856; cv=none; d=zohomail.com; s=zohoarc; b=biHTrxm2gpCNlGfl8/KpsPenZm4PLr3FuCTvnnpediIOQCFr7D1tQUxN2W1FprBttA6HNEeOi6JWI8PNRRwsOlzQdlgd35M7fgiwLEfVEzEjLs8y+vF3vgOl8vbIB3zHxQ2pCSqagE0P5vvbag9CDrsYjQRk9UDoxkTcfgEK9Go= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540856; 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=got//1gi4PMmteYLSSsgGdYXp14HtV4ABbm+n8EndmE=; b=R6wBB4vIHDZ8x2duzoRo9NESXMbxgM8oB0w4BlTbJgqPiWt0gC3s9qHzQ+dxRIhfY8dnC96fMSd+xab4mkmCh1lyjYrXVf328X2USi0vFfCDBPi9sS9juJN45K8PwKCKwRhAT8aEQoOW4JvIsN3syQbtFYtJcA+GciNMRcrAPcs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540856505129.2659222526787; Wed, 15 Oct 2025 08:07:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xd-0007kS-5t; Wed, 15 Oct 2025 10:58:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xa-0007jA-7l for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:38 -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 1v92xS-0000do-Qj for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:37 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id D8C9FC069C; Wed, 15 Oct 2025 17:58:23 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-0Q6kUU16; Wed, 15 Oct 2025 17:58:23 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540303; bh=got//1gi4PMmteYLSSsgGdYXp14HtV4ABbm+n8EndmE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=l3BmVzResY+pBoD/T7TuVwAPIpQHfFuuVtjw0F3W5RTd3wq2owApeUnbI3vW7eJOh 8XmvUSUFb31Ai3u8t6BlhY8mESh+XIGfWdU1huoGcwCrtViL+ZcvLNMU6oFHxz7d5j gBqSs2OXQPGhgfKKMrAuApXSliNxUPg/FHGtTmqQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v3 14/23] vhost: vhost_virtqueue_start(): drop extra local variables Date: Wed, 15 Oct 2025 17:57:58 +0300 Message-ID: <20251015145808.1112843-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540870016154100 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 Reviewed-by: Daniil Tatianin Tested-by: Lei Yang --- hw/virtio/vhost.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index db93b93fb1..52a3236fff 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1276,7 +1276,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, a; int r; int vhost_vq_index =3D dev->vhost_ops->vhost_get_vq_index(dev, idx); struct vhost_vring_file file =3D { @@ -1287,28 +1286,27 @@ int vhost_virtqueue_start(struct vhost_dev *dev, }; struct VirtQueue *vvq =3D virtio_get_queue(vdev, idx); =20 - a =3D virtio_queue_get_desc_addr(vdev, idx); - if (a =3D=3D 0) { + vq->desc_phys =3D virtio_queue_get_desc_addr(vdev, idx); + if (vq->desc_phys =3D=3D 0) { /* Queue might not be ready for start */ return 0; } - vq->desc_size =3D l =3D virtio_queue_get_desc_size(vdev, idx); - vq->desc_phys =3D a; - vq->desc =3D vhost_memory_map(dev, a, l, false); + vq->desc_size =3D virtio_queue_get_desc_size(vdev, idx); + vq->desc =3D vhost_memory_map(dev, vq->desc_phys, vq->desc_size, false= ); if (!vq->desc) { r =3D -ENOMEM; goto fail; } - vq->avail_size =3D l =3D virtio_queue_get_avail_size(vdev, idx); - vq->avail_phys =3D a =3D virtio_queue_get_avail_addr(vdev, idx); - vq->avail =3D vhost_memory_map(dev, a, l, false); + 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 vhost_memory_map(dev, vq->avail_phys, vq->avail_size, fa= lse); if (!vq->avail) { r =3D -ENOMEM; goto fail; } - vq->used_size =3D l =3D virtio_queue_get_used_size(vdev, idx); - vq->used_phys =3D a =3D virtio_queue_get_used_addr(vdev, idx); - vq->used =3D vhost_memory_map(dev, a, l, true); + 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 vhost_memory_map(dev, vq->used_phys, vq->used_size, true); if (!vq->used) { r =3D -ENOMEM; goto fail; --=20 2.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540427; cv=none; d=zohomail.com; s=zohoarc; b=NsUxtJTLT+Dws10WMFIwCtllp/j07mSBCY6pZOZJl3SgaS+VJRatAOTlwvs/p2xTPcqrWd2x7nh4VP/Rx437L3fnEV+4g0Lerxv/8UQNEsykP7LF0U/gACpg5mEKmp+OxxJJyO407ZiknCbMFQ2A2ZMJMbZXaJ4MKKrqWjvmswA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540427; 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=7cF3P2LWCnkJ6+Z8tJLkgzbc+ihDE5lR0cnBIILM/Ew=; b=nTOL0nepRbPp/fZjCoD2Z7CmdJvp1IA60pERDkdfRnd3M9ADFbjFomLPrvhgXclADca7RnY88ITHSvsjWQ25gKshEqOmnFuZsnVhTyLjeW10gFdS08vWakTla7Ug9ygxjBZ2EgNPnqENSN0+U3WBv51JM8eqBp5wBD2wpYLtK1c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540426749837.2625410707586; Wed, 15 Oct 2025 08:00:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xe-0007lC-W2; Wed, 15 Oct 2025 10:58:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xd-0007kn-C8 for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:41 -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 1v92xR-0000dn-JV for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:40 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 9B298C069D; Wed, 15 Oct 2025 17:58:24 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-iszgJGE7; Wed, 15 Oct 2025 17:58:24 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540304; bh=7cF3P2LWCnkJ6+Z8tJLkgzbc+ihDE5lR0cnBIILM/Ew=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Za2JIVfc7o46G4PyeZv0vISMVxhfdKSISBp3oDcQVphZFV73BH2CxzqfNGuV8pQfP RprNEMhFtTjOVRmIw2Y4x246cCQmeAnEOnzZ+EvG8+qM8zDwPuwXgc/gniUnrDOiTL ZzW3FfK4kT8om4+qBaXHvcXh+ryugw7VPyKV8zS4= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v3 15/23] vhost: final refactoring of vhost vrings map/unmap Date: Wed, 15 Oct 2025 17:57:59 +0300 Message-ID: <20251015145808.1112843-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540430756154100 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: Daniil Tatianin Reviewed-by: Raphael Norwitz Tested-by: Lei Yang --- hw/virtio/vhost.c | 82 ++++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 52a3236fff..8c5e434b89 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -488,6 +488,53 @@ 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_phys =3D virtio_queue_get_desc_addr(vdev, idx); + if (vq->desc_phys =3D=3D 0) { + /* Queue might not be ready for start */ + return 0; + } + vq->desc_size =3D virtio_queue_get_desc_size(vdev, idx); + vq->desc =3D vhost_memory_map(dev, vq->desc_phys, vq->desc_size, false= ); + if (!vq->desc) { + return -ENOMEM; + } + + 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 vhost_memory_map(dev, vq->avail_phys, vq->avail_size, fa= lse); + if (!vq->avail) { + goto fail; + } + + 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 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, @@ -1286,30 +1333,9 @@ int vhost_virtqueue_start(struct vhost_dev *dev, }; struct VirtQueue *vvq =3D virtio_get_queue(vdev, idx); =20 - vq->desc_phys =3D virtio_queue_get_desc_addr(vdev, idx); - if (vq->desc_phys =3D=3D 0) { - /* Queue might not be ready for start */ - return 0; - } - vq->desc_size =3D virtio_queue_get_desc_size(vdev, idx); - vq->desc =3D vhost_memory_map(dev, vq->desc_phys, vq->desc_size, false= ); - if (!vq->desc) { - r =3D -ENOMEM; - goto fail; - } - 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 vhost_memory_map(dev, vq->avail_phys, vq->avail_size, fa= lse); - if (!vq->avail) { - r =3D -ENOMEM; - goto fail; - } - 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 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); @@ -1371,9 +1397,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 @@ -1420,9 +1444,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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540831; cv=none; d=zohomail.com; s=zohoarc; b=PO0wkig8CPzYLaH6BRLgYDp6RZMyhYkmIjPOWE8EYOOwQMyTjZRf59u3EGji4KcGQFYuZtU5isFy83QqTj/FLc9GY4m2WX90pdvK/SlvCJlQ4amABq0zeriWBDmAgt+uYMn8Qm4GzzZ1QM54WwOsfFZYDva/xqPaYhgzHf+TWzI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540831; 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=IKbrDYzfqGZ1MP25DmkK99IEgBtrTVOgXHAsSgntcCY=; b=UgdvKwCKmCN/Sey4ArbaUvxGHdw1vz7RsPnKoS3Ghp8r43znQ7xHPGbd8Fv08fV9F6hFNOr77/hiYztftcyJYypMRhmxz8kWFNxi6+wXrx2bOMGI2vwEr661CLaeT6CMdlPYLVUzOJVgGbtQ35wZ7cKhE9lrQRIvG4s65aqzQ+k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540831508873.5085747382632; Wed, 15 Oct 2025 08:07:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xg-0007m1-Lz; Wed, 15 Oct 2025 10:58:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xf-0007ls-Hd for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:43 -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 1v92xU-0000e9-Kr for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:43 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 54EF6C069F; Wed, 15 Oct 2025 17:58:25 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-NdIXGGyK; Wed, 15 Oct 2025 17:58:24 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540304; bh=IKbrDYzfqGZ1MP25DmkK99IEgBtrTVOgXHAsSgntcCY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=p4UHwpQiBzHthkp8As3f47iPRzRXTycXMfOLAty8z3rLck7D7yOAy9PxHaVNJ0fEz qMo+37CjJ2O4QPwCUfTfN6h/TxPZFEFWe10LgQZ2tajsELtIpRdgU67ZoZtJBWSVBL kYNRzeNTpHZevX9LmxWEJjcD3nc9AwUYGBCPxKpM= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v3 16/23] vhost: simplify vhost_dev_init() error-path Date: Wed, 15 Oct 2025 17:58:00 +0300 Message-ID: <20251015145808.1112843-17-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540832644154100 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 Tested-by: Lei Yang --- 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 8c5e434b89..2dba7d53c9 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1621,7 +1621,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; } } } @@ -1661,7 +1661,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 @@ -1693,17 +1693,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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540788; cv=none; d=zohomail.com; s=zohoarc; b=OKwV5Q5890uf+gZXxmff/EEeyeFnbPTQq+XBt6QSFsImAJb1D8iNfzRbggVpAYtfFPaMwLPGtJx+/HPKnMFP9Ehl6NDr9823yHfTeIhsqvK+Z4qe7wX1KIxNVgqIcTaPNcIwtHHey3jTlPGksiQG9C7iaHuV4b5rICT0w4/O03w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540788; 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=jmrcT5tiIcYvJdhiksseeBL030ZB4DWyqAsa5a1lKAQ=; b=G5JXZeUCG8CoyOCoWWilk1NNhgyUnYGH9pie+pSNdSNZjuFP+s1a9lhJLPHDy7qJoV/1UVM5jSgzr92wD/T6HHwuwjLuDcwL8o3x8PR6DS2k7a0rm/zZXuAex261hIwDcMhHxlDWFv8kfrsB3JZxMYbaA7ohQjUkYGkZjpw+kjI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540788937590.4944603169524; Wed, 15 Oct 2025 08:06:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xg-0007m3-Ol; Wed, 15 Oct 2025 10:58:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xd-0007kr-Db for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:41 -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 1v92xT-0000eA-6Q for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:41 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 0F502C050E; Wed, 15 Oct 2025 17:58:26 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-etWv9sFg; Wed, 15 Oct 2025 17:58:25 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540305; bh=jmrcT5tiIcYvJdhiksseeBL030ZB4DWyqAsa5a1lKAQ=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=hdIlpwQjJF/rvVjGebPqAgVw6YapmZkr2l0+Rbku02cz9dwGpVmzPnD0Bs/uY24BD zxadg2ncRlVKDXfzKhnsbZPs3YxYDG4WLA8GNMK8O4qr1oLVcbIJ/yqc4g2T/ZYFX/ 8MvS8af2cIBhB0i8NHhlQXseS9gyiCE/VqYd0LWw= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v3 17/23] vhost: move busyloop timeout initialization to vhost_virtqueue_init() Date: Wed, 15 Oct 2025 17:58:01 +0300 Message-ID: <20251015145808.1112843-18-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540789835158500 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 Tested-by: Lei Yang --- 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 2dba7d53c9..34846edf36 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1493,7 +1493,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 { @@ -1530,6 +1531,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: @@ -1608,24 +1617,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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540565; cv=none; d=zohomail.com; s=zohoarc; b=frv7nqCDGthshiY1Qd3SOC+bks3fs3qML6NgQ1TQcSyJZz5GEAHXaUD9QFoFDXtdtO6oPtTkfcwZQAKOBnetjU4fN4qhuQmEebaeXGJIjE0n6GU7qq5TMYCFr8htmYYQ+uK+rXSPk1wYDYjMjrK8lH0G+XqP6yEvi57dfIu3bpk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540565; 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=1/S7iH6/rmUz2u1Y049C9XSMrpfPhGe2Jbh+LATmEaU=; b=XnPM4ohidXmAWj1h0mfPmm2/s1Zpsfel6wcRYYHnO/piY4W/+7VMohShL32hMQ1nTbukRaZ4H3MdukVAgYg/bK9tDm2ZKBZLCmo6y2inVHp4dgco35Bu6QAVT37kMms3htpX1npSfmURZ08eXbnh6rg4dUyObFKS8HRiiqMGLwc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540565273873.6170208243728; Wed, 15 Oct 2025 08:02:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xw-0007o3-18; Wed, 15 Oct 2025 10:59:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xo-0007nM-JL for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:54 -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 1v92xd-0000eT-5D for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:52 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id D3B71C04DA; Wed, 15 Oct 2025 17:58:26 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-UgIqORcV; Wed, 15 Oct 2025 17:58:26 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540306; bh=1/S7iH6/rmUz2u1Y049C9XSMrpfPhGe2Jbh+LATmEaU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=TVBSZu2R4L5TRp29eCeOZ3M9cDD1TkIsbbCn+LikYo2XfTM0g8y8K7SKbAD6+l990 jD3f7DBHw2WaZjzVb3p5eM3Fsj8znkU66cgX2zDaMeNwCeb5L2biF8ke8hOabBs0cP UQP0J6n14QzSCgkbDiU6IZXHHJkQ/pNP/yGOHd5o= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v3 18/23] vhost: introduce check_memslots() helper Date: Wed, 15 Oct 2025 17:58:02 +0300 Message-ID: <20251015145808.1112843-19-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -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, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540567262158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz Reviewed-by: Daniil Tatianin Tested-by: Lei Yang --- hw/virtio/vhost.c | 71 ++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 34846edf36..56a812b06b 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1572,12 +1572,50 @@ static int vhost_dev_get_features(struct vhost_dev = *hdev, return r; } =20 +static bool check_memslots(struct vhost_dev *hdev, Error **errp) +{ + unsigned int used, reserved, limit; + + limit =3D hdev->vhost_ops->vhost_backend_memslots_limit(hdev); + if (limit < MEMORY_DEVICES_SAFE_MAX_MEMSLOTS && + memory_devices_memslot_auto_decision_active()) { + error_setg(errp, "some memory device (like virtio-mem)" + " decided how many memory slots to use based on the overall" + " number of memory slots; this vhost backend would further" + " restricts the overall number of memory slots"); + error_append_hint(errp, "Try plugging this vhost backend before" + " plugging such memory devices.\n"); + return false; + } + + /* + * The listener we registered properly setup the number of required + * memslots in vhost_commit(). + */ + used =3D hdev->mem->nregions; + + /* + * We assume that all reserved memslots actually require a real memslot + * in our vhost backend. This might not be true, for example, if the + * memslot would be ROM. If ever relevant, we can optimize for that -- + * but we'll need additional information about the reservations. + */ + reserved =3D memory_devices_get_reserved_memslots(); + if (used + reserved > limit) { + error_setg(errp, "vhost backend memory slots limit (%d) is less" + " than current number of used (%d) and reserved (%d)" + " memory slots for memory devices.", limit, used, reser= ved); + return false; + } + + return true; +} + int vhost_dev_init(struct vhost_dev *hdev, void *opaque, 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 hdev->vdev =3D NULL; @@ -1603,19 +1641,6 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opa= que, goto fail; } =20 - limit =3D hdev->vhost_ops->vhost_backend_memslots_limit(hdev); - if (limit < MEMORY_DEVICES_SAFE_MAX_MEMSLOTS && - memory_devices_memslot_auto_decision_active()) { - error_setg(errp, "some memory device (like virtio-mem)" - " decided how many memory slots to use based on the overall" - " number of memory slots; this vhost backend would further" - " restricts the overall number of memory slots"); - error_append_hint(errp, "Try plugging this vhost backend before" - " plugging such memory devices.\n"); - r =3D -EINVAL; - goto fail; - } - for (i =3D 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { r =3D vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i, busyloop_timeout); @@ -1674,23 +1699,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opa= que, memory_listener_register(&hdev->memory_listener, &address_space_memory= ); QLIST_INSERT_HEAD(&vhost_devices, hdev, entry); =20 - /* - * The listener we registered properly setup the number of required - * memslots in vhost_commit(). - */ - used =3D hdev->mem->nregions; - - /* - * We assume that all reserved memslots actually require a real memslot - * in our vhost backend. This might not be true, for example, if the - * memslot would be ROM. If ever relevant, we can optimize for that -- - * but we'll need additional information about the reservations. - */ - reserved =3D memory_devices_get_reserved_memslots(); - if (used + reserved > limit) { - error_setg(errp, "vhost backend memory slots limit (%d) is less" - " than current number of used (%d) and reserved (%d)" - " memory slots for memory devices.", limit, used, reser= ved); + if (!check_memslots(hdev, errp)) { r =3D -EINVAL; goto fail; } --=20 2.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540749; cv=none; d=zohomail.com; s=zohoarc; b=hu/PnXXNLbEvmL1396/3CgomRatNDYah0Xz61l7C7xyBWqzGY6Zir064OMxP9A/6t79msePcDrZa4nvA8T5JTHdLVzLV6ZiefbDkPT0KneHCjXJ5g9tH4wCQMryT9lbzGFdtdR3IiEPQ0W1s8ggDwx6v0Np3GGwiIcJHGTYRflM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540749; 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=e9/Yv3dJf43GhwZe5cd7CVMTYBfmA9K1KYNbAWzvgrs=; b=NRL5oHYjEhsAWF+XS3G4tXuKtoPW5oJTseAKAutzyzMInzVErVIsTodZ/IyhcdVFSOZMlr07v0mjmq0YS+Dj2i4pYnGFoQwecom0aGuEyC7IrT2d6VA3R5NwYpBHG9hvhmooMt4Ufx7lu1mWk9CtOTMpjOa0slgqfAsHb4i/sck= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540749127495.22225699270734; Wed, 15 Oct 2025 08:05:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92y3-0007qu-KU; Wed, 15 Oct 2025 10:59:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xx-0007oU-TO for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:59:01 -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 1v92xo-0000ek-FZ for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:59:01 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 9D037C0684; Wed, 15 Oct 2025 17:58:27 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-CgNmny3c; Wed, 15 Oct 2025 17:58:27 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540307; bh=e9/Yv3dJf43GhwZe5cd7CVMTYBfmA9K1KYNbAWzvgrs=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=tHaXFpdjj/xacL9NU7FuvSzwVA0zTyKbl/L12Z+1ZJI7ZSRe+s45ZZshvqJaCdp7/ j4p4kZV8yDAqFzSgCjC7NFfWUnxdCS8PrUBPFPKiQ1BRvputpBPynx8Ccrj1P0XRjq KfK5edgk7Ec/EHBfcE2Nqe71JPQnFUuGRtPuVO+M= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v3 19/23] vhost: vhost_dev_init(): simplify features initialization Date: Wed, 15 Oct 2025 17:58:03 +0300 Message-ID: <20251015145808.1112843-20-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540751753154100 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 Tested-by: Lei Yang --- 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 56a812b06b..fb5c4ba1ca 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1557,18 +1557,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 @@ -1615,7 +1614,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]; int i, r, n_initialized_vqs =3D 0; =20 hdev->vdev =3D NULL; @@ -1635,9 +1633,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 @@ -1650,8 +1648,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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540926; cv=none; d=zohomail.com; s=zohoarc; b=SFZ7MC2nafJOeosnXmvCOecdIgeAPMLIQVCLScFepqu1anBof9iMkCys3DvCVUJykBy08/cxkIequ35sCHerOsMxMCTD7846egW2KkOQZJMRTLgB1+8HtoWnsDRhGNwV3EKCrGXJDD5ZxaWv/6sZOjv8awJxXN6HpReVL1yaat4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540926; 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=Qvhx2PfrSL/sLNOgPGSepT8yXjtIZZets0wvlD0gIvE=; b=hfNCU2VUUABr/wyyYdlIEgrdLaXjGXcyO70jX8PSUDiPET90zBF0yIu1bPw9ySLZTM8lyALfXur1dgHe7s1E9qvcXjcyX7pzHtfu7y3ctf6X/pBNyuB+xeB+EE8VJSpoweEj8nErwwI/hdzr9f+a8SvH2Rz6U6GYtoBT3pnscVs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540925999841.7541678345718; Wed, 15 Oct 2025 08:08:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92y2-0007qa-IR; Wed, 15 Oct 2025 10:59:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xq-0007ng-IZ for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:56 -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 1v92xg-0000fH-VA for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:54 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 4FA5FC067C; Wed, 15 Oct 2025 17:58:28 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-rX3IEuCK; Wed, 15 Oct 2025 17:58:27 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540307; bh=Qvhx2PfrSL/sLNOgPGSepT8yXjtIZZets0wvlD0gIvE=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=0DHLyI0N1bXIgGXn88iAjOdrbyy8jf0ck0OJzGBs5im2og9Hb0OPurEhH/BVJ7WHs suagy6eQAim/oQczd/VQQshMERts1Umltwdzn4m3gHOpdeTibcf0Ts6p3nHYjPnm8j oVOR+PFOdGbHWYv6iusUff1EG2Q/Wg24TCDsQlIo= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Raphael Norwitz Subject: [PATCH v3 20/23] hw/virtio/virtio-bus: refactor virtio_bus_set_host_notifier() Date: Wed, 15 Oct 2025 17:58:04 +0300 Message-ID: <20251015145808.1112843-21-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-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=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540927690154100 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 Tested-by: Lei Yang --- 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 cef944e015..9b545acda3 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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540742; cv=none; d=zohomail.com; s=zohoarc; b=H1ERoLeaJ6MHzYNdfJd7afVFOSdqS8YBt7xjvYS8+ZWhBBZK5KTR7aQ/1xQuhw36Pr5UhsMVEczPfu/6dcK+WjLLY3rQ5rWOgsaMEW6cTN+cUoQjYVLW2Ix8iooZeOhbAftWOg03uIJP5ElXm7JYIPt7wA/mZah/W5l4BZiWuMU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540742; 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=i+Ml9JXsD0yCNdPC8wPWT5tprwkwd9kIFUUhFxR3nUM=; b=bNPOsSDGjq5svFK0jYjdvitV5v7WH3DsNrNGWeMmBDAP7GuJmgj/JgXMMfCZiEXbDTqwbVAgt4EjgS1kkYyIwgMPvrCZbi1z3CFSEtgF+pkbXNqaEJ4o6T2Hi5I+Yf5wekb+dci6hGQUWCkoonDpi14NEbS0h/9FjefjcLJQvbA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540741712879.516108178736; Wed, 15 Oct 2025 08:05:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xv-0007ny-Vp; Wed, 15 Oct 2025 10:59:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xm-0007nJ-KP for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:52 -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 1v92xf-0000fI-7c for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:50 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 32B72C0682; Wed, 15 Oct 2025 17:58:29 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-jD4PzcbG; Wed, 15 Oct 2025 17:58: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=1760540308; bh=i+Ml9JXsD0yCNdPC8wPWT5tprwkwd9kIFUUhFxR3nUM=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=SBUwL4wsvdweuvds816r74IpXihk3VLN1/xheBUQdlanumJBrdTvGJ3hLZ932V/K8 qzTPc+AlkK3hni1ZyFZeictLTJ8RIjSwQuuhrXiefuSOXdxGgpHxz6IrcYKj4atHOd WWypp59/RQg5gC4pq2pzVaX+NaVlKFpozS+2zk3M= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Raphael Norwitz Subject: [PATCH v3 21/23] vhost-user: make trace events more readable Date: Wed, 15 Oct 2025 17:58:05 +0300 Message-ID: <20251015145808.1112843-22-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-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=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540745512158500 Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Raphael Norwitz Reviewed-by: Daniil Tatianin Tested-by: Lei Yang --- hw/virtio/trace-events | 4 +- hw/virtio/vhost-user.c | 94 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 94 insertions(+), 4 deletions(-) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 658cc365e7..aa1ffa5e94 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 23e7c12b16..e45b74eddd 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -119,6 +119,94 @@ typedef enum VhostUserBackendRequest { VHOST_USER_BACKEND_MAX } VhostUserBackendRequest; =20 +static const char *vhost_req_name(VhostUserRequest req) +{ + switch (req) { + case VHOST_USER_NONE: + return "NONE"; + case VHOST_USER_GET_FEATURES: + return "GET_FEATURES"; + case VHOST_USER_SET_FEATURES: + return "SET_FEATURES"; + case VHOST_USER_SET_OWNER: + return "SET_OWNER"; + case VHOST_USER_RESET_OWNER: + return "RESET_OWNER"; + case VHOST_USER_SET_MEM_TABLE: + return "SET_MEM_TABLE"; + case VHOST_USER_SET_LOG_BASE: + return "SET_LOG_BASE"; + case VHOST_USER_SET_LOG_FD: + return "SET_LOG_FD"; + case VHOST_USER_SET_VRING_NUM: + return "SET_VRING_NUM"; + case VHOST_USER_SET_VRING_ADDR: + return "SET_VRING_ADDR"; + case VHOST_USER_SET_VRING_BASE: + return "SET_VRING_BASE"; + case VHOST_USER_GET_VRING_BASE: + return "GET_VRING_BASE"; + case VHOST_USER_SET_VRING_KICK: + return "SET_VRING_KICK"; + case VHOST_USER_SET_VRING_CALL: + return "SET_VRING_CALL"; + case VHOST_USER_SET_VRING_ERR: + return "SET_VRING_ERR"; + case VHOST_USER_GET_PROTOCOL_FEATURES: + return "GET_PROTOCOL_FEATURES"; + case VHOST_USER_SET_PROTOCOL_FEATURES: + return "SET_PROTOCOL_FEATURES"; + case VHOST_USER_GET_QUEUE_NUM: + return "GET_QUEUE_NUM"; + case VHOST_USER_SET_VRING_ENABLE: + return "SET_VRING_ENABLE"; + case VHOST_USER_SEND_RARP: + return "SEND_RARP"; + case VHOST_USER_NET_SET_MTU: + return "NET_SET_MTU"; + case VHOST_USER_SET_BACKEND_REQ_FD: + return "SET_BACKEND_REQ_FD"; + case VHOST_USER_IOTLB_MSG: + return "IOTLB_MSG"; + case VHOST_USER_SET_VRING_ENDIAN: + return "SET_VRING_ENDIAN"; + case VHOST_USER_GET_CONFIG: + return "GET_CONFIG"; + case VHOST_USER_SET_CONFIG: + return "SET_CONFIG"; + case VHOST_USER_CREATE_CRYPTO_SESSION: + return "CREATE_CRYPTO_SESSION"; + case VHOST_USER_CLOSE_CRYPTO_SESSION: + return "CLOSE_CRYPTO_SESSION"; + case VHOST_USER_POSTCOPY_ADVISE: + return "POSTCOPY_ADVISE"; + case VHOST_USER_POSTCOPY_LISTEN: + return "POSTCOPY_LISTEN"; + case VHOST_USER_POSTCOPY_END: + return "POSTCOPY_END"; + case VHOST_USER_GET_INFLIGHT_FD: + return "GET_INFLIGHT_FD"; + case VHOST_USER_SET_INFLIGHT_FD: + return "SET_INFLIGHT_FD"; + case VHOST_USER_GPU_SET_SOCKET: + return "GPU_SET_SOCKET"; + case VHOST_USER_RESET_DEVICE: + return "RESET_DEVICE"; + case VHOST_USER_GET_MAX_MEM_SLOTS: + return "GET_MAX_MEM_SLOTS"; + case VHOST_USER_ADD_MEM_REG: + return "ADD_MEM_REG"; + case VHOST_USER_REM_MEM_REG: + return "REM_MEM_REG"; + case VHOST_USER_SET_STATUS: + return "SET_STATUS"; + case VHOST_USER_GET_STATUS: + return "GET_STATUS"; + default: + return ""; + } +} + typedef struct VhostUserMemoryRegion { uint64_t guest_phys_addr; uint64_t memory_size; @@ -311,7 +399,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; } @@ -431,7 +520,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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540429; cv=none; d=zohomail.com; s=zohoarc; b=QcMMVJsZrXARQK3rmPPyua8T3iORM2O0LXXcpJo1Wss5Lt4wLo2IzSRqBG2hL3qs9MG+WUVkZw3NYDi+GEeT1V8ZnyjiwydSomWicT3//vtHWfA9iSoP2n/9Pnedj+xqOLsqwQrVd8DY1YZLUjTeLiKncqVupNa3BklgAQX8Mfc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540429; 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=wNwdu8SceSxrcW0rk9s55+OjbMtBeK9dCvm3vEfhvUE=; b=PManSkWGv2cK0DClYsWR0inrc89dcKT/zf7AEvp6oKd4Po7E94CAgJ/PyCdrDQB7XPqvdq/YUpaucKL2JC/o3ibIxCn5vlwxse65KPHnUtP1v7PyluGoVevuuAGdbcXQCtDEFnrAJk2tkehDq3WIIK0IuakecqKBMGGqTVTkkgs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176054042917170.47580566182842; Wed, 15 Oct 2025 08:00:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xk-0007n6-59; Wed, 15 Oct 2025 10:58:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xg-0007m2-Ki; Wed, 15 Oct 2025 10:58:44 -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 1v92xX-0000fV-5D; Wed, 15 Oct 2025 10:58:44 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 14900C0697; Wed, 15 Oct 2025 17:58:30 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-XKLzqHqu; Wed, 15 Oct 2025 17:58:29 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540309; bh=wNwdu8SceSxrcW0rk9s55+OjbMtBeK9dCvm3vEfhvUE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=NIiBvSgtUo6N8DQ0A35y21ATV+e46h9/ZBA/mzikqghhCzc+pEk9bs2v7J+Lson8B jFwGlzFHnmfnne/VtpVri8n/O1aaSSrYKZGqxGVNR+01ZQkqv/Xztn72C94TXZnXe5 YRvfxWGnb/J+HfKom46XvC7yC2UoD9NPAmqeS8C4= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block layer core) Subject: [PATCH v3 22/23] vhost-user-blk: add some useful trace-points Date: Wed, 15 Oct 2025 17:58:06 +0300 Message-ID: <20251015145808.1112843-23-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540434198154100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz Tested-by: Lei Yang --- 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 cc9a9f2460..dbaa5ca6cb 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 de7a810c93..a5daed4346 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; } @@ -365,6 +377,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 @@ -455,6 +469,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; @@ -514,6 +530,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.48.1 From nobody Fri Nov 14 18:23:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760540655; cv=none; d=zohomail.com; s=zohoarc; b=TUK+n5Fru8SfPiSJy/r5vJ6ZLpjlgV4yrTXpLoB7gdh0Kde6Xo0r4GfkZl0kcu1FsI0u7HOU7kBSLml9QJkEnPvDQGjgmE5BQ2fx5Vl1sChtlAU68qD6lrO239xjirgfv6eBLMNlTB8IJpBSyNl2/bVdFdcKoF3+kja2FVRPAWQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760540655; 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=vsodk9AXUS2kWNzrVElaIrmi/9pMIgvOF9+FQJJtX2g=; b=nORH26xsDYNKGpEyafDd/gcOUdPZy9rm1uzrKgLQb/HMvepLcc0aP7lAJPZDHGutAkKAor9zGmcXyCuAaC4f+HGhcPgeE/3FfcTAAu0dYKem9V3LgyULrHI6UElbg8GZ+EnrbpC8WenuMe+X7Pwocxht68d82O2KHeO+edT6p5k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1760540655826270.132087056107; Wed, 15 Oct 2025 08:04:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v92xu-0007nv-2V; Wed, 15 Oct 2025 10:58:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v92xo-0007nL-JG for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:54 -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 1v92xj-0000fv-Pe for qemu-devel@nongnu.org; Wed, 15 Oct 2025 10:58:51 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id CFB81C0678; Wed, 15 Oct 2025 17:58:30 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id AwRFIp2FFSw0-MaNMqgIP; Wed, 15 Oct 2025 17:58:30 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760540310; bh=vsodk9AXUS2kWNzrVElaIrmi/9pMIgvOF9+FQJJtX2g=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=cE3jGIS/WGabD9/OOjUTL7OverKyy/P6XCDCGnAhNyr0MENMl1fobC8yO/He+R36p 2Mj4x4piZOAlzvQCItPXd/fBoUaOToFmj9hUcjjShQT7J0MRnKtp7e3lZQz18dq3/M CBmIPSiksNnMcAoHt0jbUV3DVGnv0HPYRwZMBRWw= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v3 23/23] vhost: add some useful trace-points Date: Wed, 15 Oct 2025 17:58:07 +0300 Message-ID: <20251015145808.1112843-24-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015145808.1112843-1-vsementsov@yandex-team.ru> References: <20251015145808.1112843-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760540662259158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz Tested-by: Lei Yang --- 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 aa1ffa5e94..c2529814f9 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_virtque_start_in(void *dev, const char *name, int idx) "%p:%s %d" +vhost_virtque_start_out(void *dev, const char *name, int idx) "%p:%s %d" +vhost_virtque_stop_in(void *dev, const char *name, int idx) "%p:%s %d" +vhost_virtque_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 fb5c4ba1ca..7ba90c24db 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1333,6 +1333,8 @@ int vhost_virtqueue_start(struct vhost_dev *dev, }; struct VirtQueue *vvq =3D virtio_get_queue(vdev, idx); =20 + trace_vhost_virtque_start_in(dev, vdev->name, idx); + r =3D vhost_vrings_map(dev, vdev, vq, idx); if (r <=3D 0) { return r; @@ -1394,6 +1396,8 @@ int vhost_virtqueue_start(struct vhost_dev *dev, } } =20 + trace_vhost_virtque_start_out(dev, vdev->name, idx); + return 0; =20 fail: @@ -1412,6 +1416,8 @@ static int do_vhost_virtqueue_stop(struct vhost_dev *= dev, }; int r =3D 0; =20 + trace_vhost_virtque_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; @@ -1445,6 +1451,8 @@ static int do_vhost_virtqueue_stop(struct vhost_dev *= dev, } =20 vhost_vrings_unmap(dev, vq, true); + + trace_vhost_virtque_stop_out(dev, vdev->name, idx); return r; } =20 @@ -1616,6 +1624,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, { 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 @@ -1700,6 +1710,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: @@ -2048,7 +2060,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; @@ -2133,6 +2145,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) && @@ -2182,7 +2196,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); @@ -2212,6 +2226,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.48.1