From nobody Sat Oct 24 00:32:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790939086; cv=none; d=zohomail.com; s=zohoarc; b=MX95NeQNU73cw03vJQMtXf+FgmpN3J+FMkBs1CNjx0hRr8Nyt+uqpTouUkYdTW2KIOc2XLd6VQHqYkg3RQrp3wmHR0v/pb+w+d5BpjkrIDYskIjQ/c7Q2NTtw1KvNDycrxU+U6FWjkuMrTQs5HcBUkidN01KLw5aVk4s1j1SRYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790939086; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3NL85gesnrWtNA0x1156/EFbnVpOENQI5jaa40zkUhc=; b=TGaxse/WE9X+48/1FovfR4b6/jOqlqedUSuLEYaKgQVcYmiKefr1vW0YEiRrB0j63nBQQQ12+IYAXuxULdfOrJKBZv+0W0Cq1+xUfjoBFmw8F8QjbEevetr6hbVWU5X3PBBYuwGIYDp9zWKEi7tAMSx+4eFo8P/QEVAg/lIcPBg= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790939086535384.1435283470016; Fri, 2 Oct 2026 04:04:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xCb3K-0001Tv-Sb; Fri, 02 Oct 2026 07:03:47 -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 1xCb3I-0001TR-PR for qemu-devel@nongnu.org; Fri, 02 Oct 2026 07:03:44 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xCb3H-0008UB-3J for qemu-devel@nongnu.org; Fri, 02 Oct 2026 07:03:44 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49ce364488dso13741105e9.0 for ; Fri, 02 Oct 2026 04:03:42 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:9f21:a362:21c8:d9a1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a03ff3cab2sm24533785e9.2.2026.10.02.04.03.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2026 04:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790939021; x=1791543821; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3NL85gesnrWtNA0x1156/EFbnVpOENQI5jaa40zkUhc=; b=V0wt0oKqcSzkVkWOHMMb4RqnZyXTk3yg0uhcTnqJRSv9+ebU9rhdYsYd6iFF9RBI7/ Q6yj4j6MYsh8wS26PxgvqXVwRJu78Jq4/NSuhLBFJFlEpRWeucntywP/f1kyYmSqnYKk S8KNhO38MyADxcE0KxdgFJY/lQFaMhLhhyn3Poj1cegTuGThqPtkyy7a2Gxle4Hs1oW4 rCPwES6HjrJucs4qlRqna7NYb9cVThL21C2oMOOadRL8SMAfaYeYrVqD2G4Yl4wkCKe3 bxLaOo12JjgpdqJxO4WI8oSW2OXUk5ec/dHBJeirdTnXXdNi+UHl+m4+3Aq6ZWljVaxS 5oXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790939021; x=1791543821; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=3NL85gesnrWtNA0x1156/EFbnVpOENQI5jaa40zkUhc=; b=K3gUAK9l9oYqazTaW2PNSOokWZC0HCdN79iYBRQcCfHA0kj/IA6VMAggC1ZUE89vPh 1kqhpnwzepkShp9a+NnMil6B5d+PZgAkuY7+/DNMNaJjzhooJBmx9daCQslCqPOGsPPh 0rrznXUeMqwvIL9dnUMofixjjahCCnUyjC04BuuZISPdxsCtn/Kz8dZRcs+VE7Yxbxq8 L3Qyqw2WcwQ9o0glGLzwTPufioKbcpTr0Pm3h3TkWKrAkqCAauLoHFop+UsxbtQgVB9B smzOpiCjjfMa3DZQbP9GbKAqkrWzcA0ElaLHGoKOlkXNwO/G9EnJGQof+Ot5uCoVf/AK kDzA== X-Gm-Message-State: AFuF++k1lElVNWyw/6kBoy8fz2rBOnk9IgkRdgvqGJCOX156j0wZNh1V qAGxT3bd3x3IpBDHg1DDt1FeOuCU/IWHtiyenGLr8BzthcTddrJTcTiva39T+UOqT/e8oL0E+4k uz8Z5 X-Gm-Gg: AYBFou2dtNcchGixprUa+aOcBtkjDteZDhYmH8454U8qAoDTbtTtdXbPAzIuHuhNLec NiUnegu9qyvLoh1q5CG4+0AEkO3q6kPBaKT3O6CKaFoW7XHiVJxpFrZFM7E/Gja881qTb9Fwcgi bRZJ46GYLzX2lQmt905SZn2C41Rg+5UxvAdkJAX1Ha3V4PExdt6FAtwn8qAtDySi4DCFFOFoo+L 6JW9qRtOJfvZ9UUA+AymFhtxCk3QsVOKIDccktjDjRzFId10wasrpBJLCl9XGa2X8hr2hoA4/gV 80V+HKVBcWfCus384dwhNWjYadT7F1pvaWIYK68GaCuRr82QpixMbZX+B3zbNYfYG7PGelUpzQy funT688mR3WlYJbHWo+Ar6I2Uf6cR3x/sbxVPRDBvtn6kRNWJNvxDDfUWDxMFxiBiTormtAr10T umOn6Z/MylRguTjyhTeYQPd1p5DSlFgpTWoRrrKMdm1B0yMSZViK3beQUxelquStv2N9I= X-Received: by 2002:a05:600c:870f:b0:49f:fc4f:9efb with SMTP id 5b1f17b1804b1-4a02753fd01mr43234085e9.7.1790939021288; Fri, 02 Oct 2026 04:03:41 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Peter Xu , Fabiano Rosas , Juraj Marcin Subject: [PATCH 1/4] migration/postcopy: report COMPLETED only after the run BH has run Date: Fri, 2 Oct 2026 13:02:55 +0200 Message-ID: <20261002110258.1835979-2-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261002110258.1835979-1-den@openvz.org> References: <20261002110258.1835979-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=den@openvz.org; helo=mail-wm2-x10.google.com 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_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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790939088637158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev The postcopy listen thread waits for main_thread_load_event before it reports COMPLETED. That event is set as soon as qemu_loadvm_state_main() returns in the main thread, while the run state is changed later, in loadvm_postcopy_handle_run_bh(). The listen thread can therefore report COMPLETED while the VM is still in RUN_STATE_INMIGRATE, easily so in a bitmap-only postcopy where it has little to load. Management reacting to COMPLETED then finds the VM still incoming: a blockdev-add creates an inactive node, since bds_tree_init() forces BDRV_O_INACTIVE in RUN_STATE_INMIGRATE, and attaching a device to it fails with "Block node is read-only". Precopy gets this right: process_incoming_migration_bh() changes the run state before it reports COMPLETED. Set an event at the end of the run BH and wait for it in the listen thread, unless loading failed before CMD_POSTCOPY_RUN and the BH was never scheduled. Signed-off-by: Denis V. Lunev Cc: Peter Xu Cc: Fabiano Rosas Cc: Juraj Marcin --- migration/migration.c | 2 ++ migration/migration.h | 2 ++ migration/postcopy-ram.c | 4 ++++ migration/savevm.c | 1 + 4 files changed, 9 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index fab7949fe1..8944acf3cd 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -324,6 +324,7 @@ void migration_object_init(void) qemu_mutex_init(¤t_incoming->rp_mutex); qemu_mutex_init(¤t_incoming->postcopy_prio_thread_mutex); qemu_event_init(¤t_incoming->main_thread_load_event, false); + qemu_event_init(¤t_incoming->postcopy_run_event, false); qemu_sem_init(¤t_incoming->postcopy_pause_sem_dst, 0); qemu_sem_init(¤t_incoming->postcopy_pause_sem_fault, 0); qemu_sem_init(¤t_incoming->postcopy_pause_sem_fast_load, 0); @@ -493,6 +494,7 @@ void migration_incoming_state_destroy(void) =20 migration_incoming_transport_cleanup(mis); qemu_event_reset(&mis->main_thread_load_event); + qemu_event_reset(&mis->postcopy_run_event); =20 if (mis->page_requested) { g_tree_destroy(mis->page_requested); diff --git a/migration/migration.h b/migration/migration.h index 683bc7bdd5..c65212ff63 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -108,6 +108,8 @@ struct MigrationIncomingState { * loading state. */ QemuEvent main_thread_load_event; + /* Set once the postcopy run BH has changed the run state */ + QemuEvent postcopy_run_event; =20 /* For network announces */ AnnounceTimer announce_timer; diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 5509cbdcb8..fd2c139cfe 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -2443,6 +2443,10 @@ static void *postcopy_listen_thread(void *opaque) * state yet; wait for the end of the main thread. */ qemu_event_wait(&mis->main_thread_load_event); + /* The VM run state is changed later, in loadvm_postcopy_handle_run_bh= () */ + if (postcopy_state_get() =3D=3D POSTCOPY_INCOMING_RUNNING) { + qemu_event_wait(&mis->postcopy_run_event); + } =20 /* * Device load in the main thread has finished, we should be in diff --git a/migration/savevm.c b/migration/savevm.c index 4b590ea672..5ec09d4889 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2263,6 +2263,7 @@ static void loadvm_postcopy_handle_run_bh(void *opaqu= e) } =20 trace_vmstate_downtime_checkpoint("dst-postcopy-bh-vm-started"); + qemu_event_set(&mis->postcopy_run_event); } =20 /* After all discards we can start running and asking for pages */ base-commit: f7ada39edacaa5c26b30e98b94017b0b2ccbcf94 --=20 2.53.0 From nobody Sat Oct 24 00:32:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790939072; cv=none; d=zohomail.com; s=zohoarc; b=nQkfn3wOMmL4HzrFn3hQeAZxcJFRHUMT3AgxaJCYGkS6HVsQ24mmcf8FSg/uQrvubwerQlb8l9RIxYha1IKmXuoKLmjxEDaWyysflrnMcNhPb6NAWHGL+dB20TmtFXgKvSXUtD/fZVd8R98ooHQyT4W0fSIqCLPz223iH1/zVmo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790939072; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AkIWwe4jZm6YDp2pbP9DnlPuFTMr8x6zTE3n3Ll2UnA=; b=LRa1Y4F0qfnf1ZXZe/4cQnw99H7bAJsvew7M/FDP3RnA5URpqXkCAfnGBGO2wGYjRHcdTnfRn5Va5KDYo3mBs3b3dYlLZbWnm99BLHCvEaZYvtJX+SPfDLcX9hDZXMZANziIj3FyWjfrERxg1Rli9jr/XhOvvAK9oqsW7pp4F8A= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790939072095768.39620008062; Fri, 2 Oct 2026 04:04:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xCb3N-0001VE-5P; Fri, 02 Oct 2026 07:03:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xCb3K-0001Ts-H7 for qemu-devel@nongnu.org; Fri, 02 Oct 2026 07:03:46 -0400 Received: from mail-wm2-x11.google.com ([2a00:1450:4864:31::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xCb3I-0008UQ-K5 for qemu-devel@nongnu.org; Fri, 02 Oct 2026 07:03:45 -0400 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49e7bcb94d3so57160885e9.2 for ; Fri, 02 Oct 2026 04:03:44 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:9f21:a362:21c8:d9a1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a03ff3cab2sm24533785e9.2.2026.10.02.04.03.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2026 04:03:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790939023; x=1791543823; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=AkIWwe4jZm6YDp2pbP9DnlPuFTMr8x6zTE3n3Ll2UnA=; b=BnGDyp8KmZmxE18Aunz11CucttW47mzo4gc/tTBTccdYOTSGBUVLzb8NEJLQ6nar6Z UFInBrfi6l9GrMCoQ6N6vmBPC9MjyokfE1nJztRhkxnUm2cce0Jx6Oz4iyMf58goodK8 pckRrkTCuqhqERtIITIqCErBUs5A40gnM6M88DITpbl12VdxEqMZetJRgdsbl3mt+bPe 7wzXfqh+0nph+N+eR8BKCJ0pJ0hG7zlsAC0CuzdLaFDYWNXBRbnkB/SwESgprcoYCVns sYjPDegeQuCqM/f9Hblg3uYi9PLnZLtV/4AhA1AuaFqBxHATKctIJ8d1AeNhpWwkLRnh xXPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790939023; x=1791543823; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=AkIWwe4jZm6YDp2pbP9DnlPuFTMr8x6zTE3n3Ll2UnA=; b=Xow4ouUJ8jhuNuSq0lsyhmMvlEfbDZJozWH1vRCDXeCW0euUtR+/IkE5H0Sqjl6RJV zWv848rH63xPsgXCCEwbp0+FPDAnCL8CwlYXU4tI0COSEYK0fMZySZVmXbyqClJUDQ5r 7VDVmbTgGd7QgGWWBx8IzlJwJqOZDuYAr78YqoU4fJ6CKmkb1HcOUmRQFQgU29g7ucGH +QJ8Fixij7c3I2ZtF44kI2WBP0e07fe4Mxps0Jp0DlHbXtUXgY8eO2jzgN5yQ6JeSOPu 4mv0YqbtWn22+spVxLF/qLPc9vxHs4Zm3AuY7/p83egTjGIr5jVdMLWmSgEzQQSkLv4D v0RA== X-Gm-Message-State: AFuF++kMNEVnZvrGirLEIoyM1+cK16YEtAcvQnSN+FUIqzRPj6cqCCdl hTRZD6FohbjDmth+Pa2gC6Ph19KoUKLAOZqkrn0HGOQGf52x14tbhrSA7ctxfeX+cxedOUHrv0p cX6JQ X-Gm-Gg: AYBFou2ElTlVzVl0A0XHe0s+jCU3A6xTc8Q6s8zkXw/vZYcU2C5SKCgr6WTybCh01Hp Ra+2gF0+g6QUkvqGit7ac4YwBAukjGVAQLKZ0M9ni5WTFgb3XlwAVASGIo0Y55j6wn9USmMyoXz 1Nj5I5C2pCuHjjUTcCGr++dEsfnHvNx4lXFTJdHSh49isX8wUUvVqJf3KvrQzsy1PmcM/6/VuQY foIvG+rnpbhUIAajnVnPwitf5p+XqUWoiCNb0uG4FzylewjmWGJBGfKKky+WB4PuhZbgdcUUdKT eo443Ic1c9q0h1IprAnPiAM4+gS7sE99MZ9R/CpPmuSXU8EU5pIkxmu2wpcOq6z/cSYxhi4aeeh VYWHDmdOGU9H5HZ49TUMvSRQ4GvFuXo3VFnk5D290cbCjekFGZONHDaAX5O2Ptn/PtmxCgof3oD Ecgc2gq3le1N4Ve6Hbdo2vcy4lZlTPtH5i7E85tnuB3uM0nM58e5YVaFWBFE38XLdwg7U= X-Received: by 2002:a05:600c:3103:b0:49d:1842:f001 with SMTP id 5b1f17b1804b1-4a027559c92mr43524285e9.14.1790939023073; Fri, 02 Oct 2026 04:03:43 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Peter Xu , Fabiano Rosas , Juraj Marcin Subject: [PATCH 2/4] migration/postcopy: set destination postcopy-active in the run BH Date: Fri, 2 Oct 2026 13:02:56 +0200 Message-ID: <20261002110258.1835979-3-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261002110258.1835979-1-den@openvz.org> References: <20261002110258.1835979-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::11; envelope-from=den@openvz.org; helo=mail-wm2-x11.google.com 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_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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790939072584158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev Commit 7b842fe354c ("migration: Introduce POSTCOPY_DEVICE state") made the destination enter POSTCOPY_ACTIVE in loadvm_postcopy_handle_run(), before it schedules loadvm_postcopy_handle_run_bh(), and only the BH starts the VM or moves it to RUN_STATE_PAUSED. Management reacting to the destination's postcopy-active event can therefore still find the VM in RUN_STATE_INMIGRATE, where blockdev-add creates inactive nodes and attaching a device to them fails with "Block node is read-only". Move the transition to the end of the run BH, after vm_start() or runstate_set(), as process_incoming_migration_bh() does for precopy COMPLETED. Without a return path the listen thread enters POSTCOPY_ACTIVE directly, and the fast snapshot load path switches right after scheduling the BH; in both cases the state is no longer POSTCOPY_DEVICE when the BH runs and the transition is a no-op. Signed-off-by: Denis V. Lunev Cc: Peter Xu Cc: Fabiano Rosas Cc: Juraj Marcin --- migration/savevm.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 5ec09d4889..bc1bc98a0e 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2263,6 +2263,10 @@ static void loadvm_postcopy_handle_run_bh(void *opaq= ue) } =20 trace_vmstate_downtime_checkpoint("dst-postcopy-bh-vm-started"); + + /* Already POSTCOPY_ACTIVE without a return path or in fast snapshot l= oad */ + migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_DEVICE, + MIGRATION_STATUS_POSTCOPY_ACTIVE); qemu_event_set(&mis->postcopy_run_event); } =20 @@ -2277,11 +2281,6 @@ static int loadvm_postcopy_handle_run(MigrationIncom= ingState *mis, Error **errp) return -1; } =20 - /* We might be already in POSTCOPY_ACTIVE if there is no return path */ - if (mis->state =3D=3D MIGRATION_STATUS_POSTCOPY_DEVICE) { - migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_DEVICE, - MIGRATION_STATUS_POSTCOPY_ACTIVE); - } postcopy_state_set(POSTCOPY_INCOMING_RUNNING); migration_bh_schedule(loadvm_postcopy_handle_run_bh, mis); =20 --=20 2.53.0 From nobody Sat Oct 24 00:32:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790939086; cv=none; d=zohomail.com; s=zohoarc; b=jbiqrqPKAc/z9rQbnLSRlXjCo4yQWzXcCYs/ZHQBrxP4hKCNYhtW7YFPb87UsMkSbaqUiE+HK5qtAuCt+Wf7kjsuTEB3Olw7qsmZC1Y2he8Z5X5BU9bXn3vNfU7jGkO3fF2YL1PEDBvzEG49DqUn8XC//iZix8cy2ZLAVjRHSrU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790939086; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wZ5fd90wMmGhR18V4PeDCCYB/ele6ujHSK6hnH2+u28=; b=bBnwsCdxHuxXfzaUkoF1y+a1MB9DvETsCcqktxZA6cy6V2ytZyCRMb9Ew1QT3hbbo+YgnFyym16QwW6/7ANXgescIamn25DbNksWaIAhIhwChV60ycYp9cC9AHYDlzY/7rCnrDXXXN1+OGc7FrKgrTppWX3ddgcCkx0o5yVH4bI= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790939086663351.0680387141099; Fri, 2 Oct 2026 04:04:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xCb3O-0001W0-Kk; Fri, 02 Oct 2026 07:03:50 -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 1xCb3N-0001VO-2B for qemu-devel@nongnu.org; Fri, 02 Oct 2026 07:03:49 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xCb3L-0008Ud-4e for qemu-devel@nongnu.org; Fri, 02 Oct 2026 07:03:48 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49ffed768deso22460595e9.1 for ; Fri, 02 Oct 2026 04:03:46 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:9f21:a362:21c8:d9a1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a03ff3cab2sm24533785e9.2.2026.10.02.04.03.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2026 04:03:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790939025; x=1791543825; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=wZ5fd90wMmGhR18V4PeDCCYB/ele6ujHSK6hnH2+u28=; b=rvOE2RIDlispbUKfewn2/OIoBoSemaDO1Fq+WFk0Xfd43t6EDEpCqYdJ68EijqhSnd 0LIa3xsSzn873gdMnbzADfdXccexMqt6z4vtckaVxufbN7+LcCqn0cOEaC42bWJgCsB3 P2fiyOYZu+qcsYJ8mv2tkPB+NeGQ/rXPRTrRgdnQbN6pER6wzgeVGGbDU8TyM6XswJo5 Uzjj3fZF86fa0WkKqi7hTxuFfe2G1Sgeed/eHg69Tb0xnfz73w4lKtpmyqY3c3kW/yD1 7h5bmvKyCgCqmW0dXVMOf0+64MmrRp4iCEWax/dmEeJB8QuZLnENMkOYbbC4fF2OTTyi REzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790939025; x=1791543825; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=wZ5fd90wMmGhR18V4PeDCCYB/ele6ujHSK6hnH2+u28=; b=yQmNcPTqu43AkkxIZZhxk6Ycr9BEU5HgIQTIMxy2TVc56DvOdKJEHmC8BAAkdaKEvz meCF5+43Kjv71/20cdAgpYwMatjb5yx3c2Tz50xLa4BWuizFWKFrXRp6H6L34nB4ZNr9 uK73rrRZmSgCuLxSV9nMddaPTpR8zts0vxrUoNv3/Bxkjj2ZdBWRnyNXuRv05ifKtIbJ 0KCsv5sAW5w6Dm9N+nAZnlR5vfBxbJGPkKTfYA8rjSUM+1PhUKM0K7oHsP2l1LTE60IC /luRqDlyTOvKXqNE//FFqzxCnRKPrSy49EYbdCdLWHEcgf4Lp0JDwGrTR91F/gKh4pu/ kLhA== X-Gm-Message-State: AFuF++kgjt6WcCsZVPv/APXImaj1039zjPXU60jL4pRgtwyz7/0tpShh wZ5OpWx+msUQiHleEObTH8GGunzwV1BQHKulEcXcY0RRcC+EcV3sixpXjp/eWtQD0Kh3wrOqkde jRXav X-Gm-Gg: AYBFou3gBnVqkxFBu9o98FhcWlVE829oTuEzdW6QxG8VZ5rcXfnqz8Rbe4gQfrBUsFv fa7GpZuEnsNubGrixwY8AQOVvlVhVkD1+2WRCJSYPWmozwR8OKyV29bEyAI3ZKBimoM6PwLEuRs 0W1xu1NW7u3oj7/1GTUFIpRIfwZRWooyRDLoUDPczdkXIxHlq+ZCaoDrd7rn2RSQKiXv7ekH4hh 1Ps7X5aTnuSB1HQlgooVdaKrjzYbwiY+hbH7t9p6Ue6jqaiwKinE1ysa1v0AIm64rHbyYSwY0xz QLtgpSrjJFtxEj/U55GHJrchOFfjN+LWV77F62BZ+2ZVushDAhn22keeLE+9gZ4h9MSDS5u8wzv 0BcG7oJjOqGaHh/D9p8FlZ1fpq5iP7Sur0w9kqiImFlvkOqBn1Q8BaKWbUKQQk3T0cD+JzZ9/th 504pspDkTR/YAEHdWBN5KDWShp9GjOej3PWLbunneulOimJMVbKXum6SJjfVrN3WVwPpQ= X-Received: by 2002:a05:600c:4fc1:b0:4a0:34a:588c with SMTP id 5b1f17b1804b1-4a0275649cbmr42097435e9.14.1790939025637; Fri, 02 Oct 2026 04:03:45 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Peter Xu , Fabiano Rosas , Juraj Marcin Subject: [PATCH 3/4] tests/qtest/migration: check the destination run state in postcopy tests Date: Fri, 2 Oct 2026 13:02:57 +0200 Message-ID: <20261002110258.1835979-4-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261002110258.1835979-1-den@openvz.org> References: <20261002110258.1835979-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=den@openvz.org; helo=mail-wm2-x10.google.com 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_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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790939088660158502 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev The destination must not report postcopy-active or completed while it is still in RUN_STATE_INMIGRATE. The destination autostarts in these tests, so the run state change emits RESUME and the order is visible in the event stream: record a MIGRATION postcopy-active or completed event seen before RESUME and fail the postcopy tests on it once the destination has completed. migrate_postcopy_start() waited for the destination's RESUME with qtest_qmp_eventwait(), which reads events past the event callback and drops the ones it does not want. Poll query-status instead, so every destination event reaches the callback. Signed-off-by: Denis V. Lunev Cc: Peter Xu Cc: Fabiano Rosas Cc: Juraj Marcin --- tests/qtest/migration/framework.c | 6 ++++-- tests/qtest/migration/migration-qmp.c | 10 ++++++++-- tests/qtest/migration/migration-qmp.h | 3 ++- tests/qtest/migration/migration-util.c | 8 ++++++++ tests/qtest/migration/migration-util.h | 2 ++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/fram= ework.c index b7aef6b21c..1cf18233f7 100644 --- a/tests/qtest/migration/framework.c +++ b/tests/qtest/migration/framework.c @@ -667,6 +667,8 @@ static void migrate_postcopy_complete(QTestState *from,= QTestState *to, MigrationTestEnv *env =3D migration_get_env(); =20 wait_for_migration_complete(from); + wait_for_migration_complete(to); + g_assert(!dst_state.migrated_before_resume); =20 if (args->start.suspend_me) { /* wakeup succeeds only if guest is suspended */ @@ -695,7 +697,7 @@ void test_postcopy_common(MigrateCommon *args) if (migrate_postcopy_prepare(&from, &to, &hook_data, args)) { return; } - migrate_postcopy_start(from, to, &src_state); + migrate_postcopy_start(from, to, &src_state, &dst_state); migrate_postcopy_complete(from, to, hook_data, args); } =20 @@ -842,7 +844,7 @@ void test_postcopy_recovery_common(MigrateCommon *args, migrate_set_parameter_int(from, "max-postcopy-bandwidth", 4096); =20 /* Now we start the postcopy */ - migrate_postcopy_start(from, to, &src_state); + migrate_postcopy_start(from, to, &src_state, &dst_state); =20 /* * Wait until postcopy is really started; we can only run the diff --git a/tests/qtest/migration/migration-qmp.c b/tests/qtest/migration/= migration-qmp.c index 437b5eaeff..77befe1027 100644 --- a/tests/qtest/migration/migration-qmp.c +++ b/tests/qtest/migration/migration-qmp.c @@ -549,10 +549,16 @@ void migrate_cancel(QTestState *who) } =20 void migrate_postcopy_start(QTestState *from, QTestState *to, - QTestMigrationState *src_state) + QTestMigrationState *src_state, + QTestMigrationState *dst_state) { qtest_qmp_assert_success(from, "{ 'execute': 'migrate-start-postcopy' = }"); =20 wait_for_stop(from, src_state); - qtest_qmp_eventwait(to, "RESUME"); + + /* Poll so that every destination event passes the event callback */ + while (!dst_state->resume_seen) { + qtest_qmp_assert_success(to, "{ 'execute': 'query-status' }"); + g_usleep(1000); + } } diff --git a/tests/qtest/migration/migration-qmp.h b/tests/qtest/migration/= migration-qmp.h index 940ffd5950..f275cd7692 100644 --- a/tests/qtest/migration/migration-qmp.h +++ b/tests/qtest/migration/migration-qmp.h @@ -46,6 +46,7 @@ void migrate_continue(QTestState *who, const char *state); void migrate_recover(QTestState *who, const char *uri); void migrate_cancel(QTestState *who); void migrate_postcopy_start(QTestState *from, QTestState *to, - QTestMigrationState *src_state); + QTestMigrationState *src_state, + QTestMigrationState *dst_state); =20 #endif /* MIGRATION_QMP_H */ diff --git a/tests/qtest/migration/migration-util.c b/tests/qtest/migration= /migration-util.c index db66d8b24f..4b5663c5a6 100644 --- a/tests/qtest/migration/migration-util.c +++ b/tests/qtest/migration/migration-util.c @@ -178,6 +178,14 @@ bool migrate_watch_for_events(QTestState *who, const c= har *name, } else if (g_str_equal(name, "RESUME")) { state->resume_seen =3D true; return true; + } else if (g_str_equal(name, "MIGRATION") && !state->resume_seen) { + const char *status =3D qdict_get_str(qdict_get_qdict(event, "data"= ), + "status"); + + if (g_str_equal(status, "postcopy-active") || + g_str_equal(status, "completed")) { + state->migrated_before_resume =3D true; + } } =20 return false; diff --git a/tests/qtest/migration/migration-util.h b/tests/qtest/migration= /migration-util.h index 694773e594..f195aeea48 100644 --- a/tests/qtest/migration/migration-util.h +++ b/tests/qtest/migration/migration-util.h @@ -22,6 +22,8 @@ typedef struct QTestMigrationState { bool resume_seen; bool suspend_seen; bool suspend_me; + /* postcopy-active or completed reported before RESUME */ + bool migrated_before_resume; } QTestMigrationState; =20 bool migrate_watch_for_events(QTestState *who, const char *name, --=20 2.53.0 From nobody Sat Oct 24 00:32:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790939069; cv=none; d=zohomail.com; s=zohoarc; b=RwRgA1QzKefSyxj1OSAxhmP9N2+NGry9+k404b0LCD5IbwQ5GRcCZQIWRDTw/rGy0mi3s/qR4JTMQd/l9H7dFQ107eIRrh5TSqkzGHvBX7In8QeGfZrUEXZrfiNXFItKANxAUpM7yowzt4bMbAsS9qbF67NynxebZikaciAxDWg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790939069; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9tN+AxFYSB1fAa8V08Lpm1ZM27JAKqWIOqROhNIAGb8=; b=H/xlf9qg4nJTziNWzEsOEdDH4cTI4t0qPW2w7VLV8SFt6IDWsqQmr4mwuDRYfFa1BtfK5lBKwLWRL2P8EO1JeY0RMUutPWNQgN1k17RRCrwDqhBv24URTPfkN7aoXkxHg6ZVTxp59A0QoJUS/SS0Q+1aCsGkKHK/HYdayuyJN9g= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790939069564376.4525142458458; Fri, 2 Oct 2026 04:04:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xCb3Q-0001XY-G2; Fri, 02 Oct 2026 07:03:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xCb3O-0001WD-Lz for qemu-devel@nongnu.org; Fri, 02 Oct 2026 07:03:50 -0400 Received: from mail-wm2-x11.google.com ([2a00:1450:4864:31::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xCb3M-0008VT-RP for qemu-devel@nongnu.org; Fri, 02 Oct 2026 07:03:50 -0400 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-4a00d8bec5aso24683405e9.2 for ; Fri, 02 Oct 2026 04:03:48 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:9f21:a362:21c8:d9a1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a03ff3cab2sm24533785e9.2.2026.10.02.04.03.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2026 04:03:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790939027; x=1791543827; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=9tN+AxFYSB1fAa8V08Lpm1ZM27JAKqWIOqROhNIAGb8=; b=hMSDut8FjMGKUJAPtqLdAB6DFT5wrVnPgOfi+rCb65Sc5iIS+52Fw3dadfh3beL9Sy b4CcIajodwsKqH4V6TvqCoP8eK2npm1cUQhHSLA9HtGD9TGii9hTmJuXDJC/LQoMjyfr Iq3BoUSrKwYa95L8KrwTX89usUxE8VElxaRPVftg6KPG2hh5E3BJRL+fncdqTHwbI/vE dWPV05/s8QjUxG2y6zeDLBO90DxBRjDd5w3c4kGjf9EoluX8s+UPlr4koarOXE8hE9Vp 5pwerpXm/IYBQ003rRdE3AQ62L30CNDKMVIyrm7gADRjwIYJhxSEdXMZ4Zm+KEELyikZ 2vnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790939027; x=1791543827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=9tN+AxFYSB1fAa8V08Lpm1ZM27JAKqWIOqROhNIAGb8=; b=ysSPyNHRLwHn5smu5rQZ2DCgcyq/YkWbz1ouXpO9NZNAuNZYKpppVJQEo17cdAndAB hyOxDv8xU+bjCiJpDB3vo1sa4IIW84LWw5wy7WDnY5uQG04tqmDAQ6VKZv1yli2q/uVj s34Lv0Auc464xyAffUlTq35nKyOnCsvhhlXt482TFc1FUW4ylz64Ovn+8TqFXB1bVCE3 ot1v7dPf7Aem9y6UOtN02cSOby1XRb43PYdrmOpPs9QknomLSQlc3/f9Xx1uaHRIz08+ Xszw9vfXYMHNnPl4bkZhEOgY0Q3PDfUERfKASg01CQcw0GSB0fvKhJpUKFyD+LsrCp1n e8AA== X-Gm-Message-State: AFuF++n6Sh+DKHBNNtzfbbVyA3+deNKdoCx+7yWanNud86zKWmEICRUk lcqNV033U4RqY7vkkNGlXTldtpiiPeaPpQiWE8JTc8j+/rjxkjf2GmY9rVTV1QspNvqstNRdj/f Q7Bp5 X-Gm-Gg: AYBFou36KNPSuUZPUeyZz3HR7smVl5Vl6JCtd9cWERnrfs9o2xP62Zs91MOc2L57IJO X7qJF4AQjCIemhldJtIGcY3sIjPSVoKlGDi1ag8HrHWeHF7FQbTvyFUBTc7pPNbLaMdQQMtWr2E PKcG5rlfT81HoLrPRYZmsahjVek6tCAlU2KZonUOc28tTVrrn8AlHlS29HgjHgvNOy7aXkArcZ2 rr+D14y9BG0bTE4EbEOUTISHX8Fobe7o4ve90iez3TFzoxqcIqbiTzBNbCEkvCeR6RhVaq+0Pzo c35SHpVTpWIJ6r1RM1AU0LswIrrTdxTPnfAmPOIGa2mlxhj1n/r4UH1imfdpgil2e8mCcRq7m0R LXYnuKxwu0UBWdcbO8WPfstUE0iwPQnfHrhvYD3GU1FkaXExS+ka1GcelmXNQR3AhOicuv6kmiN cfc+WyTe8WrbxykN/711cjtRFoDsgEDPxBqZPXY0SfyN3sR+xlSefJ87IemwC5U0VwOvw= X-Received: by 2002:a05:600c:1d09:b0:4a0:37d:9e21 with SMTP id 5b1f17b1804b1-4a0276ed19amr41398095e9.29.1790939027268; Fri, 02 Oct 2026 04:03:47 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Peter Xu , Fabiano Rosas , Juraj Marcin Subject: [PATCH 4/4] migration/postcopy: answer the package-loaded ping from the run BH Date: Fri, 2 Oct 2026 13:02:58 +0200 Message-ID: <20261002110258.1835979-5-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261002110258.1835979-1-den@openvz.org> References: <20261002110258.1835979-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::11; envelope-from=den@openvz.org; helo=mail-wm2-x11.google.com 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_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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790939070552158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev Commit 7b842fe354c ("migration: Introduce POSTCOPY_DEVICE state") keeps the source in POSTCOPY_DEVICE until the destination answers the QEMU_VM_PING_PACKAGED_LOADED ping packaged right before CMD_POSTCOPY_RUN. The destination answers it from the generic MIG_CMD_PING handler as soon as it reads it, so the source's postcopy-active means the device state is loaded, not that the destination has left RUN_STATE_INMIGRATE. Management acting on the destination once the source reports postcopy-active can still race with loadvm_postcopy_handle_run_bh(). Record the ping in the MIG_CMD_PING handler instead of answering it, and send the pong at the end of the run BH, after the run state change. The wire format is unchanged: the pong only arrives later, and an older destination keeps answering at once, so mixed versions interoperate. The cost is that the source stays in POSTCOPY_DEVICE for the duration of the run BH, including block layer activation when the destination autostarts. Suggested-by: Peter Xu Signed-off-by: Denis V. Lunev Cc: Peter Xu Cc: Fabiano Rosas Cc: Juraj Marcin Reviewed-by: Juraj Marcin Reviewed-by: Peter Xu Tested-by: Juraj Marcin --- migration/migration.c | 1 + migration/migration.h | 2 ++ migration/savevm.c | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index 8944acf3cd..f93f99f30e 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -495,6 +495,7 @@ void migration_incoming_state_destroy(void) migration_incoming_transport_cleanup(mis); qemu_event_reset(&mis->main_thread_load_event); qemu_event_reset(&mis->postcopy_run_event); + mis->postcopy_package_loaded_ping =3D false; =20 if (mis->page_requested) { g_tree_destroy(mis->page_requested); diff --git a/migration/migration.h b/migration/migration.h index c65212ff63..80401391f8 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -110,6 +110,8 @@ struct MigrationIncomingState { QemuEvent main_thread_load_event; /* Set once the postcopy run BH has changed the run state */ QemuEvent postcopy_run_event; + /* QEMU_VM_PING_PACKAGED_LOADED received, answered by the run BH */ + bool postcopy_package_loaded_ping; =20 /* For network announces */ AnnounceTimer announce_timer; diff --git a/migration/savevm.c b/migration/savevm.c index bc1bc98a0e..e20471892f 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2267,6 +2267,10 @@ static void loadvm_postcopy_handle_run_bh(void *opaq= ue) /* Already POSTCOPY_ACTIVE without a return path or in fast snapshot l= oad */ migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_DEVICE, MIGRATION_STATUS_POSTCOPY_ACTIVE); + if (mis->postcopy_package_loaded_ping) { + mis->postcopy_package_loaded_ping =3D false; + migrate_send_rp_pong(mis, QEMU_VM_PING_PACKAGED_LOADED); + } qemu_event_set(&mis->postcopy_run_event); } =20 @@ -2618,6 +2622,10 @@ static int loadvm_process_command(QEMUFile *f, Error= **errp) tmp32); return -1; } + if (tmp32 =3D=3D QEMU_VM_PING_PACKAGED_LOADED) { + mis->postcopy_package_loaded_ping =3D true; + return 0; + } migrate_send_rp_pong(mis, tmp32); return 0; =20 --=20 2.53.0