Skip to contentSkip to conversation

s390x: add migration test for CMM

PATCH In review Nico Boehr 2 participants 4 messages May 12, 2022

Subsystems (2)
lore
Share & tools
lore

Nico Boehr

author
#0 lore raw

v3 cover s390x: add migration test for CMM

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
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH v3 1/2 lib: s390x: add header for CMM related defines

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.

---
 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
lib/s390x/asm/cmm.h new file +50 -0
new file mode 100644
index 000000000000..554a60031fbf
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ *    Copyright IBM Corp. 2017, 2022
+ *    Author(s): Claudio Imbrenda <[email protected]>
+ *               Nico Boehr <[email protected]>
+ */
+#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
s390x/cmm.c +3 -22
index c3f0c931ae36..af852838851e 100644
@@ -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) {
Signature · 1 line
2.31.1
author
#2 lore raw

PATCH v3 2/2 s390x: add cmm migration test

In reply to Nico Boehr

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

---
 s390x/Makefile        |  1 +
 s390x/migration-cmm.c | 77 +++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg   |  4 +++
 3 files changed, 82 insertions(+)
 create mode 100644 s390x/migration-cmm.c
s390x/Makefile +1 -0
index a8e04aa6fe4d..1877c8a6e86e 100644
@@ -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
 
s390x/migration-cmm.c new file +77 -0

77 lines not on this page · raw message

s390x/unittests.cfg +4 -0
index b456b2881448..9b97d0471bcf 100644
@@ -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
Signature · 1 line
2.31.1
#3 lore raw
In reply to Nico Boehr
Quoted 12 lines · On Thu, 12 May 2022 15:42:31 +0200 Nico Boehr <[email protected]> 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

Quoted 7 lines

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

Quoted 13 lines

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