public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Nico Boehr <nrb@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com,
	pbonzini@redhat.com
Subject: [kvm-unit-tests PATCH v1 3/3] s390x: add storage key test during migration
Date: Thu,  1 Dec 2022 09:46:42 +0100	[thread overview]
Message-ID: <20221201084642.3747014-4-nrb@linux.ibm.com> (raw)
In-Reply-To: <20221201084642.3747014-1-nrb@linux.ibm.com>

Add a test which modifies storage keys while migration is in progress.

Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 s390x/Makefile                |   1 +
 s390x/migration-during-skey.c | 103 ++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg           |   5 ++
 3 files changed, 109 insertions(+)
 create mode 100644 s390x/migration-during-skey.c

diff --git a/s390x/Makefile b/s390x/Makefile
index d097b7071dfb..d9ba9b5fc392 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-skey.elf
 
 pv-tests += $(TEST_DIR)/pv-diags.elf
 
diff --git a/s390x/migration-during-skey.c b/s390x/migration-during-skey.c
new file mode 100644
index 000000000000..bd0e6feb02bc
--- /dev/null
+++ b/s390x/migration-during-skey.c
@@ -0,0 +1,103 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Perform storage key operations during migration
+ *
+ * Copyright IBM Corp. 2022
+ *
+ * Authors:
+ *  Nico Boehr <nrb@linux.ibm.com>
+ */
+
+#include <libcflat.h>
+#include <asm/facility.h>
+#include <asm/barrier.h>
+#include <hardware.h>
+#include <smp.h>
+#include <skey.h>
+
+#define NUM_PAGES 128
+static uint8_t pagebuf[NUM_PAGES * PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
+
+static unsigned int thread_iters;
+static bool thread_should_exit;
+static bool thread_exited;
+static struct skey_verify_result result;
+
+static void test_skeys_during_migration(void)
+{
+	while (!READ_ONCE(thread_should_exit)) {
+		skey_set_keys_with_seed(pagebuf, NUM_PAGES, thread_iters);
+
+		result = skey_verify_keys_with_seed(pagebuf, NUM_PAGES, thread_iters);
+
+		/*
+		 * Always increment even if the verify fails. This ensures primary CPU knows where
+		 * we left off and can do an additional verify round after migration finished.
+		 */
+		thread_iters++;
+
+		if (result.verify_failed)
+			break;
+	}
+
+	WRITE_ONCE(thread_exited, 1);
+}
+
+static void migrate_once(void)
+{
+	static bool migrated;
+
+	if (migrated)
+		return;
+
+	migrated = true;
+	puts("Please migrate me, then press return\n");
+	(void)getchar();
+}
+
+int main(void)
+{
+	report_prefix_push("migration-skey");
+	if (test_facility(169)) {
+		report_skip("storage key removal facility is active");
+		goto error;
+	}
+
+	if (smp_query_num_cpus() == 1) {
+		report_skip("need at least 2 cpus for this test");
+		goto error;
+	}
+
+	smp_cpu_setup(1, PSW_WITH_CUR_MASK(test_skeys_during_migration));
+
+	migrate_once();
+
+	WRITE_ONCE(thread_should_exit, 1);
+
+	while (!thread_exited)
+		mb();
+
+	report_info("thread completed %u iterations", thread_iters);
+
+	report_prefix_push("during migration");
+	skey_report_verify(&result);
+	report_prefix_pop();
+
+	/*
+	 * Verification of skeys 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 skeys which might not have been migrated
+	 * correctly.
+	 */
+	report_prefix_push("after migration");
+	assert(thread_iters > 0);
+	result = skey_verify_keys_with_seed(pagebuf, NUM_PAGES, thread_iters - 1);
+	skey_report_verify(&result);
+	report_prefix_pop();
+
+error:
+	migrate_once();
+	report_prefix_pop();
+	return report_summary();
+}
diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
index 3caf81eda396..855c352929a4 100644
--- a/s390x/unittests.cfg
+++ b/s390x/unittests.cfg
@@ -208,3 +208,8 @@ groups = migration
 [exittime]
 file = exittime.elf
 smp = 2
+
+[migration-during-skey]
+file = migration-during-skey.elf
+smp = 2
+groups = migration
-- 
2.36.1


      parent reply	other threads:[~2022-12-01  8:48 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-01  8:46 [kvm-unit-tests PATCH v1 0/3] s390x: test storage keys during migration Nico Boehr
2022-12-01  8:46 ` [kvm-unit-tests PATCH v1 1/3] s390x: add library for skey-related functions Nico Boehr
2022-12-01 13:16   ` Claudio Imbrenda
2022-12-01 15:55     ` Nico Boehr
2022-12-01 16:46       ` Claudio Imbrenda
2022-12-02  9:03   ` Janosch Frank
2022-12-02  9:09     ` Thomas Huth
2022-12-02 10:44       ` Nico Boehr
2022-12-02 11:32         ` Thomas Huth
2022-12-02 11:56           ` Janosch Frank
2022-12-02 12:48             ` Thomas Huth
2022-12-02 12:56               ` Claudio Imbrenda
2022-12-09  9:02                 ` Nico Boehr
2022-12-02 10:39     ` Nico Boehr
2022-12-02 11:20       ` Janosch Frank
2022-12-02 11:29         ` Claudio Imbrenda
2022-12-01  8:46 ` [kvm-unit-tests PATCH v1 2/3] lib: s390x: skey: add seed value for storage keys Nico Boehr
2022-12-01 13:27   ` Claudio Imbrenda
2022-12-01 15:16     ` Nico Boehr
2022-12-01  8:46 ` Nico Boehr [this message]

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=20221201084642.3747014-4-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=pbonzini@redhat.com \
    --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