s390x: add migration test for CMM
v2 cover s390x: add migration test for CMM
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 | 78 +++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 +++ 5 files changed, 136 insertions(+), 22 deletions(-) create mode 100644 lib/s390x/asm/cmm.h create mode 100644 s390x/migration-cmm.c
Signature · 1 line
2.31.1
PATCH v2 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
@@ -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; + + asmvolatile (".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
@@ -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; - - asmvolatile (".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
Re: [kvm-unit-tests PATCH v2 1/2] lib: s390x: add header for CMM related defines
Quoted 10 lines · On Wed, 11 May 2022 10:56:51 +0200 Nico Boehr <[email protected]> wrote:
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.hfrom linux.While at it, use the constants in existing calls to CMM related functions.
Also move
essa()andtest_availability()there to be able to use it outsidecmm.c.Signed-off-by Nico Boehr <[email protected]>
Quoted 114 lines
--- lib/s390x/asm/cmm.h | 50 +++++++++++++++++++++++++++++++++++++++++++++ s390x/cmm.c | 25 +++-------------------- 2 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 lib/s390x/asm/cmm.hlib/s390x/asm/cmm.h new file +50
-0@@ -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; + + asmvolatile (".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@@ -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; - - asmvolatile (".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) {
PATCH v2 2/2 s390x: add cmm migration test
In reply to Nico BoehrWhen 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 | 78 +++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 +++ 3 files changed, 83 insertions(+) create mode 100644 s390x/migration-cmm.c
s390x/Makefile +1 -0
@@ -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 +78 -0
78 lines not on this page · raw message
s390x/unittests.cfg +4 -0
@@ -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
Re: [kvm-unit-tests PATCH v2 2/2] s390x: add cmm migration test
Quoted 31 lines · On Wed, 11 May 2022 10:56:52 +0200 Nico Boehr <[email protected]> wrote:
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 <[email protected]>--- s390x/Makefile | 1 + s390x/migration-cmm.c | 78 +++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 +++ 3 files changed, 83 insertions(+) create mode 100644 s390x/migration-cmm.cs390x/Makefile +1
-0@@ -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.elfs390x/migration-cmm.c new file +2
-0@@ -0,0 +1,78 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/*
s390x/migration-cmm.c line 12
Quoted 10 lines
s390x/migration-cmm.c new file +10
-0+* CMM migration tests (ESSA) +* +* Copyright IBM Corp. 2022 +* +* Authors: +* Nico Boehr <[email protected]> +*/ + +#include <libcflat.h> +#include <asm/asm-offsets.h>
do we actually need this include?
if not, remove it, then you can add:
Quoted 78 lines
s390x/migration-cmm.c new file +66
-0+#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 ("cmm-migration" ); +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 (); +}s390x/unittests.cfg +4
-0@@ -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
Re: [kvm-unit-tests PATCH v2 2/2] s390x: add cmm migration test
Quoted 1 line · Claudio Imbrenda
do we actually need this include?
It is not needed, removed.
Quoted 2 lines
if not, remove it, then you can add:
Reviewed-by Claudio Imbrenda <[email protected]>
Thanks.