* [PATCH hci-8.1/hci-dev 0/2] migration: fix a source hang on cancel before the channel connects #VSTOR-155277
@ 2026-11-25 19:32 Denis V. Lunev
2026-11-25 19:32 ` [PATCH hci-8.1 1/2] migration: fix " Denis V. Lunev
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Denis V. Lunev @ 2026-11-25 19:32 UTC (permalink / raw)
To: svt-core; +Cc: andrey.drobyshev, den
Cancelling a migration right after starting it can hang the source
QEMU forever. This happens when the cancel arrives while the source is
still connecting to the destination and the connection then succeeds.
The source goes on as if nothing was cancelled, then waits for a reply
from the destination that never comes. It waits with the BQL held, so
the monitor stops answering too, and the only way out is to kill the
source. The hci-8.1 autotests hit it three times in
test_abort_live_migration_immediate: VSTOR-155277, VSTOR-156593 and
VSTOR-156857.
The same two patches go to qemu-devel. Here the test is adapted to the
older qtest framework.
Denis V. Lunev (2):
migration: fix source hang on cancel before the channel connects
#VSTOR-155277
tests/qtest/migration: test cancel before the channel connects
#VSTOR-155277
migration/channel.c | 6 +++
migration/migration.c | 2 +-
migration/migration.h | 1 +
tests/qtest/migration/precopy-tests.c | 67 +++++++++++++++++++++++++++
4 files changed, 75 insertions(+), 1 deletion(-)
base-commit: 042da14bb2ceec27fe0680c3aca300395ba0072c
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH hci-8.1 1/2] migration: fix source hang on cancel before the channel connects #VSTOR-155277
2026-11-25 19:32 [PATCH hci-8.1/hci-dev 0/2] migration: fix a source hang on cancel before the channel connects #VSTOR-155277 Denis V. Lunev
@ 2026-11-25 19:32 ` Denis V. Lunev
2026-12-01 0:30 ` no-reply
2026-11-25 19:32 ` [PATCH hci-8.1 2/2] tests/qtest/migration: test " Denis V. Lunev
2026-11-25 20:14 ` [PATCH hci-8.1/hci-dev 0/2] migration: fix a source hang on " Andrey Drobyshev
2 siblings, 1 reply; 6+ messages in thread
From: Denis V. Lunev @ 2026-11-25 19:32 UTC (permalink / raw)
To: svt-core; +Cc: andrey.drobyshev, den
From: Denis V. Lunev <den@openvz.org>
Cancelling a migration while the source is still connecting to the
destination hangs the source QEMU forever if the connection then
succeeds. It hangs with the BQL held, so the monitor stops answering
too.
When the cancel arrives there is no connection yet and nothing to shut
down. Since c12736385bbc, migration_cancel() only marks the migration as
cancelling and leaves the rest to the code that runs when the connect
completes, and that code finishes the cancel only when the connect
fails.
When the connect succeeds, the migration starts anyway. The return path
thread starts and waits for the destination. The migration thread sees
the cancel and quits. The cleanup then waits for the return path thread
to exit, and that never happens: the destination has nothing to send
and keeps the connection open, and a cancel, unlike a failure, does not
make the cleanup shut the return path down.
Check for the cancel as soon as the connection is up, in
migration_channel_connect(), and clean up there before anything is
started. A cancel during the TLS handshake gets there too, once the
handshake is done. migration_cleanup() is no longer static so that
channel.c can call it.
Fixes: c12736385bbc ("migration: Fix crash on second migration when cancel early")
Signed-off-by: Denis V. Lunev <den@openvz.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: Fabiano Rosas <farosas@suse.de>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
---
migration/channel.c | 6 ++++++
migration/migration.c | 2 +-
migration/migration.h | 1 +
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/migration/channel.c b/migration/channel.c
index a547b1fbfeb..6016d6e47d8 100644
--- a/migration/channel.c
+++ b/migration/channel.c
@@ -73,6 +73,12 @@ void migration_channel_connect(MigrationState *s,
ioc, object_get_typename(OBJECT(ioc)), hostname, error);
if (!error) {
+ /* migration_cancel() leaves a cancel during connect for us to finish */
+ if (s->state == MIGRATION_STATUS_CANCELLING) {
+ migration_cleanup(s);
+ return;
+ }
+
if (migrate_channel_requires_tls_upgrade(ioc)) {
migration_tls_channel_connect(s, ioc, hostname, &error);
diff --git a/migration/migration.c b/migration/migration.c
index 57aa0dea264..8fcdf836ddc 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1493,7 +1493,7 @@ static void migration_cleanup_json_writer(MigrationState *s)
g_clear_pointer(&s->vmdesc, json_writer_free);
}
-static void migration_cleanup(MigrationState *s)
+void migration_cleanup(MigrationState *s)
{
MigrationEventType type;
QEMUFile *tmp = NULL;
diff --git a/migration/migration.h b/migration/migration.h
index ee15ca88461..639474bfc2c 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -530,6 +530,7 @@ void migrate_set_error(MigrationState *s, const Error *error);
bool migrate_has_error(MigrationState *s);
void migration_connect(MigrationState *s, Error *error_in);
+void migration_cleanup(MigrationState *s);
int migration_call_notifiers(MigrationEventType type, Error **errp);
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH hci-8.1 2/2] tests/qtest/migration: test cancel before the channel connects #VSTOR-155277
2026-11-25 19:32 [PATCH hci-8.1/hci-dev 0/2] migration: fix a source hang on cancel before the channel connects #VSTOR-155277 Denis V. Lunev
2026-11-25 19:32 ` [PATCH hci-8.1 1/2] migration: fix " Denis V. Lunev
@ 2026-11-25 19:32 ` Denis V. Lunev
2026-12-01 0:31 ` no-reply
2026-11-25 20:14 ` [PATCH hci-8.1/hci-dev 0/2] migration: fix a source hang on " Andrey Drobyshev
2 siblings, 1 reply; 6+ messages in thread
From: Denis V. Lunev @ 2026-11-25 19:32 UTC (permalink / raw)
To: svt-core; +Cc: andrey.drobyshev, den
From: Denis V. Lunev <den@openvz.org>
Cancel a migration while the source is still connecting, then let the
connection succeed. The source must end up in "cancelled", and a
second migration afterwards must complete.
To keep the source waiting in connect(), the test points it at a unix
socket of its own whose listen queue is already full. On Linux,
connect() then blocks until the test accepts a connection, so the test
is Linux-only.
The return-path capability is on because the hang this test guards
against is the cleanup waiting for the return path thread.
Signed-off-by: Denis V. Lunev <den@openvz.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: Fabiano Rosas <farosas@suse.de>
Cc: Laurent Vivier <lvivier@redhat.com>
---
tests/qtest/migration/precopy-tests.c | 67 +++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/tests/qtest/migration/precopy-tests.c b/tests/qtest/migration/precopy-tests.c
index bb38292550c..2b0afdbd48d 100644
--- a/tests/qtest/migration/precopy-tests.c
+++ b/tests/qtest/migration/precopy-tests.c
@@ -821,6 +821,69 @@ static void test_cancel_src_after_status(void *opaque)
migrate_end(from, to, false);
}
+#ifdef CONFIG_LINUX
+/* On Linux connect() to a unix socket with a full backlog blocks */
+static int unix_listen_full(const char *path, int *filler)
+{
+ struct sockaddr_un addr = { .sun_family = AF_UNIX };
+ int lfd = socket(AF_UNIX, SOCK_STREAM, 0);
+
+ *filler = socket(AF_UNIX, SOCK_STREAM, 0);
+ g_assert_cmpint(lfd, >=, 0);
+ g_assert_cmpint(*filler, >=, 0);
+
+ g_assert_cmpuint(strlen(path), <, sizeof(addr.sun_path));
+ strcpy(addr.sun_path, path);
+ g_assert_cmpint(bind(lfd, (struct sockaddr *)&addr, sizeof(addr)), ==, 0);
+ g_assert_cmpint(listen(lfd, 0), ==, 0);
+ g_assert_cmpint(connect(*filler, (struct sockaddr *)&addr, sizeof(addr)),
+ ==, 0);
+ return lfd;
+}
+
+static void test_cancel_src_before_connect(void)
+{
+ g_autofree char *full_path = g_strdup_printf("%s/migsocket-full", tmpfs);
+ g_autofree char *full_uri = g_strdup_printf("unix:%s", full_path);
+ g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+ QTestState *from, *to;
+ MigrateStart args = {};
+ int lfd, filler, accepted;
+
+ if (migrate_start(&from, &to, "defer", &args)) {
+ return;
+ }
+
+ migrate_set_capability(from, "return-path", true);
+ migrate_set_capability(to, "return-path", true);
+
+ lfd = unix_listen_full(full_path, &filler);
+ migrate_qmp(from, to, full_uri, NULL, "{}");
+ migrate_cancel(from);
+
+ /* Taking the filler off the backlog lets the source's connect() finish */
+ accepted = accept(lfd, NULL, NULL);
+ g_assert_cmpint(accepted, >=, 0);
+
+ wait_for_migration_status(from, "cancelled",
+ (const char * []) { "completed", NULL });
+
+ close(accepted);
+ close(filler);
+ close(lfd);
+ unlink(full_path);
+
+ migrate_incoming_qmp(to, uri, NULL, "{}");
+ wait_for_serial("src_serial");
+ migrate_ensure_converge(from);
+ migrate_qmp(from, to, uri, NULL, "{}");
+ wait_for_migration_complete(from);
+ wait_for_migration_complete(to);
+
+ migrate_end(from, to, true);
+}
+#endif
+
static void calc_dirty_rate(QTestState *who, uint64_t calc_time)
{
qtest_qmp_assert_success(who,
@@ -1334,4 +1397,8 @@ void migration_test_add_precopy(MigrationTestEnv *env)
test_cancel_src_after_status);
}
}
+#ifdef CONFIG_LINUX
+ migration_test_add("/migration/cancel/src/before/connect",
+ test_cancel_src_before_connect);
+#endif
}
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH hci-8.1/hci-dev 0/2] migration: fix a source hang on cancel before the channel connects #VSTOR-155277
2026-11-25 19:32 [PATCH hci-8.1/hci-dev 0/2] migration: fix a source hang on cancel before the channel connects #VSTOR-155277 Denis V. Lunev
2026-11-25 19:32 ` [PATCH hci-8.1 1/2] migration: fix " Denis V. Lunev
2026-11-25 19:32 ` [PATCH hci-8.1 2/2] tests/qtest/migration: test " Denis V. Lunev
@ 2026-11-25 20:14 ` Andrey Drobyshev
2 siblings, 0 replies; 6+ messages in thread
From: Andrey Drobyshev @ 2026-11-25 20:14 UTC (permalink / raw)
To: Denis V. Lunev, svt-core
Ack
Applied onto hci-8.1 and hci-dev
On 11/25/26 9:32 PM, Denis V. Lunev wrote:
> Cancelling a migration right after starting it can hang the source
> QEMU forever. This happens when the cancel arrives while the source is
> still connecting to the destination and the connection then succeeds.
> The source goes on as if nothing was cancelled, then waits for a reply
> from the destination that never comes. It waits with the BQL held, so
> the monitor stops answering too, and the only way out is to kill the
> source. The hci-8.1 autotests hit it three times in
> test_abort_live_migration_immediate: VSTOR-155277, VSTOR-156593 and
> VSTOR-156857.
>
> The same two patches go to qemu-devel. Here the test is adapted to the
> older qtest framework.
>
> Denis V. Lunev (2):
> migration: fix source hang on cancel before the channel connects
> #VSTOR-155277
> tests/qtest/migration: test cancel before the channel connects
> #VSTOR-155277
>
> migration/channel.c | 6 +++
> migration/migration.c | 2 +-
> migration/migration.h | 1 +
> tests/qtest/migration/precopy-tests.c | 67 +++++++++++++++++++++++++++
> 4 files changed, 75 insertions(+), 1 deletion(-)
>
>
> base-commit: 042da14bb2ceec27fe0680c3aca300395ba0072c
> --
> 2.55.0
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH hci-8.1 1/2] migration: fix source hang on cancel before the channel connects #VSTOR-155277
2026-11-25 19:32 ` [PATCH hci-8.1 1/2] migration: fix " Denis V. Lunev
@ 2026-12-01 0:30 ` no-reply
0 siblings, 0 replies; 6+ messages in thread
From: no-reply @ 2026-12-01 0:30 UTC (permalink / raw)
To: Denis V. Lunev, svt-core; +Cc: andrey.drobyshev
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] migration: cancel during postcopy resume connect hangs in
migration_cleanup()
--
commit c746b1b1a4198168dbe30b6b4ea7b0bb9e2bd656
Author: Denis V. Lunev <den@openvz.org>
migration: fix source hang on cancel before the channel connects #VSTOR-155277
When a cancel arrives while the source is still connecting, this patch makes migration_channel_connect() call migration_cleanup() once the connection is up. That happens before the return path and migration threads are started. migration_cleanup() is made non-static so channel.c can call it.
> diff --git a/migration/channel.c b/migration/channel.c
> index a547b1fbfebee..6016d6e47d86b 100644
> --- a/migration/channel.c
> +++ b/migration/channel.c
> @@ -73,6 +73,12 @@ void migration_channel_connect(MigrationState *s,
> ioc, object_get_typename(OBJECT(ioc)), hostname, error);
>
> if (!error) {
> + /* migration_cancel() leaves a cancel during connect for us to finish */
> + if (s->state == MIGRATION_STATUS_CANCELLING) {
> + migration_cleanup(s);
> + return;
> + }
> +
[Severity: Low]
Can this hang for a postcopy resume connect? If migration_cancel() moves
POSTCOPY_RECOVER_SETUP to CANCELLING, the old migration thread is still
parked in postcopy_pause() on qemu_sem_wait(&s->postcopy_pause_sem), and
migration_cancel() does not post that semaphore.
When the connect completes, this check calls migration_cleanup().
Because migration_thread_running is true, it does qemu_thread_join(&s->thread)
and blocks forever with the BQL held, so the monitor stops answering.
qmp_migrate_cancel() refuses to cancel in this state because
migration_in_postcopy() covers POSTCOPY_RECOVER_SETUP. But
ram_mig_ram_block_resized() calls migration_cancel() whenever
migration_is_running() is true, with no postcopy guard. A RAM block resize
on the paused source during the resume could reach it.
The commit message only discusses fresh migrations. Before this patch,
migration_connect() would instead start a second migration thread in this
case, so the outcome was also broken, but now it is a hang.
Carry the trailer below into the next revision and Sashiko will not review this patch again.
Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261125193204.1424799-1-den@openvz.org?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH hci-8.1 2/2] tests/qtest/migration: test cancel before the channel connects #VSTOR-155277
2026-11-25 19:32 ` [PATCH hci-8.1 2/2] tests/qtest/migration: test " Denis V. Lunev
@ 2026-12-01 0:31 ` no-reply
0 siblings, 0 replies; 6+ messages in thread
From: no-reply @ 2026-12-01 0:31 UTC (permalink / raw)
To: Denis V. Lunev, svt-core; +Cc: andrey.drobyshev
> From: Denis V. Lunev <den@openvz.org>
>
> Cancel a migration while the source is still connecting, then let the
> connection succeed. The source must end up in "cancelled", and a
> second migration afterwards must complete.
>
> To keep the source waiting in connect(), the test points it at a unix
> socket of its own whose listen queue is already full. On Linux,
> connect() then blocks until the test accepts a connection, so the test
> is Linux-only.
>
> The return-path capability is on because the hang this test guards
> against is the cleanup waiting for the return path thread.
>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
Sashiko has reviewed this patch and found no issues.
Carry the trailer below into the next revision and Sashiko will not review this patch again.
Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261125193204.1424799-1-den@openvz.org?part=2
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-01 0:31 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 19:32 [PATCH hci-8.1/hci-dev 0/2] migration: fix a source hang on cancel before the channel connects #VSTOR-155277 Denis V. Lunev
2026-11-25 19:32 ` [PATCH hci-8.1 1/2] migration: fix " Denis V. Lunev
2026-12-01 0:30 ` no-reply
2026-11-25 19:32 ` [PATCH hci-8.1 2/2] tests/qtest/migration: test " Denis V. Lunev
2026-12-01 0:31 ` no-reply
2026-11-25 20:14 ` [PATCH hci-8.1/hci-dev 0/2] migration: fix a source hang on " Andrey Drobyshev
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.