s390x: test CMM during migration
cover s390x: test CMM during migration
Add a test which changes CMM page states while VM is being migrated.
Nico Boehr (2):
s390x: add a library for CMM-related functions
s390x: add CMM test during migration
lib/s390x/cmm.c | 83 ++++++++++++++++++++++++++ lib/s390x/cmm.h | 29 +++++++++ s390x/Makefile | 2 + s390x/migration-cmm.c | 36 ++++-------- s390x/migration-during-cmm.c | 111 +++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 5 ++ 6 files changed, 240 insertions(+), 26 deletions(-) create mode 100644 lib/s390x/cmm.c create mode 100644 lib/s390x/cmm.h create mode 100644 s390x/migration-during-cmm.c
Signature · 1 line
2.36.1
PATCH 1/2 s390x: add a library for CMM-related functions
Upcoming changes will add a test which is very similar to the existing CMM migration test. To reduce code duplication, move the common function to a library which can be re-used by both tests.
--- lib/s390x/cmm.c | 83 +++++++++++++++++++++++++++++++++++++++++++ lib/s390x/cmm.h | 29 +++++++++++++++ s390x/Makefile | 1 + s390x/migration-cmm.c | 36 ++++++------------- 4 files changed, 123 insertions(+), 26 deletions(-) create mode 100644 lib/s390x/cmm.c create mode 100644 lib/s390x/cmm.h
lib/s390x/cmm.c new file +83 -0
@@ -0,0 +1,83 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* CMM test library +* +* Copyright IBM Corp. 2022 +* +* Authors: +* Nico Boehr <[email protected]> +*/ +#include <libcflat.h> +#include <bitops.h> +#include "cmm.h" + +/* +* Maps ESSA actions to states the page is allowed to be in after the +* respective action was executed. +*/ +const 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 */ +}; + +static inline unsigned long get_page_addr (uint8_t *pagebuf,int page_idx) +{ +return (unsigned long )(pagebuf +PAGE_SIZE * page_idx); +} + +/* +* Set CMM page states on pagebuf. +* pagebuf must point to page_count consecutive pages. +* page_count must be a multiple of 4. +*/ +void cmm_set_page_states (uint8_t *pagebuf,int page_count) +{ +int i; + +assert (page_count %4 ==0 ); +for (i =0 ; i < page_count; i +=4 ) { +essa (ESSA_SET_STABLE ,get_page_addr (pagebuf, i)); +essa (ESSA_SET_UNUSED ,get_page_addr (pagebuf, i +1 )); +essa (ESSA_SET_VOLATILE ,get_page_addr (pagebuf, i +2 )); +essa (ESSA_SET_POT_VOLATILE ,get_page_addr (pagebuf, i +3 )); + } +} + +/* +* Verify CMM page states on pagebuf. +* Page states must have been set by cmm_set_page_states on pagebuf before. +* page_count must be a multiple of 4. +* +* If page states match the expected result, +* will return true and result will be untouched. When a mismatch occurs, will +* return false and result will be filled with details on the first mismatch. +*/ +bool cmm_verify_page_states (uint8_t *pagebuf,int page_count,struct cmm_verify_result *result) +{ +int i, state_mask, actual_state; + +assert (page_count %4 ==0 ); + +for (i =0 ; i < page_count; i++) { + actual_state =essa (ESSA_GET_STATE ,get_page_addr (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)]; +if (!(BIT (actual_state) & state_mask)) { + result->page_mismatch = i; + result->expected_mask = state_mask; + result->actual_mask =BIT (actual_state); +return false; + } + } + +return true; +} + +void cmm_report_verify_fail (struct cmm_verify_result const *result) +{ +report_fail ("page state mismatch: first page = %d, expected_mask = 0x%x, actual_mask = 0x%x" , result->page_mismatch, result->expected_mask, result->actual_mask); +} +
lib/s390x/cmm.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* CMM test library +* +* Copyright IBM Corp. 2022 +* +* Authors: +* Nico Boehr <[email protected]> +*/ +#ifndef S390X_CMM_H +#define S390X_CMM_H + +#include <libcflat.h> +#include <asm/page.h> +#include <asm/cmm.h> + +struct cmm_verify_result { +int page_mismatch; +int expected_mask; +int actual_mask; +}; + +void cmm_set_page_states (uint8_t *pagebuf,int page_count); + +bool cmm_verify_page_states (uint8_t *pagebuf,int page_count,struct cmm_verify_result *result); + +void cmm_report_verify_fail (struct cmm_verify_result const *result); + +#endif /* S390X_CMM_H */
s390x/Makefile +1 -0
@@ -99,6 +99,7 @@ cflatobjs += lib/s390x/malloc_io.o cflatobjs += lib/s390x/uv.o cflatobjs += lib/s390x/sie.o cflatobjs += lib/s390x/fault.o +cflatobjs += lib/s390x/cmm.o OBJDIRS += lib/s390x
s390x/migration-cmm.c +10 -26
@@ -14,41 +14,25 @@#include <asm/cmm.h> #include <bitops.h> +#include "cmm.h" +#define NUM_PAGES 128 -static uint8_t pagebuf[NUM_PAGES][PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); + +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 */ - }; +struct cmm_verify_result result = {}; -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 ]); - } +cmm_set_page_states (pagebuf,NUM_PAGES );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)); - } +if (!cmm_verify_page_states (pagebuf,NUM_PAGES , &result)) +cmm_report_verify_fail (&result); +else +report_pass ("page states match" ); }int main (void )
Signature · 1 line
2.36.1
Re: [kvm-unit-tests PATCH v1 1/2] s390x: add a library for CMM-related functions
Quoted 3 lines · On Tue, 22 Nov 2022 17:12:42 +0100 Nico Boehr <[email protected]> wrote:
Upcoming changes will add a test which is very similar to the existing CMM migration test. To reduce code duplication, move the common function to a library which can be re-used by both tests.
I have several (mostly cosmetic) nits
Quoted 32 lines
Signed-off-by Nico Boehr <[email protected]>--- lib/s390x/cmm.c | 83 +++++++++++++++++++++++++++++++++++++++++++ lib/s390x/cmm.h | 29 +++++++++++++++ s390x/Makefile | 1 + s390x/migration-cmm.c | 36 ++++++------------- 4 files changed, 123 insertions(+), 26 deletions(-) create mode 100644 lib/s390x/cmm.c create mode 100644 lib/s390x/cmm.hlib/s390x/cmm.c new file +15
-0@@ -0,0 +1,83 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* CMM test library +* +* Copyright IBM Corp. 2022 +* +* Authors: +* Nico Boehr <[email protected]> +*/ +#include <libcflat.h> +#include <bitops.h> +#include "cmm.h" + +/* +* Maps ESSA actions to states the page is allowed to be in after the
lib/s390x/cmm.c line 25
Quoted 10 lines
lib/s390x/cmm.c new file +10
-0+* respective action was executed. +*/ +const 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 */ +}; + +static inline unsigned long get_page_addr (uint8_t *pagebuf,int page_idx)
I don't like the name of this function, but maybe you can just get rid of it (see below)
lib/s390x/cmm.c line 36
Quoted 11 lines
lib/s390x/cmm.c new file +11
-0+{ +return (unsigned long )(pagebuf +PAGE_SIZE * page_idx); +} + +/* +* Set CMM page states on pagebuf. +* pagebuf must point to page_count consecutive pages. +* page_count must be a multiple of 4. +*/ +void cmm_set_page_states (uint8_t *pagebuf,int page_count) +{
unsigned long addr = (unsigned long)pagebuf;
lib/s390x/cmm.c line 41
Quoted 5 lines
lib/s390x/cmm.c new file +5
-0+int i; + +assert (page_count %4 ==0 ); +for (i =0 ; i < page_count; i +=4 ) { +essa (ESSA_SET_STABLE ,get_page_addr (pagebuf, i));
addr + i * PAGE_SIZE
lib/s390x/cmm.c line 42
Quoted 1 line
lib/s390x/cmm.c new file +1
-0+essa (ESSA_SET_UNUSED ,get_page_addr (pagebuf, i +1 ));
addr + (i + 1) * PAGE_SIZE
lib/s390x/cmm.c line 43
Quoted 1 line
lib/s390x/cmm.c new file +1
-0+essa (ESSA_SET_VOLATILE ,get_page_addr (pagebuf, i +2 ));
etc
Quoted 6 lines
lib/s390x/cmm.c new file +6
-0+essa (ESSA_SET_POT_VOLATILE ,get_page_addr (pagebuf, i +3 )); + } +} + +/* +* Verify CMM page states on pagebuf.
lib/s390x/cmm.c line 59
Quoted 10 lines
lib/s390x/cmm.c new file +10
-0+* Page states must have been set by cmm_set_page_states on pagebuf before. +* page_count must be a multiple of 4. +* +* If page states match the expected result, +* will return true and result will be untouched. When a mismatch occurs, will +* return false and result will be filled with details on the first mismatch. +*/ +bool cmm_verify_page_states (uint8_t *pagebuf,int page_count,struct cmm_verify_result *result) +{ +int i, state_mask, actual_state;
I think "expected_mask" would be a better name, and maybe call the other one "actual_mask"
lib/s390x/cmm.c line 64
Quoted 5 lines
lib/s390x/cmm.c new file +5
-0+ +assert (page_count %4 ==0 ); + +for (i =0 ; i < page_count; i++) { + actual_state =essa (ESSA_GET_STATE ,get_page_addr (pagebuf, i));
addr + i * PAGE_SIZE (if we get rid of get_page_addr)
lib/s390x/cmm.c line 66
Quoted 2 lines
lib/s390x/cmm.c new file +2
-0+/* extract the usage state in bits 60 and 61 */ + actual_state = (actual_state >>2 ) &0x3 ;
actual_mask = BIT((actual_mask >> 2) & 3);
Quoted 5 lines
lib/s390x/cmm.c new file +5
-0+ state_mask = allowed_essa_state_masks[i %ARRAY_SIZE (allowed_essa_state_masks)]; +if (!(BIT (actual_state) & state_mask)) { + result->page_mismatch = i; + result->expected_mask = state_mask; + result->actual_mask =BIT (actual_state);
lib/s390x/cmm.c line 81
Quoted 10 lines
lib/s390x/cmm.c new file +10
-0+return false; + } + } + +return true; +} + +void cmm_report_verify_fail (struct cmm_verify_result const *result) +{ +report_fail ("page state mismatch: first page = %d, expected_mask = 0x%x, actual_mask = 0x%x" , result->page_mismatch, result->expected_mask, result->actual_mask);
it would be a good idea to also print the actual address where the mismatch was found (with %p and (pagebuf + result->page_mismatch))
Quoted 19 lines
lib/s390x/cmm.c new file +2
-0+} +lib/s390x/cmm.h new file +11
-0@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* CMM test library +* +* Copyright IBM Corp. 2022 +* +* Authors: +* Nico Boehr <[email protected]> +*/ +#ifndef S390X_CMM_H +#define S390X_CMM_H
lib/s390x/cmm.h line 21
Quoted 10 lines
lib/s390x/cmm.h new file +10
-0+ +#include <libcflat.h> +#include <asm/page.h> +#include <asm/cmm.h> + +struct cmm_verify_result { +int page_mismatch; +int expected_mask; +int actual_mask; +};
I'm not too fond of this, I wonder if it's possible to just return the struct (maybe make the masks chars, since they will be small)
but I am not sure if the code will actually look better in the end
Quoted 76 lines
lib/s390x/cmm.h new file +8
-0+ +void cmm_set_page_states (uint8_t *pagebuf,int page_count); + +bool cmm_verify_page_states (uint8_t *pagebuf,int page_count,struct cmm_verify_result *result); + +void cmm_report_verify_fail (struct cmm_verify_result const *result); + +#endif /* S390X_CMM_H */ s390x/Makefile +1
-0@@ -99,6 +99,7 @@ cflatobjs += lib/s390x/malloc_io.o cflatobjs += lib/s390x/uv.o cflatobjs += lib/s390x/sie.o cflatobjs += lib/s390x/fault.o +cflatobjs += lib/s390x/cmm.o OBJDIRS += lib/s390xs390x/migration-cmm.c +10
-26@@ -14,41 +14,25 @@#include <asm/cmm.h> #include <bitops.h> +#include "cmm.h" +#define NUM_PAGES 128 -static uint8_t pagebuf[NUM_PAGES][PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); + +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 */ - }; +struct cmm_verify_result result = {}; -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 ]); - } +cmm_set_page_states (pagebuf,NUM_PAGES );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)); - } +if (!cmm_verify_page_states (pagebuf,NUM_PAGES , &result)) +cmm_report_verify_fail (&result); +else +report_pass ("page states match" ); }int main (void )
Re: [kvm-unit-tests PATCH v1 1/2] s390x: add a library for CMM-related functions
Quoting Claudio Imbrenda (2022-11-23 13:13:38)
Quoted 3 lines
Quoted 3 lines
lib/s390x/cmm.c new file +0
-0
[...]
Quoted 4 lines
Quoted 1 line
+static inline unsigned long
get_page_addr(uint8_t *pagebuf, int page_idx)I don't like the name of this function, but maybe you can just get rid of it (see below)
Didn't like repeating the cast with the address calculation every time, but your solution with the cast first is good too. Done.
[...]
Quoted 7 lines
Quoted 7 lines
+/*
+ * Verify CMM page states on pagebuf.
+ * Page states must have been set bycmm_set_page_stateson pagebuf before.
+ *page_countmust be a multiple of 4.
+ *
+ * If page states match the expected result,
+ * will return true and result will be untouched. When a mismatch occurs, will
Quoted 8 lines
lib/s390x/cmm.c line 59
Quoted 5 lines
+ * return false and result will be filled with details on the first mismatch.
+ */lib/s390x/cmm.c new file +3
-0+bool cmm_verify_page_states (uint8_t *pagebuf,int page_count,struct cmm_verify_result *result) +{ +int i, state_mask, actual_state;I think "
expected_mask" would be a better name, and maybe call the other one "actual_mask"
Yes, makes perfect sense. Done.
Quoted 8 lines
lib/s390x/cmm.c line 64
Quoted 5 lines
lib/s390x/cmm.c new file +5
-0+ +assert (page_count %4 ==0 ); + +for (i =0 ; i < page_count; i++) { + actual_state =essa (ESSA_GET_STATE ,get_page_addr (pagebuf, i));addr + i *
PAGE_SIZE(if we get rid ofget_page_addr)
Quoted 4 lines
lib/s390x/cmm.c line 66
Quoted 2 lines
lib/s390x/cmm.c new file +2
-0+/* extract the usage state in bits 60 and 61 */ + actual_state = (actual_state >>2 ) &0x3 ;
actual_mask=BIT((actual_mask >> 2) & 3);
Yes makes sense, I will also adjust the comment a bit.
[...]
Quoted 6 lines
lib/s390x/cmm.c line 81
Quoted 3 lines
lib/s390x/cmm.c new file +3
-0+void cmm_report_verify_fail (struct cmm_verify_result const *result) +{ +report_fail ("page state mismatch: first page = %d, expected_mask = 0x%x, actual_mask = 0x%x" , result->page_mismatch, result->expected_mask, result->actual_mask);it would be a good idea to also print the actual address where the mismatch was found (with %p and (pagebuf +
result->page_mismatch))
pagebuf is not available here, I want to avoid adding another argument, so I'll add a new field for the address in cmm_verify_result.
Quoted 3 lines
Quoted 3 lines
lib/s390x/cmm.h new file +0
-0
[...]
Quoted 8 lines
lib/s390x/cmm.h line 21
Quoted 5 lines
lib/s390x/cmm.h new file +5
-0+struct cmm_verify_result { +int page_mismatch; +int expected_mask; +int actual_mask; +};I'm not too fond of this, I wonder if it's possible to just return the struct (maybe make the masks chars, since they will be small)
No real reason to optimize for size, but also no reason not to, so I just changed it.
Quoted 1 line
but I am not sure if the code will actually look better in the end
I am not a fan of returning structs, but none of my arguments against it apply here, so I changed it. Will add a field verify_failed to cmm_verify_result.
This has the nice side effect that I don't have to do
if(cmm_verify_page_states())
report_pass()
else
cmm_report_verify_fail()
in every caller, but can just move this whole logic to a function.
Re: [kvm-unit-tests PATCH v1 1/2] s390x: add a library for CMM-related functions
Quoted 69 lines · On Wed, 23 Nov 2022 17:12:52 +0100 Nico Boehr <[email protected]> wrote:
Quoting Claudio Imbrenda (2022-11-23 13:13:38)
Quoted 3 lines
Quoted 3 lines
lib/s390x/cmm.c new file +0
-0[...]
Quoted 4 lines
Quoted 1 line
+static inline unsigned long
get_page_addr(uint8_t *pagebuf, int page_idx)I don't like the name of this function, but maybe you can just get rid of it (see below)
Didn't like repeating the cast with the address calculation every time, but your solution with the cast first is good too. Done.
[...]
Quoted 7 lines
Quoted 7 lines
+/*
+ * Verify CMM page states on pagebuf.
+ * Page states must have been set bycmm_set_page_stateson pagebuf before.
+ *page_countmust be a multiple of 4.
+ *
+ * If page states match the expected result,
+ * will return true and result will be untouched. When a mismatch occurs, willQuoted 8 lines
lib/s390x/cmm.c line 59
Quoted 5 lines
+ * return false and result will be filled with details on the first mismatch.
+ */lib/s390x/cmm.c new file +3
-0+bool cmm_verify_page_states (uint8_t *pagebuf,int page_count,struct cmm_verify_result *result) +{ +int i, state_mask, actual_state;I think "
expected_mask" would be a better name, and maybe call the other one "actual_mask"Yes, makes perfect sense. Done.
Quoted 8 lines
lib/s390x/cmm.c line 64
Quoted 5 lines
lib/s390x/cmm.c new file +5
-0+ +assert (page_count %4 ==0 ); + +for (i =0 ; i < page_count; i++) { + actual_state =essa (ESSA_GET_STATE ,get_page_addr (pagebuf, i));addr + i *
PAGE_SIZE(if we get rid ofget_page_addr)Quoted 4 lines
lib/s390x/cmm.c line 66
Quoted 2 lines
lib/s390x/cmm.c new file +2
-0+/* extract the usage state in bits 60 and 61 */ + actual_state = (actual_state >>2 ) &0x3 ;
actual_mask=BIT((actual_mask >> 2) & 3);Yes makes sense, I will also adjust the comment a bit.
[...]
Quoted 6 lines
lib/s390x/cmm.c line 81
Quoted 3 lines
lib/s390x/cmm.c new file +3
-0+void cmm_report_verify_fail (struct cmm_verify_result const *result) +{ +report_fail ("page state mismatch: first page = %d, expected_mask = 0x%x, actual_mask = 0x%x" , result->page_mismatch, result->expected_mask, result->actual_mask);it would be a good idea to also print the actual address where the mismatch was found (with %p and (pagebuf +
result->page_mismatch))pagebuf is not available here, I want to avoid adding another argument, so I'll add a new field for the address in
cmm_verify_result.Quoted 3 lines
Quoted 3 lines
lib/s390x/cmm.h new file +0
-0[...]
Quoted 8 lines
lib/s390x/cmm.h line 21
Quoted 5 lines
lib/s390x/cmm.h new file +5
-0+struct cmm_verify_result { +int page_mismatch; +int expected_mask; +int actual_mask; +};I'm not too fond of this, I wonder if it's possible to just return the struct (maybe make the masks chars, since they will be small)
Quoted 6 lines
No real reason to optimize for size, but also no reason not to, so I just changed it.
Quoted 1 line
but I am not sure if the code will actually look better in the end
I am not a fan of returning structs, but none of my arguments against it apply here, so I changed it. Will add a field
verify_failedtocmm_verify_result.
I'm not sure I follow, but I guess I'll see it in v2
just make sure the code is not uglier, otherwise it's pointless :)
Quoted 7 lines
This has the nice side effect that I don't have to do
if(cmm_verify_page_states())
report_pass()
else
cmm_report_verify_fail()
in every caller, but can just move this whole logic to a function.
PATCH 2/2 s390x: add CMM test during migration
In reply to Nico BoehrAdd a test which modifies CMM page states while migration is in progress.
--- s390x/Makefile | 1 + s390x/migration-during-cmm.c | 111 +++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 5 ++ 3 files changed, 117 insertions(+) create mode 100644 s390x/migration-during-cmm.c
s390x/Makefile +1 -0
@@ -39,6 +39,7 @@ tests += $(TEST_DIR)/panic-loop-extint.elf tests += $(TEST_DIR)/panic-loop-pgm.elf tests += $(TEST_DIR)/migration-sck.elf tests += $(TEST_DIR)/exittime.elf +tests += $(TEST_DIR)/migration-during-cmm.elf pv-tests += $(TEST_DIR)/pv-diags.elf
s390x/migration-during-cmm.c new file +111 -0
111 lines not on this page · raw message
s390x/unittests.cfg +5 -0
@@ -208,3 +208,8 @@ groups = migration [exittime] file = exittime.elf smp = 2 + +[migration-during-cmm] +file = migration-during-cmm.elf +groups = migration +smp = 2
Signature · 1 line
2.36.1
Re: [kvm-unit-tests PATCH v1 2/2] s390x: add CMM test during migration
Quoted 36 lines · On Tue, 22 Nov 2022 17:12:43 +0100 Nico Boehr <[email protected]> wrote:
Add a test which modifies CMM page states while migration is in progress.
Signed-off-by Nico Boehr <[email protected]>--- s390x/Makefile | 1 + s390x/migration-during-cmm.c | 111 +++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 5 ++ 3 files changed, 117 insertions(+) create mode 100644 s390x/migration-during-cmm.cs390x/Makefile +1
-0@@ -39,6 +39,7 @@ tests += $(TEST_DIR)/panic-loop-extint.elf tests += $(TEST_DIR)/panic-loop-pgm.elf tests += $(TEST_DIR)/migration-sck.elf tests += $(TEST_DIR)/exittime.elf +tests += $(TEST_DIR)/migration-during-cmm.elf pv-tests += $(TEST_DIR)/pv-diags.elfs390x/migration-during-cmm.c new file +7
-0@@ -0,0 +1,111 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Perform CMMA actions while migrating. +* +* Copyright IBM Corp. 2022 +* +* Authors:
s390x/migration-during-cmm.c line 17
Quoted 10 lines
s390x/migration-during-cmm.c new file +10
-0+* Nico Boehr <[email protected]> +*/ + +#include <libcflat.h> +#include <smp.h> +#include <asm-generic/barrier.h> + +#include "cmm.h" + +#define NUM_PAGES 128
is 128 enough to allow multiple iterations of the thread?
s390x/migration-during-cmm.c line 21
Quoted 4 lines
s390x/migration-during-cmm.c new file +4
-0+ +static uint8_t pagebuf[NUM_PAGES * PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); + +static int thread_iters;
please make all ints unsigned unless you really need them signed
s390x/migration-during-cmm.c line 23
Quoted 2 lines
s390x/migration-during-cmm.c new file +2
-0+static int thread_should_exit; +static int thread_exited;
(these are fine as is, since they are only used as flags)
s390x/migration-during-cmm.c line 34
Quoted 11 lines
s390x/migration-during-cmm.c new file +11
-0+static bool verification_failure_occured; +struct cmm_verify_result result; + +static void test_cmm_during_migration (void ) +{ +/* +* The second CPU must not print on the console, otherwise it will race with +* the primary CPU on the SCLP buffer. +*/ +while (!thread_should_exit) { +cmm_set_page_states (pagebuf,NUM_PAGES );
I would do (pagebuf + (thread_iters % 4) * PAGE_SIZE
this way you will actually change the values for each page at each iteration (will need a bigger buffer)
Quoted 25 lines
s390x/migration-during-cmm.c new file +25
-0+if (!cmm_verify_page_states (pagebuf,NUM_PAGES , &result)) { + verification_failure_occured = true; + goto out; + } + thread_iters++; + } + +out: + thread_exited =1 ; +} + +int main (void ) +{ +bool has_essa =check_essa_available (); +struct psw psw; + +report_prefix_push ("migration-during-cmm" ); +if (!has_essa) { +report_skip ("ESSA is not available" ); + goto error; + } + +if (smp_query_num_cpus () ==1 ) { +report_skip ("need at least 2 cpus for this test" ); + goto error;
s390x/migration-during-cmm.c line 69
Quoted 10 lines
s390x/migration-during-cmm.c new file +10
-0+ } + + psw.mask =extract_psw_mask (); + psw.addr = (unsigned long )test_cmm_during_migration; +smp_cpu_setup (1 , psw); + +puts ("Please migrate me, then press return\n" ); + (void )getchar (); + + thread_should_exit =1 ;
I would use WRITE_ONCE, otherwise you probably need a mb() here
Quoted 12 lines
s390x/migration-during-cmm.c new file +12
-0+ +while (!thread_exited) +mb (); + +report_info ("thread completed %d iterations" , thread_iters); + +report_prefix_push ("during migration" ); +if (verification_failure_occured) +cmm_report_verify_fail (&result); +else +report_pass ("page states matched" ); +report_prefix_pop ();
s390x/migration-during-cmm.c line 91
Quoted 10 lines
s390x/migration-during-cmm.c new file +10
-0+ +/* +* Verification of page states occurs on the thread. We don't know if we +* were still migrating during the verification. +* To be sure, make another verification round after the migration +* finished to catch page states which might not have been migrated +* correctly. +*/ +report_prefix_push ("after migration" ); +if (!cmm_verify_page_states (pagebuf,NUM_PAGES , &result))
pagebuf + ((thread_iters - 1) % 4) * PAGE_SIZE
Quoted 33 lines
s390x/migration-during-cmm.c new file +20
-0+cmm_report_verify_fail (&result); + else + report_pass("page states matched"); +report_prefix_pop (); + + goto done; + +error: +/* +* 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 (); + +done: +report_prefix_pop (); +return report_summary (); +}s390x/unittests.cfg +5
-0@@ -208,3 +208,8 @@ groups = migration [exittime] file = exittime.elf smp = 2 + +[migration-during-cmm] +file = migration-during-cmm.elf +groups = migration +smp = 2
Re: [kvm-unit-tests PATCH v1 2/2] s390x: add CMM test during migration
Quoting Claudio Imbrenda (2022-11-23 13:25:55)
[...]
Quoted 17 lines
Quoted 17 lines
s390x/migration-during-cmm.c new file +11
-0@@ -0,0 +1,111 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Perform CMMA actions while migrating. +* +* Copyright IBM Corp. 2022 +* +* Authors: +* Nico Boehr <[email protected]> +*/ + +#include <libcflat.h>
Quoted 8 lines
s390x/migration-during-cmm.c line 17
Quoted 6 lines
s390x/migration-during-cmm.c new file +6
-0+#include <smp.h> +#include <asm-generic/barrier.h> + +#include "cmm.h" + +#define NUM_PAGES 128is 128 enough to allow multiple iterations of the thread?
Enough for about 16.000 iterations on my box :)