From: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
To: Thomas Huth <thuth@redhat.com>,
Janosch Frank <frankja@linux.ibm.com>,
Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: Janis Schoetterl-Glausch <scgl@linux.ibm.com>,
David Hildenbrand <david@redhat.com>,
kvm@vger.kernel.org, linux-s390@vger.kernel.org
Subject: [kvm-unit-tests PATCH v2 0/4] More skey instr. emulation test
Date: Tue, 17 May 2022 13:56:03 +0200 [thread overview]
Message-ID: <20220517115607.3252157-1-scgl@linux.ibm.com> (raw)
Add test cases similar to those testing the effect of storage keys on
instructions emulated by KVM, but test instructions emulated by user
space/qemu instead.
Test that DIAG 308 is not subject to key protection.
Additionally, check the transaction exception identification on
protection exceptions.
v1 -> v2
* don't mixup sclp fix with new bits for the TEID patch
* address feedback
* cosmetic changes, i.e. shortening identifiers
* remove unconditional report_info
* add DIAG 308 test
Janis Schoetterl-Glausch (4):
s390x: Fix sclp facility bit numbers
s390x: Test TEID values in storage key test
s390x: Test effect of storage keys on some more instructions
s390x: Test effect of storage keys on diag 308
lib/s390x/asm/facility.h | 21 +++
lib/s390x/sclp.h | 18 +-
lib/s390x/sclp.c | 2 +
s390x/skey.c | 371 ++++++++++++++++++++++++++++++++++++++-
s390x/unittests.cfg | 1 +
5 files changed, 400 insertions(+), 13 deletions(-)
Range-diff against v1:
1: 4c833d84 ! 1: d6e6b532 s390x: Fix sclp facility bit numbers
@@ Commit message
Fixes: 4dd649c8 ("lib: s390x: sclp: Extend feature probing")
Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
+ Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
+ Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
## lib/s390x/sclp.h ##
@@ lib/s390x/sclp.h: struct sclp_facilities {
@@ lib/s390x/sclp.h: struct sclp_facilities {
-#define SCLP_FEAT_116_BIT_ESCA 3
-#define SCLP_FEAT_117_BIT_PFMFI 6
-#define SCLP_FEAT_117_BIT_IBS 5
-+#define SCLP_FEAT_80_BIT_SOP 2
+#define SCLP_FEAT_85_BIT_GSLS 0
-+#define SCLP_FEAT_85_BIT_ESOP 6
+#define SCLP_FEAT_98_BIT_KSS 7
+#define SCLP_FEAT_116_BIT_64BSCAO 0
+#define SCLP_FEAT_116_BIT_CMMA 1
2: 1defccd8 ! 2: 3c03bfba s390x: Test TEID values in storage key test
@@ lib/s390x/sclp.h: struct sclp_facilities {
uint64_t has_cmma : 1;
uint64_t has_64bscao : 1;
uint64_t has_esca : 1;
+@@ lib/s390x/sclp.h: struct sclp_facilities {
+ };
+
+ /* bit number within a certain byte */
++#define SCLP_FEAT_80_BIT_SOP 2
+ #define SCLP_FEAT_85_BIT_GSLS 0
++#define SCLP_FEAT_85_BIT_ESOP 6
+ #define SCLP_FEAT_98_BIT_KSS 7
+ #define SCLP_FEAT_116_BIT_64BSCAO 0
+ #define SCLP_FEAT_116_BIT_CMMA 1
## lib/s390x/sclp.c ##
@@ lib/s390x/sclp.c: void sclp_facilities_setup(void)
@@ s390x/skey.c: static void test_test_protection(void)
}
+enum access {
-+ ACC_FETCH = 2,
+ ACC_STORE = 1,
++ ACC_FETCH = 2,
+ ACC_UPDATE = 3,
+};
+
@@ s390x/skey.c: static void test_test_protection(void)
+ if (teid.val & BIT(63 - 60)) {
+ int access_code = teid.fetch << 1 | teid.store;
+
-+ report_info("access code: %d", access_code);
+ if (access_code == 2)
+ report((access & 2) && (prot & 2),
+ "exception due to fetch");
+ if (access_code == 1)
+ report((access & 1) && (prot & 1),
+ "exception due to store");
++ /* no relevant information if code is 0 or 3 */
+ }
+ }
+ break;
3: 58893c9c ! 3: 0b7b0e57 s390x: Test effect of storage keys on some more instructions
@@ s390x/skey.c: static void test_store_cpu_address(void)
+ * Perform CHANNEL SUBSYSTEM CALL (CHSC) instruction while temporarily executing
+ * with access key 1.
+ */
-+static unsigned int channel_subsystem_call_key_1(void *communication_block)
++static unsigned int chsc_key_1(void *comm_block)
+{
+ uint32_t program_mask;
+
+ asm volatile (
+ "spka 0x10\n\t"
-+ ".insn rre,0xb25f0000,%[communication_block],0\n\t"
++ ".insn rre,0xb25f0000,%[comm_block],0\n\t"
+ "spka 0\n\t"
+ "ipm %[program_mask]\n"
+ : [program_mask] "=d" (program_mask)
-+ : [communication_block] "d" (communication_block)
++ : [comm_block] "d" (comm_block)
+ : "memory"
+ );
+ return program_mask >> 28;
+}
+
-+static void init_store_channel_subsystem_characteristics(uint16_t *communication_block)
++static const char chsc_msg[] = "Performed store-channel-subsystem-characteristics";
++static void init_comm_block(uint16_t *comm_block)
+{
-+ memset(communication_block, 0, PAGE_SIZE);
-+ communication_block[0] = 0x10;
-+ communication_block[1] = 0x10;
-+ communication_block[9] = 0;
++ memset(comm_block, 0, PAGE_SIZE);
++ /* store-channel-subsystem-characteristics command */
++ comm_block[0] = 0x10;
++ comm_block[1] = 0x10;
++ comm_block[9] = 0;
+}
+
+static void test_channel_subsystem_call(void)
+{
-+ static const char request_name[] = "Store channel-subsystem-characteristics";
-+ uint16_t *communication_block = (uint16_t *)&pagebuf;
++ uint16_t *comm_block = (uint16_t *)&pagebuf;
+ unsigned int cc;
+
+ report_prefix_push("CHANNEL SUBSYSTEM CALL");
+
+ report_prefix_push("zero key");
-+ init_store_channel_subsystem_characteristics(communication_block);
-+ set_storage_key(communication_block, 0x10, 0);
++ init_comm_block(comm_block);
++ set_storage_key(comm_block, 0x10, 0);
+ asm volatile (
-+ ".insn rre,0xb25f0000,%[communication_block],0\n\t"
++ ".insn rre,0xb25f0000,%[comm_block],0\n\t"
+ "ipm %[cc]\n"
+ : [cc] "=d" (cc)
-+ : [communication_block] "d" (communication_block)
++ : [comm_block] "d" (comm_block)
+ : "memory"
+ );
+ cc = cc >> 28;
-+ report(cc == 0 && communication_block[9], request_name);
++ report(cc == 0 && comm_block[9], chsc_msg);
+ report_prefix_pop();
+
+ report_prefix_push("matching key");
-+ init_store_channel_subsystem_characteristics(communication_block);
-+ set_storage_key(communication_block, 0x10, 0);
-+ cc = channel_subsystem_call_key_1(communication_block);
-+ report(cc == 0 && communication_block[9], request_name);
++ init_comm_block(comm_block);
++ set_storage_key(comm_block, 0x10, 0);
++ cc = chsc_key_1(comm_block);
++ report(cc == 0 && comm_block[9], chsc_msg);
+ report_prefix_pop();
+
+ report_prefix_push("mismatching key");
+
+ report_prefix_push("no fetch protection");
-+ init_store_channel_subsystem_characteristics(communication_block);
-+ set_storage_key(communication_block, 0x20, 0);
++ init_comm_block(comm_block);
++ set_storage_key(comm_block, 0x20, 0);
+ expect_pgm_int();
-+ channel_subsystem_call_key_1(communication_block);
++ chsc_key_1(comm_block);
+ check_key_prot_exc(ACC_UPDATE, PROT_STORE);
+ report_prefix_pop();
+
+ report_prefix_push("fetch protection");
-+ init_store_channel_subsystem_characteristics(communication_block);
-+ set_storage_key(communication_block, 0x28, 0);
++ init_comm_block(comm_block);
++ set_storage_key(comm_block, 0x28, 0);
+ expect_pgm_int();
-+ channel_subsystem_call_key_1(communication_block);
++ chsc_key_1(comm_block);
+ check_key_prot_exc(ACC_UPDATE, PROT_FETCH_STORE);
+ report_prefix_pop();
+
+ ctl_set_bit(0, CTL0_STORAGE_PROTECTION_OVERRIDE);
+
+ report_prefix_push("storage-protection override, invalid key");
-+ set_storage_key(communication_block, 0x20, 0);
-+ init_store_channel_subsystem_characteristics(communication_block);
++ set_storage_key(comm_block, 0x20, 0);
++ init_comm_block(comm_block);
+ expect_pgm_int();
-+ channel_subsystem_call_key_1(communication_block);
++ chsc_key_1(comm_block);
+ check_key_prot_exc(ACC_UPDATE, PROT_STORE);
+ report_prefix_pop();
+
+ report_prefix_push("storage-protection override, override key");
-+ init_store_channel_subsystem_characteristics(communication_block);
-+ set_storage_key(communication_block, 0x90, 0);
-+ cc = channel_subsystem_call_key_1(communication_block);
-+ report(cc == 0 && communication_block[9], request_name);
++ init_comm_block(comm_block);
++ set_storage_key(comm_block, 0x90, 0);
++ cc = chsc_key_1(comm_block);
++ report(cc == 0 && comm_block[9], chsc_msg);
+ report_prefix_pop();
+
+ ctl_clear_bit(0, CTL0_STORAGE_PROTECTION_OVERRIDE);
+
+ report_prefix_push("storage-protection override disabled, override key");
-+ init_store_channel_subsystem_characteristics(communication_block);
-+ set_storage_key(communication_block, 0x90, 0);
++ init_comm_block(comm_block);
++ set_storage_key(comm_block, 0x90, 0);
+ expect_pgm_int();
-+ channel_subsystem_call_key_1(communication_block);
++ chsc_key_1(comm_block);
+ check_key_prot_exc(ACC_UPDATE, PROT_STORE);
+ report_prefix_pop();
+
+ report_prefix_pop();
+
-+ set_storage_key(communication_block, 0x00, 0);
++ set_storage_key(comm_block, 0x00, 0);
+ report_prefix_pop();
+}
+
@@ s390x/skey.c: static void test_set_prefix(void)
+{
+ uint32_t program_mask;
+
++/*
++ * gcc 12.0.1 warns if schib is < 4k.
++ * We need such addresses to test fetch protection override.
++ */
++#pragma GCC diagnostic push
++#pragma GCC diagnostic ignored "-Warray-bounds"
+ asm volatile (
+ "lr %%r1,%[sid]\n\t"
+ "spka 0x10\n\t"
@@ s390x/skey.c: static void test_set_prefix(void)
+ [schib] "Q" (*schib)
+ : "%r1"
+ );
++#pragma GCC diagnostic pop
+ return program_mask >> 28;
+}
+
-: -------- > 4: 7fb70993 s390x: Test effect of storage keys on diag 308
base-commit: c315f52b88b967cfb4cd58f3b4e1987378c47f3b
prerequisite-patch-id: 1c147bf31109769a454ef133daacb0786ac69a2d
--
2.33.1
next reply other threads:[~2022-05-17 11:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-17 11:56 Janis Schoetterl-Glausch [this message]
2022-05-17 11:56 ` [kvm-unit-tests PATCH v2 1/4] s390x: Fix sclp facility bit numbers Janis Schoetterl-Glausch
2022-05-17 11:56 ` [kvm-unit-tests PATCH v2 2/4] s390x: Test TEID values in storage key test Janis Schoetterl-Glausch
2022-05-17 13:46 ` Claudio Imbrenda
2022-05-17 15:11 ` Janis Schoetterl-Glausch
2022-05-17 15:32 ` Claudio Imbrenda
2022-05-17 11:56 ` [kvm-unit-tests PATCH v2 3/4] s390x: Test effect of storage keys on some more instructions Janis Schoetterl-Glausch
2022-05-17 13:54 ` Claudio Imbrenda
2022-05-17 15:34 ` Janis Schoetterl-Glausch
2022-05-17 11:56 ` [kvm-unit-tests PATCH v2 4/4] s390x: Test effect of storage keys on diag 308 Janis Schoetterl-Glausch
2022-05-17 14:52 ` Claudio Imbrenda
2022-05-17 15:47 ` Janis Schoetterl-Glausch
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=20220517115607.3252157-1-scgl@linux.ibm.com \
--to=scgl@linux.ibm.com \
--cc=david@redhat.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