public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Nico Boehr <nrb@linux.ibm.com>
To: kvm@vger.kernel.org, linux-s390@vger.kernel.org
Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com
Subject: [kvm-unit-tests PATCH v1 2/2] s390x: add cmm migration test
Date: Mon,  9 May 2022 14:08:05 +0200	[thread overview]
Message-ID: <20220509120805.437660-3-nrb@linux.ibm.com> (raw)
In-Reply-To: <20220509120805.437660-1-nrb@linux.ibm.com>

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


  parent reply	other threads:[~2022-05-09 12:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2022-05-09 13:58   ` [kvm-unit-tests PATCH v1 2/2] s390x: add cmm migration test 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220509120805.437660-3-nrb@linux.ibm.com \
    --to=nrb@linux.ibm.com \
    --cc=frankja@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox