From nobody Mon Nov 23 04:44:12 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=1794335614; cv=none; d=zohomail.com; s=zohoarc; b=llxsuwzYYKsSHG1mfKWOaAcxukeGHOXaORBxzh276AANX940z9XyRkoTZDdgq0OdMORttCh8hZxQKUCVH5gwoMhmRpxn3b5oPD8Ht7A3vpl8agojJVxaDvXX/ZcX/Dela7wcIqiBWT3gBieVHdMamQea9PGZ+0tVkyzH+iFulnE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794335614; 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=PPzcitYLzdgLdpiyw0A2TaajXXBAe50hLVDnRF1w7+E=; b=dPOjOKTfC3P8dKx+EiLWxdMSdAqmIvQeBwfZ4+v36i33FPmeeO1egrzGfstyMgeoAlNkvm40FKBbVzyzM2TiuGOJDFMcF7LNP1mbFuj3BLN++8o8J+D4MobOt84TWQKGp2k10mWPQA5lVoU/JyBJjcr/gGdbXmNfFybSvNRi/5g= 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 179433561475875.2286511617151; Tue, 10 Nov 2026 10:33:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQqed-0005NI-KA; Tue, 10 Nov 2026 13:33:12 -0500 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 1xQqea-0005L5-E2 for qemu-devel@nongnu.org; Tue, 10 Nov 2026 13:33:09 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xQqeW-0003Mc-Aa for qemu-devel@nongnu.org; Tue, 10 Nov 2026 13:33:07 -0500 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4a1fbd52ab6so16017495e9.0 for ; Tue, 10 Nov 2026 10:33:03 -0800 (PST) Received: from athena.sw.ru ([2a06:5b06:b600:300:4f78:6441:d0f1:22af]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-498363df7a5sm6384827f8f.37.2026.11.10.10.33.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2026 10:33:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1794335582; x=1794940382; 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=PPzcitYLzdgLdpiyw0A2TaajXXBAe50hLVDnRF1w7+E=; b=XTuu5zJ+Cv2Cv+dhkw1ZHgsJpKYCdugPMgPshDLpCt4NMZhMqGz5T3kstRjizbRzba guTlyZWlCQzfhZId4misoODcRHqCHTtfYzaD6sgb5B7lrKf+92kH/HBZpcblMFU254VP dCYbupTsyCgQBoLpjmDnZhSW7lPvEwsraR7sNUO81RcSSsG9JXnYmPpRLDm0MOI/n5ne HHsEJSi6nS+LFl7vVdVrK+PmQiNW9EpA8377qb7fkemA1cRzO/9EBuO9jCF8BnGm0kP0 +riIiZ+ND3WPjDVFxg5CmzpIFU+ai1vqa/qRv0sn5NVf/JEREmLvZtUHGyNLcKFrs0mW JgtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794335582; x=1794940382; 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=PPzcitYLzdgLdpiyw0A2TaajXXBAe50hLVDnRF1w7+E=; b=bUIcjdJhaLm6PcEZeB+iFHQUxp+ZCVVKICOL988/5vJVVlzBZviCZLhfHnbjiRxms6 X4XNaYTG4A6NF8bwuRtkb/7Dw4XYC2qeWGPB2BCFdAMFUQVqKn7JucAAyqG8p1dZCvAr lvAf1srnaSs6JKhnLNlycKw6YSJ7NDNYnE1Z52Secx3cDTg6eIp6FdbD3ner5+Yg0vqJ dCqeSDGiR5TbU9kmOd5cGxSbhfkqhHHD05ot5TEwA2fl+1JW8vsGAwIlkcQzPoTG72VU 3JSJVAtklZl3IKYBtY31F2o89t7QXUOvpKidiBLAyPNVxW0+Bqv74fg+dcr8H4VVS4lP hecQ== X-Gm-Message-State: APuU4Z8m5jQqD31KJA1OfwvQXD/DfR/5/V1+i2td/TTkvM+sU3dG5Oj6 3M3nJYMtJ7omCNacDZtZJrx1iG5bZPtEyg1HRvF6ewxrfqQbWWD0bjvuUX6yyuf+6yTzHBsAQpR EINtO X-Gm-Gg: AYBFou2ckoWhGPyAsRmXvnptYVzlxQkspv8C1Kw36BTtn0RFCnFSM+610xQRAOtuK3d IHTdoAH3OqZUgPKW2p7k85M6VvyWYTbp9ykHm1bX//L/OVF0ssYyf7UWebB+nPHQIyXc7XC9RqQ 6VQqsaOryBLI6WTKtHEopLzbIJCQm1N+ElsOcCZgEPd5wnCZp3xPF5MXIlZwhBNir6c/dbP9Jh6 fYki7AXqORjEWMtKoFu4ROPOD2d1qkiwY3KQAXjqq6gxDAQnzYs8UjPUaqtYTPnoP3hU6b7r9eO AKvkoiju0WrOB2/OuOYMmIa/EbEZkn9W8wzBjzWAMAMCArK0VL1dEA+qd7kTde/cNHHzjLvemda l6Th3PK+f4aEYlK+cRuUhBXtZTox4Ysdav1zxsUmIwBv9W/ZGNwjAVX5CmrGVs8v2C6nmrpDKTq olpDx+AnAiuYIpX8ssPno/YjHwUrlDJ0uP174X8DpCF/Y5i+ILrROaH8wrAqpIKyFMM+fI2wnbP Am8Fc1waZIEsgepWQISP4eBezoBusxi4X4aD0ryqMRKgRlNQQrGVkxKaeq7qQSHopxApmujp9N3 Tv+WiQaLBN5muh34QMIm9MMwWQ== X-Received: by 2002:a05:600c:b8d:b0:4ba:761:97a1 with SMTP id 5b1f17b1804b1-4ba076197d0mr38103975e9.14.1794335582257; Tue, 10 Nov 2026 10:33:02 -0800 (PST) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Peter Xu , Fabiano Rosas , Juraj Marcin Subject: [PATCH v2 1/5] migration/postcopy: report COMPLETED only after the run BH has run Date: Tue, 10 Nov 2026 19:32:53 +0100 Message-ID: <20261110183257.2930908-2-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261110183257.2930908-1-den@openvz.org> References: <20261110183257.2930908-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:20::332; envelope-from=den@openvz.org; helo=mail-wm1-x332.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: 1794335615666158500 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. Once CMD_POSTCOPY_RUN has scheduled the run BH, set the event at the end of the BH instead. qemu_loadvm_state() keeps setting it in every other case, including a load that failed before CMD_POSTCOPY_RUN. The postcopy state it checks only becomes RUNNING on the main thread, right before the BH is scheduled. Signed-off-by: Denis V. Lunev Cc: Peter Xu Cc: Fabiano Rosas Cc: Juraj Marcin Reviewed-by: Eric Blake --- migration/migration.h | 2 +- migration/savevm.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 057c85d611..b223480d28 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -127,7 +127,7 @@ struct MigrationIncomingState { QemuEvent thread_sync_event; /* * Free at the start of the main state load, set as the main thread fi= nishes - * loading state. + * loading state, or in postcopy once the run BH has changed the run s= tate. */ QemuEvent main_thread_load_event; =20 diff --git a/migration/savevm.c b/migration/savevm.c index fe94ba96e4..7d0276c1d7 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->main_thread_load_event); } =20 /* After all discards we can start running and asking for pages */ @@ -3148,7 +3149,10 @@ int qemu_loadvm_state(QEMUFile *f, Error **errp) cpu_synchronize_all_pre_loadvm(); =20 ret =3D qemu_loadvm_state_main(f, mis, errp); - qemu_event_set(&mis->main_thread_load_event); + /* Otherwise loadvm_postcopy_handle_run_bh() sets it */ + if (postcopy_state_get() !=3D POSTCOPY_INCOMING_RUNNING) { + qemu_event_set(&mis->main_thread_load_event); + } =20 trace_qemu_loadvm_state_post_main(ret); =20 base-commit: 723622bedb0b423de7d1c61ebbe6e7a71934949c prerequisite-patch-id: 67b7337e86202ef7509fc53ff8915a814a477e3b --=20 2.53.0 From nobody Mon Nov 23 04:44:12 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=1794335646; cv=none; d=zohomail.com; s=zohoarc; b=ESGWON3Fs+/C1OY5iMPGZtN5bhmlgqQtc4beZBc0gOX09cua81eAJOG85v+iVmQSZ9OAF1Nj/tm+F8vLj+++oFfZmo1SxXcvIJubZZCwzj4/x4Jekf49xHfaoz1QM2a+mfwZpVyIxR1UZOqQdcxm6v9o3pjAV0FYr1M2blW/Q4c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794335646; 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=isfZxjU3qOEiLMN4EsyJzrszmQX9hADapqRpoX6Eh3M=; b=hbc8XPXtBexzSgJ4UPeUJYjior19lTWKZyGAdH6DSWrCn99YiyfUDl/Sdnjhzdt2GdHCqP7/OslIN8jtGVgYh31KmdzJem3OIm2KZrM80fXpNSFrcNSphqJ6H4qDHQebK5y1AZeV6oI4O95Lkp0dcQSotswbgpEnQ/fEvQyaTrw= 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 1794335646103323.73912054385926; Tue, 10 Nov 2026 10:34:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQqec-0005Mh-DQ; Tue, 10 Nov 2026 13:33:10 -0500 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 1xQqea-0005L7-EG for qemu-devel@nongnu.org; Tue, 10 Nov 2026 13:33:09 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xQqeX-0003Mk-4Y for qemu-devel@nongnu.org; Tue, 10 Nov 2026 13:33:07 -0500 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-48e47347279so1562818f8f.1 for ; Tue, 10 Nov 2026 10:33:04 -0800 (PST) Received: from athena.sw.ru ([2a06:5b06:b600:300:4f78:6441:d0f1:22af]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-498363df7a5sm6384827f8f.37.2026.11.10.10.33.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2026 10:33:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1794335584; x=1794940384; 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=isfZxjU3qOEiLMN4EsyJzrszmQX9hADapqRpoX6Eh3M=; b=dhi2mo84NeuuUIZMGXWlWUWA72ksEjw3f/fxW+H682TBzj2zYSAxRmUcMZTyFp9B1V T9QZrDIGqB1UJRufa5BQxj6h7DigAhnBayTTjLeh/VW63R1/92loyuC2yZJ9XxtTuw/h TSdLbUTIjZriscNJuA3XdfdsCcsL3+VQBKHX3Ojmj5XWRxzQGSrBZZwMlmdLX0QpAf94 6oMmeE/8S97pvqrWcU16HQ8O//l4mO+/+za5751OQvnoFoN2j26r1Po32uS3zhft1qFy jrX7H5Bu+i/x4V44iilBjMrrovMDWjevxqQnITFhnkgkVQgGgG+HQstaCqtIJMNGgt11 kTBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794335584; x=1794940384; 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=isfZxjU3qOEiLMN4EsyJzrszmQX9hADapqRpoX6Eh3M=; b=OD21Mi5UG7fIZ8sLp+mtdvp7q8C3Zx2WMN5XzE59V9nsDrQ+Yhn575AjGlPtUf8KC/ 9+Wb9gw/EJd7HfzONaCIWZwDdxWitjRHRXlakuiGn6iKNU2Y5gGndhiXJluoZgLi8OJI DE50c37c6qR+mzlYy2+JYT5c88XM1InKd7xoUYZvgdK+6t29Grqcm9EAwZMHFhN7RtNC q0/SCDcOq0wICe6HjrwjBAvaPP4QF2Cf3WLOpSsMWlbZUuHTCdVQJLkBlxkPPvv3VJrZ UGfAsiZ0Njv39W45Bz+WrucMtYyOUqU66h/ZqU0vNcOBsXrURJPxXEyC9U5f6Jns10d2 gNFA== X-Gm-Message-State: APuU4Z85RIoB5uc5i73pG3ZHGlGgAnLW7lPXpDB5HGs4a+FNmRIjOfkD sU+gKYJffZTVaz8vj+EfwFDup95+stmra+hJD0TzSLUtCwizl/lCN0NOtr3EODTt5hEJlYnBJKT C18zt X-Gm-Gg: AYBFou0rf64vlld7t9xd9lx6TCo/LzHLZB4sVEGpMrb/A3Gp7Vx0CVdZOxFqeb3y+Kb yx9pzv0SGeOnqVtB3t13+075m5oAXzIm0ZCS9P4FMnSafLG/WMYapcEdeKjlluKA2lzcj8HKPgX ZJ1ZrEx9f+LveW93JPlzdsiyCGH1x577jnLOgmRamofFi+QN1EfM4c3CGeaJoqxwgEaerA6zdfI B2nNsqgK5k0fkDet4ucEtCupZxhsFlt720xjMJRvim5cKnEVdFv2xOyWMLuc9+N29gCIDd7je56 mhI4hcZ+xfR4qVF1syctOwrt7XTkGHm0wvTtSGi342K8A36BiORaX5SOMtAEQCi52ujOuawopRX CooM/Xocn6lF2Nfkow2DVE08U07GnDrru4EF4rB+dC5KUE5ZbRFafItE3hO6dqcmf9f7hviABty DGroI5NNtv8eF6cgCQUHJVNhPpE0ozzJwd/w2EUoMlOtvBLTHddPXkCNSVAS0/boVzegCFKQ5vF zhbOMkfLvChILP8Yb5xVzjA6GeI4bUuCELGiJVDJAUHc7ns5X4KLoHZcDm8WA9mNglc+5hwTPjj 846vBi/wasBL7enxVeaENYmo9RjHWpsjqU49Xd1KvbAIZc4= X-Received: by 2002:a05:6000:1a8c:b0:493:5d67:499 with SMTP id ffacd0b85a97d-4982e737b02mr6697722f8f.14.1794335583577; Tue, 10 Nov 2026 10:33:03 -0800 (PST) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Peter Xu , Fabiano Rosas , Juraj Marcin Subject: [PATCH v2 2/5] migration/postcopy: set destination postcopy-active in the run BH Date: Tue, 10 Nov 2026 19:32:54 +0100 Message-ID: <20261110183257.2930908-3-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261110183257.2930908-1-den@openvz.org> References: <20261110183257.2930908-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:20::42b; envelope-from=den@openvz.org; helo=mail-wr1-x42b.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: 1794335647779158500 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 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 7d0276c1d7..600db7a1ab 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2263,6 +2263,12 @@ 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 */ + if (mis->state =3D=3D MIGRATION_STATUS_POSTCOPY_DEVICE) { + migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_DEVICE, + MIGRATION_STATUS_POSTCOPY_ACTIVE); + } qemu_event_set(&mis->main_thread_load_event); } =20 @@ -2277,11 +2283,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 Mon Nov 23 04:44:12 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=1794335633; cv=none; d=zohomail.com; s=zohoarc; b=Rr8Iy7pO6aUnFzYNN8xbNyEr7V4TJOduZbip5PlW8eTOatcyRotH+fJN+XW9b4WXd7h/m+6RVB1fkgPHsaPt26qc1WGeYcKwic9NRWBGp8LFQrqZY32IZztvbphZp7lDIBDfch3GtCfFCPSBWfCZD02ss8/y28IU6OKC1mBhPrk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794335633; 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=IM9TYdeOK3qc/JigrRusdri0gCIwrlkHCBRkW4UFPE/xq5EcY1Fh5AOw5oJzA/wRZo1iTbRUzkbSsXsHxNZt8EO4AHwnEHVhm6csWiJIttatMRLsDzKbCfPOhBHYyGS+OyUMtKhpL32wQvG53jiT2G5rXC75wnxZi1UVmEc9PPU= 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 1794335633461729.1626703712706; Tue, 10 Nov 2026 10:33:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQqeg-0005OZ-Qp; Tue, 10 Nov 2026 13:33:15 -0500 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 1xQqec-0005Mg-9r for qemu-devel@nongnu.org; Tue, 10 Nov 2026 13:33:10 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xQqeY-0003Mp-JE for qemu-devel@nongnu.org; Tue, 10 Nov 2026 13:33:09 -0500 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-4918c2d727fso1298645f8f.3 for ; Tue, 10 Nov 2026 10:33:06 -0800 (PST) Received: from athena.sw.ru ([2a06:5b06:b600:300:4f78:6441:d0f1:22af]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-498363df7a5sm6384827f8f.37.2026.11.10.10.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2026 10:33:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1794335585; x=1794940385; 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=K9aTtn2ycXb2idX78Z6daLGk3QY2mfxpIvb1U1NoNtmLhxZfMwyGLOpDsW5Z/klIb1 KWfG8AjxsZ1KgyLzScQJnLMMhzuE+1ouJElJQsnYTrKffVNdaCeiCnxyf/zf5NwExxC+ 4STwqVlv4dL8CBUFVHDj/0W/E3IiBNx1I7oqEH+99HucvodLslhHrg0XF0HrzhHcb0Yb HS1yN3QzTW2NfQJSXug/EzI8rl2eLvAL8dd9zZ/rt85me7Ndnuo058BiVVedkHKiYyNc z5T4fiJ08ulWJdQMpEQ4E5HqPxWh6aDKD6s4bbhfRJ6rUaLDHJvgfWxf1yyd8l44I2t3 xHWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794335585; x=1794940385; 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=WnB7i/mGo1KbS0IFFoCc3oYH5tYG/s1VJPb2Qv+SbgcfsCish1SsW+NhYxa/4c6f6M C4UhbKbcHGlt1MYxPbObarBgdEB8n46mfDI2QsF7SHVaJmRmFIYFiTODA3AOkyrAL2mM Rc9ynSLjt/xi+rSGd1pbsJiYGYVypYJ4gVGQj/LE4uLBShyh9STal++4q4YPq2hnMHCi CojoiDU3feqJGjT+rFaHJqwDbY52F0TcrSCvmrhsN8f1Cd/g/FwPbjLasKvWdGFgAUBu TAuGSXRHVRkCS0qr7ac21AobQniqVNFYiundVnM7QEKw4dfSiYU5Gf3UiUPLblrxIoSf akPQ== X-Gm-Message-State: APuU4Z9J9CmXqxugKMiy/dDohhjB857oVv1pPLE0mjrBcK63QxDKrQyh Qiggoydw6Le6xObGCak1aXHuHF3DN0DXykAN+DfM2hvmDogiIAf0nGBi7jTHx4tPbiKr9nNwtfs pSnh/ X-Gm-Gg: AYBFou2YZH9lsaN7I55Ve3VRZujwXX85XjpISiPYusisu1Ok1Az/7rF1ZJgE67d4dRc cCiLMS+3ycYnjsMzvefMoRP5YmQK3AG9CH6AJWTjIi4nZqU4KTgIdY51AUUTC9IOXaIC00yP+ts nxRor8g5CCEPAdocKmHXgS6hKe5iR8yeDagh8eJ147mE6S8l1b3x5aGNqU9/77ijkqoM24N4O7Y X2tqwZxvyfiJxv7fIX+sacM7xPJOz3N/sp6Jhv1XW5Lomt+u1RRyG3xhFPIxEL1XhzdmaoHFVad BV5Z0atde9QLOFF0zuL7DAcGHvevqtrANpswJOC8o+C1QYMHasaig1R4uYLacNe/xErVkOAQuPy pGWgq92FkRmJ7xubLR21U65Kz0cddjKFqKi0k6tzIJt42pZQrF9oq8ItapltdQuqlNaO1BWp+0k eN+lHBXJmhG5FoAcyTpoS1xNmA3z/diuV99q53VS5reMK2LtewC8/8bUPiltkIQgTxjeskpokdJ 8Q/UKBfvmTH9VOifEiGJJYt+cB8rMOMre8dng6Dw0YCBRp+ZwbiO5o6cJLb5dIP8w0w8MWsafCi LnOfb5a/m7IX8KfOOOgU6WfCGQ== X-Received: by 2002:a05:6000:3c5:b0:48e:e98:8b64 with SMTP id ffacd0b85a97d-4982e82c23fmr6266416f8f.19.1794335584874; Tue, 10 Nov 2026 10:33:04 -0800 (PST) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Peter Xu , Fabiano Rosas , Juraj Marcin Subject: [PATCH v2 3/5] tests/qtest/migration: check the destination run state in postcopy tests Date: Tue, 10 Nov 2026 19:32:55 +0100 Message-ID: <20261110183257.2930908-4-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261110183257.2930908-1-den@openvz.org> References: <20261110183257.2930908-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:20::432; envelope-from=den@openvz.org; helo=mail-wr1-x432.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: 1794335635797158500 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 Reviewed-by: Eric Blake Tested-by: Eric Blake --- 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 Mon Nov 23 04:44:12 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=1794335666; cv=none; d=zohomail.com; s=zohoarc; b=h0+0rCIycN5d/cU89Zm6qAQVyNan+sbEPILvwvdMybHRzBjb216dkYS1Paey4f4cctwtLRZek317bRCsz2lRGAv1pH4H5abe+P+dektd3Ko7JZlxSmyNmBKUf09iNSD5mfKjqVFDVebV1b5SxFAhAWqu3YsvW/26wK7PiqHtrJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794335666; 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=AXXVM2yp1eVWA7kGXw2w9aDX2Sr2hnb8YxrJCeVkjsc=; b=fHCh/yiqEidbKCzjZPsrjPIgcN+4IhTKPYlfG+WFtNcMeZL5wJv7VOdoW1ZYqvhOvva08bTPztDXhP45G73Rg6ghTG3Qwnv/Z/+dKmq+wXK4uzy6Zjq7E0fH+FHv0WxRkMrxnljV2LzkHXrW8GB/NjE+ZO0BaN2CWJZXd/9dERs= 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 1794335666664926.1332264978832; Tue, 10 Nov 2026 10:34:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQqeh-0005Q2-Sg; Tue, 10 Nov 2026 13:33:16 -0500 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 1xQqed-0005NL-Nx for qemu-devel@nongnu.org; Tue, 10 Nov 2026 13:33:12 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xQqea-0003N9-9U for qemu-devel@nongnu.org; Tue, 10 Nov 2026 13:33:11 -0500 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-4918c2d727fso1298653f8f.3 for ; Tue, 10 Nov 2026 10:33:07 -0800 (PST) Received: from athena.sw.ru ([2a06:5b06:b600:300:4f78:6441:d0f1:22af]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-498363df7a5sm6384827f8f.37.2026.11.10.10.33.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2026 10:33:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1794335586; x=1794940386; 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=AXXVM2yp1eVWA7kGXw2w9aDX2Sr2hnb8YxrJCeVkjsc=; b=eHRMsDAlOX3ISnKzeL/uk0aNGE+EZSIxKJBLtBMKj+4NvCtQ4/IysgmRsNDcGZk76O wVIhVxXkxAIh+4kcr9+5rKebCnufMoDQrYpNWaIxKaTcKOfwlPJoarfj+icDcDtrUffl FfBYt+4bwUi4TJI8zVOIsOi0a/31k+g046sWu9274Qn/iQnq3WcpRWNfwJN1Qctcaup4 itWiJVpcsPaeBmSxYS/p7siZJ6/gLOa/lOofmoyvceBNp/W+aUc4aJMeFGs7ceICWZ27 25iXtqUQ06SqPfwIYrF5EVRlbtlVjqMlxoDaIhIRHwcHKPeX4w5O6Rqr28WsyyPKsX4S Vc/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794335586; x=1794940386; 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=AXXVM2yp1eVWA7kGXw2w9aDX2Sr2hnb8YxrJCeVkjsc=; b=pMKxi9qNm+h1RHJ7GT3mkaAgmmU4KN1VtE4XypZFbPc3Wi88ONqjxUa5Bf7+5r9lCT TgmCauXgyjPmjpk69IQQBbmVowSck5s1SPWae/kscbEj7c9HSOXtBIJWjKlajGWj7zI9 Zy9eIuytoriCylTihM+G1I34KJEJC3swQQdt1S/Qs92SKV2k49ZtnHA9mto3MTtyo7fB pLTW6Z0bSUlVbcIUwKWv+5QJXxXhTZrjOZMbEZX8fiEr1hyzAlt9f45wx4RPo00Tf2Ft wNVUPojWv7DBUoG5gjH3h8gER43CZMzgn6Bn0OkZotUl2pIr01WkqYONd2eL+kiuVZUd xzcw== X-Gm-Message-State: APuU4Z/Ohb1IdNJSrXVBh15OZgkqGJrdYYrxkwWXRIpbkYDTz5twicUL ufzD8FGOreo3V8iU3ijIJE0V35RonscEF5F4AZ8bG23nvj3CEtcRabbEh+M7/EAsyB04fFdK7UP gPAxL X-Gm-Gg: AYBFou0U1j/PEdAVBbDewr9gw1q+9oqRF0Y9fHbIt2f75sUrezf36GU1Lwt6mIRPS3h n5nhoKKxX6+02HqQbHZ95ou+0g4nmy64Wq7RyDY/quDmWRnkWolTWC8F1aTneFM4ORKePHXEwkV rQ7sj/qPC49hKFocBnqS8wc2qZpaBLuIu/VbdRL8n+8P1KpaVMr3w5O+m6jRqentMSj1CR/BoUQ cI09pVAsMDXtfjruDO9GfrDGjEHvVSeotLaQfBzDnPRYvrH2UZ8NoqOKctrr0uXfQnr426iFjSo b8E2e3mBP3L0gw1rYSx8MkWKXUxr2XMUziu6msXc3Fr+oh0M7t4OXssn8ASDNmwMpQ+E4dn2tcg w+HydZaaHaYFlylASbTNXEazSmbKXGr4AjN3e2PBVnNaHd0AvBbgO3YwYE8TuXFV4IIiIq6Wtw8 356CNuezvCCSu8UFvaVp1Ska1gCCgSD/CV3WYbR+TWUNKAwPmbrrhW8QNTgZtVXGEYxQhss/IjA ila1FTbIxKp78sBuM0+QnzDv2viykwIOX/19qF+hT29kKx5ZCn6TNQIkSv6TwKqOt5tcSMi34kq 7eoHOGGtnxoHInprJSA7JROFXg== X-Received: by 2002:a05:6000:2305:b0:48f:bcdf:6f68 with SMTP id ffacd0b85a97d-498303f104amr7405303f8f.37.1794335586549; Tue, 10 Nov 2026 10:33:06 -0800 (PST) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Peter Xu , Juraj Marcin , Fabiano Rosas Subject: [PATCH v2 4/5] migration/postcopy: answer the package-loaded ping from the run BH Date: Tue, 10 Nov 2026 19:32:56 +0100 Message-ID: <20261110183257.2930908-5-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261110183257.2930908-1-den@openvz.org> References: <20261110183257.2930908-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:20::436; envelope-from=den@openvz.org; helo=mail-wr1-x436.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: 1794335667909158500 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(). Answering early also leaves the source unrecoverable when the destination dies in the run BH, for example while synchronizing the CPU state: by then the source has moved to POSTCOPY_ACTIVE and can no longer fail the migration and resume the VM itself. 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. 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. An autostarting destination that dies between vm_start() and the pong now leaves the source in POSTCOPY_DEVICE, so the source resumes after the guest has briefly run on the destination. The pong cannot go out before vm_start(), which is where the run state changes. With -S, as libvirt starts the destination, the run BH does not start the VM. Suggested-by: Peter Xu Signed-off-by: Denis V. Lunev Reviewed-by: Peter Xu Reviewed-by: Juraj Marcin Tested-by: Juraj Marcin Cc: Fabiano Rosas --- 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 5686209ab1..138cc307cb 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -514,6 +514,7 @@ void migration_incoming_state_destroy(void) } =20 qemu_event_reset(&mis->main_thread_load_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 b223480d28..4adec429e9 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -130,6 +130,8 @@ struct MigrationIncomingState { * loading state, or in postcopy once the run BH has changed the run s= tate. */ QemuEvent main_thread_load_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 600db7a1ab..c1aa3d054d 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2269,6 +2269,10 @@ static void loadvm_postcopy_handle_run_bh(void *opaq= ue) 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->main_thread_load_event); } =20 @@ -2620,6 +2624,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 From nobody Mon Nov 23 04:44:12 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=1794335633; cv=none; d=zohomail.com; s=zohoarc; b=m7XiUWOLSWuFS3p70FGoFgGyYreYgcoyy+EdRmk9rH/uidA1V7Sgoos4mAyENqSFMTApVyN+8LsNc9HkdqYgWVBrsQ61HZvkiskcFCgSErRhYQSPGWRWzx4z46nD/I/W6+Th2AJ9AYi+NkCj4KpO9TqIEsqEft+TfDLYaQLMHv0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794335633; 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=+E13g80s30L9W/BYkJ3BK+ngM9SB5aSpfwYclbX7M68=; b=fErK/K8AbhKx51DFB3Magy2OJOR4VH07AyToqzwrHsQwp5YBqkU7hrfnfoPCWcddCD5jUqCrNsBexmnirqH3wF2ZUDDhoNADlhrR3Ts/8UyNcX3Umk2jJZRrvm+1TF+/w9nkCCp4OFCQtj0iDnOzdeIR7YYoXxBzXYUZ+/mTLFE= 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 1794335633491364.87403493604677; Tue, 10 Nov 2026 10:33:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQqei-0005Q6-Po; Tue, 10 Nov 2026 13:33:17 -0500 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 1xQqef-0005O2-3W for qemu-devel@nongnu.org; Tue, 10 Nov 2026 13:33:13 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xQqec-0003NP-00 for qemu-devel@nongnu.org; Tue, 10 Nov 2026 13:33:12 -0500 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-4918c2d727fso1298666f8f.3 for ; Tue, 10 Nov 2026 10:33:09 -0800 (PST) Received: from athena.sw.ru ([2a06:5b06:b600:300:4f78:6441:d0f1:22af]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-498363df7a5sm6384827f8f.37.2026.11.10.10.33.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2026 10:33:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1794335588; x=1794940388; 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=+E13g80s30L9W/BYkJ3BK+ngM9SB5aSpfwYclbX7M68=; b=Qg/YQwdWfMWNm036hyYQsystU88QPglCK0hCOqAAAqPpY4eC+U0YlZnpmwrkGaJSVV cBO/7O0y3R/hkRD1fbw3W/kmjJNILAP8i5Q9z9zw5xMXdcdQLXgqaVrkMHti/0SpY3d2 U8Neb0+0pi2iv2TOIhxsoMlmzWEL7DL3bT+CchVOBhpydt13w8G7oviBkeqlML8zJ5/D Y9uZL7eyYaslB3vlMK39BnDOhbMoi7PyCHXDDBX6z4btsEdfHwrYDeJF6muJznBz9QvW pDopIQTR0lHz+DEPkztvrb9JEMo95ITl6lLkViBZRNaFR05T1wfGXNylYaTCWSAYKfC0 2S7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794335588; x=1794940388; 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=+E13g80s30L9W/BYkJ3BK+ngM9SB5aSpfwYclbX7M68=; b=W1hX4zn7oGz2Njcjw0Sm7wLxyvjlc8/GBkoMes/XBFRdNZkejn2k+j1pUzeOOPBpq6 FewoyM8QAzcBDvy4Ceo3AwTKTOeV+dKRmcVHTKmCOuaUrthULPQB+baP+rbbz8Dch8bQ D/qPgly4PubeI4eT73BuFMLWVYZvkvycUPrx+rLxzx4azd2vABuGhTaVqL+ETbei1Qyk cCDMXLVe6K6y11HCi9lBeU48OUAOvTxkW+w7P7waR5t26KjQg4/Y4IGieuRhZCoZPOUb zrdsdkrnPqPzRt/BQ0atLLOZ8k9NKNk5nWdJjAas7JSIzwplOZOWR2QD8G3Ciswasy4Z IloA== X-Gm-Message-State: APuU4Z+UR3K/t5PGLliyYfIUuQvCaqMlQ/2yrw5nimLaJVGb3gCGdYp7 OzL6ECmrjRmyBaRTyRGY19S2Buc6CND1u9k9pASU7OFIlbZhLPxqT4jXakRVYH9gaiGqycNcrUz +CIW0 X-Gm-Gg: AYBFou0YObmW9xLxwLIEjRP4MqvklFphWerpS6wjFRrPpnRtrSFU6yPwnYzCzWkLgiY B0W1f4mQgfr5T73ugi58ZIhDleaf3K5WczZ2jtGTE5WMaJQk4rhRopUSvSFPAHRuvcQ8CeXpXuu zef22ZA4N/Px/71M1FprisV5g/AJPVKQTMuOmm+bBIBFXjwVCr+0wQKdC/S+899PCLMEYA9vZdR /FZAJhGuLV7zCzatBYM6gHjjEIHHN/gfOtjt9HvAXlB7y7tRehp8xoMdSle5YcCIvQCRX2kk+fx dv0SXCAztD5KP0kFKTKPMm1hJUpzgoAsDNEwSfTjtHOED76R0WclQ6IbI2qkE0rauj6n/DV92Hl UleUG9vwRYxMjeEIaRwbhOu3sz+e3bG2gm9phrfjovHXXZZSCZCReiECMyTx/33ZgjsdPETd8J2 sZ/BnzPyY+XdRREuuIZrXsuepfNX9MgZNNA8Ajpwuwny1Zn8AlnCBToSdYNDe0pDZzo6nrTUCzv Uj2BCpEUVJR9Hy/EK0yL1JpU/GeilZHXrMrtSZVdEpAd1YbHZlFS+d+JetC3K5CQQ8txntorwZx 8TFlC477184IIE05zkM3pl9YKQ== X-Received: by 2002:a05:6000:230b:b0:48d:fdd0:6ce8 with SMTP id ffacd0b85a97d-4982b28a797mr7863741f8f.3.1794335588148; Tue, 10 Nov 2026 10:33:08 -0800 (PST) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Peter Xu , Fabiano Rosas , Juraj Marcin , Vladimir Sementsov-Ogievskiy , Eric Blake , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org Subject: [PATCH v2 5/5] iotests/migrate-bitmaps-postcopy-test: cover postcopy with a return path Date: Tue, 10 Nov 2026 19:32:57 +0100 Message-ID: <20261110183257.2930908-6-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261110183257.2930908-1-den@openvz.org> References: <20261110183257.2930908-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:20::42c; envelope-from=den@openvz.org; helo=mail-wr1-x42c.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=unavailable 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: 1794335635756158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev The test migrates through an exec: fifo, which has no return path, so the source never waits for the destination's package-loaded pong. libvirt enables return-path for every migration that is not tunnelled. Add a case that migrates one bitmap over a unix socket with return-path, unthrottled, and waits for the source to enter postcopy-active, so that the bitmap really goes through postcopy, and then for both sides to complete. It times out when the destination answers the pong from the run BH while dirty_bitmap_load() holds its lock across stream reads. The existing cases are not run with a return path instead. They throttle the source, which lets the run BH take the lock between sections, and with a return path the source notices the destination shutdown and resumes the VM, as each VM has its own image. Signed-off-by: Denis V. Lunev Cc: Peter Xu Cc: Fabiano Rosas Cc: Juraj Marcin Cc: Vladimir Sementsov-Ogievskiy Cc: Eric Blake Cc: Kevin Wolf Cc: Hanna Reitz Cc: qemu-block@nongnu.org --- .../tests/migrate-bitmaps-postcopy-test | 39 +++++++++++++++++++ .../tests/migrate-bitmaps-postcopy-test.out | 4 +- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/tests/migrate-bitmaps-postcopy-test b/tests= /qemu-iotests/tests/migrate-bitmaps-postcopy-test index 53f7dafc79..a6e21dec0a 100755 --- a/tests/qemu-iotests/tests/migrate-bitmaps-postcopy-test +++ b/tests/qemu-iotests/tests/migrate-bitmaps-postcopy-test @@ -31,6 +31,7 @@ disk_a1 =3D os.path.join(iotests.test_dir, 'disk_a1') disk_b1 =3D os.path.join(iotests.test_dir, 'disk_b1') size =3D '256G' fifo =3D os.path.join(iotests.test_dir, 'mig_fifo') +mig_sock =3D os.path.join(iotests.sock_dir, 'mig_sock') =20 granularity =3D 512 nb_bitmaps =3D 15 @@ -299,6 +300,44 @@ class TestDirtyBitmapPostcopyMigration(iotests.QMPTest= Case): check_bitmaps(self.vm_b, 0) =20 =20 +# libvirt's configuration: the source waits for the destination's pong +class TestDirtyBitmapPostcopyReturnPath(iotests.QMPTestCase): + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, disk_a, '1G') + qemu_img('create', '-f', iotests.imgfmt, disk_b, '1G') + self.vm_a =3D iotests.VM(path_suffix=3D'a').add_drive(disk_a) + self.vm_b =3D iotests.VM(path_suffix=3D'b').add_drive(disk_b) + self.vm_b.add_incoming('unix:' + mig_sock) + self.vm_a.launch() + self.vm_b.launch() + + def tearDown(self): + self.vm_a.shutdown() + self.vm_b.shutdown() + os.remove(disk_a) + os.remove(disk_b) + + def test_postcopy_success(self): + self.vm_a.cmd('block-dirty-bitmap-add', node=3D'drive0', + name=3D'bitmap0', persistent=3DTrue) + + caps =3D [{'capability': 'dirty-bitmaps', 'state': True}, + {'capability': 'events', 'state': True}, + {'capability': 'return-path', 'state': True}] + self.vm_a.cmd('migrate-set-capabilities', capabilities=3Dcaps) + self.vm_b.cmd('migrate-set-capabilities', capabilities=3Dcaps) + + self.vm_a.cmd('migrate', uri=3D'unix:' + mig_sock) + self.vm_a.cmd('migrate-start-postcopy') + + match =3D {'data': {'status': 'postcopy-active'}} + self.vm_a.event_wait('MIGRATION', match=3Dmatch) + match =3D {'data': {'status': 'completed'}} + self.vm_b.event_wait('MIGRATION', match=3Dmatch) + self.vm_a.event_wait('MIGRATION', match=3Dmatch) + check_bitmaps(self.vm_b, 1) + + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2'], unsupported_imgopts=3D['compat'], diff --git a/tests/qemu-iotests/tests/migrate-bitmaps-postcopy-test.out b/t= ests/qemu-iotests/tests/migrate-bitmaps-postcopy-test.out index 8d7e996700..89968f35d7 100644 --- a/tests/qemu-iotests/tests/migrate-bitmaps-postcopy-test.out +++ b/tests/qemu-iotests/tests/migrate-bitmaps-postcopy-test.out @@ -1,5 +1,5 @@ -... +.... ---------------------------------------------------------------------- -Ran 3 tests +Ran 4 tests =20 OK --=20 2.53.0