All of lore.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v3 0/2] s390x: add migration test for CMM
@ 2022-05-12 13:42 Nico Boehr
  2022-05-12 13:42 ` [kvm-unit-tests PATCH v3 1/2] lib: s390x: add header for CMM related defines Nico Boehr
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nico Boehr @ 2022-05-12 13:42 UTC (permalink / raw)
  To: kvm, linux-s390; +Cc: frankja, imbrenda, thuth

v2->v3:
---
* remove unneeded include asm-offsets.h (Thanks Claudio)
* change prefix of test to match filename (migration-cmm instead of
  cmm-migration)

v1->v2:
---
* Rename cmm-migration.c to migration-cmm.c (Thanks Janosch)
* Replace switch-case with unrolled loop (Thanks Claudio)
* Migrate even when ESSA is not available so we don't hang forever

Upon migration, we expect the CMM page states to be preserved. Add a test which
checks for that.

The new test gets a new file so the existing cmm test can still run when the
prerequisites for running migration tests aren't given (netcat). Therefore, move
some definitions to a common header to be able to re-use them.

Nico Boehr (2):
  lib: s390x: add header for CMM related defines
  s390x: add cmm migration test

 lib/s390x/asm/cmm.h   | 50 ++++++++++++++++++++++++++++
 s390x/Makefile        |  1 +
 s390x/cmm.c           | 25 ++------------
 s390x/migration-cmm.c | 77 +++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg   |  4 +++
 5 files changed, 135 insertions(+), 22 deletions(-)
 create mode 100644 lib/s390x/asm/cmm.h
 create mode 100644 s390x/migration-cmm.c

-- 
2.31.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [kvm-unit-tests PATCH v3 1/2] lib: s390x: add header for CMM related defines
  2022-05-12 13:42 [kvm-unit-tests PATCH v3 0/2] s390x: add migration test for CMM Nico Boehr
@ 2022-05-12 13:42 ` Nico Boehr
  2022-05-12 13:42 ` [kvm-unit-tests PATCH v3 2/2] s390x: add cmm migration test Nico Boehr
  2022-05-12 15:44 ` [kvm-unit-tests PATCH v3 0/2] s390x: add migration test for CMM Claudio Imbrenda
  2 siblings, 0 replies; 4+ messages in thread
From: Nico Boehr @ 2022-05-12 13:42 UTC (permalink / raw)
  To: kvm, linux-s390; +Cc: frankja, imbrenda, thuth

Since we're going to need the definitions in an upcoming migration test for CMM,
add a header for CMM related defines. It is based on
arch/s390/include/asm/page-states.h from linux.

While at it, use the constants in existing calls to CMM related functions.

Also move essa() and test_availability() there to be able to use it outside
cmm.c.

Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
 lib/s390x/asm/cmm.h | 50 +++++++++++++++++++++++++++++++++++++++++++++
 s390x/cmm.c         | 25 +++--------------------
 2 files changed, 53 insertions(+), 22 deletions(-)
 create mode 100644 lib/s390x/asm/cmm.h

diff --git a/lib/s390x/asm/cmm.h b/lib/s390x/asm/cmm.h
new file mode 100644
index 000000000000..554a60031fbf
--- /dev/null
+++ b/lib/s390x/asm/cmm.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ *    Copyright IBM Corp. 2017, 2022
+ *    Author(s): Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
+ *               Nico Boehr <nrb@linux.ibm.com>
+ */
+#include <asm/interrupt.h>
+
+#ifndef PAGE_STATES_H
+#define PAGE_STATES_H
+
+#define ESSA_GET_STATE			0
+#define ESSA_SET_STABLE			1
+#define ESSA_SET_UNUSED			2
+#define ESSA_SET_VOLATILE		3
+#define ESSA_SET_POT_VOLATILE		4
+#define ESSA_SET_STABLE_RESIDENT	5
+#define ESSA_SET_STABLE_IF_RESIDENT	6
+#define ESSA_SET_STABLE_NODAT		7
+
+#define ESSA_MAX	ESSA_SET_STABLE_NODAT
+
+#define ESSA_USAGE_STABLE		0
+#define ESSA_USAGE_UNUSED		1
+#define ESSA_USAGE_POT_VOLATILE		2
+#define ESSA_USAGE_VOLATILE		3
+
+static unsigned long essa(uint8_t state, unsigned long paddr)
+{
+	uint64_t extr_state;
+
+	asm volatile(".insn rrf,0xb9ab0000,%[extr_state],%[addr],%[new_state],0" \
+			: [extr_state] "=d" (extr_state) \
+			: [addr] "a" (paddr), [new_state] "i" (state));
+
+	return (unsigned long)extr_state;
+}
+
+/*
+ * Unfortunately the availability is not indicated by stfl bits, but
+ * we have to try to execute it and test for an operation exception.
+ */
+static inline bool check_essa_available(void)
+{
+	expect_pgm_int();
+	essa(ESSA_GET_STATE, 0);
+	return clear_pgm_int() == 0;
+}
+
+#endif
diff --git a/s390x/cmm.c b/s390x/cmm.c
index c3f0c931ae36..af852838851e 100644
--- a/s390x/cmm.c
+++ b/s390x/cmm.c
@@ -12,19 +12,10 @@
 #include <asm/asm-offsets.h>
 #include <asm/interrupt.h>
 #include <asm/page.h>
+#include <asm/cmm.h>
 
 static uint8_t pagebuf[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
 
-static unsigned long essa(uint8_t state, unsigned long paddr)
-{
-	uint64_t extr_state;
-
-	asm volatile(".insn rrf,0xb9ab0000,%[extr_state],%[addr],%[new_state],0"
-			: [extr_state] "=d" (extr_state)
-			: [addr] "a" (paddr), [new_state] "i" (state));
-	return (unsigned long)extr_state;
-}
-
 static void test_params(void)
 {
 	report_prefix_push("invalid ORC 8");
@@ -39,24 +30,14 @@ static void test_priv(void)
 	report_prefix_push("privileged");
 	expect_pgm_int();
 	enter_pstate();
-	essa(0, (unsigned long)pagebuf);
+	essa(ESSA_GET_STATE, (unsigned long)pagebuf);
 	check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION);
 	report_prefix_pop();
 }
 
-/* Unfortunately the availability is not indicated by stfl bits, but
- * we have to try to execute it and test for an operation exception.
- */
-static bool test_availability(void)
-{
-	expect_pgm_int();
-	essa(0, (unsigned long)pagebuf);
-	return clear_pgm_int() == 0;
-}
-
 int main(void)
 {
-	bool has_essa = test_availability();
+	bool has_essa = check_essa_available();
 
 	report_prefix_push("cmm");
 	if (!has_essa) {
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [kvm-unit-tests PATCH v3 2/2] s390x: add cmm migration test
  2022-05-12 13:42 [kvm-unit-tests PATCH v3 0/2] s390x: add migration test for CMM Nico Boehr
  2022-05-12 13:42 ` [kvm-unit-tests PATCH v3 1/2] lib: s390x: add header for CMM related defines Nico Boehr
@ 2022-05-12 13:42 ` Nico Boehr
  2022-05-12 15:44 ` [kvm-unit-tests PATCH v3 0/2] s390x: add migration test for CMM Claudio Imbrenda
  2 siblings, 0 replies; 4+ messages in thread
From: Nico Boehr @ 2022-05-12 13:42 UTC (permalink / raw)
  To: kvm, linux-s390; +Cc: frankja, imbrenda, thuth

When a VM is migrated, we expect the page states to be preserved. Add a test
which checks for that.

Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
 s390x/Makefile        |  1 +
 s390x/migration-cmm.c | 77 +++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg   |  4 +++
 3 files changed, 82 insertions(+)
 create mode 100644 s390x/migration-cmm.c

diff --git a/s390x/Makefile b/s390x/Makefile
index a8e04aa6fe4d..1877c8a6e86e 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -32,6 +32,7 @@ tests += $(TEST_DIR)/epsw.elf
 tests += $(TEST_DIR)/adtl-status.elf
 tests += $(TEST_DIR)/migration.elf
 tests += $(TEST_DIR)/pv-attest.elf
+tests += $(TEST_DIR)/migration-cmm.elf
 
 pv-tests += $(TEST_DIR)/pv-diags.elf
 
diff --git a/s390x/migration-cmm.c b/s390x/migration-cmm.c
new file mode 100644
index 000000000000..aa7910ca76bf
--- /dev/null
+++ b/s390x/migration-cmm.c
@@ -0,0 +1,77 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * CMM migration tests (ESSA)
+ *
+ * Copyright IBM Corp. 2022
+ *
+ * Authors:
+ *  Nico Boehr <nrb@linux.ibm.com>
+ */
+
+#include <libcflat.h>
+#include <asm/interrupt.h>
+#include <asm/page.h>
+#include <asm/cmm.h>
+#include <bitops.h>
+
+#define NUM_PAGES 128
+static uint8_t pagebuf[NUM_PAGES][PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
+
+static void test_migration(void)
+{
+	int i, state_mask, actual_state;
+	/*
+	 * Maps ESSA actions to states the page is allowed to be in after the
+	 * respective action was executed.
+	 */
+	int allowed_essa_state_masks[4] = {
+		BIT(ESSA_USAGE_STABLE),					/* ESSA_SET_STABLE */
+		BIT(ESSA_USAGE_UNUSED),					/* ESSA_SET_UNUSED */
+		BIT(ESSA_USAGE_VOLATILE),				/* ESSA_SET_VOLATILE */
+		BIT(ESSA_USAGE_VOLATILE) | BIT(ESSA_USAGE_POT_VOLATILE) /* ESSA_SET_POT_VOLATILE */
+	};
+
+	assert(NUM_PAGES % 4 == 0);
+	for (i = 0; i < NUM_PAGES; i += 4) {
+		essa(ESSA_SET_STABLE, (unsigned long)pagebuf[i]);
+		essa(ESSA_SET_UNUSED, (unsigned long)pagebuf[i + 1]);
+		essa(ESSA_SET_VOLATILE, (unsigned long)pagebuf[i + 2]);
+		essa(ESSA_SET_POT_VOLATILE, (unsigned long)pagebuf[i + 3]);
+	}
+
+	puts("Please migrate me, then press return\n");
+	(void)getchar();
+
+	for (i = 0; i < NUM_PAGES; i++) {
+		actual_state = essa(ESSA_GET_STATE, (unsigned long)pagebuf[i]);
+		/* extract the usage state in bits 60 and 61 */
+		actual_state = (actual_state >> 2) & 0x3;
+		state_mask = allowed_essa_state_masks[i % ARRAY_SIZE(allowed_essa_state_masks)];
+		report(BIT(actual_state) & state_mask, "page %d state: expected_mask=0x%x actual_mask=0x%lx", i, state_mask, BIT(actual_state));
+	}
+}
+
+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();
+
+		goto done;
+	}
+
+	test_migration();
+done:
+	report_prefix_pop();
+	return report_summary();
+}
diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
index b456b2881448..9b97d0471bcf 100644
--- a/s390x/unittests.cfg
+++ b/s390x/unittests.cfg
@@ -176,3 +176,7 @@ extra_params = -cpu qemu,gs=off,vx=off
 file = migration.elf
 groups = migration
 smp = 2
+
+[migration-cmm]
+file = migration-cmm.elf
+groups = migration
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [kvm-unit-tests PATCH v3 0/2] s390x: add migration test for CMM
  2022-05-12 13:42 [kvm-unit-tests PATCH v3 0/2] s390x: add migration test for CMM Nico Boehr
  2022-05-12 13:42 ` [kvm-unit-tests PATCH v3 1/2] lib: s390x: add header for CMM related defines Nico Boehr
  2022-05-12 13:42 ` [kvm-unit-tests PATCH v3 2/2] s390x: add cmm migration test Nico Boehr
@ 2022-05-12 15:44 ` Claudio Imbrenda
  2 siblings, 0 replies; 4+ messages in thread
From: Claudio Imbrenda @ 2022-05-12 15:44 UTC (permalink / raw)
  To: Nico Boehr; +Cc: kvm, linux-s390, frankja, thuth

On Thu, 12 May 2022 15:42:31 +0200
Nico Boehr <nrb@linux.ibm.com> wrote:

> v2->v3:
> ---
> * remove unneeded include asm-offsets.h (Thanks Claudio)
> * change prefix of test to match filename (migration-cmm instead of
>   cmm-migration)
> 
> v1->v2:
> ---
> * Rename cmm-migration.c to migration-cmm.c (Thanks Janosch)
> * Replace switch-case with unrolled loop (Thanks Claudio)
> * Migrate even when ESSA is not available so we don't hang forever
> 
> Upon migration, we expect the CMM page states to be preserved. Add a test which
> checks for that.
> 
> The new test gets a new file so the existing cmm test can still run when the
> prerequisites for running migration tests aren't given (netcat). Therefore, move
> some definitions to a common header to be able to re-use them.
> 

thanks, queued

> Nico Boehr (2):
>   lib: s390x: add header for CMM related defines
>   s390x: add cmm migration test
> 
>  lib/s390x/asm/cmm.h   | 50 ++++++++++++++++++++++++++++
>  s390x/Makefile        |  1 +
>  s390x/cmm.c           | 25 ++------------
>  s390x/migration-cmm.c | 77 +++++++++++++++++++++++++++++++++++++++++++
>  s390x/unittests.cfg   |  4 +++
>  5 files changed, 135 insertions(+), 22 deletions(-)
>  create mode 100644 lib/s390x/asm/cmm.h
>  create mode 100644 s390x/migration-cmm.c
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-05-12 15:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-12 13:42 [kvm-unit-tests PATCH v3 0/2] s390x: add migration test for CMM Nico Boehr
2022-05-12 13:42 ` [kvm-unit-tests PATCH v3 1/2] lib: s390x: add header for CMM related defines Nico Boehr
2022-05-12 13:42 ` [kvm-unit-tests PATCH v3 2/2] s390x: add cmm migration test Nico Boehr
2022-05-12 15:44 ` [kvm-unit-tests PATCH v3 0/2] s390x: add migration test for CMM Claudio Imbrenda

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.