blob: e72a2b198dac18c486f8acd397e63dc5e44c3d39 [file] [log] [blame]
Janosch Frankfa624cc2020-12-07 04:38:46 -05001/* SPDX-License-Identifier: GPL-2.0-only */
Janosch Frank47df95c2019-08-28 13:36:15 +02002/*
3 * Storage key removal facility tests
4 *
5 * Copyright (c) 2019 IBM Corp
6 *
7 * Authors:
8 * Janosch Frank <frankja@linux.ibm.com>
Janosch Frank47df95c2019-08-28 13:36:15 +02009 */
10#include <libcflat.h>
Janosch Frankd34d3252021-08-06 09:05:09 +000011#include <bitops.h>
Janosch Frank47df95c2019-08-28 13:36:15 +020012#include <asm/asm-offsets.h>
Janosch Frank787d1bc2020-08-07 07:15:54 -040013#include <asm-generic/barrier.h>
Janosch Frank47df95c2019-08-28 13:36:15 +020014#include <asm/interrupt.h>
15#include <asm/page.h>
16#include <asm/facility.h>
17#include <asm/mem.h>
Janosch Frank787d1bc2020-08-07 07:15:54 -040018#include <asm/sigp.h>
19#include <smp.h>
Janosch Frank47df95c2019-08-28 13:36:15 +020020
21static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2)));
Janosch Frank787d1bc2020-08-07 07:15:54 -040022static int testflag = 0;
Janosch Frank47df95c2019-08-28 13:36:15 +020023
24static void test_facilities(void)
25{
26 report_prefix_push("facilities");
Thomas Hutha2998952019-12-06 12:31:02 +010027 report(!test_facility(10), "!10");
28 report(!test_facility(14), "!14");
29 report(!test_facility(66), "!66");
30 report(!test_facility(145), "!145");
31 report(!test_facility(140), "!149");
Janosch Frank47df95c2019-08-28 13:36:15 +020032 report_prefix_pop();
33}
34
35static void test_skey(void)
36{
37 report_prefix_push("sske");
38 expect_pgm_int();
39 set_storage_key(pagebuf, 0x30, 0);
40 check_pgm_int_code(PGM_INT_CODE_SPECIAL_OPERATION);
41 expect_pgm_int();
42 report_prefix_pop();
43 report_prefix_push("iske");
44 get_storage_key(pagebuf);
45 check_pgm_int_code(PGM_INT_CODE_SPECIAL_OPERATION);
46 report_prefix_pop();
47}
48
49static void test_pfmf(void)
50{
51 union pfmf_r1 r1;
52
53 report_prefix_push("pfmf");
54 r1.val = 0;
55 r1.reg.sk = 1;
56 r1.reg.fsc = PFMF_FSC_4K;
57 r1.reg.key = 0x30;
58 expect_pgm_int();
59 pfmf(r1.val, pagebuf);
60 check_pgm_int_code(PGM_INT_CODE_SPECIAL_OPERATION);
61 report_prefix_pop();
62}
63
64static void test_psw_key(void)
65{
Janosch Frank47df95c2019-08-28 13:36:15 +020066 report_prefix_push("psw key");
67 expect_pgm_int();
Claudio Imbrenda086985a2022-06-23 11:16:08 +020068 psw_mask_set_bits(PSW_MASK_KEY);
Janosch Frank47df95c2019-08-28 13:36:15 +020069 check_pgm_int_code(PGM_INT_CODE_SPECIAL_OPERATION);
70 report_prefix_pop();
71}
72
73static void test_mvcos(void)
74{
75 uint64_t r3 = 64;
76 uint8_t *src = pagebuf;
77 uint8_t *dst = pagebuf + PAGE_SIZE;
78 /* K bit set, as well as keys */
79 register unsigned long oac asm("0") = 0xf002f002;
80
81 report_prefix_push("mvcos");
82 expect_pgm_int();
83 asm volatile("mvcos %[dst],%[src],%[len]"
84 : [dst] "+Q" (*(dst))
85 : [src] "Q" (*(src)), [len] "d" (r3), "d" (oac)
86 : "cc", "memory");
87 check_pgm_int_code(PGM_INT_CODE_SPECIAL_OPERATION);
88 report_prefix_pop();
89}
90
91static void test_spka(void)
92{
93 report_prefix_push("spka");
94 expect_pgm_int();
95 asm volatile("spka 0xf0(0)\n");
96 check_pgm_int_code(PGM_INT_CODE_SPECIAL_OPERATION);
97 report_prefix_pop();
98}
99
100static void test_tprot(void)
101{
102 report_prefix_push("tprot");
103 expect_pgm_int();
Janis Schoetterl-Glausch443987a2021-09-22 15:05:40 +0200104 tprot((unsigned long)pagebuf, 0xf);
Janosch Frank47df95c2019-08-28 13:36:15 +0200105 check_pgm_int_code(PGM_INT_CODE_SPECIAL_OPERATION);
106 report_prefix_pop();
107}
108
Janosch Frank787d1bc2020-08-07 07:15:54 -0400109static void wait_for_flag(void)
110{
111 while (!testflag)
112 mb();
113}
114
115static void set_flag(int val)
116{
117 mb();
118 testflag = val;
119 mb();
120}
121
Claudio Imbrenda4e5dd752022-02-21 17:45:08 +0100122static void ecall_cleanup(struct stack_frame_int *stack)
Janosch Frank787d1bc2020-08-07 07:15:54 -0400123{
Janis Schoetterl-Glauschcd719532022-06-08 14:29:52 +0200124 lowcore.ext_new_psw.mask = PSW_MASK_64;
125 lowcore.sw_int_crs[0] = BIT_ULL(CTL0_AFP);
Janosch Frank787d1bc2020-08-07 07:15:54 -0400126
127 /*
128 * PGM old contains the ext new PSW, we need to clean it up,
129 * so we don't get a special operation exception on the lpswe
130 * of pgm old.
131 */
Janis Schoetterl-Glauschcd719532022-06-08 14:29:52 +0200132 lowcore.pgm_old_psw.mask = PSW_MASK_64;
Janosch Frank787d1bc2020-08-07 07:15:54 -0400133
134 check_pgm_int_code(PGM_INT_CODE_SPECIFICATION);
135 set_flag(1);
136}
137
138/* Set a key into the external new psw mask and open external call masks */
139static void ecall_setup(void)
140{
Janosch Frank787d1bc2020-08-07 07:15:54 -0400141 register_pgm_cleanup_func(ecall_cleanup);
142 expect_pgm_int();
143 /* Put a skey into the ext new psw */
Claudio Imbrenda086985a2022-06-23 11:16:08 +0200144 lowcore.ext_new_psw.mask = PSW_MASK_KEY | PSW_MASK_64;
Janosch Frank787d1bc2020-08-07 07:15:54 -0400145 /* Open up ext masks */
Claudio Imbrenda1b2c0432021-06-11 16:06:59 +0200146 ctl_set_bit(0, CTL0_EXTERNAL_CALL);
Claudio Imbrenda086985a2022-06-23 11:16:08 +0200147 psw_mask_set_bits(PSW_MASK_EXT);
Janosch Frank787d1bc2020-08-07 07:15:54 -0400148 /* Tell cpu 0 that we're ready */
149 set_flag(1);
150}
151
152static void test_exception_ext_new(void)
153{
Janosch Frank787d1bc2020-08-07 07:15:54 -0400154 report_prefix_push("exception external new");
155 if (smp_query_num_cpus() < 2) {
156 report_skip("Need second cpu for exception external new test.");
157 report_prefix_pop();
158 return;
159 }
160
Claudio Imbrendaf514b4f2022-11-30 16:40:38 +0100161 smp_cpu_setup(1, PSW_WITH_CUR_MASK(ecall_setup));
Janosch Frank787d1bc2020-08-07 07:15:54 -0400162 wait_for_flag();
163 set_flag(0);
164
Claudio Imbrenda962129d2022-01-28 14:03:09 +0100165 smp_sigp(1, SIGP_EXTERNAL_CALL, 0, NULL);
Janosch Frank787d1bc2020-08-07 07:15:54 -0400166 wait_for_flag();
167 smp_cpu_stop(1);
168 report_prefix_pop();
169}
170
Janosch Frank47df95c2019-08-28 13:36:15 +0200171int main(void)
172{
173 report_prefix_push("skrf");
174 if (!test_facility(169)) {
175 report_skip("storage key removal facility not available\n");
176 goto done;
177 }
178
179 test_facilities();
180 test_skey();
181 test_pfmf();
182 test_psw_key();
183 test_mvcos();
184 test_spka();
185 test_tprot();
Janosch Frank787d1bc2020-08-07 07:15:54 -0400186 test_exception_ext_new();
Janosch Frank47df95c2019-08-28 13:36:15 +0200187
188done:
189 report_prefix_pop();
190 return report_summary();
191}