Skip to contentSkip to conversation

lib: add function to request migration

PATCH In review Nico Boehr 3 participants 8 messages Dec 12, 2022 – Dec 13, 2022

Subsystems (2)
lore
Share & tools
lore

Nico Boehr

author
#0 lore raw

v3 cover lib: add function to request migration

v2->v3:
---
* s390x: remove unneeded parenthesis (thanks Claudio)

v1->v2:
---
* arm: commit message gib->gic (thanks Andrew)
* arm: remove unneeded {} (thanks Andrew)
* s390x: make patch less intrusive (thanks Claudio)

With this series, I pick up a suggestion Claudio has brought up in my CMM-migration series[1].

Migration tests can ask migrate_cmd to migrate them to a new QEMU process. Requesting migration and waiting for completion is hence a common pattern which is repeated all over the code base. Add a function which does all of that to avoid repetition.

Since migrate_cmd currently can only migrate exactly once, this function is called migrate_once() and is a no-op when it has been called before. This can simplify the control flow, especially when tests are skipped.

[1] https://lore.kernel.org/kvm/20221125154646.5974cb52@p-imbrenda/

Nico Boehr (4):
lib: add function to request migration
powerpc: use migrate_once() in migration tests
s390x: use migrate_once() in migration tests
arm: use migrate_once() in migration tests

 arm/Makefile.common     |  1 +
 powerpc/Makefile.common |  1 +
 s390x/Makefile          |  1 +
 lib/migrate.h           |  9 ++++++++
 lib/migrate.c           | 34 ++++++++++++++++++++++++++++
 arm/debug.c             | 17 +++++---------
 arm/gic.c               | 49 ++++++++++++-----------------------------
 powerpc/sprs.c          |  4 ++--
 s390x/migration-cmm.c   | 24 ++++++--------------
 s390x/migration-sck.c   |  4 ++--
 s390x/migration-skey.c  | 20 ++++++-----------
 s390x/migration.c       |  7 ++----
 12 files changed, 85 insertions(+), 86 deletions(-)
 create mode 100644 lib/migrate.h
 create mode 100644 lib/migrate.c
Signature · 1 line
2.36.1
author
#1 lore raw

PATCH v3 1/4 lib: add function to request migration

Migration tests can ask migrate_cmd to migrate them to a new QEMU process. Requesting migration and waiting for completion is hence a common pattern which is repeated all over the code base. Add a function which does all of that to avoid repeating the same pattern.

Since migrate_cmd currently can only migrate exactly once, this function is called migrate_once() and is a no-op when it has been called before. This can simplify the control flow, especially when tests are skipped.

---
 lib/migrate.h |  9 +++++++++
 lib/migrate.c | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)
 create mode 100644 lib/migrate.h
 create mode 100644 lib/migrate.c
lib/migrate.h new file +9 -0
new file mode 100644
index 000000000000..3c94e6af761c
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Migration-related functions
+ *
+ * Copyright IBM Corp. 2022
+ * Author: Nico Boehr <[email protected]>
+ */
+
+void migrate_once(void);
lib/migrate.c new file +34 -0
new file mode 100644
index 000000000000..527e63ae189b
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Migration-related functions
+ *
+ * Copyright IBM Corp. 2022
+ * Author: Nico Boehr <[email protected]>
+ */
+#include <libcflat.h>
+#include "migrate.h"
+
+/* static for now since we only support migrating exactly once per test. */
+static void migrate(void)
+{
+	puts("Now migrate the VM, then press a key to continue...\n");
+	(void)getchar();
+	report_info("Migration complete");
+}
+
+/*
+ * Initiate migration and wait for it to complete.
+ * If this function is called more than once, it is a no-op.
+ * Since migrate_cmd can only migrate exactly once this function can
+ * simplify the control flow, especially when skipping tests.
+ */
+void migrate_once(void)
+{
+	static bool migrated;
+
+	if (migrated)
+		return;
+
+	migrated = true;
+	migrate();
+}
Signature · 1 line
2.36.1
author
#2 lore raw

PATCH v3 2/4 powerpc: use migrate_once() in migration tests

In reply to Nico Boehr
---
 powerpc/Makefile.common | 1 +
 powerpc/sprs.c          | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
powerpc/Makefile.common +1 -0
index 12c280c15fff..8ce00340b6be 100644
@@ -36,6 +36,7 @@ cflatobjs += lib/getchar.o
 cflatobjs += lib/alloc_phys.o
 cflatobjs += lib/alloc.o
 cflatobjs += lib/devicetree.o
+cflatobjs += lib/migrate.o
 cflatobjs += lib/powerpc/io.o
 cflatobjs += lib/powerpc/hcall.o
 cflatobjs += lib/powerpc/setup.o
powerpc/sprs.c +2 -2
index d3c8780e8376..5cc1cd16cfda 100644
@@ -21,6 +21,7 @@
  */
 #include <libcflat.h>
 #include <util.h>
+#include <migrate.h>
 #include <alloc.h>
 #include <asm/handlers.h>
 #include <asm/hcall.h>
@@ -285,8 +286,7 @@ int main(int argc, char **argv)
 	get_sprs(before);
 
 	if (pause) {
-		puts("Now migrate the VM, then press a key to continue...\n");
-		(void) getchar();
+		migrate_once();
 	} else {
 		puts("Sleeping...\n");
 		handle_exception(0x900, &dec_except_handler, &decr);
Signature · 1 line
2.36.1
author
#3 lore raw

PATCH v3 3/4 s390x: use migrate_once() in migration tests

In reply to Nico Boehr

migrate_once() can simplify the control flow in migration-skey and migration-cmm.

---
 s390x/Makefile         |  1 +
 s390x/migration-cmm.c  | 24 +++++++-----------------
 s390x/migration-sck.c  |  4 ++--
 s390x/migration-skey.c | 20 +++++++-------------
 s390x/migration.c      |  7 ++-----
 5 files changed, 19 insertions(+), 37 deletions(-)
s390x/Makefile +1 -0
index bf1504f9d58c..52a9d821974e 100644
@@ -85,6 +85,7 @@ cflatobjs += lib/alloc_page.o
 cflatobjs += lib/vmalloc.o
 cflatobjs += lib/alloc_phys.o
 cflatobjs += lib/getchar.o
+cflatobjs += lib/migrate.o
 cflatobjs += lib/s390x/io.o
 cflatobjs += lib/s390x/stack.o
 cflatobjs += lib/s390x/sclp.o
s390x/migration-cmm.c +7 -17
index aa7910ca76bf..43673f18e45a 100644
@@ -9,6 +9,7 @@
  */
 
 #include <libcflat.h>
+#include <migrate.h>
 #include <asm/interrupt.h>
 #include <asm/page.h>
 #include <asm/cmm.h>
@@ -39,8 +40,7 @@ static void test_migration(void)
 		essa(ESSA_SET_POT_VOLATILE, (unsigned long)pagebuf[i + 3]);
 	}
 
-	puts("Please migrate me, then press return\n");
-	(void)getchar();
+	migrate_once();
 
 	for (i = 0; i < NUM_PAGES; i++) {
 		actual_state = essa(ESSA_GET_STATE, (unsigned long)pagebuf[i]);
@@ -53,25 +53,15 @@ static void test_migration(void)
 
 int main(void)
 {
-	bool has_essa = check_essa_available();
-
 	report_prefix_push("migration-cmm");
-	if (!has_essa) {
-		report_skip("ESSA is not available");
 
-		/*
-		 * If we just exit and don't ask migrate_cmd to migrate us, it
-		 * will just hang forever. Hence, also ask for migration when we
-		 * skip this test alltogether.
-		 */
-		puts("Please migrate me, then press return\n");
-		(void)getchar();
+	if (!check_essa_available())
+		report_skip("ESSA is not available");
+	else
+		test_migration();
 
-		goto done;
-	}
+	migrate_once();
 
-	test_migration();
-done:
 	report_prefix_pop();
 	return report_summary();
 }
s390x/migration-sck.c +2 -2
index 2d9a195ab4c4..2a9c87071643 100644
@@ -9,6 +9,7 @@
  */
 
 #include <libcflat.h>
+#include <migrate.h>
 #include <asm/time.h>
 
 static void test_sck_migration(void)
@@ -30,8 +31,7 @@ static void test_sck_migration(void)
 	report(!cc, "clock running after set");
 	report(now_after_set >= time_to_set, "TOD clock value is larger than what has been set");
 
-	puts("Please migrate me, then press return\n");
-	(void)getchar();
+	migrate_once();
 
 	cc = stckf(&now_after_migration);
 	report(!cc, "clock still set");
s390x/migration-skey.c +7 -13
index b7bd82581abe..a91eb6b5a63e 100644
@@ -9,6 +9,7 @@
  */
 
 #include <libcflat.h>
+#include <migrate.h>
 #include <asm/facility.h>
 #include <asm/page.h>
 #include <asm/mem.h>
@@ -35,8 +36,7 @@ static void test_migration(void)
 		set_storage_key(pagebuf[i], key_to_set, 1);
 	}
 
-	puts("Please migrate me, then press return\n");
-	(void)getchar();
+	migrate_once();
 
 	for (i = 0; i < NUM_PAGES; i++) {
 		actual_key.val = get_storage_key(pagebuf[i]);
@@ -64,19 +64,13 @@ static void test_migration(void)
 int main(void)
 {
 	report_prefix_push("migration-skey");
-	if (test_facility(169)) {
-		report_skip("storage key removal facility is active");
 
-		/*
-		 * If we just exit and don't ask migrate_cmd to migrate us, it
-		 * will just hang forever. Hence, also ask for migration when we
-		 * skip this test altogether.
-		 */
-		puts("Please migrate me, then press return\n");
-		(void)getchar();
-	} else {
+	if (test_facility(169))
+		report_skip("storage key removal facility is active");
+	else
 		test_migration();
-	}
+
+	migrate_once();
 
 	report_prefix_pop();
 	return report_summary();
s390x/migration.c +2 -5
index a45296374cd8..fe6ea8369edb 100644
@@ -8,6 +8,7 @@
  *  Nico Boehr <[email protected]>
  */
 #include <libcflat.h>
+#include <migrate.h>
 #include <asm/arch_def.h>
 #include <asm/vector.h>
 #include <asm/barrier.h>
@@ -178,11 +179,7 @@ int main(void)
 		mb();
 	flag_thread_complete = 0;
 
-	/* ask migrate_cmd to migrate (it listens for 'migrate') */
-	puts("Please migrate me, then press return\n");
-
-	/* wait for migration to finish, we will read a newline */
-	(void)getchar();
+	migrate_once();
 
 	flag_migration_complete = 1;
 
Signature · 1 line
2.36.1
Reviewed-by on v3 3/4
#4 lore raw

Re: [kvm-unit-tests PATCH v3 3/4] s390x: use migrate_once() in migration tests

Quoted 4 lines · On Mon, 12 Dec 2022 12:17:30 +0100 Nico Boehr <[email protected]> wrote:

migrate_once() can simplify the control flow in migration-skey and migration-cmm.

Quoted 167 lines
---
 s390x/Makefile         |  1 +
 s390x/migration-cmm.c  | 24 +++++++-----------------
 s390x/migration-sck.c  |  4 ++--
 s390x/migration-skey.c | 20 +++++++-------------
 s390x/migration.c      |  7 ++-----
 5 files changed, 19 insertions(+), 37 deletions(-)
s390x/Makefile +1 -0
index bf1504f9d58c..52a9d821974e 100644
@@ -85,6 +85,7 @@ cflatobjs += lib/alloc_page.o
 cflatobjs += lib/vmalloc.o
 cflatobjs += lib/alloc_phys.o
 cflatobjs += lib/getchar.o
+cflatobjs += lib/migrate.o
 cflatobjs += lib/s390x/io.o
 cflatobjs += lib/s390x/stack.o
 cflatobjs += lib/s390x/sclp.o
s390x/migration-cmm.c +7 -17
index aa7910ca76bf..43673f18e45a 100644
@@ -9,6 +9,7 @@
  */
 
 #include <libcflat.h>
+#include <migrate.h>
 #include <asm/interrupt.h>
 #include <asm/page.h>
 #include <asm/cmm.h>
@@ -39,8 +40,7 @@ static void test_migration(void)
 		essa(ESSA_SET_POT_VOLATILE, (unsigned long)pagebuf[i + 3]);
 	}
 
-	puts("Please migrate me, then press return\n");
-	(void)getchar();
+	migrate_once();
 
 	for (i = 0; i < NUM_PAGES; i++) {
 		actual_state = essa(ESSA_GET_STATE, (unsigned long)pagebuf[i]);
@@ -53,25 +53,15 @@ static void test_migration(void)
 
 int main(void)
 {
-	bool has_essa = check_essa_available();
-
 	report_prefix_push("migration-cmm");
-	if (!has_essa) {
-		report_skip("ESSA is not available");
 
-		/*
-		 * If we just exit and don't ask migrate_cmd to migrate us, it
-		 * will just hang forever. Hence, also ask for migration when we
-		 * skip this test alltogether.
-		 */
-		puts("Please migrate me, then press return\n");
-		(void)getchar();
+	if (!check_essa_available())
+		report_skip("ESSA is not available");
+	else
+		test_migration();
 
-		goto done;
-	}
+	migrate_once();
 
-	test_migration();
-done:
 	report_prefix_pop();
 	return report_summary();
 }
s390x/migration-sck.c +2 -2
index 2d9a195ab4c4..2a9c87071643 100644
@@ -9,6 +9,7 @@
  */
 
 #include <libcflat.h>
+#include <migrate.h>
 #include <asm/time.h>
 
 static void test_sck_migration(void)
@@ -30,8 +31,7 @@ static void test_sck_migration(void)
 	report(!cc, "clock running after set");
 	report(now_after_set >= time_to_set, "TOD clock value is larger than what has been set");
 
-	puts("Please migrate me, then press return\n");
-	(void)getchar();
+	migrate_once();
 
 	cc = stckf(&now_after_migration);
 	report(!cc, "clock still set");
s390x/migration-skey.c +7 -13
index b7bd82581abe..a91eb6b5a63e 100644
@@ -9,6 +9,7 @@
  */
 
 #include <libcflat.h>
+#include <migrate.h>
 #include <asm/facility.h>
 #include <asm/page.h>
 #include <asm/mem.h>
@@ -35,8 +36,7 @@ static void test_migration(void)
 		set_storage_key(pagebuf[i], key_to_set, 1);
 	}
 
-	puts("Please migrate me, then press return\n");
-	(void)getchar();
+	migrate_once();
 
 	for (i = 0; i < NUM_PAGES; i++) {
 		actual_key.val = get_storage_key(pagebuf[i]);
@@ -64,19 +64,13 @@ static void test_migration(void)
 int main(void)
 {
 	report_prefix_push("migration-skey");
-	if (test_facility(169)) {
-		report_skip("storage key removal facility is active");
 
-		/*
-		 * If we just exit and don't ask migrate_cmd to migrate us, it
-		 * will just hang forever. Hence, also ask for migration when we
-		 * skip this test altogether.
-		 */
-		puts("Please migrate me, then press return\n");
-		(void)getchar();
-	} else {
+	if (test_facility(169))
+		report_skip("storage key removal facility is active");
+	else
 		test_migration();
-	}
+
+	migrate_once();
 
 	report_prefix_pop();
 	return report_summary();
s390x/migration.c +2 -5
index a45296374cd8..fe6ea8369edb 100644
@@ -8,6 +8,7 @@
  *  Nico Boehr <[email protected]>
  */
 #include <libcflat.h>
+#include <migrate.h>
 #include <asm/arch_def.h>
 #include <asm/vector.h>
 #include <asm/barrier.h>
@@ -178,11 +179,7 @@ int main(void)
 		mb();
 	flag_thread_complete = 0;
 
-	/* ask migrate_cmd to migrate (it listens for 'migrate') */
-	puts("Please migrate me, then press return\n");
-
-	/* wait for migration to finish, we will read a newline */
-	(void)getchar();
+	migrate_once();
 
 	flag_migration_complete = 1;
 
author
#5 lore raw

PATCH v3 4/4 arm: use migrate_once() in migration tests

In reply to Nico Boehr

Some tests already shipped with their own do_migrate() function, remove it and instead use the new migrate_once() function. The control flow in the gic tests can be simplified due to migrate_once().

---
 arm/Makefile.common |  1 +
 arm/debug.c         | 17 +++++-----------
 arm/gic.c           | 49 +++++++++++++--------------------------------
 3 files changed, 20 insertions(+), 47 deletions(-)
arm/Makefile.common +1 -0
index 38385e0c558e..1bbec64f2342 100644
@@ -38,6 +38,7 @@ cflatobjs += lib/alloc_page.o
 cflatobjs += lib/vmalloc.o
 cflatobjs += lib/alloc.o
 cflatobjs += lib/devicetree.o
+cflatobjs += lib/migrate.o
 cflatobjs += lib/pci.o
 cflatobjs += lib/pci-host-generic.o
 cflatobjs += lib/pci-testdev.o
arm/debug.c +5 -12
index e9f805632db7..b3e9749c598f 100644
@@ -1,4 +1,5 @@
 #include <libcflat.h>
+#include <migrate.h>
 #include <errata.h>
 #include <asm/setup.h>
 #include <asm/processor.h>
@@ -257,13 +258,6 @@ static void reset_debug_state(void)
 	isb();
 }
 
-static void do_migrate(void)
-{
-	puts("Now migrate the VM, then press a key to continue...\n");
-	(void)getchar();
-	report_info("Migration complete");
-}
-
 static noinline void test_hw_bp(bool migrate)
 {
 	extern unsigned char hw_bp0;
@@ -291,7 +285,7 @@ static noinline void test_hw_bp(bool migrate)
 	isb();
 
 	if (migrate) {
-		do_migrate();
+		migrate_once();
 		report(num_bp == get_num_hw_bp(), "brps match after migrate");
 	}
 
@@ -335,7 +329,7 @@ static noinline void test_wp(bool migrate)
 	isb();
 
 	if (migrate) {
-		do_migrate();
+		migrate_once();
 		report(num_wp == get_num_wp(), "wrps match after migrate");
 	}
 
@@ -368,9 +362,8 @@ static noinline void test_ss(bool migrate)
 	write_sysreg(mdscr, mdscr_el1);
 	isb();
 
-	if (migrate) {
-		do_migrate();
-	}
+	if (migrate)
+		migrate_once();
 
 	asm volatile("msr daifclr, #8");
 
arm/gic.c +14 -35

117 lines not on this page · raw message

Signature · 1 line
2.36.1
#6 lore raw
In reply to Nico Boehr

Paolo and/or Thomas: if you do not have objections, could you pick this series?

every affected architecture has been reviewed :)

Quoted 46 lines · On Mon, 12 Dec 2022 12:17:27 +0100 Nico Boehr <[email protected]> wrote:

v2->v3:
---
* s390x: remove unneeded parenthesis (thanks Claudio)

v1->v2:
---
* arm: commit message gib->gic (thanks Andrew)
* arm: remove unneeded {} (thanks Andrew)
* s390x: make patch less intrusive (thanks Claudio)

With this series, I pick up a suggestion Claudio has brought up in my CMM-migration series[1].

Migration tests can ask migrate_cmd to migrate them to a new QEMU process. Requesting migration and waiting for completion is hence a common pattern which is repeated all over the code base. Add a function which does all of that to avoid repetition.

Since migrate_cmd currently can only migrate exactly once, this function is called migrate_once() and is a no-op when it has been called before. This can simplify the control flow, especially when tests are skipped.

[1] https://lore.kernel.org/kvm/20221125154646.5974cb52@p-imbrenda/

Nico Boehr (4):
lib: add function to request migration
powerpc: use migrate_once() in migration tests
s390x: use migrate_once() in migration tests
arm: use migrate_once() in migration tests

 arm/Makefile.common     |  1 +
 powerpc/Makefile.common |  1 +
 s390x/Makefile          |  1 +
 lib/migrate.h           |  9 ++++++++
 lib/migrate.c           | 34 ++++++++++++++++++++++++++++
 arm/debug.c             | 17 +++++---------
 arm/gic.c               | 49 ++++++++++++-----------------------------
 powerpc/sprs.c          |  4 ++--
 s390x/migration-cmm.c   | 24 ++++++--------------
 s390x/migration-sck.c   |  4 ++--
 s390x/migration-skey.c  | 20 ++++++-----------
 s390x/migration.c       |  7 ++----
 12 files changed, 85 insertions(+), 86 deletions(-)
 create mode 100644 lib/migrate.h
 create mode 100644 lib/migrate.c
#7 lore raw
Quoted 5 lines · Claudio Imbrenda

Paolo and/or Thomas: if you do not have objections, could you pick this series?

every affected architecture has been reviewed :)

Done.

Thanks,
Thomas

Quoted 51 lines
Quoted 46 lines · On Mon, 12 Dec 2022 12:17:27 +0100 Nico Boehr <[email protected]> wrote:

v2->v3:
---
* s390x: remove unneeded parenthesis (thanks Claudio)

v1->v2:
---
* arm: commit message gib->gic (thanks Andrew)
* arm: remove unneeded {} (thanks Andrew)
* s390x: make patch less intrusive (thanks Claudio)

With this series, I pick up a suggestion Claudio has brought up in my CMM-migration series[1].

Migration tests can ask migrate_cmd to migrate them to a new QEMU process. Requesting migration and waiting for completion is hence a common pattern which is repeated all over the code base. Add a function which does all of that to avoid repetition.

Since migrate_cmd currently can only migrate exactly once, this function is called migrate_once() and is a no-op when it has been called before. This can simplify the control flow, especially when tests are skipped.

[1] https://lore.kernel.org/kvm/20221125154646.5974cb52@p-imbrenda/

Nico Boehr (4):
lib: add function to request migration
powerpc: use migrate_once() in migration tests
s390x: use migrate_once() in migration tests
arm: use migrate_once() in migration tests

  arm/Makefile.common     |  1 +
  powerpc/Makefile.common |  1 +
  s390x/Makefile          |  1 +
  lib/migrate.h           |  9 ++++++++
  lib/migrate.c           | 34 ++++++++++++++++++++++++++++
  arm/debug.c             | 17 +++++---------
  arm/gic.c               | 49 ++++++++++++-----------------------------
  powerpc/sprs.c          |  4 ++--
  s390x/migration-cmm.c   | 24 ++++++--------------
  s390x/migration-sck.c   |  4 ++--
  s390x/migration-skey.c  | 20 ++++++-----------
  s390x/migration.c       |  7 ++----
  12 files changed, 85 insertions(+), 86 deletions(-)

create mode 100644 lib/migrate.h
create mode 100644 lib/migrate.c