From nobody Fri Nov 14 18:21:37 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=1760225114; cv=none; d=zohomail.com; s=zohoarc; b=cARdajzfGs+1RNMbhEbMAWj+B3k+Ua5x9bAQyHCm+e8MCiNTQArwFWqDr9amsXCexxuJW821ANsZ7TeoZrkc6ob2dJ6VHJAWLwKyIpuLBcNwK08qxkJpEQutDZ1phhLGWvK8r7tCDVqusmz7CG85n+WMFHU7Jv/tc7KnKILRtdM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225114; 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=kPANk57eCGyW2xi6VXpwOdfF/zPec2fDl+4MdLGVlPk=; b=BEFt2zOhgvuOxBnLisc5VlRM42IItzOK5cW9CNSclrYt17ldfrWtww/6pzI62euPyri4bLoZg59q7vSmBh/cKKYYYN2db/sCl8tBYob534GhT1f6L48SrBP5DokwHroZCTsoCbMXAEYrm1Dbk9rwLBWddTxjFSXY0HlGKd81Ngc= 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 1760225114966458.87681687138695; Sat, 11 Oct 2025 16:25:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwl-00069y-7L; Sat, 11 Oct 2025 19:24:19 -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 1v7iwh-00068M-Mk for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:15 -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 1v7iwf-0000r4-HE for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:15 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 6570CC01DA; Sun, 12 Oct 2025 02:24:09 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-e9wupjhW; Sun, 12 Oct 2025 02:24:08 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760225048; bh=kPANk57eCGyW2xi6VXpwOdfF/zPec2fDl+4MdLGVlPk=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=czwjZpPW/YZAZflH3sNu5+16EPdJx7rIHqUiRgXehc5IeFxSfrqoy/0K1cvKg73PC fIDOHAitjr3Pu53kK2SaY2adeO9r4h76f0fbg9VvZeZykOXkOLEaqafd417UKzrBpN ZkQtzzaTjTFGDiDpAliILNP02/u/HCVErSA6OzoA= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, "Gonglei (Arei)" , Zhenwei Pi , Jason Wang Subject: [PATCH v2 01/23] vhost-user: rework enabling vrings Date: Sun, 12 Oct 2025 02:23:40 +0300 Message-ID: <20251011232404.561024-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1760225119042154100 Content-Type: text/plain; charset="utf-8" We call the handler almost the same way in three places: - cryptodev-vhost.c - vhost_net.c - vhost.c The only difference, is that in vhost.c we don't try to call the handler for old vhost-user (when VHOST_USER_F_PROTOCOL_FEATURES is not supported). cryptodev-vhost and vhost_net code will just fail in this case. Probably they were developed only for newer vhost-user. Anyway, it doesn't seem correct to rely on this error path, if these devices want to check, that they don't communicate to old vhost-user protocol, they should do that earlier. Let's create the common helper, to call .vhost_set_vring_enable and use in all three places. For vhost-user let's just always skip enable/disable if it's unsupported. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- backends/cryptodev-vhost.c | 8 +------- hw/net/vhost_net.c | 7 +------ hw/virtio/vhost-user.c | 7 ++++++- hw/virtio/vhost.c | 21 --------------------- include/hw/virtio/vhost.h | 9 +++++++++ 5 files changed, 17 insertions(+), 35 deletions(-) diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index 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:21:37 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=1760225178; cv=none; d=zohomail.com; s=zohoarc; b=Vf7it1pTHF42I0BmIe32ATxoMJuYx33ZAcsqaNV9xdxsO7usB+HkYSIpDdJE/nuyS9w0VgxHPzYeyDgU6FzH3Uj+achxuy1FzFgEETdt7fCNc2etI6Q1eJWIX6Oipn7VZ6Yj71l+pIpJkr3H8eXljvXH4tzhWVYuWicRuSSTlGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225178; 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=2vGzStpxOn6DIJrzjS4YB1XRA5fwr4MFFMHUtdQdzNI=; b=R9kasDAHkkoUP00UBo1CNegR3jb2ocu+vw9glSIWaejQUy/huEfw51DLLf7FWkj3OiYFZCtQVqQpuqzDfp2RRO751XJ8AMw9zHlo9LhHfHt5ER0Ji7mbsi6TAb9LCQuvEJP8sU/4+mtU6rftCmtxi28TpL1Ihbuu7uzPSXAQ26E= 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 176022517816737.899866356042935; Sat, 11 Oct 2025 16:26:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwl-0006AB-S7; Sat, 11 Oct 2025 19:24:19 -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 1v7iwj-000693-LT; Sat, 11 Oct 2025 19:24:18 -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 1v7iwg-0000r6-4T; Sat, 11 Oct 2025 19:24:17 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id BB278C01DB; Sun, 12 Oct 2025 02:24:10 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-6sHTDCW2; Sun, 12 Oct 2025 02:24:09 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760225049; bh=2vGzStpxOn6DIJrzjS4YB1XRA5fwr4MFFMHUtdQdzNI=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=s12qabnwdyIJ+n/1WSkVPG2nZm2D18BxBb59VqVrAUSAXyB95Su+rvdy8P5yM+gEk jbojsPbuqJaHHckkvPgE9weFtRWHzefUQpgf2nZb93/dxbIh8Iu8iLQTmDKhhe03Ad tWn4dGhdSemJKsVNmHCGfT0ogld5o2kkpZPdqSy0= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, qemu-stable@nongnu.org, Kevin Wolf , Hanna Reitz , Jason Wang , Paolo Bonzini , Fam Zheng , Eric Blake , Markus Armbruster , qemu-block@nongnu.org (open list:Block layer core) Subject: [PATCH v2 02/23] vhost: drop backend_features field Date: Sun, 12 Oct 2025 02:23:41 +0300 Message-ID: <20251011232404.561024-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1760225181612154100 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). Let's finally do. 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: qemu-stable@nongnu.org Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Markus Armbruster Acked-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- 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:21:37 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=1760225229; cv=none; d=zohomail.com; s=zohoarc; b=bXetb4b1uYKMokN+KGh7Sc3ofc5bFgwg5Sf+eml36ib0Oj5k/in9196mmWdCKWWw9x2ekBfaPwaCLD/h3UiOlPnRFVc2PO4+MQI9hZJoon5ZNE7x89KUKacH5to+jfG0CwFphhb6kCIGy0Y8CDTyniMbEDvTCuZ+Ev6bwT5BTHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225229; 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=SqTlVhcGJ9EyDpmXzlOfNMeg33suPq7N0MPAybFtRIE=; b=MVflFYQE8KzNUQUO8yOznzPA0o1m8Llxw3N+HYBWyXS8zq4kw+en6bvXHcrY7IaNv9V403tA81p0Z6+D60dg0c04FRdgufiXmsVn1/EXjR0iqNYIiCRZNnnMlCoBQ4euy15225/QWGSnHXSEl7jc2z7CXdtk2v8Xu+lv6b7Yfm8= 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 1760225229155167.37790591979297; Sat, 11 Oct 2025 16:27:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwn-0006BW-9y; Sat, 11 Oct 2025 19:24:21 -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 1v7iwj-000692-M7 for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:17 -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 1v7iwf-0000rP-Ea for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:17 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id A52C6C01DC; Sun, 12 Oct 2025 02:24:11 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-GCqLuvXD; Sun, 12 Oct 2025 02:24:10 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760225050; bh=SqTlVhcGJ9EyDpmXzlOfNMeg33suPq7N0MPAybFtRIE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=barHOGJJFGJqOiyZgGZ8Zep2/1wbfmmQ0JYbalx066vje+7iuBipT3svxmmK1QnNS oS6KYL/2j2M5aM0ghwP3ccichzqG/rpwdboM+ts2YzCQ6t67ZFXQkFbms4oomf3VX/ Z7xsloiLSCHqXFYz3fh720Wc8I1GALczzNZmxoJE= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v2 03/23] vhost-user: introduce vhost_user_has_protocol_feature() helper Date: Sun, 12 Oct 2025 02:23:42 +0300 Message-ID: <20251011232404.561024-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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: 1760225234044158500 Content-Type: text/plain; charset="utf-8" Make all protocol feature checks in the same way. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/virtio/vhost-user.c | 120 +++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 58 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index b80174f489..b8231dcbcf 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -272,6 +272,12 @@ struct scrub_regions { int fd_idx; }; =20 +static bool vhost_user_has_protocol_feature(struct vhost_dev *dev, + uint64_t feature) +{ + return virtio_has_feature(dev->protocol_features, feature); +} + static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg) { struct vhost_user *u =3D dev->opaque; @@ -435,8 +441,8 @@ static int vhost_user_set_log_base(struct vhost_dev *de= v, uint64_t base, { int fds[VHOST_USER_MAX_RAM_SLOTS]; size_t fd_num =3D 0; - bool shmfd =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_LOG_SHMFD); + bool shmfd =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_LOG_SHM= FD); int ret; VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_LOG_BASE, @@ -1006,11 +1012,11 @@ static int vhost_user_set_mem_table(struct vhost_de= v *dev, int fds[VHOST_MEMORY_BASELINE_NREGIONS]; size_t fd_num =3D 0; bool do_postcopy =3D u->postcopy_listen && u->postcopy_fd.handler; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); bool config_mem_slots =3D - virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS); + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS); int ret; =20 if (do_postcopy) { @@ -1058,8 +1064,9 @@ static int vhost_user_set_mem_table(struct vhost_dev = *dev, static int vhost_user_set_vring_endian(struct vhost_dev *dev, struct vhost_vring_state *ring) { - bool cross_endian =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CROSS_END= IAN); + bool cross_endian =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CROSS_ENDIAN); VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_VRING_ENDIAN, .hdr.flags =3D VHOST_USER_VERSION, @@ -1129,8 +1136,9 @@ static int vhost_user_write_sync(struct vhost_dev *de= v, VhostUserMsg *msg, int ret; =20 if (wait_for_reply) { - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_REPLY_ACK); if (reply_supported) { msg->hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; } @@ -1458,8 +1466,7 @@ static int vhost_user_set_features(struct vhost_dev *= dev, ret =3D vhost_user_set_u64(dev, VHOST_USER_SET_FEATURES, features, log_enabled); =20 - if (virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_STATUS)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_STATUS)= ) { if (!ret) { return vhost_user_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); } @@ -1513,8 +1520,8 @@ static int vhost_user_reset_device(struct vhost_dev *= dev) * Historically, reset was not implemented so only reset devices * that are expecting it. */ - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_RESET_DEVICE)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_RESET_DEVICE)) { return -ENOSYS; } =20 @@ -1571,8 +1578,8 @@ static int vhost_user_backend_handle_vring_host_notif= ier(struct vhost_dev *dev, void *addr; char *name; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) || + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) || vdev =3D=3D NULL || queue_idx >=3D virtio_get_num_queues(vdev)) { return -EINVAL; } @@ -1884,13 +1891,13 @@ static int vhost_setup_backend_channel(struct vhost= _dev *dev) }; struct vhost_user *u =3D dev->opaque; int sv[2], ret =3D 0; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); Error *local_err =3D NULL; QIOChannel *ioc; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_BACKEND_REQ)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ)) { return 0; } =20 @@ -2138,8 +2145,8 @@ static int vhost_user_postcopy_notifier(NotifierWithR= eturn *notifier, =20 switch (pnd->reason) { case POSTCOPY_NOTIFY_PROBE: - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_PAGEFAULT)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_PAGEFAULT)) { /* TODO: Get the device name into this error somehow */ error_setg(errp, "vhost-user backend not capable of postcopy"); @@ -2230,7 +2237,7 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, } =20 /* query the max queues we support if backend supports Multiple Qu= eue */ - if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_MQ)= ) { err =3D vhost_user_get_u64(dev, VHOST_USER_GET_QUEUE_NUM, &dev->max_queues); if (err < 0) { @@ -2248,18 +2255,18 @@ static int vhost_user_backend_init(struct vhost_dev= *dev, void *opaque, } =20 if (virtio_has_feature(features, VIRTIO_F_IOMMU_PLATFORM) && - !(virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_BACKEND_REQ) && - virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_ACK))) { + !(vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ) && + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_REPLY_ACK))) { error_setg(errp, "IOMMU support requires reply-ack and " "backend-req protocol features."); return -EINVAL; } =20 /* get max memory regions if backend supports configurable RAM slo= ts */ - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS)= ) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS)) { u->user->memory_slots =3D VHOST_MEMORY_BASELINE_NREGIONS; } else { err =3D vhost_user_get_max_memslots(dev, &ram_slots); @@ -2281,8 +2288,8 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, } =20 if (dev->migration_blocker =3D=3D NULL && - !virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_LOG_SHMFD)) { + !vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_LOG_SHMFD)) { error_setg(&dev->migration_blocker, "Migration disabled: vhost-user backend lacks " "VHOST_USER_PROTOCOL_F_LOG_SHMFD feature."); @@ -2351,8 +2358,8 @@ static bool vhost_user_requires_shm_log(struct vhost_= dev *dev) { assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_USER); =20 - return virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_LOG_SHMFD); + return vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_LOG_SHMFD); } =20 static int vhost_user_migration_done(struct vhost_dev *dev, char* mac_addr) @@ -2367,8 +2374,7 @@ static int vhost_user_migration_done(struct vhost_dev= *dev, char* mac_addr) } =20 /* if backend supports VHOST_USER_PROTOCOL_F_RARP ask it to send the R= ARP */ - if (virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_RARP)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_RARP)) { msg.hdr.request =3D VHOST_USER_SEND_RARP; msg.hdr.flags =3D VHOST_USER_VERSION; memcpy((char *)&msg.payload.u64, mac_addr, 6); @@ -2382,11 +2388,11 @@ static int vhost_user_migration_done(struct vhost_d= ev *dev, char* mac_addr) static int vhost_user_net_set_mtu(struct vhost_dev *dev, uint16_t mtu) { VhostUserMsg msg; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); int ret; =20 - if (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_NET_MTU)= )) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_NET_MT= U)) { return 0; } =20 @@ -2446,8 +2452,7 @@ static int vhost_user_get_config(struct vhost_dev *de= v, uint8_t *config, .hdr.size =3D VHOST_USER_CONFIG_HDR_SIZE + config_len, }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIG)) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_CONFIG= )) { error_setg(errp, "VHOST_USER_PROTOCOL_F_CONFIG not supported"); return -EINVAL; } @@ -2490,8 +2495,8 @@ static int vhost_user_set_config(struct vhost_dev *de= v, const uint8_t *data, { int ret; uint8_t *p; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); =20 VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_CONFIG, @@ -2499,8 +2504,7 @@ static int vhost_user_set_config(struct vhost_dev *de= v, const uint8_t *data, .hdr.size =3D VHOST_USER_CONFIG_HDR_SIZE + size, }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIG)) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_CONFIG= )) { return -ENOTSUP; } =20 @@ -2535,8 +2539,9 @@ static int vhost_user_crypto_create_session(struct vh= ost_dev *dev, uint64_t *session_id) { int ret; - bool crypto_session =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CRYPTO_SESSIO= N); + bool crypto_session =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CRYPTO_SESSION); CryptoDevBackendSessionInfo *backend_info =3D session_info; VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_CREATE_CRYPTO_SESSION, @@ -2637,8 +2642,9 @@ static int vhost_user_crypto_close_session(struct vhost_dev *dev, uint64_t session_id) { int ret; - bool crypto_session =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CRYPTO_SESSIO= N); + bool crypto_session =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CRYPTO_SESSION); VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_CLOSE_CRYPTO_SESSION, .hdr.flags =3D VHOST_USER_VERSION, @@ -2683,8 +2689,8 @@ static int vhost_user_get_inflight_fd(struct vhost_de= v *dev, .hdr.size =3D sizeof(msg.payload.inflight), }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { return 0; } =20 @@ -2751,8 +2757,8 @@ static int vhost_user_set_inflight_fd(struct vhost_de= v *dev, .hdr.size =3D sizeof(msg.payload.inflight), }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { return 0; } =20 @@ -2851,8 +2857,7 @@ void vhost_user_async_close(DeviceState *d, =20 static int vhost_user_dev_start(struct vhost_dev *dev, bool started) { - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_STATUS)) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_STATUS= )) { return 0; } =20 @@ -2877,16 +2882,15 @@ static void vhost_user_reset_status(struct vhost_de= v *dev) return; } =20 - if (virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_STATUS)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_STATUS)= ) { vhost_user_set_status(dev, 0); } } =20 static bool vhost_user_supports_device_state(struct vhost_dev *dev) { - return virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_DEVICE_STATE); + return vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_DEVICE_STATE); } =20 static int vhost_user_set_device_state_fd(struct vhost_dev *dev, --=20 2.48.1 From nobody Fri Nov 14 18:21:37 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=1760225200; cv=none; d=zohomail.com; s=zohoarc; b=GpRNaUs0M7cGyLbnS/CtqUFUtsijT/bkcZki4LkSKyi1imDrjvX6t39Rpk4SR/V/coeMxD5ddGOzzxaV1Hj1JCtCnESG1JlwchlcuK1tNTJB+xN6Te0tOBAxxUMwmJoGL7KKLPXhIugX7fSqdcRolM0rQPWOefgXkRLyD3umyKg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225200; 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=03IuelRDIS50tGxI+U6wAMi9oT18Y8qRE+dfG16mOKs=; b=g1Rv2g4F9iomiP52PEy54Wcnj6cbUHE+VieB0C19e3XHgZQS95vrep2cypF4YOz9RvEtGMp8oHGqNNwtUmAM0WrI5VhOJqSAsnhTLvj7qPbZ15bC6h5yfGdi/2NWMy52AXTT7k1VW/Bl/3CEpgMKQtwaXQFRR+JrB6ycr3E8k4E= 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 1760225199970192.83813141702308; Sat, 11 Oct 2025 16:26:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwo-0006Bu-9m; Sat, 11 Oct 2025 19:24:22 -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 1v7iwj-00068q-A7 for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:17 -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 1v7iwg-0000rc-Ag for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:17 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 09939C01DD; Sun, 12 Oct 2025 02:24:13 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-9p0QMlHa; Sun, 12 Oct 2025 02:24: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=1760225052; bh=03IuelRDIS50tGxI+U6wAMi9oT18Y8qRE+dfG16mOKs=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=FGCXcutK//xjpmSncpM9FhMDDz3AKdIMuGcNZ548or3b71Pwm8EGGtUvhicT7dPZl jg5l79AxamAj1Iyu6OESCwnevnWA8RupLBKaW4LoRkEdnYVtOQ7zy7WeZgCIaJM3/s N+yK+U0P/yHDJDU0Y0rzqg+bhMB/oxkc8hf3VPcE= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, "Gonglei (Arei)" , Zhenwei Pi , Jason Wang Subject: [PATCH v2 04/23] vhost: move protocol_features to vhost_user Date: Sun, 12 Oct 2025 02:23:43 +0300 Message-ID: <20251011232404.561024-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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: 1760225201674154100 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 --- 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:21:37 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=1760225213; cv=none; d=zohomail.com; s=zohoarc; b=XOVNcmrHK1sNV6FAVCOyApVdH8IJXz67cAo/Zg3t2TPK3uwQk7ga5nGCFbjOQ3ZzRed1G6a9COku53ALvgjRXlRaz0S4x6+6xL2JHuOnfgEEC+B1d0yHktg4qe3ImjDMKB6YeWNO0KXyFF04ClL+d5JPnRmp7vid+6GkgCMeowc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225213; 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=4mJ1VHuBdwLrb2ySHOOnurFjpRGws2FgUP8esS7AlX8=; b=BAAg/ai9KfreY+WdgDJTtbaATKmLlThOSxHU2P70tkEgZRGEzz1PtNgC8L0p5p61aBXP0CDicQuFkJUdEu7KUQI4K+mXp6W+trokRYjKezWjFHleP+yaWKRyC97TOnxqf6Wv+z8KVAJo726yenbjQ/1eqQfpc/q7vqYwXtTSz14= 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 176022521348823.181128172290414; Sat, 11 Oct 2025 16:26:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwm-0006AS-9V; Sat, 11 Oct 2025 19:24:20 -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 1v7iwi-00068c-RX for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:16 -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 1v7iwh-0000rj-7h for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:16 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id B5074C01DE; Sun, 12 Oct 2025 02:24:13 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-itmZIpX6; Sun, 12 Oct 2025 02:24:13 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760225053; bh=4mJ1VHuBdwLrb2ySHOOnurFjpRGws2FgUP8esS7AlX8=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=EGB5D6U1uzVqwMMLTCsNsvAnGC1AhJov8RL/0ZV049lzqHf6wXbP7vOrEkIhwOZzH ZREyCrRoBwFmEp7PEtBr6aX5a7FFdVTyN+njG7Il7ma5CrXosm/VOH3rBZZZocR6jl tpOiJBjxC8em/oWyTSg14NZgSL5HAPMOQyF2LWeI= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v2 05/23] vhost-user-gpu: drop code duplication Date: Sun, 12 Oct 2025 02:23:44 +0300 Message-ID: <20251011232404.561024-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1760225215673154100 Obviously, this duplicated fragment doesn't make any sense. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/display/vhost-user-gpu.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 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:21:37 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=1760225204; cv=none; d=zohomail.com; s=zohoarc; b=d2G9J0/efJmjeLAcxXprFTJfXfRFGl1ewfPc6zMHQDudmON2VY8417AeXx92tXkfrTd/swvQ0WFmBl67mab5gY4L+HvcRmgaauQuBnG+AczhjU3XMkWD4JDHqC/yCbDUibKudue8wDukbyAyI1n4aA5y8GNpu00ug9FTxzZhl/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225204; 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=Y2BY6NHjkhdhS9INpn6O9BZitHvaS3f/owmgS2hRSTo=; b=NESbJ/udY47vk8Mbd99bQz8x3O01dPIBW6iIGry+ppqgj6dmLN8LOc2MaFQ7/t+rrY5Yhs8CzG0gzVQTVZMDErRodYOTQzJ4DzOB/XQQTxNjTgXZ7B5UK62JAi5XVIAVu07QS6gIrZmvGexIAiVvdSDveFhy+hmYTYnGVuxr7yw= 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 1760225204905888.3578488547402; Sat, 11 Oct 2025 16:26:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwn-0006At-3f; Sat, 11 Oct 2025 19:24:21 -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 1v7iwk-00069Z-QC for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:18 -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 1v7iwi-0000rv-6B for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:18 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id D3D7FC01E0; Sun, 12 Oct 2025 02:24:14 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-r8SB4UMO; Sun, 12 Oct 2025 02:24: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=1760225054; bh=Y2BY6NHjkhdhS9INpn6O9BZitHvaS3f/owmgS2hRSTo=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=knjbMEO+rT2FwghYctIlmyuqPB+U33l3ixStrlioQWz1bAR9ce9BiymIfVT/ZL9JU whZleyLvJGDwkKCvmMLVq4ZXF3DzjUjk/tZ1G2TXblgsIwIYGDIr/+2S0WSjqFM+Fc Lhv/VdpMQ7Qo8Sb6riAP4+X0p8PF3hfJhELwxq/o= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, 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 v2 06/23] vhost: make vhost_dev.features private Date: Sun, 12 Oct 2025 02:23:45 +0300 Message-ID: <20251011232404.561024-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1760225205924154100 Content-Type: text/plain; charset="utf-8" It's hard to control where and how do we use this field. Let's cover all usages by getters/setters, and keep direct access to the field only in vhost.c. It will help to control migration of this field in further commits. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin --- hw/display/vhost-user-gpu.c | 7 +++---- hw/net/vhost_net.c | 18 +++++++++--------- hw/virtio/vdpa-dev.c | 2 +- hw/virtio/vhost-user-base.c | 8 ++++++-- hw/virtio/vhost-user.c | 4 ++-- hw/virtio/vhost.c | 6 +++--- hw/virtio/virtio-qmp.c | 2 +- include/hw/virtio/vhost.h | 27 +++++++++++++++++++++++++-- net/vhost-vdpa.c | 7 +++---- 9 files changed, 53 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..773b91c0a0 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(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(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..e4e4526ca8 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.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,28 @@ 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_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_ex(&dev->_features, 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:21:37 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=1760225214; cv=none; d=zohomail.com; s=zohoarc; b=Zlio+8JilPPAmwgBFXqVYVJ8hYqDaRz1l5ebJD8GqDMSlyeH38VklxvWm2EgFDnmpif4cegLwQmJ4weEXGkDa2nlFySEuzout85zr6ujTyGUf4TMBJYCIq1h/m+/uhb4qNiF8QZTvH9GbMJ+3vlT2M1GJiC1oMV/kajzj7ALCis= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225214; 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=RkPVkseQdp11g9w6+LT6/uIFZi6PpJlNShC1n+zz4dI=; b=EcPmYvWtYydoAOdMnm4jl9G8gnLO6FZGL3BYDpVCxtfqAU96wgXiuDasCem8rUFTfmcRVoKYAYwu7WlqzLO1Qi/uFGcNT+cty6/sX+jMI5G+WCS9vq8Na8C5ONF7cIHaMExgZIcF6VOTFZ/MOFnUenSIysRU5sMmD+9+Gjh0WTQ= 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 1760225214769368.3900226962447; Sat, 11 Oct 2025 16:26:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwo-0006C0-Bt; Sat, 11 Oct 2025 19:24:22 -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 1v7iwl-00069z-9x for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:19 -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 1v7iwj-0000sG-24 for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:18 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id C4595C01D9; Sun, 12 Oct 2025 02:24:15 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-by7Ewwdx; Sun, 12 Oct 2025 02:24: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=1760225055; bh=RkPVkseQdp11g9w6+LT6/uIFZi6PpJlNShC1n+zz4dI=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=CLZKrCKgcPo5JFxyProDctbCrIAZw4h41wmhFbTYU4FlPlqO/R2ai2X5ZFEGj1ngr sj2sKwwyGLhbiuSNHHphA6MgssnScwUc/rWwSw9XRyidj7gRZbCbpoJ2QeU9tFlpj9 5cLIxbvDG53ljbsxvUjiibvFp4Tm3fg0og1FbqmQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v2 07/23] virtio: move common part of _set_guest_notifier to generic code Date: Sun, 12 Oct 2025 02:23:46 +0300 Message-ID: <20251011232404.561024-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1760225215849154100 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 --- 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:21:37 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=1760225202; cv=none; d=zohomail.com; s=zohoarc; b=C59WTcBIcJQ5KQVp+fdFPf/mcY+s/U81cuMfbi9WhcFWy+5RzaikeTquByUQo682jox4GKH8+DwdOrreJimASl1ADYn5+25yCx3hqLD4hre6V1dPr/LoCrunDkWYK+9eOD7Ae1Roi1Cs5/sUjAtOBfmVp+YmMoA1V9t8xcX4XwA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225202; 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=7iBWtw0Z0kHa8ERnbSROoIy5jXfRFBDMUrdw3WpYWrc=; b=afK/wS/LwMUmoDgwpTGEIrzE5r1fVJwdzoZlNxf2dp0vj3+VHN2Ze8QYJjF72Er4TCc2mjDwK02p38Ed2NeIaF5wWYFpsWCZ67X1ngEjJszXfU0xDlL4Tpal5t36F3zMqEedF39bQlRFj7UuFwTHUGDDOmfMTUcAyvfawHQkCEw= 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 1760225202938888.5794904221676; Sat, 11 Oct 2025 16:26:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwp-0006D1-DT; Sat, 11 Oct 2025 19:24:23 -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 1v7iwl-0006AC-Rv for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:19 -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 1v7iwj-0000sW-Up for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:19 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 93C50C01E2; Sun, 12 Oct 2025 02:24:16 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-16vv4Tzx; Sun, 12 Oct 2025 02:24: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=1760225056; bh=7iBWtw0Z0kHa8ERnbSROoIy5jXfRFBDMUrdw3WpYWrc=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=MBF4El27PTihiYdXpMT/rv73p2ZRWBwf3IoYx3Q8K864pcTz8XWqa7eGrxRr6C5qa aAmtttU7Vi77wx/DZ4PX0f9WhetV6bfIxWMZK5JftBs6IZO79FqqJsBQyvsI6oJyab pzTnRsB2Zp4Nfq5qFJJslB16fWPFvdlcAfdAiqyc= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v2 08/23] virtio: drop *_set_guest_notifier_fd_handler() helpers Date: Sun, 12 Oct 2025 02:23:47 +0300 Message-ID: <20251011232404.561024-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1760225203706154100 Content-Type: text/plain; charset="utf-8" Now they don't make code more readable. Let's better put the whole logic into virtio_queue_set_guest_notifier(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin --- hw/virtio/virtio.c | 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:21:37 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=1760225185; cv=none; d=zohomail.com; s=zohoarc; b=bLefX4YLIzFxV8NVJB6uzBoz2DPXL/tNjFK4ZuLkEcAxPh78q5BJln/Meu2oIO7l1CghjmDWcy0+7VVjCuHeUoE54cHnb0QpdhE2hPhD1TDgGil/XyKVglcIn386W9DRZPv5VMuUKLJojjfNiPEsklv18GRQ3zJ5aDFFFWEsZEc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225185; 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=oM6dB5UP+eH8D0StIMh+lrqt58h5lQe6HbACeTqCRDo=; b=ekPNTmxHLBAmvhQMbNVV+UrunK7ErIaYVozUHEM+2RCMprmhGX/2x/gjtfCey9zcx8jo5CPt840E/KYBDxaiIn4nV5QV5Cefpzt/dT3Hf388CLyR7nkEO9E8KTtfSMtCvq2KQ51nkU+80yAmH34mA4E6Pw/GaI2JWAv0fyEKmeE= 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 1760225185138882.2506145261718; Sat, 11 Oct 2025 16:26:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwq-0006DH-2B; Sat, 11 Oct 2025 19:24:24 -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 1v7iwm-0006AY-66 for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:20 -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 1v7iwk-0000sl-HC for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:19 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 485F3C01DE; Sun, 12 Oct 2025 02:24:17 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-VZsBO5c8; Sun, 12 Oct 2025 02:24: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=1760225056; bh=oM6dB5UP+eH8D0StIMh+lrqt58h5lQe6HbACeTqCRDo=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=mblRoPRLdrh+yr1bxUZbAf9Ih15HM2VyXCNi2PlB20dFI4u1pEvbiUfVMnZOIMp+w /Qvew2UPzoz4ttXXZnyECjaBbBfvKF4FN4o5nkY2Q+1BsW4p4gSSBR7SuKAzguomiv 3XAPnzbVXu2YZ02CqljpT0WBd3sG6Ls4lbnu/YK8= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v2 09/23] vhost-user: keep QIOChannelSocket for backend channel Date: Sun, 12 Oct 2025 02:23:48 +0300 Message-ID: <20251011232404.561024-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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: 1760225187374154100 Content-Type: text/plain; charset="utf-8" Keep QIOChannelSocket pointer instead of more generic QIOChannel. No real difference for now, but it would be simpler to migrate socket fd in further commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/virtio/vhost-user.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 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:21:37 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=1760225238; cv=none; d=zohomail.com; s=zohoarc; b=Z34h9NPxl8SthZsp4x3wBmsubkIZ2XOFcl8vL0EWjyvOfUMYHQdy30L7FqeR69McmKXb01A9Ux8QMvqpEg2dZvsXrZLBS3SeOwF4pToroC/+3Gv69e8XIonp3kLjrkD4MumvAF8myZ9B5Y3F5q6vjQd+fZgc9diOgnBgh1N48Ak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225238; 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=0qYWlMlHRcMke3GhvkwqdwZLc5N5XbXutJHC8scvnU0=; b=BaJS0WdYThtu0HV0a8zlA8NYn2fjBxJ0eJM9pai2qyO2+rGb2Z+pnh9iEmkwk6XQug3TdFxtTaQTS7p/SLQEsotUl/MPoUe3LLllp5Ca5d3EnITHsgxH7vE3LJKb//LLgonbl1kfxGk+x21gCDxylNJhLoiWIhTzjmpIH0OtMLI= 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 1760225238339360.8310696140139; Sat, 11 Oct 2025 16:27:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwo-0006CY-Re; Sat, 11 Oct 2025 19:24:22 -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 1v7iwn-0006B1-1C for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:21 -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 1v7iwl-0000sv-Ah for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:20 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 1B0F0C01DB; Sun, 12 Oct 2025 02:24:18 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-J4YcHnyt; Sun, 12 Oct 2025 02:24: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=1760225057; bh=0qYWlMlHRcMke3GhvkwqdwZLc5N5XbXutJHC8scvnU0=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=mMNiTR4eiCLi8GZWnQS539bkuCbYpa+Rw755zGJzGTZbPnVo4oer9uIdilngkc0Wa GIOzH0EmniVGwbdg5ZtuaOEwqp7V2LgOL+2G/hwqkak3BEst2lhlbRE7DMEX1f9rm3 y0MKIdmz9Kamvg5Of9TTgysHUSlQ1JKZLEiUkUcA= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v2 10/23] vhost: vhost_virtqueue_start(): fix failure path Date: Sun, 12 Oct 2025 02:23:49 +0300 Message-ID: <20251011232404.561024-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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: 1760225239948154100 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 --- 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 773b91c0a0..8031c74e7b 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:21:37 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=1760225155; cv=none; d=zohomail.com; s=zohoarc; b=bUI73YdOomgj8gC35rU/cSAMlC3swqmbPYfX44bFwTn7ixPt6+3MYaFZkS42/fi+tZLGtWtWnHcXOMeWuUmGxWt0bj/c+h2L6mdE7nKp46QcfFHiAyNLVviR9kAp5pUjra75XGT8Gj3DKZQQZENrbI+ace5ujRP2D4G4/svTYaI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225155; 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=lnmrNOdH9PiRJ6qfAMMgLMUKPbunmPfqaClpCsSkPRM=; b=GEU8EblT+PgLbvj3/RpppVE5/SByRLQriXxsH8SgXB9A0gQHorYvLdaeAcoY3NxzfY2xXKRd6rPY8lFzvnyp6GCccvBi8aOhEXpLLTCRf3tMsIvUrofbioq3j6IM/yINEOTLrdonyEIi5LrmKxNerAjVSdeG0UbjafoKZB4zPGE= 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 1760225155859244.14488087446648; Sat, 11 Oct 2025 16:25:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwr-0006Dm-4b; Sat, 11 Oct 2025 19:24:25 -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 1v7iwn-0006Br-UK for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:22 -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 1v7iwm-0000t8-3Y for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:21 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id C4ABBC01DC; Sun, 12 Oct 2025 02:24:18 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-AOZ2PORW; Sun, 12 Oct 2025 02:24: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=1760225058; bh=lnmrNOdH9PiRJ6qfAMMgLMUKPbunmPfqaClpCsSkPRM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=rBrkvocJrduEtCy2znmVy7Mkr7KS6qt04/5JeJoj+cx7CV1gHyuD25o1sMry2YWSX ZrCBDfPki6SdU/TRWc5X34CrX9wp930tTFTYD5y/Xpln9K1gfihbMcqXJ8oDIbpR4n zkOmegFyHP9QZrrxA7cSpwMz2MUxoohz1hOBYL/w= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v2 11/23] vhost: make vhost_memory_unmap() null-safe Date: Sun, 12 Oct 2025 02:23:50 +0300 Message-ID: <20251011232404.561024-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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: 1760225157398158500 Content-Type: text/plain; charset="utf-8" This helps to simplify failure paths of vhost_virtqueue_start() a lot. We also need to zero-out pointers on unmap, to not try to unmap invalid pointers. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 8031c74e7b..6fec193d5f 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:21:37 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=1760225245; cv=none; d=zohomail.com; s=zohoarc; b=JG/OAJ0UJQLP79DjEkfQU2q+CHkfn9Z7bOVosLB+D6lbr4J2cFc1ah9gcfQu3EJAa8YA0lryLJWPwPLTSfBcPPVUbcj/SIdluINIPDMv00uvZEDpgFa+VubPRYltt1EM+pfeM0yVijHZdUfqMcbQJb+VkD35Cgx6ZTPXiyjBxto= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225245; 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=VfCRh10wp9awipccg7WiKA37wsZY3PMD5spjGWMcQj4=; b=E2CMWPT1e6pJf9b5KWaLrOE/Hy956E15vnzQX7wC9AB/R0GFCDO3OjUTHI+jC9YRvhtFMS7cHZ4qCzFa0w3PPfrc3/5N1Y8a0s+SVmQmrL5oGhOQdb6/zz+/lcr249ljdQr264ZD2v3+/8/IhFAbN+RrD2ec+ts3imLtrtuWWxE= 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 1760225245815481.78589405767457; Sat, 11 Oct 2025 16:27:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwr-0006EN-QQ; Sat, 11 Oct 2025 19:24:25 -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 1v7iwp-0006D2-EN for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:23 -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 1v7iwm-0000tO-Q7 for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:23 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 83046C01DA; Sun, 12 Oct 2025 02:24:19 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-0eh1ic6W; Sun, 12 Oct 2025 02:24: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=1760225059; bh=VfCRh10wp9awipccg7WiKA37wsZY3PMD5spjGWMcQj4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=zKYqEqCoh8osd2A02gobfyVv427vdh141CnVVFHrxMGwzuiLm1oyKZ8XAiUMNRayf jVyemaKa9sam61SECHikVbDShubnXsHnoqfzAxoKvR/D+9iF5RVt9EKeyHGgirXTRA vEE3qpNT8eoS4YaYvmEo0IriM3QRW2c7EwWmvF2E= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v2 12/23] vhost: simplify calls to vhost_memory_unmap() Date: Sun, 12 Oct 2025 02:23:51 +0300 Message-ID: <20251011232404.561024-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1760225248036154100 Content-Type: text/plain; charset="utf-8" No reason to calculate memory size again, as we have corresponding variable for each vring. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 6fec193d5f..e00ba9ecc8 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:21:37 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=1760225134; cv=none; d=zohomail.com; s=zohoarc; b=Iatmd0UvD6kllJ1A/9rZI+jAgVh1t8KaZ5xMhDCsBL2jwzDF6tgpnJ1K6IuAlUSI32R4MyQLMdiZ21s4AktTLCQewZ6sD0HHifZ0+IELT8JwBmgFlZFRQtE/ygMQCroGaCRLQBqKDLl8NK4pn8KzCqlpB2GgVazmVs+HPMYgDjE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225134; 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=u27L2M8u6j1kppFVUbBMCV7tSqAkvFYG75S8wBcpS5M=; b=Pax83d1yTqLbcfMh2ExoSoGmSnMlObVbzkeMpCfQ3KtyvObJ5PG4a3hnsc2IQBbAek4nFU2sRk/Hu8tanEYi/Ob4x3HI5X0g38EEI0uEqUnUYNbtxQlm6c2p+cj1HK3MaED16FwiwzoC3MmWs2e/YlvqyOO9Roco7Ib4VeZGd10= 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 1760225134186885.8377347716048; Sat, 11 Oct 2025 16:25:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwt-0006FR-A2; Sat, 11 Oct 2025 19:24: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 1v7iwq-0006DN-3Q for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:24 -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 1v7iwo-0000tZ-De for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:23 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 25266C01D9; Sun, 12 Oct 2025 02:24:20 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-cYrSavS7; Sun, 12 Oct 2025 02:24: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=1760225059; bh=u27L2M8u6j1kppFVUbBMCV7tSqAkvFYG75S8wBcpS5M=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=FCzOM/MzVamUN/ahrHpqUar7lI8P54hsJOKB1adnvpGCj2xSUWt0e18j4n67tGXeo 0STl8rFVj/4KEPhSV7AXfcGsrYPYQyRW/NSZnvLpbmoVzP61S587LaxbqOjiXVbANB 6T5OJc10EBfE/D26qqNsjIsfpqDV6sSmX0wkhZM4= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v2 13/23] vhost: move vrings mapping to the top of vhost_virtqueue_start() Date: Sun, 12 Oct 2025 02:23:52 +0300 Message-ID: <20251011232404.561024-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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: 1760225138977158500 Content-Type: text/plain; charset="utf-8" This simplifies further refactoring and final introduction of vhost backend live migration. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/virtio/vhost.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index e00ba9ecc8..7390385876 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:21:37 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=1760225186; cv=none; d=zohomail.com; s=zohoarc; b=AHGzx6w2bIcJLR4NM65j0qd1NaI/KlIHA/GLxe5BDy0PV8zG7/nCHEPcro7NUvpbXuBxk7vukO+3OMcMK8lMB2emfQCz1rB0roTr0pwJg06iVKuteLQiwmhBSzN8kKQVeq4QsnJOHa44mqH0kQ4LX+0Zs7kq1Jkj8jDUDWXceTk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225186; 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=qYZfcwllKjUj6UaRjGgKCTD4vkqsayoZmnl4mcq1nK4=; b=fT0OvjpNp/lFtpUoBi2KGOjME9N4UH/ZtOSit4KCnPCTNiSm9PRniKH7egelizIGyaOQnIMLmol9iKZR4+tV3vd1Lu2otZLwOoszC/gl1PiYTZnheA03PbCY0AI9wGq2/kDSrW3Dy26B/WTmkMBVaFRuSze65Rhc1wAW1XS/cmU= 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 17602251864691002.757103968127; Sat, 11 Oct 2025 16:26:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwu-0006G6-LA; Sat, 11 Oct 2025 19:24:28 -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 1v7iwp-0006D6-Jg for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:23 -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 1v7iwo-0000tj-0L for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:23 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id BC960C01E0; Sun, 12 Oct 2025 02:24:20 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-S5QKNkcL; Sun, 12 Oct 2025 02:24: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=1760225060; bh=qYZfcwllKjUj6UaRjGgKCTD4vkqsayoZmnl4mcq1nK4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=p/B/FmdnQ+QZIMwJhcihKRxYV5mSgcwW95Q6/cNzwunKpjoJs9tHDVsYnbxAm24xo z4+pM9vmCpF7fLF+dUQvWzfgDJCCkNPF6s19/Qn4QaMJEkegfXPhqIDQaw5fzR7jX6 OrKHW2uE1a+/VBNv3GOtMpGaM/xXN0EKjnNJffL0= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v2 14/23] vhost: vhost_virtqueue_start(): drop extra local variables Date: Sun, 12 Oct 2025 02:23:53 +0300 Message-ID: <20251011232404.561024-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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: 1760225191624158500 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 --- 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 7390385876..cc07450dcb 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:21:37 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=1760225197; cv=none; d=zohomail.com; s=zohoarc; b=fI8tw6xz8PtsrXlOzBUKOuROqVvdQ9eJwmVy6Wl4yfEL/bcSeCDuqCjEhUwItA668TiY0tMCFq7MEnDnwVZ5xPLjO1VUBHZmGEsqzYZt2aGPENRBRAaGi/1qYhdikt+PoaPy020Kt7oY0nsw8xqoqzGlJlOD2IxqCGPKOlUPZuk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225197; 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=uMh/dZ/uonyTO1ezn9fw9bl7wDtRi1TtdrctK7PE95k=; b=MixJ+cKDbxpoyx9kYL7vT6H4l70ZgTBXtrJPCfWd8D5AwYw6rNDMM0mLrmrQQGCbNneIdICvhb2BkwlKk8FSYJyvw4/KNHlBCT17xSy+W5EMFB540qr44xiXni2XtPKYjI9nAqnWnZdR1h+NHeDy9Vh7KjLcy4DDKxEp9nz1usY= 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 1760225197886919.7173641898547; Sat, 11 Oct 2025 16:26:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwt-0006FD-4G; Sat, 11 Oct 2025 19:24: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 1v7iwr-0006Du-AO for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24: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 1v7iwo-0000tt-Of for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:25 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 6A98FC01DD; Sun, 12 Oct 2025 02:24:21 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-jTS1LAGG; Sun, 12 Oct 2025 02:24: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=1760225060; bh=uMh/dZ/uonyTO1ezn9fw9bl7wDtRi1TtdrctK7PE95k=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=qdSmguYH9MijkppxiD1YdeRn1Bj8fGPbgacUZC7Bre6Z5k7qrs+NS/7yoAeUdqwjA vahocoibVu8a0EIJlKjswmG5G0Zwc2TDoeTEV6JA1LFN7bbc1kBtQOn9H0c63NozYc PlIkShdhsTfLHRRmfnKfgsvMRKU3nNa9ynGP9Uc8= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v2 15/23] vhost: final refactoring of vhost vrings map/unmap Date: Sun, 12 Oct 2025 02:23:54 +0300 Message-ID: <20251011232404.561024-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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: 1760225199567158500 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 --- 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 cc07450dcb..ebdea096aa 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:21:37 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=1760225222; cv=none; d=zohomail.com; s=zohoarc; b=Zbiz1/HpTaKP0tlB7cIeqXGKHCds6e/bn6QP0164CgVVd3vxc4b6V6+nE/0yDUO4O+x7UszvI09lfk352KSm1I30xSxyb/64EGQ5/12bXzxXIX4Sak73NDEI/LmVSxytlDi3aVNcopHP+vq8YKPHnOGGWqWaSAQ2np02YxJYjcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225222; 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=XEvi3adXzXhv3hAtbmzh4wUci3ltl+p6RB499smUSBU=; b=kfiYVTP1PJO7BD3m2S7FRPCZSxkAaHJD5VagsYSRiVdk1RwqkdyEE8MNj2x1V0ObPZA+qvQsp7v6/MEjrQzUsqUA03ROjqfHYIbVYq5d0rh+0YgruhTU1O5iCVRwnW7ksz4j98nxfZi1MLY3vemlXM2TbYnQKwPEy0xQMOlbc+s= 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 1760225222036759.5528537483972; Sat, 11 Oct 2025 16:27:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iws-0006EU-DA; Sat, 11 Oct 2025 19:24:26 -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 1v7iwr-0006Dl-0v for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:25 -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 1v7iwp-0000u4-Ae for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:24 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 0419DC01DB; Sun, 12 Oct 2025 02:24:22 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-VDDfSdew; Sun, 12 Oct 2025 02:24: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=1760225061; bh=XEvi3adXzXhv3hAtbmzh4wUci3ltl+p6RB499smUSBU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Lq1squkTiglGqIQ6hn7fqI2FKU0Sn6+PEm/XrZcBPmTt4viZfLNgAD/2Q0/Nj0qa7 ZyAqjWvRqTHmqgTxNM14Fbt9fKMTjxNqnUDEl7VoRhuiXvEOy+54/RW6vgRQAK9pMi f3UKlieDyQ3WQaZpE5G7nZDkwhVW09cidd58tw4Q= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v2 16/23] vhost: simplify vhost_dev_init() error-path Date: Sun, 12 Oct 2025 02:23:55 +0300 Message-ID: <20251011232404.561024-17-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1760225223773158500 Content-Type: text/plain; charset="utf-8" No reason to rollback setting up busyloop timeout on failure. We don't do such rollback for other things we setup in backend. Also, look at vhost_net_init() in hw/net/vhost_net.c: we may fail after successfully called vhost_dev_init(), and in this case we'll just call vhost_dev_cleanup(), which doesn't rollback busyloop timeout. So, let's keep it simple. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/virtio/vhost.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index ebdea096aa..188ea0f955 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:21:37 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=1760225201; cv=none; d=zohomail.com; s=zohoarc; b=nigVPEzi7H55JeMnwMC9qZjUrx/tpg6uHxWAl0UaTQtxX4m36+W9elPgVHGllHByMTVaSfJHp4ymWSd5P642yXqvtJl5fENx6NmkVjkkk6DJeXD4R4Wo+pIsaxrWQzewZCFAbc51XcveVzhVjn6R5rJw/FcNdwsj2pXPwXrJUEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225201; 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=jZOBOlTwZdT6WnA6Ykh1BoX7JewxPnDdD4bXRwoAqAA=; b=jUNPKluvqBWjK5fvHZUt3ay17TXq5yDVCF8lIQlhDQxop5SbHzu3tSnp7LXVf3sGlVYaRdnWpEvETR2w+i7aYS1MkgI0nOU5Jy8CUVDJzJI5nOQz+Gvh+ced/Wo9ohLjgohdb7MNcQPlqQOvRGHXnV+r6Jh2ZasxbxHqH42najw= 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 1760225201034703.4502514745291; Sat, 11 Oct 2025 16:26:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iws-0006En-Pw; Sat, 11 Oct 2025 19:24:26 -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 1v7iwr-0006Dz-Hf for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:25 -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 1v7iwp-0000uC-VL for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:25 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 9B69FC01DC; Sun, 12 Oct 2025 02:24:22 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-moRAbouJ; Sun, 12 Oct 2025 02:24: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=1760225062; bh=jZOBOlTwZdT6WnA6Ykh1BoX7JewxPnDdD4bXRwoAqAA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=vY2G5GeIAlh567/T+JK2Xr5AxAUR6Jv/H3hOgqBKfgai/80zgnseTo2mxPuN4n17C BWHuZ1+ts+L+Y4MK970Y+Jk3Y8z2bZvwcUheL5ccTbLWWR9NdC/BjaFAuFvhTSdHIr VQ+4ZUDoKbPerIPu2zE6DpBVFk2hd1cMZb/n+Z6g= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v2 17/23] vhost: move busyloop timeout initialization to vhost_virtqueue_init() Date: Sun, 12 Oct 2025 02:23:56 +0300 Message-ID: <20251011232404.561024-18-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1760225203525158500 Content-Type: text/plain; charset="utf-8" Let's all per-virtqueue initializations be in one place. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/virtio/vhost.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 188ea0f955..8ba97c231b 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:21:37 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=1760225205; cv=none; d=zohomail.com; s=zohoarc; b=IMjXZohzUMMiRBcOMYVOtaCz+LheUOa+oHX3EICBrFsHpuT1Gcg4fgrB8RpYnHUa6mvH26kok39m8tDsAPEbyantFTuu4qLAVLj8vZdhb7GD+W/wBWOoDCwdLUV/ieq/AyknOqvzBgIZzevh3k96F1LHwt1+HA1KKqxRIW1xYkU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225205; 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=WN5yuwTmhtU1R4aUfiR8bSsIlHXGKve2ZsnRiu3lKQ4=; b=EB3Uh4uFqeYlCj/UOvaUaTyv4fPQGCl1LUdH5i7mAvTGBNaoSjyH2cGagKzv5mIcSiGkR6vVZR9VUsTlBJwwmi9gRKgWAZy0ncpDSOxKS1LtW6RdHe+UTBKBG8EqwrE2Nr4XvjlKv5ccfrXEEMUrWgD2kfixjdXEDzraJ6l0e2Q= 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 1760225205789872.1057074133415; Sat, 11 Oct 2025 16:26:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwu-0006Fw-HI; Sat, 11 Oct 2025 19:24:28 -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 1v7iws-0006F0-V0 for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:26 -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 1v7iwq-0000uV-Ou for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:26 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 544C2C01DA; Sun, 12 Oct 2025 02:24:23 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-dLmyNdO4; Sun, 12 Oct 2025 02:24: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=1760225062; bh=WN5yuwTmhtU1R4aUfiR8bSsIlHXGKve2ZsnRiu3lKQ4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Ua04rSKfwuLK7FDd1r/TJValNMgRcKJqI35LbeF5M51XRQshQkyG+z6SxCo5BXWGl G+5na8b4CWxrbevpSnVCAolyEgWn7bO9Qtc0DxEvEE/+V1xrARWRZzayi96P8Wl9TQ vAucYtiYkNytFfGKnRg5CrutZ3qkP5Q2vqrafO9c= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v2 18/23] vhost: introduce check_memslots() helper Date: Sun, 12 Oct 2025 02:23:57 +0300 Message-ID: <20251011232404.561024-19-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1760225207624154100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- 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 8ba97c231b..c990029756 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:21:37 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=1760225165; cv=none; d=zohomail.com; s=zohoarc; b=PoHDU0TgWd36u8QbrYph8j7twaihd5HW1R1NIX9401OX93pqOeQwQMGnaiYYhsZTZHiEnHbuB7qQLzD+1CaP1sMaQGXdYId0mw6MW8xVj+YhjNoAsta2w/3awhLqPfPOp4GCsqtqflPaTr9FsfQoyp88viryVTFmRll2ZGV+S94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225165; 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=OMhmUaU9DNTaQUYOhlrO4kclp+J0BsKC+ljy90fIMbc=; b=goGIif28TZ6XFHwQXnzfSUJYKYWc+htIFDPV/iMoUNAZFqvKTyfQz9oeMmEIqKO6nl8moNO54I+zMIXmH8xh0Mxufb3ICSnFNs+HCs4lTvjkS483SDsAW6qQ+2ZJd0F7aPQeGd5TdOnxQp3o9pxeJCaKY0r7gUh2DhVRA+j4Olo= 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 1760225165229133.4241734673269; Sat, 11 Oct 2025 16:26:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iww-0006GQ-HN; Sat, 11 Oct 2025 19:24: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 1v7iws-0006F1-VQ for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:26 -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 1v7iwr-0000ug-8B for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:26 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id E1579C01D9; Sun, 12 Oct 2025 02:24:23 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-jCIlRWQX; Sun, 12 Oct 2025 02:24: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=1760225063; bh=OMhmUaU9DNTaQUYOhlrO4kclp+J0BsKC+ljy90fIMbc=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=GaGr/8GiV0WNXrjz7Pyc/YAExVacom948D7y/uveE1cCYgYZMPHARisla2Nvhluof bruXYTaoC7usBSTJCYo7Vvm3NViLCRmyjZNVSQ4V6YLkNWF6ZcrCiXoU213yK6F63u 50o9qejSqgHZST87KJUEQKhjlUo2TsK5cOlvPSOY= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v2 19/23] vhost: vhost_dev_init(): simplify features initialization Date: Sun, 12 Oct 2025 02:23:58 +0300 Message-ID: <20251011232404.561024-20-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1760225167272158500 Content-Type: text/plain; charset="utf-8" Drop extra variable and extra function parameter passing, initialize dev._features directly. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index c990029756..d02d1d4c34 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:21:37 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=1760225125; cv=none; d=zohomail.com; s=zohoarc; b=dyzTaE31EQBLtB1FKTbLoorAIeoVmssxaFPYRPi6jrG7h0saSJuiXplq3eMbP7o+d7ZSnI2vX3cf6b4nY+elPz/Ini/Ejc+oLqGr8msZLu0Olp+qjgi/Qr+n4oVJ8celJLxChKFqxe/HpY9DqmgT65TFyrhySECMmKb5N4tYzcc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225125; 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=Ekk4/4NZiDIN7M1T5bcaSvl+AxuaOFAFrcEe704nZ4k=; b=j39lW7H/r0GjVQvkeYPb0D65OAKpSG33hlm4oYYmxMH/T6jW9s7pjAqOIuHPNs+qVT07SbnjNDMyRjrvB7P0rpA39nyuCM43D2Sh0/vbFekw6FWxGF1HEWm/OMu2X6ETVAQy9GhgcSiUfWvuAs/EgH3LSfStCPacvtwZ2s99YPA= 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 1760225125742353.67864053415167; Sat, 11 Oct 2025 16:25:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iwv-0006GK-KO; Sat, 11 Oct 2025 19:24: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 1v7iwt-0006FU-KK for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24: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 1v7iwr-0000un-PG for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:27 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 784F0C01E0; Sun, 12 Oct 2025 02:24:24 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-ph9kBoOd; Sun, 12 Oct 2025 02:24: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=1760225064; bh=Ekk4/4NZiDIN7M1T5bcaSvl+AxuaOFAFrcEe704nZ4k=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=wxnHuzkZgEFelTg0wUNtXIeb1rLLWSHK9JN39pvLBrFVxcUYGbTJs0ndmTz/eTSXd aL5onNgcxDmuIJiq43zd/yax1D6Td9YF1yzpvrb9yPSitS5qBLXE7Rx/AQ2T6V3LRn 8l0aX/OoA1abdInlpD8HlP1wGKUrIedZV4aUoA9A= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 20/23] hw/virtio/virtio-bus: refactor virtio_bus_set_host_notifier() Date: Sun, 12 Oct 2025 02:23:59 +0300 Message-ID: <20251011232404.561024-21-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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: 1760225127528158500 The logic kept as is. Refactor to simplify further changes. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/virtio/virtio-bus.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index 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:21:37 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=1760225113; cv=none; d=zohomail.com; s=zohoarc; b=Ao8c+Ph43t5XWsSb1mtBKP/KgYh6Ob+69qzE34/mPcdzLPrYRwpGGJ08GB/i9hlYJQCSL+HVbd3EhpxuZ5jkM7QwmhFnFA4PfgddQOPVeqVtaQYCf1JNUXfyzmN6JW1ElLvBIm38eoUGOahBPbaLGm2E/O6YF0dBeUKb/6SlfNo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225113; 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=mv1f7ZZ2zJbNKP6/QSP2QCtxNPErA8wy445npUZiAX8=; b=Oeh4cddIduFEUkCI8KpWTdYkiPdQlZaZTFrXgvXmm8bmgZSYwwHu/1KIPWMFwNNIiliMcj/H76PHoqAfRDMsRhu3RZvptxH8d2NQuKVyVRY59VqS0NUwwqlG2ByOVz4+OApoRMm1gtsk1GiCIrrGY0kSKhA+vYMxJTTOjm31voU= 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 1760225112729905.9417430662152; Sat, 11 Oct 2025 16:25:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7ixA-0006KV-Gj; Sat, 11 Oct 2025 19:24: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 1v7ix9-0006KG-Fb for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24: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 1v7ix2-0000vM-Mk for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:43 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 40328C01DB; Sun, 12 Oct 2025 02:24:25 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-I8Sta8FG; Sun, 12 Oct 2025 02:24: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=1760225064; bh=mv1f7ZZ2zJbNKP6/QSP2QCtxNPErA8wy445npUZiAX8=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=JbTtPRckx7LXn+3mhOU1SNk1jyBQKG8AdqhzVnm8BTLu38RZ7wkgVPzGpSnlxWhkC pEZkPYFCsGH2tY2V/jsq8KsJbhSFanyn/uNMdoTFtbTXrv4LDDsp35w9qEOtx4QE71 gHfW/MW0d6BFuv9GNz+tixU21fjOiKjvoGbLfEiM= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 21/23] vhost-user: make trace events more readable Date: Sun, 12 Oct 2025 02:24:00 +0300 Message-ID: <20251011232404.561024-22-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1760225118289158500 Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- 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:21:37 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=1760225113; cv=none; d=zohomail.com; s=zohoarc; b=FqOiqGpgPlRHU38xi8TYZJlEp9We2MRjNyLEzgtNv4owI/G+HU2anfbFZK5qxnrdj+a+zqahHYvH7Z4qqL4bQfaIWlyskLE3hvj5BhwCtLvzKUmSteu1pnIKgG8aYcs9szGZApl3lqOgYqp0dgZeElPNTOWm/AiFFdjVcsSeoas= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225113; 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=PS6EEAn7WwmtDz3cXTZkOLfrAiCnkxUt9LIG5+06S44=; b=SSzbNF93ViLEKRBCXDW/bq7BRf12/m5qBNxown8eIAzsS7A3B9t9taULbJZJ45Dc6xbieI15UCOfNsVIN8GssKUE0yZX0qdtP3cPlWapeD/NsRMY4VYzbbN3Y1DsmgBEfZ+2BGafawctW26SuIzWOAMIpGIAODkp2PvS93C3wwg= 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 1760225113162297.8489667196276; Sat, 11 Oct 2025 16:25:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7iww-0006Gf-SQ; Sat, 11 Oct 2025 19:24: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 1v7iwv-0006GD-8Q; Sat, 11 Oct 2025 19:24:29 -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 1v7iwt-0000vV-FK; Sat, 11 Oct 2025 19:24:28 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id E7F97C01DC; Sun, 12 Oct 2025 02:24:25 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-9fZfG4D6; Sun, 12 Oct 2025 02:24: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=1760225065; bh=PS6EEAn7WwmtDz3cXTZkOLfrAiCnkxUt9LIG5+06S44=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Buws9hFtKKpFf4+AjYBzUI9t4jTOGVHAggL2aZW0YZexcYsam08H1R1gmiYxwn5yF pvCWzNMESunON6wyZ6OtgbLXH/jl9jsucdFjaElssRy5jBF65O2/7h29qWjCsYaVCN KLiuqX0DT9B9YA5EmO9oAln4Xcgs9lBLn+O/L5tg= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block layer core) Subject: [PATCH v2 22/23] vhost-user-blk: add some useful trace-points Date: Sun, 12 Oct 2025 02:24:01 +0300 Message-ID: <20251011232404.561024-23-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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: 1760225118068154100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/block/trace-events | 10 ++++++++++ hw/block/vhost-user-blk.c | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/hw/block/trace-events b/hw/block/trace-events index 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:21:37 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=1760225136; cv=none; d=zohomail.com; s=zohoarc; b=ZxGZzsAFTfOCkM/kP0yhL13LglVdBbaQkW8tnuAu1VNjvbWrQzfnACoIqMLv6cLevPQiJyQdkBwqyB+rpOu8XvjyUeqKVp8CfmyDmFUa3WXriTrxoP7pjuisGXOUK4VevlcjPRPLx1GqjwyvSm5jyIUiBA/bmxl5UztamcngV14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760225136; 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=rkKDNqLmUfNjo4O0c7dmnMJaKIu8C/BqjUGQSszHpfU=; b=MifGsiNruSojknKX8WcRu/clQ0Ce514Wpx2mQYQoz/KlL9V7KEjithXdDM58EJgoMfrxBkauMJd1EgvE4Nl5omWTdnSwlZz1Y7y28km7X1n1Ry6JSR5oov0OiOZwIK/eLFqgbPEJv8yXxT08zZtt3AKbdhCGaAsQQ/1FrOA+ODs= 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 1760225136801553.2153785273694; Sat, 11 Oct 2025 16:25:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v7ix7-0006Jt-8M; Sat, 11 Oct 2025 19:24: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 1v7ix5-0006JF-O9 for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:39 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7ix3-0000vl-To for qemu-devel@nongnu.org; Sat, 11 Oct 2025 19:24:39 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 9B627C01DD; Sun, 12 Oct 2025 02:24:26 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a4b::1:3c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6OWMXt1FjqM0-W9WADeRZ; Sun, 12 Oct 2025 02:24: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=1760225066; bh=rkKDNqLmUfNjo4O0c7dmnMJaKIu8C/BqjUGQSszHpfU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=z3+o7rhGTlgGdX+V011HX40aWdfxWoTCschahxUEhVHWcFrOHT7EQ6j8lZ8urzR7C p+LUU2/sSpTPfEzE6Xa+jMpZUBaEJPUYWZU3kNTJYOCHfVUVX7PZS4oq8YlrBHY5vl JkeyOwe/tKGSOAD95UnLhav1HdeQ2O4ILiCzNO1s= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.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, raphael.s.norwitz@gmail.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v2 23/23] vhost: add some useful trace-points Date: Sun, 12 Oct 2025 02:24:02 +0300 Message-ID: <20251011232404.561024-24-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251011232404.561024-1-vsementsov@yandex-team.ru> References: <20251011232404.561024-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: 1760225138977158501 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/virtio/trace-events | 12 ++++++++++-- hw/virtio/vhost.c | 20 ++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 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 d02d1d4c34..f15ef8cff6 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