From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715495; cv=none; d=zohomail.com; s=zohoarc; b=cNNUiHQXrxfsHs5fMdqptJfSeNjDPIrKhzeAGERGpW/r7lH0JoDRrDwxtcuOg8hCij/H7Cj1vdd8vmumbjiSpXhDEcfhxwzzA1ypethfoK/hksmYsuEWiB/XP4fGvltbyjfcAKPgDLmi/3MX10m4Dckp+q7eBxgeAjjHfjgi8wM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715495; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=52WD3FWkb0j8c8h/V6OhMQSzRC7zRqnFb8vo6zNsGZg=; b=Vq0KsETs3Zu0mkFDtWeoY759qnw+OJgJafR2HvvFmPxEO446i+CUxr2cMBpKFX9NFAbMpDEL/oACbQsH1rqdIgBPg+8nlaxDy8k0xHXNPPi2toTPuv8p8Lj98jqfTBzEZIqVDBbz0SO9xk9+3AfcGaf+aZ0OG0davgonOoLHUcw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715495405189.95033613197165; Mon, 20 Apr 2026 13:04:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEuqy-0001Zs-15; Mon, 20 Apr 2026 16:04:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqf-0001K8-2n for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:03 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqX-0001k3-Gf for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:03:56 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 82F9780676; Mon, 20 Apr 2026 23:03:47 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-TnnmZKyo; Mon, 20 Apr 2026 23:03:46 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1776715426; bh=52WD3FWkb0j8c8h/V6OhMQSzRC7zRqnFb8vo6zNsGZg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=lYZu89zoESSoM73r3pjAG/uovZAQo2PlEpfAq+cDIC2A8J7SHnMH3dg1YHk6B2ONP d94fZToDPSyl/fja2FBMe9xhyi6jcBeh9OE2757N/MgPD7TFN2m3vvKFM8BLRpDHJx dBVKgIt+XiVY7HMRSEf3Ow3g8DXIu2BgwoejC9j0= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz , "Gonglei (Arei)" , zhenwei pi , Jason Wang Subject: [PATCH v6 01/22] vhost-user: rework enabling vrings Date: Mon, 20 Apr 2026 23:03:16 +0300 Message-ID: <20260420200339.708640-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715496494154100 Content-Type: text/plain; charset="utf-8" We call the handler almost the same way in three places: - cryptodev-vhost.c - vhost_net.c - vhost.c The only difference, is that in vhost.c we don't try to call the handler for old vhost-user (when VHOST_USER_F_PROTOCOL_FEATURES is not supported). cryptodev-vhost and vhost_net code will just fail in this case. Probably they were developed only for newer vhost-user. Anyway, it doesn't seem correct to rely on this error path, if these devices want to check, that they don't communicate to old vhost-user protocol, they should do that earlier. Let's create the common helper, to call .vhost_set_vring_enable and use in all three places. For vhost-user let's just always skip enable/disable if it's unsupported. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- backends/cryptodev-vhost.c | 8 +------- hw/net/vhost_net.c | 7 +------ hw/virtio/vhost-user.c | 7 ++++++- hw/virtio/vhost.c | 21 --------------------- include/hw/virtio/vhost.h | 9 +++++++++ 5 files changed, 17 insertions(+), 35 deletions(-) diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index 943680a23af..abdfce33afc 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -152,7 +152,6 @@ vhost_set_vring_enable(CryptoDevBackendClient *cc, { CryptoDevBackendVhost *crypto =3D cryptodev_get_vhost(cc, b, queue); - const VhostOps *vhost_ops; =20 cc->vring_enable =3D enable; =20 @@ -160,12 +159,7 @@ vhost_set_vring_enable(CryptoDevBackendClient *cc, return 0; } =20 - vhost_ops =3D crypto->dev.vhost_ops; - if (vhost_ops->vhost_set_vring_enable) { - return vhost_ops->vhost_set_vring_enable(&crypto->dev, enable); - } - - return 0; + return vhost_dev_set_vring_enable(&crypto->dev, enable); } =20 int cryptodev_vhost_start(VirtIODevice *dev, int total_queues) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index a8ee18a9126..25e9f1fd244 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -587,7 +587,6 @@ VHostNetState *get_vhost_net(NetClientState *nc) int vhost_net_set_vring_enable(NetClientState *nc, int enable) { VHostNetState *net =3D get_vhost_net(nc); - const VhostOps *vhost_ops =3D net->dev.vhost_ops; =20 /* * vhost-vdpa network devices need to enable dataplane virtqueues after @@ -601,11 +600,7 @@ int vhost_net_set_vring_enable(NetClientState *nc, int= enable) =20 nc->vring_enable =3D enable; =20 - if (vhost_ops && vhost_ops->vhost_set_vring_enable) { - return vhost_ops->vhost_set_vring_enable(&net->dev, enable); - } - - return 0; + return vhost_dev_set_vring_enable(&net->dev, enable); } =20 int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index a8907cca74e..13c73e7b178 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1230,7 +1230,12 @@ static int vhost_user_set_vring_enable(struct vhost_= dev *dev, int enable) int i; =20 if (!virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES)= ) { - return -EINVAL; + /* + * For vhost-user devices, if VHOST_USER_F_PROTOCOL_FEATURES has n= ot + * been negotiated, the rings start directly in the enabled state, + * and can't be disabled. + */ + return 0; } =20 for (i =3D 0; i < dev->nvqs; ++i) { diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index b9dc4ed13ba..b89797df95e 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -2078,27 +2078,6 @@ int vhost_dev_get_inflight(struct vhost_dev *dev, ui= nt16_t queue_size, return 0; } =20 -static int vhost_dev_set_vring_enable(struct vhost_dev *hdev, int enable) -{ - if (!hdev->vhost_ops->vhost_set_vring_enable) { - return 0; - } - - /* - * For vhost-user devices, if VHOST_USER_F_PROTOCOL_FEATURES has not - * been negotiated, the rings start directly in the enabled state, and - * .vhost_set_vring_enable callback will fail since - * VHOST_USER_SET_VRING_ENABLE is not supported. - */ - if (hdev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_USER && - !virtio_has_feature(hdev->backend_features, - VHOST_USER_F_PROTOCOL_FEATURES)) { - return 0; - } - - return hdev->vhost_ops->vhost_set_vring_enable(hdev, enable); -} - /* * Host notifiers must be enabled at this point. * diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 89817bd8486..3dfec5e15cc 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -215,6 +215,15 @@ static inline bool vhost_dev_is_started(struct vhost_d= ev *hdev) return hdev->started; } =20 +static inline int vhost_dev_set_vring_enable(struct vhost_dev *hdev, int e= nable) +{ + if (!hdev->vhost_ops->vhost_set_vring_enable) { + return 0; + } + + return hdev->vhost_ops->vhost_set_vring_enable(hdev, enable); +} + /** * vhost_dev_start() - start the vhost device * @hdev: common vhost_dev structure --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715587; cv=none; d=zohomail.com; s=zohoarc; b=oHJGmRc0/F9ARcJdkEgLwzRm+jSWiXXLEWl44zVCQu+g7jL3BRc4wn043/sW0wVeIzbBjSQdgrKjs89+8WviKK6/PeO4x8qGFV6O6W3ED1G9ht65zwapiOo9G5Q4+9kgAbvxOjiqCs+q1wrr31COHOcERqdNwJpyWsXrhrWZCXA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715587; 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=Gkxf+me90eN6ZhWRVM0cpnIRnA6GgN0WsU3pUhxePJg=; b=ZBXvbGGwvW39u2kGXQJlff5xslRlyaNR7tzE4MZFzE8aFoQADqDM+ZRiEhBmctTbZEADl+e3EzD8ZdipVLwBZK+Tjy8W7mPH+eWoT8bk7WNv2HFvxSWhdU4aPc+6w5yYhmult4T4gOsCgSxLcd8pB0DUw/Q1cyHd0nVfFn6ow3w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715587313650.9715330525172; Mon, 20 Apr 2026 13:06:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEur3-0001mG-Ey; Mon, 20 Apr 2026 16:04:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqf-0001KB-3f; Mon, 20 Apr 2026 16:04:04 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqW-0001kG-Tg; Mon, 20 Apr 2026 16:03:57 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id B666780725; Mon, 20 Apr 2026 23:03:50 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-JhIwtFtH; Mon, 20 Apr 2026 23:03:49 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1776715430; bh=Gkxf+me90eN6ZhWRVM0cpnIRnA6GgN0WsU3pUhxePJg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=FyY28VTBtzookzoqAbpTHZE0UzivXrg+YR1m5lPHxhHT5RciOATqk5V7e7DTUhcF0 OjOkgflKkq8Dbgyf77ZaWWMrl+NXY2ENqozTw+P83ntjUaiFWweLVbQLgnLNfanK1c MTrjV9+bC/kZV0TmSCQHUAY1scqyL6HwH5YnppEg= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, devel@lists.libvirt.org, Markus Armbruster , Raphael Norwitz , Raphael Norwitz , Kevin Wolf , Hanna Reitz , Jason Wang , Paolo Bonzini , Fam Zheng , Eric Blake , qemu-block@nongnu.org (open list:Block layer core) Subject: [PATCH v6 02/22] vhost: drop backend_features field Date: Mon, 20 Apr 2026 23:03:17 +0300 Message-ID: <20260420200339.708640-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715588325154100 Content-Type: text/plain; charset="utf-8" This field is mostly unused and sometimes confusing. We even have a TODO-like comment to drop it, the comment is removed in this commit. The field is used to held VHOST_USER_F_PROTOCOL_FEATURES for vhost-user and/or VHOST_NET_F_VIRTIO_NET_HDR for vhost-net (which may be vhost-user-net). But we can simply recalculate these two flags in place from hdev->features, and from net-client for VHOST_NET_F_VIRTIO_NET_HDR. Note: removing field from x-query-virtio-status result is incompatible change. We can do it because the command is unstable. Cc: devel@lists.libvirt.org Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Markus Armbruster Reviewed-by: Daniil Tatianin Acked-by: Raphael Norwitz --- hw/block/vhost-user-blk.c | 1 - hw/net/vhost_net.c | 26 ++++++++++++++------------ hw/scsi/vhost-scsi.c | 1 - hw/scsi/vhost-user-scsi.c | 1 - hw/virtio/vdpa-dev.c | 1 - hw/virtio/vhost-user.c | 17 ++++++++--------- hw/virtio/virtio-hmp-cmds.c | 2 -- hw/virtio/virtio-qmp.c | 4 ---- include/hw/virtio/vhost.h | 7 ------- qapi/virtio.json | 3 --- 10 files changed, 22 insertions(+), 41 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index c151e836770..dc99de02635 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -348,7 +348,6 @@ static int vhost_user_blk_connect(DeviceState *dev, Err= or **errp) s->dev.nvqs =3D s->num_queues; s->dev.vqs =3D s->vhost_vqs; s->dev.vq_index =3D 0; - s->dev.backend_features =3D 0; =20 vhost_dev_set_config_notifier(&s->dev, &blk_ops); =20 diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 25e9f1fd244..fda90e231e6 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -52,8 +52,14 @@ int vhost_net_set_config(struct vhost_net *net, const ui= nt8_t *data, =20 void vhost_net_ack_features_ex(struct vhost_net *net, const uint64_t *feat= ures) { - virtio_features_copy(net->dev.acked_features_ex, - net->dev.backend_features_ex); + virtio_features_clear(net->dev.acked_features_ex); + if (net->backend =3D=3D -1) { + net->dev.acked_features =3D + net->dev.features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES); + } else if (!qemu_has_vnet_hdr(net->nc)) { + net->dev.acked_features =3D 1ULL << VHOST_NET_F_VIRTIO_NET_HDR; + } + vhost_ack_features_ex(&net->dev, net->feature_bits, features); } =20 @@ -258,12 +264,9 @@ struct vhost_net *vhost_net_init(VhostNetOptions *opti= ons) if (r < 0) { goto fail; } - net->dev.backend_features =3D qemu_has_vnet_hdr(options->net_backe= nd) - ? 0 : (1ULL << VHOST_NET_F_VIRTIO_NET_HDR); net->backend =3D r; net->dev.protocol_features =3D 0; } else { - virtio_features_clear(net->dev.backend_features_ex); net->dev.protocol_features =3D 0; net->backend =3D -1; =20 @@ -284,13 +287,12 @@ struct vhost_net *vhost_net_init(VhostNetOptions *opt= ions) net->dev.features &=3D ~(1ULL << VIRTIO_NET_F_MRG_RXBUF); } =20 - if (virtio_features_andnot(missing_features, - net->dev.backend_features_ex, - net->dev.features_ex)) { - fprintf(stderr, "vhost lacks feature mask 0x" VIRTIO_FEATURES_= FMT - " for backend\n", VIRTIO_FEATURES_PR(missing_features)); - goto fail; - } + if (!qemu_has_vnet_hdr(options->net_backend) && + (~net->dev.features & (1ULL << VHOST_NET_F_VIRTIO_NET_HDR))) { + fprintf(stderr, "vhost lacks feature mask 0x%llx for backend\n= ", + ~net->dev.features & (1ULL << VHOST_NET_F_VIRTIO_NET_H= DR)); + goto fail; + } } =20 /* Set sane init value. Override when guest acks. */ diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index 699863cc109..859888fdbaf 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -275,7 +275,6 @@ static void vhost_scsi_realize(DeviceState *dev, Error = **errp) vqs =3D g_new0(struct vhost_virtqueue, vsc->dev.nvqs); vsc->dev.vqs =3D vqs; vsc->dev.vq_index =3D 0; - vsc->dev.backend_features =3D 0; =20 ret =3D vhost_dev_init(&vsc->dev, (void *)(uintptr_t)vhostfd, VHOST_BACKEND_TYPE_KERNEL, 0, errp); diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index 3612897d4b9..5070178dc28 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -159,7 +159,6 @@ static int vhost_user_scsi_connect(DeviceState *dev, Er= ror **errp) vsc->dev.nvqs =3D VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; vsc->dev.vqs =3D s->vhost_vqs; vsc->dev.vq_index =3D 0; - vsc->dev.backend_features =3D 0; =20 ret =3D vhost_dev_init(&vsc->dev, &s->vhost_user, VHOST_BACKEND_TYPE_U= SER, 0, errp); diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c index 4532d63653e..06179e402e4 100644 --- a/hw/virtio/vdpa-dev.c +++ b/hw/virtio/vdpa-dev.c @@ -104,7 +104,6 @@ static void vhost_vdpa_device_realize(DeviceState *dev,= Error **errp) v->dev.vqs =3D vqs; v->dev.vq_index =3D 0; v->dev.vq_index_end =3D v->dev.nvqs; - v->dev.backend_features =3D 0; v->started =3D false; =20 ret =3D vhost_vdpa_get_iova_range(v->vhostfd, &iova_range); diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 13c73e7b178..7ce17c5b2d8 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1465,14 +1465,15 @@ static int vhost_user_set_features(struct vhost_dev= *dev, int ret; =20 /* - * We need to include any extra backend only feature bits that - * might be needed by our device. Currently this includes the - * VHOST_USER_F_PROTOCOL_FEATURES bit for enabling protocol - * features. + * Don't lose VHOST_USER_F_PROTOCOL_FEATURES, which is vhost-user + * specific. */ - ret =3D vhost_user_set_u64(dev, VHOST_USER_SET_FEATURES, - features | dev->backend_features, - log_enabled); + if (virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES))= { + features |=3D 1ULL << VHOST_USER_F_PROTOCOL_FEATURES; + } + + ret =3D vhost_user_set_u64(dev, VHOST_USER_SET_FEATURES, features, + log_enabled); =20 if (virtio_has_feature(dev->protocol_features, VHOST_USER_PROTOCOL_F_STATUS)) { @@ -2192,8 +2193,6 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, (dev->config_ops && dev->config_ops->vhost_dev_config_notifier= ); uint64_t protocol_features; =20 - dev->backend_features |=3D 1ULL << VHOST_USER_F_PROTOCOL_FEATURES; - err =3D vhost_user_get_u64(dev, VHOST_USER_GET_PROTOCOL_FEATURES, &protocol_features); if (err < 0) { diff --git a/hw/virtio/virtio-hmp-cmds.c b/hw/virtio/virtio-hmp-cmds.c index 1daae482d37..4bf9a3109d4 100644 --- a/hw/virtio/virtio-hmp-cmds.c +++ b/hw/virtio/virtio-hmp-cmds.c @@ -176,8 +176,6 @@ void hmp_virtio_status(Monitor *mon, const QDict *qdict) hmp_virtio_dump_features(mon, s->vhost_dev->features); monitor_printf(mon, " Acked features:\n"); hmp_virtio_dump_features(mon, s->vhost_dev->acked_features); - monitor_printf(mon, " Backend features:\n"); - hmp_virtio_dump_features(mon, s->vhost_dev->backend_features); monitor_printf(mon, " Protocol features:\n"); hmp_virtio_dump_protocols(mon, s->vhost_dev->protocol_features); } diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c index f9cdca50d99..71717c56a41 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -710,8 +710,6 @@ VirtioStatus *qmp_x_query_virtio_status(const char *pat= h, Error **errp) vdev->guest_features_ex); status->host_features =3D qmp_decode_features(vdev->device_id, vdev->host_features_ex); - status->backend_features =3D qmp_decode_features(vdev->device_id, - vdev->backend_features_ex= ); =20 switch (vdev->device_endian) { case VIRTIO_DEVICE_ENDIAN_LITTLE: @@ -752,8 +750,6 @@ VirtioStatus *qmp_x_query_virtio_status(const char *pat= h, Error **errp) qmp_decode_features(vdev->device_id, hdev->features_ex); status->vhost_dev->acked_features =3D qmp_decode_features(vdev->device_id, hdev->acked_features_ex); - status->vhost_dev->backend_features =3D - qmp_decode_features(vdev->device_id, hdev->backend_features_ex= ); =20 status->vhost_dev->protocol_features =3D qmp_decode_protocols(hdev->protocol_features); diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 3dfec5e15cc..e139e059857 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -100,16 +100,9 @@ struct vhost_dev { * * @features: available features provided by the backend * @acked_features: final negotiated features with front-end driver - * - * @backend_features: this is used in a couple of places to either - * store VHOST_USER_F_PROTOCOL_FEATURES to apply to - * VHOST_USER_SET_FEATURES or VHOST_NET_F_VIRTIO_NET_HDR. Its - * future use should be discouraged and the variable retired as - * its easy to confuse with the VirtIO backend_features. */ VIRTIO_DECLARE_FEATURES(features); VIRTIO_DECLARE_FEATURES(acked_features); - VIRTIO_DECLARE_FEATURES(backend_features); =20 /** * @protocol_features: is the vhost-user only feature set by diff --git a/qapi/virtio.json b/qapi/virtio.json index 09dd0e6d05a..671f1ad793c 100644 --- a/qapi/virtio.json +++ b/qapi/virtio.json @@ -85,8 +85,6 @@ # # @acked-features: vhost_dev acked_features # -# @backend-features: vhost_dev backend_features -# # @protocol-features: vhost_dev protocol_features # # @max-queues: vhost_dev max_queues @@ -106,7 +104,6 @@ 'vq-index': 'int', 'features': 'VirtioDeviceFeatures', 'acked-features': 'VirtioDeviceFeatures', - 'backend-features': 'VirtioDeviceFeatures', 'protocol-features': 'VhostDeviceProtocols', 'max-queues': 'uint64', 'backend-cap': 'uint64', --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715461; cv=none; d=zohomail.com; s=zohoarc; b=Umheg1p4z5vSMzguMwMvhMi5ztRh6Ohi0bn9kkKZBnHza9hGCo91+igPR7zHZOa7yEneeOJf3apcSGGnfFHAkOAiBU9xil51lr503eyrDKwEtlaDWRkmcWxKB5MC2YbKdout4/i/Ay7V7W2j4piyTjaWWwj2nq3bZT2SU/FeOdY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715461; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wi8hBb/FxrPq6K5pIYsFChHST4eY8LX3PmM3S/gooyY=; b=aXGe0BZF5df0RZNUOWgOO76ySycStXq1AguaUays2FQRkuEX/fJ8A7o1rdmuUf/K2NJhICsUjJjodueOXWq+FWbfBaDZdoz7Ct1gpR8fTAVwUaUtpJyZ/dImGYs1OXSNlJ6Fu3IJcfocgHHzevbWuj40wC8LfJmJjvitdrjhM+I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715461127447.20437515671813; Mon, 20 Apr 2026 13:04:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEuqt-0001QO-QV; Mon, 20 Apr 2026 16:04:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqf-0001KA-2n for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:04 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqX-0001kS-Ka for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:03:57 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 57D2380663; Mon, 20 Apr 2026 23:03:52 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-hUBQjjhm; Mon, 20 Apr 2026 23:03:51 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1776715431; bh=wi8hBb/FxrPq6K5pIYsFChHST4eY8LX3PmM3S/gooyY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Pi1D5+wjB3yv3CuucS9KomuWQrVLm4PU5JBdMobGej/Q5W7+RG3HF8XC3Uc/5RKFm BM0ilmRF7uuuW0q3Qp6QlWGkVbh4LBLQW2SWcoQV/aTEB7bfv1tpXv6z2tbKqD/668 OciqBzpWOxV9JxBiT6OzFayHJ4R2g8OzAFyJ6nA4= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v6 03/22] vhost-user: introduce vhost_user_has_protocol_feature() helper Date: Mon, 20 Apr 2026 23:03:18 +0300 Message-ID: <20260420200339.708640-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715465441158500 Content-Type: text/plain; charset="utf-8" Make all protocol feature checks in the same way. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/virtio/vhost-user.c | 120 +++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 58 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 7ce17c5b2d8..72aeed26caa 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -267,6 +267,12 @@ struct scrub_regions { int fd_idx; }; =20 +static bool vhost_user_has_protocol_feature(struct vhost_dev *dev, + uint64_t feature) +{ + return virtio_has_feature(dev->protocol_features, feature); +} + static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg) { struct vhost_user *u =3D dev->opaque; @@ -430,8 +436,8 @@ static int vhost_user_set_log_base(struct vhost_dev *de= v, uint64_t base, { int fds[VHOST_USER_MAX_RAM_SLOTS]; size_t fd_num =3D 0; - bool shmfd =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_LOG_SHMFD); + bool shmfd =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_LOG_SHM= FD); int ret; VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_LOG_BASE, @@ -1001,11 +1007,11 @@ static int vhost_user_set_mem_table(struct vhost_de= v *dev, int fds[VHOST_MEMORY_BASELINE_NREGIONS]; size_t fd_num =3D 0; bool do_postcopy =3D u->postcopy_listen && u->postcopy_fd.handler; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); bool config_mem_slots =3D - virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS); + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS); int ret; =20 if (do_postcopy) { @@ -1053,8 +1059,9 @@ static int vhost_user_set_mem_table(struct vhost_dev = *dev, static int vhost_user_set_vring_endian(struct vhost_dev *dev, struct vhost_vring_state *ring) { - bool cross_endian =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CROSS_END= IAN); + bool cross_endian =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CROSS_ENDIAN); VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_VRING_ENDIAN, .hdr.flags =3D VHOST_USER_VERSION, @@ -1124,8 +1131,9 @@ static int vhost_user_write_sync(struct vhost_dev *de= v, VhostUserMsg *msg, int ret; =20 if (wait_for_reply) { - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_REPLY_ACK); if (reply_supported) { msg->hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; } @@ -1475,8 +1483,7 @@ static int vhost_user_set_features(struct vhost_dev *= dev, ret =3D vhost_user_set_u64(dev, VHOST_USER_SET_FEATURES, features, log_enabled); =20 - if (virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_STATUS)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_STATUS)= ) { if (!ret) { return vhost_user_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); } @@ -1530,8 +1537,8 @@ static int vhost_user_reset_device(struct vhost_dev *= dev) * Historically, reset was not implemented so only reset devices * that are expecting it. */ - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_RESET_DEVICE)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_RESET_DEVICE)) { return -ENOSYS; } =20 @@ -1588,8 +1595,8 @@ static int vhost_user_backend_handle_vring_host_notif= ier(struct vhost_dev *dev, void *addr; char *name; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) || + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) || vdev =3D=3D NULL || queue_idx >=3D virtio_get_num_queues(vdev)) { return -EINVAL; } @@ -1887,13 +1894,13 @@ static int vhost_setup_backend_channel(struct vhost= _dev *dev) }; struct vhost_user *u =3D dev->opaque; int sv[2], ret =3D 0; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); Error *local_err =3D NULL; QIOChannel *ioc; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_BACKEND_REQ)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ)) { return 0; } =20 @@ -2141,8 +2148,8 @@ static int vhost_user_postcopy_notifier(NotifierWithR= eturn *notifier, =20 switch (pnd->reason) { case POSTCOPY_NOTIFY_PROBE: - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_PAGEFAULT)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_PAGEFAULT)) { /* TODO: Get the device name into this error somehow */ error_setg(errp, "vhost-user backend not capable of postcopy"); @@ -2240,7 +2247,7 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, } =20 /* query the max queues we support if backend supports Multiple Qu= eue */ - if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_MQ)= ) { err =3D vhost_user_get_u64(dev, VHOST_USER_GET_QUEUE_NUM, &dev->max_queues); if (err < 0) { @@ -2258,18 +2265,18 @@ static int vhost_user_backend_init(struct vhost_dev= *dev, void *opaque, } =20 if (virtio_has_feature(features, VIRTIO_F_IOMMU_PLATFORM) && - !(virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_BACKEND_REQ) && - virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_ACK))) { + !(vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ) && + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_REPLY_ACK))) { error_setg(errp, "IOMMU support requires reply-ack and " "backend-req protocol features."); return -EINVAL; } =20 /* get max memory regions if backend supports configurable RAM slo= ts */ - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS)= ) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS)) { u->user->memory_slots =3D VHOST_MEMORY_BASELINE_NREGIONS; } else { err =3D vhost_user_get_max_memslots(dev, &ram_slots); @@ -2293,8 +2300,8 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, } =20 if (dev->migration_blocker =3D=3D NULL && - !virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_LOG_SHMFD)) { + !vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_LOG_SHMFD)) { error_setg(&dev->migration_blocker, "Migration disabled: vhost-user backend lacks " "VHOST_USER_PROTOCOL_F_LOG_SHMFD feature."); @@ -2363,8 +2370,8 @@ static bool vhost_user_requires_shm_log(struct vhost_= dev *dev) { assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_USER); =20 - return virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_LOG_SHMFD); + return vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_LOG_SHMFD); } =20 static int vhost_user_migration_done(struct vhost_dev *dev, char* mac_addr) @@ -2379,8 +2386,7 @@ static int vhost_user_migration_done(struct vhost_dev= *dev, char* mac_addr) } =20 /* if backend supports VHOST_USER_PROTOCOL_F_RARP ask it to send the R= ARP */ - if (virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_RARP)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_RARP)) { msg.hdr.request =3D VHOST_USER_SEND_RARP; msg.hdr.flags =3D VHOST_USER_VERSION; memcpy((char *)&msg.payload.u64, mac_addr, 6); @@ -2394,11 +2400,11 @@ static int vhost_user_migration_done(struct vhost_d= ev *dev, char* mac_addr) static int vhost_user_net_set_mtu(struct vhost_dev *dev, uint16_t mtu) { VhostUserMsg msg; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); int ret; =20 - if (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_NET_MTU)= )) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_NET_MT= U)) { return 0; } =20 @@ -2458,8 +2464,7 @@ static int vhost_user_get_config(struct vhost_dev *de= v, uint8_t *config, .hdr.size =3D VHOST_USER_CONFIG_HDR_SIZE + config_len, }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIG)) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_CONFIG= )) { error_setg(errp, "VHOST_USER_PROTOCOL_F_CONFIG not supported"); return -EINVAL; } @@ -2502,8 +2507,8 @@ static int vhost_user_set_config(struct vhost_dev *de= v, const uint8_t *data, { int ret; uint8_t *p; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); =20 VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_CONFIG, @@ -2511,8 +2516,7 @@ static int vhost_user_set_config(struct vhost_dev *de= v, const uint8_t *data, .hdr.size =3D VHOST_USER_CONFIG_HDR_SIZE + size, }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIG)) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_CONFIG= )) { return -ENOTSUP; } =20 @@ -2547,8 +2551,9 @@ static int vhost_user_crypto_create_session(struct vh= ost_dev *dev, uint64_t *session_id) { int ret; - bool crypto_session =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CRYPTO_SESSIO= N); + bool crypto_session =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CRYPTO_SESSION); CryptoDevBackendSessionInfo *backend_info =3D session_info; VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_CREATE_CRYPTO_SESSION, @@ -2649,8 +2654,9 @@ static int vhost_user_crypto_close_session(struct vhost_dev *dev, uint64_t session_id) { int ret; - bool crypto_session =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CRYPTO_SESSIO= N); + bool crypto_session =3D + vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_CRYPTO_SESSION); VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_CLOSE_CRYPTO_SESSION, .hdr.flags =3D VHOST_USER_VERSION, @@ -2695,8 +2701,8 @@ static int vhost_user_get_inflight_fd(struct vhost_de= v *dev, .hdr.size =3D sizeof(msg.payload.inflight), }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { return 0; } =20 @@ -2763,8 +2769,8 @@ static int vhost_user_set_inflight_fd(struct vhost_de= v *dev, .hdr.size =3D sizeof(msg.payload.inflight), }; =20 - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { + if (!vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { return 0; } =20 @@ -2863,8 +2869,7 @@ void vhost_user_async_close(DeviceState *d, =20 static int vhost_user_dev_start(struct vhost_dev *dev, bool started) { - if (!virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_STATUS)) { + if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_STATUS= )) { return 0; } =20 @@ -2889,16 +2894,15 @@ static void vhost_user_reset_status(struct vhost_de= v *dev) return; } =20 - if (virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_STATUS)) { + if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_STATUS)= ) { vhost_user_set_status(dev, 0); } } =20 static bool vhost_user_supports_device_state(struct vhost_dev *dev) { - return virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_DEVICE_STATE); + return vhost_user_has_protocol_feature( + dev, VHOST_USER_PROTOCOL_F_DEVICE_STATE); } =20 static int vhost_user_set_device_state_fd(struct vhost_dev *dev, --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715618; cv=none; d=zohomail.com; s=zohoarc; b=blodnhr6TuxBx5DVZuxzbUBLqS/sWG1gt4Z0TEoVfSDx/YC6OY5spGKrsLFnqbafuS+x5BAj6yc0xxwBePSDBdOIma/Hw8CvsjYfhxc6o3GIbUYafiuJu2TH13hKKYdGCq1IWzplupIJXnrmmaYbLytHqqp5YN8feVYuJ7DmHoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715618; 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=SMmontHdsj1x/Xo2OKpTpsUMrsx0YlKdiWr/lKmVTuA=; b=Cd/ti9nIw0QxFTXOildtCP1I/JyA9/Pw7uMF6I5EApx5uz8voZTKXyTzGUuZG/IWxWyJzMuIYR9KMM+m3ijG4gIYbkIcMh7JwAxNlVJPNEU1grzSs7x0Sq39nLmdKEgpmGKkEL0LqWw0ZjAa4pt875q5f58aSj/R1Cgr/bg8zME= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715618082162.75198176282834; Mon, 20 Apr 2026 13:06:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEur2-0001lU-6A; Mon, 20 Apr 2026 16:04:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqk-0001LO-23; Mon, 20 Apr 2026 16:04:08 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqf-0001l2-4a; Mon, 20 Apr 2026 16:04:04 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 85CDC806F6; Mon, 20 Apr 2026 23:03:54 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-dZfyZF20; Mon, 20 Apr 2026 23:03:53 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1776715433; bh=SMmontHdsj1x/Xo2OKpTpsUMrsx0YlKdiWr/lKmVTuA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=UqyWIg/CYBvXRnydcejiGXxngk4gVfQumdGGG7aO9EF6bH9vcP7bvq34Ciq8wdt/T NaU33HeotY2W7gcctqmYoJx/wpgK1NLY8BAjur/5S+UUG3wpafBivTdm3OtkMRVSDU dUIE7i8sKfio8IhODLICkz/kHYBV9kQSfat+I4dg= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, "Gonglei (Arei)" , zhenwei pi , Raphael Norwitz , Kevin Wolf , Hanna Reitz , Jason Wang , qemu-block@nongnu.org (open list:Block layer core) Subject: [PATCH v6 04/22] vhost: move protocol_features to vhost_user Date: Mon, 20 Apr 2026 23:03:19 +0300 Message-ID: <20260420200339.708640-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715620517154100 Content-Type: text/plain; charset="utf-8" As comment says: it's only for vhost-user. So, let's move it to corresponding vhost backend realization. Signed-off-by: Vladimir Sementsov-Ogievskiy --- backends/cryptodev-vhost.c | 1 - hw/block/vhost-user-blk.c | 6 ++---- hw/net/vhost_net.c | 2 -- hw/virtio/meson.build | 3 +++ hw/virtio/vhost-user-stub.c | 6 ++++++ hw/virtio/vhost-user.c | 36 +++++++++++++++++++++++++++------- hw/virtio/virtio-qmp.c | 6 ++++-- include/hw/virtio/vhost-user.h | 4 ++++ include/hw/virtio/vhost.h | 8 -------- 9 files changed, 48 insertions(+), 24 deletions(-) create mode 100644 hw/virtio/vhost-user-stub.c diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index abdfce33afc..c6069f4e5bd 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -60,7 +60,6 @@ cryptodev_vhost_init( =20 crypto->cc =3D options->cc; =20 - crypto->dev.protocol_features =3D 0; crypto->backend =3D -1; =20 /* vhost-user needs vq_index to initiate a specific queue pair */ diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index dc99de02635..2831f3c0530 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -572,10 +572,8 @@ static bool vhost_user_blk_inflight_needed(void *opaqu= e) { struct VHostUserBlk *s =3D opaque; =20 - bool inflight_migration =3D virtio_has_feature(s->dev.protocol_feature= s, - VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIG= HT); - - return inflight_migration; + return vhost_user_has_protocol_feature( + &s->dev, VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIGHT); } =20 static const VMStateDescription vmstate_vhost_user_blk_inflight =3D { diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index fda90e231e6..ca199831260 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -265,9 +265,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *optio= ns) goto fail; } net->backend =3D r; - net->dev.protocol_features =3D 0; } else { - net->dev.protocol_features =3D 0; net->backend =3D -1; =20 /* vhost-user needs vq_index to initiate a specific queue pair */ diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 415e359e9fc..adc3a4f748a 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -43,6 +43,8 @@ if have_vhost if_true: files('vhost-user-input-pci.c')) system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_SP= I'], if_true: files('vhost-user-spi-pci.c')) + else + system_virtio_ss.add(files('vhost-user-stub.c')) endif if have_vhost_vdpa system_virtio_ss.add(files('vhost-vdpa.c')) @@ -91,6 +93,7 @@ system_virtio_ss.add_all(when: 'CONFIG_VIRTIO_PCI', if_tr= ue: virtio_pci_ss) =20 system_ss.add_all(when: 'CONFIG_VIRTIO', if_true: system_virtio_ss) stub_ss.add(files('vhost-stub.c')) +stub_ss.add(files('vhost-user-stub.c')) stub_ss.add(files('virtio-stub.c')) stub_ss.add(files('virtio-md-stubs.c')) =20 diff --git a/hw/virtio/vhost-user-stub.c b/hw/virtio/vhost-user-stub.c new file mode 100644 index 00000000000..45559788dd4 --- /dev/null +++ b/hw/virtio/vhost-user-stub.c @@ -0,0 +1,6 @@ +#include "qemu/osdep.h" +#include "hw/virtio/vhost-user.h" + +void vhost_user_qmp_status(struct vhost_dev *dev, VirtioStatus *status) +{ +} diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 72aeed26caa..fc2ed1f17e5 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -11,6 +11,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "hw/virtio/virtio-dmabuf.h" +#include "hw/virtio/virtio-qmp.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-crypto.h" #include "hw/virtio/vhost-user.h" @@ -259,6 +260,14 @@ struct vhost_user { /* Our current regions */ int num_shadow_regions; struct vhost_memory_region shadow_regions[VHOST_USER_MAX_RAM_SLOTS]; + + /** + * @protocol_features: the vhost-user protocol feature set by + * VHOST_USER_SET_PROTOCOL_FEATURES. Protocol features are only + * negotiated if VHOST_USER_F_PROTOCOL_FEATURES has been offered + * by the backend (see @features). + */ + uint64_t protocol_features; }; =20 struct scrub_regions { @@ -267,10 +276,13 @@ struct scrub_regions { int fd_idx; }; =20 -static bool vhost_user_has_protocol_feature(struct vhost_dev *dev, - uint64_t feature) +bool vhost_user_has_protocol_feature(struct vhost_dev *dev, uint64_t featu= re) { - return virtio_has_feature(dev->protocol_features, feature); + struct vhost_user *u =3D dev->opaque; + + assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_USER); + + return virtio_has_feature(u->protocol_features, feature); } =20 static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg) @@ -1338,8 +1350,8 @@ static int vhost_set_vring_file(struct vhost_dev *dev, int ret; int fds[VHOST_USER_MAX_RAM_SLOTS]; size_t fd_num =3D 0; - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_= ACK); + bool reply_supported =3D + vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); VhostUserMsg msg =3D { .hdr.request =3D request, .hdr.flags =3D VHOST_USER_VERSION, @@ -2239,8 +2251,8 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, } =20 /* final set of protocol features */ - dev->protocol_features =3D protocol_features; - err =3D vhost_user_set_protocol_features(dev, dev->protocol_featur= es); + u->protocol_features =3D protocol_features; + err =3D vhost_user_set_protocol_features(dev, u->protocol_features= ); if (err < 0) { error_setg_errno(errp, EPROTO, "vhost_backend_init failed"); return -EPROTO; @@ -3033,6 +3045,16 @@ static int vhost_user_check_device_state(struct vhos= t_dev *dev, Error **errp) return 0; } =20 +void vhost_user_qmp_status(struct vhost_dev *dev, VirtioStatus *status) +{ + struct vhost_user *u =3D dev->opaque; + + assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_USER); + + status->vhost_dev->protocol_features =3D + qmp_decode_protocols(u->protocol_features); +} + const VhostOps user_ops =3D { .backend_type =3D VHOST_BACKEND_TYPE_USER, .vhost_backend_init =3D vhost_user_backend_init, diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c index 71717c56a41..c8bf702d38d 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -751,12 +751,14 @@ VirtioStatus *qmp_x_query_virtio_status(const char *p= ath, Error **errp) status->vhost_dev->acked_features =3D qmp_decode_features(vdev->device_id, hdev->acked_features_ex); =20 - status->vhost_dev->protocol_features =3D - qmp_decode_protocols(hdev->protocol_features); status->vhost_dev->max_queues =3D hdev->max_queues; status->vhost_dev->backend_cap =3D hdev->backend_cap; status->vhost_dev->log_enabled =3D hdev->log_enabled; status->vhost_dev->log_size =3D hdev->log_size; + + if (hdev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_USER) { + vhost_user_qmp_status(hdev, status); + } } =20 return status; diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h index 53fe9966862..0e576fc5386 100644 --- a/include/hw/virtio/vhost-user.h +++ b/include/hw/virtio/vhost-user.h @@ -10,6 +10,7 @@ =20 #include "chardev/char-fe.h" #include "hw/virtio/virtio.h" +#include "qapi/qapi-types-virtio.h" =20 enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_MQ =3D 0, @@ -113,4 +114,7 @@ void vhost_user_async_close(DeviceState *d, CharFrontend *chardev, struct vhost_dev *vhost, vu_async_close_fn cb); =20 +void vhost_user_qmp_status(struct vhost_dev *dev, VirtioStatus *status); +bool vhost_user_has_protocol_feature(struct vhost_dev *dev, uint64_t featu= re); + #endif diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index e139e059857..4a9bd3effef 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -104,14 +104,6 @@ struct vhost_dev { VIRTIO_DECLARE_FEATURES(features); VIRTIO_DECLARE_FEATURES(acked_features); =20 - /** - * @protocol_features: is the vhost-user only feature set by - * VHOST_USER_SET_PROTOCOL_FEATURES. Protocol features are only - * negotiated if VHOST_USER_F_PROTOCOL_FEATURES has been offered - * by the backend (see @features). - */ - uint64_t protocol_features; - uint64_t max_queues; uint64_t backend_cap; /* @started: is the vhost device started? */ --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715463; cv=none; d=zohomail.com; s=zohoarc; b=il9dJjWwp1vg6bMVHlQc4EnUxPQ1+kZpvCgkVS543PRowy04gfaMnBs+USrx0bzdsAmVo7XYglVdTd3gVOpPuZaC9dmPwNkO8IH0go03bxWRYeFHVDkKK6XknEV68fNUiTkRN65aNtLQmXhfgMtHwAbj78IxxE95wPHozG+5Ggk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715463; 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=U+MpPWCzWZd0Q1GJnS+Zgp15vilEZPYK+pK2ksRXVxg=; b=JiCx3S4isbnE7OTV2Y9q4tB0NXLMZQ0liuXEas2Ta72CCoabncyS0f8+ym3IvcNT64Ix3wif5pw/nEIzRV37vxNzw/fqq+CPo6q54YOLNariPf/4QhUqUIH+ykrTK8yuVdep18TMhbb81yzeuYujjS6ff459Fmn3k6XDEhM9VpE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715463329130.98617017989704; Mon, 20 Apr 2026 13:04:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEuqw-0001VH-Ut; Mon, 20 Apr 2026 16:04:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqi-0001L8-QS for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:06 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqe-0001lO-PH for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:03 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id E955D8075E; Mon, 20 Apr 2026 23:03:55 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-K71ifzMM; Mon, 20 Apr 2026 23:03:55 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1776715435; bh=U+MpPWCzWZd0Q1GJnS+Zgp15vilEZPYK+pK2ksRXVxg=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=kOugIIq5rNtAsHLbXoHFmQ1Sck/L7daLjDIRuR9a2WABRgFBvDaiKA6KLm4NCFbId YlvoBJjH/WthgrelTD5s7Ld9T6rF9OB1pUMZKhfhNMh6utcw5tmGZ/ngitAyJ9zS7x tKL8bLUDn90YAZtJzhvfinE6OeoiTrnWreWp9uUE= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Raphael Norwitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v6 05/22] vhost-user-gpu: drop code duplication Date: Mon, 20 Apr 2026 23:03:20 +0300 Message-ID: <20260420200339.708640-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715466325154100 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 3f6fb7a8033..8911b2a72f7 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -644,10 +644,6 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error= **errp) VIRTIO_GPU_F_RESOURCE_UUID)) { g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_RESOURCE_UUID_E= NABLED; } - if (virtio_has_feature(g->vhost->dev.features, - VIRTIO_GPU_F_RESOURCE_UUID)) { - g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_RESOURCE_UUID_E= NABLED; - } =20 if (!virtio_gpu_base_device_realize(qdev, NULL, NULL, errp)) { return; --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715614; cv=none; d=zohomail.com; s=zohoarc; b=mgGsjzYEA80+xxHsSFn8G+GfbLAY/+bYpx2K9Kaf1CEzfJKNv3un3eImsFkAwVrtpCQFwZ/q6wJFRBg2E3T/Ky6SY+08odfDoxaUdrTtwoKQgeb7Mo4xeEuxIR7WMoZbkVMT2vFAi9TahXRzOenEfC3EmoYkjsvq1K5r3Tc9fg4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715614; 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=+axeZ2TTYr0f20W8V8FaxxcfZODhNBsnjsiwjpJ0gkc=; b=JMF82PVXGmXgD2ubFmSBM9mPktBah0tkcfysa8FZTLDszZJbwrzsb3T5AFZpOeCVd06s60ecg+gTNkjC3m2j4/eyd8YAUZn2o72TK50W54J+3Ha7A1BqtIkARyy6J2PAYwywK09UgFPLoSE9QgQAcCe2KExbRMxrY4476U9Rl5k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715614057446.1446502339028; Mon, 20 Apr 2026 13:06:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEuqy-0001cP-Jh; Mon, 20 Apr 2026 16:04:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqi-0001L9-S6 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:07 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqe-0001me-Po for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:03 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id D049380778; Mon, 20 Apr 2026 23:03:57 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-1FRJDOrQ; Mon, 20 Apr 2026 23:03:56 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1776715437; bh=+axeZ2TTYr0f20W8V8FaxxcfZODhNBsnjsiwjpJ0gkc=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=DEMlqPe+J9iFCP688fteB8G4Y2P8MvEH4X209DXbsXIwHDTa48O0SpG616TdJMBwh f0rxAHOP/Fj4Q39PkdRdi+myVv8ht0Y/40SiojGBennFP/z44Qqb6sUW2P3Ysy1wHW fN6/hfLDbCfYS66zZctO6dpFSqjCpnBGuXG6NZO8= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Jason Wang , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v6 06/22] vhost: make vhost_dev.features private Date: Mon, 20 Apr 2026 23:03:21 +0300 Message-ID: <20260420200339.708640-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715614608158500 Content-Type: text/plain; charset="utf-8" It's hard to control where and how do we use this field. Let's cover all usages by getters/setters, and keep direct access to the field only in vhost.c. It will help to control migration of this field in further commits. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin --- hw/display/vhost-user-gpu.c | 7 +++---- hw/net/vhost_net.c | 18 ++++++++--------- hw/virtio/vdpa-dev.c | 2 +- hw/virtio/vhost-user-base.c | 8 ++++++-- hw/virtio/vhost-user.c | 4 ++-- hw/virtio/vhost.c | 6 +++--- hw/virtio/virtio-qmp.c | 2 +- include/hw/virtio/vhost.h | 39 +++++++++++++++++++++++++++++++++++-- net/vhost-vdpa.c | 7 +++---- 9 files changed, 65 insertions(+), 28 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 8911b2a72f7..3566e49a1aa 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -631,17 +631,16 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Erro= r **errp) =20 /* existing backend may send DMABUF, so let's add that requirement */ g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED; - if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_VIRGL)) { + if (vhost_dev_has_feature(&g->vhost->dev, VIRTIO_GPU_F_VIRGL)) { g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED; } - if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_EDID)) { + if (vhost_dev_has_feature(&g->vhost->dev, VIRTIO_GPU_F_EDID)) { g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_EDID_ENABLED; } else { error_report("EDID requested but the backend doesn't support it."); g->parent_obj.conf.flags &=3D ~(1 << VIRTIO_GPU_FLAG_EDID_ENABLED); } - if (virtio_has_feature(g->vhost->dev.features, - VIRTIO_GPU_F_RESOURCE_UUID)) { + if (vhost_dev_has_feature(&g->vhost->dev, VIRTIO_GPU_F_RESOURCE_UUID))= { g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_RESOURCE_UUID_E= NABLED; } =20 diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index ca199831260..323d1177359 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -54,8 +54,8 @@ void vhost_net_ack_features_ex(struct vhost_net *net, con= st uint64_t *features) { virtio_features_clear(net->dev.acked_features_ex); if (net->backend =3D=3D -1) { - net->dev.acked_features =3D - net->dev.features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES); + net->dev.acked_features =3D (vhost_dev_features(&net->dev) & + (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)); } else if (!qemu_has_vnet_hdr(net->nc)) { net->dev.acked_features =3D 1ULL << VHOST_NET_F_VIRTIO_NET_HDR; } @@ -282,15 +282,15 @@ struct vhost_net *vhost_net_init(VhostNetOptions *opt= ions) if (backend_kernel) { if (!qemu_has_vnet_hdr_len(options->net_backend, sizeof(struct virtio_net_hdr_mrg_rxbuf))) { - net->dev.features &=3D ~(1ULL << VIRTIO_NET_F_MRG_RXBUF); + vhost_dev_clear_feature(&net->dev, VIRTIO_NET_F_MRG_RXBUF); } =20 if (!qemu_has_vnet_hdr(options->net_backend) && - (~net->dev.features & (1ULL << VHOST_NET_F_VIRTIO_NET_HDR))) { - fprintf(stderr, "vhost lacks feature mask 0x%llx for backend\n= ", - ~net->dev.features & (1ULL << VHOST_NET_F_VIRTIO_NET_H= DR)); - goto fail; - } + !vhost_dev_has_feature(&net->dev, VHOST_NET_F_VIRTIO_NET_HDR))= { + fprintf(stderr, "vhost lacks VHOST_NET_F_VIRTIO_NET_HDR " + "feature for backend\n"); + goto fail; + } } =20 /* Set sane init value. Override when guest acks. */ @@ -298,7 +298,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *optio= ns) virtio_features_from_u64(features, options->get_acked_features(net->nc)); if (virtio_features_andnot(missing_features, features, - net->dev.features_ex)) { + vhost_dev_features_ex(&net->dev))) { fprintf(stderr, "vhost lacks feature mask 0x" VIRTIO_FEATURES_= FMT " for backend\n", VIRTIO_FEATURES_PR(missing_features)= ); goto fail; diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c index 06179e402e4..94188d37bbf 100644 --- a/hw/virtio/vdpa-dev.c +++ b/hw/virtio/vdpa-dev.c @@ -224,7 +224,7 @@ static uint64_t vhost_vdpa_device_get_features(VirtIODe= vice *vdev, Error **errp) { VhostVdpaDevice *s =3D VHOST_VDPA_DEVICE(vdev); - uint64_t backend_features =3D s->dev.features; + uint64_t backend_features =3D vhost_dev_features(&s->dev); =20 if (!virtio_has_feature(features, VIRTIO_F_IOMMU_PLATFORM)) { virtio_clear_feature(&backend_features, VIRTIO_F_IOMMU_PLATFORM); diff --git a/hw/virtio/vhost-user-base.c b/hw/virtio/vhost-user-base.c index 01ab9ca56b1..5bbf4a73679 100644 --- a/hw/virtio/vhost-user-base.c +++ b/hw/virtio/vhost-user-base.c @@ -118,9 +118,13 @@ static uint64_t vub_get_features(VirtIODevice *vdev, uint64_t requested_features, Error **errp) { VHostUserBase *vub =3D VHOST_USER_BASE(vdev); + uint64_t backend_features =3D vhost_dev_features(&vub->vhost_dev); + /* This should be set when the vhost connection initialises */ - g_assert(vub->vhost_dev.features); - return vub->vhost_dev.features & ~(1ULL << VHOST_USER_F_PROTOCOL_FEATU= RES); + g_assert(backend_features); + virtio_clear_feature(&backend_features, VHOST_USER_F_PROTOCOL_FEATURES= ); + + return backend_features; } =20 /* diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index fc2ed1f17e5..68dd89cd8f8 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1249,7 +1249,7 @@ static int vhost_user_set_vring_enable(struct vhost_d= ev *dev, int enable) { int i; =20 - if (!virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES)= ) { + if (!vhost_dev_has_feature(dev, VHOST_USER_F_PROTOCOL_FEATURES)) { /* * For vhost-user devices, if VHOST_USER_F_PROTOCOL_FEATURES has n= ot * been negotiated, the rings start directly in the enabled state, @@ -1488,7 +1488,7 @@ static int vhost_user_set_features(struct vhost_dev *= dev, * Don't lose VHOST_USER_F_PROTOCOL_FEATURES, which is vhost-user * specific. */ - if (virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES))= { + if (vhost_dev_has_feature(dev, VHOST_USER_F_PROTOCOL_FEATURES)) { features |=3D 1ULL << VHOST_USER_F_PROTOCOL_FEATURES; } =20 diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index b89797df95e..e39e0676e00 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1612,7 +1612,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, } } =20 - virtio_features_copy(hdev->features_ex, features); + virtio_features_copy(hdev->_features_ex, features); =20 hdev->memory_listener =3D (MemoryListener) { .name =3D "vhost", @@ -1635,7 +1635,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, }; =20 if (hdev->migration_blocker =3D=3D NULL) { - if (!virtio_has_feature_ex(hdev->features_ex, VHOST_F_LOG_ALL)) { + if (!vhost_dev_has_feature_ex(hdev, VHOST_F_LOG_ALL)) { error_setg(&hdev->migration_blocker, "Migration disabled: vhost lacks VHOST_F_LOG_ALL fe= ature."); } else if (vhost_dev_log_is_shared(hdev) && !qemu_memfd_alloc_chec= k()) { @@ -1909,7 +1909,7 @@ void vhost_get_features_ex(struct vhost_dev *hdev, const int *bit =3D feature_bits; =20 while (*bit !=3D VHOST_INVALID_FEATURE_BIT) { - if (!virtio_has_feature_ex(hdev->features_ex, *bit)) { + if (!vhost_dev_has_feature_ex(hdev, *bit)) { virtio_clear_feature_ex(features, *bit); } bit++; diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c index c8bf702d38d..51e3a42c4c4 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -747,7 +747,7 @@ VirtioStatus *qmp_x_query_virtio_status(const char *pat= h, Error **errp) status->vhost_dev->nvqs =3D hdev->nvqs; status->vhost_dev->vq_index =3D hdev->vq_index; status->vhost_dev->features =3D - qmp_decode_features(vdev->device_id, hdev->features_ex); + qmp_decode_features(vdev->device_id, vhost_dev_features_ex(hde= v)); status->vhost_dev->acked_features =3D qmp_decode_features(vdev->device_id, hdev->acked_features_ex); =20 diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 4a9bd3effef..54862f9b445 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -98,10 +98,11 @@ struct vhost_dev { * offered by a backend which may be a subset of the total * features eventually offered to the guest. * - * @features: available features provided by the backend + * @_features: available features provided by the backend, private, + * direct access only in vhost.h/vhost.c * @acked_features: final negotiated features with front-end driver */ - VIRTIO_DECLARE_FEATURES(features); + VIRTIO_DECLARE_FEATURES(_features); VIRTIO_DECLARE_FEATURES(acked_features); =20 uint64_t max_queues; @@ -403,6 +404,40 @@ int vhost_dev_get_inflight(struct vhost_dev *dev, uint= 16_t queue_size, struct vhost_inflight *inflight); bool vhost_dev_has_iommu(struct vhost_dev *dev); =20 +static inline bool vhost_dev_has_feature(struct vhost_dev *dev, + uint64_t feature) +{ + return virtio_has_feature(dev->_features, feature); +} + +static inline bool vhost_dev_has_feature_ex(struct vhost_dev *dev, + uint64_t feature) +{ + return virtio_has_feature_ex(dev->_features_ex, feature); +} + +static inline uint64_t vhost_dev_features(struct vhost_dev *dev) +{ + return dev->_features; +} + +static inline const uint64_t *vhost_dev_features_ex(struct vhost_dev *dev) +{ + return dev->_features_ex; +} + +static inline void vhost_dev_clear_feature(struct vhost_dev *dev, + uint64_t feature) +{ + virtio_clear_feature(&dev->_features, feature); +} + +static inline void vhost_dev_clear_feature_ex(struct vhost_dev *dev, + uint64_t feature) +{ + virtio_clear_feature_ex(dev->_features_ex, feature); +} + #ifdef CONFIG_VHOST int vhost_reset_device(struct vhost_dev *hdev); #else diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 3df6091274e..ed402ff8aaf 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -257,15 +257,14 @@ static bool vhost_vdpa_get_vnet_hash_supported_types(= NetClientState *nc, { assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); - uint64_t features =3D s->vhost_vdpa.dev->features; int fd =3D s->vhost_vdpa.shared->device_fd; struct { struct vhost_vdpa_config hdr; uint32_t supported_hash_types; } config; =20 - if (!virtio_has_feature(features, VIRTIO_NET_F_HASH_REPORT) && - !virtio_has_feature(features, VIRTIO_NET_F_RSS)) { + if (!vhost_dev_has_feature(s->vhost_vdpa.dev, VIRTIO_NET_F_HASH_REPORT= ) && + !vhost_dev_has_feature(s->vhost_vdpa.dev, VIRTIO_NET_F_RSS)) { return false; } =20 @@ -586,7 +585,7 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) * If we early return in these cases SVQ will not be enabled. The migr= ation * will be blocked as long as vhost-vdpa backends will not offer _F_LO= G. */ - if (!vhost_vdpa_net_valid_svq_features(v->dev->features, NULL)) { + if (!vhost_vdpa_net_valid_svq_features(vhost_dev_features(v->dev), NUL= L)) { return 0; } =20 --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715556; cv=none; d=zohomail.com; s=zohoarc; b=VXFCMrWUZjP4Ct3j74OgDkDNxC64QA2h84adRPux1gs8rs8Bpyl5Ut09Sz21JA6Z6jpeLcxXaro3Upzbq8NP4iQTgkL9pB4aiUG6Xg86+mHJsdR9SQXLp5hNBUUsu4XvNS0IR4O+qm3jIMg2e+k4599xfdAbjQubeUZVWkZ2rB8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715556; 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=BuHCkvPCUH8ek8ltWnzcAd7N450RrqnWYvfnQTDG1rQ=; b=XFpU+x5iaBISnSHpJ3meFzBA4VyzrYLxWHllx0carQvlcWniLm/QaUQgAMm/tfkYMqoITVV2Hdr+ykhevTM6R/dPgXCTiJN9+fw32Hy6CHp9DuGbNZb9+WaLTQLcyD6H3Jz/Xl0icH+HcaXFPEXAw2CkWH/lRmtjra6t/1qcchk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715556084274.5138224407941; Mon, 20 Apr 2026 13:05:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEuqy-0001bj-Bt; Mon, 20 Apr 2026 16:04:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqo-0001Mj-0F; Mon, 20 Apr 2026 16:04:11 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqi-0001mn-Uc; Mon, 20 Apr 2026 16:04:08 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 3EE258075D; Mon, 20 Apr 2026 23:04:00 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-9ePIJgih; Mon, 20 Apr 2026 23:03:59 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1776715439; bh=BuHCkvPCUH8ek8ltWnzcAd7N450RrqnWYvfnQTDG1rQ=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=ZFxxCl8oDm+/nXDeUhZTdW8teIsxEJcKRtNwnFBH21SggVPZ8HHb4pl7MvjK3QowU NmBiYAel/WBJh9WneX0hc3KpASfMVMIOcYm0+w+U0HcE/Q4dUawUOLGV9Eac0htjuW YL/K1M67crZFF2lmbRIUuzcbaRlLLWJM5KyNzWOE= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Eric Farman , Cornelia Huck , Halil Pasic , Richard Henderson , Ilya Leoshkevich , David Hildenbrand , Matthew Rosato , Christian Borntraeger , qemu-s390x@nongnu.org (open list:virtio-ccw) Subject: [PATCH v6 07/22] virtio: move common part of _set_guest_notifier to generic code Date: Mon, 20 Apr 2026 23:03:22 +0300 Message-ID: <20260420200339.708640-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715558376158500 Content-Type: text/plain; charset="utf-8" virtio-pci, virtio-mmio and virtio-ccw handle config notifier equally but with different code (mmio adds a separate function, when pci use common function). Let's chose the more compact way (pci) and reuse it for mmio. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Eric Farman --- hw/s390x/virtio-ccw.c | 35 ++++++++++++------------- hw/virtio/virtio-mmio.c | 41 +++++------------------------ hw/virtio/virtio-pci.c | 34 +++--------------------- hw/virtio/virtio.c | 47 +++++++++++++++++++++++++++++++--- include/hw/virtio/virtio-pci.h | 3 --- include/hw/virtio/virtio.h | 15 ++++++++--- 6 files changed, 82 insertions(+), 93 deletions(-) diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index ba55bf4fe97..cdad862ec23 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -1025,20 +1025,27 @@ static int virtio_ccw_set_guest_notifier(VirtioCcwD= evice *dev, int n, VirtQueue *vq =3D virtio_get_queue(vdev, n); EventNotifier *notifier =3D virtio_queue_get_guest_notifier(vq); VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); + int r; =20 - if (assign) { - int r =3D event_notifier_init(notifier, 0); - - if (r < 0) { - return r; + if (!assign) { + if (k->guest_notifier_mask && vdev->use_guest_notifier_mask) { + k->guest_notifier_mask(vdev, n, true); } - virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd); + if (with_irqfd) { + virtio_ccw_remove_irqfd(dev, n); + } + } + + r =3D virtio_set_guest_notifier(vdev, n, assign, with_irqfd); + if (r < 0) { + return r; + } + + if (assign) { if (with_irqfd) { r =3D virtio_ccw_add_irqfd(dev, n); if (r) { - virtio_queue_set_guest_notifier_fd_handler(vq, false, - with_irqfd); - event_notifier_cleanup(notifier); + virtio_set_guest_notifier(vdev, n, false, with_irqfd); return r; } } @@ -1054,16 +1061,8 @@ static int virtio_ccw_set_guest_notifier(VirtioCcwDe= vice *dev, int n, k->guest_notifier_pending(vdev, n)) { event_notifier_set(notifier); } - } else { - if (k->guest_notifier_mask && vdev->use_guest_notifier_mask) { - k->guest_notifier_mask(vdev, n, true); - } - if (with_irqfd) { - virtio_ccw_remove_irqfd(dev, n); - } - virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd); - event_notifier_cleanup(notifier); } + return 0; } =20 diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c index 742ca3d3e4d..58c6d46aab4 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -670,18 +670,11 @@ static int virtio_mmio_set_guest_notifier(DeviceState= *d, int n, bool assign, VirtIOMMIOProxy *proxy =3D VIRTIO_MMIO(d); VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); - VirtQueue *vq =3D virtio_get_queue(vdev, n); - EventNotifier *notifier =3D virtio_queue_get_guest_notifier(vq); + int r; =20 - if (assign) { - int r =3D event_notifier_init(notifier, 0); - if (r < 0) { - return r; - } - virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd); - } else { - virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd); - event_notifier_cleanup(notifier); + r =3D virtio_set_guest_notifier(vdev, n, assign, with_irqfd); + if (r < 0) { + return r; } =20 if (vdc->guest_notifier_mask && vdev->use_guest_notifier_mask) { @@ -690,30 +683,7 @@ static int virtio_mmio_set_guest_notifier(DeviceState = *d, int n, bool assign, =20 return 0; } -static int virtio_mmio_set_config_guest_notifier(DeviceState *d, bool assi= gn, - bool with_irqfd) -{ - VirtIOMMIOProxy *proxy =3D VIRTIO_MMIO(d); - VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); - VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); - EventNotifier *notifier =3D virtio_config_get_guest_notifier(vdev); - int r =3D 0; =20 - if (assign) { - r =3D event_notifier_init(notifier, 0); - if (r < 0) { - return r; - } - virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irq= fd); - } else { - virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irq= fd); - event_notifier_cleanup(notifier); - } - if (vdc->guest_notifier_mask && vdev->use_guest_notifier_mask) { - vdc->guest_notifier_mask(vdev, VIRTIO_CONFIG_IRQ_IDX, !assign); - } - return r; -} static int virtio_mmio_set_guest_notifiers(DeviceState *d, int nvqs, bool assign) { @@ -735,7 +705,8 @@ static int virtio_mmio_set_guest_notifiers(DeviceState = *d, int nvqs, goto assign_error; } } - r =3D virtio_mmio_set_config_guest_notifier(d, assign, with_irqfd); + r =3D virtio_mmio_set_guest_notifier(d, VIRTIO_CONFIG_IRQ_IDX, assign, + with_irqfd); if (r < 0) { goto assign_error; } diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index bcab2d18b80..fd9719547f9 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1208,43 +1208,17 @@ static void virtio_pci_vector_poll(PCIDevice *dev, } } =20 -void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev, VirtQueu= e *vq, - int n, bool assign, - bool with_irqfd) -{ - if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { - virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irq= fd); - } else { - virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd); - } -} - static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assig= n, bool with_irqfd) { VirtIOPCIProxy *proxy =3D to_virtio_pci_proxy(d); VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); - VirtQueue *vq =3D NULL; - EventNotifier *notifier =3D NULL; + int r; =20 - if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { - notifier =3D virtio_config_get_guest_notifier(vdev); - } else { - vq =3D virtio_get_queue(vdev, n); - notifier =3D virtio_queue_get_guest_notifier(vq); - } - - if (assign) { - int r =3D event_notifier_init(notifier, 0); - if (r < 0) { - return r; - } - virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, true, with_i= rqfd); - } else { - virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, false, - with_irqfd); - event_notifier_cleanup(notifier); + r =3D virtio_set_guest_notifier(vdev, n, assign, with_irqfd); + if (r < 0) { + return r; } =20 if (!msix_enabled(&proxy->pci_dev) && diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 8fcf6cfd0b4..4941b0c2861 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3835,8 +3835,10 @@ static void virtio_config_guest_notifier_read(EventN= otifier *n) virtio_notify_config(vdev); } } -void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign, - bool with_irqfd) + +static void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, + bool assign, + bool with_irqfd) { if (assign && !with_irqfd) { event_notifier_set_handler(&vq->guest_notifier, @@ -3851,7 +3853,7 @@ void virtio_queue_set_guest_notifier_fd_handler(VirtQ= ueue *vq, bool assign, } } =20 -void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev, +static void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev, bool assign, bool with_ir= qfd) { EventNotifier *n; @@ -3868,6 +3870,45 @@ void virtio_config_set_guest_notifier_fd_handler(Vir= tIODevice *vdev, } } =20 +static void virtio_set_guest_notifier_fd_handler(VirtIODevice *vdev, + VirtQueue *vq, + int n, bool assign, + bool with_irqfd) +{ + if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irq= fd); + } else { + virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd); + } +} + +int virtio_set_guest_notifier(VirtIODevice *vdev, int n, bool assign, + bool with_irqfd) +{ + VirtQueue *vq =3D NULL; + EventNotifier *notifier =3D NULL; + + if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + notifier =3D virtio_config_get_guest_notifier(vdev); + } else { + vq =3D virtio_get_queue(vdev, n); + notifier =3D virtio_queue_get_guest_notifier(vq); + } + + if (assign) { + int r =3D event_notifier_init(notifier, 0); + if (r < 0) { + return r; + } + virtio_set_guest_notifier_fd_handler(vdev, vq, n, true, with_irqfd= ); + } else { + virtio_set_guest_notifier_fd_handler(vdev, vq, n, false, with_irqf= d); + event_notifier_cleanup(notifier); + } + + return 0; +} + EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq) { return &vq->guest_notifier; diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h index 5cb20b73f62..ee50fb0d551 100644 --- a/include/hw/virtio/virtio-pci.h +++ b/include/hw/virtio/virtio-pci.h @@ -250,9 +250,6 @@ void virtio_pci_types_register(const VirtioPCIDeviceTyp= eInfo *t); * @fixed_queues. */ unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues); -void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev, VirtQueu= e *vq, - int n, bool assign, - bool with_irqfd); =20 int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, uint8_t bar, uint64_t of= fset, uint64_t length, uint8_t id); diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 6344bd7b689..d9fde425581 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -420,8 +420,6 @@ void virtio_queue_update_used_idx(VirtIODevice *vdev, i= nt n); VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n); uint16_t virtio_get_queue_index(VirtQueue *vq); EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq); -void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign, - bool with_irqfd); int virtio_device_start_ioeventfd(VirtIODevice *vdev); int virtio_device_grab_ioeventfd(VirtIODevice *vdev); void virtio_device_release_ioeventfd(VirtIODevice *vdev); @@ -435,8 +433,17 @@ void virtio_queue_aio_detach_host_notifier(VirtQueue *= vq, AioContext *ctx); VirtQueue *virtio_vector_first_queue(VirtIODevice *vdev, uint16_t vector); VirtQueue *virtio_vector_next_queue(VirtQueue *vq); EventNotifier *virtio_config_get_guest_notifier(VirtIODevice *vdev); -void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev, - bool assign, bool with_ir= qfd); + +/** + * virtio_set_guest_notifier - set/unset queue or config guest notifier + * + * @vdev: the VirtIO device + * @n: queue number, or VIRTIO_CONFIG_IRQ_IDX to set config notifer + * @assign: true to set notifier, false to unset + * @with_irqfd: irqfd enabled + */ +int virtio_set_guest_notifier(VirtIODevice *vdev, int n, bool assign, + bool with_irqfd); =20 static inline void virtio_add_feature(uint64_t *features, unsigned int fbi= t) { --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715590; cv=none; d=zohomail.com; s=zohoarc; b=XQ+QACSDm2HPL/C3g14KwZeLmmb7N2oSQYSRRVEszW72lAjcgpVZiCHs2dh/hHsmrkYi+dlsJLE9nkE4HUKFl/IRCPrw3cxSyXIbFxD86E0zizThBvm4u+kHOWTRrYxSt1XqiU+NtmQeDGcIEeaQIxcvqQNcyUrrR4btt9JsAw4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715590; 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=Fq8VchYgWYio+J+istM1mBldZkLvILQJGVqd5bh/k8w=; b=An9JIHxhewOvJPm+1lorX7r1GTuZuBGEqARTEBexZEW7OMHeVSUFVrh8KL4Q6lNwOl7+eEuQqJOjwaL/rQG0zcmwzdCrv3mdjB5j9r60tQwJKY/v72x5MKOZzIkEzHVIsiFhXk4rqvR6+6V/yt4KdFfw+C/db9GdtpEqK+z+jK8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715590112353.4088833837367; Mon, 20 Apr 2026 13:06:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEur2-0001ll-H9; Mon, 20 Apr 2026 16:04:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuql-0001LT-AX for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:08 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqi-0001o6-Iw for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:07 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 808CC8071E; Mon, 20 Apr 2026 23:04:01 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-AuQU5g2R; Mon, 20 Apr 2026 23:04:00 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1776715440; bh=Fq8VchYgWYio+J+istM1mBldZkLvILQJGVqd5bh/k8w=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=gHkjerACyrm9ITPYHq4/+awNzKg7Y+jVE/8AV1z+Fuw7PYulxKUc3sWY6zKA4zRd1 fGutSlx8RI8T0LpIepS78AKBq26j6neOCm6pO2S7/51H0coayT7y3s0/5mRqxihjJW A3VStVysaGP+Qqnips3hoDBjMZUIAPOVDjZzHBgE= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v6 08/22] virtio: drop *_set_guest_notifier_fd_handler() helpers Date: Mon, 20 Apr 2026 23:03:23 +0300 Message-ID: <20260420200339.708640-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715591958154100 Content-Type: text/plain; charset="utf-8" Now they don't make code more readable. Let's better put the whole logic into virtio_queue_set_guest_notifier(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin --- hw/virtio/virtio.c | 75 +++++++++++----------------------------------- 1 file changed, 17 insertions(+), 58 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 4941b0c2861..30ac7d7b37a 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3836,73 +3836,32 @@ static void virtio_config_guest_notifier_read(Event= Notifier *n) } } =20 -static void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, - bool assign, - bool with_irqfd) -{ - if (assign && !with_irqfd) { - event_notifier_set_handler(&vq->guest_notifier, - virtio_queue_guest_notifier_read); - } else { - event_notifier_set_handler(&vq->guest_notifier, NULL); - } - if (!assign) { - /* Test and clear notifier before closing it, - * in case poll callback didn't have time to run. */ - virtio_queue_guest_notifier_read(&vq->guest_notifier); - } -} - -static void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev, - bool assign, bool with_ir= qfd) -{ - EventNotifier *n; - n =3D &vdev->config_notifier; - if (assign && !with_irqfd) { - event_notifier_set_handler(n, virtio_config_guest_notifier_read); - } else { - event_notifier_set_handler(n, NULL); - } - if (!assign) { - /* Test and clear notifier before closing it,*/ - /* in case poll callback didn't have time to run. */ - virtio_config_guest_notifier_read(n); - } -} - -static void virtio_set_guest_notifier_fd_handler(VirtIODevice *vdev, - VirtQueue *vq, - int n, bool assign, - bool with_irqfd) -{ - if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { - virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irq= fd); - } else { - virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd); - } -} - int virtio_set_guest_notifier(VirtIODevice *vdev, int n, bool assign, bool with_irqfd) { - VirtQueue *vq =3D NULL; - EventNotifier *notifier =3D NULL; - - if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { - notifier =3D virtio_config_get_guest_notifier(vdev); - } else { - vq =3D virtio_get_queue(vdev, n); - notifier =3D virtio_queue_get_guest_notifier(vq); - } + bool is_config =3D n =3D=3D VIRTIO_CONFIG_IRQ_IDX; + VirtQueue *vq =3D is_config ? NULL : virtio_get_queue(vdev, n); + EventNotifier *notifier =3D is_config ? + virtio_config_get_guest_notifier(vdev) : + virtio_queue_get_guest_notifier(vq); + EventNotifierHandler *read_fn =3D is_config ? + virtio_config_guest_notifier_read : + virtio_queue_guest_notifier_read; =20 if (assign) { int r =3D event_notifier_init(notifier, 0); if (r < 0) { return r; } - virtio_set_guest_notifier_fd_handler(vdev, vq, n, true, with_irqfd= ); - } else { - virtio_set_guest_notifier_fd_handler(vdev, vq, n, false, with_irqf= d); + } + + event_notifier_set_handler(notifier, + (assign && !with_irqfd) ? read_fn : NULL); + + if (!assign) { + /* Test and clear notifier before closing it,*/ + /* in case poll callback didn't have time to run. */ + read_fn(notifier); event_notifier_cleanup(notifier); } =20 --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715471; cv=none; d=zohomail.com; s=zohoarc; b=YSOGZdjl1ERU9sQD6v1LicnYIJX/uV2tD+wN4uoPSCYR0Qlz1pnx8FVTx7VsCIS0JufRuvBejWtXk+iHX0rX7gmHApxHaC051o6buNHLeY9OOycVYXdF4cG6ED24zJodnmRWAahQpsfqkQvj+1KDkRZpkkBqRyo1PepoH+d9+q0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715471; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=z7NzS2BOltO1smLgMQemP3Hs/WnVs4xBnAPGQOKC/zU=; b=VBc8ORYtI+iDZbw+xPd3vkCgynJY3qK9UliBvbkVvjFJJiHQXQ9BgwQ0kkBjtIyiMEQs+RbdhKQs/fXWA00uYI2m/IenvPaQjLcT5+9fz0qKvATdUd8iZEy1Jgdpmwne11EyDQ0Sk6fGKKn0NL5sxajRYwexy25xM+aeWXGhqZM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715470383813.0894935439877; Mon, 20 Apr 2026 13:04:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEuqx-0001Y4-Gu; Mon, 20 Apr 2026 16:04:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuql-0001LU-Ax for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:09 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqi-0001oR-JF for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:07 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id CDC5D80786; Mon, 20 Apr 2026 23:04:02 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-Dpvbel3I; Mon, 20 Apr 2026 23:04:02 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1776715442; bh=z7NzS2BOltO1smLgMQemP3Hs/WnVs4xBnAPGQOKC/zU=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=hyQWB2qsYq5I8xbu0kEStJIqOTB+WPxzzOVpniK3+9ZlG4AGe+iCo7F6hs8Fxaq7V ALIGy+lNlJz0K+xFWThXM/EW1TH8mKZY/2dcZoklbFfynlfO0X9Mwj4+9i0IgpIHLT KvatKxAIPDmG7s/bpGq0/uZXG55qLYBM5mNCOBoE= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v6 09/22] vhost-user: keep QIOChannelSocket for backend channel Date: Mon, 20 Apr 2026 23:03:24 +0300 Message-ID: <20260420200339.708640-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715474130158500 Content-Type: text/plain; charset="utf-8" Keep QIOChannelSocket pointer instead of more generic QIOChannel. No real difference for now, but it would be simpler to migrate socket fd in further commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/virtio/vhost-user.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 68dd89cd8f8..31eaf65430e 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -239,7 +239,7 @@ struct vhost_user { struct vhost_dev *dev; /* Shared between vhost devs of the same virtio device */ VhostUserState *user; - QIOChannel *backend_ioc; + QIOChannelSocket *backend_sioc; GSource *backend_src; NotifierWithReturn postcopy_notifier; struct PostCopyFD postcopy_fd; @@ -1796,8 +1796,8 @@ static void close_backend_channel(struct vhost_user *= u) g_source_destroy(u->backend_src); g_source_unref(u->backend_src); u->backend_src =3D NULL; - object_unref(OBJECT(u->backend_ioc)); - u->backend_ioc =3D NULL; + object_unref(OBJECT(u->backend_sioc)); + u->backend_sioc =3D NULL; } =20 static gboolean backend_read(QIOChannel *ioc, GIOCondition condition, @@ -1909,7 +1909,6 @@ static int vhost_setup_backend_channel(struct vhost_d= ev *dev) bool reply_supported =3D vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_A= CK); Error *local_err =3D NULL; - QIOChannel *ioc; =20 if (!vhost_user_has_protocol_feature( dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ)) { @@ -1922,15 +1921,15 @@ static int vhost_setup_backend_channel(struct vhost= _dev *dev) return -saved_errno; } =20 - ioc =3D QIO_CHANNEL(qio_channel_socket_new_fd(sv[0], &local_err)); - if (!ioc) { + u->backend_sioc =3D qio_channel_socket_new_fd(sv[0], &local_err); + if (!u->backend_sioc) { error_report_err(local_err); return -ECONNREFUSED; } - u->backend_ioc =3D ioc; - u->backend_src =3D qio_channel_add_watch_source(u->backend_ioc, - G_IO_IN | G_IO_HUP, - backend_read, dev, NULL, N= ULL); + u->backend_src =3D qio_channel_add_watch_source(QIO_CHANNEL(u->backend= _sioc), + G_IO_IN | G_IO_HUP, + backend_read, dev, + NULL, NULL); =20 if (reply_supported) { msg.hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; @@ -2350,7 +2349,7 @@ static int vhost_user_backend_cleanup(struct vhost_de= v *dev) close(u->postcopy_fd.fd); u->postcopy_fd.handler =3D NULL; } - if (u->backend_ioc) { + if (u->backend_sioc) { close_backend_channel(u); } g_free(u->region_rb); --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715603; cv=none; d=zohomail.com; s=zohoarc; b=fsMlmGJhlumglKkq3EnpiMeDmfAQVAAzEZqg2qK6xDAmevR6FyA89d901KunrP15Q4LR5JPyjvKUsryzSiTU8g/fVrDIlgd0X7vwXKiyy2tGbmRcbKNJvZ9N+kYBhDzFXxNnSe8TrHfTC9cv97B5ifmdtHIQbCTqqgUbnqAue7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715603; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=34scPHp2ZdybOm2yZ0WL9aJaMm2nao2xuPbVsUANPc0=; b=L2VWgdYYKDi2nZeo6bVNkdgXe6FXq278oc61FOkDr9ja/3UqDQJJ15+H3kKOGL+x+zjPhSnOdL/jWjyecXAzW23PtB4uie+dGeftfxpPKnzyCCUXRBaKTGldmAVvo5MPC/NSoIKeNPWfS7je+zvD24Mo3CxAdX/pa1Gi2r/SvTk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715603366780.4464393408163; Mon, 20 Apr 2026 13:06:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEur2-0001lu-Ke; Mon, 20 Apr 2026 16:04:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqo-0001Mi-0I for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:11 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqj-0001oZ-VD for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:08 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 3E5CE80795; Mon, 20 Apr 2026 23:04:04 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-IJFHQbSb; Mon, 20 Apr 2026 23:04:03 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1776715443; bh=34scPHp2ZdybOm2yZ0WL9aJaMm2nao2xuPbVsUANPc0=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=RgFUKMAwfAaoFaTDJl/pPEutgmAh4vjAg26XhDyCrc3eT+sX8p4hQfMEUaiRH+/6H 3L/oFWlAxcBB35saNHuI8+EsAMm1LZJ+490lT4cyE5wKaYpCf28AAL1OIoqOJhG90k 7SSXuo1Q0aan3PNX1rYdSnyrrjX0ppMA0luaJ7kE= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v6 10/22] vhost: vhost_virtqueue_start(): fix failure path Date: Mon, 20 Apr 2026 23:03:25 +0300 Message-ID: <20260420200339.708640-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715604094154100 Content-Type: text/plain; charset="utf-8" We miss call to unmap in cases when vhost_memory_map() returns lenght less than requested (still we consider such cases as an error). Let's fix it in vhost_memory_map(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index e39e0676e00..131a2fbf870 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -454,11 +454,20 @@ static inline void vhost_dev_log_resize(struct vhost_= dev *dev, uint64_t size) } =20 static void *vhost_memory_map(struct vhost_dev *dev, hwaddr addr, - hwaddr *plen, bool is_write) + hwaddr len, bool is_write) { if (!vhost_dev_has_iommu(dev)) { - return address_space_map(dev->vdev->dma_as, addr, plen, is_write, - MEMTXATTRS_UNSPECIFIED); + hwaddr mapped_len =3D len; + void *res =3D address_space_map(dev->vdev->dma_as, addr, &mapped_l= en, + is_write, MEMTXATTRS_UNSPECIFIED); + if (!res) { + return NULL; + } + if (len !=3D mapped_len) { + address_space_unmap(dev->vdev->dma_as, res, mapped_len, 0, 0); + return NULL; + } + return res; } else { return (void *)(uintptr_t)addr; } @@ -1312,22 +1321,22 @@ int vhost_virtqueue_start(struct vhost_dev *dev, } =20 l =3D vq->desc_size; - vq->desc =3D vhost_memory_map(dev, vq->desc_phys, &l, false); - if (!vq->desc || l !=3D vq->desc_size) { + vq->desc =3D vhost_memory_map(dev, vq->desc_phys, l, false); + if (!vq->desc) { r =3D -ENOMEM; goto fail_alloc_desc; } =20 l =3D vq->avail_size; - vq->avail =3D vhost_memory_map(dev, vq->avail_phys, &l, false); - if (!vq->avail || l !=3D vq->avail_size) { + vq->avail =3D vhost_memory_map(dev, vq->avail_phys, l, false); + if (!vq->avail) { r =3D -ENOMEM; goto fail_alloc_avail; } =20 l =3D vq->used_size; - vq->used =3D vhost_memory_map(dev, vq->used_phys, &l, true); - if (!vq->used || l !=3D vq->used_size) { + vq->used =3D vhost_memory_map(dev, vq->used_phys, l, true); + if (!vq->used) { r =3D -ENOMEM; goto fail_alloc_used; } --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715467; cv=none; d=zohomail.com; s=zohoarc; b=OkHYjmUOf7yVn8Ztb6RIrZz0WJHG9RAz/kkSJ4cPrC67wRAEWHNL7KOmF2EpiBwnWdsdIVoEwpJK5fPtvNHUeKgf0ZCXEZEYPA8JkqJvPUf6Sqbna5on3mShCUzpWzV0G3Xhx1ECgsgZFXJX7k1GlZYcdp80TGMqgU3XcpDxSTY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715467; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uXIHNL9MutPa4LnUI29ZbTfFKnQQj49Z1ngH4e7u84w=; b=UelRM1k6smeXpFeQgF5gPKD+uMXRSp3ai69bwAfMJzhxllccxMDPv9XFVA+YKuqtW8jGKkQwR9NZ/dRnHMGCYibwdXiGxwzULexxS8czKgCe9n50CL4lB/WPq1RqTdoRoFTDCcZwlskfeb5j+4is3TP+s5+zfInNZDCODO7WWjA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177671546718963.21638105832369; Mon, 20 Apr 2026 13:04:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEuqw-0001Ub-RJ; Mon, 20 Apr 2026 16:04:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqo-0001Mh-0G for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:11 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuql-0001rH-06 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:08 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 954B98075E; Mon, 20 Apr 2026 23:04:05 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-GmkwQ0HG; Mon, 20 Apr 2026 23:04:04 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1776715445; bh=uXIHNL9MutPa4LnUI29ZbTfFKnQQj49Z1ngH4e7u84w=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=c+uUBiH907IjVXJw1zl5uBESeVKMUBqxxRWS1cnHC/XwXtxZJ5MEUW/2Lq+7q5NWD hwjYgMJBQhVGf77y0c5+y4Y2RgGtujS5zHlJJL8q32TVCsNVqF7s/T0WEPYdm5PKgj sg6sKhUJ/iOwz4nW3f6LQaTXq5Yeh3wgVolKUxvU= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v6 11/22] vhost: make vhost_memory_unmap() null-safe Date: Mon, 20 Apr 2026 23:03:26 +0300 Message-ID: <20260420200339.708640-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715467755158500 Content-Type: text/plain; charset="utf-8" This helps to simplify failure paths of vhost_virtqueue_start() a lot. We also need to zero-out pointers on unmap, to not try to unmap invalid pointers. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 131a2fbf870..b9b7a984e33 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -473,14 +473,20 @@ static void *vhost_memory_map(struct vhost_dev *dev, = hwaddr addr, } } =20 -static void vhost_memory_unmap(struct vhost_dev *dev, void *buffer, +static void vhost_memory_unmap(struct vhost_dev *dev, void **buffer, hwaddr len, int is_write, hwaddr access_len) { + if (!*buffer) { + return; + } + if (!vhost_dev_has_iommu(dev)) { - address_space_unmap(dev->vdev->dma_as, buffer, len, is_write, + address_space_unmap(dev->vdev->dma_as, *buffer, len, is_write, access_len); } + + *buffer =3D NULL; } =20 static int vhost_verify_ring_part_mapping(void *ring_hva, @@ -1324,33 +1330,33 @@ int vhost_virtqueue_start(struct vhost_dev *dev, vq->desc =3D vhost_memory_map(dev, vq->desc_phys, l, false); if (!vq->desc) { r =3D -ENOMEM; - goto fail_alloc_desc; + goto fail; } =20 l =3D vq->avail_size; vq->avail =3D vhost_memory_map(dev, vq->avail_phys, l, false); if (!vq->avail) { r =3D -ENOMEM; - goto fail_alloc_avail; + goto fail; } =20 l =3D vq->used_size; vq->used =3D vhost_memory_map(dev, vq->used_phys, l, true); if (!vq->used) { r =3D -ENOMEM; - goto fail_alloc_used; + goto fail; } =20 r =3D vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabl= ed); if (r < 0) { - goto fail_alloc; + goto fail; } =20 file.fd =3D event_notifier_get_fd(virtio_queue_get_host_notifier(vvq)); r =3D dev->vhost_ops->vhost_set_vring_kick(dev, &file); if (r) { VHOST_OPS_DEBUG(r, "vhost_set_vring_kick failed"); - goto fail_kick; + goto fail; } =20 /* Clear and discard previous events if any. */ @@ -1370,24 +1376,19 @@ int vhost_virtqueue_start(struct vhost_dev *dev, file.fd =3D -1; r =3D dev->vhost_ops->vhost_set_vring_call(dev, &file); if (r) { - goto fail_vector; + goto fail; } } =20 return 0; =20 -fail_vector: -fail_kick: -fail_alloc: - vhost_memory_unmap(dev, vq->used, virtio_queue_get_used_size(vdev, idx= ), +fail: + vhost_memory_unmap(dev, &vq->used, virtio_queue_get_used_size(vdev, id= x), 0, 0); -fail_alloc_used: - vhost_memory_unmap(dev, vq->avail, virtio_queue_get_avail_size(vdev, i= dx), + vhost_memory_unmap(dev, &vq->avail, virtio_queue_get_avail_size(vdev, = idx), 0, 0); -fail_alloc_avail: - vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx= ), + vhost_memory_unmap(dev, &vq->desc, virtio_queue_get_desc_size(vdev, id= x), 0, 0); -fail_alloc_desc: return r; } =20 @@ -1434,11 +1435,11 @@ static int do_vhost_virtqueue_stop(struct vhost_dev= *dev, vhost_vq_index); } =20 - vhost_memory_unmap(dev, vq->used, virtio_queue_get_used_size(vdev, idx= ), + vhost_memory_unmap(dev, &vq->used, virtio_queue_get_used_size(vdev, id= x), 1, virtio_queue_get_used_size(vdev, idx)); - vhost_memory_unmap(dev, vq->avail, virtio_queue_get_avail_size(vdev, i= dx), + vhost_memory_unmap(dev, &vq->avail, virtio_queue_get_avail_size(vdev, = idx), 0, virtio_queue_get_avail_size(vdev, idx)); - vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx= ), + vhost_memory_unmap(dev, &vq->desc, virtio_queue_get_desc_size(vdev, id= x), 0, virtio_queue_get_desc_size(vdev, idx)); return r; } --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715507; cv=none; d=zohomail.com; s=zohoarc; b=Ry4CjfFAMXe3hiI6dCI3iK3afa/nUbUaX57wcjxRjXOE5xgyHgx+j50fXhyuDiTlEfPcYgDtUK6/1OmYPKFNvoTXSXDSJ548br+QhZUmHtMSTq1txqtqdQlFzrNgLjJ656T8k+BI/cieAdjleEn/IpESmhiYpdOeTIjQ7hNNitQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715507; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DVN2E1fV05CJbMdBv0cpyI66en0JLWifnhyATE8IemA=; b=VoehPVIlkFBQzQfAqGffdg2e5Rfx8wSpqkglMV2p2nqz2TLKKbk2SoXILtummfYOyJzExla2BMzYza1aaDjqKQk3boFNE2vNfJUnxJ8sMtk6dtRRiFAmEBvjUT+InpOU9vRSSwdit8y5Y0uwvQsdeUpzhl+wQzifvIliGb+bEbU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715507211643.8002519044758; Mon, 20 Apr 2026 13:05:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEuqy-0001dG-SM; Mon, 20 Apr 2026 16:04:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqp-0001My-C9 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:11 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqn-0001sk-P4 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:11 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 078CC80663; Mon, 20 Apr 2026 23:04:07 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-Jg34glw7; Mon, 20 Apr 2026 23:04:06 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1776715446; bh=DVN2E1fV05CJbMdBv0cpyI66en0JLWifnhyATE8IemA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=wmo2gjEK9wwgvGffYGrYyWeCN5amZ1DdAcrCdPrUV9geQocQOTJjVAgSkG7q/9Q3l 5qXGadu3pwO4BMkYnyJSAw3ffC5gzrmywWfQWZzn7SeqxzPe+DhO3aNjgWdc/XNo8V +Xy9ldwcm/MSD64iN7bb1A77pOjsfYvBgJ8BZAGc= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v6 12/22] vhost: simplify calls to vhost_memory_unmap() Date: Mon, 20 Apr 2026 23:03:27 +0300 Message-ID: <20260420200339.708640-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715508594154100 Content-Type: text/plain; charset="utf-8" No reason to calculate memory size again, as we have corresponding variable for each vring. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index b9b7a984e33..f43e563f0de 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1383,12 +1383,9 @@ int vhost_virtqueue_start(struct vhost_dev *dev, return 0; =20 fail: - vhost_memory_unmap(dev, &vq->used, virtio_queue_get_used_size(vdev, id= x), - 0, 0); - vhost_memory_unmap(dev, &vq->avail, virtio_queue_get_avail_size(vdev, = idx), - 0, 0); - vhost_memory_unmap(dev, &vq->desc, virtio_queue_get_desc_size(vdev, id= x), - 0, 0); + vhost_memory_unmap(dev, &vq->used, vq->used_size, 0, 0); + vhost_memory_unmap(dev, &vq->avail, vq->avail_size, 0, 0); + vhost_memory_unmap(dev, &vq->desc, vq->desc_size, 0, 0); return r; } =20 @@ -1435,12 +1432,9 @@ static int do_vhost_virtqueue_stop(struct vhost_dev = *dev, vhost_vq_index); } =20 - vhost_memory_unmap(dev, &vq->used, virtio_queue_get_used_size(vdev, id= x), - 1, virtio_queue_get_used_size(vdev, idx)); - vhost_memory_unmap(dev, &vq->avail, virtio_queue_get_avail_size(vdev, = idx), - 0, virtio_queue_get_avail_size(vdev, idx)); - vhost_memory_unmap(dev, &vq->desc, virtio_queue_get_desc_size(vdev, id= x), - 0, virtio_queue_get_desc_size(vdev, idx)); + vhost_memory_unmap(dev, &vq->used, vq->used_size, 1, vq->used_size); + vhost_memory_unmap(dev, &vq->avail, vq->avail_size, 0, vq->avail_size); + vhost_memory_unmap(dev, &vq->desc, vq->desc_size, 0, vq->desc_size); return r; } =20 --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715568; cv=none; d=zohomail.com; s=zohoarc; b=FLEJ2DBpG9RKflheO7cump0NxG7THO+giIn45yJg5Sv4+D2iWBt5fWjsQ95I7epH3ro1Pjr0rmMoqr6QkLrdrGUjbVOUBQns+ZeJi8fRhSUZmTC0R7v/rNrhiLHDciALKTPFabcDAKrj1ooDeVlAg0MYXvkAjnRH8gywJEHX0E4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715568; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XocdcTcecnBxB/Sds6p3bzMTQMvxaXfbHbggfQ8XQGg=; b=mpfNEyzf2LMzgP2f5Y8/wuxcDyiYbiHMxqA8U6AR88yQBXJiUxxoL3dor4yYXDSJyiJDwXawz/G+R71oS/SQnze9rU+VYSXEbI6wS/h2Izbmk1MRSFAuJRMSO3Vgk6+xw8dMGQQU3z1K6j3NtHXv2in8wDBpmotHdzLDRZmpqF0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715568411241.61279008576412; Mon, 20 Apr 2026 13:06:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEuqz-0001dt-0E; Mon, 20 Apr 2026 16:04:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqq-0001PP-Cr for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:13 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqo-0001xN-A4 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:12 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 0868A8071E; Mon, 20 Apr 2026 23:04:09 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-CjCKRb82; Mon, 20 Apr 2026 23:04: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=1776715448; bh=XocdcTcecnBxB/Sds6p3bzMTQMvxaXfbHbggfQ8XQGg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=sptKxpIcclktT0cPCdkVSNOgpmjwrIoFuvJW7ZwXn1CkT6AX+nEsAV3EvvhmgiG5A OpBEmotuXWYgTi6V7WMl3N12q2B4lUcAE5fCwoGZXd/eUFbCM6IGdxxwq5lA+Dn/g1 auyez3TtaeLBJxK3Kyv6L/aiQcdQcup3AdtpQ3Jo= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v6 13/22] vhost: move vrings mapping to the top of vhost_virtqueue_start() Date: Mon, 20 Apr 2026 23:03:28 +0300 Message-ID: <20260420200339.708640-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715571616154100 Content-Type: text/plain; charset="utf-8" This simplifies further refactoring and final introduction of vhost backend live migration. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/virtio/vhost.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index f43e563f0de..d5bafbcc4b3 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1303,29 +1303,6 @@ int vhost_virtqueue_start(struct vhost_dev *dev, return 0; } =20 - vq->num =3D state.num =3D virtio_queue_get_num(vdev, idx); - r =3D dev->vhost_ops->vhost_set_vring_num(dev, &state); - if (r) { - VHOST_OPS_DEBUG(r, "vhost_set_vring_num failed"); - return r; - } - - state.num =3D virtio_queue_get_last_avail_idx(vdev, idx); - r =3D dev->vhost_ops->vhost_set_vring_base(dev, &state); - if (r) { - VHOST_OPS_DEBUG(r, "vhost_set_vring_base failed"); - return r; - } - - if (vhost_needs_vring_endian(vdev)) { - r =3D vhost_virtqueue_set_vring_endian_legacy(dev, - virtio_vdev_is_big_end= ian(vdev), - vhost_vq_index); - if (r) { - return r; - } - } - l =3D vq->desc_size; vq->desc =3D vhost_memory_map(dev, vq->desc_phys, l, false); if (!vq->desc) { @@ -1347,6 +1324,28 @@ int vhost_virtqueue_start(struct vhost_dev *dev, goto fail; } =20 + vq->num =3D state.num =3D virtio_queue_get_num(vdev, idx); + r =3D dev->vhost_ops->vhost_set_vring_num(dev, &state); + if (r) { + VHOST_OPS_DEBUG(r, "vhost_set_vring_num failed"); + goto fail; + } + + state.num =3D virtio_queue_get_last_avail_idx(vdev, idx); + r =3D dev->vhost_ops->vhost_set_vring_base(dev, &state); + if (r) { + VHOST_OPS_DEBUG(r, "vhost_set_vring_base failed"); + goto fail; + } + + if (vhost_needs_vring_endian(vdev)) { + r =3D vhost_virtqueue_set_vring_endian_legacy( + dev, virtio_vdev_is_big_endian(vdev), vhost_vq_index); + if (r) { + goto fail; + } + } + r =3D vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabl= ed); if (r < 0) { goto fail; --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715483; cv=none; d=zohomail.com; s=zohoarc; b=gakQHW36naFkoE5Ws9cRH/l/70D3UQmtb8OT74vkmDW4wnUom5LD8dRj/ddtMgLuk0Kqsz72GANNWgFR/O9c1oi9BH4n4mB+jE6S2UThQ8e8g3pssUFRyd9l/Pn2YLLgJUfRIi/C/76AkrnBqUL4ET4uZrYS51c+Tn00DrxY0lo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715483; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=p7Mm9GudtPAeqe5zCfAh27owVpQGvscwVTdaF2yAkKc=; b=XL3KQyxpKf6qr1K/ruTJX7R6mHcbNX3NbUBCtS4Qd5PQNzqF2D/jjI8aRZa86wiyFkMCqInaLjQcKrWFEcNk9V9+mcU2suFtQkydsf3tpVVb4ZurFwVbc2ZC9IatDI1ipnohCZ5yC0nsPr6x5UG7cj2oR/Bhf41mvoL7sbN5Bu4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715483340936.5369438453952; Mon, 20 Apr 2026 13:04:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEur4-0001n1-2a; Mon, 20 Apr 2026 16:04:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqt-0001QR-6P for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:15 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqr-0001zo-Od for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:14 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 7D7F580778; Mon, 20 Apr 2026 23:04:12 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-oFxuUmkY; Mon, 20 Apr 2026 23:04:11 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1776715451; bh=p7Mm9GudtPAeqe5zCfAh27owVpQGvscwVTdaF2yAkKc=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=I0QT02KASqb47D2QLz53aIRZLVwW1anG1pulBEEU3dvb6VTsSywKzY7QKtwSdLelk yS/id88O6ON6KZfZEBt+PsYbVd/fJSqfWIFr/Kdtn6wFLrfrjW9KN0M/u+ANy9lrD5 FxGYHbGEcDFUTN1Co4qKZRj/KXjEN465bl1mE21E= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v6 14/22] vhost: vhost_virtqueue_start(): drop extra local variables Date: Mon, 20 Apr 2026 23:03:29 +0300 Message-ID: <20260420200339.708640-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715484259154100 Content-Type: text/plain; charset="utf-8" One letter named variables doesn't really help to read the code, and they simply duplicate structure fields. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index d5bafbcc4b3..a3bf7e5a9b8 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1277,7 +1277,6 @@ int vhost_virtqueue_start(struct vhost_dev *dev, BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); VirtioBusState *vbus =3D VIRTIO_BUS(qbus); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); - hwaddr l; int r; int vhost_vq_index =3D dev->vhost_ops->vhost_get_vq_index(dev, idx); struct vhost_vring_file file =3D { @@ -1302,23 +1301,17 @@ int vhost_virtqueue_start(struct vhost_dev *dev, /* Queue might not be ready for start */ return 0; } - - l =3D vq->desc_size; - vq->desc =3D vhost_memory_map(dev, vq->desc_phys, l, false); + vq->desc =3D vhost_memory_map(dev, vq->desc_phys, vq->desc_size, false= ); if (!vq->desc) { r =3D -ENOMEM; goto fail; } - - l =3D vq->avail_size; - vq->avail =3D vhost_memory_map(dev, vq->avail_phys, l, false); + vq->avail =3D vhost_memory_map(dev, vq->avail_phys, vq->avail_size, fa= lse); if (!vq->avail) { r =3D -ENOMEM; goto fail; } - - l =3D vq->used_size; - vq->used =3D vhost_memory_map(dev, vq->used_phys, l, true); + vq->used =3D vhost_memory_map(dev, vq->used_phys, vq->used_size, true); if (!vq->used) { r =3D -ENOMEM; goto fail; --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715591; cv=none; d=zohomail.com; s=zohoarc; b=L0KEdqWUwQROpYQgqoFrmVuiK1eCbGEt40/HD3oEYU5HY8Fj0aIKu6toH8nLjqrhfjo4PhyF7VHqyJWRysRHdKQjSK/iH0H6C0UUMmGku4fp9TZx/EuXS3ICMWteNMDiERfAQlNRh4cwuF6chLq/jOS6vWC7PBFeUhh6dWdtg0s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715591; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8EIeZvm1CKDsTOi9FWm63RbYAd44Mkvf/dqAC7eZxQg=; b=iwPD7MG4Dwp2Nuf+DWOQ+wFQvV4fIevj9LV+tsMX0CsJyxsVATHRhdOs3ktjPH+J0QIaliwrtPw//yHEDwH9ZbwdnLS2pzyyWTLocLSY//7xSeiwzPZJLaL4CwtykdK7ve/XAJyNZ0V2Myg3cRsw3PT7CQOmLssrKhgaz19L+Lw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715591958503.08555951958647; Mon, 20 Apr 2026 13:06:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEur0-0001fw-1z; Mon, 20 Apr 2026 16:04:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqv-0001SB-B1 for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:18 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqt-0001zs-HU for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:17 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id D761780663; Mon, 20 Apr 2026 23:04:13 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-EYOraZle; Mon, 20 Apr 2026 23:04: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=1776715453; bh=8EIeZvm1CKDsTOi9FWm63RbYAd44Mkvf/dqAC7eZxQg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=yCaKZ6tQRATwU7ge4mW4iVgjcIju6xrIUPdK1nvy7GkGPSTpRKaVd10f/F/nK9FSq yU+IWzHV8E8bAgmRup4KkDs93pJ917jpI8m9jd4PGVsZxjoQ81AXGJkLxvqNv59UmO fnZaXCEHuEAui0zKoQsIAHxS3Bgcci4dcbLNdRM8= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v6 15/22] vhost: final refactoring of vhost vrings map/unmap Date: Mon, 20 Apr 2026 23:03:30 +0300 Message-ID: <20260420200339.708640-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715592323158500 Content-Type: text/plain; charset="utf-8" Introduce helper functions vhost_vrings_map() and vhost_vrings_unmap() and use them. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 89 +++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index a3bf7e5a9b8..c71b18cfc8d 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -489,6 +489,56 @@ static void vhost_memory_unmap(struct vhost_dev *dev, = void **buffer, *buffer =3D NULL; } =20 +static void vhost_vrings_unmap(struct vhost_dev *dev, + struct vhost_virtqueue *vq, bool touched) +{ + vhost_memory_unmap(dev, &vq->used, vq->used_size, touched, + touched ? vq->used_size : 0); + vhost_memory_unmap(dev, &vq->avail, vq->avail_size, 0, + touched ? vq->avail_size : 0); + vhost_memory_unmap(dev, &vq->desc, vq->desc_size, 0, + touched ? vq->desc_size : 0); +} + +static int vhost_vrings_map(struct vhost_dev *dev, + struct VirtIODevice *vdev, + struct vhost_virtqueue *vq, + unsigned idx) +{ + vq->desc_size =3D virtio_queue_get_desc_size(vdev, idx); + vq->desc_phys =3D virtio_queue_get_desc_addr(vdev, idx); + vq->desc =3D NULL; + vq->avail_size =3D virtio_queue_get_avail_size(vdev, idx); + vq->avail_phys =3D virtio_queue_get_avail_addr(vdev, idx); + vq->avail =3D NULL; + vq->used_size =3D virtio_queue_get_used_size(vdev, idx); + vq->used_phys =3D virtio_queue_get_used_addr(vdev, idx); + vq->used =3D NULL; + + if (vq->desc_phys =3D=3D 0) { + /* Queue might not be ready for start */ + return 0; + } + vq->desc =3D vhost_memory_map(dev, vq->desc_phys, vq->desc_size, false= ); + if (!vq->desc) { + goto fail; + } + vq->avail =3D vhost_memory_map(dev, vq->avail_phys, vq->avail_size, fa= lse); + if (!vq->avail) { + goto fail; + } + vq->used =3D vhost_memory_map(dev, vq->used_phys, vq->used_size, true); + if (!vq->used) { + goto fail; + } + + return 1; + +fail: + vhost_vrings_unmap(dev, vq, false); + return -ENOMEM; +} + static int vhost_verify_ring_part_mapping(void *ring_hva, uint64_t ring_gpa, uint64_t ring_size, @@ -1287,34 +1337,9 @@ int vhost_virtqueue_start(struct vhost_dev *dev, }; struct VirtQueue *vvq =3D virtio_get_queue(vdev, idx); =20 - vq->desc_size =3D virtio_queue_get_desc_size(vdev, idx); - vq->desc_phys =3D virtio_queue_get_desc_addr(vdev, idx); - vq->desc =3D NULL; - vq->avail_size =3D virtio_queue_get_avail_size(vdev, idx); - vq->avail_phys =3D virtio_queue_get_avail_addr(vdev, idx); - vq->avail =3D NULL; - vq->used_size =3D virtio_queue_get_used_size(vdev, idx); - vq->used_phys =3D virtio_queue_get_used_addr(vdev, idx); - vq->used =3D NULL; - - if (vq->desc_phys =3D=3D 0) { - /* Queue might not be ready for start */ - return 0; - } - vq->desc =3D vhost_memory_map(dev, vq->desc_phys, vq->desc_size, false= ); - if (!vq->desc) { - r =3D -ENOMEM; - goto fail; - } - vq->avail =3D vhost_memory_map(dev, vq->avail_phys, vq->avail_size, fa= lse); - if (!vq->avail) { - r =3D -ENOMEM; - goto fail; - } - vq->used =3D vhost_memory_map(dev, vq->used_phys, vq->used_size, true); - if (!vq->used) { - r =3D -ENOMEM; - goto fail; + r =3D vhost_vrings_map(dev, vdev, vq, idx); + if (r <=3D 0) { + return r; } =20 vq->num =3D state.num =3D virtio_queue_get_num(vdev, idx); @@ -1375,9 +1400,7 @@ int vhost_virtqueue_start(struct vhost_dev *dev, return 0; =20 fail: - vhost_memory_unmap(dev, &vq->used, vq->used_size, 0, 0); - vhost_memory_unmap(dev, &vq->avail, vq->avail_size, 0, 0); - vhost_memory_unmap(dev, &vq->desc, vq->desc_size, 0, 0); + vhost_vrings_unmap(dev, vq, false); return r; } =20 @@ -1424,9 +1447,7 @@ static int do_vhost_virtqueue_stop(struct vhost_dev *= dev, vhost_vq_index); } =20 - vhost_memory_unmap(dev, &vq->used, vq->used_size, 1, vq->used_size); - vhost_memory_unmap(dev, &vq->avail, vq->avail_size, 0, vq->avail_size); - vhost_memory_unmap(dev, &vq->desc, vq->desc_size, 0, vq->desc_size); + vhost_vrings_unmap(dev, vq, true); return r; } =20 --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715509; cv=none; d=zohomail.com; s=zohoarc; b=dwNv4FPpvbLzKE9jQWGqdqrFQGf04I+S+E1C6SWM9o2bVViO8jaSP/TSh4v8GIVFD4le4IGgIT8bILofRtC1L+VQ+jI8ta/EVeZhArbL+BcuH1tJ3go3fB5vXEooIyRP7hlbiIqzRFd6zGVUt7MsMf2lGqEumjxISi1/GNC/zsY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715509; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LWaZ2xUEjmtd/ow6Imr4cQ0Z/NL5RAS13aeCcPFAeGQ=; b=fU3Z40WgPGL8TeZU0ElDLBTxevTRFc35FzSUcGLOJfPcP5DAmR+jD4c7oAAnDUSv/OWzifjE/Pskzeggb/PLrwiP0G3oDuR2HqgxJd6nH04iznw0K1BVWxcdTEarX6dbpXurbTNlOBzfODLh5VgJ0ap+7Jvx+ZxMkoS8vaNMKGA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715509377101.31969950146481; Mon, 20 Apr 2026 13:05:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEur1-0001l2-Nx; Mon, 20 Apr 2026 16:04:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqw-0001SR-2P for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:18 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqu-000203-HZ for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:17 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 3F3E38071E; Mon, 20 Apr 2026 23:04:15 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-0TxfyeRG; Mon, 20 Apr 2026 23:04: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=1776715454; bh=LWaZ2xUEjmtd/ow6Imr4cQ0Z/NL5RAS13aeCcPFAeGQ=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=XACxuPAd70yQk9yYkeCDEXY+r7qdWHJbT6V2O8bi8cTQypd1922mjFvpkCjxa+rCm VFXhjLTiT9se5ANwigdNypjf9O7XB7G+lMM/AB7w3b0OC6GOVoxD1syrBhDn6aTLvU uFahJbVfOkjqEx8uTV909S8RCW5zazsDUmSPPswo= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v6 16/22] vhost: simplify vhost_dev_init() error-path Date: Mon, 20 Apr 2026 23:03:31 +0300 Message-ID: <20260420200339.708640-17-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715510644154100 Content-Type: text/plain; charset="utf-8" No reason to rollback setting up busyloop timeout on failure. We don't do such rollback for other things we setup in backend. Also, look at vhost_net_init() in hw/net/vhost_net.c: we may fail after successfully called vhost_dev_init(), and in this case we'll just call vhost_dev_cleanup(), which doesn't rollback busyloop timeout. So, let's keep it simple. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/virtio/vhost.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index c71b18cfc8d..7f370f393e9 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1624,7 +1624,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, busyloop_timeout); if (r < 0) { error_setg_errno(errp, -r, "Failed to set busyloop timeout= "); - goto fail_busyloop; + goto fail; } } } @@ -1664,7 +1664,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, if (hdev->migration_blocker !=3D NULL) { r =3D migrate_add_blocker_normal(&hdev->migration_blocker, errp); if (r < 0) { - goto fail_busyloop; + goto fail; } } =20 @@ -1696,17 +1696,11 @@ int vhost_dev_init(struct vhost_dev *hdev, void *op= aque, " than current number of used (%d) and reserved (%d)" " memory slots for memory devices.", limit, used, reser= ved); r =3D -EINVAL; - goto fail_busyloop; + goto fail; } =20 return 0; =20 -fail_busyloop: - if (busyloop_timeout) { - while (--i >=3D 0) { - vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i,= 0); - } - } fail: hdev->nvqs =3D n_initialized_vqs; vhost_dev_cleanup(hdev); --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715624; cv=none; d=zohomail.com; s=zohoarc; b=ZBnpSVzWL1+q4iXLqrZL2WuxAPPEz750QEbKCQF3sc+cDHrdrIvdm+YCKxSeypcmE8/D4gCCgzq+5GijVAW42TnUcVVeuUBIfjuRjaz2nikl1t1d70DxF/J3fNJkmXZf9DCew9zVpfpgngKWOr+GNcDtvztStPyu2N+xSshyyv0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715624; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9H42VfdWXv4YR9fUBy+45ZxRHJLalt72HE6C4geWja4=; b=GZQNnKxVMMdG0VTLo/tCODRcltfgU3WyC7QN3VdRsmpF2dov9uJmCV7t/0A9O5eLmt3gxNzxkemul3msRKwksiNOENAJ4LM52GW4YaP9VrHZk1mqY+CzLWwlDinZVPEl1ySqblPfXHdaK++nVwpAqQtcenrHPZEM++GBBSPY6jw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715624318697.5985846787455; Mon, 20 Apr 2026 13:07:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEur2-0001lX-6s; Mon, 20 Apr 2026 16:04:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqx-0001Z8-Ma for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:19 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqw-00020F-4t for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:19 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id D2D598075D; Mon, 20 Apr 2026 23:04:16 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-sfRtE90u; Mon, 20 Apr 2026 23:04: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=1776715456; bh=9H42VfdWXv4YR9fUBy+45ZxRHJLalt72HE6C4geWja4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=ywciq/407nKvyyLDStnLQ5Civcs8456EvORmQY77lwg8a6AH2ZM3LryjPlUpp33x3 cPNvayL0jsKAErcRu8YFlpq7NUDGyTNPevoMQwbpfkHAT9F7IwBSfjeLvtD8ZQPVja Z0FvLGDFsnQK+64eN0M/AYgQOyEZSlbFbuBBBIcI= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v6 17/22] vhost: move busyloop timeout initialization to vhost_virtqueue_init() Date: Mon, 20 Apr 2026 23:03:32 +0300 Message-ID: <20260420200339.708640-18-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715626424154100 Content-Type: text/plain; charset="utf-8" Let's all per-virtqueue initializations be in one place. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/virtio/vhost.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 7f370f393e9..55ce7ae977f 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1496,7 +1496,8 @@ static void vhost_virtqueue_error_notifier(EventNotif= ier *n) } =20 static int vhost_virtqueue_init(struct vhost_dev *dev, - struct vhost_virtqueue *vq, int n) + struct vhost_virtqueue *vq, int n, + bool busyloop_timeout) { int vhost_vq_index =3D dev->vhost_ops->vhost_get_vq_index(dev, n); struct vhost_vring_file file =3D { @@ -1533,6 +1534,14 @@ static int vhost_virtqueue_init(struct vhost_dev *de= v, vhost_virtqueue_error_notifier); } =20 + if (busyloop_timeout) { + r =3D vhost_virtqueue_set_busyloop_timeout(dev, n, busyloop_timeou= t); + if (r < 0) { + VHOST_OPS_DEBUG(r, "Failed to set busyloop timeout"); + goto fail_err; + } + } + return 0; =20 fail_err: @@ -1611,24 +1620,14 @@ int vhost_dev_init(struct vhost_dev *hdev, void *op= aque, } =20 for (i =3D 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { - r =3D vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i= ); + r =3D vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i, + busyloop_timeout); if (r < 0) { error_setg_errno(errp, -r, "Failed to initialize virtqueue %d"= , i); goto fail; } } =20 - if (busyloop_timeout) { - for (i =3D 0; i < hdev->nvqs; ++i) { - r =3D vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_inde= x + i, - busyloop_timeout); - if (r < 0) { - error_setg_errno(errp, -r, "Failed to set busyloop timeout= "); - goto fail; - } - } - } - virtio_features_copy(hdev->_features_ex, features); =20 hdev->memory_listener =3D (MemoryListener) { --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715556; cv=none; d=zohomail.com; s=zohoarc; b=BEfgDC2ZNUN6rizelRGQ/HY2zcjw5j2z4y2v3Yr3Uj12hArE6DrbZ9DzYvgxSD2PdCiWWegMYYMnUg5FjvwWXPZkfHktup+9YBHmtV+m8VaXFaQuc2bBXgOYk4jJcMBYoTJ4RF25M3zQCRJBOh+uPqDqtaIZP6+AisKYcjhMFWw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715556; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vyElk3FXLNKWSELumKfi8IPDAq8aQq0zwO2Sd49gLCs=; b=j6NSenngTttxkUQqTRx1EyXB0ucd2OgaO0eop0GpZjvqtinxVS+/kexQBDyeesM5RddO5w4CvqDVJu/O+LigWkc1ZnWiTOsDz7SLZ75JUoc0twiXv4WRBOh2rs4kbWKxU2GY5L6wUBbVzdT8+WWRmq1ZVzTOSlfOkoifN8oir5s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715555645568.0525370841176; Mon, 20 Apr 2026 13:05:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEur2-0001lv-NW; Mon, 20 Apr 2026 16:04:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEur0-0001gF-4g for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:22 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqy-00020p-EV for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:21 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id B97898075E; Mon, 20 Apr 2026 23:04:18 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-i8DFrlwM; Mon, 20 Apr 2026 23:04: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=1776715458; bh=vyElk3FXLNKWSELumKfi8IPDAq8aQq0zwO2Sd49gLCs=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Yo9hkl0pAj+aU4PtUgTEnzd4COY8bEZ4ONuImVPL/ZWkQw+Z/S1nXBBNVw1bNYx4O AkGvXniSpr/D4+cVfjC5qWju5QqGX+ziKpCC4uvrng1tJseFg1jFgfeFsl9u8yCXbQ Jb3k5gbU3Ijl18ZKqQ9AHSiXdAyi+GpOdIJcqzKg= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v6 18/22] vhost: vhost_dev_init(): simplify features initialization Date: Mon, 20 Apr 2026 23:03:33 +0300 Message-ID: <20260420200339.708640-19-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715558243158500 Content-Type: text/plain; charset="utf-8" Drop extra variable and extra function parameter passing, initialize dev._features directly. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 55ce7ae977f..93c6a5f5e9a 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1560,18 +1560,17 @@ static void vhost_virtqueue_cleanup(struct vhost_vi= rtqueue *vq) } } =20 -static int vhost_dev_get_features(struct vhost_dev *hdev, - uint64_t *features) +static int vhost_dev_init_features(struct vhost_dev *hdev) { uint64_t features64; int r; =20 if (hdev->vhost_ops->vhost_get_features_ex) { - return hdev->vhost_ops->vhost_get_features_ex(hdev, features); + return hdev->vhost_ops->vhost_get_features_ex(hdev, hdev->_feature= s_ex); } =20 r =3D hdev->vhost_ops->vhost_get_features(hdev, &features64); - virtio_features_from_u64(features, features64); + virtio_features_from_u64(hdev->_features_ex, features64); return r; } =20 @@ -1579,7 +1578,6 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, VhostBackendType backend_type, uint32_t busyloop_timeou= t, Error **errp) { - uint64_t features[VIRTIO_FEATURES_NU64S]; unsigned int used, reserved, limit; int i, r, n_initialized_vqs =3D 0; =20 @@ -1600,9 +1598,9 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, goto fail; } =20 - r =3D vhost_dev_get_features(hdev, features); + r =3D vhost_dev_init_features(hdev); if (r < 0) { - error_setg_errno(errp, -r, "vhost_get_features failed"); + error_setg_errno(errp, -r, "vhost_init_features failed"); goto fail; } =20 @@ -1628,8 +1626,6 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, } } =20 - virtio_features_copy(hdev->_features_ex, features); - hdev->memory_listener =3D (MemoryListener) { .name =3D "vhost", .begin =3D vhost_begin, --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715478; cv=none; d=zohomail.com; s=zohoarc; b=BDHiNmoLetwgrSZW9pZZYjuSLsiT/63uzA2X+ycBsfZVd4A0F4h5MPLSi/YPWoppgm+wf7MrmoHhcXiZj6RUSjfDcQo1MXZ1TbXpMyGhL5uatYuxicYaoILMj/gRsVTybVSzVcV2lcNn3dHSs3X1IpiJL+tCL1LWePvPTfUCMh8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715478; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Cy9Kfz7LJW3sOr7QWA68FHIr1PIHJhZFd5ELVkaKPk4=; b=ioIZYTuEkmqeQbnjxQKdCLoZmtr8E7eJSLu8ZmMtfMXF2Y0w5cMwgFqCoGrLphdbry7X419mL52E2dT9pJLVqWa67LHONA3t0t+qxuVKyKTQ4MxlGkfiz0XXh+vBmHscigJkaax4sb7OzP3AUKGsqYnnP9aRBmmKBQVX2AcLaeo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177671547832354.515548931911326; Mon, 20 Apr 2026 13:04:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEur9-0001vp-KV; Mon, 20 Apr 2026 16:04:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEur1-0001kH-DY for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:23 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEuqz-00021n-St for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:23 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 5C32E80778; Mon, 20 Apr 2026 23:04:20 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-14GazpNW; Mon, 20 Apr 2026 23:04: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=1776715459; bh=Cy9Kfz7LJW3sOr7QWA68FHIr1PIHJhZFd5ELVkaKPk4=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=DT1/7gb23Gp+wlYc0luFQR7iZqgMraePV85BhDIEZAL+sN9fwy/ZhrI8qsudfpcvz JjjpwZmmLgL0vzJPTH/s42CNtZdML0YAoSmQk912bwyucJ4XbM3asghE1yilRs6UJH txeyTUGlLmY97cBMrw5vL6KAJ+UYoOLWM8/H5/Ac= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Raphael Norwitz Subject: [PATCH v6 19/22] hw/virtio/virtio-bus: refactor virtio_bus_set_host_notifier() Date: Mon, 20 Apr 2026 23:03:34 +0300 Message-ID: <20260420200339.708640-20-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715480193154100 The logic kept as is. Refactor to simplify further changes. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Raphael Norwitz Reviewed-by: Daniil Tatianin --- hw/virtio/virtio-bus.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index cef944e0158..9b545acda31 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -298,20 +298,18 @@ int virtio_bus_set_host_notifier(VirtioBusState *bus,= int n, bool assign) __func__, strerror(-r), r); return r; } - r =3D k->ioeventfd_assign(proxy, notifier, n, true); - if (r < 0) { - error_report("%s: unable to assign ioeventfd: %d", __func__, r= ); - virtio_bus_cleanup_host_notifier(bus, n); - } - } else { - k->ioeventfd_assign(proxy, notifier, n, false); } =20 - if (r =3D=3D 0) { - virtio_queue_set_host_notifier_enabled(vq, assign); + r =3D k->ioeventfd_assign(proxy, notifier, n, assign); + if (r < 0 && assign) { + error_report("%s: unable to assign ioeventfd: %d", __func__, r); + virtio_bus_cleanup_host_notifier(bus, n); + return r; } =20 - return r; + virtio_queue_set_host_notifier_enabled(vq, assign); + + return 0; } =20 void virtio_bus_cleanup_host_notifier(VirtioBusState *bus, int n) --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715561; cv=none; d=zohomail.com; s=zohoarc; b=CZRCKGaUQLnMEwktF6uV/7oFgOtQsen8UDaD0ZWqMfol/zE9igeZASwRlasDYaACKuHz2/A80gPR5TuHPuBU14trkAtp423ekXY5tullGohLep7n6s92GARdSPmgoarq3fEjRBl9aTk/KOSRjGFkjxzTLVXlkptxu2MdROK3yCc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715561; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dU9wUhXlCE3BAJRpC9u2OYkNwoLoZDEIRrhVKwfUBGc=; b=lUTflzD4+jdJk73I900DU2hPO+v12CTloJruPxAjbfVY4iN52Y7yKDicufnL+OQ5GeRjKGPzJnM71pIBmqTWxvVSj3IZSes5SwvI2oAz/L6aofTGzeRQK+Ln7UWrhuZxt5Vy/0WwFQlu026pajMb7D5qpLjMUCxYlJYVHiGsKWY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715561070901.4824906906681; Mon, 20 Apr 2026 13:06:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEur7-0001tX-3g; Mon, 20 Apr 2026 16:04:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEur2-0001lw-RX for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:24 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEur1-00023L-6V for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:24 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id E24CD806F6; Mon, 20 Apr 2026 23:04:21 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-hIC6kkAs; Mon, 20 Apr 2026 23:04: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=1776715461; bh=dU9wUhXlCE3BAJRpC9u2OYkNwoLoZDEIRrhVKwfUBGc=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=F/2EAcEehHuM3UKIc/ynEg+1WVUaWF1xG1NlenS/le+oS2XAk0xdstnjjs/P3kdyx Pv/6rnx+WdZX5MmhFfOXb5NzszOiwNVGNYWxSgrviPZIrEjWrOkTOBJ2XPRZV81lwh koNmv8NVYZzzyQdNcjRxmjC4sdHg97FxIIgJlzsY= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v6 20/22] vhost-user: make trace events more readable Date: Mon, 20 Apr 2026 23:03:35 +0300 Message-ID: <20260420200339.708640-21-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715563539154100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz --- hw/virtio/trace-events | 4 +-- hw/virtio/vhost-user.c | 63 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 658cc365e70..aa1ffa5e949 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -25,8 +25,8 @@ vhost_user_set_mem_table_withfd(int index, const char *na= me, uint64_t memory_siz vhost_user_postcopy_waker(const char *rb, uint64_t rb_offset) "%s + 0x%"PR= Ix64 vhost_user_postcopy_waker_found(uint64_t client_addr) "0x%"PRIx64 vhost_user_postcopy_waker_nomatch(const char *rb, uint64_t rb_offset) "%s = + 0x%"PRIx64 -vhost_user_read(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32"" -vhost_user_write(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32"" +vhost_user_read(uint32_t req, const char *req_name, uint32_t flags) "req:%= d (%s) flags:0x%"PRIx32"" +vhost_user_write(uint32_t req, const char *req_name, uint32_t flags) "req:= %d (%s) flags:0x%"PRIx32"" vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" =20 # vhost-vdpa.c diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 31eaf65430e..4fb136b7b37 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -114,6 +114,63 @@ typedef enum VhostUserBackendRequest { VHOST_USER_BACKEND_MAX } VhostUserBackendRequest; =20 +#define VHOST_USER_CASE(name) \ + case VHOST_USER_##name: \ + return #name; + +static const char *vhost_req_name(VhostUserRequest req) +{ + switch (req) { + VHOST_USER_CASE(NONE) + VHOST_USER_CASE(GET_FEATURES) + VHOST_USER_CASE(SET_FEATURES) + VHOST_USER_CASE(SET_OWNER) + VHOST_USER_CASE(RESET_OWNER) + VHOST_USER_CASE(SET_MEM_TABLE) + VHOST_USER_CASE(SET_LOG_BASE) + VHOST_USER_CASE(SET_LOG_FD) + VHOST_USER_CASE(SET_VRING_NUM) + VHOST_USER_CASE(SET_VRING_ADDR) + VHOST_USER_CASE(SET_VRING_BASE) + VHOST_USER_CASE(GET_VRING_BASE) + VHOST_USER_CASE(SET_VRING_KICK) + VHOST_USER_CASE(SET_VRING_CALL) + VHOST_USER_CASE(SET_VRING_ERR) + VHOST_USER_CASE(GET_PROTOCOL_FEATURES) + VHOST_USER_CASE(SET_PROTOCOL_FEATURES) + VHOST_USER_CASE(GET_QUEUE_NUM) + VHOST_USER_CASE(SET_VRING_ENABLE) + VHOST_USER_CASE(SEND_RARP) + VHOST_USER_CASE(NET_SET_MTU) + VHOST_USER_CASE(SET_BACKEND_REQ_FD) + VHOST_USER_CASE(IOTLB_MSG) + VHOST_USER_CASE(SET_VRING_ENDIAN) + VHOST_USER_CASE(GET_CONFIG) + VHOST_USER_CASE(SET_CONFIG) + VHOST_USER_CASE(CREATE_CRYPTO_SESSION) + VHOST_USER_CASE(CLOSE_CRYPTO_SESSION) + VHOST_USER_CASE(POSTCOPY_ADVISE) + VHOST_USER_CASE(POSTCOPY_LISTEN) + VHOST_USER_CASE(POSTCOPY_END) + VHOST_USER_CASE(GET_INFLIGHT_FD) + VHOST_USER_CASE(SET_INFLIGHT_FD) + VHOST_USER_CASE(GPU_SET_SOCKET) + VHOST_USER_CASE(RESET_DEVICE) + VHOST_USER_CASE(GET_MAX_MEM_SLOTS) + VHOST_USER_CASE(ADD_MEM_REG) + VHOST_USER_CASE(REM_MEM_REG) + VHOST_USER_CASE(SET_STATUS) + VHOST_USER_CASE(GET_STATUS) + VHOST_USER_CASE(GET_SHARED_OBJECT) + VHOST_USER_CASE(SET_DEVICE_STATE_FD) + VHOST_USER_CASE(CHECK_DEVICE_STATE) + default: + return ""; + } +} + +#undef VHOST_USER_CASE + typedef struct VhostUserMemoryRegion { uint64_t guest_phys_addr; uint64_t memory_size; @@ -308,7 +365,8 @@ static int vhost_user_read_header(struct vhost_dev *dev= , VhostUserMsg *msg) return -EPROTO; } =20 - trace_vhost_user_read(msg->hdr.request, msg->hdr.flags); + trace_vhost_user_read(msg->hdr.request, + vhost_req_name(msg->hdr.request), msg->hdr.flags= ); =20 return 0; } @@ -428,7 +486,8 @@ static int vhost_user_write(struct vhost_dev *dev, Vhos= tUserMsg *msg, return ret < 0 ? -saved_errno : -EIO; } =20 - trace_vhost_user_write(msg->hdr.request, msg->hdr.flags); + trace_vhost_user_write(msg->hdr.request, vhost_req_name(msg->hdr.reque= st), + msg->hdr.flags); =20 return 0; } --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715531; cv=none; d=zohomail.com; s=zohoarc; b=Cq0aisTKIiz7lNELsx2YYwPbXJR9pF6/eFqXZ8XMQRmRiVPC2riofv0pVdHCld+lXBdBS8oVMgDMouU8oQyZ13DUeCn7gO0vMsdX6m2XalTJNNRqO4axn3UIBUy2M/DZaH4I1KtkPnsS/Cku+IR2jXkDtbe4RvOn7st77M4tbhU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715531; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QRCDo8FBCZVffKxPT5McAWTtvtWm+UKlIvG2NlKOFHw=; b=gGzsZX4ZPn8aHiZrX5scG4G+j2lPtXhjEtArAONgvdTwnOLsqpFyvr/m46NCTH1eG/JG6ZU0JdvP2L+pt28E3Xx6NXhwZbuRkR9CO1AjSr+hVJLJTzMypqxrXdpwi6XVImgBknjq2nc+mWdxZiH4OTmO78DPQ69WIWn6flevfeQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177671553196460.481761514629056; Mon, 20 Apr 2026 13:05:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEurU-0002qT-0g; Mon, 20 Apr 2026 16:04:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEurR-0002VB-6o; Mon, 20 Apr 2026 16:04:49 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEurN-00024x-4z; Mon, 20 Apr 2026 16:04:48 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 8390580778; Mon, 20 Apr 2026 23:04:23 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-EeymCGJf; Mon, 20 Apr 2026 23:04: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=1776715462; bh=QRCDo8FBCZVffKxPT5McAWTtvtWm+UKlIvG2NlKOFHw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=xPa3DIZkmwpzNrw5OV79Hs3zcOr0Lz/G33essM2UDCG/ertXEmQ0Y/FcQuNuIiE9e T9ywTZnBQrso7C6oRUqecnxPui6CsgSxOLowEmxasISbTfy4LsPoRk6QFzAcrZXZ7P c+IcdlP1Fr8G3MumOr3kPXaOoUBouklxXpQcJJrw= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz , Kevin Wolf , Hanna Reitz , Raphael Norwitz , qemu-block@nongnu.org (open list:Block layer core) Subject: [PATCH v6 21/22] vhost-user-blk: add some useful trace-points Date: Mon, 20 Apr 2026 23:03:36 +0300 Message-ID: <20260420200339.708640-22-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715533025154101 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/block/trace-events | 10 ++++++++++ hw/block/vhost-user-blk.c | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/hw/block/trace-events b/hw/block/trace-events index cc9a9f24603..dbaa5ca6cb2 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -58,6 +58,16 @@ virtio_blk_handle_zone_mgmt(void *vdev, void *req, uint8= _t op, int64_t sector, i virtio_blk_handle_zone_reset_all(void *vdev, void *req, int64_t sector, in= t64_t len) "vdev %p req %p sector 0x%" PRIx64 " cap 0x%" PRIx64 "" virtio_blk_handle_zone_append(void *vdev, void *req, int64_t sector) "vdev= %p req %p, append sector 0x%" PRIx64 "" =20 +# vhost-user-blk.c +vhost_user_blk_start_in(void *vdev) "vdev %p" +vhost_user_blk_start_out(void *vdev) "vdev %p" +vhost_user_blk_stop_in(void *vdev) "vdev %p" +vhost_user_blk_stop_out(void *vdev) "vdev %p" +vhost_user_blk_connect_in(void *vdev) "vdev %p" +vhost_user_blk_connect_out(void *vdev) "vdev %p" +vhost_user_blk_device_realize_in(void *vdev) "vdev %p" +vhost_user_blk_device_realize_out(void *vdev) "vdev %p" + # hd-geometry.c hd_geometry_lchs_guess(void *blk, int cyls, int heads, int secs) "blk %p L= CHS %d %d %d" hd_geometry_guess(void *blk, uint32_t cyls, uint32_t heads, uint32_t secs,= int trans) "blk %p CHS %u %u %u trans %d" diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 2831f3c0530..530f44ab520 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -31,6 +31,7 @@ #include "hw/virtio/virtio-access.h" #include "system/system.h" #include "system/runstate.h" +#include "trace.h" =20 static const int user_feature_bits[] =3D { VIRTIO_BLK_F_SIZE_MAX, @@ -137,6 +138,8 @@ static int vhost_user_blk_start(VirtIODevice *vdev, Err= or **errp) VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); int i, ret; =20 + trace_vhost_user_blk_start_in(vdev); + if (!k->set_guest_notifiers) { error_setg(errp, "binding does not support guest notifiers"); return -ENOSYS; @@ -192,6 +195,8 @@ static int vhost_user_blk_start(VirtIODevice *vdev, Err= or **errp) } s->started_vu =3D true; =20 + trace_vhost_user_blk_start_out(vdev); + return ret; =20 err_guest_notifiers: @@ -212,6 +217,8 @@ static int vhost_user_blk_stop(VirtIODevice *vdev) int ret; bool force_stop =3D false; =20 + trace_vhost_user_blk_stop_in(vdev); + if (!s->started_vu) { return 0; } @@ -233,6 +240,9 @@ static int vhost_user_blk_stop(VirtIODevice *vdev) } =20 vhost_dev_disable_notifiers(&s->dev, vdev); + + trace_vhost_user_blk_stop_out(vdev); + return ret; } =20 @@ -340,6 +350,8 @@ static int vhost_user_blk_connect(DeviceState *dev, Err= or **errp) VHostUserBlk *s =3D VHOST_USER_BLK(vdev); int ret =3D 0; =20 + trace_vhost_user_blk_connect_in(vdev); + if (s->connected) { return 0; } @@ -366,6 +378,8 @@ static int vhost_user_blk_connect(DeviceState *dev, Err= or **errp) ret =3D vhost_user_blk_start(vdev, errp); } =20 + trace_vhost_user_blk_connect_out(vdev); + return ret; } =20 @@ -456,6 +470,8 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) int retries; int i, ret; =20 + trace_vhost_user_blk_device_realize_in(vdev); + if (!s->chardev.chr) { error_setg(errp, "chardev is mandatory"); return; @@ -515,6 +531,9 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, vhost_user_blk_event, NULL, (void *)dev, NULL, true); + + trace_vhost_user_blk_device_realize_out(vdev); + return; =20 virtio_err: --=20 2.52.0 From nobody Tue Apr 21 14:39:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1776715570; cv=none; d=zohomail.com; s=zohoarc; b=gc6DBOjiLnTVNTZFUrUVmqDU83Hww7mq16kB+/aBkIhcGwSEK2RrH5KbF95UaQ23JiNTj70Hf+arUlBElbhWOVkhZN53T0vwwr2FfriFvuH/3bMslBLqFFkEs/Z4kAheciD+GWgExxn4D8t2x2DPq6Pg8xtRJIhn3JWRVPKtLEM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776715570; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cHNUGQYHpBInLb95ZLOID6Q1Am1IdFzgTlHbpH702Ng=; b=mStgWA++zy0tZWL98gpyAW3xlgAzz0PMl3RKHSi9eqDVRByHr3uIvIqa1p5iq4bo8UitLp/TE0ewPY4hLzm1nR95HXThrGrP92E59lydhrhdbemnetZ8fRpTAOqW5DRa1jAfZXfF/XY4tsv+baBODwDUAClY4h2Jx5P1/C3J8mI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776715570308985.0177276189156; Mon, 20 Apr 2026 13:06:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEurR-0002UN-6k; Mon, 20 Apr 2026 16:04:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEurI-0002Dt-Ec for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:42 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEurE-00025A-Dk for qemu-devel@nongnu.org; Mon, 20 Apr 2026 16:04:39 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 261FD80663; Mon, 20 Apr 2026 23:04:25 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:54b::1:34]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id f3YMX10K1Sw0-FCTIqPKv; Mon, 20 Apr 2026 23:04: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=1776715464; bh=cHNUGQYHpBInLb95ZLOID6Q1Am1IdFzgTlHbpH702Ng=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=OsBuvADris3zqqRHIH3z73AvSRZgrGE4rY+d5p0L0zkbOTEbObwJ5WJItzQ7x/9Gd DtAPLZ52AUOeuF677k9CTnaf83tLawf0NOxVgTSTCKVbCb+f63qkDSCdZ2cJcW3cK9 kE8Cu5pfhviLU3MOga/tHV7pgHoDGOPxdb1+BhIY= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com Cc: sgarzare@redhat.com, raphael@enfabrica.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, Raphael Norwitz Subject: [PATCH v6 22/22] vhost: add some useful trace-points Date: Mon, 20 Apr 2026 23:03:37 +0300 Message-ID: <20260420200339.708640-23-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260420200339.708640-1-vsementsov@yandex-team.ru> References: <20260420200339.708640-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1776715573604154100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniil Tatianin Reviewed-by: Raphael Norwitz --- hw/virtio/trace-events | 12 ++++++++++-- hw/virtio/vhost.c | 20 ++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index aa1ffa5e949..2a57edc21e3 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -9,8 +9,16 @@ vhost_section(const char *name) "%s" vhost_reject_section(const char *name, int d) "%s:%d" vhost_iotlb_miss(void *dev, int step) "%p step %d" vhost_dev_cleanup(void *dev) "%p" -vhost_dev_start(void *dev, const char *name, bool vrings) "%p:%s vrings:%d" -vhost_dev_stop(void *dev, const char *name, bool vrings) "%p:%s vrings:%d" +vhost_dev_start_in(void *dev, const char *name, bool vrings) "%p:%s vrings= :%d" +vhost_dev_start_out(void *dev, const char *name) "%p:%s" +vhost_dev_stop_in(void *dev, const char *name, bool vrings) "%p:%s vrings:= %d" +vhost_dev_stop_out(void *dev, const char *name) "%p:%s" +vhost_virtqueue_start_in(void *dev, const char *name, int idx) "%p:%s %d" +vhost_virtqueue_start_out(void *dev, const char *name, int idx) "%p:%s %d" +vhost_virtqueue_stop_in(void *dev, const char *name, int idx) "%p:%s %d" +vhost_virtqueue_stop_out(void *dev, const char *name, int idx) "%p:%s %d" +vhost_dev_init_in(void *dev) "%p" +vhost_dev_init_out(void *dev) "%p" =20 =20 # vhost-user.c diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 93c6a5f5e9a..c610007e812 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1337,6 +1337,8 @@ int vhost_virtqueue_start(struct vhost_dev *dev, }; struct VirtQueue *vvq =3D virtio_get_queue(vdev, idx); =20 + trace_vhost_virtqueue_start_in(dev, vdev->name, idx); + r =3D vhost_vrings_map(dev, vdev, vq, idx); if (r <=3D 0) { return r; @@ -1397,6 +1399,8 @@ int vhost_virtqueue_start(struct vhost_dev *dev, } } =20 + trace_vhost_virtqueue_start_out(dev, vdev->name, idx); + return 0; =20 fail: @@ -1415,6 +1419,8 @@ static int do_vhost_virtqueue_stop(struct vhost_dev *= dev, }; int r =3D 0; =20 + trace_vhost_virtqueue_stop_in(dev, vdev->name, idx); + if (virtio_queue_get_desc_addr(vdev, idx) =3D=3D 0) { /* Don't stop the virtqueue which might have not been started */ return 0; @@ -1448,6 +1454,8 @@ static int do_vhost_virtqueue_stop(struct vhost_dev *= dev, } =20 vhost_vrings_unmap(dev, vq, true); + + trace_vhost_virtqueue_stop_out(dev, vdev->name, idx); return r; } =20 @@ -1581,6 +1589,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, unsigned int used, reserved, limit; int i, r, n_initialized_vqs =3D 0; =20 + trace_vhost_dev_init_in(hdev); + hdev->vdev =3D NULL; hdev->migration_blocker =3D NULL; =20 @@ -1694,6 +1704,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, goto fail; } =20 + trace_vhost_dev_init_out(hdev); + return 0; =20 fail: @@ -2098,7 +2110,7 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODev= ice *vdev, bool vrings) /* should only be called after backend is connected */ assert(hdev->vhost_ops); =20 - trace_vhost_dev_start(hdev, vdev->name, vrings); + trace_vhost_dev_start_in(hdev, vdev->name, vrings); =20 vdev->vhost_started =3D true; hdev->started =3D true; @@ -2183,6 +2195,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODev= ice *vdev, bool vrings) } } vhost_start_config_intr(hdev); + + trace_vhost_dev_start_out(hdev, vdev->name); return 0; fail_iotlb: if (vhost_dev_has_iommu(hdev) && @@ -2232,7 +2246,7 @@ static int do_vhost_dev_stop(struct vhost_dev *hdev, = VirtIODevice *vdev, event_notifier_cleanup( &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier); =20 - trace_vhost_dev_stop(hdev, vdev->name, vrings); + trace_vhost_dev_stop_in(hdev, vdev->name, vrings); =20 if (hdev->vhost_ops->vhost_dev_start) { hdev->vhost_ops->vhost_dev_start(hdev, false); @@ -2262,6 +2276,8 @@ static int do_vhost_dev_stop(struct vhost_dev *hdev, = VirtIODevice *vdev, hdev->started =3D false; vdev->vhost_started =3D false; hdev->vdev =3D NULL; + + trace_vhost_dev_stop_out(hdev, vdev->name); return rc; } =20 --=20 2.52.0