From: Nico Boehr <nrb@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com
Subject: [kvm-unit-tests PATCH v1 1/2] s390x: add a library for CMM-related functions
Date: Tue, 22 Nov 2022 17:12:42 +0100 [thread overview]
Message-ID: <20221122161243.214814-2-nrb@linux.ibm.com> (raw)
In-Reply-To: <20221122161243.214814-1-nrb@linux.ibm.com>
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.
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
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
diff --git a/lib/s390x/cmm.c b/lib/s390x/cmm.c
new file mode 100644
index 000000000000..9609cea68950
--- /dev/null
+++ b/lib/s390x/cmm.c
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * CMM test library
+ *
+ * Copyright IBM Corp. 2022
+ *
+ * Authors:
+ * Nico Boehr <nrb@linux.ibm.com>
+ */
+#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);
+}
+
diff --git a/lib/s390x/cmm.h b/lib/s390x/cmm.h
new file mode 100644
index 000000000000..56e188c78704
--- /dev/null
+++ b/lib/s390x/cmm.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * CMM test library
+ *
+ * Copyright IBM Corp. 2022
+ *
+ * Authors:
+ * Nico Boehr <nrb@linux.ibm.com>
+ */
+#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 */
diff --git a/s390x/Makefile b/s390x/Makefile
index bf1504f9d58c..401cb6371cee 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -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
diff --git a/s390x/migration-cmm.c b/s390x/migration-cmm.c
index aa7910ca76bf..ffd656f4db75 100644
--- a/s390x/migration-cmm.c
+++ b/s390x/migration-cmm.c
@@ -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)
--
2.36.1
next prev parent reply other threads:[~2022-11-22 16:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-22 16:12 [kvm-unit-tests PATCH v1 0/2] s390x: test CMM during migration Nico Boehr
2022-11-22 16:12 ` Nico Boehr [this message]
2022-11-23 12:13 ` [kvm-unit-tests PATCH v1 1/2] s390x: add a library for CMM-related functions Claudio Imbrenda
2022-11-23 16:12 ` Nico Boehr
2022-11-23 16:34 ` Claudio Imbrenda
2022-11-22 16:12 ` [kvm-unit-tests PATCH v1 2/2] s390x: add CMM test during migration Nico Boehr
2022-11-23 12:25 ` Claudio Imbrenda
2022-11-24 13:34 ` 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=20221122161243.214814-2-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=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