From nobody Tue Nov 26 22:30:36 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1704342987; cv=none; d=zohomail.com; s=zohoarc; b=ctoOR/GpUIVE4G5yYuJrrVZXFzw+Docxh8JC9olooZLyhzOXUTorf53FJCU5sGj+Ua86uIy2mJDh0kDEVO62hPzyFsJM0F8bAfQzOqncIg0HvhHm4p6GEsuqc6aA6R56ZbJlf8YBevrEhPLAbuFU7uL+nZzeKHPyseoaW0L7mVM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704342987; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9wo1amShqbR7nHhQ6whCPhB59mDEhZ8kFcQVY5uBXCI=; b=mE2UGvFk23Qd2tWlnFy6PFuH+S/gyk/ML6jPQfqXlZGTD5mEp1ijwjMzCB8+41D5JYdrFSnIxIKL8aKs8D8B3sFHX8mCtcY3M/5JXUn+6xQLIATl3jv6aIrxTJHrPPvocAhU7xBnVqL0tqUK0vypAELkCUUiXwAX74vNvp3Xtdc= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704342987409648.0742201554738; Wed, 3 Jan 2024 20:36:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLFQA-0001h3-Nj; Wed, 03 Jan 2024 23:33:30 -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 1rLFQ8-0001OA-0y for qemu-devel@nongnu.org; Wed, 03 Jan 2024 23:33:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLFQ6-0006da-2T for qemu-devel@nongnu.org; Wed, 03 Jan 2024 23:33:27 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-6JMG9sumPt2Wm-UzdSVX3w-1; Wed, 03 Jan 2024 23:33:24 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E647A280A9BB; Thu, 4 Jan 2024 04:33:23 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1853EC15968; Thu, 4 Jan 2024 04:33:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704342805; h=from:from:reply-to:subject:subject: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=9wo1amShqbR7nHhQ6whCPhB59mDEhZ8kFcQVY5uBXCI=; b=gjh5CTrbP2O/Ui1dl/C5sOhaVTq2Av/2x6xTveYUK+xqyGZOd8GYbjZ3tRdVLqccKhDmlu /438hjj30oGxLksRPRysIZWi7RpAM7+QURnAY1N0SnABiCtpE0sOeU9L7b06NOBqm+AWQn Pjj3bkbWcxby+xfllRHVQDH/A1cKmXs= X-MC-Unique: 6JMG9sumPt2Wm-UzdSVX3w-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Stefan Hajnoczi Cc: Fabiano Rosas , Steve Sistare , Juan Quintela , peterx@redhat.com, Leonardo Bras Soares Passos , Avihai Horon Subject: [PULL 13/26] tests/qtest: precopy migration with suspend Date: Thu, 4 Jan 2024 12:31:58 +0800 Message-ID: <20240104043213.431566-14-peterx@redhat.com> In-Reply-To: <20240104043213.431566-1-peterx@redhat.com> References: <20240104043213.431566-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -46 X-Spam_score: -4.7 X-Spam_bar: ---- X-Spam_report: (-4.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.601, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1704342988237100001 Content-Type: text/plain; charset="utf-8" From: Steve Sistare Add a test case to verify that the suspended state is handled correctly during live migration precopy. The test suspends the src, migrates, then wakes the dest. Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas Reviewed-by: Peter Xu Link: https://lore.kernel.org/r/1704312341-66640-12-git-send-email-steven.s= istare@oracle.com Signed-off-by: Peter Xu --- tests/qtest/migration-helpers.h | 2 ++ tests/qtest/migration-helpers.c | 3 ++ tests/qtest/migration-test.c | 62 +++++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helper= s.h index 3d32699c45..b478549096 100644 --- a/tests/qtest/migration-helpers.h +++ b/tests/qtest/migration-helpers.h @@ -18,6 +18,8 @@ typedef struct QTestMigrationState { bool stop_seen; bool resume_seen; + bool suspend_seen; + bool suspend_me; } QTestMigrationState; =20 bool migrate_watch_for_events(QTestState *who, const char *name, diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helper= s.c index fd3b94efa2..37e8e812c5 100644 --- a/tests/qtest/migration-helpers.c +++ b/tests/qtest/migration-helpers.c @@ -32,6 +32,9 @@ bool migrate_watch_for_events(QTestState *who, const char= *name, if (g_str_equal(name, "STOP")) { state->stop_seen =3D true; return true; + } else if (g_str_equal(name, "SUSPEND")) { + state->suspend_seen =3D true; + return true; } else if (g_str_equal(name, "RESUME")) { state->resume_seen =3D true; return true; diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 2e2ab6af3c..a3bfbf2654 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -178,7 +178,7 @@ static void bootfile_delete(void) /* * Wait for some output in the serial output file, * we get an 'A' followed by an endless string of 'B's - * but on the destination we won't have the A. + * but on the destination we won't have the A (unless we enabled suspend/r= esume) */ static void wait_for_serial(const char *side) { @@ -245,6 +245,13 @@ static void wait_for_resume(QTestState *who, QTestMigr= ationState *state) } } =20 +static void wait_for_suspend(QTestState *who, QTestMigrationState *state) +{ + if (state->suspend_me && !state->suspend_seen) { + qtest_qmp_eventwait(who, "SUSPEND"); + } +} + /* * It's tricky to use qemu's migration event capability with qtest, * events suddenly appearing confuse the qmp()/hmp() responses. @@ -299,7 +306,7 @@ static void wait_for_migration_pass(QTestState *who) { uint64_t pass, prev_pass =3D 0, changes =3D 0; =20 - while (changes < 2 && !src_state.stop_seen) { + while (changes < 2 && !src_state.stop_seen && !src_state.suspend_seen)= { usleep(1000); pass =3D get_migration_pass(who); changes +=3D (pass !=3D prev_pass); @@ -584,6 +591,12 @@ static void migrate_wait_for_dirty_mem(QTestState *fro= m, usleep(1000 * 10); } while (qtest_readq(to, marker_address) !=3D MAGIC_MARKER); =20 + + /* If suspended, src only iterates once, and watch_byte may never chan= ge */ + if (src_state.suspend_me) { + return; + } + /* * Now ensure that already transferred bytes are * dirty again from the guest workload. Note the @@ -771,6 +784,7 @@ static int test_migrate_start(QTestState **from, QTestS= tate **to, dst_state =3D (QTestMigrationState) { }; src_state =3D (QTestMigrationState) { }; bootfile_create(tmpfs, args->suspend_me); + src_state.suspend_me =3D args->suspend_me; =20 if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { memory_size =3D "150M"; @@ -1717,6 +1731,7 @@ static void test_precopy_common(MigrateCommon *args) /* Wait for the first serial output from the source */ if (args->result =3D=3D MIG_TEST_SUCCEED) { wait_for_serial("src_serial"); + wait_for_suspend(from, &src_state); } =20 if (args->live) { @@ -1793,6 +1808,11 @@ static void test_precopy_common(MigrateCommon *args) =20 wait_for_resume(to, &dst_state); =20 + if (args->start.suspend_me) { + /* wakeup succeeds only if guest is suspended */ + qtest_qmp_assert_success(to, "{'execute': 'system_wakeup'}"); + } + wait_for_serial("dest_serial"); } =20 @@ -1879,6 +1899,34 @@ static void test_precopy_unix_plain(void) test_precopy_common(&args); } =20 +static void test_precopy_unix_suspend_live(void) +{ + g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); + MigrateCommon args =3D { + .listen_uri =3D uri, + .connect_uri =3D uri, + /* + * despite being live, the test is fast because the src + * suspends immediately. + */ + .live =3D true, + .start.suspend_me =3D true, + }; + + test_precopy_common(&args); +} + +static void test_precopy_unix_suspend_notlive(void) +{ + g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); + MigrateCommon args =3D { + .listen_uri =3D uri, + .connect_uri =3D uri, + .start.suspend_me =3D true, + }; + + test_precopy_common(&args); +} =20 static void test_precopy_unix_dirty_ring(void) { @@ -3279,7 +3327,7 @@ static bool kvm_dirty_ring_supported(void) int main(int argc, char **argv) { bool has_kvm, has_tcg; - bool has_uffd; + bool has_uffd, is_x86; const char *arch; g_autoptr(GError) err =3D NULL; const char *qemu_src =3D getenv(QEMU_ENV_SRC); @@ -3309,6 +3357,7 @@ int main(int argc, char **argv) =20 has_uffd =3D ufd_version_check(); arch =3D qtest_get_arch(); + is_x86 =3D !strcmp(arch, "i386") || !strcmp(arch, "x86_64"); =20 /* * On ppc64, the test only works with kvm-hv, but not with kvm-pr and = TCG @@ -3339,6 +3388,13 @@ int main(int argc, char **argv) =20 module_call_init(MODULE_INIT_QOM); =20 + if (is_x86) { + qtest_add_func("/migration/precopy/unix/suspend/live", + test_precopy_unix_suspend_live); + qtest_add_func("/migration/precopy/unix/suspend/notlive", + test_precopy_unix_suspend_notlive); + } + if (has_uffd) { qtest_add_func("/migration/postcopy/plain", test_postcopy); qtest_add_func("/migration/postcopy/recovery/plain", --=20 2.41.0