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 v2 1/2] lib: s390x: add header for CMM related defines
Date: Wed, 11 May 2022 10:56:51 +0200 [thread overview]
Message-ID: <20220511085652.823371-2-nrb@linux.ibm.com> (raw)
In-Reply-To: <20220511085652.823371-1-nrb@linux.ibm.com>
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
next prev parent reply other threads:[~2022-05-11 8:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-11 8:56 [kvm-unit-tests PATCH v2 0/2] s390x: add migration test for CMM Nico Boehr
2022-05-11 8:56 ` Nico Boehr [this message]
2022-05-11 9:12 ` [kvm-unit-tests PATCH v2 1/2] lib: s390x: add header for CMM related defines Claudio Imbrenda
2022-05-11 8:56 ` [kvm-unit-tests PATCH v2 2/2] s390x: add cmm migration test Nico Boehr
2022-05-11 11:14 ` Claudio Imbrenda
2022-05-11 11:32 ` 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=20220511085652.823371-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=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