From nobody Thu Apr 3 11:02:53 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741126852332791.6221666422668; Tue, 4 Mar 2025 14:20:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tpaaG-0006TF-Gl; Tue, 04 Mar 2025 17:17:53 -0500 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 1tpaYK-00047H-4X for qemu-devel@nongnu.org; Tue, 04 Mar 2025 17:15:54 -0500 Received: from vps-ovh.mhejs.net ([145.239.82.108]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tpaWy-0001Rb-Ua for qemu-devel@nongnu.org; Tue, 04 Mar 2025 17:15:51 -0500 Received: from MUA by vps-ovh.mhejs.net with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.98) (envelope-from ) id 1tpaPz-00000000LbB-3tMo; Tue, 04 Mar 2025 23:07:15 +0100 From: "Maciej S. Szmigiero" To: Peter Xu , Fabiano Rosas Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Eric Blake , Markus Armbruster , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Avihai Horon , Joao Martins , qemu-devel@nongnu.org Subject: [PATCH v6 29/36] vfio/migration: Multifd device state transfer support - config loading support Date: Tue, 4 Mar 2025 23:03:56 +0100 Message-ID: <5dbd3f3703ec1097da2cf82a7262233452146fee.1741124640.git.maciej.szmigiero@oracle.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: 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=145.239.82.108; envelope-from=mhej@vps-ovh.mhejs.net; helo=vps-ovh.mhejs.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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-ZM-MESSAGEID: 1741126853816019100 Content-Type: text/plain; charset="utf-8" From: "Maciej S. Szmigiero" Load device config received via multifd using the existing machinery behind vfio_load_device_config_state(). Also, make sure to process the relevant main migration channel flags. Signed-off-by: Maciej S. Szmigiero Reviewed-by: C=C3=A9dric Le Goater --- hw/vfio/migration-multifd.c | 49 +++++++++++++++++++++++++++++++++-- hw/vfio/migration.c | 9 ++++++- include/hw/vfio/vfio-common.h | 2 ++ 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c index 2eef27604e4f..1d81233c755f 100644 --- a/hw/vfio/migration-multifd.c +++ b/hw/vfio/migration-multifd.c @@ -17,6 +17,7 @@ #include "qemu/lockable.h" #include "qemu/main-loop.h" #include "qemu/thread.h" +#include "io/channel-buffer.h" #include "migration/qemu-file.h" #include "migration-multifd.h" #include "trace.h" @@ -193,8 +194,52 @@ bool vfio_multifd_load_state_buffer(void *opaque, char= *data, size_t data_size, static bool vfio_load_bufs_thread_load_config(VFIODevice *vbasedev, Error **errp) { - error_setg(errp, "not yet there"); - return false; + VFIOMigration *migration =3D vbasedev->migration; + VFIOMultifd *multifd =3D migration->multifd; + VFIOStateBuffer *lb; + g_autoptr(QIOChannelBuffer) bioc =3D NULL; + g_autoptr(QEMUFile) f_out =3D NULL, f_in =3D NULL; + uint64_t mig_header; + int ret; + + assert(multifd->load_buf_idx =3D=3D multifd->load_buf_idx_last); + lb =3D vfio_state_buffers_at(&multifd->load_bufs, multifd->load_buf_id= x); + assert(lb->is_present); + + bioc =3D qio_channel_buffer_new(lb->len); + qio_channel_set_name(QIO_CHANNEL(bioc), "vfio-device-config-load"); + + f_out =3D qemu_file_new_output(QIO_CHANNEL(bioc)); + qemu_put_buffer(f_out, (uint8_t *)lb->data, lb->len); + + ret =3D qemu_fflush(f_out); + if (ret) { + error_setg(errp, "%s: load config state flush failed: %d", + vbasedev->name, ret); + return false; + } + + qio_channel_io_seek(QIO_CHANNEL(bioc), 0, 0, NULL); + f_in =3D qemu_file_new_input(QIO_CHANNEL(bioc)); + + mig_header =3D qemu_get_be64(f_in); + if (mig_header !=3D VFIO_MIG_FLAG_DEV_CONFIG_STATE) { + error_setg(errp, "%s: expected FLAG_DEV_CONFIG_STATE but got %" PR= Ix64, + vbasedev->name, mig_header); + return false; + } + + bql_lock(); + ret =3D vfio_load_device_config_state(f_in, vbasedev); + bql_unlock(); + + if (ret < 0) { + error_setg(errp, "%s: vfio_load_device_config_state() failed: %d", + vbasedev->name, ret); + return false; + } + + return true; } =20 static VFIOStateBuffer *vfio_load_state_buffer_get(VFIOMultifd *multifd) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 0096344f74f9..f325a619c3ed 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -264,7 +264,7 @@ static int vfio_save_device_config_state(QEMUFile *f, v= oid *opaque, return ret; } =20 -static int vfio_load_device_config_state(QEMUFile *f, void *opaque) +int vfio_load_device_config_state(QEMUFile *f, void *opaque) { VFIODevice *vbasedev =3D opaque; uint64_t data; @@ -723,6 +723,13 @@ static int vfio_load_state(QEMUFile *f, void *opaque, = int version_id) switch (data) { case VFIO_MIG_FLAG_DEV_CONFIG_STATE: { + if (vfio_multifd_transfer_enabled(vbasedev)) { + error_report("%s: got DEV_CONFIG_STATE in main migration " + "channel but doing multifd transfer", + vbasedev->name); + return -EINVAL; + } + return vfio_load_device_config_state(f, opaque); } case VFIO_MIG_FLAG_DEV_SETUP_STATE: diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 40382390692d..9d72ac1eae8a 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -298,6 +298,8 @@ void vfio_mig_add_bytes_transferred(unsigned long val); bool vfio_device_state_is_running(VFIODevice *vbasedev); bool vfio_device_state_is_precopy(VFIODevice *vbasedev); =20 +int vfio_load_device_config_state(QEMUFile *f, void *opaque); + #ifdef CONFIG_LINUX int vfio_get_region_info(VFIODevice *vbasedev, int index, struct vfio_region_info **info);