Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2E7A6CD342F for ; Tue, 5 May 2026 08:17:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wKAw0-0001PL-Fu; Tue, 05 May 2026 04:15:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wKAvz-0001OV-9N for qemu-devel@nongnu.org; Tue, 05 May 2026 04:15:15 -0400 Received: from mail-southcentralusazlp170110003.outbound.protection.outlook.com ([2a01:111:f403:c10d::3] helo=SN4PR0501CU005.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wKAvx-0006Yo-4O for qemu-devel@nongnu.org; Tue, 05 May 2026 04:15:14 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yaiyllZdis86pTofMzHAEP4jiyyavvdlvG3ja6r1m1qRTG04uS7UXQAC4gXC1sJMlWSnkMJhdrY5bycLWYN1Ni7z8OCva1iiBVIFZOszwLDQzcRzZpJeMYNQbyMmuBsoggwLihBi6IR6xE4y3pXPqE0cvFFdUqFcdFNa0uNpucn+bSmGSSvP+SH1Ry2bHN+mvnGBRW6NrLM1bhX2u/3NvodlJ3flGok1A+H2Iqj+IiDg5Jz61Vum318urCZuFkJ6eHeSQ6AXeXdtlElcGTQFsOUC4jkC3rCKUJJfpIaerGHMxhZUX61x2oSIvxOAJR7LsQ9htoiZAhFxjZV43u5MaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1145C9qJNePzERXyuTkOezsOV2Vw7sScDnH4KYnnJpk=; b=mpeM6SOjPjUL+ekTjXJHquTIPXfbXLMC3V+eyLTTf72dkcGsYX4ENVVwsMYluvj2x3Y5iNk6qOQjPvz2P0MhpBL1FYkcdF1ClMy7cLaE8kj38nUj8eG/BQbBcfQkcDaUieKGl6hnMj603HL7itJrQfVpgk5DN9SDCLKRXuHEtOi4alIDgBUPpRdX6gLuzh1Qn5RyMUESh6C0HGB1YBfSftbZKV2VmxHR3s0IdAjZ1YMRpJ16NSFqXy2CSTuKoSwkWX1/f7FxM2cxGUdCam5qF8SOD91Vh6dEyv6cThQpKZlltnrY02dyZW/6Pw2aF6ONMHhvKnLpQnqRU/iPUxZDSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=nongnu.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1145C9qJNePzERXyuTkOezsOV2Vw7sScDnH4KYnnJpk=; b=p7/zypOL1Oe9E550anYNHipnc9pcUjckSpB63pmIE3cHVtaPIaJAJ/FTERSUQaiJDqb+KkYYYrf0Zxjfl6gV9JG0W6Unz03AHItv/0IPpCoItRJHYpDGfEB+bjL5K2O4+Jmjg6F7RJvEJQh7EzWQxOrvWncRUEMMiftVIVY+d7va0Jq1OS3k742GmtYcrMG+OtYslGhuNm9N5j/NiEuAnyr8sBveGR1svy3W2gcPDaqn3VVdLdkm4ogPsC9LcAsA+ZVbfol+pcttUZzm1AaeaDWe1x5wwEZoxpliVeCibf5P3eV1Nf3J41Tk5Ky0Dd7bthT/xQKgPvFXVbplsnIqww== Received: from MW4P223CA0012.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::17) by BN7PPFCE25C719B.namprd12.prod.outlook.com (2603:10b6:40f:fc02::6e1) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.25; Tue, 5 May 2026 08:15:07 +0000 Received: from SJ5PEPF000001D4.namprd05.prod.outlook.com (2603:10b6:303:80:cafe::30) by MW4P223CA0012.outlook.office365.com (2603:10b6:303:80::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9870.27 via Frontend Transport; Tue, 5 May 2026 08:15:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by SJ5PEPF000001D4.mail.protection.outlook.com (10.167.242.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9891.9 via Frontend Transport; Tue, 5 May 2026 08:15:05 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Tue, 5 May 2026 01:14:48 -0700 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Tue, 5 May 2026 01:14:48 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Tue, 5 May 2026 01:14:44 -0700 From: Avihai Horon To: CC: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Xu , Fabiano Rosas , Pierrick Bouvier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu , "Michael S. Tsirkin" , Cornelia Huck , Paolo Bonzini , Maor Gottlieb , Avihai Horon Subject: [PATCH 05/14] migration: Replace switchover_ack_needed SaveVMHandler Date: Tue, 5 May 2026 11:14:14 +0300 Message-ID: <20260505081423.28326-6-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20260505081423.28326-1-avihaih@nvidia.com> References: <20260505081423.28326-1-avihaih@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001D4:EE_|BN7PPFCE25C719B:EE_ X-MS-Office365-Filtering-Correlation-Id: bb947cac-fc72-4807-fb71-08deaa7e6a51 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|7416014|82310400026|1800799024|36860700016|56012099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: Y9150oOc8tZ7tI231J7v9zWlvidFpV6k6DVycXccxFexovFERzja6IZqpeXJXDS0a99fDiPsYJafPTFqjtHeT5RrQaQMXGfbc1pbr5tqiptrYwOafg/IqemlNv+UewgmZkrnYtkGtVLVw+MRbMgk5KCdzE9g9/NW9AgABlc21qSBmXm5U0Uu4gOgrRtKD25alf3Th61EXMtJVi5VprTRlB39LBDUZVAtrFgCxM9cO52a7k92QuYtnyO/Tjs9yCYyhZ6NscbfSllBuvX6p/gUV9jf8SqpOuhSJhtLL/lRJme5xRCHg5VZ2GcBXNy5Kn3hcR4IxEkC5JT5GVi6x/AD9GXV72aRFn4Kb+xOZQB/I/uYajUqYgnzuNBKYG0FVX5+IkWkQsWO3pLUpaKJ9YGHGfpcm2vypC6bc2QXvOmhKHIY1VoCtj1Ihe93hLYIx/VVFu9MVZoyH+Ikk5xhdSZxfoedYM0VdtkJzysZaFQhYYHRNsU3KoAui6n2tostC38g9CDzJ6jFAhWCKGE6pl3KR1pagRsCnvbJ2MmNkIRBErF994157tqAWbfe84oQm0H1OxlGmBa8twLmaEmRPgZMb44xgFuIJj6MXv7uUYNOeSLB7y7GfDvIxaX62Woxo30Qw6a4COtWX7GzyuYe46Cz6Y6YrIo8OZFy5eqW+uGWIm62ZMp1DZEM7XboU3Fd8pPozeZHlAu/mSYYgllkkI0AwwIUWIHCyOQZoRYFPMMboeM= X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230040)(376014)(7416014)(82310400026)(1800799024)(36860700016)(56012099003)(22082099003)(18002099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xMnqlyFTEal7Etxa3xbu2YIuyrGsHaD7/cobkHrYae75gyT+UV+8WQAJXDhHmD11An7fZ3RjhicYHPAOwTEKYkP4fujaKxSYH7KfMWDTwuNp5v/rTZbDp1zlfHWZiglN2FAk6skte1IIRSdOUK/h1JvLxiLnoquITznEx23MentiEvMLpvBN/z9sXCiMBpiLx9MtSHaE6VvVfG9hScvKJcN2DqUJYCe5GehUv3ab243jXKCdiAX1mipYw+SHyze0n1cnNeoVlYcXf0LPwgzx4lub136LAjvC838aKfixg9SMbCP0vvZF/cApK1Qqt+iMJJFyphkB9ReacSzI4tduwiP4Q9Y+B58xwzVlmKWH7BXNhsvcPhrhE/6M+btF8Qvl7NAkYL+s9v/6AAYzmJL+Vp/r1IfnghdCaqc93ZuXlezBZ26PQx+4cG4UHEDALMyG X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2026 08:15:05.9259 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bb947cac-fc72-4807-fb71-08deaa7e6a51 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ5PEPF000001D4.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PPFCE25C719B Received-SPF: permerror client-ip=2a01:111:f403:c10d::3; envelope-from=avihaih@nvidia.com; helo=SN4PR0501CU005.outbound.protection.outlook.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.444, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org A new switchover-ack mechanism that will replace the existing one will be added in the following patches. The new mechanism will have a new SaveVMHandler and will not use switchover_ack_needed. However, the old mechanism must still be kept for backward compatibility. To keep things clear and decrease API surface of old code, replace switchover_ack_needed SaveVMHandler with a regular function migration_request_switchover_ack(). No functional changes intended. Signed-off-by: Avihai Horon --- docs/devel/migration/vfio.rst | 3 --- include/migration/misc.h | 2 ++ include/migration/register.h | 13 ------------- hw/vfio/migration.c | 18 ++++++++++-------- migration/migration.c | 15 +++++++++++++++ migration/savevm.c | 21 --------------------- migration/trace-events | 2 +- 7 files changed, 28 insertions(+), 46 deletions(-) diff --git a/docs/devel/migration/vfio.rst b/docs/devel/migration/vfio.rst index 691061d182..854277b11c 100644 --- a/docs/devel/migration/vfio.rst +++ b/docs/devel/migration/vfio.rst @@ -59,9 +59,6 @@ VFIO implements the device hooks for the iterative approach as follows: * A ``save_live_iterate`` function that reads the VFIO device's data from the vendor driver during iterative pre-copy phase. -* A ``switchover_ack_needed`` function that checks if the VFIO device uses - "switchover-ack" migration capability when this capability is enabled. - * A ``switchover_start`` function that in the multifd mode starts a thread that reassembles the multifd received data and loads it in-order into the device. In the non-multifd mode this function is a NOP. diff --git a/include/migration/misc.h b/include/migration/misc.h index 3159a5e53c..a2219c981b 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -156,4 +156,6 @@ bool multifd_device_state_save_thread_should_exit(void); void multifd_abort_device_state_save_threads(void); bool multifd_join_device_state_save_threads(void); +void migration_request_switchover_ack(const char *requester); + #endif diff --git a/include/migration/register.h b/include/migration/register.h index 5e5e0ee432..eae4c4ffca 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -299,19 +299,6 @@ typedef struct SaveVMHandlers { */ int (*resume_prepare)(MigrationState *s, void *opaque); - /** - * @switchover_ack_needed - * - * Checks if switchover ack should be used. Called only on - * destination. - * - * @opaque: data pointer passed to register_savevm_live() - * - * Returns true if switchover ack should be used and false - * otherwise - */ - bool (*switchover_ack_needed)(void *opaque); - /** * @switchover_start * diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index c3dd30d619..4dab569e62 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -463,6 +463,14 @@ static bool vfio_precopy_supported(VFIODevice *vbasedev) return migration->mig_flags & VFIO_MIGRATION_PRE_COPY; } +static void vfio_request_switchover_ack(VFIODevice *vbasedev) +{ + if (vfio_precopy_supported(vbasedev)) { + /* Precopy support implies switchover-ack is needed */ + migration_request_switchover_ack(vbasedev->name); + } +} + /* ---------------------------------------------------------------------- */ static int vfio_save_prepare(void *opaque, Error **errp) @@ -747,6 +755,8 @@ static int vfio_load_setup(QEMUFile *f, void *opaque, Error **errp) return ret; } + vfio_request_switchover_ack(vbasedev); + return 0; } @@ -845,13 +855,6 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id) return ret; } -static bool vfio_switchover_ack_needed(void *opaque) -{ - VFIODevice *vbasedev = opaque; - - return vfio_precopy_supported(vbasedev); -} - static int vfio_switchover_start(void *opaque) { VFIODevice *vbasedev = opaque; @@ -875,7 +878,6 @@ static const SaveVMHandlers savevm_vfio_handlers = { .load_setup = vfio_load_setup, .load_cleanup = vfio_load_cleanup, .load_state = vfio_load_state, - .switchover_ack_needed = vfio_switchover_ack_needed, /* * Multifd support */ diff --git a/migration/migration.c b/migration/migration.c index a5c7ca6796..1db2d296bc 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2164,6 +2164,21 @@ void migration_rp_kick(MigrationState *s) qemu_sem_post(&s->rp_state.rp_sem); } +/* This is called only on destination side */ +void migration_request_switchover_ack(const char *requester) +{ + MigrationIncomingState *mis = migration_incoming_get_current(); + + if (!migrate_switchover_ack()) { + return; + } + + mis->switchover_ack_pending_num++; + + trace_migration_request_switchover_ack(requester, + mis->switchover_ack_pending_num); +} + static struct rp_cmd_args { ssize_t len; /* -1 = variable */ const char *name; diff --git a/migration/savevm.c b/migration/savevm.c index bd8c6ada5a..2bc3414363 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2784,23 +2784,6 @@ static int qemu_loadvm_state_header(QEMUFile *f, Error **errp) return 0; } -static void qemu_loadvm_state_switchover_ack_needed(MigrationIncomingState *mis) -{ - SaveStateEntry *se; - - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { - if (!se->ops || !se->ops->switchover_ack_needed) { - continue; - } - - if (se->ops->switchover_ack_needed(se->opaque)) { - mis->switchover_ack_pending_num++; - } - } - - trace_loadvm_state_switchover_ack_needed(mis->switchover_ack_pending_num); -} - static int qemu_loadvm_state_setup(QEMUFile *f, Error **errp) { ERRP_GUARD(); @@ -3062,10 +3045,6 @@ int qemu_loadvm_state(QEMUFile *f, Error **errp) return -EINVAL; } - if (migrate_switchover_ack()) { - qemu_loadvm_state_switchover_ack_needed(mis); - } - cpu_synchronize_all_pre_loadvm(); ret = qemu_loadvm_state_main(f, mis, errp); diff --git a/migration/trace-events b/migration/trace-events index d9084a2692..9f5f6142d3 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -8,7 +8,6 @@ qemu_loadvm_state_post_main(int ret) "%d" qemu_loadvm_state_section_startfull(uint32_t section_id, const char *idstr, uint32_t instance_id, uint32_t version_id) "%u(%s) %u %u" qemu_savevm_send_packaged(void) "" qemu_savevm_query_pending(bool exact, uint64_t precopy, uint64_t stopcopy, uint64_t postcopy, uint64_t total) "exact=%d, precopy=%"PRIu64", stopcopy=%"PRIu64", postcopy=%"PRIu64", total=%"PRIu64 -loadvm_state_switchover_ack_needed(unsigned int switchover_ack_pending_num) "Switchover ack pending num=%u" loadvm_state_setup(void) "" loadvm_state_cleanup(void) "" loadvm_handle_cmd_packaged(unsigned int length) "%u" @@ -199,6 +198,7 @@ process_incoming_migration_co_postcopy_end_main(void) "" postcopy_preempt_enabled(bool value) "%d" migration_precopy_complete(void) "" migration_call_notifiers(int type) "type=%d" +migration_request_switchover_ack(const char *requester, unsigned int switchover_ack_pending_num) "Requester %s, switchover_ack_pending_num %u" # migration-stats migration_transferred_bytes(uint64_t qemu_file, uint64_t multifd, uint64_t rdma) "qemu_file %" PRIu64 " multifd %" PRIu64 " RDMA %" PRIu64 -- 2.40.1