Skip to content

Commit 356dab4

Browse files
committed
Merge tag 'kvm-s390-next-6.12-1' of https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into HEAD
* New ucontrol selftest * Inline assembly touchups
2 parents 0cdcc99 + f9b56b2 commit 356dab4

File tree

14 files changed

+683
-25
lines changed

14 files changed

+683
-25
lines changed

arch/s390/configs/debug_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ CONFIG_CMM=m
5959
CONFIG_APPLDATA_BASE=y
6060
CONFIG_S390_HYPFS_FS=y
6161
CONFIG_KVM=m
62+
CONFIG_KVM_S390_UCONTROL=y
6263
CONFIG_S390_UNWIND_SELFTEST=m
6364
CONFIG_S390_KPROBES_SANITY_TEST=m
6465
CONFIG_S390_MODULES_SANITY_TEST=m

arch/s390/kvm/kvm-s390.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -348,20 +348,29 @@ static inline int plo_test_bit(unsigned char nr)
348348
return cc == 0;
349349
}
350350

351-
static __always_inline void __insn32_query(unsigned int opcode, u8 *query)
351+
static __always_inline void __sortl_query(u8 (*query)[32])
352352
{
353353
asm volatile(
354354
" lghi 0,0\n"
355-
" lgr 1,%[query]\n"
355+
" la 1,%[query]\n"
356356
/* Parameter registers are ignored */
357-
" .insn rrf,%[opc] << 16,2,4,6,0\n"
357+
" .insn rre,0xb9380000,2,4\n"
358+
: [query] "=R" (*query)
358359
:
359-
: [query] "d" ((unsigned long)query), [opc] "i" (opcode)
360-
: "cc", "memory", "0", "1");
360+
: "cc", "0", "1");
361361
}
362362

363-
#define INSN_SORTL 0xb938
364-
#define INSN_DFLTCC 0xb939
363+
static __always_inline void __dfltcc_query(u8 (*query)[32])
364+
{
365+
asm volatile(
366+
" lghi 0,0\n"
367+
" la 1,%[query]\n"
368+
/* Parameter registers are ignored */
369+
" .insn rrf,0xb9390000,2,4,6,0\n"
370+
: [query] "=R" (*query)
371+
:
372+
: "cc", "0", "1");
373+
}
365374

366375
static void __init kvm_s390_cpu_feat_init(void)
367376
{
@@ -415,10 +424,10 @@ static void __init kvm_s390_cpu_feat_init(void)
415424
kvm_s390_available_subfunc.kdsa);
416425

417426
if (test_facility(150)) /* SORTL */
418-
__insn32_query(INSN_SORTL, kvm_s390_available_subfunc.sortl);
427+
__sortl_query(&kvm_s390_available_subfunc.sortl);
419428

420429
if (test_facility(151)) /* DFLTCC */
421-
__insn32_query(INSN_DFLTCC, kvm_s390_available_subfunc.dfltcc);
430+
__dfltcc_query(&kvm_s390_available_subfunc.dfltcc);
422431

423432
if (MACHINE_HAS_ESOP)
424433
allow_cpu_feat(KVM_S390_VM_CPU_FEAT_ESOP);

tools/testing/selftests/kvm/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
!*.h
66
!*.S
77
!*.sh
8+
!config

tools/testing/selftests/kvm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ TEST_GEN_PROGS_s390x += s390x/tprot
188188
TEST_GEN_PROGS_s390x += s390x/cmma_test
189189
TEST_GEN_PROGS_s390x += s390x/debug_test
190190
TEST_GEN_PROGS_s390x += s390x/shared_zeropage_test
191+
TEST_GEN_PROGS_s390x += s390x/ucontrol_test
191192
TEST_GEN_PROGS_s390x += demand_paging_test
192193
TEST_GEN_PROGS_s390x += dirty_log_test
193194
TEST_GEN_PROGS_s390x += guest_print_test
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Definition for kernel virtual machines on s390x
4+
*
5+
* Copyright IBM Corp. 2024
6+
*
7+
* Authors:
8+
* Christoph Schlameuss <[email protected]>
9+
*/
10+
11+
#ifndef SELFTEST_KVM_DEBUG_PRINT_H
12+
#define SELFTEST_KVM_DEBUG_PRINT_H
13+
14+
#include "asm/ptrace.h"
15+
#include "kvm_util.h"
16+
#include "sie.h"
17+
18+
static inline void print_hex_bytes(const char *name, u64 addr, size_t len)
19+
{
20+
u64 pos;
21+
22+
pr_debug("%s (%p)\n", name, (void *)addr);
23+
pr_debug(" 0/0x00---------|");
24+
if (len > 8)
25+
pr_debug(" 8/0x08---------|");
26+
if (len > 16)
27+
pr_debug(" 16/0x10--------|");
28+
if (len > 24)
29+
pr_debug(" 24/0x18--------|");
30+
for (pos = 0; pos < len; pos += 8) {
31+
if ((pos % 32) == 0)
32+
pr_debug("\n %3lu 0x%.3lx ", pos, pos);
33+
pr_debug(" %16lx", *((u64 *)(addr + pos)));
34+
}
35+
pr_debug("\n");
36+
}
37+
38+
static inline void print_hex(const char *name, u64 addr)
39+
{
40+
print_hex_bytes(name, addr, 512);
41+
}
42+
43+
static inline void print_psw(struct kvm_run *run, struct kvm_s390_sie_block *sie_block)
44+
{
45+
pr_debug("flags:0x%x psw:0x%.16llx:0x%.16llx exit:%u %s\n",
46+
run->flags,
47+
run->psw_mask, run->psw_addr,
48+
run->exit_reason, exit_reason_str(run->exit_reason));
49+
pr_debug("sie_block psw:0x%.16llx:0x%.16llx\n",
50+
sie_block->psw_mask, sie_block->psw_addr);
51+
}
52+
53+
static inline void print_run(struct kvm_run *run, struct kvm_s390_sie_block *sie_block)
54+
{
55+
print_hex_bytes("run", (u64)run, 0x150);
56+
print_hex("sie_block", (u64)sie_block);
57+
print_psw(run, sie_block);
58+
}
59+
60+
static inline void print_regs(struct kvm_run *run)
61+
{
62+
struct kvm_sync_regs *sync_regs = &run->s.regs;
63+
64+
print_hex_bytes("GPRS", (u64)sync_regs->gprs, 8 * NUM_GPRS);
65+
print_hex_bytes("ACRS", (u64)sync_regs->acrs, 4 * NUM_ACRS);
66+
print_hex_bytes("CRS", (u64)sync_regs->crs, 8 * NUM_CRS);
67+
}
68+
69+
#endif /* SELFTEST_KVM_DEBUG_PRINT_H */

tools/testing/selftests/kvm/include/s390x/processor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
#define PAGE_PROTECT 0x200 /* HW read-only bit */
2222
#define PAGE_NOEXEC 0x100 /* HW no-execute bit */
2323

24+
/* Page size definitions */
25+
#define PAGE_SHIFT 12
26+
#define PAGE_SIZE BIT_ULL(PAGE_SHIFT)
27+
#define PAGE_MASK (~(PAGE_SIZE - 1))
28+
2429
/* Is there a portable way to do this? */
2530
static inline void cpu_relax(void)
2631
{
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Definition for kernel virtual machines on s390.
4+
*
5+
* Adapted copy of struct definition kvm_s390_sie_block from
6+
* arch/s390/include/asm/kvm_host.h for use in userspace selftest programs.
7+
*
8+
* Copyright IBM Corp. 2008, 2024
9+
*
10+
* Authors:
11+
* Christoph Schlameuss <[email protected]>
12+
* Carsten Otte <[email protected]>
13+
*/
14+
15+
#ifndef SELFTEST_KVM_SIE_H
16+
#define SELFTEST_KVM_SIE_H
17+
18+
#include <linux/types.h>
19+
20+
struct kvm_s390_sie_block {
21+
#define CPUSTAT_STOPPED 0x80000000
22+
#define CPUSTAT_WAIT 0x10000000
23+
#define CPUSTAT_ECALL_PEND 0x08000000
24+
#define CPUSTAT_STOP_INT 0x04000000
25+
#define CPUSTAT_IO_INT 0x02000000
26+
#define CPUSTAT_EXT_INT 0x01000000
27+
#define CPUSTAT_RUNNING 0x00800000
28+
#define CPUSTAT_RETAINED 0x00400000
29+
#define CPUSTAT_TIMING_SUB 0x00020000
30+
#define CPUSTAT_SIE_SUB 0x00010000
31+
#define CPUSTAT_RRF 0x00008000
32+
#define CPUSTAT_SLSV 0x00004000
33+
#define CPUSTAT_SLSR 0x00002000
34+
#define CPUSTAT_ZARCH 0x00000800
35+
#define CPUSTAT_MCDS 0x00000100
36+
#define CPUSTAT_KSS 0x00000200
37+
#define CPUSTAT_SM 0x00000080
38+
#define CPUSTAT_IBS 0x00000040
39+
#define CPUSTAT_GED2 0x00000010
40+
#define CPUSTAT_G 0x00000008
41+
#define CPUSTAT_GED 0x00000004
42+
#define CPUSTAT_J 0x00000002
43+
#define CPUSTAT_P 0x00000001
44+
__u32 cpuflags; /* 0x0000 */
45+
__u32: 1; /* 0x0004 */
46+
__u32 prefix : 18;
47+
__u32: 1;
48+
__u32 ibc : 12;
49+
__u8 reserved08[4]; /* 0x0008 */
50+
#define PROG_IN_SIE BIT(0)
51+
__u32 prog0c; /* 0x000c */
52+
union {
53+
__u8 reserved10[16]; /* 0x0010 */
54+
struct {
55+
__u64 pv_handle_cpu;
56+
__u64 pv_handle_config;
57+
};
58+
};
59+
#define PROG_BLOCK_SIE BIT(0)
60+
#define PROG_REQUEST BIT(1)
61+
__u32 prog20; /* 0x0020 */
62+
__u8 reserved24[4]; /* 0x0024 */
63+
__u64 cputm; /* 0x0028 */
64+
__u64 ckc; /* 0x0030 */
65+
__u64 epoch; /* 0x0038 */
66+
__u32 svcc; /* 0x0040 */
67+
#define LCTL_CR0 0x8000
68+
#define LCTL_CR6 0x0200
69+
#define LCTL_CR9 0x0040
70+
#define LCTL_CR10 0x0020
71+
#define LCTL_CR11 0x0010
72+
#define LCTL_CR14 0x0002
73+
__u16 lctl; /* 0x0044 */
74+
__s16 icpua; /* 0x0046 */
75+
#define ICTL_OPEREXC 0x80000000
76+
#define ICTL_PINT 0x20000000
77+
#define ICTL_LPSW 0x00400000
78+
#define ICTL_STCTL 0x00040000
79+
#define ICTL_ISKE 0x00004000
80+
#define ICTL_SSKE 0x00002000
81+
#define ICTL_RRBE 0x00001000
82+
#define ICTL_TPROT 0x00000200
83+
__u32 ictl; /* 0x0048 */
84+
#define ECA_CEI 0x80000000
85+
#define ECA_IB 0x40000000
86+
#define ECA_SIGPI 0x10000000
87+
#define ECA_MVPGI 0x01000000
88+
#define ECA_AIV 0x00200000
89+
#define ECA_VX 0x00020000
90+
#define ECA_PROTEXCI 0x00002000
91+
#define ECA_APIE 0x00000008
92+
#define ECA_SII 0x00000001
93+
__u32 eca; /* 0x004c */
94+
#define ICPT_INST 0x04
95+
#define ICPT_PROGI 0x08
96+
#define ICPT_INSTPROGI 0x0C
97+
#define ICPT_EXTREQ 0x10
98+
#define ICPT_EXTINT 0x14
99+
#define ICPT_IOREQ 0x18
100+
#define ICPT_WAIT 0x1c
101+
#define ICPT_VALIDITY 0x20
102+
#define ICPT_STOP 0x28
103+
#define ICPT_OPEREXC 0x2C
104+
#define ICPT_PARTEXEC 0x38
105+
#define ICPT_IOINST 0x40
106+
#define ICPT_KSS 0x5c
107+
#define ICPT_MCHKREQ 0x60
108+
#define ICPT_INT_ENABLE 0x64
109+
#define ICPT_PV_INSTR 0x68
110+
#define ICPT_PV_NOTIFY 0x6c
111+
#define ICPT_PV_PREF 0x70
112+
__u8 icptcode; /* 0x0050 */
113+
__u8 icptstatus; /* 0x0051 */
114+
__u16 ihcpu; /* 0x0052 */
115+
__u8 reserved54; /* 0x0054 */
116+
#define IICTL_CODE_NONE 0x00
117+
#define IICTL_CODE_MCHK 0x01
118+
#define IICTL_CODE_EXT 0x02
119+
#define IICTL_CODE_IO 0x03
120+
#define IICTL_CODE_RESTART 0x04
121+
#define IICTL_CODE_SPECIFICATION 0x10
122+
#define IICTL_CODE_OPERAND 0x11
123+
__u8 iictl; /* 0x0055 */
124+
__u16 ipa; /* 0x0056 */
125+
__u32 ipb; /* 0x0058 */
126+
__u32 scaoh; /* 0x005c */
127+
#define FPF_BPBC 0x20
128+
__u8 fpf; /* 0x0060 */
129+
#define ECB_GS 0x40
130+
#define ECB_TE 0x10
131+
#define ECB_SPECI 0x08
132+
#define ECB_SRSI 0x04
133+
#define ECB_HOSTPROTINT 0x02
134+
#define ECB_PTF 0x01
135+
__u8 ecb; /* 0x0061 */
136+
#define ECB2_CMMA 0x80
137+
#define ECB2_IEP 0x20
138+
#define ECB2_PFMFI 0x08
139+
#define ECB2_ESCA 0x04
140+
#define ECB2_ZPCI_LSI 0x02
141+
__u8 ecb2; /* 0x0062 */
142+
#define ECB3_AISI 0x20
143+
#define ECB3_AISII 0x10
144+
#define ECB3_DEA 0x08
145+
#define ECB3_AES 0x04
146+
#define ECB3_RI 0x01
147+
__u8 ecb3; /* 0x0063 */
148+
#define ESCA_SCAOL_MASK ~0x3fU
149+
__u32 scaol; /* 0x0064 */
150+
__u8 sdf; /* 0x0068 */
151+
__u8 epdx; /* 0x0069 */
152+
__u8 cpnc; /* 0x006a */
153+
__u8 reserved6b; /* 0x006b */
154+
__u32 todpr; /* 0x006c */
155+
#define GISA_FORMAT1 0x00000001
156+
__u32 gd; /* 0x0070 */
157+
__u8 reserved74[12]; /* 0x0074 */
158+
__u64 mso; /* 0x0080 */
159+
__u64 msl; /* 0x0088 */
160+
__u64 psw_mask; /* 0x0090 */
161+
__u64 psw_addr; /* 0x0098 */
162+
__u64 gg14; /* 0x00a0 */
163+
__u64 gg15; /* 0x00a8 */
164+
__u8 reservedb0[8]; /* 0x00b0 */
165+
#define HPID_KVM 0x4
166+
#define HPID_VSIE 0x5
167+
__u8 hpid; /* 0x00b8 */
168+
__u8 reservedb9[7]; /* 0x00b9 */
169+
union {
170+
struct {
171+
__u32 eiparams; /* 0x00c0 */
172+
__u16 extcpuaddr; /* 0x00c4 */
173+
__u16 eic; /* 0x00c6 */
174+
};
175+
__u64 mcic; /* 0x00c0 */
176+
} __packed;
177+
__u32 reservedc8; /* 0x00c8 */
178+
union {
179+
struct {
180+
__u16 pgmilc; /* 0x00cc */
181+
__u16 iprcc; /* 0x00ce */
182+
};
183+
__u32 edc; /* 0x00cc */
184+
} __packed;
185+
union {
186+
struct {
187+
__u32 dxc; /* 0x00d0 */
188+
__u16 mcn; /* 0x00d4 */
189+
__u8 perc; /* 0x00d6 */
190+
__u8 peratmid; /* 0x00d7 */
191+
};
192+
__u64 faddr; /* 0x00d0 */
193+
} __packed;
194+
__u64 peraddr; /* 0x00d8 */
195+
__u8 eai; /* 0x00e0 */
196+
__u8 peraid; /* 0x00e1 */
197+
__u8 oai; /* 0x00e2 */
198+
__u8 armid; /* 0x00e3 */
199+
__u8 reservede4[4]; /* 0x00e4 */
200+
union {
201+
__u64 tecmc; /* 0x00e8 */
202+
struct {
203+
__u16 subchannel_id; /* 0x00e8 */
204+
__u16 subchannel_nr; /* 0x00ea */
205+
__u32 io_int_parm; /* 0x00ec */
206+
__u32 io_int_word; /* 0x00f0 */
207+
};
208+
} __packed;
209+
__u8 reservedf4[8]; /* 0x00f4 */
210+
#define CRYCB_FORMAT_MASK 0x00000003
211+
#define CRYCB_FORMAT0 0x00000000
212+
#define CRYCB_FORMAT1 0x00000001
213+
#define CRYCB_FORMAT2 0x00000003
214+
__u32 crycbd; /* 0x00fc */
215+
__u64 gcr[16]; /* 0x0100 */
216+
union {
217+
__u64 gbea; /* 0x0180 */
218+
__u64 sidad;
219+
};
220+
__u8 reserved188[8]; /* 0x0188 */
221+
__u64 sdnxo; /* 0x0190 */
222+
__u8 reserved198[8]; /* 0x0198 */
223+
__u32 fac; /* 0x01a0 */
224+
__u8 reserved1a4[20]; /* 0x01a4 */
225+
__u64 cbrlo; /* 0x01b8 */
226+
__u8 reserved1c0[8]; /* 0x01c0 */
227+
#define ECD_HOSTREGMGMT 0x20000000
228+
#define ECD_MEF 0x08000000
229+
#define ECD_ETOKENF 0x02000000
230+
#define ECD_ECC 0x00200000
231+
__u32 ecd; /* 0x01c8 */
232+
__u8 reserved1cc[18]; /* 0x01cc */
233+
__u64 pp; /* 0x01de */
234+
__u8 reserved1e6[2]; /* 0x01e6 */
235+
__u64 itdba; /* 0x01e8 */
236+
__u64 riccbd; /* 0x01f0 */
237+
__u64 gvrd; /* 0x01f8 */
238+
} __packed __aligned(512);
239+
240+
#endif /* SELFTEST_KVM_SIE_H */

0 commit comments

Comments
 (0)