Re: [kvm-unit-tests PATCH v1 2/2] s390x: add CMM test during migration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 22 Nov 2022 17:12:43 +0100
Nico Boehr <nrb@xxxxxxxxxxxxx> wrote:

> Add a test which modifies CMM page states while migration is in
> progress.
> 
> Signed-off-by: Nico Boehr <nrb@xxxxxxxxxxxxx>
> ---
>  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
> 
> diff --git a/s390x/Makefile b/s390x/Makefile
> index 401cb6371cee..64c7c04409ae 100644
> --- a/s390x/Makefile
> +++ b/s390x/Makefile
> @@ -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
>  
> diff --git a/s390x/migration-during-cmm.c b/s390x/migration-during-cmm.c
> new file mode 100644
> index 000000000000..3c96283d7b00
> --- /dev/null
> +++ b/s390x/migration-during-cmm.c
> @@ -0,0 +1,111 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Perform CMMA actions while migrating.
> + *
> + * Copyright IBM Corp. 2022
> + *
> + * Authors:
> + *  Nico Boehr <nrb@xxxxxxxxxxxxx>
> + */
> +
> +#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?

> +
> +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

> +static int thread_should_exit;
> +static int thread_exited;

(these are fine as is, since they are only used as flags)

> +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)

> +		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;
> +	}
> +
> +	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

> +
> +	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();
> +
> +	/*
> +	 * 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

> +		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();
> +}
> diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
> index 3caf81eda396..f6889bd4da01 100644
> --- a/s390x/unittests.cfg
> +++ b/s390x/unittests.cfg
> @@ -208,3 +208,8 @@ groups = migration
>  [exittime]
>  file = exittime.elf
>  smp = 2
> +
> +[migration-during-cmm]
> +file = migration-during-cmm.elf
> +groups = migration
> +smp = 2




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux