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 v3 0/4] More skey instr. emulation test
Date: Mon, 23 May 2022 15:24:03 +0200 [thread overview]
Message-ID: <20220523132406.1820550-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.
This series is based on s390x: Rework TEID decoding and usage .
https://lore.kernel.org/kvm/20220520190850.3445768-1-scgl@linux.ibm.com/
v2 -> v3
* move sclp patch and part of TEID test to series
s390x: Rework TEID decoding and usage
* make use of reworked TEID union in skey TEID test
* get rid of pointer to array for diag 308 test
* use lowcore symbol and mem_all
* don't reset intparm when expecting exception in msch test
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 (3):
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
s390x/skey.c | 376 +++++++++++++++++++++++++++++++++++++++++++-
s390x/unittests.cfg | 1 +
2 files changed, 371 insertions(+), 6 deletions(-)
Range-diff against v2:
1: 3c03bfba ! 1: 073ffb3c s390x: Test TEID values in storage key test
@@ Commit message
Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
- ## lib/s390x/asm/facility.h ##
-@@
- #include <asm/facility.h>
- #include <asm/arch_def.h>
- #include <bitops.h>
-+#include <sclp.h>
-
- #define NB_STFL_DOUBLEWORDS 32
- extern uint64_t stfl_doublewords[];
-@@ lib/s390x/asm/facility.h: static inline void setup_facilities(void)
- stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS);
- }
-
-+enum supp_on_prot_facility {
-+ SOP_NONE,
-+ SOP_BASIC,
-+ SOP_ENHANCED_1,
-+ SOP_ENHANCED_2,
-+};
-+
-+static inline enum supp_on_prot_facility get_supp_on_prot_facility(void)
-+{
-+ if (sclp_facilities.has_esop) {
-+ if (test_facility(131)) /* side-effect-access facility */
-+ return SOP_ENHANCED_2;
-+ else
-+ return SOP_ENHANCED_1;
-+ }
-+ if (sclp_facilities.has_sop)
-+ return SOP_BASIC;
-+ return SOP_NONE;
-+}
-+
- #endif
-
- ## lib/s390x/sclp.h ##
-@@ lib/s390x/sclp.h: struct sclp_facilities {
- uint64_t has_cei : 1;
-
- uint64_t has_diag318 : 1;
-+ uint64_t has_sop : 1;
- uint64_t has_gsls : 1;
-+ uint64_t has_esop : 1;
- 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)
- cpu = sclp_get_cpu_entries();
- if (read_info->offset_cpu > 134)
- sclp_facilities.has_diag318 = read_info->byte_134_diag318;
-+ sclp_facilities.has_sop = sclp_feat_check(80, SCLP_FEAT_80_BIT_SOP);
- sclp_facilities.has_gsls = sclp_feat_check(85, SCLP_FEAT_85_BIT_GSLS);
-+ sclp_facilities.has_esop = sclp_feat_check(85, SCLP_FEAT_85_BIT_ESOP);
- sclp_facilities.has_kss = sclp_feat_check(98, SCLP_FEAT_98_BIT_KSS);
- sclp_facilities.has_cmma = sclp_feat_check(116, SCLP_FEAT_116_BIT_CMMA);
- sclp_facilities.has_64bscao = sclp_feat_check(116, SCLP_FEAT_116_BIT_64BSCAO);
-
## s390x/skey.c ##
@@
* Janosch Frank <frankja@linux.vnet.ibm.com>
*/
#include <libcflat.h>
-+#include <bitops.h>
++#include <asm/arch_def.h>
#include <asm/asm-offsets.h>
#include <asm/interrupt.h>
#include <vmalloc.h>
@@ s390x/skey.c: static void test_test_protection(void)
+
+static void check_key_prot_exc(enum access access, enum protection prot)
+{
-+ struct lowcore *lc = 0;
+ union teid teid;
++ int access_code;
+
+ check_pgm_int_code(PGM_INT_CODE_PROTECTION);
+ report_prefix_push("TEID");
-+ teid.val = lc->trans_exc_id;
++ teid.val = lowcore.trans_exc_id;
+ switch (get_supp_on_prot_facility()) {
+ case SOP_NONE:
+ case SOP_BASIC:
+ break;
+ case SOP_ENHANCED_1:
-+ if ((teid.val & (BIT(63 - 61))) == 0)
-+ report_pass("key-controlled protection");
++ report(!teid.esop1_acc_list_or_dat, "valid protection code");
+ break;
+ case SOP_ENHANCED_2:
-+ if ((teid.val & (BIT(63 - 56) | BIT(63 - 61))) == 0) {
-+ report_pass("key-controlled protection");
-+ if (teid.val & BIT(63 - 60)) {
-+ int access_code = teid.fetch << 1 | teid.store;
++ switch (teid_esop2_prot_code(teid)) {
++ case PROT_KEY:
++ access_code = teid.acc_exc_f_s;
+
-+ 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 */
++ switch (access_code) {
++ case 0:
++ report_pass("valid access code");
++ break;
++ case 1:
++ case 2:
++ report((access & access_code) && (prot & access_code),
++ "valid access code");
++ break;
++ case 3:
++ /*
++ * This is incorrect in that reserved values
++ * should be ignored, but kvm should not return
++ * a reserved value and having a test for that
++ * is more valuable.
++ */
++ report_fail("valid access code");
++ break;
+ }
++ /* fallthrough */
++ case PROT_KEY_LAP:
++ report_pass("valid protection code");
++ break;
++ default:
++ report_fail("valid protection code");
+ }
+ break;
+ }
@@ s390x/skey.c: static void test_set_prefix(void)
@@ s390x/skey.c: static void test_set_prefix(void)
install_page(root, virt_to_pte_phys(root, pagebuf), 0);
- set_prefix_key_1((uint32_t *)2048);
+ set_prefix_key_1((uint32_t *)&mem_all[2048]);
install_page(root, 0, 0);
- check_pgm_int_code(PGM_INT_CODE_PROTECTION);
+ check_key_prot_exc(ACC_FETCH, PROT_FETCH_STORE);
2: 0b7b0e57 ! 2: 9f300b87 s390x: Test effect of storage keys on some more instructions
@@ 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;
+}
+
@@ s390x/skey.c: static void test_set_prefix(void)
+ expect_pgm_int();
+ modify_subchannel_key_1(test_device_sid, schib);
+ check_key_prot_exc(ACC_FETCH, PROT_FETCH_STORE);
-+ WRITE_ONCE(schib->pmcw.intparm, 0);
+ cc = stsch(test_device_sid, schib);
+ report(!cc && schib->pmcw.intparm == 0, "did not modify subchannel");
+ report_prefix_pop();
@@ s390x/skey.c: static void test_set_prefix(void)
+ modify_subchannel_key_1(test_device_sid, (struct schib *)0);
+ install_page(root, 0, 0);
+ check_key_prot_exc(ACC_FETCH, PROT_FETCH_STORE);
-+ WRITE_ONCE(schib->pmcw.intparm, 0);
+ cc = stsch(test_device_sid, schib);
+ report(!cc && schib->pmcw.intparm == 0, "did not modify subchannel");
+ report_prefix_pop();
@@ s390x/skey.c: static void test_set_prefix(void)
+ set_storage_key(pagebuf, 0x28, 0);
+ expect_pgm_int();
+ install_page(root, virt_to_pte_phys(root, pagebuf), 0);
-+ modify_subchannel_key_1(test_device_sid, (struct schib *)2048);
++ modify_subchannel_key_1(test_device_sid, (struct schib *)&mem_all[2048]);
+ install_page(root, 0, 0);
+ check_key_prot_exc(ACC_FETCH, PROT_FETCH_STORE);
-+ WRITE_ONCE(schib->pmcw.intparm, 0);
+ cc = stsch(test_device_sid, schib);
+ report(!cc && schib->pmcw.intparm == 0, "did not modify subchannel");
+ report_prefix_pop();
3: 7fb70993 ! 3: c4ca0619 s390x: Test effect of storage keys on diag 308
@@ s390x/skey.c: static void test_store_cpu_address(void)
+static void test_diag_308(void)
+{
+ uint16_t response;
-+ uint32_t (*ipib)[1024] = (void *)pagebuf;
++ uint32_t *ipib = (uint32_t *)pagebuf;
+
+ report_prefix_push("DIAG 308");
-+ (*ipib)[0] = 0; /* Invalid length */
++ WRITE_ONCE(ipib[0], 0); /* Invalid length */
+ set_storage_key(ipib, 0x28, 0);
+ /* key-controlled protection does not apply */
+ asm volatile (
base-commit: 8719e8326101c1be8256617caf5835b57e819339
prerequisite-patch-id: aa682f50e4eba0e9b6cacd245d568f5bcca05e0f
prerequisite-patch-id: 55b90f625ada542f074cecb82cf63e2980205ce1
prerequisite-patch-id: bebbc71ca3cc8d085e36a049466dba5a420c9c75
prerequisite-patch-id: d38a4fc7bc1fa6e352502f294cb9413f0b738b99
prerequisite-patch-id: 16ccb9380be55e33fc96639bf69570a9f8327697
--
2.33.1
next reply other threads:[~2022-05-23 13:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-23 13:24 Janis Schoetterl-Glausch [this message]
2022-05-23 13:24 ` [kvm-unit-tests PATCH v3 1/3] s390x: Test TEID values in storage key test Janis Schoetterl-Glausch
2022-05-24 15:09 ` Claudio Imbrenda
2022-06-08 17:03 ` Janis Schoetterl-Glausch
2022-06-09 7:44 ` Claudio Imbrenda
2022-05-23 13:24 ` [kvm-unit-tests PATCH v3 2/3] s390x: Test effect of storage keys on some more instructions Janis Schoetterl-Glausch
2022-05-25 6:05 ` Claudio Imbrenda
2022-05-23 13:24 ` [kvm-unit-tests PATCH v3 3/3] s390x: Test effect of storage keys on diag 308 Janis Schoetterl-Glausch
2022-05-24 15:01 ` Claudio Imbrenda
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=20220523132406.1820550-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.