Skip to content

Commit 1644e27

Browse files
committed
Merge tag 'kvm-s390-next-5.19-1' of git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into HEAD
KVM: s390: Fix and feature for 5.19 - ultravisor communication device driver - fix TEID on terminating storage key ops
2 parents b699da3 + c711596 commit 1644e27

File tree

14 files changed

+714
-6
lines changed

14 files changed

+714
-6
lines changed

Documentation/virt/kvm/api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3814,12 +3814,18 @@ in case of KVM_S390_MEMOP_F_CHECK_ONLY), the ioctl returns a positive
38143814
error number indicating the type of exception. This exception is also
38153815
raised directly at the corresponding VCPU if the flag
38163816
KVM_S390_MEMOP_F_INJECT_EXCEPTION is set.
3817+
On protection exceptions, unless specified otherwise, the injected
3818+
translation-exception identifier (TEID) indicates suppression.
38173819

38183820
If the KVM_S390_MEMOP_F_SKEY_PROTECTION flag is set, storage key
38193821
protection is also in effect and may cause exceptions if accesses are
38203822
prohibited given the access key designated by "key"; the valid range is 0..15.
38213823
KVM_S390_MEMOP_F_SKEY_PROTECTION is available if KVM_CAP_S390_MEM_OP_EXTENSION
38223824
is > 0.
3825+
Since the accessed memory may span multiple pages and those pages might have
3826+
different storage keys, it is possible that a protection exception occurs
3827+
after memory has been modified. In this case, if the exception is injected,
3828+
the TEID does not indicate suppression.
38233829

38243830
Absolute read/write:
38253831
^^^^^^^^^^^^^^^^^^^^

MAINTAINERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10785,9 +10785,12 @@ F: Documentation/virt/kvm/s390*
1078510785
F: arch/s390/include/asm/gmap.h
1078610786
F: arch/s390/include/asm/kvm*
1078710787
F: arch/s390/include/uapi/asm/kvm*
10788+
F: arch/s390/include/uapi/asm/uvdevice.h
1078810789
F: arch/s390/kernel/uv.c
1078910790
F: arch/s390/kvm/
1079010791
F: arch/s390/mm/gmap.c
10792+
F: drivers/s390/char/uvdevice.c
10793+
F: tools/testing/selftests/drivers/s390x/uvdevice/
1079110794
F: tools/testing/selftests/kvm/*/s390x/
1079210795
F: tools/testing/selftests/kvm/s390x/
1079310796

arch/s390/include/asm/uv.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* Ultravisor Interfaces
44
*
5-
* Copyright IBM Corp. 2019
5+
* Copyright IBM Corp. 2019, 2022
66
*
77
* Author(s):
88
* Vasily Gorbik <[email protected]>
@@ -52,6 +52,7 @@
5252
#define UVC_CMD_UNPIN_PAGE_SHARED 0x0342
5353
#define UVC_CMD_SET_SHARED_ACCESS 0x1000
5454
#define UVC_CMD_REMOVE_SHARED_ACCESS 0x1001
55+
#define UVC_CMD_RETR_ATTEST 0x1020
5556

5657
/* Bits in installed uv calls */
5758
enum uv_cmds_inst {
@@ -76,6 +77,7 @@ enum uv_cmds_inst {
7677
BIT_UVC_CMD_UNSHARE_ALL = 20,
7778
BIT_UVC_CMD_PIN_PAGE_SHARED = 21,
7879
BIT_UVC_CMD_UNPIN_PAGE_SHARED = 22,
80+
BIT_UVC_CMD_RETR_ATTEST = 28,
7981
};
8082

8183
enum uv_feat_ind {
@@ -219,6 +221,25 @@ struct uv_cb_share {
219221
u64 reserved28;
220222
} __packed __aligned(8);
221223

224+
/* Retrieve Attestation Measurement */
225+
struct uv_cb_attest {
226+
struct uv_cb_header header; /* 0x0000 */
227+
u64 reserved08[2]; /* 0x0008 */
228+
u64 arcb_addr; /* 0x0018 */
229+
u64 cont_token; /* 0x0020 */
230+
u8 reserved28[6]; /* 0x0028 */
231+
u16 user_data_len; /* 0x002e */
232+
u8 user_data[256]; /* 0x0030 */
233+
u32 reserved130[3]; /* 0x0130 */
234+
u32 meas_len; /* 0x013c */
235+
u64 meas_addr; /* 0x0140 */
236+
u8 config_uid[16]; /* 0x0148 */
237+
u32 reserved158; /* 0x0158 */
238+
u32 add_data_len; /* 0x015c */
239+
u64 add_data_addr; /* 0x0160 */
240+
u64 reserved168[4]; /* 0x0168 */
241+
} __packed __aligned(8);
242+
222243
static inline int __uv_call(unsigned long r1, unsigned long r2)
223244
{
224245
int cc;

arch/s390/include/uapi/asm/uvdevice.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+
/*
3+
* Copyright IBM Corp. 2022
4+
* Author(s): Steffen Eiden <[email protected]>
5+
*/
6+
#ifndef __S390_ASM_UVDEVICE_H
7+
#define __S390_ASM_UVDEVICE_H
8+
9+
#include <linux/types.h>
10+
11+
struct uvio_ioctl_cb {
12+
__u32 flags;
13+
__u16 uv_rc; /* UV header rc value */
14+
__u16 uv_rrc; /* UV header rrc value */
15+
__u64 argument_addr; /* Userspace address of uvio argument */
16+
__u32 argument_len;
17+
__u8 reserved14[0x40 - 0x14]; /* must be zero */
18+
};
19+
20+
#define UVIO_ATT_USER_DATA_LEN 0x100
21+
#define UVIO_ATT_UID_LEN 0x10
22+
struct uvio_attest {
23+
__u64 arcb_addr; /* 0x0000 */
24+
__u64 meas_addr; /* 0x0008 */
25+
__u64 add_data_addr; /* 0x0010 */
26+
__u8 user_data[UVIO_ATT_USER_DATA_LEN]; /* 0x0018 */
27+
__u8 config_uid[UVIO_ATT_UID_LEN]; /* 0x0118 */
28+
__u32 arcb_len; /* 0x0128 */
29+
__u32 meas_len; /* 0x012c */
30+
__u32 add_data_len; /* 0x0130 */
31+
__u16 user_data_len; /* 0x0134 */
32+
__u16 reserved136; /* 0x0136 */
33+
};
34+
35+
/*
36+
* The following max values define an upper length for the IOCTL in/out buffers.
37+
* However, they do not represent the maximum the Ultravisor allows which is
38+
* often way smaller. By allowing larger buffer sizes we hopefully do not need
39+
* to update the code with every machine update. It is therefore possible for
40+
* userspace to request more memory than actually used by kernel/UV.
41+
*/
42+
#define UVIO_ATT_ARCB_MAX_LEN 0x100000
43+
#define UVIO_ATT_MEASUREMENT_MAX_LEN 0x8000
44+
#define UVIO_ATT_ADDITIONAL_MAX_LEN 0x8000
45+
46+
#define UVIO_DEVICE_NAME "uv"
47+
#define UVIO_TYPE_UVC 'u'
48+
49+
#define UVIO_IOCTL_ATT _IOWR(UVIO_TYPE_UVC, 0x01, struct uvio_ioctl_cb)
50+
51+
#endif /* __S390_ASM_UVDEVICE_H */

arch/s390/kvm/gaccess.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ enum prot_type {
491491
PROT_TYPE_IEP = 4,
492492
};
493493

494-
static int trans_exc(struct kvm_vcpu *vcpu, int code, unsigned long gva,
495-
u8 ar, enum gacc_mode mode, enum prot_type prot)
494+
static int trans_exc_ending(struct kvm_vcpu *vcpu, int code, unsigned long gva, u8 ar,
495+
enum gacc_mode mode, enum prot_type prot, bool terminate)
496496
{
497497
struct kvm_s390_pgm_info *pgm = &vcpu->arch.pgm;
498498
struct trans_exc_code_bits *tec;
@@ -520,6 +520,11 @@ static int trans_exc(struct kvm_vcpu *vcpu, int code, unsigned long gva,
520520
tec->b61 = 1;
521521
break;
522522
}
523+
if (terminate) {
524+
tec->b56 = 0;
525+
tec->b60 = 0;
526+
tec->b61 = 0;
527+
}
523528
fallthrough;
524529
case PGM_ASCE_TYPE:
525530
case PGM_PAGE_TRANSLATION:
@@ -552,6 +557,12 @@ static int trans_exc(struct kvm_vcpu *vcpu, int code, unsigned long gva,
552557
return code;
553558
}
554559

560+
static int trans_exc(struct kvm_vcpu *vcpu, int code, unsigned long gva, u8 ar,
561+
enum gacc_mode mode, enum prot_type prot)
562+
{
563+
return trans_exc_ending(vcpu, code, gva, ar, mode, prot, false);
564+
}
565+
555566
static int get_vcpu_asce(struct kvm_vcpu *vcpu, union asce *asce,
556567
unsigned long ga, u8 ar, enum gacc_mode mode)
557568
{
@@ -1109,8 +1120,11 @@ int access_guest_with_key(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
11091120
data += fragment_len;
11101121
ga = kvm_s390_logical_to_effective(vcpu, ga + fragment_len);
11111122
}
1112-
if (rc > 0)
1113-
rc = trans_exc(vcpu, rc, ga, ar, mode, prot);
1123+
if (rc > 0) {
1124+
bool terminate = (mode == GACC_STORE) && (idx > 0);
1125+
1126+
rc = trans_exc_ending(vcpu, rc, ga, ar, mode, prot, terminate);
1127+
}
11141128
out_unlock:
11151129
if (need_ipte_lock)
11161130
ipte_unlock(vcpu);

drivers/s390/char/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ config SCLP_OFB
100100
This option enables the Open-for-Business interface to the s390
101101
Service Element.
102102

103+
config S390_UV_UAPI
104+
def_tristate m
105+
prompt "Ultravisor userspace API"
106+
help
107+
Selecting exposes parts of the UV interface to userspace
108+
by providing a misc character device at /dev/uv.
109+
Using IOCTLs one can interact with the UV.
110+
The device is only available if the Ultravisor
111+
Facility (158) is present.
112+
103113
config S390_TAPE
104114
def_tristate m
105115
prompt "S/390 tape device support"

drivers/s390/char/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ obj-$(CONFIG_MONREADER) += monreader.o
4848
obj-$(CONFIG_MONWRITER) += monwriter.o
4949
obj-$(CONFIG_S390_VMUR) += vmur.o
5050
obj-$(CONFIG_CRASH_DUMP) += sclp_sdias.o zcore.o
51+
obj-$(CONFIG_S390_UV_UAPI) += uvdevice.o
5152

5253
hmcdrv-objs := hmcdrv_mod.o hmcdrv_dev.o hmcdrv_ftp.o hmcdrv_cache.o diag_ftp.o sclp_ftp.o
5354
obj-$(CONFIG_HMC_DRV) += hmcdrv.o

0 commit comments

Comments
 (0)