From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755103884; cv=none; d=zohomail.com; s=zohoarc; b=lH/btfmMa1y+6qW8tB6ypzVjC9LzMQciy+KB8YIiNbUNmG5+xwokwMjQGlsqNPdMYIc1CEVFxC2gT3dgiRG9xDp5x/tse3nX0dikBJNfCgog6pM6RdAismNJgZCO5BEI84Lfs/JEylf8yO41DWoCIfgJ28xciPwy8m5hhJjzqbM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103884; 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=1D8TczXfj+PsAi0lOr8ci9eOjVbXTipR5Kb9tGv3kuw=; b=Z5N/boAhKZ1oroVsCV42R33en9FMsiiE6ICItaaCJE3w4m5a3/U8jf32PvfyJ9Zs6hHUBwlADYzzSuZ6y/+cx6Kms0B2gzP+CDXX0PNM9HgaHJ400WTh1IeN9cc2UBGpWaZRz3RwNICGUFDBXdPI3+ABhKMvs7/B4wuhjZhtSpQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755103884528469.2063930740554; Wed, 13 Aug 2025 09:51:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfY-0002go-NB; Wed, 13 Aug 2025 12:49:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfB-0002cZ-Lv; Wed, 13 Aug 2025 12:49: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 1umEf2-0007me-K5; Wed, 13 Aug 2025 12:49:18 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id ED134813ED; Wed, 13 Aug 2025 19:49:01 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-VO6HtPTH; Wed, 13 Aug 2025 19:49:01 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103741; bh=1D8TczXfj+PsAi0lOr8ci9eOjVbXTipR5Kb9tGv3kuw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=PkchNhvZ3/t7jHg3xiAgTxmKvCYpivjVCl1hMj0RHTY19dLPvWnObVcB4p69edntd Y+pyRuw9YSRR/TADrhs+ig8LUdiVnDwIkxHjXL1eqUjG+WaF4JDn6P11cdQGAhxwID RH6sj09ysadadBXBRvV871kXZRYj/QvCFwEAQbos= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 01/33] vhost: introduce vhost_ops->vhost_set_vring_enable_supported method Date: Wed, 13 Aug 2025 19:48:22 +0300 Message-ID: <20250813164856.950363-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8: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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755103887883124100 Content-Type: text/plain; charset="utf-8" Remove vhost-user specific hack from generic code. Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/virtio/vhost-user.c | 8 ++++++++ hw/virtio/vhost.c | 15 ++++++--------- include/hw/virtio/vhost-backend.h | 2 ++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 1e1d6b0d6e..1b2879a90c 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1230,6 +1230,12 @@ static int vhost_user_set_vring_base(struct vhost_de= v *dev, return vhost_set_vring(dev, VHOST_USER_SET_VRING_BASE, ring, false); } =20 +static bool vhost_user_set_vring_enable_supported(struct vhost_dev *dev) +{ + return virtio_has_feature(dev->backend_features, + VHOST_USER_F_PROTOCOL_FEATURES); +} + static int vhost_user_set_vring_enable(struct vhost_dev *dev, int enable) { int i; @@ -3032,6 +3038,8 @@ const VhostOps user_ops =3D { .vhost_reset_device =3D vhost_user_reset_device, .vhost_get_vq_index =3D vhost_user_get_vq_index, .vhost_set_vring_enable =3D vhost_user_set_vring_enable, + .vhost_set_vring_enable_supported =3D + vhost_user_set_vring_enable_supported, .vhost_requires_shm_log =3D vhost_user_requires_shm_log, .vhost_migration_done =3D vhost_user_migration_done, .vhost_net_set_mtu =3D vhost_user_net_set_mtu, diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 6557c58d12..c33dad4acd 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1986,15 +1986,12 @@ static int vhost_dev_set_vring_enable(struct vhost_= dev *hdev, int enable) return 0; } =20 - /* - * 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)) { + if (hdev->vhost_ops->vhost_set_vring_enable_supported && + !hdev->vhost_ops->vhost_set_vring_enable_supported(hdev)) { + /* + * This means, that rings are always enabled, and disable/enable + * API is not supported. + */ return 0; } =20 diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index d6df209a2f..f65fa26298 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -105,6 +105,7 @@ typedef int (*vhost_reset_device_op)(struct vhost_dev *= dev); typedef int (*vhost_get_vq_index_op)(struct vhost_dev *dev, int idx); typedef int (*vhost_set_vring_enable_op)(struct vhost_dev *dev, int enable); +typedef bool (*vhost_set_vring_enable_supported_op)(struct vhost_dev *dev); typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev); typedef int (*vhost_migration_done_op)(struct vhost_dev *dev, char *mac_addr); @@ -193,6 +194,7 @@ typedef struct VhostOps { vhost_reset_device_op vhost_reset_device; vhost_get_vq_index_op vhost_get_vq_index; vhost_set_vring_enable_op vhost_set_vring_enable; + vhost_set_vring_enable_supported_op vhost_set_vring_enable_supported; vhost_requires_shm_log_op vhost_requires_shm_log; vhost_migration_done_op vhost_migration_done; vhost_vsock_set_guest_cid_op vhost_vsock_set_guest_cid; --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104375; cv=none; d=zohomail.com; s=zohoarc; b=davD+oq4ElGypP74YgRQmR4omUUFL9FfRSEWCBiNKrUl8TKZIJ95quJzF7adNAyu0KR+9emN8JOScQE2v2tML5ji1REnbvl+ZfPF8flSBpjPn+0BGaZqk7/vPPNBC5POQ8GBLP5UlaVke6vMzSQer2wKrL1cUQcUsmaOGnc3pE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104375; 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=acxYECp3A0SGP4hq0iUq8Uo4uzgqm35WfZKeXrTijzk=; b=ApzvseCwlWm5inx+LjQZCV/HYE6bEv09FQ+8JACryjROtNQr4lGVkm1Q9/J7KyaD2LFPnsatPXYNq2pByn4aBUTAbWf29r8p7pyw3gO+DOfEpxx6nL1O0sPfQjZIi90g7siFA4yAQi2xYkctJLNob6VImdFy5AOiVPmB51ramQk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104375006428.126870560169; Wed, 13 Aug 2025 09:59:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfx-0002zM-Gn; Wed, 13 Aug 2025 12:50:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfC-0002ck-AU; Wed, 13 Aug 2025 12:49: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 1umEf3-0007mi-0U; Wed, 13 Aug 2025 12:49:22 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 6337F806ED; Wed, 13 Aug 2025 19:49:03 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-GqcTJp6L; Wed, 13 Aug 2025 19:49:02 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103742; bh=acxYECp3A0SGP4hq0iUq8Uo4uzgqm35WfZKeXrTijzk=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=sjMRU4dvGWAd7DosG9x+ELz8m1mRo9JdmOSzwWQ0sG4o2FuXK1OHGir2lKwv9ccSe P+/jGpN/SbSTbnCcS9D9+NQ1G73VYbV78cCJ+MILCoxbNe903xOzU0Itpq8+oCepCJ Z7wjL8ZDljfZhP2LOmQSYLZp3vrg8ofsTJChC2EM= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru, Jason Wang , Fam Zheng Subject: [PATCH 02/33] vhost: drop backend_features field Date: Wed, 13 Aug 2025 19:48:23 +0300 Message-ID: <20250813164856.950363-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104377249116600 Content-Type: text/plain; charset="utf-8" This field is mostly unused and sometimes confusing (we even have a TODO-like comment to drop it). Let's finally do. The field is used to held VHOST_USER_F_PROTOCOL_FEATURES for vhost-user and/or VHOST_NET_F_VIRTIO_NET_HDR for vhost-net (which may be vhoust-user-net). But we can simply recalculte these two flags inplace from hdev->features, and from net-client for VHOST_NET_F_VIRTIO_NET_HDR. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Markus Armbruster Acked-by: Raphael Norwitz --- hw/block/vhost-user-blk.c | 1 - hw/net/vhost_net.c | 16 ++++++++-------- hw/scsi/vhost-scsi.c | 1 - hw/scsi/vhost-user-scsi.c | 1 - hw/virtio/vdpa-dev.c | 1 - hw/virtio/vhost-user.c | 19 +++++++++---------- hw/virtio/virtio-hmp-cmds.c | 2 -- hw/virtio/virtio-qmp.c | 2 -- include/hw/virtio/vhost.h | 7 ------- qapi/virtio.json | 3 --- 10 files changed, 17 insertions(+), 36 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index c0cc5f6942..de7a810c93 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -348,7 +348,6 @@ static int vhost_user_blk_connect(DeviceState *dev, Err= or **errp) s->dev.nvqs =3D s->num_queues; s->dev.vqs =3D s->vhost_vqs; s->dev.vq_index =3D 0; - s->dev.backend_features =3D 0; =20 vhost_dev_set_config_notifier(&s->dev, &blk_ops); =20 diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 540492b37d..fcee279f0b 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -53,7 +53,10 @@ int vhost_net_set_config(struct vhost_net *net, const ui= nt8_t *data, =20 void vhost_net_ack_features(struct vhost_net *net, uint64_t features) { - net->dev.acked_features =3D net->dev.backend_features; + net->dev.acked_features =3D + (qemu_has_vnet_hdr(net->nc) ? 0 : (1ULL << VHOST_NET_F_VIRTIO_NET_= HDR)) + | (net->dev.features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)); + vhost_ack_features(&net->dev, net->feature_bits, features); } =20 @@ -256,12 +259,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 { - net->dev.backend_features =3D 0; net->dev.protocol_features =3D 0; net->backend =3D -1; =20 @@ -281,10 +281,10 @@ struct vhost_net *vhost_net_init(VhostNetOptions *opt= ions) sizeof(struct virtio_net_hdr_mrg_rxbuf))) { net->dev.features &=3D ~(1ULL << VIRTIO_NET_F_MRG_RXBUF); } - if (~net->dev.features & net->dev.backend_features) { - fprintf(stderr, "vhost lacks feature mask 0x%" PRIx64 - " for backend\n", - (uint64_t)(~net->dev.features & net->dev.backend_featur= es)); + 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; } } diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index cdf405b0f8..d694a25fe2 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -276,7 +276,6 @@ static void vhost_scsi_realize(DeviceState *dev, Error = **errp) vqs =3D g_new0(struct vhost_virtqueue, vsc->dev.nvqs); vsc->dev.vqs =3D vqs; vsc->dev.vq_index =3D 0; - vsc->dev.backend_features =3D 0; =20 ret =3D vhost_dev_init(&vsc->dev, (void *)(uintptr_t)vhostfd, VHOST_BACKEND_TYPE_KERNEL, 0, errp); diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index 25f2d894e7..0c80a271d8 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -159,7 +159,6 @@ static int vhost_user_scsi_connect(DeviceState *dev, Er= ror **errp) vsc->dev.nvqs =3D VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; vsc->dev.vqs =3D s->vhost_vqs; vsc->dev.vq_index =3D 0; - vsc->dev.backend_features =3D 0; =20 ret =3D vhost_dev_init(&vsc->dev, &s->vhost_user, VHOST_BACKEND_TYPE_U= SER, 0, errp); diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c index d1da40afc8..3c0eed3e8e 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 1b2879a90c..cf6f53801d 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1232,7 +1232,7 @@ static int vhost_user_set_vring_base(struct vhost_dev= *dev, =20 static bool vhost_user_set_vring_enable_supported(struct vhost_dev *dev) { - return virtio_has_feature(dev->backend_features, + return virtio_has_feature(dev->features, VHOST_USER_F_PROTOCOL_FEATURES); } =20 @@ -1449,14 +1449,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)) { @@ -2187,8 +2188,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 7d8677bcf0..024904915d 100644 --- a/hw/virtio/virtio-hmp-cmds.c +++ b/hw/virtio/virtio-hmp-cmds.c @@ -175,8 +175,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 3b6377cf0d..e514a4797e 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -788,8 +788,6 @@ VirtioStatus *qmp_x_query_virtio_status(const char *pat= h, Error **errp) qmp_decode_features(vdev->device_id, hdev->features); status->vhost_dev->acked_features =3D qmp_decode_features(vdev->device_id, hdev->acked_features); - status->vhost_dev->backend_features =3D - qmp_decode_features(vdev->device_id, hdev->backend_features); status->vhost_dev->protocol_features =3D qmp_decode_protocols(hdev->protocol_features); status->vhost_dev->max_queues =3D hdev->max_queues; diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 66be6afc88..9f9dd2d46d 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. */ uint64_t features; uint64_t acked_features; - uint64_t backend_features; =20 /** * @protocol_features: is the vhost-user only feature set by diff --git a/qapi/virtio.json b/qapi/virtio.json index 9d652fe4a8..0aae77340d 100644 --- a/qapi/virtio.json +++ b/qapi/virtio.json @@ -85,8 +85,6 @@ # # @acked-features: vhost_dev acked_features # -# @backend-features: vhost_dev backend_features -# # @protocol-features: vhost_dev protocol_features # # @max-queues: vhost_dev max_queues @@ -106,7 +104,6 @@ 'vq-index': 'int', 'features': 'VirtioDeviceFeatures', 'acked-features': 'VirtioDeviceFeatures', - 'backend-features': 'VirtioDeviceFeatures', 'protocol-features': 'VhostDeviceProtocols', 'max-queues': 'uint64', 'backend-cap': 'uint64', --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755103872; cv=none; d=zohomail.com; s=zohoarc; b=QDGABht1o7DZxSw7x4SuCbXUOQt6XosjR1Bmzv++T6nHtqG2YvuWHGoN0RtMPkIdkPqtTx89Di0taqT4SzaXAYvO53n8rgfkMOvF2AtT3kfgEEdDWizSQvqI2cmIcx7cnss+SzpWfjiP6a+9WBMEQHAR4KG3JGKAebh/YDwmJIk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103872; 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=uxJY0zvUL1mJYTBT5mOxxRPsBPkedva7aliCeP7nSZo=; b=f3Ul6pI8Ra1OWy+D91xJD4//eJnOg6VdgaDYo5eEFieLauMfTOt4qG47GkMdd5brL9l5v7EfYZR5AjSjJl7ZEcZUsgJ1PiuKrYd61af9AbJ2Ib2D8RTEw1JGbq/mflelYoX1HRW1bpxVbmvo6Tlkj++dKdinz/AV85tIInuWxOw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755103872419530.0943361865211; Wed, 13 Aug 2025 09:51:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfY-0002hf-S8; Wed, 13 Aug 2025 12:49:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfC-0002cl-Ou; Wed, 13 Aug 2025 12:49: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 1umEf3-0007mt-8i; Wed, 13 Aug 2025 12:49:22 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id BC2BB8077A; Wed, 13 Aug 2025 19:49:04 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-tCxjbg1q; Wed, 13 Aug 2025 19:49:04 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103744; bh=uxJY0zvUL1mJYTBT5mOxxRPsBPkedva7aliCeP7nSZo=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=LONP4XWS49yeJu4Xk+myRH1qJxjr/QsmVLCe4oRXigyjihD/qx4SPv3Q5wCFMjb/A NZDZuN5uLSw6aZJCQyIu+K6tH5OLzyVLNeMsOVxSBQDgEtui/BRUItRPxySMu+beII fPFc3pyRtBedgwSDRAey3xcPKMT+dZrbzN1UiBQM= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 03/33] vhost-user: introduce vhost_user_has_prot() helper Date: Wed, 13 Aug 2025 19:48:24 +0300 Message-ID: <20250813164856.950363-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755103876950124100 Content-Type: text/plain; charset="utf-8" Make all protocol feature checks in the same way. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz --- hw/virtio/vhost-user.c | 102 ++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 58 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index cf6f53801d..6fa5b8a8bd 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -272,6 +272,11 @@ struct scrub_regions { int fd_idx; }; =20 +static bool vhost_user_has_prot(struct vhost_dev *dev, uint64_t feature) +{ + return virtio_has_feature(dev->protocol_features, feature); +} + static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg) { struct vhost_user *u =3D dev->opaque; @@ -435,8 +440,7 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_LOG_SHMF= D); int ret; VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_LOG_BASE, @@ -1006,11 +1010,10 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK); bool config_mem_slots =3D - virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS); + vhost_user_has_prot(dev, VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS= ); int ret; =20 if (do_postcopy) { @@ -1058,8 +1061,8 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_CROSS_ENDIAN); VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_VRING_ENDIAN, .hdr.flags =3D VHOST_USER_VERSION, @@ -1129,8 +1132,8 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK); if (reply_supported) { msg->hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; } @@ -1459,8 +1462,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_prot(dev, VHOST_USER_PROTOCOL_F_STATUS)) { if (!ret) { return vhost_user_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); } @@ -1514,8 +1516,7 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_RESET_DEVICE)) { return -ENOSYS; } =20 @@ -1572,8 +1573,7 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) || vdev =3D=3D NULL || queue_idx >=3D virtio_get_num_queues(vdev)) { return -EINVAL; } @@ -1885,13 +1885,12 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK); 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_prot(dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ)) { return 0; } =20 @@ -2136,8 +2135,7 @@ 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_prot(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"); @@ -2228,7 +2226,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_prot(dev, VHOST_USER_PROTOCOL_F_MQ)) { err =3D vhost_user_get_u64(dev, VHOST_USER_GET_QUEUE_NUM, &dev->max_queues); if (err < 0) { @@ -2246,18 +2244,16 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_BACKEND_R= EQ) && + vhost_user_has_prot(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_prot(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); @@ -2279,8 +2275,7 @@ 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_prot(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."); @@ -2349,8 +2344,7 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_LOG_SHMFD); } =20 static int vhost_user_migration_done(struct vhost_dev *dev, char* mac_addr) @@ -2365,8 +2359,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_prot(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); @@ -2380,11 +2373,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_prot(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK); int ret; =20 - if (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_NET_MTU)= )) { + if (!vhost_user_has_prot(dev, VHOST_USER_PROTOCOL_F_NET_MTU)) { return 0; } =20 @@ -2444,8 +2437,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_prot(dev, VHOST_USER_PROTOCOL_F_CONFIG)) { error_setg(errp, "VHOST_USER_PROTOCOL_F_CONFIG not supported"); return -EINVAL; } @@ -2488,8 +2480,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_prot(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK); =20 VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_CONFIG, @@ -2497,8 +2489,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_prot(dev, VHOST_USER_PROTOCOL_F_CONFIG)) { return -ENOTSUP; } =20 @@ -2533,8 +2524,8 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_CRYPTO_SESSION); CryptoDevBackendSessionInfo *backend_info =3D session_info; VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_CREATE_CRYPTO_SESSION, @@ -2635,8 +2626,8 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_CRYPTO_SESSION); VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_CLOSE_CRYPTO_SESSION, .hdr.flags =3D VHOST_USER_VERSION, @@ -2681,8 +2672,7 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { return 0; } =20 @@ -2749,8 +2739,7 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { return 0; } =20 @@ -2849,8 +2838,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_prot(dev, VHOST_USER_PROTOCOL_F_STATUS)) { return 0; } =20 @@ -2875,16 +2863,14 @@ 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_prot(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_prot(dev, VHOST_USER_PROTOCOL_F_DEVICE_STATE); } =20 static int vhost_user_set_device_state_fd(struct vhost_dev *dev, --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104294; cv=none; d=zohomail.com; s=zohoarc; b=ZeHHg5FR7irpmNH8Cd+csFVAYfpnpeJBVc72HIJDTRXP0AZLwCwvX5a1gdiX6ytUZZLug8vk4pK9s6ZS8bXiYRiTXGEmUVWDjxutD/7BKSSfuembFDZh5D1KoJXKWIhwKGGtY9VcYlxyq8Bj63rX7GnL1hZnHSlV/DVWLbKA20U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104294; 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=6y3hwaG28K0NcdouNlUVjGJba0PpSLLa4p9W0yA2JNo=; b=GlS5akZWetY8bE99+mTDGnsilfQJoLxObZxmCtVPQqTo616IkowpfS4R+UBszuWoXVtNaJPQdKx3h2LEy1W8W9P+sVLLhkVOPe+6XjFAf8DZiJ3xjbsqRzdVRe/AObm2MOyATa5kwY36E/7x1We2O87CRvt+s+xNDo4WYrmv2JQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17551042947721001.2155949763654; Wed, 13 Aug 2025 09:58:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfu-0002wT-0D; Wed, 13 Aug 2025 12:50:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfH-0002de-4b; Wed, 13 Aug 2025 12:49:28 -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 1umEf5-0007n3-US; Wed, 13 Aug 2025 12:49:25 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id E224A807AC; Wed, 13 Aug 2025 19:49:05 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-lGZn6UT8; Wed, 13 Aug 2025 19:49:05 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103745; bh=6y3hwaG28K0NcdouNlUVjGJba0PpSLLa4p9W0yA2JNo=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=jGhiuUTObn3D7JwS1wUWRk4bgrhvkvnYMCjvDIBXptboGeJWxYdcHMfbtgLCseRUL XRLceVtdxYQsJqXmtTEcRfboo4Gl1ilNJaCAuBIxpaiCElGj4kPiU36vAwUcJ/4dun 00jk44Dg9BYvLFRtY662C+8EtbAnR6saEO7mq8c4= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru, "Gonglei (Arei)" , Zhenwei Pi , Jason Wang Subject: [PATCH 04/33] vhost: move protocol_features to vhost_user Date: Wed, 13 Aug 2025 19:48:25 +0300 Message-ID: <20250813164856.950363-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104296395116600 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/net/vhost_net.c | 2 -- hw/virtio/vhost-user.c | 23 ++++++++++++++++++++--- hw/virtio/virtio-qmp.c | 6 ++++-- include/hw/virtio/vhost-backend.h | 3 +++ include/hw/virtio/vhost.h | 8 -------- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index 943680a23a..3bcdc494d8 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -60,7 +60,6 @@ cryptodev_vhost_init( =20 crypto->cc =3D options->cc; =20 - crypto->dev.protocol_features =3D 0; crypto->backend =3D -1; =20 /* vhost-user needs vq_index to initiate a specific queue pair */ diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index fcee279f0b..ce30b6e197 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -260,9 +260,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *optio= ns) goto fail; } net->backend =3D r; - net->dev.protocol_features =3D 0; } else { - net->dev.protocol_features =3D 0; net->backend =3D -1; =20 /* vhost-user needs vq_index to initiate a specific queue pair */ diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 6fa5b8a8bd..abdf47ee7b 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -11,6 +11,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "hw/virtio/virtio-dmabuf.h" +#include "hw/virtio/virtio-qmp.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-crypto.h" #include "hw/virtio/vhost-user.h" @@ -264,6 +265,14 @@ struct vhost_user { /* Our current regions */ int num_shadow_regions; struct vhost_memory_region shadow_regions[VHOST_USER_MAX_RAM_SLOTS]; + + /** + * @protocol_features: the vhost-user protocol feature set by + * VHOST_USER_SET_PROTOCOL_FEATURES. Protocol features are only + * negotiated if VHOST_USER_F_PROTOCOL_FEATURES has been offered + * by the backend (see @features). + */ + uint64_t protocol_features; }; =20 struct scrub_regions { @@ -274,7 +283,8 @@ struct scrub_regions { =20 static bool vhost_user_has_prot(struct vhost_dev *dev, uint64_t feature) { - return virtio_has_feature(dev->protocol_features, feature); + struct vhost_user *u =3D dev->opaque; + return virtio_has_feature(u->protocol_features, feature); } =20 static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg) @@ -2218,8 +2228,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; @@ -3001,6 +3011,12 @@ static int vhost_user_check_device_state(struct vhos= t_dev *dev, Error **errp) return 0; } =20 +static void vhost_user_qmp_status(struct vhost_dev *dev, VhostStatus *stat= us) +{ + struct vhost_user *u =3D dev->opaque; + status->protocol_features =3D qmp_decode_protocols(u->protocol_feature= s); +} + const VhostOps user_ops =3D { .backend_type =3D VHOST_BACKEND_TYPE_USER, .vhost_backend_init =3D vhost_user_backend_init, @@ -3041,4 +3057,5 @@ const VhostOps user_ops =3D { .vhost_supports_device_state =3D vhost_user_supports_device_state, .vhost_set_device_state_fd =3D vhost_user_set_device_state_fd, .vhost_check_device_state =3D vhost_user_check_device_state, + .vhost_qmp_status =3D vhost_user_qmp_status, }; diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c index e514a4797e..d55b12f9f3 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -788,12 +788,14 @@ VirtioStatus *qmp_x_query_virtio_status(const char *p= ath, Error **errp) qmp_decode_features(vdev->device_id, hdev->features); status->vhost_dev->acked_features =3D qmp_decode_features(vdev->device_id, hdev->acked_features); - 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->vhost_qmp_status) { + hdev->vhost_ops->vhost_qmp_status(hdev, status->vhost_dev); + } } =20 return status; diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index f65fa26298..0785fc764d 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -12,6 +12,7 @@ #define VHOST_BACKEND_H =20 #include "system/memory.h" +#include "qapi/qapi-commands-virtio.h" =20 typedef enum VhostBackendType { VHOST_BACKEND_TYPE_NONE =3D 0, @@ -160,6 +161,7 @@ typedef int (*vhost_set_device_state_fd_op)(struct vhos= t_dev *dev, int *reply_fd, Error **errp); typedef int (*vhost_check_device_state_op)(struct vhost_dev *dev, Error **= errp); +typedef void (*vhost_qmp_status_op)(struct vhost_dev *dev, VhostStatus *st= atus); =20 typedef struct VhostOps { VhostBackendType backend_type; @@ -216,6 +218,7 @@ typedef struct VhostOps { vhost_supports_device_state_op vhost_supports_device_state; vhost_set_device_state_fd_op vhost_set_device_state_fd; vhost_check_device_state_op vhost_check_device_state; + vhost_qmp_status_op vhost_qmp_status; } VhostOps; =20 int vhost_backend_update_device_iotlb(struct vhost_dev *dev, diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 9f9dd2d46d..15bc287a9d 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -104,14 +104,6 @@ struct vhost_dev { uint64_t features; uint64_t acked_features; =20 - /** - * @protocol_features: is the vhost-user only feature set by - * VHOST_USER_SET_PROTOCOL_FEATURES. Protocol features are only - * negotiated if VHOST_USER_F_PROTOCOL_FEATURES has been offered - * by the backend (see @features). - */ - uint64_t protocol_features; - uint64_t max_queues; uint64_t backend_cap; /* @started: is the vhost device started? */ --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104042; cv=none; d=zohomail.com; s=zohoarc; b=cDu6ZWW3F12iTK2wED3zM78ULNicMoawLkpyNb+T9W+788u/hjOuplIEuOXDh6LzkeMcWcFtn+niUma22khoHKp7Mk4cwgWW3X3arY1Lmi5833sT21i+obY7a+pIEOGj8S2pEdfMXXuBSLw9D2Fj/jnIBZccKtRDVq5URx4NZL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104042; 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=esMHEU9NgBhhq2zpUD2yDJwtnaTD8CPgUNj+WsGQrw4=; b=TAmwN1JeDAchCn3F8q1rZYxmvJt9elwtYzcbX9IRJJlYaq3wStIHnFJBlkTjroRwdhGeZBmE0+lQyL+KZADzW+KiPrvutUVo6IMsbRcKNyc4bkXaQPRpW1A79SB9b+DPM/JKhYxvPeibaC9fB5zYXfk0K23LyK8axdK9EPNg3rA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175510404220919.986772776609428; Wed, 13 Aug 2025 09:54:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfl-0002nJ-D6; Wed, 13 Aug 2025 12:49:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfC-0002ca-MJ; Wed, 13 Aug 2025 12:49: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 1umEf2-0007nF-KL; Wed, 13 Aug 2025 12:49:17 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 45D26807D9; Wed, 13 Aug 2025 19:49:07 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-WVVljOWB; Wed, 13 Aug 2025 19:49:06 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103746; bh=esMHEU9NgBhhq2zpUD2yDJwtnaTD8CPgUNj+WsGQrw4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Nt95syJmF7GrMnsV2/EUrAZBfo/bePdLsM9Q95XQS7QCb14Dhj7lf/LeaEhU1MRL4 zJUb3g8dlvOkl7Zq0LQ+BsGBQoZR40fPt5TOxoNcQJJXUkbD8gSDYuT3FFHtcrlMwT InKskADRARTtmR09vF/BUPV21MbSp4BJpKSU3K+A= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 05/33] vhost-user-gpu: drop code duplication Date: Wed, 13 Aug 2025 19:48:26 +0300 Message-ID: <20250813164856.950363-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104045194124101 Content-Type: text/plain; charset="utf-8" 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 --- hw/display/vhost-user-gpu.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 9fc6bbcd2c..79ea64b12c 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -644,10 +644,6 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error= **errp) VIRTIO_GPU_F_RESOURCE_UUID)) { g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_RESOURCE_UUID_E= NABLED; } - if (virtio_has_feature(g->vhost->dev.features, - VIRTIO_GPU_F_RESOURCE_UUID)) { - g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_RESOURCE_UUID_E= NABLED; - } =20 if (!virtio_gpu_base_device_realize(qdev, NULL, NULL, errp)) { return; --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104404; cv=none; d=zohomail.com; s=zohoarc; b=NKmR+ZP5aNdX65BYuNGUlGuMMdNUW8/bkpY8xggEEObsTM8j8FHC+jeHfO+8+qFr2/wcTq+EHFtxt2iAwQURZb5OVx5ixJ0t0HdR49QtSdFknyG3xaoSh3slTWerTJsfU8ocE1zGK5hgZsw30XOmoDRFhjLq4bVZZ/mGnv9rpLQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104404; 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=KVnjEs242mxf0oDV8dheNJ6G8NvptyrhWPMrmMFU1v8=; b=dlJQZcY3PI2WNvYwHZ5MQeVC+AwSMLm3IM0M6fz+Ysf4oCH3nFrW17d6WelL2Jbdw76gheD15zcketjNPSd+c6gWrk3tusQODMA298ey+tCFoPkarXKV9owUloCQPXvanh4/6rc3Ph9zzQfSqCC6im+e+MJrHoIQZn1nVS1p49I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104404007255.23273665761872; Wed, 13 Aug 2025 10:00:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfi-0002mF-BD; Wed, 13 Aug 2025 12:49:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfI-0002dk-U9; Wed, 13 Aug 2025 12:49:32 -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 1umEf4-0007nW-2C; Wed, 13 Aug 2025 12:49:26 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 84A6880AA7; Wed, 13 Aug 2025 19:49:08 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-JpK3xgI4; Wed, 13 Aug 2025 19:49:08 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103748; bh=KVnjEs242mxf0oDV8dheNJ6G8NvptyrhWPMrmMFU1v8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=cZ+T3zxjDwXc91G9hPMg/JJPtRLn80PYhqjxXRuy/IE5O/v4ey8PBexDNxjn2O313 A/Z5+PInFeMW+YSLOEuZOd1nhIulyIHZlrRy08Z3yD2afd0j9wVphyRVSDesc09Aix Xfg21+f59Hatp6byfAYkmSZtKQ07MlI3Qgbb95Nk= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru, Jason Wang , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH 06/33] vhost: make vhost_dev.features private Date: Wed, 13 Aug 2025 19:48:27 +0300 Message-ID: <20250813164856.950363-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104405655116600 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 --- hw/display/vhost-user-gpu.c | 7 +++---- hw/net/vhost_net.c | 17 +++++++++-------- hw/virtio/vdpa-dev.c | 2 +- hw/virtio/vhost-user-base.c | 8 ++++++-- hw/virtio/vhost-user.c | 7 +++---- hw/virtio/vhost.c | 21 ++++++++++++++++++--- hw/virtio/virtio-qmp.c | 2 +- include/hw/virtio/vhost.h | 21 +++++++++++++++++++-- net/vhost-vdpa.c | 7 +++---- 9 files changed, 63 insertions(+), 29 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 79ea64b12c..146620e0a3 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -631,17 +631,16 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Erro= r **errp) =20 /* existing backend may send DMABUF, so let's add that requirement */ g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED; - if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_VIRGL)) { + if (vhost_dev_has_feature(&g->vhost->dev, VIRTIO_GPU_F_VIRGL)) { g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED; } - if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_EDID)) { + if (vhost_dev_has_feature(&g->vhost->dev, VIRTIO_GPU_F_EDID)) { g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_EDID_ENABLED; } else { error_report("EDID requested but the backend doesn't support it."); g->parent_obj.conf.flags &=3D ~(1 << VIRTIO_GPU_FLAG_EDID_ENABLED); } - if (virtio_has_feature(g->vhost->dev.features, - VIRTIO_GPU_F_RESOURCE_UUID)) { + if (vhost_dev_has_feature(&g->vhost->dev, VIRTIO_GPU_F_RESOURCE_UUID))= { g->parent_obj.conf.flags |=3D 1 << VIRTIO_GPU_FLAG_RESOURCE_UUID_E= NABLED; } =20 diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index ce30b6e197..5269533864 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -55,7 +55,8 @@ void vhost_net_ack_features(struct vhost_net *net, uint64= _t features) { net->dev.acked_features =3D (qemu_has_vnet_hdr(net->nc) ? 0 : (1ULL << VHOST_NET_F_VIRTIO_NET_= HDR)) - | (net->dev.features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)); + | (vhost_dev_features(&net->dev) & + (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)); =20 vhost_ack_features(&net->dev, net->feature_bits, features); } @@ -277,23 +278,23 @@ 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); } 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)); + !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. */ if (options->get_acked_features) { + uint64_t backend_features =3D vhost_dev_features(&net->dev); features =3D options->get_acked_features(net->nc); - if (~net->dev.features & features) { + if (~backend_features & features) { fprintf(stderr, "vhost lacks feature mask 0x%" PRIx64 - " for backend\n", - (uint64_t)(~net->dev.features & features)); + " for backend\n", ~backend_features & features); goto fail; } } diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c index 3c0eed3e8e..4dfb03aaa7 100644 --- a/hw/virtio/vdpa-dev.c +++ b/hw/virtio/vdpa-dev.c @@ -224,7 +224,7 @@ static uint64_t vhost_vdpa_device_get_features(VirtIODe= vice *vdev, Error **errp) { VhostVdpaDevice *s =3D VHOST_VDPA_DEVICE(vdev); - uint64_t backend_features =3D s->dev.features; + uint64_t backend_features =3D vhost_dev_features(&s->dev); =20 if (!virtio_has_feature(features, VIRTIO_F_IOMMU_PLATFORM)) { virtio_clear_feature(&backend_features, VIRTIO_F_IOMMU_PLATFORM); diff --git a/hw/virtio/vhost-user-base.c b/hw/virtio/vhost-user-base.c index ff67a020b4..cf311c3bfc 100644 --- a/hw/virtio/vhost-user-base.c +++ b/hw/virtio/vhost-user-base.c @@ -118,9 +118,13 @@ static uint64_t vub_get_features(VirtIODevice *vdev, uint64_t requested_features, Error **errp) { VHostUserBase *vub =3D VHOST_USER_BASE(vdev); + uint64_t backend_features =3D vhost_dev_features(&vub->vhost_dev); + /* This should be set when the vhost connection initialises */ - g_assert(vub->vhost_dev.features); - return vub->vhost_dev.features & ~(1ULL << VHOST_USER_F_PROTOCOL_FEATU= RES); + g_assert(backend_features); + virtio_clear_feature(&backend_features, VHOST_USER_F_PROTOCOL_FEATURES= ); + + return backend_features; } =20 /* diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index abdf47ee7b..46f09f5988 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1245,15 +1245,14 @@ static int vhost_user_set_vring_base(struct vhost_d= ev *dev, =20 static bool vhost_user_set_vring_enable_supported(struct vhost_dev *dev) { - return virtio_has_feature(dev->features, - VHOST_USER_F_PROTOCOL_FEATURES); + return vhost_dev_has_feature(dev, VHOST_USER_F_PROTOCOL_FEATURES); } =20 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)= ) { + if (!vhost_dev_has_feature(dev, VHOST_USER_F_PROTOCOL_FEATURES)) { return -EINVAL; } =20 @@ -1465,7 +1464,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 c33dad4acd..2631bbabcf 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -50,6 +50,21 @@ static QLIST_HEAD(, vhost_dev) vhost_log_devs[VHOST_BACK= END_TYPE_MAX]; static QLIST_HEAD(, vhost_dev) vhost_devices =3D QLIST_HEAD_INITIALIZER(vhost_devices); =20 +bool vhost_dev_has_feature(struct vhost_dev *dev, uint64_t feature) +{ + return virtio_has_feature(dev->_features, feature); +} + +uint64_t vhost_dev_features(struct vhost_dev *dev) +{ + return dev->_features; +} + +void vhost_dev_clear_feature(struct vhost_dev *dev, uint64_t feature) +{ + virtio_clear_feature(&dev->_features, feature); +} + unsigned int vhost_get_max_memslots(void) { unsigned int max =3D UINT_MAX; @@ -1571,7 +1586,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, } } =20 - hdev->features =3D features; + hdev->_features =3D features; =20 hdev->memory_listener =3D (MemoryListener) { .name =3D "vhost", @@ -1594,7 +1609,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, }; =20 if (hdev->migration_blocker =3D=3D NULL) { - if (!(hdev->features & (0x1ULL << VHOST_F_LOG_ALL))) { + if (!vhost_dev_has_feature(hdev, VHOST_F_LOG_ALL)) { error_setg(&hdev->migration_blocker, "Migration disabled: vhost lacks VHOST_F_LOG_ALL fe= ature."); } else if (vhost_dev_log_is_shared(hdev) && !qemu_memfd_alloc_chec= k()) { @@ -1865,7 +1880,7 @@ uint64_t vhost_get_features(struct vhost_dev *hdev, c= onst int *feature_bits, const int *bit =3D feature_bits; while (*bit !=3D VHOST_INVALID_FEATURE_BIT) { uint64_t bit_mask =3D (1ULL << *bit); - if (!(hdev->features & bit_mask)) { + if (!vhost_dev_has_feature(hdev, *bit)) { features &=3D ~bit_mask; } bit++; diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c index d55b12f9f3..4bd23c015e 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -785,7 +785,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); + qmp_decode_features(vdev->device_id, vhost_dev_features(hdev)); status->vhost_dev->acked_features =3D qmp_decode_features(vdev->device_id, hdev->acked_features); status->vhost_dev->max_queues =3D hdev->max_queues; diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 15bc287a9d..8a4c8c3502 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -98,10 +98,11 @@ struct vhost_dev { * offered by a backend which may be a subset of the total * features eventually offered to the guest. * - * @features: available features provided by the backend + * @_features: available features provided by the backend, private, + * direct access only in vhost.c * @acked_features: final negotiated features with front-end driver */ - uint64_t features; + uint64_t _features; uint64_t acked_features; =20 uint64_t max_queues; @@ -352,6 +353,22 @@ 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 +/** + * vhost_dev_has_feature() - check if vhost device has a specific feature + * @dev: common vhost_dev structure + * @feature: feature bit to check + * + * Return: true if the feature is supported, false otherwise + */ +bool vhost_dev_has_feature(struct vhost_dev *dev, uint64_t feature); + +/** + * vhost_dev_features() - simple getter for dev->features + */ +uint64_t vhost_dev_features(struct vhost_dev *dev); + +void vhost_dev_clear_feature(struct vhost_dev *dev, uint64_t feature); + #ifdef CONFIG_VHOST int vhost_reset_device(struct vhost_dev *hdev); #else diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 74d26a9497..0af0d3bdd3 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -256,15 +256,14 @@ static bool vhost_vdpa_get_vnet_hash_supported_types(= NetClientState *nc, { assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); - uint64_t features =3D s->vhost_vdpa.dev->features; int fd =3D s->vhost_vdpa.shared->device_fd; struct { struct vhost_vdpa_config hdr; uint32_t supported_hash_types; } config; =20 - if (!virtio_has_feature(features, VIRTIO_NET_F_HASH_REPORT) && - !virtio_has_feature(features, VIRTIO_NET_F_RSS)) { + if (!vhost_dev_has_feature(s->vhost_vdpa.dev, VIRTIO_NET_F_HASH_REPORT= ) && + !vhost_dev_has_feature(s->vhost_vdpa.dev, VIRTIO_NET_F_RSS)) { return false; } =20 @@ -585,7 +584,7 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) * If we early return in these cases SVQ will not be enabled. The migr= ation * will be blocked as long as vhost-vdpa backends will not offer _F_LO= G. */ - if (!vhost_vdpa_net_valid_svq_features(v->dev->features, NULL)) { + if (!vhost_vdpa_net_valid_svq_features(vhost_dev_features(v->dev), NUL= L)) { return 0; } =20 --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755103913; cv=none; d=zohomail.com; s=zohoarc; b=VUsFaBNCkwTzEyRvxjqlKGy583Dn7fqG0DprUrFl+Qk0lL/JtFsIIL8ZncSLtJXwZyY6k4LVjllRKh0TW8UrPROc2MFzP29V/mC1J6KBsBGt3FOHn+S7XcYP5wYs+E4CiEk3KKXAqRsNwdxINAA8w4WpoWjvGE8aaWGmWWqPuZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103913; 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=nqWXIsmLLn9rg1IFHTsU/Prs4niyPIFMdRUQOysIsTY=; b=EqQENtJQ8lkSAlGSyNCr71qmrTykxD629JIWCag5ML78crqw5HpuK/78RVMG1EIqLXkwJQWfUhXbsKfvQ4ltrA2pDZRGXjtsmaijVCw9mMpgpd3rC463HxZ3jSZzkwSvXP/hieIL2waG7Qz1Q4tjrf1e5UJMuRrZvLuyfPJo0W4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755103913491872.4542286650491; Wed, 13 Aug 2025 09:51:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEft-0002w3-Vn; Wed, 13 Aug 2025 12:50:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfL-0002eA-Nt; Wed, 13 Aug 2025 12:49:33 -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 1umEf8-0007ni-LT; Wed, 13 Aug 2025 12:49:30 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 4BE9580758; Wed, 13 Aug 2025 19:49:09 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-VIYARLUk; Wed, 13 Aug 2025 19:49:08 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103748; bh=nqWXIsmLLn9rg1IFHTsU/Prs4niyPIFMdRUQOysIsTY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=AMi0yGUazKFMSkOwSImea/bfdQrJFaJbK+rui7VjrkjTHJnDeHH3qvItjXki/nlxj WGh7+XM6c1oikWWk7HeLTVX+rqQAJPHVdJBzZosyAgYrDYQ9PJzMdZCsGVVWKXjY2M Voz8M92T+dq0ohR87LS2K/HwCGnKWfa0z91RZ1so= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 07/33] virtio: move common part of _set_guest_notifier to generic code Date: Wed, 13 Aug 2025 19:48:28 +0300 Message-ID: <20250813164856.950363-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8: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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755103917804124100 Content-Type: text/plain; charset="utf-8" virtio-pci and virtio-mmiio 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 --- hw/virtio/virtio-mmio.c | 41 +++++------------------------ hw/virtio/virtio-pci.c | 34 +++--------------------- hw/virtio/virtio.c | 48 +++++++++++++++++++++++++++++++--- include/hw/virtio/virtio-pci.h | 3 --- include/hw/virtio/virtio.h | 7 +++-- 5 files changed, 58 insertions(+), 75 deletions(-) diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c index 532c67107b..18afa1c0d0 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -658,18 +658,11 @@ static int virtio_mmio_set_guest_notifier(DeviceState= *d, int n, bool assign, VirtIOMMIOProxy *proxy =3D VIRTIO_MMIO(d); VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); - VirtQueue *vq =3D virtio_get_queue(vdev, n); - EventNotifier *notifier =3D virtio_queue_get_guest_notifier(vq); + int r; =20 - if (assign) { - int r =3D event_notifier_init(notifier, 0); - if (r < 0) { - return r; - } - virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd); - } else { - virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd); - event_notifier_cleanup(notifier); + r =3D virtio_queue_set_guest_notifier(vdev, n, assign, with_irqfd); + if (r < 0) { + return r; } =20 if (vdc->guest_notifier_mask && vdev->use_guest_notifier_mask) { @@ -678,30 +671,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) { @@ -723,7 +693,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 767216d795..3eca3fe2c8 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1163,43 +1163,17 @@ static void virtio_pci_vector_poll(PCIDevice *dev, } } =20 -void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev, VirtQueu= e *vq, - int n, bool assign, - bool with_irqfd) -{ - if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { - virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irq= fd); - } else { - virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd); - } -} - static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assig= n, bool with_irqfd) { VirtIOPCIProxy *proxy =3D to_virtio_pci_proxy(d); VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); - VirtQueue *vq =3D NULL; - EventNotifier *notifier =3D NULL; + int r; =20 - if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { - notifier =3D virtio_config_get_guest_notifier(vdev); - } else { - vq =3D virtio_get_queue(vdev, n); - notifier =3D virtio_queue_get_guest_notifier(vq); - } - - if (assign) { - int r =3D event_notifier_init(notifier, 0); - if (r < 0) { - return r; - } - virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, true, with_i= rqfd); - } else { - virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, false, - with_irqfd); - event_notifier_cleanup(notifier); + r =3D virtio_queue_set_guest_notifier(vdev, n, assign, with_irqfd); + if (r < 0) { + return r; } =20 if (!msix_enabled(&proxy->pci_dev) && diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 9a81ad912e..7880c3bcd9 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3750,8 +3750,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, @@ -3766,7 +3768,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; @@ -3783,6 +3785,46 @@ void virtio_config_set_guest_notifier_fd_handler(Vir= tIODevice *vdev, } } =20 +static void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev, + VirtQueue *vq, + int n, bool assign, + bool with_irqfd) +{ + if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irq= fd); + } else { + virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd); + } +} + +int virtio_queue_set_guest_notifier(VirtIODevice *vdev, int n, bool assign, + bool with_irqfd) +{ + VirtQueue *vq =3D NULL; + EventNotifier *notifier =3D NULL; + + if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + notifier =3D virtio_config_get_guest_notifier(vdev); + } else { + vq =3D virtio_get_queue(vdev, n); + notifier =3D virtio_queue_get_guest_notifier(vq); + } + + if (assign) { + int r =3D event_notifier_init(notifier, 0); + if (r < 0) { + return r; + } + virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, true, with_i= rqfd); + } else { + virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, false, + with_irqfd); + event_notifier_cleanup(notifier); + } + + return 0; +} + EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq) { return &vq->guest_notifier; diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h index eab5394898..02c2dfb3c6 100644 --- a/include/hw/virtio/virtio-pci.h +++ b/include/hw/virtio/virtio-pci.h @@ -263,9 +263,6 @@ void virtio_pci_types_register(const VirtioPCIDeviceTyp= eInfo *t); * @fixed_queues. */ unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues); -void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev, VirtQueu= e *vq, - int n, bool assign, - bool with_irqfd); =20 int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, uint8_t bar, uint64_t of= fset, uint64_t length, uint8_t id); diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index c594764f23..8b9db08ddf 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -416,8 +416,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); @@ -431,8 +429,9 @@ void virtio_queue_aio_detach_host_notifier(VirtQueue *v= q, 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); + +int virtio_queue_set_guest_notifier(VirtIODevice *vdev, int n, bool assign, + bool with_irqfd); =20 static inline void virtio_add_feature(uint64_t *features, unsigned int fbi= t) { --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104394; cv=none; d=zohomail.com; s=zohoarc; b=IVpoQxYQ39YtJHucr5NDYxCGLJYLFcigCCmBrGcpskFZJaphk3K2brcUHCkvxgUyn0U0ADdvuEO/zHH4wIXBc13pycYEMIVfwCOZURaM1Vawx5AtIUlJ+JdZDXt2TBAf7s5BP07tEwfavZhdE1+5O24E3JiAsGs0cW6GbC1dimY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104394; 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=tyMQQBv7HuIlj77+PJGdzsTa2G/0zTifnDsW8oG5mSs=; b=cADvDqFKvrvXhkmgw+bv7apa3FgitTwUOJALYLFc6CkKcrnhAxu1MRWKTNuRVf2W1dFGAesj86xGosQnBK5crZ1JYJOPIF5hAMxMqJcjOVjnj83/4OK68pniDS7/ppqaUsleComskBWpP18B+mDq2Bosh1tqZej9jmgO41mNP0o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104394069167.66137517801008; Wed, 13 Aug 2025 09:59:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfi-0002lp-40; Wed, 13 Aug 2025 12:49:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfL-0002eB-OF; Wed, 13 Aug 2025 12:49:33 -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 1umEf3-0007ns-Ty; Wed, 13 Aug 2025 12:49:30 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 4B6F380CA1; Wed, 13 Aug 2025 19:49:10 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-Gs3p36ve; Wed, 13 Aug 2025 19:49:09 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103749; bh=tyMQQBv7HuIlj77+PJGdzsTa2G/0zTifnDsW8oG5mSs=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=b0izT8ht/kTvbNp4llLrUKrD2d9f0BMuXHb0evKBqdwlFjkNPWPWgCCuahkZJ4Q1q T7ClyTgPB3Kxj0NewQJuS+cWlANA7iEO9Z2nnZvmct5UmUyk+5+fRYLWgabkDisQNU IY8TtJd7JRE7MkHZqgBem19ePdG11+gq1NxuKJGo= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 08/33] virtio: drop *_set_guest_notifier_fd_handler() helpers Date: Wed, 13 Aug 2025 19:48:29 +0300 Message-ID: <20250813164856.950363-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104395801124100 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 --- hw/virtio/virtio.c | 76 +++++++++++----------------------------------- 1 file changed, 17 insertions(+), 59 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 7880c3bcd9..10891f0e0c 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3751,74 +3751,32 @@ static void virtio_config_guest_notifier_read(Event= Notifier *n) } } =20 -static void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, - bool assign, - bool with_irqfd) -{ - if (assign && !with_irqfd) { - event_notifier_set_handler(&vq->guest_notifier, - virtio_queue_guest_notifier_read); - } else { - event_notifier_set_handler(&vq->guest_notifier, NULL); - } - if (!assign) { - /* Test and clear notifier before closing it, - * in case poll callback didn't have time to run. */ - virtio_queue_guest_notifier_read(&vq->guest_notifier); - } -} - -static void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev, - bool assign, bool with_ir= qfd) -{ - EventNotifier *n; - n =3D &vdev->config_notifier; - if (assign && !with_irqfd) { - event_notifier_set_handler(n, virtio_config_guest_notifier_read); - } else { - event_notifier_set_handler(n, NULL); - } - if (!assign) { - /* Test and clear notifier before closing it,*/ - /* in case poll callback didn't have time to run. */ - virtio_config_guest_notifier_read(n); - } -} - -static void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev, - VirtQueue *vq, - int n, bool assign, - bool with_irqfd) -{ - if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { - virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irq= fd); - } else { - virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd); - } -} - int virtio_queue_set_guest_notifier(VirtIODevice *vdev, int n, bool assign, bool with_irqfd) { - VirtQueue *vq =3D NULL; - EventNotifier *notifier =3D NULL; - - if (n =3D=3D VIRTIO_CONFIG_IRQ_IDX) { - notifier =3D virtio_config_get_guest_notifier(vdev); - } else { - vq =3D virtio_get_queue(vdev, n); - notifier =3D virtio_queue_get_guest_notifier(vq); - } + bool is_config =3D n =3D=3D VIRTIO_CONFIG_IRQ_IDX; + VirtQueue *vq =3D is_config ? NULL : virtio_get_queue(vdev, n); + EventNotifier *notifier =3D is_config ? + virtio_config_get_guest_notifier(vdev) : + virtio_queue_get_guest_notifier(vq); + EventNotifierHandler *read_fn =3D is_config ? + virtio_config_guest_notifier_read : + virtio_queue_guest_notifier_read; =20 if (assign) { int r =3D event_notifier_init(notifier, 0); if (r < 0) { return r; } - virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, true, with_i= rqfd); - } else { - virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, false, - with_irqfd); + } + + event_notifier_set_handler(notifier, + (assign && !with_irqfd) ? read_fn : NULL); + + if (!assign) { + /* Test and clear notifier before closing it,*/ + /* in case poll callback didn't have time to run. */ + read_fn(notifier); event_notifier_cleanup(notifier); } =20 --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755103930; cv=none; d=zohomail.com; s=zohoarc; b=BQqI99XzUVb7ZmdVZy3ic3wkvYFcCQE+XP+EGsWUuSM3nXulElkPkbvF5auaOVA0CaQNQxMc4KYBAkFMJWyacf99UTlJ5wwVJ8jvMxP2uPFA/c6F/cc2zZ/G938dbX0Tl5OPfiouB64YrGWjPJbOYKI3mg5YqXkJPDHCWEGLYwA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103930; 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=F7rCpmxVpR6c7FR7+mLk5bx9QDN1wAHijBrBI/wUa5A=; b=l27HCXwyENSVJD/ina88Ljt+ewqArPqJvxkWf4O3u3lmOL2dcSPLuvk/nObVyd6C30a0oIDOoODLs5Bt8UMkGRbqBv66hAhqNWqnvDl8jt9VMqSs32Rwp2vp6jqtoIapeB47mGquVyGsWOeveFCdV9tvOC30oeLhxIIMIx8hMzI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755103929422512.5914884521255; Wed, 13 Aug 2025 09:52:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfq-0002rh-FD; Wed, 13 Aug 2025 12:50:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfH-0002dg-V3; Wed, 13 Aug 2025 12:49:29 -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 1umEf4-0007o1-2p; Wed, 13 Aug 2025 12:49:27 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id E9C4980E6C; Wed, 13 Aug 2025 19:49:10 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-6cbQRs5F; Wed, 13 Aug 2025 19:49:10 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103750; bh=F7rCpmxVpR6c7FR7+mLk5bx9QDN1wAHijBrBI/wUa5A=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=gDHRbkSQWx8MptULTFtrxsJ3x3Hl6vHar4m1lyw+4diRkUKu0osG5n2O4jl3b12cR kL6qtbc521gztJd3bbxpHoIHz7bgjjBuC85djS9Pw/BEb/jsFEkTtL1ueNfKTReSTK VALvGYKj2vjzkuiTzKGSqpTWlkS4dL6G46SVV9V8= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 09/33] vhost-user: keep QIOChannelSocket for backend channel Date: Wed, 13 Aug 2025 19:48:30 +0300 Message-ID: <20250813164856.950363-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8: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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755103932286116600 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 --- 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 46f09f5988..fe9d91348d 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -244,7 +244,7 @@ struct vhost_user { struct vhost_dev *dev; /* Shared between vhost devs of the same virtio device */ VhostUserState *user; - QIOChannel *backend_ioc; + QIOChannelSocket *backend_sioc; GSource *backend_src; NotifierWithReturn postcopy_notifier; struct PostCopyFD postcopy_fd; @@ -1789,8 +1789,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, @@ -1897,7 +1897,6 @@ static int vhost_setup_backend_channel(struct vhost_d= ev *dev) bool reply_supported =3D vhost_user_has_prot(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK); Error *local_err =3D NULL; - QIOChannel *ioc; =20 if (!vhost_user_has_prot(dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ)) { return 0; @@ -1909,15 +1908,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; @@ -2321,7 +2320,7 @@ static int vhost_user_backend_cleanup(struct vhost_de= v *dev) close(u->postcopy_fd.fd); u->postcopy_fd.handler =3D NULL; } - if (u->backend_ioc) { + if (u->backend_sioc) { close_backend_channel(u); } g_free(u->region_rb); --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104205; cv=none; d=zohomail.com; s=zohoarc; b=Xeh+zrAtrPO2CW3LRQ9wlqJVcVAPOqH9EHN7jk1e8u9rwTKfH8IkYd4mAp6CfLECYced7FHA20kAeRyxZNCUfc84X6MOY/plrv/KfaM4JanAwakrk61So2NTfNkDtulMf+g+oLKIToH2AdTrQD58B8HVjS36/xfSbbW2jrahFag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104205; 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=9hyvwdmH0K0OIC+cXL3i8jMAd9qIIupWX5IN5BKG8hA=; b=UvHCNrTBlWrLKqccVHUg5wbOO1tFGwySwp0dnyxt2w67COVxuv22tj+quw2tG6zEIXNEL3Vr4BdUWxPA1kVI89vPV9yC7LysrHLHZWFh6uVSQYVS94H/KOx4IfWVzYurvQOHANDaKqU9Qfc7/hEh7+aC+Q0GYum+R/7E2V1D4F0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104205096898.9239941629775; Wed, 13 Aug 2025 09:56:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfv-0002zq-RQ; Wed, 13 Aug 2025 12:50:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfN-0002ei-NP; Wed, 13 Aug 2025 12:49:36 -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 1umEfE-0007qY-0x; Wed, 13 Aug 2025 12:49:32 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id AC3EC81008; Wed, 13 Aug 2025 19:49:11 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-fTDHmVb0; Wed, 13 Aug 2025 19:49:11 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103751; bh=9hyvwdmH0K0OIC+cXL3i8jMAd9qIIupWX5IN5BKG8hA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=gzHEDGgl+bsrWOIijwGswfUBmXl7mXmWsrEkV93ujQfhCM3MTnZaPL8wq68QhyThz Lsd4wkf2DJsrcmEzSTmHU+iG/iXbhn0xsAvUSbTGGM7CAsvoAs5Cwz71fgD2Xulxvq zlSG/81meaffnQaqOtt61fQHYecxJHMTaTe5qEuE= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 10/33] vhost: vhost_virtqueue_start(): fix failure path Date: Wed, 13 Aug 2025 19:48:31 +0300 Message-ID: <20250813164856.950363-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8: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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104207110124100 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 | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 2631bbabcf..1e14987cd5 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -467,10 +467,19 @@ 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) { + hwaddr mapped_len =3D len; if (!vhost_dev_has_iommu(dev)) { - return cpu_physical_memory_map(addr, plen, is_write); + void *res =3D cpu_physical_memory_map(addr, &mapped_len, is_write); + if (!res) { + return NULL; + } + if (len !=3D mapped_len) { + cpu_physical_memory_unmap(res, mapped_len, 0, 0); + return NULL; + } + return res; } else { return (void *)(uintptr_t)addr; } @@ -1259,7 +1268,7 @@ int vhost_virtqueue_start(struct vhost_dev *dev, BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); VirtioBusState *vbus =3D VIRTIO_BUS(qbus); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); - hwaddr s, l, a; + hwaddr l, a; int r; int vhost_vq_index =3D dev->vhost_ops->vhost_get_vq_index(dev, idx); struct vhost_vring_file file =3D { @@ -1299,24 +1308,24 @@ int vhost_virtqueue_start(struct vhost_dev *dev, } } =20 - vq->desc_size =3D s =3D l =3D virtio_queue_get_desc_size(vdev, idx); + vq->desc_size =3D l =3D virtio_queue_get_desc_size(vdev, idx); vq->desc_phys =3D a; - vq->desc =3D vhost_memory_map(dev, a, &l, false); - if (!vq->desc || l !=3D s) { + vq->desc =3D vhost_memory_map(dev, a, l, false); + if (!vq->desc) { r =3D -ENOMEM; goto fail_alloc_desc; } - vq->avail_size =3D s =3D l =3D virtio_queue_get_avail_size(vdev, idx); + vq->avail_size =3D l =3D virtio_queue_get_avail_size(vdev, idx); vq->avail_phys =3D a =3D virtio_queue_get_avail_addr(vdev, idx); - vq->avail =3D vhost_memory_map(dev, a, &l, false); - if (!vq->avail || l !=3D s) { + vq->avail =3D vhost_memory_map(dev, a, l, false); + if (!vq->avail) { r =3D -ENOMEM; goto fail_alloc_avail; } - vq->used_size =3D s =3D l =3D virtio_queue_get_used_size(vdev, idx); + vq->used_size =3D l =3D virtio_queue_get_used_size(vdev, idx); vq->used_phys =3D a =3D virtio_queue_get_used_addr(vdev, idx); - vq->used =3D vhost_memory_map(dev, a, &l, true); - if (!vq->used || l !=3D s) { + vq->used =3D vhost_memory_map(dev, a, l, true); + if (!vq->used) { r =3D -ENOMEM; goto fail_alloc_used; } --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104213; cv=none; d=zohomail.com; s=zohoarc; b=fvl2zX8pSf7xbxT6+reLMgppLKTxifBvtFoP6Tg6w+OAC54lxyPabdN+KJpt5Sjil9pylm+ufkA3Rx4mQc0RsWYP59A8UDK+RJvfFAq2AVhfNqS0NvGV/QFtY9YlaszATYkvMoIrz7i3JN+Fm8SEBYggu+54rRoL9R/WyWJ+Zjs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104213; 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=IrPv7l0mpKuGiYo2Ah6j55mhJXmGpNK4D4BWxuRy3Tg=; b=HKUd+mk0UHKxh0jsoUa/2gtOBFvLX4uSWTw/TVYzAeZhpeodssz3vHL3yZu10kIqJ12n2EYF8YMaqzzf5MiU8p84gAK/+gyWZE9DGmRUq7vjO7RCFtxI04aWW7l7wLnQF2vxiC8HAZ3GE8i+OMQH0Qo3sfhHkeS3tK2xicJ5jgU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104213939670.6635030488611; Wed, 13 Aug 2025 09:56:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfy-00031l-In; Wed, 13 Aug 2025 12:50:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfO-0002ej-0O; Wed, 13 Aug 2025 12:49:36 -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 1umEfE-0007qX-Hx; Wed, 13 Aug 2025 12:49:33 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 5D33A810D0; Wed, 13 Aug 2025 19:49:12 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-w6KiV0KF; Wed, 13 Aug 2025 19:49:11 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103752; bh=IrPv7l0mpKuGiYo2Ah6j55mhJXmGpNK4D4BWxuRy3Tg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=PgkKvT5tIWyyRrdpLk+BDM7mAtnYORTaWt8hpeE/UameT6h3DyVngrxmGcS7a+ZDl hJVk58oouqwv1bhX/PWESk1C3yYQCk/eYWlWALQooejzgXGI09I7FPbJ6SM4zVzG91 GTRtjmDM3zPYpkZKPV71B1ISuaK0ZkFeZJrQbypY= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 11/33] vhost: make vhost_memory_unmap() null-safe Date: Wed, 13 Aug 2025 19:48:32 +0300 Message-ID: <20250813164856.950363-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104215182124100 Content-Type: text/plain; charset="utf-8" This helps to simplify failure paths of vhost_virtqueue_start() a lot. Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/virtio/vhost.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 1e14987cd5..1fdc1937b6 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -489,6 +489,10 @@ 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)) { cpu_physical_memory_unmap(buffer, len, is_write, access_len); } @@ -1313,33 +1317,33 @@ int vhost_virtqueue_start(struct vhost_dev *dev, vq->desc =3D vhost_memory_map(dev, a, l, false); if (!vq->desc) { r =3D -ENOMEM; - goto fail_alloc_desc; + goto fail; } vq->avail_size =3D l =3D virtio_queue_get_avail_size(vdev, idx); vq->avail_phys =3D a =3D virtio_queue_get_avail_addr(vdev, idx); vq->avail =3D vhost_memory_map(dev, a, l, false); if (!vq->avail) { r =3D -ENOMEM; - goto fail_alloc_avail; + goto fail; } vq->used_size =3D l =3D virtio_queue_get_used_size(vdev, idx); vq->used_phys =3D a =3D virtio_queue_get_used_addr(vdev, idx); vq->used =3D vhost_memory_map(dev, a, l, true); if (!vq->used) { r =3D -ENOMEM; - goto fail_alloc_used; + goto fail; } =20 r =3D vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabl= ed); if (r < 0) { - goto fail_alloc; + goto fail; } =20 file.fd =3D event_notifier_get_fd(virtio_queue_get_host_notifier(vvq)); r =3D dev->vhost_ops->vhost_set_vring_kick(dev, &file); if (r) { VHOST_OPS_DEBUG(r, "vhost_set_vring_kick failed"); - goto fail_kick; + goto fail; } =20 /* Clear and discard previous events if any. */ @@ -1359,24 +1363,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: +fail: vhost_memory_unmap(dev, vq->used, virtio_queue_get_used_size(vdev, idx= ), 0, 0); -fail_alloc_used: vhost_memory_unmap(dev, vq->avail, virtio_queue_get_avail_size(vdev, i= dx), 0, 0); -fail_alloc_avail: vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx= ), 0, 0); -fail_alloc_desc: return r; } =20 --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755103986; cv=none; d=zohomail.com; s=zohoarc; b=K6rWik6Mwq99XGf9gmh1XfwOVY5cbKuxWmDTB2ekl/BD/I1J7e0tCKuUlE7+h1P1EJh/jb0jMiNav4e3EbPOrOx6LbHIj7czhc1RPokG/J4NxqcibRqo626jlrDYtU3j45ZY8vXAzfLkxQxgjV+PfGSStZd5dqxcAX3hWdRwuds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103986; 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=0BbvMhvv176A45n6ck0LNiFq7u1ql13y24c+pUlCJDY=; b=GFt62d99a3vECbUHkQA9F3baYm79Uh0VrB16zgrhokpYoxUs2fJR6gt4qOz1ePWXFavp/ilc2FoeEr0Jc+7c/UIELZlOR1mGoYvOYoAd1wSscjOFQ0BRIColJWvJ7dQDtivLmrCy9WxP+Og2r3eyf29ATmcH7PFHLMyeLMFSjRo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755103986429394.12029670204356; Wed, 13 Aug 2025 09:53:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfm-0002oS-KM; Wed, 13 Aug 2025 12:49:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfS-0002gY-BC; Wed, 13 Aug 2025 12:49:38 -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 1umEfD-0007qZ-Uv; Wed, 13 Aug 2025 12:49:37 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 0F8D5810DD; Wed, 13 Aug 2025 19:49:13 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-8RxqNoLL; Wed, 13 Aug 2025 19:49:12 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103752; bh=0BbvMhvv176A45n6ck0LNiFq7u1ql13y24c+pUlCJDY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=rHJ/Wtt2PoFBIgFpAPhcZwaaMYD3LFhc72Xq/8ACfEbtq1eOSaNQuxuFj90QPDaDG DhOTujADKLrcHIrHeUuoRPSgZxOrhl6I4YgM1L6da7JdIhkI/aIS5yiuUoMbfd5YG5 2q/hlzoLOJA7Z3BA8Ynk9tBkiCP16z+fERap3+Fw= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 12/33] vhost: simplify calls to vhost_memory_unmap() Date: Wed, 13 Aug 2025 19:48:33 +0300 Message-ID: <20250813164856.950363-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8: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, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755103986850116600 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 --- 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 1fdc1937b6..bc1821eadd 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1370,12 +1370,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, idx= ), - 0, 0); - vhost_memory_unmap(dev, vq->avail, virtio_queue_get_avail_size(vdev, i= dx), - 0, 0); - vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx= ), - 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 @@ -1422,12 +1419,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, idx= ), - 1, virtio_queue_get_used_size(vdev, idx)); - vhost_memory_unmap(dev, vq->avail, virtio_queue_get_avail_size(vdev, i= dx), - 0, virtio_queue_get_avail_size(vdev, idx)); - vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx= ), - 0, virtio_queue_get_desc_size(vdev, idx)); + vhost_memory_unmap(dev, vq->used, vq->used_size, 1, vq->used_size); + vhost_memory_unmap(dev, vq->avail, vq->avail_size, 0, vq->avail_size); + vhost_memory_unmap(dev, vq->desc, vq->desc_size, 0, vq->desc_size); return r; } =20 --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755103989; cv=none; d=zohomail.com; s=zohoarc; b=ggz8r/n9LI2U+TyPzNARFldhtlE3jZO4sqi5Ufx/kG3O34t/rsNc4TVidiM1zjgpeGF9+E/ZO2hWOv/mGKJYrvWpq8kDT4jLa9534J8sQ5B3IgSXH0OrOnsG6D3MFUA31jlmhJhnYQakdq+lQndNt/1lwJKAyxWk0VWaFMIbVoQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103989; 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=UjMMyIPdl32Ub1DyuZzPzy0sDSVR6hZxY04lCdi/Nck=; b=C3sz2eb0RJXYonHPqiKqUMLaSMKHZQx46a6r0O8m+lB1qel+pH6FqpSVcLhuxjkiCgZbuofP06axETVEv4wMiO0cu8KmG/tsp18dDH9IWGjXKW0XVriTJkRoXVTSUVtk4P5ojbOWG+0a4nNfeWL+ZfTirJClOqR2cJ4l1mVEGII= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755103989814358.0971311474451; Wed, 13 Aug 2025 09:53:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfq-0002rr-MK; Wed, 13 Aug 2025 12:50:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfW-0002hP-4W; Wed, 13 Aug 2025 12:49: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 1umEfG-0007qh-Aw; Wed, 13 Aug 2025 12:49:41 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id B40F48110E; Wed, 13 Aug 2025 19:49:13 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-LMqzYRjH; Wed, 13 Aug 2025 19:49:13 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103753; bh=UjMMyIPdl32Ub1DyuZzPzy0sDSVR6hZxY04lCdi/Nck=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=HSfy99xG8ZrPi9d5x6HgYg69+PoHGgm4TtzPptYnJuW0aZ2J2tRlSSN6an2XXfgbE NCK22wznGM2wGCBJDneaTTOZ8OYegEc+4w13/R3Zob/L8GhGFYVUMklWC4k6YfGKeJ IKVUhiWfJHRr3wkKG/eOb4OsxPt9jNhW9tf0ZHS0= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 13/33] vhost: move vrings mapping to the top of vhost_virtqueue_start() Date: Wed, 13 Aug 2025 19:48:34 +0300 Message-ID: <20250813164856.950363-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755103992528124100 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 --- hw/virtio/vhost.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index bc1821eadd..97113174b9 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1288,30 +1288,6 @@ int vhost_virtqueue_start(struct vhost_dev *dev, /* Queue might not be ready for start */ return 0; } - - vq->num =3D state.num =3D virtio_queue_get_num(vdev, idx); - r =3D dev->vhost_ops->vhost_set_vring_num(dev, &state); - if (r) { - VHOST_OPS_DEBUG(r, "vhost_set_vring_num failed"); - return r; - } - - state.num =3D virtio_queue_get_last_avail_idx(vdev, idx); - r =3D dev->vhost_ops->vhost_set_vring_base(dev, &state); - if (r) { - VHOST_OPS_DEBUG(r, "vhost_set_vring_base failed"); - return r; - } - - if (vhost_needs_vring_endian(vdev)) { - r =3D vhost_virtqueue_set_vring_endian_legacy(dev, - virtio_is_big_endian(v= dev), - vhost_vq_index); - if (r) { - return r; - } - } - vq->desc_size =3D l =3D virtio_queue_get_desc_size(vdev, idx); vq->desc_phys =3D a; vq->desc =3D vhost_memory_map(dev, a, l, false); @@ -1334,6 +1310,29 @@ int vhost_virtqueue_start(struct vhost_dev *dev, goto fail; } =20 + vq->num =3D state.num =3D virtio_queue_get_num(vdev, idx); + r =3D dev->vhost_ops->vhost_set_vring_num(dev, &state); + if (r) { + VHOST_OPS_DEBUG(r, "vhost_set_vring_num failed"); + goto fail; + } + + state.num =3D virtio_queue_get_last_avail_idx(vdev, idx); + r =3D dev->vhost_ops->vhost_set_vring_base(dev, &state); + if (r) { + VHOST_OPS_DEBUG(r, "vhost_set_vring_base failed"); + goto fail; + } + + if (vhost_needs_vring_endian(vdev)) { + r =3D vhost_virtqueue_set_vring_endian_legacy(dev, + virtio_is_big_endian(v= dev), + vhost_vq_index); + if (r) { + goto fail; + } + } + r =3D vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabl= ed); if (r < 0) { goto fail; --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104201; cv=none; d=zohomail.com; s=zohoarc; b=SCYoB6hzrCUwUt9dh3KOPafTBMZivYe9CWXxHm3cYkRCULzFPC5bRRWeRY4skTEpG75pv0LsenggXr86YPxwDptTzFFeng3iysqxggCrWg+l99S3kaNNMZGr9KEHlo7GvLonxJRT8M9AV8x8XZTWfEC8k4JpAMSDoOX+i70eM6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104201; 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=jT6lvk12VgqFX+93EVObnNHwLhpclc/AavvfVXh5ctI=; b=XqiNxLU+wTOf+xfgvX48ci6H6dZ/PiGIp8lz8SFReqFnLnTpN0sYACODL5WoCqW7q+3sv2UMrEhZ7wbSuZiqCA+TQCEX3yP1FKxUrugX6VSYkS50bWAB7ntFcV+FVTU+PCT7wdTUqrXsokRUGJqNOr+NAWz/pb2ajue/ZOPpaU4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104201815150.84740090351886; Wed, 13 Aug 2025 09:56:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfy-00032C-Oi; Wed, 13 Aug 2025 12:50:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfX-0002hi-QV; Wed, 13 Aug 2025 12:49:44 -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 1umEfH-0007qt-D4; Wed, 13 Aug 2025 12:49:42 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 7B5B281208; Wed, 13 Aug 2025 19:49:14 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-UmXS4UW5; Wed, 13 Aug 2025 19:49:14 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103754; bh=jT6lvk12VgqFX+93EVObnNHwLhpclc/AavvfVXh5ctI=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=ZzGVmkbhfqbmEOIdaS4FPtRFTjZJyHTOOMkaUZJ9gn4TlP9/hwvLTFLu4lZB+wYR3 t27xT0AQy96Qm+Xt/rRVrQVixsDreda/Doa+KB2Td1TUjkWBeJ0xHI/qHBqpgbDy7F WGE3mCZ6ELtj578kl0R/OwQr3tIeeU5XXmRLbL18= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 14/33] vhost: vhost_virtqueue_start(): drop extra local variables Date: Wed, 13 Aug 2025 19:48:35 +0300 Message-ID: <20250813164856.950363-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8: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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104203049124100 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 | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 97113174b9..c76e2dbb4e 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1272,7 +1272,6 @@ int vhost_virtqueue_start(struct vhost_dev *dev, BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); VirtioBusState *vbus =3D VIRTIO_BUS(qbus); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(vbus); - hwaddr l, a; int r; int vhost_vq_index =3D dev->vhost_ops->vhost_get_vq_index(dev, idx); struct vhost_vring_file file =3D { @@ -1283,28 +1282,27 @@ int vhost_virtqueue_start(struct vhost_dev *dev, }; struct VirtQueue *vvq =3D virtio_get_queue(vdev, idx); =20 - a =3D virtio_queue_get_desc_addr(vdev, idx); - if (a =3D=3D 0) { + vq->desc_phys =3D virtio_queue_get_desc_addr(vdev, idx); + if (vq->desc_phys =3D=3D 0) { /* Queue might not be ready for start */ return 0; } - vq->desc_size =3D l =3D virtio_queue_get_desc_size(vdev, idx); - vq->desc_phys =3D a; - vq->desc =3D vhost_memory_map(dev, a, l, false); + vq->desc_size =3D virtio_queue_get_desc_size(vdev, idx); + vq->desc =3D vhost_memory_map(dev, vq->desc_phys, vq->desc_size, false= ); if (!vq->desc) { r =3D -ENOMEM; goto fail; } - vq->avail_size =3D l =3D virtio_queue_get_avail_size(vdev, idx); - vq->avail_phys =3D a =3D virtio_queue_get_avail_addr(vdev, idx); - vq->avail =3D vhost_memory_map(dev, a, l, false); + vq->avail_size =3D virtio_queue_get_avail_size(vdev, idx); + vq->avail_phys =3D virtio_queue_get_avail_addr(vdev, idx); + vq->avail =3D vhost_memory_map(dev, vq->avail_phys, vq->avail_size, fa= lse); if (!vq->avail) { r =3D -ENOMEM; goto fail; } - vq->used_size =3D l =3D virtio_queue_get_used_size(vdev, idx); - vq->used_phys =3D a =3D virtio_queue_get_used_addr(vdev, idx); - vq->used =3D vhost_memory_map(dev, a, l, true); + vq->used_size =3D virtio_queue_get_used_size(vdev, idx); + vq->used_phys =3D virtio_queue_get_used_addr(vdev, idx); + vq->used =3D vhost_memory_map(dev, vq->used_phys, vq->used_size, true); if (!vq->used) { r =3D -ENOMEM; goto fail; --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104005; cv=none; d=zohomail.com; s=zohoarc; b=hNGy9HmmJPylmCwJ9dhXGI2IzGG7a7vvgms3SqEHiam90K4+Pq1v6AFlF5SlzzDiFkveuGz53fJfdVwtoE61TXBBehjk2kY6XvLi7DLNieATHSYZamkY9vigm8WYa2G69dwRzZbXgmK+fQ3f7twkGYu6XCBKPqRuLPqYVZn4Sek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104005; 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=DcrE8wJLgwC8i8U44ZWRBtCzFDtT/tQbClNKyreVrH8=; b=a78OoNBWwTD5UTIdX70BwUCjdbzxFyoK1CPI6FxWgyyjIScld1PQarQfjZ2zLI9xuTBhQyPLxyKK9VmAmK48OB6EPCXqb5PLRvAveOOtpUp34zC7CBraCScm27M9dCYfByjrMddICYUa6lpJTN7OEgJ2MngyDTrFHrUEJ5OcqSs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104005778861.1453028563994; Wed, 13 Aug 2025 09:53:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfk-0002mz-7V; Wed, 13 Aug 2025 12:49:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfQ-0002fi-WF; Wed, 13 Aug 2025 12:49:37 -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 1umEfH-0007qs-Cx; Wed, 13 Aug 2025 12:49:36 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 2A9DD8121B; Wed, 13 Aug 2025 19:49:15 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-DemGqyZj; Wed, 13 Aug 2025 19:49:14 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103754; bh=DcrE8wJLgwC8i8U44ZWRBtCzFDtT/tQbClNKyreVrH8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=qQjFegNUW4mTrVSy/R+1lSX91gRV1tkPg1p3zcZbj/Kl4ye+XwWkcJMvQmcEqjIgm UphRRSANrJWxsTmo1OHWAMa2jBQshZLwsXD3Gl0E0VnTXyZaQzfJUBJ16aWQIKHk+5 uZyzUWyLKALfOmGod3YFy7LFx2w2nPJMAYe+Kp8Q= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 15/33] vhost: final refactoring of vhost vrings map/unmap Date: Wed, 13 Aug 2025 19:48:36 +0300 Message-ID: <20250813164856.950363-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8: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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104008703124100 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 --- hw/virtio/vhost.c | 82 ++++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index c76e2dbb4e..f6ee59425f 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -498,6 +498,53 @@ static void vhost_memory_unmap(struct vhost_dev *dev, = void *buffer, } } =20 +static void vhost_vrings_unmap(struct vhost_dev *dev, + struct vhost_virtqueue *vq, bool touched) +{ + vhost_memory_unmap(dev, vq->used, vq->used_size, touched, + touched ? vq->used_size : 0); + vhost_memory_unmap(dev, vq->avail, vq->avail_size, 0, + touched ? vq->avail_size : 0); + vhost_memory_unmap(dev, vq->desc, vq->desc_size, 0, + touched ? vq->desc_size : 0); +} + +static int vhost_vrings_map(struct vhost_dev *dev, + struct VirtIODevice *vdev, + struct vhost_virtqueue *vq, + unsigned idx) +{ + vq->desc_phys =3D virtio_queue_get_desc_addr(vdev, idx); + if (vq->desc_phys =3D=3D 0) { + /* Queue might not be ready for start */ + return 0; + } + vq->desc_size =3D virtio_queue_get_desc_size(vdev, idx); + vq->desc =3D vhost_memory_map(dev, vq->desc_phys, vq->desc_size, false= ); + if (!vq->desc) { + return -ENOMEM; + } + + vq->avail_size =3D virtio_queue_get_avail_size(vdev, idx); + vq->avail_phys =3D virtio_queue_get_avail_addr(vdev, idx); + vq->avail =3D vhost_memory_map(dev, vq->avail_phys, vq->avail_size, fa= lse); + if (!vq->avail) { + goto fail; + } + + vq->used_size =3D virtio_queue_get_used_size(vdev, idx); + vq->used_phys =3D virtio_queue_get_used_addr(vdev, idx); + vq->used =3D vhost_memory_map(dev, vq->used_phys, vq->used_size, true); + if (!vq->used) { + goto fail; + } + + return 1; +fail: + vhost_vrings_unmap(dev, vq, false); + return -ENOMEM; +} + static int vhost_verify_ring_part_mapping(void *ring_hva, uint64_t ring_gpa, uint64_t ring_size, @@ -1282,30 +1329,9 @@ int vhost_virtqueue_start(struct vhost_dev *dev, }; struct VirtQueue *vvq =3D virtio_get_queue(vdev, idx); =20 - vq->desc_phys =3D virtio_queue_get_desc_addr(vdev, idx); - if (vq->desc_phys =3D=3D 0) { - /* Queue might not be ready for start */ - return 0; - } - vq->desc_size =3D virtio_queue_get_desc_size(vdev, idx); - vq->desc =3D vhost_memory_map(dev, vq->desc_phys, vq->desc_size, false= ); - if (!vq->desc) { - r =3D -ENOMEM; - goto fail; - } - vq->avail_size =3D virtio_queue_get_avail_size(vdev, idx); - vq->avail_phys =3D virtio_queue_get_avail_addr(vdev, idx); - vq->avail =3D vhost_memory_map(dev, vq->avail_phys, vq->avail_size, fa= lse); - if (!vq->avail) { - r =3D -ENOMEM; - goto fail; - } - vq->used_size =3D virtio_queue_get_used_size(vdev, idx); - vq->used_phys =3D virtio_queue_get_used_addr(vdev, idx); - vq->used =3D vhost_memory_map(dev, vq->used_phys, vq->used_size, true); - if (!vq->used) { - r =3D -ENOMEM; - goto fail; + r =3D vhost_vrings_map(dev, vdev, vq, idx); + if (r <=3D 0) { + return r; } =20 vq->num =3D state.num =3D virtio_queue_get_num(vdev, idx); @@ -1367,9 +1393,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 @@ -1416,9 +1440,7 @@ static int do_vhost_virtqueue_stop(struct vhost_dev *= dev, vhost_vq_index); } =20 - vhost_memory_unmap(dev, vq->used, vq->used_size, 1, vq->used_size); - vhost_memory_unmap(dev, vq->avail, vq->avail_size, 0, vq->avail_size); - vhost_memory_unmap(dev, vq->desc, vq->desc_size, 0, vq->desc_size); + vhost_vrings_unmap(dev, vq, true); return r; } =20 --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755103981; cv=none; d=zohomail.com; s=zohoarc; b=kpVBH31bCRZMv8Gznc8hzNtUc/dWOJQ+kPvG7/wa/6L4iCXFE8vrG/yFWMRCJkjjLdiyfen8tXsH6Gg4ZKmu9hC7f3K7OQ4VyEro3u1Oj3rZJ2MiTh69oDo4opNeNXUOM0lNX7NWAGDBp2vLZV6XhxYXQeR6GgzeRhB0JZFGFsw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103981; 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=VPbxO6D/t+j8eJzppYHqMzsC4Sbs99/uhBFVd/OZPjI=; b=GWM2UxokpEtHS8lZp2pnzhvLrDAzABs4W9Fwc6REaCMYNOPJtFrxOMjC07WWEDDwxDZL1ILTgHgUsk/Y0zH3FsYu39cY3/nGH/c02fqcdIsQisXiCyPYF7T3uFj/akx7rkxS2DQY7xoyX3PVseXKEguWZHqERT+5ppW0fZmtUo4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755103981576610.3380640364272; Wed, 13 Aug 2025 09:53:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEg0-00033i-It; Wed, 13 Aug 2025 12:50:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfa-0002jU-65; Wed, 13 Aug 2025 12:49:47 -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 1umEfG-0007qv-8T; Wed, 13 Aug 2025 12:49:45 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id D9AC481259; Wed, 13 Aug 2025 19:49:15 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-QFZ44R64; Wed, 13 Aug 2025 19:49:15 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103755; bh=VPbxO6D/t+j8eJzppYHqMzsC4Sbs99/uhBFVd/OZPjI=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=ea3AL6gxiUKcNUZcyF4yqL+3hSjogHa5fphT1N7Hr04DWaN3lwVZsJWGMOl7QifTt JefYJ7/GD6WxtgUqKH3zp5JZuw+V/XzpObwzm4d7PQOuD6HGkF/7JQw04OqIix4HCw rn5d+ERhsFPqvIHVqbDmVDiTBdLAlA9hAQ4xcLX0= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 16/33] vhost: simplify vhost_dev_init() error-path Date: Wed, 13 Aug 2025 19:48:37 +0300 Message-ID: <20250813164856.950363-17-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755103982943116600 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 --- 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 f6ee59425f..a3620c82d8 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1602,7 +1602,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; } } } @@ -1642,7 +1642,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 @@ -1674,17 +1674,11 @@ int vhost_dev_init(struct vhost_dev *hdev, void *op= aque, " than current number of used (%d) and reserved (%d)" " memory slots for memory devices.", limit, used, reser= ved); r =3D -EINVAL; - goto fail_busyloop; + goto fail; } =20 return 0; =20 -fail_busyloop: - if (busyloop_timeout) { - while (--i >=3D 0) { - vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i,= 0); - } - } fail: hdev->nvqs =3D n_initialized_vqs; vhost_dev_cleanup(hdev); --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104052; cv=none; d=zohomail.com; s=zohoarc; b=Fti45XyC0nmR3Ywa4tSxUTiFuWkI1rWgThw2Z02Ic966vwp61sz8oHNveD+HmzUvGZBzS2TW6N6o/sZxgKpQENUNOn3+eCrKybQ+t1Nc1wtP4NqFYfWXYiqbfc6+89b3gf8GA/Oyvd3ll9AU3jKzg3xR4zKce9O/aQoC68ldnzo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104052; 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=BWMv7GCTh1zLrolstH3IcsKkRYEicDVqwv8C15LlkPE=; b=jKyAdtNZ77iVOGfuBoylGryW7BiWk5kORXax69kHMUt2u3G0fvqA77Zmuq9g9YbYTUIir21kXVQIomrqrQdCORpVcge+FsJIaVAst8/pckM0CcZpn4IvP7O8xU6x5RGaOrnuy65OPVDbYQM+DyQDtKowA0eyQQ1gELgSxBWEXtI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104052815279.6079505046878; Wed, 13 Aug 2025 09:54:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfw-00030K-RT; Wed, 13 Aug 2025 12:50:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfQ-0002fE-2r; Wed, 13 Aug 2025 12:49:36 -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 1umEfG-0007rG-Eh; Wed, 13 Aug 2025 12:49:35 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 76A9781215; Wed, 13 Aug 2025 19:49:16 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-2x9qfGo2; Wed, 13 Aug 2025 19:49:16 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103756; bh=BWMv7GCTh1zLrolstH3IcsKkRYEicDVqwv8C15LlkPE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=0l/xxhjkxW5F90hxGQKjQlAhyTdwvLnjDkFJfSBQdJ1uyKTXtSo2iSshHkYJUwAD2 /zRk710A0Y3BexD8hbBjaVRZEFMGksulbzT7a9QSEF2jFc+8ENZzlg41WCF96eLZK/ oVDpEWqc1PyksRnNkgvSBQFkSBFlnDUJ1+ZpO3yU= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 17/33] vhost: move busyloop timeout initialization to vhost_virtqueue_init() Date: Wed, 13 Aug 2025 19:48:38 +0300 Message-ID: <20250813164856.950363-18-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104055349124100 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 --- 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 a3620c82d8..a8f8b85012 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1489,7 +1489,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 { @@ -1526,6 +1527,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: @@ -1589,24 +1598,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; - } - } - } - hdev->_features =3D features; =20 hdev->memory_listener =3D (MemoryListener) { --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104403; cv=none; d=zohomail.com; s=zohoarc; b=bYWpglPtVdren2ALxMcoyiEcjb1q9vV6lbrFSYAZoNm9fFMH0vQ7PO8y6gKsBpDo1N32S2n7wsPDQGa1w+dKJiV5fWuQYJGQ4zSmSuaveS2/FM7Zrkw0B3MWFnSwbgY8hMg8rIo7ZgyGhL1cc5kDcYz21VT6WIxkkE/XO1VxrE8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104403; 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=6mQD+E56AliUFR85mWNTx1RcVkaifnsIXZcOryL08do=; b=cumYOSeJIohm01ZOhbidkD8e9Zl8+sQAJ+RXhzg6qyGJo7Dq6Is9RMgRbY0ghC7KQRuki1MM0oZJaSJBxZQCF9J2Fp4ZO5mmWSKlh76GC9xC42p1lF+zpM/THk6HNMOp6R98dxB9UQ2SyLt1+O+j26gEmNAgn47gHZrAwQPv7C0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104403212569.4894988868857; Wed, 13 Aug 2025 10:00:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfy-00031P-B8; Wed, 13 Aug 2025 12:50:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfX-0002ht-Bz; Wed, 13 Aug 2025 12:49:44 -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 1umEfG-0007r7-B2; Wed, 13 Aug 2025 12:49:43 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 35BDA8126C; Wed, 13 Aug 2025 19:49:17 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-pC4CY3Sq; Wed, 13 Aug 2025 19:49:16 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103756; bh=6mQD+E56AliUFR85mWNTx1RcVkaifnsIXZcOryL08do=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=QMU/bscdy7Wbc4jjTwkYSVHiah6+xtqFIJxlFwAwrmsKpZwztpygzQvhKq6e5EofY YyS8ss3aF+zVmZNCX2SFfIP5N+VE94ADKGV9LXL2lYTAvc3er4763Cv6skfd9Fj0Vg XSd63L9EzGdpJDfA8P/lQeHDthv0X7zjWHYg3h0w= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 18/33] vhost: introduce check_memslots() helper Date: Wed, 13 Aug 2025 19:48:39 +0300 Message-ID: <20250813164856.950363-19-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104405390116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Raphael Norwitz --- hw/virtio/vhost.c | 71 ++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index a8f8b85012..f9163ba895 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1553,11 +1553,49 @@ static void vhost_virtqueue_cleanup(struct vhost_vi= rtqueue *vq) } } =20 +static bool check_memslots(struct vhost_dev *hdev, Error **errp) +{ + unsigned int used, reserved, limit; + + limit =3D hdev->vhost_ops->vhost_backend_memslots_limit(hdev); + if (limit < MEMORY_DEVICES_SAFE_MAX_MEMSLOTS && + memory_devices_memslot_auto_decision_active()) { + error_setg(errp, "some memory device (like virtio-mem)" + " decided how many memory slots to use based on the overall" + " number of memory slots; this vhost backend would further" + " restricts the overall number of memory slots"); + error_append_hint(errp, "Try plugging this vhost backend before" + " plugging such memory devices.\n"); + return false; + } + + /* + * The listener we registered properly setup the number of required + * memslots in vhost_commit(). + */ + used =3D hdev->mem->nregions; + + /* + * We assume that all reserved memslots actually require a real memslot + * in our vhost backend. This might not be true, for example, if the + * memslot would be ROM. If ever relevant, we can optimize for that -- + * but we'll need additional information about the reservations. + */ + reserved =3D memory_devices_get_reserved_memslots(); + if (used + reserved > limit) { + error_setg(errp, "vhost backend memory slots limit (%d) is less" + " than current number of used (%d) and reserved (%d)" + " memory slots for memory devices.", limit, used, reser= ved); + return false; + } + + return true; +} + int vhost_dev_init(struct vhost_dev *hdev, void *opaque, VhostBackendType backend_type, uint32_t busyloop_timeou= t, Error **errp) { - unsigned int used, reserved, limit; uint64_t features; int i, r, n_initialized_vqs =3D 0; =20 @@ -1584,19 +1622,6 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opa= que, goto fail; } =20 - limit =3D hdev->vhost_ops->vhost_backend_memslots_limit(hdev); - if (limit < MEMORY_DEVICES_SAFE_MAX_MEMSLOTS && - memory_devices_memslot_auto_decision_active()) { - error_setg(errp, "some memory device (like virtio-mem)" - " decided how many memory slots to use based on the overall" - " number of memory slots; this vhost backend would further" - " restricts the overall number of memory slots"); - error_append_hint(errp, "Try plugging this vhost backend before" - " plugging such memory devices.\n"); - r =3D -EINVAL; - goto fail; - } - for (i =3D 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { r =3D vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i, busyloop_timeout); @@ -1655,23 +1680,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opa= que, memory_listener_register(&hdev->memory_listener, &address_space_memory= ); QLIST_INSERT_HEAD(&vhost_devices, hdev, entry); =20 - /* - * The listener we registered properly setup the number of required - * memslots in vhost_commit(). - */ - used =3D hdev->mem->nregions; - - /* - * We assume that all reserved memslots actually require a real memslot - * in our vhost backend. This might not be true, for example, if the - * memslot would be ROM. If ever relevant, we can optimize for that -- - * but we'll need additional information about the reservations. - */ - reserved =3D memory_devices_get_reserved_memslots(); - if (used + reserved > limit) { - error_setg(errp, "vhost backend memory slots limit (%d) is less" - " than current number of used (%d) and reserved (%d)" - " memory slots for memory devices.", limit, used, reser= ved); + if (!check_memslots(hdev, errp)) { r =3D -EINVAL; goto fail; } --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755103972; cv=none; d=zohomail.com; s=zohoarc; b=L66fDVj7SB0APuR3oDzzm6ehgQvLLRn9MX0pPUWSx/JWvtJyPt2pcDrn8y5EReY/rNMdIGgz16wfrqSrNJ82F0OoceHPjnB90TXU8K2/hSTdtZIrxutLa8KbpsVoTPaabFH7nPLyupWb0b+Fh++9xiYqWNFolkl1oss166YO9cI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103972; 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=rXiud6+k3mRG4e7DZUcOmRi9puWzox9stDZ5dAJZ6ms=; b=bOJMsPo3nhKRkx7o5YeB7rQo7L+kZ/EU85IoR3uzPZEAywoj6U6vpff6heUi4nJa+gktjbM8kuolbVxOyLZOpGwphxY+e3RArr95UfwrVbnvgPO9I4NNMrM+cln52L54PClPYfFVRVh8eRpkB8LEVf2iIFYpOdQ5AIcr1ldepWM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755103972433793.8999841723224; Wed, 13 Aug 2025 09:52:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfo-0002pT-Lh; Wed, 13 Aug 2025 12:50:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfU-0002h9-Dc; Wed, 13 Aug 2025 12:49:41 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfG-0007r6-BT; Wed, 13 Aug 2025 12:49:40 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id C74D681281; Wed, 13 Aug 2025 19:49:17 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-VTd4Pxo8; Wed, 13 Aug 2025 19:49:17 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103757; bh=rXiud6+k3mRG4e7DZUcOmRi9puWzox9stDZ5dAJZ6ms=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=BriZZjTCSnaKy1FVMx0Wg5x+sW4bXz+XShxMHw3zGPUmi50Mp5DV+7SWROdgQAvUq t0kYv/G4i0uuIT+XmzvDZqJUopjG+m8BWLuU/jAqR76GNIxPnusndZlt6TqrEN3OfG zJvNGYOYOsCtje4Gmnw+4CloCo30qELemOriDF2Y= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 19/33] vhost: vhost_dev_init(): drop extra features variable Date: Wed, 13 Aug 2025 19:48:40 +0300 Message-ID: <20250813164856.950363-20-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8: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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755103974315124100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/virtio/vhost.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index f9163ba895..e796ad347d 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1596,7 +1596,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; int i, r, n_initialized_vqs =3D 0; =20 hdev->vdev =3D NULL; @@ -1616,7 +1615,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, goto fail; } =20 - r =3D hdev->vhost_ops->vhost_get_features(hdev, &features); + r =3D hdev->vhost_ops->vhost_get_features(hdev, &hdev->_features); if (r < 0) { error_setg_errno(errp, -r, "vhost_get_features failed"); goto fail; @@ -1631,8 +1630,6 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, } } =20 - hdev->_features =3D features; - hdev->memory_listener =3D (MemoryListener) { .name =3D "vhost", .begin =3D vhost_begin, --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755103970; cv=none; d=zohomail.com; s=zohoarc; b=gWqPKgi0wkOTFGB3DGvKTUFrm5DGGDZ97ys4rxtrnDoEFL88oJFSm1DYzgWbElmZJVF5KWPbjoh6+oL28fbqx6udfkjRj5IcpwIHXHIetvRDr0EBJS4n+rxv1zNndNCCoAbSv8z+/Fh8MQbiTUV0e6RMu1flTVP0pzFA18UiBmU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103970; 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=pizgr/SLVxn2pIPfmpvPOohwXp224DmrZh/s1CjFm9w=; b=BFZekiQryQ4vpt5KH1FMLJ+d2fE7NLMTm6IPqDqAk9GR90XqykHU8CJ7WkV6dnuNQYvYzOgu1uy2iywIKR5NAqcPaEDVfKs9nmN7oQUBlcvsxJEbg+21SDwXiiMQD91IFpj6xQngB+2ju520gDDqB7VYeJfaQ6n2uVOfMx9nKag= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755103970553148.0009492188659; Wed, 13 Aug 2025 09:52:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEg2-000366-6h; Wed, 13 Aug 2025 12:50:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfn-0002pD-0C; Wed, 13 Aug 2025 12:49:59 -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 1umEfg-0007sH-1J; Wed, 13 Aug 2025 12:49:58 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 7F4BE812B1; Wed, 13 Aug 2025 19:49:18 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-DXc6VwvB; Wed, 13 Aug 2025 19:49:18 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103758; bh=pizgr/SLVxn2pIPfmpvPOohwXp224DmrZh/s1CjFm9w=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=qVgGTHAr6UTecedE5eh70TuHhG+Hm7jfssuiQybvpx2iqOHufEh7REEcyOZo5A6W5 Mz7qa4vag5lNSEmxYoQgwDGq2nrO+84HczKa7xtUEkaaBU6Q4rcKqjwQ+IlqoVw+iK 3syFcJYw534AdHqMwmh2bDAz0DROCt/tHIEAieww= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 20/33] hw/virtio/virtio-bus: refactor virtio_bus_set_host_notifier() Date: Wed, 13 Aug 2025 19:48:41 +0300 Message-ID: <20250813164856.950363-21-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755103972752116600 Content-Type: text/plain; charset="utf-8" The logic kept as is. Reaftor to simplify further changes. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Raphael Norwitz --- 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 11adfbf3ab..c7e3941b1e 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -293,20 +293,18 @@ int virtio_bus_set_host_notifier(VirtioBusState *bus,= int n, bool assign) __func__, strerror(-r), r); return r; } - r =3D k->ioeventfd_assign(proxy, notifier, n, true); - if (r < 0) { - error_report("%s: unable to assign ioeventfd: %d", __func__, r= ); - virtio_bus_cleanup_host_notifier(bus, n); - } - } else { - k->ioeventfd_assign(proxy, notifier, n, false); } =20 - if (r =3D=3D 0) { - virtio_queue_set_host_notifier_enabled(vq, assign); + r =3D k->ioeventfd_assign(proxy, notifier, n, assign); + if (r < 0 && assign) { + error_report("%s: unable to assign ioeventfd: %d", __func__, r); + virtio_bus_cleanup_host_notifier(bus, n); + return r; } =20 - return r; + virtio_queue_set_host_notifier_enabled(vq, assign); + + return 0; } =20 void virtio_bus_cleanup_host_notifier(VirtioBusState *bus, int n) --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104289; cv=none; d=zohomail.com; s=zohoarc; b=C1AnV4zDM7NED+NX30I1pw0rQLs3obiFilqM3rGWRQ/R/NITOduhM/AIuQ0Mbbt/F7DZsrLCI6x33IraSiyZGwhnuUyy7zBXl8jz4hPRXKElg4xYAhYNRl7qosNB7IHsEmV3pwN/1gtIMZOia8hwxUGZsburNiSmRruNWGcWOgM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104289; 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=beNcQYTX6DnX17DPcwxxbCJUIdHSyei20zNuVbTjZac=; b=h3Tq5fRNpMBdhoddoU4JnkIxu1cSddUdq8FpYkfTCBbZDemsnOYGkZnBiaI2yPG1/IA5dVu2tRiOXI6OlyVTXNUt9dMNw3ct/eB9dTAcygVnDUEBavEZwXenXLxvAVjOAdikfV6WTZgNxIEIc4RMGqm+mVN0wCab42exskN3yGo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104289098747.5839269946256; Wed, 13 Aug 2025 09:58:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEfs-0002u1-FP; Wed, 13 Aug 2025 12:50:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfZ-0002im-2k; Wed, 13 Aug 2025 12:49:45 -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 1umEfK-0007sF-6X; Wed, 13 Aug 2025 12:49:44 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 46343812B6; Wed, 13 Aug 2025 19:49:19 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-z0Bhqwlx; Wed, 13 Aug 2025 19:49:18 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103758; bh=beNcQYTX6DnX17DPcwxxbCJUIdHSyei20zNuVbTjZac=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=nDCtV4xGsjY2U/lbyq1xaV62UJwSbftdJgfL1vbVCBPuHYYugUOq2lRMu1DrCyXMT 9X3H291Pu/oPqFgGkPBsgY60TvfXbUA0CEE+QpQ7ow2TQp6CMG/6XAfhrAW9v1mQJg lq7Uo3Dx3S1yu/7b/RNRq8toK0SOaOOsar3i7hzI= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 21/33] vhost-user: make trace events more readable Date: Wed, 13 Aug 2025 19:48:42 +0300 Message-ID: <20250813164856.950363-22-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104290368124100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Raphael Norwitz --- hw/virtio/trace-events | 4 +- hw/virtio/vhost-user.c | 94 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 94 insertions(+), 4 deletions(-) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 76f0d458b2..e5142c27f9 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 fe9d91348d..3979582975 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -119,6 +119,94 @@ typedef enum VhostUserBackendRequest { VHOST_USER_BACKEND_MAX } VhostUserBackendRequest; =20 +static const char *vhost_req_name(VhostUserRequest req) +{ + switch (req) { + case VHOST_USER_NONE: + return "NONE"; + case VHOST_USER_GET_FEATURES: + return "GET_FEATURES"; + case VHOST_USER_SET_FEATURES: + return "SET_FEATURES"; + case VHOST_USER_SET_OWNER: + return "SET_OWNER"; + case VHOST_USER_RESET_OWNER: + return "RESET_OWNER"; + case VHOST_USER_SET_MEM_TABLE: + return "SET_MEM_TABLE"; + case VHOST_USER_SET_LOG_BASE: + return "SET_LOG_BASE"; + case VHOST_USER_SET_LOG_FD: + return "SET_LOG_FD"; + case VHOST_USER_SET_VRING_NUM: + return "SET_VRING_NUM"; + case VHOST_USER_SET_VRING_ADDR: + return "SET_VRING_ADDR"; + case VHOST_USER_SET_VRING_BASE: + return "SET_VRING_BASE"; + case VHOST_USER_GET_VRING_BASE: + return "GET_VRING_BASE"; + case VHOST_USER_SET_VRING_KICK: + return "SET_VRING_KICK"; + case VHOST_USER_SET_VRING_CALL: + return "SET_VRING_CALL"; + case VHOST_USER_SET_VRING_ERR: + return "SET_VRING_ERR"; + case VHOST_USER_GET_PROTOCOL_FEATURES: + return "GET_PROTOCOL_FEATURES"; + case VHOST_USER_SET_PROTOCOL_FEATURES: + return "SET_PROTOCOL_FEATURES"; + case VHOST_USER_GET_QUEUE_NUM: + return "GET_QUEUE_NUM"; + case VHOST_USER_SET_VRING_ENABLE: + return "SET_VRING_ENABLE"; + case VHOST_USER_SEND_RARP: + return "SEND_RARP"; + case VHOST_USER_NET_SET_MTU: + return "NET_SET_MTU"; + case VHOST_USER_SET_BACKEND_REQ_FD: + return "SET_BACKEND_REQ_FD"; + case VHOST_USER_IOTLB_MSG: + return "IOTLB_MSG"; + case VHOST_USER_SET_VRING_ENDIAN: + return "SET_VRING_ENDIAN"; + case VHOST_USER_GET_CONFIG: + return "GET_CONFIG"; + case VHOST_USER_SET_CONFIG: + return "SET_CONFIG"; + case VHOST_USER_CREATE_CRYPTO_SESSION: + return "CREATE_CRYPTO_SESSION"; + case VHOST_USER_CLOSE_CRYPTO_SESSION: + return "CLOSE_CRYPTO_SESSION"; + case VHOST_USER_POSTCOPY_ADVISE: + return "POSTCOPY_ADVISE"; + case VHOST_USER_POSTCOPY_LISTEN: + return "POSTCOPY_LISTEN"; + case VHOST_USER_POSTCOPY_END: + return "POSTCOPY_END"; + case VHOST_USER_GET_INFLIGHT_FD: + return "GET_INFLIGHT_FD"; + case VHOST_USER_SET_INFLIGHT_FD: + return "SET_INFLIGHT_FD"; + case VHOST_USER_GPU_SET_SOCKET: + return "GPU_SET_SOCKET"; + case VHOST_USER_RESET_DEVICE: + return "RESET_DEVICE"; + case VHOST_USER_GET_MAX_MEM_SLOTS: + return "GET_MAX_MEM_SLOTS"; + case VHOST_USER_ADD_MEM_REG: + return "ADD_MEM_REG"; + case VHOST_USER_REM_MEM_REG: + return "REM_MEM_REG"; + case VHOST_USER_SET_STATUS: + return "SET_STATUS"; + case VHOST_USER_GET_STATUS: + return "GET_STATUS"; + default: + return ""; + } +} + typedef struct VhostUserMemoryRegion { uint64_t guest_phys_addr; uint64_t memory_size; @@ -310,7 +398,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; } @@ -430,7 +519,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.request), msg->hdr.flags= ); =20 return 0; } --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755103945; cv=none; d=zohomail.com; s=zohoarc; b=N5eY17RYHbXHHcxAfVxm3zdOCHfvIlXdrg6T6LwmjTvpHWyJ4DUQe1gf7zq2POak3+ywIZ+qaySzg85c5kStiKHWOkPGRhYY0pTNGUeC96FVfNsf2ceQMfsAS5PwYr4wS/EnvozLyn+TponGChhQD1R5YphQ/STkECDcyAoMdWU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103945; 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=RVMjTVzFKCrR8tcU9nJeNLV2M5Rh2vtB7v608WCFWz8=; b=VQRbS1jUk/1G7/0C7diz1J2S56cMuzQe4LeqW6Hqz24ie22ScuoCPmv8RKROgeiYZfRPKfHgr+uuVw9KmbcRe5szoFdRuAX9LZwfcgEyk2zMsSHNiqE/u8bz2AkOq67UyOlvCnZo5zjn6QsYYSWW8vqGHfpcSnl99BSnuFqPpZI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755103945302672.8114476956194; Wed, 13 Aug 2025 09:52:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEg5-00038w-4I; Wed, 13 Aug 2025 12:50:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfo-0002pt-7x; Wed, 13 Aug 2025 12:50:00 -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 1umEfg-0007sW-0x; Wed, 13 Aug 2025 12:49:59 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 040F681120; Wed, 13 Aug 2025 19:49:20 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-r37fMOkh; Wed, 13 Aug 2025 19:49:19 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103759; bh=RVMjTVzFKCrR8tcU9nJeNLV2M5Rh2vtB7v608WCFWz8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=mv/YQw7zHXyLg8O9kapWcCGLgHZUnr59AWTb9LtZg+QDjuX9Q8dk/vKFxeOJrIAEF ZYqX0MNVZJbwlNWtXWf6TRyZZ4lDJyWcMEw3QHsdA/4pxmT22AOm7KC3aP8Bryivzu ryfSqfED1jc3vhL0ev2i85cbxcu4EtcTYAcE7TKo= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 22/33] vhost-user-blk: add some useful trace-points Date: Wed, 13 Aug 2025 19:48:43 +0300 Message-ID: <20250813164856.950363-23-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755103947961124100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/block/trace-events | 10 ++++++++++ hw/block/vhost-user-blk.c | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/hw/block/trace-events b/hw/block/trace-events index cc9a9f2460..3b5fd2a599 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(void) "" +vhost_user_blk_start_finish(void) "" +vhost_user_blk_stop(void) "" +vhost_user_blk_stop_finish(void) "" +vhost_user_blk_connect(void) "" +vhost_user_blk_connect_finish(void) "" +vhost_user_blk_device_realize(void) "" +vhost_user_blk_device_realize_finish(void) "" + # hd-geometry.c hd_geometry_lchs_guess(void *blk, int cyls, int heads, int secs) "blk %p L= CHS %d %d %d" hd_geometry_guess(void *blk, uint32_t cyls, uint32_t heads, uint32_t secs,= int trans) "blk %p CHS %u %u %u trans %d" diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index de7a810c93..c8bc2c78e6 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(); + 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_finish(); + 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(); + if (!s->started_vu) { return 0; } @@ -233,6 +240,8 @@ static int vhost_user_blk_stop(VirtIODevice *vdev) } =20 vhost_dev_disable_notifiers(&s->dev, vdev); + + trace_vhost_user_blk_stop_finish(); return ret; } =20 @@ -340,6 +349,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(); + if (s->connected) { return 0; } @@ -365,6 +376,7 @@ 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_finish(); return ret; } =20 @@ -455,6 +467,8 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) int retries; int i, ret; =20 + trace_vhost_user_blk_device_realize(); + if (!s->chardev.chr) { error_setg(errp, "chardev is mandatory"); return; @@ -514,6 +528,7 @@ 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_finish(); return; =20 virtio_err: --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755103943; cv=none; d=zohomail.com; s=zohoarc; b=P3c63pef9o2qgJ+L1n1qrtO31oBl00fP5pBXZd1OPKF2bA3PDY7xx88Lz1ZeMieLCY0ZWBLxZS/XXJpiv4Xg3DcLyayPWuTHdk1kSWEUSowPCNeYYLsHCSbdgF/gvuJIv+u/UsbBtweeFLcDMM+DBYrzUgIgHBM4ewC/0jrTTzU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103943; 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=9x+pN5wqcLxluCQaOQzc9Rm1O+CLACFMRucvbD3nD5I=; b=FhKyZOE6q8NrZ7zLLrBnRUIAOi5Djt2Dk88Om+wU+u+Y8Mo8gDCkKI/I6oS0dIxR2g0ej60tkoPtBh4+U4JfXhcioPjiqJnwgbaNWugF8LrRhRly7TGtvs7BzS+ghqOmNDT94VUP1t/N3HwUm6fc51VoC8HDrESeOl/suHxGUqo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755103943648398.7005797230414; Wed, 13 Aug 2025 09:52:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEg9-0003B7-HT; Wed, 13 Aug 2025 12:50:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfs-0002u0-Cw; Wed, 13 Aug 2025 12:50:04 -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 1umEfg-0007sV-Uo; Wed, 13 Aug 2025 12:50:02 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 38741812F5; Wed, 13 Aug 2025 19:49:21 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-ZdwXD6Pi; Wed, 13 Aug 2025 19:49:20 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103760; bh=9x+pN5wqcLxluCQaOQzc9Rm1O+CLACFMRucvbD3nD5I=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=VBYz5hG3FNXy5ZlViA0PqjzTXLzHxobGhbV8JlYjsvSKKBLxdzMXUytO0d0bMI43C 3nj9EblMTuM7mT6PEyA6Jp/hQ1BpaJTmAAk1hHPrP/FGRLZs/bE/tWZ3YZ1sb8MAQK 9sY/Td+4apW8+H6/gUmaFhEwULN6IVBbEiO4NB8Y= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 23/33] vhost: add some useful trace-points Date: Wed, 13 Aug 2025 19:48:44 +0300 Message-ID: <20250813164856.950363-24-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8: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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755103946176124100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/virtio/trace-events | 8 ++++++++ hw/virtio/vhost.c | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index e5142c27f9..bd595fcd91 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -10,7 +10,15 @@ 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_start_finish(const char *name) "%s" vhost_dev_stop(void *dev, const char *name, bool vrings) "%p:%s vrings:%d" +vhost_dev_stop_finish(const char *name) "%s" +vhost_virtque_start(const char *name, int idx) "%s %d" +vhost_virtque_start_finish(const char *name, int idx) "%s %d" +vhost_virtque_stop(const char *name, int idx) "%s %d" +vhost_virtque_stop_finish(const char *name, int idx) "%s %d" +vhost_dev_init(void) "" +vhost_dev_init_finish(void) "" =20 =20 # vhost-user.c diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index e796ad347d..e7c809400b 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1329,6 +1329,8 @@ int vhost_virtqueue_start(struct vhost_dev *dev, }; struct VirtQueue *vvq =3D virtio_get_queue(vdev, idx); =20 + trace_vhost_virtque_start(vdev->name, idx); + r =3D vhost_vrings_map(dev, vdev, vq, idx); if (r <=3D 0) { return r; @@ -1390,6 +1392,8 @@ int vhost_virtqueue_start(struct vhost_dev *dev, } } =20 + trace_vhost_virtque_start_finish(vdev->name, idx); + return 0; =20 fail: @@ -1408,6 +1412,8 @@ static int do_vhost_virtqueue_stop(struct vhost_dev *= dev, }; int r =3D 0; =20 + trace_vhost_virtque_stop(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; @@ -1441,6 +1447,8 @@ static int do_vhost_virtqueue_stop(struct vhost_dev *= dev, } =20 vhost_vrings_unmap(dev, vq, true); + + trace_vhost_virtque_stop_finish(vdev->name, idx); return r; } =20 @@ -1598,6 +1606,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, { int i, r, n_initialized_vqs =3D 0; =20 + trace_vhost_dev_init(); + hdev->vdev =3D NULL; hdev->migration_blocker =3D NULL; =20 @@ -1682,6 +1692,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, goto fail; } =20 + trace_vhost_dev_init_finish(); + return 0; =20 fail: @@ -2132,6 +2144,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODev= ice *vdev, bool vrings) } } vhost_start_config_intr(hdev); + + trace_vhost_dev_start_finish(vdev->name); return 0; fail_iotlb: if (vhost_dev_has_iommu(hdev) && @@ -2210,6 +2224,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_finish(vdev->name); return rc; } =20 --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104463; cv=none; d=zohomail.com; s=zohoarc; b=U2M7DKftwzvBRGvEhlD1YiKEL8p2LnXQBUbEJR/RmuYoOLfBi3X9VvQ/24M/opyltagpcpZ/Y0UUYkDATtl4u3iha5OD9ZwNgn+a+ORYpc+lylUCTP7J94cqewkBXXjck96iNBk04weJ0FMHf+qNsuLCUis2UTWNid0HAMGx9rs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104463; 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=Wp+4GceFeTBXu9j82YWHNLbIdiUNa1OHM2J6/qAbIfM=; b=A3ghiRcyLz7Jl9uZSbmBAq13OrJTzYXINkZZjKnOPzbrTAxPB82iUEtkOwTvDjWcXtB+G4T3qSKVaRK2YeN0XFh4OJQpsYGbr9ZmDDSogdSPOBVWLzlPqsdQZ5ssa9DNk9TdLkrEAIp7Q/tBxrE2eAqg8sGHYdy/p7paU+6nDpM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104463074488.7634023797657; Wed, 13 Aug 2025 10:01:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEg3-00037F-Dq; Wed, 13 Aug 2025 12:50:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfm-0002pC-Vs; Wed, 13 Aug 2025 12:49:59 -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 1umEfN-0007sY-SQ; Wed, 13 Aug 2025 12:49:58 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 2AAFB81392; Wed, 13 Aug 2025 19:49:22 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-zEYONDc4; Wed, 13 Aug 2025 19:49:21 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103761; bh=Wp+4GceFeTBXu9j82YWHNLbIdiUNa1OHM2J6/qAbIfM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=yDnKq5SbtdknzNvdH+vl1dfbw6wNj2qtOHpMuFuKbD0x8LsES4qPZLDeQovwlFv31 C6OahqMKQDRHOQlSLpnR3/44OXJOsIhHT/3HPfOjytsNJ+tNF2JZ3AeiS+KNms/quq lZVW3q8vbm5iZRSIV2t+xsuoWTAioWf4WZRGkLkk= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru, Laurent Vivier Subject: [PATCH 24/33] chardev-add: support local migration Date: Wed, 13 Aug 2025 19:48:45 +0300 Message-ID: <20250813164856.950363-25-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8: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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104466011124100 Content-Type: text/plain; charset="utf-8" This commit introduces a possibility to migrate open chardev socket fd through migration channel without reconnecting. For this, user should: - enable new migration capability local-char-socket - mark the socket by an option support-local-migration=3Dtrue - on target add local-incoming=3Dtrue option to the socket Motivation for the API: 1. We don't want to migrate all sockets. For example, QMP-connection is bad candidate, as it is separate on source and target. So, we need @support-local-migration option to mark sockets, which we want to migrate (after this series, we'll want to migrate chardev used to connect with vhost-user-server). 2. Still, for remote migration, we can't migrate any sockets, so, we need a capability, to enable/disable the whole feature. 3. And finally, we need a sign for the socket to not open a connection on initialization, but wait for incoming migration. We can't use @support-local-migration option for it, as it may be enabled, but we are in incoming-remote migration. Also, we can't rely on the migration capability, as user is free to setup capabilities before or after chardev creation, and it would be a bad precedent to create relations here. Signed-off-by: Vladimir Sementsov-Ogievskiy --- chardev/char-socket.c | 101 +++++++++++++++++++++++++++++++++- include/chardev/char-socket.h | 3 + migration/options.c | 7 +++ migration/options.h | 1 + qapi/char.json | 16 +++++- qapi/migration.json | 8 ++- stubs/meson.build | 1 + stubs/qemu_file.c | 15 +++++ stubs/vmstate.c | 6 ++ tests/qtest/meson.build | 2 +- tests/unit/meson.build | 4 +- 11 files changed, 158 insertions(+), 6 deletions(-) create mode 100644 stubs/qemu_file.c diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 1e8313915b..db6616e2f2 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -24,6 +24,7 @@ =20 #include "qemu/osdep.h" #include "chardev/char.h" +#include "qapi-types-char.h" #include "io/channel-socket.h" #include "io/channel-websock.h" #include "qemu/error-report.h" @@ -34,6 +35,10 @@ #include "qapi/qapi-visit-sockets.h" #include "qemu/yank.h" #include "trace.h" +#include "migration/vmstate.h" +#include "migration/qemu-file.h" +#include "migration/migration.h" +#include "hw/vmstate-if.h" =20 #include "chardev/char-io.h" #include "chardev/char-socket.h" @@ -1118,6 +1123,7 @@ static void char_socket_finalize(Object *obj) object_unref(OBJECT(s->tls_creds)); } g_free(s->tls_authz); + g_free(s->vmstate_name); if (s->registered_yank) { /* * In the chardev-change special-case, we shouldn't unregister the= yank @@ -1276,8 +1282,15 @@ static int qmp_chardev_open_socket_client(Chardev *c= hr, { SocketChardev *s =3D SOCKET_CHARDEV(chr); =20 + s->reconnect_time_ms =3D reconnect_ms; + + if (s->local_incoming) { + /* We'll get fd at migreation load. This field works once */ + s->local_incoming =3D false; + return 0; + } + if (reconnect_ms > 0) { - s->reconnect_time_ms =3D reconnect_ms; tcp_chr_connect_client_async(chr); return 0; } else { @@ -1367,6 +1380,52 @@ static bool qmp_chardev_validate_socket(ChardevSocke= t *sock, return true; } =20 +static int char_socket_save(QEMUFile *f, void *opaque, size_t size, + const VMStateField *field, JSONWriter *vmdesc) +{ + SocketChardev *s =3D opaque; + + warn_report("%s", __func__); + return qemu_file_put_fd(f, s->sioc->fd); +} + +static int char_socket_load(QEMUFile *f, void *opaque, size_t size, + const VMStateField *field) +{ + Chardev *chr =3D opaque; + + int fd =3D qemu_file_get_fd(f); + warn_report("%s %d", __func__, fd); + if (fd < 0) { + return fd; + } + return tcp_chr_add_client(chr, fd); +} + +static bool char_socket_needed(void *opaque) +{ + SocketChardev *s =3D opaque; + + return !!s->vmstate_name; +} + +const VMStateDescription vmstate_char_socket =3D { + .name =3D "char_socket", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D char_socket_needed, + .fields =3D (VMStateField[]) { + { + .name =3D "fd", + .info =3D &(const VMStateInfo) { + .name =3D "fd", + .get =3D char_socket_load, + .put =3D char_socket_save, + }, + }, + VMSTATE_END_OF_LIST() + }, +}; =20 static void qmp_chardev_open_socket(Chardev *chr, ChardevBackend *backend, @@ -1381,14 +1440,36 @@ static void qmp_chardev_open_socket(Chardev *chr, bool is_tn3270 =3D sock->has_tn3270 ? sock->tn3270 : false; bool is_waitconnect =3D sock->has_wait ? sock->wait : false; bool is_websock =3D sock->has_websocket ? sock->websocket : false; + bool support_local_mig =3D sock->has_support_local_migration + ? sock->support_local_migration + : false; + bool local_incoming =3D sock->local_incoming; int64_t reconnect_ms =3D 0; SocketAddress *addr; =20 + if (support_local_mig && is_listen) { + error_setg(errp, + "local migration is not supported for listening sockets= "); + return; + } + + if (support_local_mig && !(chr->label && chr->label[0])) { + error_setg(errp, + "local migration is not supported for unnamed chardevs"= ); + return; + } + s->is_listen =3D is_listen; s->is_telnet =3D is_telnet; s->is_tn3270 =3D is_tn3270; s->is_websock =3D is_websock; s->do_nodelay =3D do_nodelay; + s->local_incoming =3D local_incoming; + + if (support_local_mig) { + s->vmstate_name =3D g_strdup_printf("__yc-chardev-%s", chr->label); + } + if (sock->tls_creds) { Object *creds; creds =3D object_resolve_path_component( @@ -1448,6 +1529,7 @@ static void qmp_chardev_open_socket(Chardev *chr, update_disconnected_filename(s); =20 if (s->is_listen) { + assert(!s->vmstate_name); if (qmp_chardev_open_socket_server(chr, is_telnet || is_tn3270, is_waitconnect, errp) < 0) { return; @@ -1463,6 +1545,8 @@ static void qmp_chardev_open_socket(Chardev *chr, return; } } + + vmstate_register(VMSTATE_IF(s), -1, &vmstate_char_socket, s); } =20 static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, @@ -1581,9 +1665,20 @@ char_socket_get_connected(Object *obj, Error **errp) return s->state =3D=3D TCP_CHARDEV_STATE_CONNECTED; } =20 +static char * +char_socket_if_get_id(VMStateIf *obj) +{ + SocketChardev *s =3D SOCKET_CHARDEV(obj); + + return s->vmstate_name; +} + static void char_socket_class_init(ObjectClass *oc, const void *data) { ChardevClass *cc =3D CHARDEV_CLASS(oc); + VMStateIfClass *vc =3D VMSTATE_IF_CLASS(oc); + + vc->get_id =3D char_socket_if_get_id; =20 cc->supports_yank =3D true; =20 @@ -1613,6 +1708,10 @@ static const TypeInfo char_socket_type_info =3D { .instance_size =3D sizeof(SocketChardev), .instance_finalize =3D char_socket_finalize, .class_init =3D char_socket_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_VMSTATE_IF }, + { } + } }; =20 static void register_types(void) diff --git a/include/chardev/char-socket.h b/include/chardev/char-socket.h index d6d13ad37f..69b9609215 100644 --- a/include/chardev/char-socket.h +++ b/include/chardev/char-socket.h @@ -78,6 +78,9 @@ struct SocketChardev { bool connect_err_reported; =20 QIOTask *connect_task; + + char *vmstate_name; + bool local_incoming; }; typedef struct SocketChardev SocketChardev; =20 diff --git a/migration/options.c b/migration/options.c index 4e923a2e07..dffb6910f4 100644 --- a/migration/options.c +++ b/migration/options.c @@ -262,6 +262,13 @@ bool migrate_mapped_ram(void) return s->capabilities[MIGRATION_CAPABILITY_MAPPED_RAM]; } =20 +bool migrate_local_char_socket(void) +{ + MigrationState *s =3D migrate_get_current(); + + return s->capabilities[MIGRATION_CAPABILITY_LOCAL_CHAR_SOCKET]; +} + bool migrate_ignore_shared(void) { MigrationState *s =3D migrate_get_current(); diff --git a/migration/options.h b/migration/options.h index 82d839709e..40971f0aa0 100644 --- a/migration/options.h +++ b/migration/options.h @@ -30,6 +30,7 @@ bool migrate_colo(void); bool migrate_dirty_bitmaps(void); bool migrate_events(void); bool migrate_mapped_ram(void); +bool migrate_local_char_socket(void); bool migrate_ignore_shared(void); bool migrate_late_block_activate(void); bool migrate_multifd(void); diff --git a/qapi/char.json b/qapi/char.json index f0a53f742c..5b535c196a 100644 --- a/qapi/char.json +++ b/qapi/char.json @@ -280,11 +280,23 @@ # mutually exclusive with @reconnect. # (default: 0) (Since: 9.2) # +# @support-local-migration: The socket open file descriptor will +# migrate if this field is true and local-char-socket migration +# capability enabled (default: false) (Since: 10.2) +# +# @local-incoming: Do load open file descriptor for the socket +# on incoming migration. May be used only if QEMU is started +# for incoming migration and only together with local-char-socket +# migration capability (default: false) (Since: 10.2) +# # Features: # # @deprecated: Member @reconnect is deprecated. Use @reconnect-ms # instead. # +# @unstable: Members @support-local-migration and @local-incoming +# are experimental +# # Since: 1.4 ## { 'struct': 'ChardevSocket', @@ -298,7 +310,9 @@ '*tn3270': 'bool', '*websocket': 'bool', '*reconnect': { 'type': 'int', 'features': [ 'deprecated' ] }, - '*reconnect-ms': 'int' }, + '*reconnect-ms': 'int', + '*support-local-migration': { 'type': 'bool', 'features': [ 'u= nstable' ] }, + '*local-incoming': { 'type': 'bool', 'features': [ 'unstable' = ] } }, 'base': 'ChardevCommon' } =20 ## diff --git a/qapi/migration.json b/qapi/migration.json index 2387c21e9c..4f282d168e 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -517,6 +517,11 @@ # each RAM page. Requires a migration URI that supports seeking, # such as a file. (since 9.0) # +# @local-char-socket: Migrate socket chardevs open file descriptors. +# Only may be used when migration channel is unix socket. Only +# involves socket chardevs with "support-local-migration" option +# enabled. (since 10.2) +# # Features: # # @unstable: Members @x-colo and @x-ignore-shared are experimental. @@ -536,7 +541,8 @@ { 'name': 'x-ignore-shared', 'features': [ 'unstable' ] }, 'validate-uuid', 'background-snapshot', 'zero-copy-send', 'postcopy-preempt', 'switchover-ack', - 'dirty-limit', 'mapped-ram'] } + 'dirty-limit', 'mapped-ram', + { 'name': 'local-char-socket', 'features': [ 'unstable' ] } ] } =20 ## # @MigrationCapabilityStatus: diff --git a/stubs/meson.build b/stubs/meson.build index cef046e685..7855483639 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -50,6 +50,7 @@ if have_block or have_user stub_ss.add(files('qtest.c')) stub_ss.add(files('vm-stop.c')) stub_ss.add(files('vmstate.c')) + stub_ss.add(files('qemu_file.c')) endif =20 if have_user diff --git a/stubs/qemu_file.c b/stubs/qemu_file.c new file mode 100644 index 0000000000..854d4c13cd --- /dev/null +++ b/stubs/qemu_file.c @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" +#include "migration/qemu-file.h" + + +int qemu_file_get_fd(QEMUFile *f) +{ + return -1; +} + +int qemu_file_put_fd(QEMUFile *f, int fd) +{ + return -1; +} diff --git a/stubs/vmstate.c b/stubs/vmstate.c index c190762d7c..f345edf3c9 100644 --- a/stubs/vmstate.c +++ b/stubs/vmstate.c @@ -2,6 +2,7 @@ #include "migration/vmstate.h" #include "qapi/qapi-types-migration.h" #include "migration/client-options.h" +#include "migration/options.h" =20 int vmstate_register_with_alias_id(VMStateIf *obj, uint32_t instance_id, @@ -28,3 +29,8 @@ MigMode migrate_mode(void) { return MIG_MODE_NORMAL; } + +bool migrate_local_char_socket(void) +{ + return false; +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 669d07c06b..8be0c1dc7c 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -381,7 +381,7 @@ qtests =3D { 'pxe-test': files('boot-sector.c'), 'pnv-xive2-test': files('pnv-xive2-common.c', 'pnv-xive2-flush-sync.c', 'pnv-xive2-nvpg_bar.c'), - 'qos-test': [chardev, io, qos_test_ss.apply({}).sources()], + 'qos-test': [chardev, io, qos_test_ss.apply({}).sources(), '../../hw/cor= e/vmstate-if.c'], 'tpm-crb-swtpm-test': [io, tpmemu_files], 'tpm-crb-test': [io, tpmemu_files], 'tpm-tis-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'], diff --git a/tests/unit/meson.build b/tests/unit/meson.build index d5248ae51d..b96f4dcabe 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -139,7 +139,7 @@ if have_system 'test-bufferiszero': [], 'test-smp-parse': [qom, meson.project_source_root() / 'hw/core/machine= -smp.c'], 'test-vmstate': [migration, io], - 'test-yank': ['socket-helpers.c', qom, io, chardev] + 'test-yank': ['socket-helpers.c', qom, io, chardev, '../../hw/core/vms= tate-if.c'] } if config_host_data.get('CONFIG_INOTIFY1') tests +=3D {'test-util-filemonitor': []} @@ -151,7 +151,7 @@ if have_system if not get_option('tsan') if host_os !=3D 'windows' tests +=3D { - 'test-char': ['socket-helpers.c', qom, io, chardev] + 'test-char': ['socket-helpers.c', qom, io, chardev, '../../hw/co= re/vmstate-if.c'] } endif =20 --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104056; cv=none; d=zohomail.com; s=zohoarc; b=SSade7B714E+X6ZlF0hHGgy7qTVFTevntCJHVoGvVGNPHvOgpS1dXhcKBGn2cVwSE3wRjY1szTmH6f6ZJAiRduGqZ9MfnKZb5S/CK6933xeyPJwswm33HblAAik4WIxfLkJZrj332hQ3DPN7BzQD1ueDSxsCxFhHedivPaJfI9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104056; 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=ZP0m2iDnfarTInOhw140IrfQHwLhKgCJqmsVxIbp4EI=; b=RXDM/5pMkh0dAp8RSZajt859PZHKevqzgBXthuJJCX7iyAJGuyJex9XJSwWF5L6hFq/1n2oCCI7FoI45cj0/eG/Rkyfy86OBv02AjzXBYyEyzagB0LawcOI3S4gBbk7RF/BCALZoLOt1xkQQ2Reau3yzP9kI4mgfpxTzfcWzFBs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104056175206.4631189455464; Wed, 13 Aug 2025 09:54:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEg1-00035g-Qh; Wed, 13 Aug 2025 12:50:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfg-0002lz-EF; Wed, 13 Aug 2025 12:49:54 -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 1umEfN-0007sa-Sb; Wed, 13 Aug 2025 12:49:51 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id D7E3C81293; Wed, 13 Aug 2025 19:49:22 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-AjtT8153; Wed, 13 Aug 2025 19:49:22 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103762; bh=ZP0m2iDnfarTInOhw140IrfQHwLhKgCJqmsVxIbp4EI=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=vq+LyZby3Ac3qLJHar+od0dCVnu23OvoImoXuSipzu2Fz6pnCIw7PA8edeKaCS7jv JJW8UBaVK6ippz9ORw7ZvI1A7v31nEdwqRyxpGy5NubXJG/1bMPZWf8hVzVMO5RaVz 2PJui5tkB4KHvb7UQPAR/JF4fJUU6Tdivkubxz00= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 25/33] virtio: introduce .skip_vhost_migration_log() handler Date: Wed, 13 Aug 2025 19:48:46 +0300 Message-ID: <20250813164856.950363-26-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8: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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104059399124100 Content-Type: text/plain; charset="utf-8" For vhost user backend migration we'll need to disable memory logging on the device. Let's prepare a corresponding handler for the device. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Raphael Norwitz --- hw/virtio/vhost.c | 10 ++++++++++ include/hw/virtio/virtio.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index e7c809400b..0427fc29b2 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1134,6 +1134,16 @@ static int vhost_migration_log(MemoryListener *liste= ner, bool enable) struct vhost_dev *dev =3D container_of(listener, struct vhost_dev, memory_listener); int r; + + if (dev->vdev) { + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(dev->vdev); + + if (vdc->skip_vhost_migration_log && + vdc->skip_vhost_migration_log(dev->vdev)) { + return 0; + } + } + if (enable =3D=3D dev->log_enabled) { return 0; } diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 8b9db08ddf..9a4a0a94aa 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -234,6 +234,8 @@ struct VirtioDeviceClass { /* May be called even when vdev->vhost_started is false */ struct vhost_dev *(*get_vhost)(VirtIODevice *vdev); void (*toggle_device_iotlb)(VirtIODevice *vdev); + + bool (*skip_vhost_migration_log)(VirtIODevice *vdev); }; =20 void virtio_instance_init_common(Object *proxy_obj, void *data, --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755103941; cv=none; d=zohomail.com; s=zohoarc; b=hR/ZLMxU5YfFjQtnauSioyPNsqWGeYiUwDh1dqXejCvMvowuNA1qq2VptGQ4jmSE/EoZ09W4+Y+P95GFXrmoOEkEUJVcPbpDAdIHizlNytZuHI6qFm8l8Q1cOlMPUbymXAssijpaxlhSkOjFgPT7J6fMFlurZgpZa4DEP+RtokU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103941; 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=xvfsbTtoNa6txz9pDWOU7s8gMBMfz7afPsycmey1QP0=; b=f7lFqz5RTtGnvEavL27au2fibB8npSM7fI4msowvrvkVJfDM2LfxSDG5ZNJsTRkDrqLWxhN4oTpDQFcbmAwDyd4g1RTvYi2PJz+xjFHjC1it4Q4mqhtlvP227IlVx/QXw8bJGEfiomgo3BTFiQN0wNq06upkVI9G99RW3eShVMk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755103941329756.1917528956711; Wed, 13 Aug 2025 09:52:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEg9-0003Bh-IW; Wed, 13 Aug 2025 12:50:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfo-0002q3-JE; Wed, 13 Aug 2025 12:50:00 -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 1umEfk-0007tP-77; Wed, 13 Aug 2025 12:50:00 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 9CAD381397; Wed, 13 Aug 2025 19:49:23 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-6QpLxnRE; Wed, 13 Aug 2025 19:49:23 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103763; bh=xvfsbTtoNa6txz9pDWOU7s8gMBMfz7afPsycmey1QP0=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Pb7sGPsu/zEU/ogwFSulZ6rY7olIH3GJgwgVbQbSJDI0UoS2AkpWB5aGvmFpssdsc iE418Gx98MF3egceYMLuarQNjfcVj+u1DC5aafzWVDkPblDddFSx72lrl05ijpsBy7 DwYMhg3W34mLXJo5MiybgrsGD7KnSLXHVx5CBLWw= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 26/33] io/channel-socket: introduce qio_channel_socket_keep_nonblock() Date: Wed, 13 Aug 2025 19:48:47 +0300 Message-ID: <20250813164856.950363-27-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755103942517116600 Content-Type: text/plain; charset="utf-8" Add a possibility to keep socket non-block status when passing through qio channel. We need this to support migration of open fds through migration channel. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/io/channel-socket.h | 3 +++ io/channel-socket.c | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h index a88cf8b3a9..0a4327d745 100644 --- a/include/io/channel-socket.h +++ b/include/io/channel-socket.h @@ -49,6 +49,7 @@ struct QIOChannelSocket { socklen_t remoteAddrLen; ssize_t zero_copy_queued; ssize_t zero_copy_sent; + bool keep_nonblock; }; =20 =20 @@ -275,4 +276,6 @@ int qio_channel_socket_set_send_buffer(QIOChannelSocket= *ioc, size_t size, Error **errp); =20 +void qio_channel_socket_keep_nonblock(QIOChannel *ioc); + #endif /* QIO_CHANNEL_SOCKET_H */ diff --git a/io/channel-socket.c b/io/channel-socket.c index 3b7ca924ff..cd93d7f180 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -462,9 +462,16 @@ static void qio_channel_socket_finalize(Object *obj) } =20 =20 +void qio_channel_socket_keep_nonblock(QIOChannel *ioc) +{ + QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); + sioc->keep_nonblock =3D true; +} + + #ifndef WIN32 static void qio_channel_socket_copy_fds(struct msghdr *msg, - int **fds, size_t *nfds) + int **fds, size_t *nfds, bool set_= block) { struct cmsghdr *cmsg; =20 @@ -497,8 +504,9 @@ static void qio_channel_socket_copy_fds(struct msghdr *= msg, continue; } =20 - /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ - qemu_socket_set_block(fd); + if (set_block) { + qemu_socket_set_block(fd); + } =20 #ifndef MSG_CMSG_CLOEXEC qemu_set_cloexec(fd); @@ -556,7 +564,7 @@ static ssize_t qio_channel_socket_readv(QIOChannel *ioc, } =20 if (fds && nfds) { - qio_channel_socket_copy_fds(&msg, fds, nfds); + qio_channel_socket_copy_fds(&msg, fds, nfds, !sioc->keep_nonblock); } =20 return ret; --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104202; cv=none; d=zohomail.com; s=zohoarc; b=Itl7L1tfofIxT3JpbFIP9mlHmEZwxvlsf6DemRlprLgvJb5+xJ/mk2ki4vPq9PcOsVEMcUYgf4y3q0PzKFlnhlrLMK/2+fskUHHrlW3ykWO8ELD9QHex7V0DCnVJvKoCzaxFKGYMQuTs87uGlX9wtCndc9x0iKyOsmFy0omYU8o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104202; 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=93HXWox7mDMTrDEoXXvnQwNTiWuDVZrp/8nMnjfFJoA=; b=bW/SCcrPbIiBscRFaiiE1RPxoYEqH07cJbtZTpLKlh/M7ZBOuuSTOGJKZF794rN+ywKtT04QI0ldaRPG3kNVQ4/Xcp4RvqGDrpuQRnFUsOWRzmnmXAliveJpO3BMRmDmXRuQL1I48Q2THRwibuzDETUPFliRq3VsfnSvwwNjUAU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104202839371.03097701989986; Wed, 13 Aug 2025 09:56:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEgH-0003Cs-E9; Wed, 13 Aug 2025 12:50:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfs-0002uU-SZ; Wed, 13 Aug 2025 12:50:05 -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 1umEfk-0007tN-65; Wed, 13 Aug 2025 12:50:04 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 71630812B4; Wed, 13 Aug 2025 19:49:24 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-3xQMxoVW; Wed, 13 Aug 2025 19:49:23 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103763; bh=93HXWox7mDMTrDEoXXvnQwNTiWuDVZrp/8nMnjfFJoA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=bQ2cJxeGv+HZTLlCK7SPEU2xys6oRZU1yyREmDoyGPJVjrnfTpf4tZ7sjeIDr/CTe cD/hCx2RGB6RIMfG6JQj38V/Oc+yb5MSFXg3TWTD+Jgh8TbuCkFJzuhz7uVpFElWO3 gA1tKKCnNkAheukzWc3cR6ODzHsP94H1x/cKfhb0= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 27/33] migration/socket: keep fds non-block Date: Wed, 13 Aug 2025 19:48:48 +0300 Message-ID: <20250813164856.950363-28-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8: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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104204908116600 Content-Type: text/plain; charset="utf-8" For migration channel keep fds non-blocking property as is. It's needed for future local migration of fds. Signed-off-by: Vladimir Sementsov-Ogievskiy --- migration/socket.c | 1 + 1 file changed, 1 insertion(+) diff --git a/migration/socket.c b/migration/socket.c index 5ec65b8c03..9f7b6919cf 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -129,6 +129,7 @@ static void socket_accept_incoming_migration(QIONetList= ener *listener, } =20 qio_channel_set_name(QIO_CHANNEL(cioc), "migration-socket-incoming"); + qio_channel_socket_keep_nonblock(QIO_CHANNEL(cioc)); migration_channel_process_incoming(QIO_CHANNEL(cioc)); } =20 --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104051; cv=none; d=zohomail.com; s=zohoarc; b=A8iGbBsCpi7CMsNTHOfBav9HthLcaKZrfI4iQ1fKKvMxHV0EATHJgUnJKCdG0jyPgrYr271SMwUk9tLfk7fqvsveCz8UueyoZQlVmj58tmxhLm5SXanzMcycL5xpAI+3z6DIJOmHx8j5k7XaAemGXun1AoZZ+u93Uyj6cb9tTOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104051; 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=U5xk0Mm+xj1gGYHsGb0KWHnifSCYfGr8y1lwHMvVzaA=; b=gdMdRtU7szvh9iqw1HPNarILPYJwP8zbMtd9rkcqNmTAXivq3Bhiav3yg+KZad7/JEu6bGKRSC8awUTY1UWmXjlDi8RvXyO/Jo5gfXWfikRAuIrsPP25Rm+fawJC/vQVd06I+Wn7PRoIdtDKW+HvzDQhF+VPVy/81+FzHPtOWQI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104051417741.4006344338887; Wed, 13 Aug 2025 09:54:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEgC-0003Bd-5Q; Wed, 13 Aug 2025 12:50:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfu-0002wm-3N; Wed, 13 Aug 2025 12:50: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 1umEfk-0007tM-QZ; Wed, 13 Aug 2025 12:50:05 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 5E4DE813B1; Wed, 13 Aug 2025 19:49:25 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-a0tJfqHE; Wed, 13 Aug 2025 19:49:24 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103764; bh=U5xk0Mm+xj1gGYHsGb0KWHnifSCYfGr8y1lwHMvVzaA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=CWqayTB4OsZEjfzdKYwvCXgwo/pe/DyShQX8FoxEYy1xlLDx66pOiRRLQb7kuha2c EdYrFJ2zmg1qL7r3ucWIXS7Lyo+Gz5aJnuis0I6DgXokg4VCsaC7ZEDREKYxAryLX4 32EAqOvICYk9qpAB0nUqkThEfN1oOTcWVC0URhnA= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 28/33] vhost: introduce backend migration Date: Wed, 13 Aug 2025 19:48:49 +0300 Message-ID: <20250813164856.950363-29-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104053328124100 Content-Type: text/plain; charset="utf-8" Normally on migration we stop and destroy connection with vhost (vhost-user-blk server, or kernel vhost) on source and reinitialize it on target. With this commit we start to implement vhost backend migration, i.e. we don't stop the connection and operation of vhost. Instead, we pass backend-related state, including open file descriptors to target process. Of course, it's possible only for local migration, and migration channel should be a unix socket. Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/virtio/vhost.c | 184 +++++++++++++++++++++++++----- include/hw/virtio/vhost-backend.h | 5 + include/hw/virtio/vhost.h | 6 + 3 files changed, 167 insertions(+), 28 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 0427fc29b2..80371a2653 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -26,8 +26,10 @@ #include "hw/mem/memory-device.h" #include "migration/blocker.h" #include "migration/qemu-file-types.h" +#include "migration/qemu-file.h" #include "system/dma.h" #include "trace.h" +#include =20 /* enabled until disconnected backend stabilizes */ #define _VHOST_DEBUG 1 @@ -1321,6 +1323,8 @@ out: return ret; } =20 +static void vhost_virtqueue_error_notifier(EventNotifier *n); + int vhost_virtqueue_start(struct vhost_dev *dev, struct VirtIODevice *vdev, struct vhost_virtqueue *vq, @@ -1346,7 +1350,17 @@ int vhost_virtqueue_start(struct vhost_dev *dev, return r; } =20 - vq->num =3D state.num =3D virtio_queue_get_num(vdev, idx); + vq->num =3D virtio_queue_get_num(vdev, idx); + + if (dev->migrating_backend) { + if (dev->vhost_ops->vhost_set_vring_err) { + event_notifier_set_handler(&vq->error_notifier, + vhost_virtqueue_error_notifier); + } + return 0; + } + + state.num =3D vq->num; r =3D dev->vhost_ops->vhost_set_vring_num(dev, &state); if (r) { VHOST_OPS_DEBUG(r, "vhost_set_vring_num failed"); @@ -1424,6 +1438,10 @@ static int do_vhost_virtqueue_stop(struct vhost_dev = *dev, =20 trace_vhost_virtque_stop(vdev->name, idx); =20 + if (dev->migrating_backend) { + return 0; + } + if (virtio_queue_get_desc_addr(vdev, idx) =3D=3D 0) { /* Don't stop the virtqueue which might have not been started */ return 0; @@ -1514,7 +1532,15 @@ static int vhost_virtqueue_init(struct vhost_dev *de= v, struct vhost_vring_file file =3D { .index =3D vhost_vq_index, }; - int r =3D event_notifier_init(&vq->masked_notifier, 0); + int r; + + vq->dev =3D dev; + + if (dev->migrating_backend) { + return 0; + } + + r =3D event_notifier_init(&vq->masked_notifier, 0); if (r < 0) { return r; } @@ -1526,8 +1552,6 @@ static int vhost_virtqueue_init(struct vhost_dev *dev, goto fail_call; } =20 - vq->dev =3D dev; - if (dev->vhost_ops->vhost_set_vring_err) { r =3D event_notifier_init(&vq->error_notifier, 0); if (r < 0) { @@ -1564,10 +1588,14 @@ fail_call: =20 static void vhost_virtqueue_cleanup(struct vhost_virtqueue *vq) { - event_notifier_cleanup(&vq->masked_notifier); + if (!vq->dev->migrating_backend) { + event_notifier_cleanup(&vq->masked_notifier); + } if (vq->dev->vhost_ops->vhost_set_vring_err) { event_notifier_set_handler(&vq->error_notifier, NULL); - event_notifier_cleanup(&vq->error_notifier); + if (!vq->dev->migrating_backend) { + event_notifier_cleanup(&vq->error_notifier); + } } } =20 @@ -1624,21 +1652,30 @@ int vhost_dev_init(struct vhost_dev *hdev, void *op= aque, r =3D vhost_set_backend_type(hdev, backend_type); assert(r >=3D 0); =20 - r =3D hdev->vhost_ops->vhost_backend_init(hdev, opaque, errp); - if (r < 0) { - goto fail; + if (hdev->migrating_backend) { + /* backend must support detached state */ + assert(hdev->vhost_ops->vhost_save_backend); + assert(hdev->vhost_ops->vhost_load_backend); + hdev->_features_wait_incoming =3D true; } =20 - r =3D hdev->vhost_ops->vhost_set_owner(hdev); + r =3D hdev->vhost_ops->vhost_backend_init(hdev, opaque, errp); if (r < 0) { - error_setg_errno(errp, -r, "vhost_set_owner failed"); goto fail; } =20 - r =3D hdev->vhost_ops->vhost_get_features(hdev, &hdev->_features); - if (r < 0) { - error_setg_errno(errp, -r, "vhost_get_features failed"); - goto fail; + if (!hdev->migrating_backend) { + r =3D hdev->vhost_ops->vhost_set_owner(hdev); + if (r < 0) { + error_setg_errno(errp, -r, "vhost_set_owner failed"); + goto fail; + } + + r =3D hdev->vhost_ops->vhost_get_features(hdev, &hdev->_features); + if (r < 0) { + error_setg_errno(errp, -r, "vhost_get_features failed"); + goto fail; + } } =20 for (i =3D 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { @@ -1670,7 +1707,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, .region_del =3D vhost_iommu_region_del, }; =20 - if (hdev->migration_blocker =3D=3D NULL) { + if (!hdev->migrating_backend && hdev->migration_blocker =3D=3D NULL) { if (!vhost_dev_has_feature(hdev, VHOST_F_LOG_ALL)) { error_setg(&hdev->migration_blocker, "Migration disabled: vhost lacks VHOST_F_LOG_ALL fe= ature."); @@ -1697,7 +1734,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, memory_listener_register(&hdev->memory_listener, &address_space_memory= ); QLIST_INSERT_HEAD(&vhost_devices, hdev, entry); =20 - if (!check_memslots(hdev, errp)) { + if (!hdev->migrating_backend && !check_memslots(hdev, errp)) { r =3D -EINVAL; goto fail; } @@ -1765,8 +1802,11 @@ void vhost_dev_disable_notifiers_nvqs(struct vhost_d= ev *hdev, */ memory_region_transaction_commit(); =20 - for (i =3D 0; i < nvqs; ++i) { - virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index = + i); + if (!hdev->migrating_backend) { + for (i =3D 0; i < nvqs; ++i) { + virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), + hdev->vq_index + i); + } } virtio_device_release_ioeventfd(vdev); } @@ -1920,6 +1960,12 @@ uint64_t vhost_get_features(struct vhost_dev *hdev, = const int *feature_bits, uint64_t features) { const int *bit =3D feature_bits; + + if (hdev->_features_wait_incoming) { + /* Excessive set is enough for early initialization. */ + return features; + } + while (*bit !=3D VHOST_INVALID_FEATURE_BIT) { uint64_t bit_mask =3D (1ULL << *bit); if (!vhost_dev_has_feature(hdev, *bit)) { @@ -1930,6 +1976,66 @@ uint64_t vhost_get_features(struct vhost_dev *hdev, = const int *feature_bits, return features; } =20 +void vhost_save_backend(struct vhost_dev *hdev, QEMUFile *f) +{ + int i; + + assert(hdev->migrating_backend); + + if (hdev->vhost_ops->vhost_save_backend) { + hdev->vhost_ops->vhost_save_backend(hdev, f); + } + + qemu_put_be64(f, hdev->_features); + qemu_put_be64(f, hdev->max_queues); + qemu_put_be64(f, hdev->nvqs); + + for (i =3D 0; i < hdev->nvqs; i++) { + qemu_file_put_fd(f, + event_notifier_get_fd(&hdev->vqs[i].error_notifie= r)); + qemu_file_put_fd(f, + event_notifier_get_fd(&hdev->vqs[i].masked_notifi= er)); + } +} + +int vhost_load_backend(struct vhost_dev *hdev, QEMUFile *f) +{ + int i; + Error *err =3D NULL; + uint64_t nvqs; + + assert(hdev->migrating_backend); + + if (hdev->vhost_ops->vhost_load_backend) { + hdev->vhost_ops->vhost_load_backend(hdev, f); + } + + qemu_get_be64s(f, &hdev->_features); + qemu_get_be64s(f, &hdev->max_queues); + qemu_get_be64s(f, &nvqs); + + if (nvqs !=3D hdev->nvqs) { + error_report("%s: number of virt queues mismatch", __func__); + return -EINVAL; + } + + for (i =3D 0; i < hdev->nvqs; i++) { + event_notifier_init_fd(&hdev->vqs[i].error_notifier, + qemu_file_get_fd(f)); + event_notifier_init_fd(&hdev->vqs[i].masked_notifier, + qemu_file_get_fd(f)); + } + + if (!check_memslots(hdev, &err)) { + error_report_err(err); + return -EINVAL; + } + + hdev->_features_wait_incoming =3D false; + + return 0; +} + void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits, uint64_t features) { @@ -2075,19 +2181,24 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIOD= evice *vdev, bool vrings) hdev->started =3D true; hdev->vdev =3D vdev; =20 - r =3D vhost_dev_set_features(hdev, hdev->log_enabled); - if (r < 0) { - goto fail_features; + if (!hdev->migrating_backend) { + r =3D vhost_dev_set_features(hdev, hdev->log_enabled); + if (r < 0) { + warn_report("%s %d", __func__, __LINE__); + goto fail_features; + } } =20 if (vhost_dev_has_iommu(hdev)) { memory_listener_register(&hdev->iommu_listener, vdev->dma_as); } =20 - r =3D hdev->vhost_ops->vhost_set_mem_table(hdev, hdev->mem); - if (r < 0) { - VHOST_OPS_DEBUG(r, "vhost_set_mem_table failed"); - goto fail_mem; + if (!hdev->migrating_backend) { + r =3D hdev->vhost_ops->vhost_set_mem_table(hdev, hdev->mem); + if (r < 0) { + VHOST_OPS_DEBUG(r, "vhost_set_mem_table failed"); + goto fail_mem; + } } for (i =3D 0; i < hdev->nvqs; ++i) { r =3D vhost_virtqueue_start(hdev, @@ -2127,7 +2238,7 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODev= ice *vdev, bool vrings) } vhost_dev_elect_mem_logger(hdev, true); } - if (vrings) { + if (vrings && !hdev->migrating_backend) { r =3D vhost_dev_set_vring_enable(hdev, true); if (r) { goto fail_log; @@ -2155,6 +2266,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODev= ice *vdev, bool vrings) } vhost_start_config_intr(hdev); =20 + hdev->migrating_backend =3D false; + trace_vhost_dev_start_finish(vdev->name); return 0; fail_iotlb: @@ -2204,14 +2317,29 @@ 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 + if (hdev->migrating_backend) { + /* backend must support detached state */ + assert(hdev->vhost_ops->vhost_save_backend); + assert(hdev->vhost_ops->vhost_load_backend); + } + trace_vhost_dev_stop(hdev, vdev->name, vrings); =20 if (hdev->vhost_ops->vhost_dev_start) { hdev->vhost_ops->vhost_dev_start(hdev, false); } - if (vrings) { + if (vrings && !hdev->migrating_backend) { vhost_dev_set_vring_enable(hdev, false); } + + if (hdev->migrating_backend) { + for (i =3D 0; i < hdev->nvqs; ++i) { + struct vhost_virtqueue *vq =3D hdev->vqs + i; + + event_notifier_set_handler(&vq->error_notifier, NULL); + } + } + for (i =3D 0; i < hdev->nvqs; ++i) { rc |=3D do_vhost_virtqueue_stop(hdev, vdev, diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index 0785fc764d..66627c6a56 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -163,6 +163,9 @@ typedef int (*vhost_set_device_state_fd_op)(struct vhos= t_dev *dev, typedef int (*vhost_check_device_state_op)(struct vhost_dev *dev, Error **= errp); typedef void (*vhost_qmp_status_op)(struct vhost_dev *dev, VhostStatus *st= atus); =20 +typedef void (*vhost_detached_save_op)(struct vhost_dev *dev, QEMUFile *f); +typedef int (*vhost_detached_load_op)(struct vhost_dev *dev, QEMUFile *f); + typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -219,6 +222,8 @@ typedef struct VhostOps { vhost_set_device_state_fd_op vhost_set_device_state_fd; vhost_check_device_state_op vhost_check_device_state; vhost_qmp_status_op vhost_qmp_status; + vhost_detached_save_op vhost_save_backend; + vhost_detached_load_op vhost_load_backend; } VhostOps; =20 int vhost_backend_update_device_iotlb(struct vhost_dev *dev, diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 8a4c8c3502..330374aca2 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -103,6 +103,10 @@ struct vhost_dev { * @acked_features: final negotiated features with front-end driver */ uint64_t _features; + bool _features_wait_incoming; + + bool migrating_backend; + uint64_t acked_features; =20 uint64_t max_queues; @@ -318,6 +322,8 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtI= ODevice *vdev, int n, */ uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bit= s, uint64_t features); +void vhost_save_backend(struct vhost_dev *hdev, QEMUFile *f); +int vhost_load_backend(struct vhost_dev *hdev, QEMUFile *f); =20 /** * vhost_ack_features() - set vhost acked_features --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755103953; cv=none; d=zohomail.com; s=zohoarc; b=CeEyMr1zNVOe51DuGxDwpYaUyCSxPFMKKtgoIRr4tKPBza4yO4ZgltF0Wr07Vx4XBuCNHimjbHClUCm9RXkB5MYpigFsFRnqAgNSQdt/uRtf8Z7uswScVONXQ6liXK2DYNbJi2bOkqtQAIPIg6xUfzOES7tACfgF8SDy5pyg7mk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103953; 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=ZqwjUtz1Fm9Op2W/FGi59SOWO4q8FsJ64eme844Jh7E=; b=KTWM+4IbiQ9MrYjBqpVDgbtkgGAkS6CLUypx3yI/FcZiuu8IVtjNGfA6amojE06kIAoo/Vo50mEjtGA1/u1k/xDyWrGzxtXbC57+f6q1gCbOK48jeMYGShupW283+6qSeqrGnISSapV+1P6lrDHRQ9+InUbCgKpXmm0d0hRKdjQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755103953823625.4345943621115; Wed, 13 Aug 2025 09:52:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEgG-0003CD-Gs; Wed, 13 Aug 2025 12:50:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfz-00031K-27; Wed, 13 Aug 2025 12:50: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 1umEfl-0007tO-IU; Wed, 13 Aug 2025 12:50:09 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 1D1CE813B7; Wed, 13 Aug 2025 19:49:26 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-BXvnPBfe; Wed, 13 Aug 2025 19:49:25 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103765; bh=ZqwjUtz1Fm9Op2W/FGi59SOWO4q8FsJ64eme844Jh7E=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=iKOCjq5xNP9AhG9fGwVtNMYgeMqZI/YCNto3h869woiD77SVF15WewCnJTJtQ8K/H PgtqjwkEFMzUAPQ7VQ+Lz2b0+vHZ2kbkvTEWR6XNtXfbKLJGOHwXRfvzRhP/JllkVM Jxd4UCUreczclxkmENtZrgHKxdghc39OIrcPht5I= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 29/33] vhost-user: support backend migration Date: Wed, 13 Aug 2025 19:48:50 +0300 Message-ID: <20250813164856.950363-30-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755103956270124100 Content-Type: text/plain; charset="utf-8" In case of local backend migration, skip backend-related initialization, but instead get the state from migration channel (including secondary channel file descriptor). Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/virtio/vhost-user.c | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 3979582975..f220af270e 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -28,6 +28,8 @@ #include "system/runstate.h" #include "system/cryptodev.h" #include "migration/postcopy-ram.h" +#include "migration/qemu-file-types.h" +#include "migration/qemu-file.h" #include "trace.h" #include "system/ramblock.h" =20 @@ -2273,6 +2275,10 @@ static int vhost_user_backend_init(struct vhost_dev = *dev, void *opaque, u->dev =3D dev; dev->opaque =3D u; =20 + if (dev->migrating_backend) { + goto out; + } + err =3D vhost_user_get_features(dev, &features); if (err < 0) { error_setg_errno(errp, -err, "vhost_backend_init failed"); @@ -2387,6 +2393,7 @@ static int vhost_user_backend_init(struct vhost_dev *= dev, void *opaque, } } =20 +out: u->postcopy_notifier.notify =3D vhost_user_postcopy_notifier; postcopy_add_notifier(&u->postcopy_notifier); =20 @@ -2936,6 +2943,10 @@ void vhost_user_async_close(DeviceState *d, =20 static int vhost_user_dev_start(struct vhost_dev *dev, bool started) { + if (dev->migrating_backend) { + return 0; + } + if (!vhost_user_has_prot(dev, VHOST_USER_PROTOCOL_F_STATUS)) { return 0; } @@ -3105,6 +3116,55 @@ static void vhost_user_qmp_status(struct vhost_dev *= dev, VhostStatus *status) status->protocol_features =3D qmp_decode_protocols(u->protocol_feature= s); } =20 +static void vhost_user_save(struct vhost_dev *dev, QEMUFile *f) +{ + struct vhost_user *u =3D dev->opaque; + bool has_backend_channel =3D !!u->backend_sioc; + qemu_put_be64(f, u->protocol_features); + qemu_put_be32(f, u->user->memory_slots); + + qemu_put_byte(f, has_backend_channel); + if (u->backend_sioc) { + qemu_file_put_fd(f, u->backend_sioc->fd); + } +} + +static int vhost_user_load(struct vhost_dev *dev, QEMUFile *f) +{ + struct vhost_user *u =3D dev->opaque; + uint8_t has_backend_channel; + uint32_t memory_slots; + + qemu_get_be64s(f, &u->protocol_features); + qemu_get_be32s(f, &memory_slots); + qemu_get_8s(f, &has_backend_channel); + + u->user->memory_slots =3D memory_slots; + + if (has_backend_channel) { + int fd =3D qemu_file_get_fd(f); + Error *local_err =3D NULL; + + u->backend_sioc =3D qio_channel_socket_new_fd(fd, &local_err); + if (!u->backend_sioc) { + error_report_err(local_err); + return -ECONNREFUSED; + } + 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); + } + + if (dev->migration_blocker =3D=3D NULL && + !vhost_user_has_prot(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."); + } + + return 0; +} + const VhostOps user_ops =3D { .backend_type =3D VHOST_BACKEND_TYPE_USER, .vhost_backend_init =3D vhost_user_backend_init, @@ -3146,4 +3206,6 @@ const VhostOps user_ops =3D { .vhost_set_device_state_fd =3D vhost_user_set_device_state_fd, .vhost_check_device_state =3D vhost_user_check_device_state, .vhost_qmp_status =3D vhost_user_qmp_status, + .vhost_save_backend =3D vhost_user_save, + .vhost_load_backend =3D vhost_user_load, }; --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104106; cv=none; d=zohomail.com; s=zohoarc; b=nNuKQ0JQZxuDH5Gqq67m/I8FWk6Xng6Fa4cdSGk2/8i19r0ynZ6R5Aw5Kc8LYQIkRgLjsPbNBdeX5QyF8Am5xTtWhFgvEiK2BYSu5BjFf+v0Mt1pgGYlC2AWDA2uVlDU4Hbi4lbdo4Gh0KxC3idKukVlrbTO81mbrkoBwNNl5xA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104106; 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=CfSnNSlxRpA2aJcGzzhON1DJQHG5UHMfQuoe5LBYTDw=; b=jkOfSHFmkXCxAOjm1rKi0x/VC6EFZDVm+CuaQboxhBFRbD7MAew+q1HcoR/kFyDScAI3CfEO6IpqnEVXvPuHyLfYbkl1+SxGXJsoWlWKILW2wXtOSLvMpSlBse82IsrTdgvH3gEIP6EoFTypQXL3jzjCwVTab0DGX+mZTsyMmLk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104106646925.8185053238453; Wed, 13 Aug 2025 09:55:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEgY-0003Lp-0m; Wed, 13 Aug 2025 12:50:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEg1-000345-90; Wed, 13 Aug 2025 12:50: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 1umEfp-0007tv-PX; Wed, 13 Aug 2025 12:50:11 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id DC96381304; Wed, 13 Aug 2025 19:49:26 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-0i988P68; Wed, 13 Aug 2025 19:49:26 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103766; bh=CfSnNSlxRpA2aJcGzzhON1DJQHG5UHMfQuoe5LBYTDw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=VOMtBMSTuo8/z0FgWvMdYjiFSW0nadwyp3Un89099B+eYa1CPE8vJQ3Ouw7pHUHwG 2s8uohLkyYvWmmquagElzuXQ0n602luuExLsyfITu5TWCuDLgQcWAOSKBqbQTcwtfp Yin2me2cMDByChTf4Fh15Iiup3vQAOkqSYbgOlU8= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 30/33] virtio: support vhost backend migration Date: Wed, 13 Aug 2025 19:48:51 +0300 Message-ID: <20250813164856.950363-31-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104108387116601 Content-Type: text/plain; charset="utf-8" Add logic to transfer virtio notifiers through migration channel for vhost backend migration case. Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/virtio/virtio-bus.c | 2 +- hw/virtio/virtio.c | 74 ++++++++++++++++++++++++++++++++++++-- include/hw/virtio/virtio.h | 2 ++ 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index c7e3941b1e..c1848144a2 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -286,7 +286,7 @@ int virtio_bus_set_host_notifier(VirtioBusState *bus, i= nt n, bool assign) return -ENOSYS; } =20 - if (assign) { + if (assign && !virtio_is_vhost_migrating_backend(vdev)) { r =3D event_notifier_init(notifier, 1); if (r < 0) { error_report("%s: unable to init event notifier: %s (%d)", diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 10891f0e0c..87c243edad 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -26,6 +26,7 @@ #include "hw/virtio/virtio.h" #include "hw/virtio/vhost.h" #include "migration/qemu-file-types.h" +#include "migration/qemu-file.h" #include "qemu/atomic.h" #include "hw/virtio/virtio-bus.h" #include "hw/qdev-properties.h" @@ -2992,6 +2993,7 @@ int virtio_save(VirtIODevice *vdev, QEMUFile *f) VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); uint32_t guest_features_lo =3D (vdev->guest_features & 0xffffffff); int i; + bool migrating_backend =3D virtio_is_vhost_migrating_backend(vdev); =20 if (k->save_config) { k->save_config(qbus->parent, f); @@ -3025,11 +3027,23 @@ int virtio_save(VirtIODevice *vdev, QEMUFile *f) */ qemu_put_be64(f, vdev->vq[i].vring.desc); qemu_put_be16s(f, &vdev->vq[i].last_avail_idx); + + if (migrating_backend) { + qemu_file_put_fd(f, + event_notifier_get_fd(&vdev->vq[i].host_notif= ier)); + qemu_file_put_fd( + f, event_notifier_get_fd(&vdev->vq[i].guest_notifier)); + } + if (k->save_queue) { k->save_queue(qbus->parent, i, f); } } =20 + if (migrating_backend) { + qemu_file_put_fd(f, event_notifier_get_fd(&vdev->config_notifier)); + } + if (vdc->save !=3D NULL) { vdc->save(vdev, f); } @@ -3235,6 +3249,8 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int vers= ion_id) BusState *qbus =3D qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); + Error *local_err =3D NULL; + bool migrating_backend =3D virtio_is_vhost_migrating_backend(vdev); =20 /* * We poison the endianness to ensure it does not get used before @@ -3304,6 +3320,13 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int ver= sion_id) vdev->vq[i].signalled_used_valid =3D false; vdev->vq[i].notification =3D true; =20 + if (migrating_backend) { + event_notifier_init_fd(&vdev->vq[i].host_notifier, + qemu_file_get_fd(f)); + event_notifier_init_fd(&vdev->vq[i].guest_notifier, + qemu_file_get_fd(f)); + } + if (!vdev->vq[i].vring.desc && vdev->vq[i].last_avail_idx) { error_report("VQ %d address 0x0 " "inconsistent with Host index 0x%x", @@ -3317,6 +3340,10 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int ver= sion_id) } } =20 + if (migrating_backend) { + event_notifier_init_fd(&vdev->config_notifier , qemu_file_get_fd= (f)); + } + virtio_notify_vector(vdev, VIRTIO_NO_VECTOR); =20 if (vdc->load !=3D NULL) { @@ -3333,6 +3360,19 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int ver= sion_id) } } =20 + if (migrating_backend) { + /* + * On vhost backend migration, device do load host_features from + * migration stream. So update host_features. + */ + vdev->host_features =3D vdc->get_features(vdev, vdev->host_feature= s, + &local_err); + if (local_err) { + error_report_err(local_err); + return -EINVAL; + } + } + /* Subsections */ ret =3D vmstate_load_state(f, &vmstate_virtio, vdev, 1); if (ret) { @@ -3394,6 +3434,18 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int ver= sion_id) continue; } =20 + if (migrating_backend) { + /* + * Indices are not synced prior backend migration (as we d= on't + * stop vrings by GET_VRING_BASE). No reason to sync them = now, + * and do any checks. + */ + vdev->vq[i].used_idx =3D 0; + vdev->vq[i].shadow_avail_idx =3D 0; + vdev->vq[i].inuse =3D 0; + continue; + } + nheads =3D vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_av= ail_idx; /* Check it isn't doing strange things with descriptor numbers= . */ if (nheads > vdev->vq[i].vring.num) { @@ -3762,8 +3814,9 @@ int virtio_queue_set_guest_notifier(VirtIODevice *vde= v, int n, bool assign, EventNotifierHandler *read_fn =3D is_config ? virtio_config_guest_notifier_read : virtio_queue_guest_notifier_read; + bool migrating_backend =3D virtio_is_vhost_migrating_backend(vdev); =20 - if (assign) { + if (assign && !migrating_backend) { int r =3D event_notifier_init(notifier, 0); if (r < 0) { return r; @@ -3773,7 +3826,7 @@ int virtio_queue_set_guest_notifier(VirtIODevice *vde= v, int n, bool assign, event_notifier_set_handler(notifier, (assign && !with_irqfd) ? read_fn : NULL); =20 - if (!assign) { + if (!assign && !migrating_backend) { /* Test and clear notifier before closing it,*/ /* in case poll callback didn't have time to run. */ read_fn(notifier); @@ -4392,6 +4445,23 @@ done: return element; } =20 +bool virtio_is_vhost_migrating_backend(VirtIODevice *vdev) +{ + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); + struct vhost_dev *hdev; + + if (!vdc->get_vhost) { + return false; + } + + hdev =3D vdc->get_vhost(vdev); + if (!hdev) { + return false; + } + + return hdev->migrating_backend; +} + static const TypeInfo virtio_device_info =3D { .name =3D TYPE_VIRTIO_DEVICE, .parent =3D TYPE_DEVICE, diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 9a4a0a94aa..f94a7e5895 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -238,6 +238,8 @@ struct VirtioDeviceClass { bool (*skip_vhost_migration_log)(VirtIODevice *vdev); }; =20 +bool virtio_is_vhost_migrating_backend(VirtIODevice *vdev); + void virtio_instance_init_common(Object *proxy_obj, void *data, size_t vdev_size, const char *vdev_name); =20 --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755103890; cv=none; d=zohomail.com; s=zohoarc; b=kpqguS8NSY9MDPAp1+0yOzShuq5pGNRT8F+nbNS7+Be8TBTTBBFDGR2SFp6J+5qMi7hJ+8nhKNv/rfLwmw5uzaWFUXfv4MWBRESNnHtRNO/H0wOEXd4weUydfmCDrKzaBypdtqECkocVuFymo2jTckG88ADI5pI6JRzq3NAGMtU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103890; 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=ySTklhZeyl9879IHDj6pOytJKMMT2EjW0woilwTiBYw=; b=LcFs9+/CyQ0JH7iZD+/HXHteoC6624kufGjVPBfqw918cNCKYcH6jVE8YzhoU8V1iA+H4P/QHqad4hdQbUrosFZiHoivH96QPu49J7/VroXKV4RIR9iIzrJR4vsUMCUvbFsOMK+BdPu2T+JLnKHDnflPgCPhIkW2hN7b8wB5owQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17551038900701012.2832499980879; Wed, 13 Aug 2025 09:51:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEg5-00038p-0y; Wed, 13 Aug 2025 12:50:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfw-00030Y-OM; Wed, 13 Aug 2025 12:50: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 1umEfk-0007tu-Hi; Wed, 13 Aug 2025 12:50:07 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id BD302813EE; Wed, 13 Aug 2025 19:49:27 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-tyTiIsXB; Wed, 13 Aug 2025 19:49:27 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103767; bh=ySTklhZeyl9879IHDj6pOytJKMMT2EjW0woilwTiBYw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=VUWTwCtS6WZ5e6lVny+K3mw/0Dr11WoxdBM0KS3vtRM80sB1mSpcT5Vqacgkbnb8H Dt/vscMqWcgJKsEjnUxvnP+l/FskCQYTcKKND2VrWfSOyM/X0EPp2R6vuI+XUpjlbt fRNwXnbNHPJWRuvtKJIapP6p5+Yd2eTOwWDfoUKs= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 31/33] vhost-user-blk: support vhost backend migration Date: Wed, 13 Aug 2025 19:48:52 +0300 Message-ID: <20250813164856.950363-32-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8: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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755103892656116600 Content-Type: text/plain; charset="utf-8" Opt-out backend initialization code, and instead get the state from migration channel (including inflight region). Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/block/vhost-user-blk.c | 185 +++++++++++++++++++++++------ include/hw/virtio/vhost-user-blk.h | 2 + migration/options.c | 7 ++ migration/options.h | 1 + qapi/migration.json | 15 ++- 5 files changed, 169 insertions(+), 41 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index c8bc2c78e6..2e6ef6477e 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -17,6 +17,7 @@ */ =20 #include "qemu/osdep.h" +#include "qapi-types-run-state.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/cutils.h" @@ -32,6 +33,11 @@ #include "system/system.h" #include "system/runstate.h" #include "trace.h" +#include "migration/qemu-file.h" +#include "migration/migration.h" +#include "migration/options.h" +#include "qemu/event_notifier.h" +#include =20 static const int user_feature_bits[] =3D { VIRTIO_BLK_F_SIZE_MAX, @@ -159,32 +165,35 @@ static int vhost_user_blk_start(VirtIODevice *vdev, E= rror **errp) =20 s->dev.acked_features =3D vdev->guest_features; =20 - ret =3D vhost_dev_prepare_inflight(&s->dev, vdev); - if (ret < 0) { - error_setg_errno(errp, -ret, "Error setting inflight format"); - goto err_guest_notifiers; - } - - if (!s->inflight->addr) { - ret =3D vhost_dev_get_inflight(&s->dev, s->queue_size, s->inflight= ); + if (!s->dev.migrating_backend) { + ret =3D vhost_dev_prepare_inflight(&s->dev, vdev); if (ret < 0) { - error_setg_errno(errp, -ret, "Error getting inflight"); + error_setg_errno(errp, -ret, "Error setting inflight format"); goto err_guest_notifiers; } - } =20 - ret =3D vhost_dev_set_inflight(&s->dev, s->inflight); - if (ret < 0) { - error_setg_errno(errp, -ret, "Error setting inflight"); - goto err_guest_notifiers; - } + if (!s->inflight->addr) { + ret =3D vhost_dev_get_inflight(&s->dev, s->queue_size, s->infl= ight); + if (ret < 0) { + error_setg_errno(errp, -ret, "Error getting inflight"); + goto err_guest_notifiers; + } + } =20 - /* guest_notifier_mask/pending not used yet, so just unmask - * everything here. virtio-pci will do the right thing by - * enabling/disabling irqfd. - */ - for (i =3D 0; i < s->dev.nvqs; i++) { - vhost_virtqueue_mask(&s->dev, vdev, i, false); + ret =3D vhost_dev_set_inflight(&s->dev, s->inflight); + if (ret < 0) { + error_setg_errno(errp, -ret, "Error setting inflight"); + goto err_guest_notifiers; + } + + /* + * guest_notifier_mask/pending not used yet, so just unmask + * everything here. virtio-pci will do the right thing by + * enabling/disabling irqfd. + */ + for (i =3D 0; i < s->dev.nvqs; i++) { + vhost_virtqueue_mask(&s->dev, vdev, i, false); + } } =20 s->dev.vq_index_end =3D s->dev.nvqs; @@ -231,6 +240,10 @@ static int vhost_user_blk_stop(VirtIODevice *vdev) force_stop =3D s->skip_get_vring_base_on_force_shutdown && qemu_force_shutdown_requested(); =20 + s->dev.migrating_backend =3D s->dev.migrating_backend || + (runstate_check(RUN_STATE_FINISH_MIGRATE) && + migrate_local_vhost_user_blk()); + ret =3D force_stop ? vhost_dev_force_stop(&s->dev, vdev, true) : vhost_dev_stop(&s->dev, vdev, true); =20 @@ -343,7 +356,9 @@ static void vhost_user_blk_reset(VirtIODevice *vdev) vhost_dev_free_inflight(s->inflight); } =20 -static int vhost_user_blk_connect(DeviceState *dev, Error **errp) +static int vhost_user_blk_connect(DeviceState *dev, + bool migrating_backend, + Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VHostUserBlk *s =3D VHOST_USER_BLK(vdev); @@ -359,6 +374,7 @@ 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.migrating_backend =3D migrating_backend; =20 vhost_dev_set_config_notifier(&s->dev, &blk_ops); =20 @@ -409,7 +425,7 @@ static void vhost_user_blk_event(void *opaque, QEMUChrE= vent event) =20 switch (event) { case CHR_EVENT_OPENED: - if (vhost_user_blk_connect(dev, &local_err) < 0) { + if (vhost_user_blk_connect(dev, false, &local_err) < 0) { error_report_err(local_err); qemu_chr_fe_disconnect(&s->chardev); return; @@ -428,31 +444,37 @@ static void vhost_user_blk_event(void *opaque, QEMUCh= rEvent event) } } =20 -static int vhost_user_blk_realize_connect(VHostUserBlk *s, Error **errp) +static int vhost_user_blk_realize_connect(VHostUserBlk *s, + bool migrating_backend, + Error **errp) { DeviceState *dev =3D DEVICE(s); int ret; =20 s->connected =3D false; =20 - ret =3D qemu_chr_fe_wait_connected(&s->chardev, errp); - if (ret < 0) { - return ret; + if (!migrating_backend) { + ret =3D qemu_chr_fe_wait_connected(&s->chardev, errp); + if (ret < 0) { + return ret; + } } =20 - ret =3D vhost_user_blk_connect(dev, errp); + ret =3D vhost_user_blk_connect(dev, migrating_backend, errp); if (ret < 0) { qemu_chr_fe_disconnect(&s->chardev); return ret; } assert(s->connected); =20 - ret =3D vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg, - VIRTIO_DEVICE(s)->config_len, errp); - if (ret < 0) { - qemu_chr_fe_disconnect(&s->chardev); - vhost_dev_cleanup(&s->dev); - return ret; + if (!migrating_backend) { + ret =3D vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg, + VIRTIO_DEVICE(s)->config_len, errp); + if (ret < 0) { + qemu_chr_fe_disconnect(&s->chardev); + vhost_dev_cleanup(&s->dev); + return ret; + } } =20 return 0; @@ -469,6 +491,11 @@ static void vhost_user_blk_device_realize(DeviceState = *dev, Error **errp) =20 trace_vhost_user_blk_device_realize(); =20 + if (s->incoming_backend && !runstate_check(RUN_STATE_INMIGRATE)) { + error_setg(errp, "__yc_local-incoming can be used " + "only for incoming migration"); + } + if (!s->chardev.chr) { error_setg(errp, "chardev is mandatory"); return; @@ -517,7 +544,7 @@ static void vhost_user_blk_device_realize(DeviceState *= dev, Error **errp) error_report_err(*errp); *errp =3D NULL; } - ret =3D vhost_user_blk_realize_connect(s, errp); + ret =3D vhost_user_blk_realize_connect(s, s->incoming_backend, err= p); } while (ret < 0 && retries--); =20 if (ret < 0) { @@ -525,9 +552,12 @@ static void vhost_user_blk_device_realize(DeviceState = *dev, Error **errp) } =20 /* we're fully initialized, now we can operate, so add the handler */ - qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, - vhost_user_blk_event, NULL, (void *)dev, - NULL, true); + if (!s->incoming_backend) { + qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, + vhost_user_blk_event, NULL, (void *)dev, + NULL, true); + } + trace_vhost_user_blk_device_realize_finish(); return; =20 @@ -592,6 +622,79 @@ static const VMStateDescription vmstate_vhost_user_blk= =3D { }, }; =20 +static void vhost_user_blk_save(VirtIODevice *vdev, QEMUFile *f) +{ + VHostUserBlk *s =3D VHOST_USER_BLK(vdev); + struct vhost_dev *hdev =3D vhost_user_blk_get_vhost(vdev); + + if (!hdev->migrating_backend) { + return; + } + + qemu_file_put_fd(f, s->inflight->fd); + qemu_put_be64(f, s->inflight->size); + qemu_put_be64(f, s->inflight->offset); + qemu_put_be16(f, s->inflight->queue_size); + + vhost_save_backend(hdev, f); +} + +static int vhost_user_blk_load(VirtIODevice *vdev, QEMUFile *f, + int version_id) +{ + VHostUserBlk *s =3D VHOST_USER_BLK(vdev); + struct vhost_dev *hdev =3D vhost_user_blk_get_vhost(vdev); + + if (!hdev->migrating_backend) { + return 0; + } + + s->inflight->fd =3D qemu_file_get_fd(f); + qemu_get_be64s(f, &s->inflight->size); + qemu_get_be64s(f, &s->inflight->offset); + qemu_get_be16s(f, &s->inflight->queue_size); + + s->inflight->addr =3D mmap(0, s->inflight->size, PROT_READ | PROT_WRIT= E, + MAP_SHARED, s->inflight->fd, s->inflight->off= set); + if (s->inflight->addr =3D=3D MAP_FAILED) { + return -EINVAL; + } + + vhost_load_backend(hdev, f); + + return 0; +} + +static int vhost_user_blk_post_load(VirtIODevice *vdev) +{ + VHostUserBlk *s =3D VHOST_USER_BLK(vdev); + struct vhost_dev *hdev =3D vhost_user_blk_get_vhost(vdev); + DeviceState *dev =3D &s->parent_obj.parent_obj; + + if (!hdev->migrating_backend) { + return 0; + } + + memcpy(&s->blkcfg, vdev->config, vdev->config_len); + + /* we're fully initialized, now we can operate, so add the handler */ + qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, + vhost_user_blk_event, NULL, (void *)dev, + NULL, true); + + return 0; +} + +static bool vhost_user_blk_skip_migration_log(VirtIODevice *vdev) +{ + /* + * Note that hdev->migrating_backend is false at this moment, + * as logging is being setup during outging migration setup stage, + * which is far before vm stop. + */ + return migrate_local_vhost_user_blk(); +} + static const Property vhost_user_blk_properties[] =3D { DEFINE_PROP_CHR("chardev", VHostUserBlk, chardev), DEFINE_PROP_UINT16("num-queues", VHostUserBlk, num_queues, @@ -605,6 +708,8 @@ static const Property vhost_user_blk_properties[] =3D { VIRTIO_BLK_F_WRITE_ZEROES, true), DEFINE_PROP_BOOL("skip-get-vring-base-on-force-shutdown", VHostUserBlk, skip_get_vring_base_on_force_shutdown, false), + DEFINE_PROP_BOOL("local-incoming", VHostUserBlk, + incoming_backend, false), }; =20 static void vhost_user_blk_class_init(ObjectClass *klass, const void *data) @@ -624,6 +729,10 @@ static void vhost_user_blk_class_init(ObjectClass *kla= ss, const void *data) vdc->set_status =3D vhost_user_blk_set_status; vdc->reset =3D vhost_user_blk_reset; vdc->get_vhost =3D vhost_user_blk_get_vhost; + vdc->save =3D vhost_user_blk_save; + vdc->load =3D vhost_user_blk_load; + vdc->post_load =3D vhost_user_blk_post_load, + vdc->skip_vhost_migration_log =3D vhost_user_blk_skip_migration_log; } =20 static const TypeInfo vhost_user_blk_info =3D { diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-u= ser-blk.h index a10f785672..b06f55fd6f 100644 --- a/include/hw/virtio/vhost-user-blk.h +++ b/include/hw/virtio/vhost-user-blk.h @@ -52,6 +52,8 @@ struct VHostUserBlk { bool started_vu; =20 bool skip_get_vring_base_on_force_shutdown; + + bool incoming_backend; }; =20 #endif diff --git a/migration/options.c b/migration/options.c index dffb6910f4..11b719c81b 100644 --- a/migration/options.c +++ b/migration/options.c @@ -269,6 +269,13 @@ bool migrate_local_char_socket(void) return s->capabilities[MIGRATION_CAPABILITY_LOCAL_CHAR_SOCKET]; } =20 +bool migrate_local_vhost_user_blk(void) +{ + MigrationState *s =3D migrate_get_current(); + + return s->capabilities[MIGRATION_CAPABILITY_LOCAL_VHOST_USER_BLK]; +} + bool migrate_ignore_shared(void) { MigrationState *s =3D migrate_get_current(); diff --git a/migration/options.h b/migration/options.h index 40971f0aa0..5a40ac073d 100644 --- a/migration/options.h +++ b/migration/options.h @@ -31,6 +31,7 @@ bool migrate_dirty_bitmaps(void); bool migrate_events(void); bool migrate_mapped_ram(void); bool migrate_local_char_socket(void); +bool migrate_local_vhost_user_blk(void); bool migrate_ignore_shared(void); bool migrate_late_block_activate(void); bool migrate_multifd(void); diff --git a/qapi/migration.json b/qapi/migration.json index 4f282d168e..ead7f4d17c 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -520,11 +520,19 @@ # @local-char-socket: Migrate socket chardevs open file descriptors. # Only may be used when migration channel is unix socket. Only # involves socket chardevs with "support-local-migration" option -# enabled. (since 10.2) +# enabled. For target device also @local-incoming option must +# be specified (since 10.2) +# +# @local-vhost-user-blk: Migrate vhost-user-blk locally, keeping +# backend alive. Open file descriptors and backend-related state are +# migrated. Only may be used when migration channel is unix socket. +# For target device also @local-incoming option must be specified +# (since 10.2) # # Features: # -# @unstable: Members @x-colo and @x-ignore-shared are experimental. +# @unstable: Members @x-colo, @x-ignore-shared, @local-char-socket, +# @local-vhost-user-blk are experimental. # @deprecated: Member @zero-blocks is deprecated as being part of # block migration which was already removed. # @@ -542,7 +550,8 @@ 'validate-uuid', 'background-snapshot', 'zero-copy-send', 'postcopy-preempt', 'switchover-ack', 'dirty-limit', 'mapped-ram', - { 'name': 'local-char-socket', 'features': [ 'unstable' ] } ] } + { 'name': 'local-char-socket', 'features': [ 'unstable' ] }, + { 'name': 'local-vhost-user-blk', 'features': [ 'unstable' ] } = ] } =20 ## # @MigrationCapabilityStatus: --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755104367; cv=none; d=zohomail.com; s=zohoarc; b=HkGGJGnkecfuu6OzQSK2fYIdAi6e2eHnls9yNT7MVcUMwiagie6cYWL9McHWWAAjBMjtFBLXmEZVRy/XsOV4FxPYGXxBaprpoxMANw3iJM8M7zKVNnBoTMY0rSmFrvtamkPFSqR408FiQZN21zpWiVJQSiG3rCuINQ/+OmAhTE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755104367; 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=zJFu12zPBlLHK7aaPdEnk7oOh6ebD/pkKyyR76Vwrf0=; b=F/KLB66H4Gby8iORXgVueWlilX0AlE0PI/Hdc/otCfUG9WPEm1D1mGkvsxbg3qwF0vx69+umCE0abMcfzlfuXf/yKR6vSf5OcnzDXKWDf2hfDwdMri+fOdbLYBSRtRgLXzgWSsj+eLdmIM4LDedzI+1YiVB08008StIo1bzh3Zg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755104367601610.0814000039268; Wed, 13 Aug 2025 09:59:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEgZ-0003NZ-Mr; Wed, 13 Aug 2025 12:50:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEg3-000377-3L; Wed, 13 Aug 2025 12:50:15 -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 1umEfn-0007u2-JA; Wed, 13 Aug 2025 12:50:13 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 7DC8380763; Wed, 13 Aug 2025 19:49:28 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-yT9KB8Db; Wed, 13 Aug 2025 19:49:28 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103768; bh=zJFu12zPBlLHK7aaPdEnk7oOh6ebD/pkKyyR76Vwrf0=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Gp9tuWKMtTYk6yeo1E1qqBEFGUeYvH/m5q9hdI3AbUdPZ1vSHauIh4hdNKnm6Ql8I JKkUK87Rykk1cMgiuz56o3a5UVl31J0T5Al7r8m2fUN9bBmygAIxHxJghRgB3xiBHs QD3Pk5glo/PH2A1cUq50LMsj6mTEALzf2/+YIpdo= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru, Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 32/33] test/functional: exec_command_and_wait_for_pattern: add vm arg Date: Wed, 13 Aug 2025 19:48:53 +0300 Message-ID: <20250813164856.950363-33-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8: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_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755104369410124100 Content-Type: text/plain; charset="utf-8" Allow to specify non default vm for the command. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Thomas Huth --- tests/functional/qemu_test/cmd.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/functional/qemu_test/cmd.py b/tests/functional/qemu_test= /cmd.py index dc5f422b77..28b36a3a54 100644 --- a/tests/functional/qemu_test/cmd.py +++ b/tests/functional/qemu_test/cmd.py @@ -172,7 +172,8 @@ def exec_command(test, command): _console_interaction(test, None, None, command + '\r') =20 def exec_command_and_wait_for_pattern(test, command, - success_message, failure_message=3DN= one): + success_message, failure_message=3DN= one, + vm=3DNone): """ Send a command to a console (appending CRLF characters), then wait for success_message to appear on the console, while logging the. @@ -184,9 +185,11 @@ def exec_command_and_wait_for_pattern(test, command, :param command: the command to send :param success_message: if this message appears, test succeeds :param failure_message: if this message appears, test fails + :param vm: the VM to use (defaults to test.vm if None) """ assert success_message - _console_interaction(test, success_message, failure_message, command += '\r') + _console_interaction(test, success_message, failure_message, command += '\r', + vm=3Dvm) =20 def get_qemu_img(test): test.log.debug('Looking for and selecting a qemu-img binary') --=20 2.48.1 From nobody Sat Nov 15 05:35:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1755103986; cv=none; d=zohomail.com; s=zohoarc; b=DcsgXxPAwTYW9lPrlq7u8ZwPvY76945FwcmRSEJWqhIax9RVZrhxMZDiU28guHe4ARxbB5TFopRahjAkbDGn/JyYiS8Ynwxu8VOsT0qmxAmRiNmId/95d/tboz/yDJAus1UTj6IsuGS2FV4uCg3+gMer845jH8ZmG5OYUsha55k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103986; 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=MVoLubdqzGcXSWvpEh3P9dHap5qN9edhnyELjiDiIEM=; b=nw2XrNt9fjYsSKPP+soxtZqj4Wx3Dh0pLpoCjJGAcHDFPm58qp7FEpo93Z7pTiXAwfTX9ov3HHH+ENjPx+WgPLoFQqstT8d2HA/2Xc3NyQRjlfsP/3dh3Tx4dN4jPnSgGEYaBBVlfXaHisDFdDBuj4JGG6QKBIMEJapfEjh2JSY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755103986610846.4280163226886; Wed, 13 Aug 2025 09:53:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEgd-0003VG-Rz; Wed, 13 Aug 2025 12:50:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1umEfx-000316-KJ; Wed, 13 Aug 2025 12:50:09 -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 1umEfm-0007u1-Ox; Wed, 13 Aug 2025 12:50:09 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id B74EE81403; Wed, 13 Aug 2025 19:49:29 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-lo4XRzL4; Wed, 13 Aug 2025 19:49:28 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103769; bh=MVoLubdqzGcXSWvpEh3P9dHap5qN9edhnyELjiDiIEM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=OwZLqwjTxqocR9E+ycF9qw1fU/pHgSsIS6/AVK77TT++Nm4/P5sBXhCAhrIc2uVEs +NCNwdP39H+AySl5gNl+k7F15yc9/GpT32H/fe2TvV+2rD4wnApKlSJbSN/uhYkqWd R0A6O4AI5vt2Zk/KyFiPzXQqq/cwokVTOonuMbl4= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 33/33] tests/functional: add test_x86_64_vhost_user_blk_fd_migration.py Date: Wed, 13 Aug 2025 19:48:54 +0300 Message-ID: <20250813164856.950363-34-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1755103988684124100 Content-Type: text/plain; charset="utf-8" Introduce a simple test to check that local migration of vhost-user-blk device with passing open fds through unix socket works, and the disk is still working on target. Signed-off-by: Vladimir Sementsov-Ogievskiy --- ...test_x86_64_vhost_user_blk_fd_migration.py | 279 ++++++++++++++++++ 1 file changed, 279 insertions(+) create mode 100644 tests/functional/test_x86_64_vhost_user_blk_fd_migratio= n.py diff --git a/tests/functional/test_x86_64_vhost_user_blk_fd_migration.py b/= tests/functional/test_x86_64_vhost_user_blk_fd_migration.py new file mode 100644 index 0000000000..7ab3f61a5b --- /dev/null +++ b/tests/functional/test_x86_64_vhost_user_blk_fd_migration.py @@ -0,0 +1,279 @@ +#!/usr/bin/env python3 +# +# Functional test that tests vhost-user-blk local migration +# with fd passing +# +# Copyright (c) Yandex +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import os +import time +import subprocess + +from qemu_test import ( + LinuxKernelTest, + Asset, + exec_command_and_wait_for_pattern, +) + + +def wait_migration_finish(source_vm, target_vm): + migr_events =3D ( + ("MIGRATION", {"data": {"status": "completed"}}), + ("MIGRATION", {"data": {"status": "failed"}}), + ) + + source_e =3D source_vm.events_wait(migr_events)["data"] + target_e =3D target_vm.events_wait(migr_events)["data"] + + source_s =3D source_vm.cmd("query-status")["status"] + target_s =3D target_vm.cmd("query-status")["status"] + + assert ( + source_e["status"] =3D=3D "completed" + and target_e["status"] =3D=3D "completed" + and source_s =3D=3D "postmigrate" + and target_s =3D=3D "paused" + ), f"""Migration failed: + SRC status: {source_s} + SRC event: {source_e} + TGT status: {target_s} + TGT event:{target_e}""" + + +class VhostUserBlkFdMigration(LinuxKernelTest): + + ASSET_KERNEL =3D Asset( + ( + "https://archives.fedoraproject.org/pub/archive/fedora/linux/r= eleases" + "/31/Server/x86_64/os/images/pxeboot/vmlinuz" + ), + "d4738d03dbbe083ca610d0821d0a8f1488bebbdccef54ce33e3adb35fda00129", + ) + + ASSET_INITRD =3D Asset( + ( + "https://archives.fedoraproject.org/pub/archive/fedora/linux/r= eleases" + "/31/Server/x86_64/os/images/pxeboot/initrd.img" + ), + "277cd6c7adf77c7e63d73bbb2cded8ef9e2d3a2f100000e92ff1f8396513cd8b", + ) + + DATA1 =3D "TEST_DATA_BEFORE_MIGRATION_12345" + DATA2 =3D "TEST_DATA_AFTER_MIGRATION_54321" + + def write_data(self, data, vm) -> None: + exec_command_and_wait_for_pattern( + self, + f'echo "{data}" | ' "dd of=3D/dev/vda bs=3D512 count=3D1 oflag= =3Ddirect", + "# ", + vm=3Dvm, + ) + + def read_data(self, data, vm) -> None: + exec_command_and_wait_for_pattern( + self, + "dd if=3D/dev/vda bs=3D512 count=3D1 iflag=3Ddirect 2>/dev/nul= l", + data, + vm=3Dvm, + ) + + def setUp(self): + super().setUp() + self.vhost_proc =3D None + + def tearDown(self): + # Cleanup vhost-user server process + if self.vhost_proc: + try: + self.vhost_proc.terminate() + self.vhost_proc.wait(timeout=3D5) + except subprocess.TimeoutExpired: + self.vhost_proc.kill() + self.vhost_proc.wait() + except: + pass + + super().tearDown() + + def create_test_image(self): + """Create a temporary test image for vhost-user-blk""" + img_path =3D self.scratch_file("disk.img") + + # Create 64MB image + with open(img_path, "wb") as f: + f.write(b"\0" * (64 * 1024 * 1024)) + + return img_path + + def start_vhost_user_server(self, socket_path, img_path): + """Start vhost-user-blk server using contrib/vhost-user-blk""" + # Find vhost-user-blk binary + vub_binary =3D self.build_file( + "contrib", "vhost-user-blk", "vhost-user-blk" + ) + + if not os.path.isfile(vub_binary) or not os.access(vub_binary, os.= X_OK): + self.skipTest("vhost-user-blk binary not found") + + # assert that our further waiting would be correct + self.assertFalse(os.path.exists(socket_path)) + + cmd =3D [vub_binary, "-s", socket_path, "-b", img_path] + self.log.info(f'Starting vhost-user server: {" ".join(cmd)}') + self.vhost_proc =3D subprocess.Popen( + cmd, stderr=3Dsubprocess.PIPE, text=3DTrue, preexec_fn=3Dos.se= tsid + ) + + # Wait for socket to be created + for _ in range(100): # 10 seconds timeout + time.sleep(0.1) + + # Check if process is still running + if self.vhost_proc.poll() is not None: + self.fail(f"vhost-user server failed: {self.vhost_proc.std= err}") + + if os.path.exists(socket_path): + return + + self.fail(f"vhost-user socket {socket_path} was not created") + + def setup_shared_memory(self): + shm_path =3D f"/dev/shm/qemu_test_{os.getpid()}" + + try: + with open(shm_path, "wb") as f: + f.write(b"\0" * (1024 * 1024 * 1024)) # 1GB + except Exception as e: + self.fail(f"Failed to create shared memory file: {e}") + + return shm_path + + def prepare_and_launch_vm( + self, shm_path, vhost_socket, incoming=3DFalse, vm=3DNone + ): + if not vm: + vm =3D self.vm + + vm.add_args("-accel", "kvm") + vm.add_args("-device", "pcie-pci-bridge,id=3Dpci.1,bus=3Dpcie.0") + vm.add_args("-m", "1G") + vm.add_args("-append", "console=3DttyS0 rd.rescue") + + vm.add_args( + "-object", + f"memory-backend-file,id=3Dram0,size=3D1G,mem-path=3D{shm_path= },share=3Don", + ) + vm.add_args("-machine", "memory-backend=3Dram0") + + vm.add_args("-kernel", self.ASSET_KERNEL.fetch()) + vm.add_args("-initrd", self.ASSET_INITRD.fetch()) + + vm.add_args("-S") + + if incoming: + vm.add_args("-incoming", "defer") + + vm.set_console() + + vm_s =3D "target" if incoming else "source" + self.log.info(f"Launching {vm_s} VM") + vm.launch() + + self.set_migration_capabilities(vm) + self.add_vhost_user_blk_device(vm, vhost_socket, incoming) + + def add_vhost_user_blk_device(self, vm, socket_path, incoming=3DFalse): + # Add chardev + chardev_params =3D { + "id": "chardev-virtio-disk0", + "backend": { + "type": "socket", + "data": { + "addr": {"type": "unix", "data": {"path": socket_path}= }, + "server": False, + "reconnect-ms": 20, + "support-local-migration": True, + }, + }, + } + + if incoming: + chardev_params["backend"]["data"]["local-incoming"] =3D True + + vm.cmd("chardev-add", chardev_params) + + # Add device + device_params =3D { + "id": "virtio-disk0", + "driver": "vhost-user-blk-pci", + "chardev": "chardev-virtio-disk0", + "num-queues": 1, + "bus": "pci.1", + "config-wce": False, + "bootindex": 1, + "disable-legacy": "off", + } + + if incoming: + device_params["local-incoming"] =3D True + + vm.cmd("device_add", device_params) + + def set_migration_capabilities(self, vm): + capabilities =3D [ + {"capability": "events", "state": True}, + {"capability": "x-ignore-shared", "state": True}, + {"capability": "local-vhost-user-blk", "state": True}, + {"capability": "local-char-socket", "state": True}, + ] + vm.cmd("migrate-set-capabilities", {"capabilities": capabilities}) + + def test_vhost_user_blk_fd_migration(self): + self.require_accelerator("kvm") + self.set_machine("q35") + + socket_dir =3D self.socket_dir() + vhost_socket =3D os.path.join(socket_dir.name, "vhost-user-blk.soc= k") + migration_socket =3D os.path.join(socket_dir.name, "migration.sock= ") + + img_path =3D self.create_test_image() + shm_path =3D self.setup_shared_memory() + + self.start_vhost_user_server(vhost_socket, img_path) + + self.prepare_and_launch_vm(shm_path, vhost_socket) + self.vm.cmd("cont") + self.wait_for_console_pattern("Entering emergency mode.") + self.wait_for_console_pattern("# ") + + self.write_data(self.DATA1, self.vm) + self.read_data(self.DATA1, self.vm) + + target_vm =3D self.get_vm(name=3D"target") + self.prepare_and_launch_vm( + shm_path, vhost_socket, incoming=3DTrue, vm=3Dtarget_vm + ) + + target_vm.cmd("migrate-incoming", {"uri": f"unix:{migration_socket= }"}) + + self.log.info("Starting migration") + self.vm.cmd("migrate", {"uri": f"unix:{migration_socket}"}) + + self.log.info("Waiting for migration completion") + wait_migration_finish(self.vm, target_vm) + + target_vm.cmd("cont") + self.vm.shutdown() + + self.log.info("Verifying disk on target VM after migration") + self.read_data(self.DATA1, target_vm) + self.write_data(self.DATA2, target_vm) + self.read_data(self.DATA2, target_vm) + + target_vm.shutdown() + + +if __name__ =3D=3D "__main__": + LinuxKernelTest.main() --=20 2.48.1