From patchwork Mon Dec 2 22:01:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabiano Rosas X-Patchwork-Id: 13891354 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 64D26E69E99 for ; Mon, 2 Dec 2024 22:03:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIEUI-00075C-5i; Mon, 02 Dec 2024 17:01:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIEUE-00074V-Uh for qemu-devel@nongnu.org; Mon, 02 Dec 2024 17:01:46 -0500 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIEUD-0003c1-B9 for qemu-devel@nongnu.org; Mon, 02 Dec 2024 17:01:46 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B0AFC21177; Mon, 2 Dec 2024 22:01:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733176903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WzLMHCrbLXY3QNyPwgC950Z+m54pLA4bbQYlZGwnSro=; b=AbTdy8bO9HY+BMbOCtxHUQ3vHxnkLv8Y13iKK5XHiVbbvPboD1fHCp0F03m51KFwiImNev oQgMFReJf8L5pgKIPn/ogg/VJSPgBeO5PL+g2y7VWwhygR/J5wbdDSBusERx1ZAzw30NDW Gr20iPEcuAD/h/yH8zttI69J4Pt7NbI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733176903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WzLMHCrbLXY3QNyPwgC950Z+m54pLA4bbQYlZGwnSro=; b=P2QEt2CHZEQTLvwWsTcC7fXhxS1Tka+aNQRqMBMshZzqxjzWWQD71MoXzKd5/dC1WQ4EGy jbcCei+Pawx7zfCA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=AbTdy8bO; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=P2QEt2CH DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733176903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WzLMHCrbLXY3QNyPwgC950Z+m54pLA4bbQYlZGwnSro=; b=AbTdy8bO9HY+BMbOCtxHUQ3vHxnkLv8Y13iKK5XHiVbbvPboD1fHCp0F03m51KFwiImNev oQgMFReJf8L5pgKIPn/ogg/VJSPgBeO5PL+g2y7VWwhygR/J5wbdDSBusERx1ZAzw30NDW Gr20iPEcuAD/h/yH8zttI69J4Pt7NbI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733176903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WzLMHCrbLXY3QNyPwgC950Z+m54pLA4bbQYlZGwnSro=; b=P2QEt2CHZEQTLvwWsTcC7fXhxS1Tka+aNQRqMBMshZzqxjzWWQD71MoXzKd5/dC1WQ4EGy jbcCei+Pawx7zfCA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8316913A40; Mon, 2 Dec 2024 22:01:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id aNlgEkYuTmdlIAAAD6G6ig (envelope-from ); Mon, 02 Dec 2024 22:01:42 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= Subject: [PATCH 1/6] tests/qtest/migration: Introduce migration_test_add_suffix Date: Mon, 2 Dec 2024 19:01:32 -0300 Message-Id: <20241202220137.32584-2-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20241202220137.32584-1-farosas@suse.de> References: <20241202220137.32584-1-farosas@suse.de> MIME-Version: 1.0 X-Rspamd-Queue-Id: B0AFC21177 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:email,suse.de:dkim,suse.de:mid]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action Received-SPF: pass client-ip=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Introduce a new migration_test_add_suffix to allow programmatic creation of tests based on a suffix. Pass the test name into the test so it can know which variant to run. Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu --- tests/qtest/migration-helpers.c | 24 ++++++++++++++++++++++++ tests/qtest/migration-helpers.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c index 3f8ba7fa8e..905f4c583d 100644 --- a/tests/qtest/migration-helpers.c +++ b/tests/qtest/migration-helpers.c @@ -437,6 +437,7 @@ char *resolve_machine_version(const char *alias, const char *var1, typedef struct { char *name; void (*func)(void); + void (*func_full)(void *); } MigrationTest; static void migration_test_destroy(gpointer data) @@ -466,6 +467,29 @@ void migration_test_add(const char *path, void (*fn)(void)) migration_test_destroy); } +static void migration_test_wrapper_full(const void *data) +{ + MigrationTest *test = (MigrationTest *)data; + + g_test_message("Running /%s%s", qtest_get_arch(), test->name); + test->func_full(test->name); +} + +void migration_test_add_suffix(const char *path, const char *suffix, + void (*fn)(void *)) +{ + MigrationTest *test = g_new0(MigrationTest, 1); + + g_assert(g_str_has_suffix(path, "/")); + g_assert(!g_str_has_prefix(suffix, "/")); + + test->func_full = fn; + test->name = g_strconcat(path, suffix, NULL); + + qtest_add_data_func_full(test->name, test, migration_test_wrapper_full, + migration_test_destroy); +} + #ifdef O_DIRECT /* * Probe for O_DIRECT support on the filesystem. Since this is used diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h index 72dba369fb..391038f59b 100644 --- a/tests/qtest/migration-helpers.h +++ b/tests/qtest/migration-helpers.h @@ -63,6 +63,8 @@ static inline bool probe_o_direct_support(const char *tmpfs) } #endif void migration_test_add(const char *path, void (*fn)(void)); +void migration_test_add_suffix(const char *path, const char *suffix, + void (*fn)(void *)); void migration_event_wait(QTestState *s, const char *target); #endif /* MIGRATION_HELPERS_H */ From patchwork Mon Dec 2 22:01:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabiano Rosas X-Patchwork-Id: 13891349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AADC2E69E97 for ; Mon, 2 Dec 2024 22:02:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIEUK-00075w-9m; Mon, 02 Dec 2024 17:01:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIEUI-00075D-6K for qemu-devel@nongnu.org; Mon, 02 Dec 2024 17:01:50 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIEUG-0003c8-JM for qemu-devel@nongnu.org; Mon, 02 Dec 2024 17:01:49 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5FD5921182; Mon, 2 Dec 2024 22:01:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733176905; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3ERIkhefWi5WqvYg6rz3y2qvknoGc8ppkoMUD2uu3uw=; b=W8VuTXpZTPQPP5g4URweH0IgYOztwdlDWloDecBp1xEjSI9g91S55rAgaNdvypo1TSDhQv WPe5vvyydbzFnpj3tXYdTrC7xNDDh2X8uIMJxveX2iEy2aWg99Qjz6borMxumoBkWgnmPs RzLJrUPzI9xvznJcUJzWYJJ0E6fLDJ8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733176905; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3ERIkhefWi5WqvYg6rz3y2qvknoGc8ppkoMUD2uu3uw=; b=fqgHsPcIx8JSH+dbPHRSOgV4TWvdoi7AZn6WMYkS8KNp+l8rW7ClNMlQccaij8+kDvRyJh Hwen3Q2Lq0SsNRBA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=W8VuTXpZ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=fqgHsPcI DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733176905; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3ERIkhefWi5WqvYg6rz3y2qvknoGc8ppkoMUD2uu3uw=; b=W8VuTXpZTPQPP5g4URweH0IgYOztwdlDWloDecBp1xEjSI9g91S55rAgaNdvypo1TSDhQv WPe5vvyydbzFnpj3tXYdTrC7xNDDh2X8uIMJxveX2iEy2aWg99Qjz6borMxumoBkWgnmPs RzLJrUPzI9xvznJcUJzWYJJ0E6fLDJ8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733176905; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3ERIkhefWi5WqvYg6rz3y2qvknoGc8ppkoMUD2uu3uw=; b=fqgHsPcIx8JSH+dbPHRSOgV4TWvdoi7AZn6WMYkS8KNp+l8rW7ClNMlQccaij8+kDvRyJh Hwen3Q2Lq0SsNRBA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3155913A31; Mon, 2 Dec 2024 22:01:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id AFbjOUcuTmdlIAAAD6G6ig (envelope-from ); Mon, 02 Dec 2024 22:01:43 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= Subject: [PATCH 2/6] migration: Kick postcopy threads on cancel Date: Mon, 2 Dec 2024 19:01:33 -0300 Message-Id: <20241202220137.32584-3-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20241202220137.32584-1-farosas@suse.de> References: <20241202220137.32584-1-farosas@suse.de> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5FD5921182 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:email,suse.de:dkim,suse.de:mid]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action Received-SPF: pass client-ip=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Make sure postcopy threads are released when migrate_cancel is issued. Kick the postcopy_pause semaphore and have the fault thread read 'fault_thread_quit' when joining. While here fix the comment mentioning userfault_event_fd. Signed-off-by: Fabiano Rosas --- migration/migration.c | 14 +++++++++++--- migration/postcopy-ram.c | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 8c5bd0a75c..07fbb5c9f4 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -105,7 +105,7 @@ static bool migration_object_check(MigrationState *ms, Error **errp); static int migration_maybe_pause(MigrationState *s, int *current_active_state, int new_state); -static void migrate_fd_cancel(MigrationState *s); +static void migrate_fd_cancel(MigrationState *s, MigrationIncomingState *mis); static bool close_return_path_on_source(MigrationState *s); static void migration_completion_end(MigrationState *s); @@ -317,7 +317,7 @@ void migration_cancel(const Error *error) if (migrate_dirty_limit()) { qmp_cancel_vcpu_dirty_limit(false, -1, NULL); } - migrate_fd_cancel(current_migration); + migrate_fd_cancel(current_migration, current_incoming); } void migration_shutdown(void) @@ -1502,7 +1502,7 @@ static void migrate_fd_error(MigrationState *s, const Error *error) migrate_set_error(s, error); } -static void migrate_fd_cancel(MigrationState *s) +static void migrate_fd_cancel(MigrationState *s, MigrationIncomingState *mis) { int old_state ; @@ -1515,6 +1515,12 @@ static void migrate_fd_cancel(MigrationState *s) } } + if (mis->state == MIGRATION_STATUS_POSTCOPY_PAUSED) { + migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_PAUSED, + MIGRATION_STATUS_CANCELLING); + qemu_sem_post(&mis->postcopy_pause_sem_dst); + } + do { old_state = s->state; if (!migration_is_running()) { @@ -1523,6 +1529,8 @@ static void migrate_fd_cancel(MigrationState *s) /* If the migration is paused, kick it out of the pause */ if (old_state == MIGRATION_STATUS_PRE_SWITCHOVER) { qemu_sem_post(&s->pause_sem); + } else if (old_state == MIGRATION_STATUS_POSTCOPY_PAUSED) { + qemu_sem_post(&s->postcopy_pause_sem); } migrate_set_state(&s->state, old_state, MIGRATION_STATUS_CANCELLING); } while (s->state != MIGRATION_STATUS_CANCELLING); diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index a535fd2e30..6882ef977d 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -634,6 +634,7 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis) qatomic_set(&mis->fault_thread_quit, 1); postcopy_fault_thread_notify(mis); trace_postcopy_ram_incoming_cleanup_join(); + qemu_sem_post(&mis->postcopy_pause_sem_fault); qemu_thread_join(&mis->fault_thread); if (postcopy_notify(POSTCOPY_NOTIFY_INBOUND_END, &local_err)) { @@ -991,8 +992,7 @@ static void *postcopy_ram_fault_thread(void *opaque) /* * We're mainly waiting for the kernel to give us a faulting HVA, - * however we can be told to quit via userfault_quit_fd which is - * an eventfd + * however we can be told to quit via userfault_event_fd. */ poll_result = poll(pfd, pfd_len, -1 /* Wait forever */); @@ -1008,6 +1008,11 @@ static void *postcopy_ram_fault_thread(void *opaque) * the channel is rebuilt. */ postcopy_pause_fault_thread(mis); + + if (qatomic_read(&mis->fault_thread_quit)) { + trace_postcopy_ram_fault_thread_quit(); + break; + } } if (pfd[1].revents) { @@ -1082,6 +1087,11 @@ retry: if (ret) { /* May be network failure, try to wait for recovery */ postcopy_pause_fault_thread(mis); + + if (qatomic_read(&mis->fault_thread_quit)) { + trace_postcopy_ram_fault_thread_quit(); + break; + } goto retry; } } From patchwork Mon Dec 2 22:01:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabiano Rosas X-Patchwork-Id: 13891350 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C94A2E69E97 for ; Mon, 2 Dec 2024 22:02:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIEUM-000769-P3; Mon, 02 Dec 2024 17:01:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIEUJ-00075Q-1w for qemu-devel@nongnu.org; Mon, 02 Dec 2024 17:01:51 -0500 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIEUG-0003cM-Gr for qemu-devel@nongnu.org; Mon, 02 Dec 2024 17:01:50 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 12E5D1F458; Mon, 2 Dec 2024 22:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733176907; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K1fOYI6uObo8w+HKEL4A4rk7nMa0YD8YUYkVRHOO2Bw=; b=Dh4mC0JmjSm5jREIrbpqie9V0U1f6Feorc+7e2lbBSdVJrxjKYfWZ7zA7+JK2e+4MIv6RI z2KrugK1Mlfwh7OXN1CeMeCkKqktjovEhRpMM5oB+KG5bIwmKz3p1wJ/uF+J7l1wgL0+1n rp4MSKWhHguL7F6wxenHuTqNy62r8eY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733176907; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K1fOYI6uObo8w+HKEL4A4rk7nMa0YD8YUYkVRHOO2Bw=; b=r2x8GKnCRfGk4p8H/QJcZR1Dhoni18Gba0P3j7H2KWRuWxcE3gH+AGoCxEsqXrr+d9zLL0 MDG8UpWi/S3mhyDA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=Dh4mC0Jm; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=r2x8GKnC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733176907; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K1fOYI6uObo8w+HKEL4A4rk7nMa0YD8YUYkVRHOO2Bw=; b=Dh4mC0JmjSm5jREIrbpqie9V0U1f6Feorc+7e2lbBSdVJrxjKYfWZ7zA7+JK2e+4MIv6RI z2KrugK1Mlfwh7OXN1CeMeCkKqktjovEhRpMM5oB+KG5bIwmKz3p1wJ/uF+J7l1wgL0+1n rp4MSKWhHguL7F6wxenHuTqNy62r8eY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733176907; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K1fOYI6uObo8w+HKEL4A4rk7nMa0YD8YUYkVRHOO2Bw=; b=r2x8GKnCRfGk4p8H/QJcZR1Dhoni18Gba0P3j7H2KWRuWxcE3gH+AGoCxEsqXrr+d9zLL0 MDG8UpWi/S3mhyDA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id D758F13A31; Mon, 2 Dec 2024 22:01:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 4PGxJkkuTmdlIAAAD6G6ig (envelope-from ); Mon, 02 Dec 2024 22:01:45 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= Subject: [PATCH 3/6] migration: Fix postcopy listen thread exit Date: Mon, 2 Dec 2024 19:01:34 -0300 Message-Id: <20241202220137.32584-4-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20241202220137.32584-1-farosas@suse.de> References: <20241202220137.32584-1-farosas@suse.de> MIME-Version: 1.0 X-Rspamd-Queue-Id: 12E5D1F458 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,suse.de:mid,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action Received-SPF: pass client-ip=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org There are a couple of problems with exiting the postcopy listen thread. It does not honor the exit-on-error flag and always exits QEMU upon error. It also does not behave well if a qmp_migrate_cancel() is issued while postcopy is paused, it either hangs during retry or crashes during access of a non-recovered QEMUFile (i.e. NULL). Fix it by adding support for exit-on-error and avoiding accessing the NULL file pointer. While here, move the end tracepoint to a later part of the function. Signed-off-by: Fabiano Rosas --- migration/savevm.c | 60 +++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 98821c8120..44b7f883f7 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2004,11 +2004,14 @@ static void *postcopy_ram_listen_thread(void *opaque) * want a wrapper for the QEMUFile handle. */ f = mis->from_src_file; + if (!f) { + /* postcopy pause never got recovered */ + goto out; + } /* And non-blocking again so we don't block in any cleanup */ qemu_file_set_blocking(f, false); - trace_postcopy_ram_listen_thread_exit(); if (load_res < 0) { qemu_file_set_error(f, load_res); dirty_bitmap_mig_cancel_incoming(); @@ -2021,10 +2024,6 @@ static void *postcopy_ram_listen_thread(void *opaque) "bitmaps are correctly migrated and valid.", __func__, load_res); load_res = 0; /* prevent further exit() */ - } else { - error_report("%s: loadvm failed: %d", __func__, load_res); - migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, - MIGRATION_STATUS_FAILED); } } if (load_res >= 0) { @@ -2034,31 +2033,40 @@ static void *postcopy_ram_listen_thread(void *opaque) * state yet; wait for the end of the main thread. */ qemu_event_wait(&mis->main_thread_load_event); - } - postcopy_ram_incoming_cleanup(mis); - if (load_res < 0) { + postcopy_ram_incoming_cleanup(mis); + + migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, + MIGRATION_STATUS_COMPLETED); + /* - * If something went wrong then we have a bad state so exit; - * depending how far we got it might be possible at this point - * to leave the guest running and fire MCEs for pages that never - * arrived as a desperate recovery step. + * If everything has worked fine, then the main thread has waited + * for us to start, and we're the last use of the mis. */ - rcu_unregister_thread(); - exit(EXIT_FAILURE); + migration_incoming_state_destroy(); } - migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, - MIGRATION_STATUS_COMPLETED); - /* - * If everything has worked fine, then the main thread has waited - * for us to start, and we're the last use of the mis. - * (If something broke then qemu will have to exit anyway since it's - * got a bad migration state). - */ - migration_incoming_state_destroy(); - +out: + trace_postcopy_ram_listen_thread_exit(); rcu_unregister_thread(); + + if (load_res < 0) { + postcopy_ram_incoming_cleanup(mis); + + error_report("%s: loadvm failed: %d", __func__, load_res); + migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, + MIGRATION_STATUS_FAILED); + if (mis->exit_on_error) { + /* + * If something went wrong then we have a bad state so exit; + * depending how far we got it might be possible at this point + * to leave the guest running and fire MCEs for pages that never + * arrived as a desperate recovery step. + */ + exit(EXIT_FAILURE); + } + } + mis->have_listen_thread = false; postcopy_state_set(POSTCOPY_INCOMING_END); @@ -2921,7 +2929,9 @@ out: migrate_postcopy_ram() && postcopy_pause_incoming(mis)) { /* Reset f to point to the newly created channel */ f = mis->from_src_file; - goto retry; + if (f) { + goto retry; + } } } return ret; From patchwork Mon Dec 2 22:01:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabiano Rosas X-Patchwork-Id: 13891353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2CFBEE69E98 for ; Mon, 2 Dec 2024 22:03:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIEUN-00076R-G1; Mon, 02 Dec 2024 17:01:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIEUJ-00075a-Sa for qemu-devel@nongnu.org; Mon, 02 Dec 2024 17:01:51 -0500 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIEUI-0003cU-7H for qemu-devel@nongnu.org; Mon, 02 Dec 2024 17:01:51 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BFC9F2117B; Mon, 2 Dec 2024 22:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733176908; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cdxYBEqgn4kOXDr/O55Bx/l2mCvnSz1Da+lplp0fIH8=; b=tDaM8YxMqygXHcpFG8It6pKZ/3K+WYiWLZ/X1HDayR447nIKdTOPahkW6AVRnuCY1eTXmj fE3125Mv34oZwmmrF25K59SMvfAkGaJp5iz+8BNorBfkAz1VuxK7P8bFnVo38/CYwFNk25 bZUUB0ZZN5cclegj+F6dOmXJKlJdWak= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733176908; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cdxYBEqgn4kOXDr/O55Bx/l2mCvnSz1Da+lplp0fIH8=; b=sgvREuEAzX2/iy2FOILIyX5xhQYoDUFs4b9yv+6Qd6b3UFlDb/dxJ3Bv0L1u6US/RiCo1P MlmGB3RS3gDIaVDg== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=tDaM8YxM; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=sgvREuEA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733176908; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cdxYBEqgn4kOXDr/O55Bx/l2mCvnSz1Da+lplp0fIH8=; b=tDaM8YxMqygXHcpFG8It6pKZ/3K+WYiWLZ/X1HDayR447nIKdTOPahkW6AVRnuCY1eTXmj fE3125Mv34oZwmmrF25K59SMvfAkGaJp5iz+8BNorBfkAz1VuxK7P8bFnVo38/CYwFNk25 bZUUB0ZZN5cclegj+F6dOmXJKlJdWak= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733176908; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cdxYBEqgn4kOXDr/O55Bx/l2mCvnSz1Da+lplp0fIH8=; b=sgvREuEAzX2/iy2FOILIyX5xhQYoDUFs4b9yv+6Qd6b3UFlDb/dxJ3Bv0L1u6US/RiCo1P MlmGB3RS3gDIaVDg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8E1EB13A31; Mon, 2 Dec 2024 22:01:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id ICOeFEsuTmdlIAAAD6G6ig (envelope-from ); Mon, 02 Dec 2024 22:01:47 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= Subject: [PATCH 4/6] migration: Make sure postcopy recovery doesn't hang when cancelling Date: Mon, 2 Dec 2024 19:01:35 -0300 Message-Id: <20241202220137.32584-5-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20241202220137.32584-1-farosas@suse.de> References: <20241202220137.32584-1-farosas@suse.de> MIME-Version: 1.0 X-Rspamd-Queue-Id: BFC9F2117B X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email, suse.de:dkim, suse.de:mid, imap1.dmz-prg2.suse.org:helo, imap1.dmz-prg2.suse.org:rdns] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action Received-SPF: pass client-ip=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Make sure postcopy recovery doesn't hang when calling qmp_migrate_cancel() and also doesn't pause the migration once more. Signed-off-by: Fabiano Rosas --- migration/migration.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index 07fbb5c9f4..8a61cc26d7 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1531,6 +1531,8 @@ static void migrate_fd_cancel(MigrationState *s, MigrationIncomingState *mis) qemu_sem_post(&s->pause_sem); } else if (old_state == MIGRATION_STATUS_POSTCOPY_PAUSED) { qemu_sem_post(&s->postcopy_pause_sem); + } else if (old_state == MIGRATION_STATUS_POSTCOPY_RECOVER) { + qemu_sem_post(&s->rp_state.rp_sem); } migrate_set_state(&s->state, old_state, MIGRATION_STATUS_CANCELLING); } while (s->state != MIGRATION_STATUS_CANCELLING); @@ -2148,6 +2150,10 @@ void qmp_migrate_continue(MigrationStatus state, Error **errp) int migration_rp_wait(MigrationState *s) { + if (qatomic_read(&s->state) == MIGRATION_STATUS_CANCELLING) { + return -1; + } + /* If migration has failure already, ignore the wait */ if (migrate_has_error(s)) { return -1; @@ -2160,6 +2166,10 @@ int migration_rp_wait(MigrationState *s) return -1; } + if (qatomic_read(&s->state) == MIGRATION_STATUS_CANCELLING) { + return -1; + } + return 0; } @@ -3023,6 +3033,9 @@ static MigThrError postcopy_pause(MigrationState *s) trace_postcopy_pause_continued(); return MIG_THR_ERR_RECOVERED; } else { + if (s->state == MIGRATION_STATUS_CANCELLING) { + return MIG_THR_ERR_FATAL; + } /* * Something wrong happened during the recovery, let's * pause again. Pause is always better than throwing From patchwork Mon Dec 2 22:01:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Fabiano Rosas X-Patchwork-Id: 13891351 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B8E6E69E95 for ; Mon, 2 Dec 2024 22:03:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIEUP-00076z-Pr; Mon, 02 Dec 2024 17:01:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIEUM-000761-06 for qemu-devel@nongnu.org; Mon, 02 Dec 2024 17:01:54 -0500 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIEUJ-0003cw-OB for qemu-devel@nongnu.org; Mon, 02 Dec 2024 17:01:53 -0500 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A053D1F45F; Mon, 2 Dec 2024 22:01:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733176910; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ervb2K7sqVuvepYZrDqX+K0WK8EkwpeLtzoNV7Q9jlQ=; b=N9Hi3P4I88AcP1PSIe/VQfClR0IL2OUYZ8qgyDHmm2pIZ+xdqu9Bq0uvGBwTns5g2W53Yb SBOOM/+SaBjOBwYtTxMZrpzKc0EclWS0H76P8DYNSZ7SpnUZdpsCfFQ/MtV3BrExeDgfZS wEkQfmFGy62S/DxmJslg+ZRWzLOVmNM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733176910; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ervb2K7sqVuvepYZrDqX+K0WK8EkwpeLtzoNV7Q9jlQ=; b=0zzRahitHBdg1T5xEgkH973A9OOSJNmFE1+n1wogkCpwK+As6I7uoMrVIfGSPTbtLqmZb9 lGNtzwB2S68KFXAg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733176910; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ervb2K7sqVuvepYZrDqX+K0WK8EkwpeLtzoNV7Q9jlQ=; b=N9Hi3P4I88AcP1PSIe/VQfClR0IL2OUYZ8qgyDHmm2pIZ+xdqu9Bq0uvGBwTns5g2W53Yb SBOOM/+SaBjOBwYtTxMZrpzKc0EclWS0H76P8DYNSZ7SpnUZdpsCfFQ/MtV3BrExeDgfZS wEkQfmFGy62S/DxmJslg+ZRWzLOVmNM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733176910; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ervb2K7sqVuvepYZrDqX+K0WK8EkwpeLtzoNV7Q9jlQ=; b=0zzRahitHBdg1T5xEgkH973A9OOSJNmFE1+n1wogkCpwK+As6I7uoMrVIfGSPTbtLqmZb9 lGNtzwB2S68KFXAg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4007113A31; Mon, 2 Dec 2024 22:01:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 0KWwAU0uTmdlIAAAD6G6ig (envelope-from ); Mon, 02 Dec 2024 22:01:49 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , Thomas Huth Subject: [PATCH 5/6] migration: Fix hang after error in destination setup phase Date: Mon, 2 Dec 2024 19:01:36 -0300 Message-Id: <20241202220137.32584-6-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20241202220137.32584-1-farosas@suse.de> References: <20241202220137.32584-1-farosas@suse.de> MIME-Version: 1.0 X-Spamd-Result: default: False [-3.30 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCPT_COUNT_THREE(0.00)[4]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo, suse.de:email, suse.de:mid] Received-SPF: pass client-ip=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org If the destination side fails at migration_ioc_process_incoming() before starting the coroutine, it will report the error but QEMU will not exit. Set the migration state to FAILED and exit the process if exit-on-error allows. CC: Thomas Huth Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2633 Reported-by: Daniel P. Berrangé Signed-off-by: Fabiano Rosas --- migration/channel.c | 11 ++++++----- migration/migration.c | 31 ++++++++++++++++++------------- migration/migration.h | 2 +- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/migration/channel.c b/migration/channel.c index f9de064f3b..6d7f9172d8 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -40,13 +40,14 @@ void migration_channel_process_incoming(QIOChannel *ioc) if (migrate_channel_requires_tls_upgrade(ioc)) { migration_tls_channel_process_incoming(s, ioc, &local_err); + + if (local_err) { + error_report_err(local_err); + } + } else { migration_ioc_register_yank(ioc); - migration_ioc_process_incoming(ioc, &local_err); - } - - if (local_err) { - error_report_err(local_err); + migration_ioc_process_incoming(ioc); } } diff --git a/migration/migration.c b/migration/migration.c index 8a61cc26d7..cd88ebc875 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -943,7 +943,7 @@ static bool migration_should_start_incoming(bool main_channel) return true; } -void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp) +void migration_ioc_process_incoming(QIOChannel *ioc) { MigrationIncomingState *mis = migration_incoming_get_current(); Error *local_err = NULL; @@ -966,10 +966,9 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp) * issue is not possible. */ ret = migration_channel_read_peek(ioc, (void *)&channel_magic, - sizeof(channel_magic), errp); - + sizeof(channel_magic), &local_err); if (ret != 0) { - return; + goto err; } default_channel = (channel_magic == cpu_to_be32(QEMU_VM_FILE_MAGIC)); @@ -977,8 +976,8 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp) default_channel = !mis->from_src_file; } - if (multifd_recv_setup(errp) != 0) { - return; + if (multifd_recv_setup(&local_err) != 0) { + goto err; } if (default_channel) { @@ -995,18 +994,24 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp) postcopy_preempt_new_channel(mis, f); } if (local_err) { - error_propagate(errp, local_err); - return; + goto err; } } - if (migration_should_start_incoming(default_channel)) { - /* If it's a recovery, we're done */ - if (postcopy_try_recover()) { - return; - } + if (migration_should_start_incoming(default_channel) && + !postcopy_try_recover()) { migration_incoming_process(); } + + return; + +err: + error_report_err(local_err); + migrate_set_state(&mis->state, MIGRATION_STATUS_SETUP, + MIGRATION_STATUS_FAILED); + if (mis->exit_on_error) { + exit(EXIT_FAILURE); + } } /** diff --git a/migration/migration.h b/migration/migration.h index 0956e9274b..c367e5ea40 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -477,7 +477,7 @@ void migrate_set_state(MigrationStatus *state, MigrationStatus old_state, MigrationStatus new_state); void migration_fd_process_incoming(QEMUFile *f); -void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp); +void migration_ioc_process_incoming(QIOChannel *ioc); void migration_incoming_process(void); bool migration_has_all_channels(void); From patchwork Mon Dec 2 22:01:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabiano Rosas X-Patchwork-Id: 13891352 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2CF89E69E95 for ; Mon, 2 Dec 2024 22:03:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIEUP-00076x-7K; Mon, 02 Dec 2024 17:01:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIEUN-00076n-Ou for qemu-devel@nongnu.org; Mon, 02 Dec 2024 17:01:55 -0500 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIEUL-0003dS-IQ for qemu-devel@nongnu.org; Mon, 02 Dec 2024 17:01:55 -0500 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 572CF1F387; Mon, 2 Dec 2024 22:01:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733176912; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=siRO2ER29XgC/MLznmevspyWks+406KbmDeRkQWUaPI=; b=WucXY2W81bBktZ56JDcp3wnI1un0vmucUWe/2XhqkpGw77k3qV5+oVxdJ8mxPe+MO9ml9X rtUVW1i1yVpnCH02JZceonFXtlVDzSyMND++vfR+iih7BQR+TqvZuP371fwonLtl50b/uN X/CBRLZrTIolUgjnZZgrkOtHU4FGu0c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733176912; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=siRO2ER29XgC/MLznmevspyWks+406KbmDeRkQWUaPI=; b=bjt0X6j8yjmu7KpR3ZfX5MpcMdzkG7T3VOiQIMVZSEu4uX4hCFEnvLcyagnIAQrdniYRCb J1VXg36V8Xw+hOCA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733176912; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=siRO2ER29XgC/MLznmevspyWks+406KbmDeRkQWUaPI=; b=WucXY2W81bBktZ56JDcp3wnI1un0vmucUWe/2XhqkpGw77k3qV5+oVxdJ8mxPe+MO9ml9X rtUVW1i1yVpnCH02JZceonFXtlVDzSyMND++vfR+iih7BQR+TqvZuP371fwonLtl50b/uN X/CBRLZrTIolUgjnZZgrkOtHU4FGu0c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733176912; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=siRO2ER29XgC/MLznmevspyWks+406KbmDeRkQWUaPI=; b=bjt0X6j8yjmu7KpR3ZfX5MpcMdzkG7T3VOiQIMVZSEu4uX4hCFEnvLcyagnIAQrdniYRCb J1VXg36V8Xw+hOCA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2173D13A31; Mon, 2 Dec 2024 22:01:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 8LsiNk4uTmdlIAAAD6G6ig (envelope-from ); Mon, 02 Dec 2024 22:01:50 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= Subject: [PATCH 6/6] tests/qtest/migration: Add a cancel test Date: Mon, 2 Dec 2024 19:01:37 -0300 Message-Id: <20241202220137.32584-7-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20241202220137.32584-1-farosas@suse.de> References: <20241202220137.32584-1-farosas@suse.de> MIME-Version: 1.0 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; RCVD_TLS_ALL(0.00)[] Received-SPF: pass client-ip=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The qmp_migrate_cancel() command is poorly tested and code inspection reveals that there might be concurrency issues with its usage. Add a test that runs a migration and calls qmp_migrate_cancel() at specific moments. In order to make the test more deterministic, instead of calling qmp_migrate_cancel() at random moments during migration, do it after the migration status change events are seen. The expected result is that qmp_migrate_cancel() on the source ends migration on the source with the "cancelled" state and ends migration on the destination with the "failed" state. Signed-off-by: Fabiano Rosas --- tests/qtest/migration-test.c | 243 +++++++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 74d3000198..48942289bf 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -23,6 +23,8 @@ #include "qapi/qmp/qlist.h" #include "ppc-util.h" +#include "qapi-types-migration.h" + #include "migration-helpers.h" #include "tests/migration/migration-test.h" #ifdef CONFIG_GNUTLS @@ -3774,6 +3776,234 @@ static bool kvm_dirty_ring_supported(void) #endif } +static void test_cancel_src_after_failed(QTestState *from, QTestState *to, + const char *uri, const char *phase) +{ + /* + * No migrate_incoming_qmp() at the start to force source into + * failed state during migrate_qmp(). + */ + + wait_for_serial("src_serial"); + migrate_ensure_converge(from); + + migrate_qmp(from, to, uri, NULL, "{}"); + + migration_event_wait(from, phase); + migrate_cancel(from); + + /* cancelling will not move the migration out of 'failed' */ + + wait_for_migration_status(from, "failed", + (const char * []) { "completed", NULL }); + + /* + * Not waiting for the destination because it never started + * migration. + */ +} + +static void test_cancel_src_after_cancelled(QTestState *from, QTestState *to, + const char *uri, const char *phase) +{ + migrate_incoming_qmp(to, uri, "{ 'exit-on-error': false }"); + + wait_for_serial("src_serial"); + migrate_ensure_converge(from); + + migrate_qmp(from, to, uri, NULL, "{}"); + + /* To move to cancelled/cancelling */ + migrate_cancel(from); + migration_event_wait(from, phase); + + /* The migrate_cancel under test */ + migrate_cancel(from); + + wait_for_migration_status(from, "cancelled", + (const char * []) { "completed", NULL }); + + wait_for_migration_status(to, "failed", + (const char * []) { "completed", NULL }); +} + +static void test_cancel_src_after_complete(QTestState *from, QTestState *to, + const char *uri, const char *phase) +{ + migrate_incoming_qmp(to, uri, "{ 'exit-on-error': false }"); + + wait_for_serial("src_serial"); + migrate_ensure_converge(from); + + migrate_qmp(from, to, uri, NULL, "{}"); + + migration_event_wait(from, phase); + migrate_cancel(from); + + /* + * qmp_migrate_cancel() exits early if migration is not running + * anymore, the status will not change to cancelled. + */ + wait_for_migration_complete(from); + wait_for_migration_complete(to); +} + +static void test_cancel_src_after_none(QTestState *from, QTestState *to, + const char *uri, const char *phase) +{ + /* + * Test that cancelling without a migration happening does not + * affect subsequent migrations + */ + migrate_cancel(to); + + wait_for_serial("src_serial"); + migrate_cancel(from); + + migrate_incoming_qmp(to, uri, "{ 'exit-on-error': false }"); + + migrate_ensure_converge(from); + migrate_qmp(from, to, uri, NULL, "{}"); + + wait_for_migration_complete(from); + wait_for_migration_complete(to); +} + +static void test_cancel_src_after_postcopy(QTestState *from, QTestState *to, + const char *uri, const char *phase) +{ + bool postcopy_active = g_str_equal(phase, "postcopy-active"); + bool postcopy_paused = g_str_equal(phase, "postcopy-paused"); + bool postcopy_recover = g_str_equal(phase, "postcopy-recover-setup") || + g_str_equal(phase, "postcopy-recover"); + + migrate_set_capability(from, "postcopy-ram", true); + migrate_set_capability(to, "postcopy-ram", true); + + migrate_incoming_qmp(to, uri, "{ 'exit-on-error': false }"); + + wait_for_serial("src_serial"); + migrate_ensure_non_converge(from); + + migrate_qmp(from, to, uri, NULL, "{}"); + + migration_event_wait(from, "active"); + + /* Turn postcopy speed down, 4K/s is slow enough on any machines */ + migrate_set_parameter_int(from, "max-postcopy-bandwidth", 4096); + qtest_qmp_assert_success(from, "{ 'execute': 'migrate-start-postcopy' }"); + + if (!postcopy_active) { + migration_event_wait(from, "postcopy-active"); + migration_event_wait(to, "postcopy-active"); + + wait_for_stop(from, &src_state); + qtest_qmp_eventwait(to, "RESUME"); + + migrate_pause(from); + } + + if (postcopy_recover) { + migration_event_wait(to, "postcopy-paused"); + migration_event_wait(from, "postcopy-paused"); + + migrate_recover(to, uri); + migrate_qmp(from, to, uri, NULL, "{'resume': true}"); + } + + migration_event_wait(from, phase); + migrate_cancel(from); + migration_event_wait(from, "cancelling"); + + wait_for_migration_status(from, "cancelled", + (const char * []) { "completed", NULL }); + + if (postcopy_paused || postcopy_recover) { + /* + * Cancelling on source is not detectable by the destination, + * so it remains paused. + */ + migration_event_wait(to, "postcopy-paused"); + } else { + wait_for_migration_status(to, "failed", + (const char * []) { "completed", NULL }); + } +} + +static void test_cancel_src_pre_switchover(QTestState *from, QTestState *to, + const char *uri, const char *phase) +{ + migrate_set_capability(from, "pause-before-switchover", true); + migrate_set_capability(to, "pause-before-switchover", true); + + migrate_set_parameter_int(from, "multifd-channels", 2); + migrate_set_parameter_int(to, "multifd-channels", 2); + migrate_set_capability(from, "multifd", true); + migrate_set_capability(to, "multifd", true); + + migrate_incoming_qmp(to, uri, "{ 'exit-on-error': false }"); + + wait_for_serial("src_serial"); + migrate_ensure_converge(from); + + migrate_qmp(from, to, uri, NULL, "{}"); + + migration_event_wait(from, phase); + migrate_cancel(from); + migration_event_wait(from, "cancelling"); + + wait_for_migration_status(from, "cancelled", + (const char * []) { "completed", NULL }); + + wait_for_migration_status(to, "failed", + (const char * []) { "completed", NULL }); +} + +static void test_cancel_src_after_status(void *opaque) +{ + const char *test_path = opaque; + g_autofree char *phase = g_path_get_basename(test_path); + g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); + QTestState *from, *to; + MigrateStart args = { + .hide_stderr = true, + }; + + if (test_migrate_start(&from, &to, "defer", &args)) { + return; + } + + if (g_str_has_prefix(phase, "postcopy")) { + if (!ufd_version_check()) { + g_test_skip("No postcopy support. " + "Cannot test migrate_cancel in postcopy states"); + goto out; + } + + test_cancel_src_after_postcopy(from, to, uri, phase); + + } else if (g_str_equal(phase, "cancelling") || + g_str_equal(phase, "cancelled")) { + test_cancel_src_after_cancelled(from, to, uri, phase); + + } else if (g_str_equal(phase, "completed")) { + test_cancel_src_after_complete(from, to, uri, phase); + + } else if (g_str_equal(phase, "failed")) { + test_cancel_src_after_failed(from, to, uri, phase); + + } else if (g_str_equal(phase, "none")) { + test_cancel_src_after_none(from, to, uri, phase); + + } else { + /* any state that comes before pre-switchover */ + test_cancel_src_pre_switchover(from, to, uri, phase); + } + +out: + test_migrate_end(from, to, false); +} + int main(int argc, char **argv) { bool has_kvm, has_tcg; @@ -4034,6 +4264,19 @@ int main(int argc, char **argv) } } + for (int i = MIGRATION_STATUS_NONE; i < MIGRATION_STATUS__MAX; i++) { + switch (i) { + case MIGRATION_STATUS_DEVICE: /* happens too fast */ + case MIGRATION_STATUS_WAIT_UNPLUG: /* no support in tests */ + case MIGRATION_STATUS_COLO: /* no support in tests */ + continue; + default: + migration_test_add_suffix("/migration/cancel/src/after/", + MigrationStatus_str(i), + test_cancel_src_after_status); + } + } + ret = g_test_run(); g_assert_cmpint(ret, ==, 0);