On the postcopy destination, the postcopy-active and completed states
can be reported while the VM is still in RUN_STATE_INMIGRATE. The run
state only changes in loadvm_postcopy_handle_run_bh(), but
loadvm_postcopy_handle_run() switches to postcopy-active before it
schedules the BH, and the listen thread can report completed before the
BH has run. Precopy does not have this problem: the run state changes
before completed is reported.
We hit this in production. A VM with a persistent dirty bitmap migrates
its bitmaps in postcopy, so libvirt runs the Finish phase as soon as the
source enters postcopy-active. Our libvirt reattaches disks on the
destination in Finish, and the blockdev-add calls land while the
destination is still in RUN_STATE_INMIGRATE. The new nodes are created
inactive, the device cannot be attached to them ("Block node is
read-only"), and the guest is lost on both hosts. A bitmap-only
postcopy makes the window wide, because the listen thread has almost
nothing to load.
The series orders both destination states after the run state change
and adds a qtest check that fails on master; fast snapshot load
(postcopy-ram with mapped-ram) is not covered. The series also gives the
source's postcopy-active the same meaning. It takes Peter's idea from
the review of Juraj's RFC [1]: record the package-loaded ping and send
the pong later [2]. Here the pong is sent from the run BH, after the run
state change, rather than from loadvm_postcopy_handle_run(). Juraj
confirmed that this fixes the unrecoverable source he reported [3]. The
late pong keeps the source in postcopy-device longer, so it can be
dropped without affecting the rest.
The late pong has two more consequences. A bitmap-only postcopy with a
return path deadlocks unless dirty_bitmap_load() stops holding its lock
while it reads the stream. That fix was sent separately [4] and this
series is based on it. The new iotest case covers that configuration;
feel free to drop it. And an autostarting destination that dies between
vm_start() and the pong lets the source resume after the guest has
briefly run there. This cannot happen with -S, which libvirt uses.
[1] https://lore.kernel.org/qemu-devel/20260423154525.10292-1-jmarcin@redhat.com/
[2] https://lore.kernel.org/qemu-devel/afJg6VzsaslzZQW1@x1.local/
[3] https://lore.kernel.org/qemu-devel/20260929132150.2215007-1-jmarcin@redhat.com/
[4] https://lore.kernel.org/qemu-devel/20261110155113.2721134-1-den@openvz.org/
Many thanks to Juraj for the postcopy-device state in 7b842fe354c. It is
what gives the source a point to wait at, and this series only moves
that point to where the destination has really left
RUN_STATE_INMIGRATE.
v2:
- the run BH sets main_thread_load_event instead of a second event
(Peter)
- the destination's switch to postcopy-active keeps the explicit
POSTCOPY_DEVICE check (Peter)
- new iotest case for a bitmap postcopy with a return path
- the commit message of the late pong is updated; the code is
unchanged, so I kept the tags
- rebased
v1: https://lore.kernel.org/qemu-devel/20261002110258.1835979-1-den@openvz.org/
Based-on: <20261110155113.2721134-1-den@openvz.org>
Signed-off-by: Denis V. Lunev <den@openvz.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: Fabiano Rosas <farosas@suse.de>
Cc: Juraj Marcin <jmarcin@redhat.com>
Cc: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Cc: Eric Blake <eblake@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Hanna Reitz <hreitz@redhat.com>
Cc: qemu-block@nongnu.org
Denis V. Lunev (5):
migration/postcopy: report COMPLETED only after the run BH has run
migration/postcopy: set destination postcopy-active in the run BH
tests/qtest/migration: check the destination run state in postcopy
tests
migration/postcopy: answer the package-loaded ping from the run BH
iotests/migrate-bitmaps-postcopy-test: cover postcopy with a return
path
migration/migration.c | 1 +
migration/migration.h | 4 +-
migration/savevm.c | 25 +++++++++---
.../tests/migrate-bitmaps-postcopy-test | 39 +++++++++++++++++++
.../tests/migrate-bitmaps-postcopy-test.out | 4 +-
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 +
10 files changed, 88 insertions(+), 14 deletions(-)
base-commit: 723622bedb0b423de7d1c61ebbe6e7a71934949c
prerequisite-patch-id: 67b7337e86202ef7509fc53ff8915a814a477e3b
--
2.53.0