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

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-migration.c | 78 +++++++++++++++++++++++++++++++++++++++++++
 s390x/cmm.c           | 25 ++------------
 s390x/unittests.cfg   |  4 +++
 5 files changed, 136 insertions(+), 22 deletions(-)
 create mode 100644 lib/s390x/asm/cmm.h
 create mode 100644 s390x/cmm-migration.c

-- 
2.31.1


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

* [kvm-unit-tests PATCH v1 1/2] lib: s390x: add header for CMM related defines
  2022-05-09 12:08 [kvm-unit-tests PATCH v1 0/2] s390x: add migration test for CMM Nico Boehr
@ 2022-05-09 12:08 ` Nico Boehr
  2022-05-09 12:08 ` [kvm-unit-tests PATCH v1 2/2] s390x: add cmm migration test Nico Boehr
  2022-05-09 14:00 ` [kvm-unit-tests PATCH v1 0/2] s390x: add migration test for CMM Claudio Imbrenda
  2 siblings, 0 replies; 11+ messages in thread
From: Nico Boehr @ 2022-05-09 12:08 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>
---
 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] 11+ messages in thread

* [kvm-unit-tests PATCH v1 2/2] s390x: add cmm migration test
  2022-05-09 12:08 [kvm-unit-tests PATCH v1 0/2] s390x: add migration test for CMM Nico Boehr
  2022-05-09 12:08 ` [kvm-unit-tests PATCH v1 1/2] lib: s390x: add header for CMM related defines Nico Boehr
@ 2022-05-09 12:08 ` Nico Boehr
  2022-05-09 13:58   ` Claudio Imbrenda
  2022-05-09 14:00 ` [kvm-unit-tests PATCH v1 0/2] s390x: add migration test for CMM Claudio Imbrenda
  2 siblings, 1 reply; 11+ messages in thread
From: Nico Boehr @ 2022-05-09 12:08 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>
---
 s390x/Makefile        |  1 +
 s390x/cmm-migration.c | 78 +++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg   |  4 +++
 3 files changed, 83 insertions(+)
 create mode 100644 s390x/cmm-migration.c

diff --git a/s390x/Makefile b/s390x/Makefile
index a8e04aa6fe4d..8ac0afdfd994 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)/cmm-migration.elf
 
 pv-tests += $(TEST_DIR)/pv-diags.elf
 
diff --git a/s390x/cmm-migration.c b/s390x/cmm-migration.c
new file mode 100644
index 000000000000..4a7b50e40fc6
--- /dev/null
+++ b/s390x/cmm-migration.c
@@ -0,0 +1,78 @@
+/* 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/asm-offsets.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 */
+	};
+
+	for (i = 0; i < NUM_PAGES; i++) {
+		switch(i % 4) {
+			case 0:
+				essa(ESSA_SET_STABLE, (unsigned long)pagebuf[i]);
+			break;
+			case 1:
+				essa(ESSA_SET_UNUSED, (unsigned long)pagebuf[i]);
+			break;
+			case 2:
+				essa(ESSA_SET_VOLATILE, (unsigned long)pagebuf[i]);
+			break;
+			case 3:
+				essa(ESSA_SET_POT_VOLATILE, (unsigned long)pagebuf[i]);
+			break;
+		}
+	}
+
+	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");
+		goto done;
+	}
+
+	test_migration();
+done:
+	report_prefix_pop();
+	return report_summary();
+}
diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
index b456b2881448..625026d90e52 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
+
+[cmm-migration]
+file = cmm-migration.elf
+groups = migration
-- 
2.31.1


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

* Re: [kvm-unit-tests PATCH v1 2/2] s390x: add cmm migration test
  2022-05-09 12:08 ` [kvm-unit-tests PATCH v1 2/2] s390x: add cmm migration test Nico Boehr
@ 2022-05-09 13:58   ` Claudio Imbrenda
  2022-05-10 13:25     ` Nico Boehr
  0 siblings, 1 reply; 11+ messages in thread
From: Claudio Imbrenda @ 2022-05-09 13:58 UTC (permalink / raw)
  To: Nico Boehr; +Cc: kvm, linux-s390, frankja, thuth

On Mon,  9 May 2022 14:08:05 +0200
Nico Boehr <nrb@linux.ibm.com> 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 <nrb@linux.ibm.com>
> ---
>  s390x/Makefile        |  1 +
>  s390x/cmm-migration.c | 78 +++++++++++++++++++++++++++++++++++++++++++
>  s390x/unittests.cfg   |  4 +++
>  3 files changed, 83 insertions(+)
>  create mode 100644 s390x/cmm-migration.c
> 
> diff --git a/s390x/Makefile b/s390x/Makefile
> index a8e04aa6fe4d..8ac0afdfd994 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)/cmm-migration.elf
>  
>  pv-tests += $(TEST_DIR)/pv-diags.elf
>  
> diff --git a/s390x/cmm-migration.c b/s390x/cmm-migration.c
> new file mode 100644
> index 000000000000..4a7b50e40fc6
> --- /dev/null
> +++ b/s390x/cmm-migration.c
> @@ -0,0 +1,78 @@
> +/* 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/asm-offsets.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 */
> +	};
> +
> +	for (i = 0; i < NUM_PAGES; i++) {
> +		switch(i % 4) {
> +			case 0:
> +				essa(ESSA_SET_STABLE, (unsigned long)pagebuf[i]);
> +			break;
> +			case 1:
> +				essa(ESSA_SET_UNUSED, (unsigned long)pagebuf[i]);
> +			break;
> +			case 2:
> +				essa(ESSA_SET_VOLATILE, (unsigned long)pagebuf[i]);
> +			break;
> +			case 3:
> +				essa(ESSA_SET_POT_VOLATILE, (unsigned long)pagebuf[i]);
> +			break;

const int essa_commands[4] = {ESSA_SET_STABLE, ESSA_SET_UNUSED, ...

for (i = 0; i < NUM_PAGES; i++)
	essa(essa_commands[i % 4], ...

I think it would look more compact and more readable

> +		}
> +	}
> +
> +	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");
> +		goto done;
> +	}
> +
> +	test_migration();
> +done:
> +	report_prefix_pop();
> +	return report_summary();
> +}
> diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
> index b456b2881448..625026d90e52 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
> +
> +[cmm-migration]
> +file = cmm-migration.elf
> +groups = migration


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

* Re: [kvm-unit-tests PATCH v1 0/2] s390x: add migration test for CMM
  2022-05-09 12:08 [kvm-unit-tests PATCH v1 0/2] s390x: add migration test for CMM Nico Boehr
  2022-05-09 12:08 ` [kvm-unit-tests PATCH v1 1/2] lib: s390x: add header for CMM related defines Nico Boehr
  2022-05-09 12:08 ` [kvm-unit-tests PATCH v1 2/2] s390x: add cmm migration test Nico Boehr
@ 2022-05-09 14:00 ` Claudio Imbrenda
  2022-05-10 10:58   ` Nico Boehr
  2 siblings, 1 reply; 11+ messages in thread
From: Claudio Imbrenda @ 2022-05-09 14:00 UTC (permalink / raw)
  To: Nico Boehr; +Cc: kvm, linux-s390, frankja, thuth

On Mon,  9 May 2022 14:08:03 +0200
Nico Boehr <nrb@linux.ibm.com> wrote:

> 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

I wonder if we are going to have more of these "split" tests.

is there a way to make sure migration prerequisites are always present?
or rewrite things so that we don't need them?

> 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-migration.c | 78 +++++++++++++++++++++++++++++++++++++++++++
>  s390x/cmm.c           | 25 ++------------
>  s390x/unittests.cfg   |  4 +++
>  5 files changed, 136 insertions(+), 22 deletions(-)
>  create mode 100644 lib/s390x/asm/cmm.h
>  create mode 100644 s390x/cmm-migration.c
> 


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

* Re: [kvm-unit-tests PATCH v1 0/2] s390x: add migration test for CMM
  2022-05-09 14:00 ` [kvm-unit-tests PATCH v1 0/2] s390x: add migration test for CMM Claudio Imbrenda
@ 2022-05-10 10:58   ` Nico Boehr
  2022-05-10 12:47     ` Janosch Frank
  0 siblings, 1 reply; 11+ messages in thread
From: Nico Boehr @ 2022-05-10 10:58 UTC (permalink / raw)
  To: Claudio Imbrenda; +Cc: kvm, linux-s390, frankja, thuth

On Mon, 2022-05-09 at 16:00 +0200, Claudio Imbrenda wrote:
> I wonder if we are going to have more of these "split" tests.
> 
> is there a way to make sure migration prerequisites are always
> present?

We could not run _any_ tests if netcat is not installed, which seems
like a bad idea. 

> or rewrite things so that we don't need them?

We need ncat to communicate with the QEMU QMP over unix socket. I am
not aware of a way to use unix sockets in Bash, but no expert either.

We could ship our own version of netcat and build it for the host,
which adds additional complexity and maintenance burden. 

I honestly can't think of a good way.

Or we just put all cmm tests in a single file and accept the fact that
if you don't have all the migration related requirements installed, you
don't get all the tests - even some which are not at all related to
migration. I did not like that so I went with the extra file.

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

* Re: [kvm-unit-tests PATCH v1 0/2] s390x: add migration test for CMM
  2022-05-10 10:58   ` Nico Boehr
@ 2022-05-10 12:47     ` Janosch Frank
  2022-05-11  8:59       ` Nico Boehr
  0 siblings, 1 reply; 11+ messages in thread
From: Janosch Frank @ 2022-05-10 12:47 UTC (permalink / raw)
  To: Nico Boehr, Claudio Imbrenda; +Cc: kvm, linux-s390, thuth

On 5/10/22 12:58, Nico Boehr wrote:
> On Mon, 2022-05-09 at 16:00 +0200, Claudio Imbrenda wrote:
>> I wonder if we are going to have more of these "split" tests.
>>
>> is there a way to make sure migration prerequisites are always
>> present?
> 
> We could not run _any_ tests if netcat is not installed, which seems
> like a bad idea.
> 
>> or rewrite things so that we don't need them?
> 
> We need ncat to communicate with the QEMU QMP over unix socket. I am
> not aware of a way to use unix sockets in Bash, but no expert either.
> 
> We could ship our own version of netcat and build it for the host,
> which adds additional complexity and maintenance burden.
> 
> I honestly can't think of a good way.
> 
> Or we just put all cmm tests in a single file and accept the fact that
> if you don't have all the migration related requirements installed, you
> don't get all the tests - even some which are not at all related to
> migration. I did not like that so I went with the extra file.

Having them separate is fine. I'd change the file name to 
migration-cmm.elf though. We might also want to change the name of the 
first migration test in the future to make the name more specific.

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

* Re: [kvm-unit-tests PATCH v1 2/2] s390x: add cmm migration test
  2022-05-09 13:58   ` Claudio Imbrenda
@ 2022-05-10 13:25     ` Nico Boehr
  2022-05-10 13:45       ` Claudio Imbrenda
  0 siblings, 1 reply; 11+ messages in thread
From: Nico Boehr @ 2022-05-10 13:25 UTC (permalink / raw)
  To: Claudio Imbrenda; +Cc: kvm, linux-s390, frankja, thuth

On Mon, 2022-05-09 at 15:58 +0200, Claudio Imbrenda wrote:
> > +       for (i = 0; i < NUM_PAGES; i++) {
> > +               switch(i % 4) {
> > +                       case 0:
> > +                               essa(ESSA_SET_STABLE, (unsigned
> > long)pagebuf[i]);
> > +                       break;
> > +                       case 1:
> > +                               essa(ESSA_SET_UNUSED, (unsigned
> > long)pagebuf[i]);
> > +                       break;
> > +                       case 2:
> > +                               essa(ESSA_SET_VOLATILE, (unsigned
> > long)pagebuf[i]);
> > +                       break;
> > +                       case 3:
> > +                               essa(ESSA_SET_POT_VOLATILE,
> > (unsigned long)pagebuf[i]);
> > +                       break;
> 
> const int essa_commands[4] = {ESSA_SET_STABLE, ESSA_SET_UNUSED, ...
> 
> for (i = 0; i < NUM_PAGES; i++)
>         essa(essa_commands[i % 4], ...
> 
> I think it would look more compact and more readable

I like your idea a lot, but the compiler doesn't :-(:

/home/nrb/kvm-unit-tests/lib/asm/cmm.h: In function ‘main’:
/home/nrb/kvm-unit-tests/lib/asm/cmm.h:32:9: error: ‘asm’ operand 2
probably does not match constraints [-Werror]
   32 |         asm volatile(".insn
rrf,0xb9ab0000,%[extr_state],%[addr],%[new_state],0" \
      |         ^~~
/home/nrb/kvm-unit-tests/lib/asm/cmm.h:32:9: error: impossible
constraint in ‘asm’

To satify the "i" constraint, new_state needs to be a compile time
constant, which it won't be any more with your suggestion
unfortunately. 

We can do crazy stuff like this in cmm.h:

#define __essa(state) \
	asm volatile(".insn
rrf,0xb9ab0000,%[extr_state],%[addr],%[new_state],0" \
			: [extr_state] "=d" (extr_state) \
			: [addr] "a" (paddr), [new_state] "i"
(state));
static unsigned long essa(uint8_t state, unsigned long paddr)
{
	uint64_t extr_state = 0;

	switch(state) {
		case ESSA_SET_STABLE:
			__essa(ESSA_SET_STABLE);
		break;
		case ESSA_SET_UNUSED:
			__essa(ESSA_SET_UNUSED);
		break;
		case ESSA_SET_VOLATILE:
			__essa(ESSA_SET_VOLATILE);
		break;
		case ESSA_SET_POT_VOLATILE:
			__essa(ESSA_SET_POT_VOLATILE);
		break;
	}

	return (unsigned long)extr_state;
}

But that essentially just shifts the readability problem to a different
file. What do you think?

Or we make essa a marco, which doesn't sound like a particularily
attractive alternative either.

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

* Re: [kvm-unit-tests PATCH v1 2/2] s390x: add cmm migration test
  2022-05-10 13:25     ` Nico Boehr
@ 2022-05-10 13:45       ` Claudio Imbrenda
  2022-05-10 14:13         ` Nico Boehr
  0 siblings, 1 reply; 11+ messages in thread
From: Claudio Imbrenda @ 2022-05-10 13:45 UTC (permalink / raw)
  To: Nico Boehr; +Cc: kvm, linux-s390, frankja, thuth

On Tue, 10 May 2022 15:25:09 +0200
Nico Boehr <nrb@linux.ibm.com> wrote:

> On Mon, 2022-05-09 at 15:58 +0200, Claudio Imbrenda wrote:
> > > +       for (i = 0; i < NUM_PAGES; i++) {
> > > +               switch(i % 4) {
> > > +                       case 0:
> > > +                               essa(ESSA_SET_STABLE, (unsigned
> > > long)pagebuf[i]);
> > > +                       break;
> > > +                       case 1:
> > > +                               essa(ESSA_SET_UNUSED, (unsigned
> > > long)pagebuf[i]);
> > > +                       break;
> > > +                       case 2:
> > > +                               essa(ESSA_SET_VOLATILE, (unsigned
> > > long)pagebuf[i]);
> > > +                       break;
> > > +                       case 3:
> > > +                               essa(ESSA_SET_POT_VOLATILE,
> > > (unsigned long)pagebuf[i]);
> > > +                       break;  
> > 
> > const int essa_commands[4] = {ESSA_SET_STABLE, ESSA_SET_UNUSED, ...
> > 
> > for (i = 0; i < NUM_PAGES; i++)
> >         essa(essa_commands[i % 4], ...
> > 
> > I think it would look more compact and more readable  
> 
> I like your idea a lot, but the compiler doesn't :-(:

ouch, I had completely forgotten about that.

> 
> /home/nrb/kvm-unit-tests/lib/asm/cmm.h: In function ‘main’:
> /home/nrb/kvm-unit-tests/lib/asm/cmm.h:32:9: error: ‘asm’ operand 2
> probably does not match constraints [-Werror]
>    32 |         asm volatile(".insn
> rrf,0xb9ab0000,%[extr_state],%[addr],%[new_state],0" \
>       |         ^~~
> /home/nrb/kvm-unit-tests/lib/asm/cmm.h:32:9: error: impossible
> constraint in ‘asm’
> 
> To satify the "i" constraint, new_state needs to be a compile time
> constant, which it won't be any more with your suggestion
> unfortunately. 
> 
> We can do crazy stuff like this in cmm.h:
> 
> #define __essa(state) \
> 	asm volatile(".insn
> rrf,0xb9ab0000,%[extr_state],%[addr],%[new_state],0" \
> 			: [extr_state] "=d" (extr_state) \
> 			: [addr] "a" (paddr), [new_state] "i"
> (state));
> static unsigned long essa(uint8_t state, unsigned long paddr)
> {
> 	uint64_t extr_state = 0;
> 
> 	switch(state) {
> 		case ESSA_SET_STABLE:
> 			__essa(ESSA_SET_STABLE);
> 		break;
> 		case ESSA_SET_UNUSED:
> 			__essa(ESSA_SET_UNUSED);
> 		break;
> 		case ESSA_SET_VOLATILE:
> 			__essa(ESSA_SET_VOLATILE);
> 		break;
> 		case ESSA_SET_POT_VOLATILE:
> 			__essa(ESSA_SET_POT_VOLATILE);
> 		break;
> 	}
> 
> 	return (unsigned long)extr_state;
> }
> 
> But that essentially just shifts the readability problem to a different
> file. What do you think?
> 
> Or we make essa a marco, which doesn't sound like a particularily
> attractive alternative either.

ok, next less ugly thing: unroll the loop

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]);
	... etc
}

maybe assert(NUM_PAGES % 4 == 0) before that, just for good measure



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

* Re: [kvm-unit-tests PATCH v1 2/2] s390x: add cmm migration test
  2022-05-10 13:45       ` Claudio Imbrenda
@ 2022-05-10 14:13         ` Nico Boehr
  0 siblings, 0 replies; 11+ messages in thread
From: Nico Boehr @ 2022-05-10 14:13 UTC (permalink / raw)
  To: Claudio Imbrenda; +Cc: kvm, linux-s390, frankja, thuth

On Tue, 2022-05-10 at 15:45 +0200, Claudio Imbrenda wrote:
> ok, next less ugly thing: unroll the loop
> 
> 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]);
>         ... etc
> }
> 
> maybe assert(NUM_PAGES % 4 == 0) before that, just for good measure

That's nicer, thanks, fixed.

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

* Re: [kvm-unit-tests PATCH v1 0/2] s390x: add migration test for CMM
  2022-05-10 12:47     ` Janosch Frank
@ 2022-05-11  8:59       ` Nico Boehr
  0 siblings, 0 replies; 11+ messages in thread
From: Nico Boehr @ 2022-05-11  8:59 UTC (permalink / raw)
  To: Janosch Frank, Claudio Imbrenda; +Cc: kvm, linux-s390, thuth

On Tue, 2022-05-10 at 14:47 +0200, Janosch Frank wrote:
> Having them separate is fine. I'd change the file name to 
> migration-cmm.elf though. We might also want to change the name of
> the 
> first migration test in the future to make the name more specific.

Yes, good thought. I have it on my TODO.

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

end of thread, other threads:[~2022-05-11  8:59 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09 12:08 [kvm-unit-tests PATCH v1 0/2] s390x: add migration test for CMM Nico Boehr
2022-05-09 12:08 ` [kvm-unit-tests PATCH v1 1/2] lib: s390x: add header for CMM related defines Nico Boehr
2022-05-09 12:08 ` [kvm-unit-tests PATCH v1 2/2] s390x: add cmm migration test Nico Boehr
2022-05-09 13:58   ` Claudio Imbrenda
2022-05-10 13:25     ` Nico Boehr
2022-05-10 13:45       ` Claudio Imbrenda
2022-05-10 14:13         ` Nico Boehr
2022-05-09 14:00 ` [kvm-unit-tests PATCH v1 0/2] s390x: add migration test for CMM Claudio Imbrenda
2022-05-10 10:58   ` Nico Boehr
2022-05-10 12:47     ` Janosch Frank
2022-05-11  8:59       ` Nico Boehr

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.