From nobody Sat Nov 15 07:46:00 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