KVM: s390: Fix and feature for 5.19
Subsystems (5)
Christian Borntraeger
maintainerPaolo,
only a small set of changes and sorry for the late pull. If Greg asks, the ultravisor device driver has userspace code that is acked by the s390 tools maintainer and will follow after the driver hits the kernel.
The following changes since commit ce522ba9ef7e2d9fb22a39eb3371c0c64e2a433e:
Linux 5.18-rc2 (2022-04-10 14:21:36 -1000)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-next-5.19-1
for you to fetch changes up to c71159648c3cf0f7127ddc0bdf3eb4d7885210df:
KVM: s390: selftest: Test suppression indication on key prot exception (2022-05-20 16:38:42 +0200)
----------------------------------------------------------------
KVM: s390: Fix and feature for 5.19
- ultravisor communication device driver
- fix TEID on terminating storage key ops
----------------------------------------------------------------
Janis Schoetterl-Glausch (2):
KVM: s390: Don't indicate suppression on dirtying, failing memop
KVM: s390: selftest: Test suppression indication on key prot exception
Steffen Eiden (2):
drivers/s390/char: Add Ultravisor io device
selftests: drivers/s390x: Add uvdevice tests
Documentation/virt/kvm/api.rst | 6 + MAINTAINERS | 3 + arch/s390/include/asm/uv.h | 23 +- arch/s390/include/uapi/asm/uvdevice.h | 51 ++++ arch/s390/kvm/gaccess.c | 22 +- drivers/s390/char/Kconfig | 10 + drivers/s390/char/Makefile | 1 + drivers/s390/char/uvdevice.c | 257 +++++++++++++++++++ tools/testing/selftests/Makefile | 1 + tools/testing/selftests/drivers/.gitignore | 1 + .../selftests/drivers/s390x/uvdevice/Makefile | 22 ++ .../selftests/drivers/s390x/uvdevice/config | 1 + .../drivers/s390x/uvdevice/test_uvdevice.c | 276 +++++++++++++++++++++ tools/testing/selftests/kvm/s390x/memop.c | 46 +++- 14 files changed, 714 insertions(+), 6 deletions(-) create mode 100644 arch/s390/include/uapi/asm/uvdevice.h create mode 100644 drivers/s390/char/uvdevice.c create mode 100644 tools/testing/selftests/drivers/s390x/uvdevice/Makefile create mode 100644 tools/testing/selftests/drivers/s390x/uvdevice/config create mode 100644 tools/testing/selftests/drivers/s390x/uvdevice/test_uvdevice.c
Christian Borntraeger
maintainer[GIT PULL 1/4] drivers/s390/char: Add Ultravisor io device
From: Steffen Eiden <[email protected]>
This patch adds a new miscdevice to expose some Ultravisor functions to userspace. Userspace can send IOCTLs to the uvdevice that will then emit a corresponding Ultravisor Call and hands the result over to userspace. The uvdevice is available if the Ultravisor Call facility is present.
Userspace can call the Retrieve Attestation Measurement Ultravisor Call using IOCTLs on the uvdevice.
The uvdevice will do some sanity checks first. Then, copy the request data to kernel space, build the UVCB, perform the UV call, and copy the result back to userspace.
Message-Id: <[email protected]>
--- MAINTAINERS | 2 + arch/s390/include/asm/uv.h | 23 ++- arch/s390/include/uapi/asm/uvdevice.h | 51 +++++ drivers/s390/char/Kconfig | 10 + drivers/s390/char/Makefile | 1 + drivers/s390/char/uvdevice.c | 257 ++++++++++++++++++++++++++ 6 files changed, 343 insertions(+), 1 deletion(-) create mode 100644 arch/s390/include/uapi/asm/uvdevice.h create mode 100644 drivers/s390/char/uvdevice.c
MAINTAINERS +2 -0
@@ -10779,9 +10779,11 @@ F: Documentation/virt/kvm/s390* F: arch/s390/include/asm/gmap.h F: arch/s390/include/asm/kvm* F: arch/s390/include/uapi/asm/kvm* +F: arch/s390/include/uapi/asm/uvdevice.h F: arch/s390/kernel/uv.c F: arch/s390/kvm/ F: arch/s390/mm/gmap.c +F: drivers/s390/char/uvdevice.c F: tools/testing/selftests/kvm/*/s390x/ F: tools/testing/selftests/kvm/s390x/
arch/s390/include/asm/uv.h +22 -1
@@ -2,7 +2,7 @@/* * Ultravisor Interfaces * -* Copyright IBM Corp. 2019 +* Copyright IBM Corp. 2019, 2022 * * Author(s): * Vasily Gorbik <[email protected]>
@@ -52,6 +52,7 @@#define UVC_CMD_UNPIN_PAGE_SHARED 0x0342#define UVC_CMD_SET_SHARED_ACCESS 0x1000#define UVC_CMD_REMOVE_SHARED_ACCESS 0x1001 +#define UVC_CMD_RETR_ATTEST 0x1020/* Bits in installed uv calls */ enum uv_cmds_inst {
@@ -76,6 +77,7 @@ enum uv_cmds_inst {BIT_UVC_CMD_UNSHARE_ALL =20 ,BIT_UVC_CMD_PIN_PAGE_SHARED =21 ,BIT_UVC_CMD_UNPIN_PAGE_SHARED =22 , + BIT_UVC_CMD_RETR_ATTEST = 28, }; enum uv_feat_ind {
@@ -219,6 +221,25 @@ struct uv_cb_share {u64 reserved28; } __packed__aligned(8) ; +/* Retrieve Attestation Measurement */ +struct uv_cb_attest { +struct uv_cb_header header;/* 0x0000 */ +u64 reserved08[2 ];/* 0x0008 */ +u64 arcb_addr;/* 0x0018 */ +u64 cont_token;/* 0x0020 */ +u8 reserved28[6 ];/* 0x0028 */ +u16 user_data_len;/* 0x002e */ +u8 user_data[256 ];/* 0x0030 */ +u32 reserved130[3 ];/* 0x0130 */ +u32 meas_len;/* 0x013c */ +u64 meas_addr;/* 0x0140 */ +u8 config_uid[16 ];/* 0x0148 */ +u32 reserved158;/* 0x0158 */ +u32 add_data_len;/* 0x015c */ +u64 add_data_addr;/* 0x0160 */ +u64 reserved168[4 ];/* 0x0168 */ +} __packed__aligned(8) ; +static inline int __uv_call (unsigned long r1,unsigned long r2) {int cc;
arch/s390/include/uapi/asm/uvdevice.h new file +51 -0
51 lines not on this page · raw message
drivers/s390/char/Kconfig +10 -0
@@ -100,6 +100,16 @@ config SCLP_OFB This option enables the Open-for-Business interface to the s390 Service Element. +config S390_UV_UAPI + def_tristate m + prompt "Ultravisor userspace API" + help + Selecting exposes parts of the UV interface to userspace + by providing a misc character device at /dev/uv. + Using IOCTLs one can interact with the UV. + The device is only available if the Ultravisor + Facility (158) is present. + config S390_TAPE def_tristate m prompt "S/390 tape device support"
drivers/s390/char/Makefile +1 -0
@@ -48,6 +48,7 @@ obj-$(CONFIG_MONREADER) += monreader.o obj-$(CONFIG_MONWRITER) += monwriter.o obj-$(CONFIG_S390_VMUR) += vmur.o obj-$(CONFIG_CRASH_DUMP) += sclp_sdias.o zcore.o +obj-$(CONFIG_S390_UV_UAPI) += uvdevice.o hmcdrv-objs := hmcdrv_mod.o hmcdrv_dev.o hmcdrv_ftp.o hmcdrv_cache.o diag_ftp.o sclp_ftp.o obj-$(CONFIG_HMC_DRV) += hmcdrv.o
drivers/s390/char/uvdevice.c new file +257 -0
257 lines not on this page · raw message
Signature · 1 line
2.35.1
Christian Borntraeger
maintainer[GIT PULL 3/4] KVM: s390: Don't indicate suppression on dirtying, failing memop
In reply to Christian BorntraegerFrom: Janis Schoetterl-Glausch <[email protected]>
If user space uses a memop to emulate an instruction and that memop fails, the execution of the instruction ends. Instruction execution can end in different ways, one of which is suppression, which requires that the instruction execute like a no-op. A writing memop that spans multiple pages and fails due to key protection may have modified guest memory, as a result, the likely correct ending is termination. Therefore, do not indicate a suppressing instruction ending in this case.
--- Documentation/virt/kvm/api.rst | 6 ++++++ arch/s390/kvm/gaccess.c | 22 ++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-)
Documentation/virt/kvm/api.rst +6 -0
@@ -3754,12 +3754,18 @@ in case of KVM_S390_MEMOP_F_CHECK_ONLY), the ioctl returns a positive error number indicating the type of exception. This exception is also raised directly at the corresponding VCPU if the flag KVM_S390_MEMOP_F_INJECT_EXCEPTION is set. +On protection exceptions, unless specified otherwise, the injected +translation-exception identifier (TEID) indicates suppression. If the KVM_S390_MEMOP_F_SKEY_PROTECTION flag is set, storage key protection is also in effect and may cause exceptions if accesses are prohibited given the access key designated by "key"; the valid range is 0..15. KVM_S390_MEMOP_F_SKEY_PROTECTION is available if KVM_CAP_S390_MEM_OP_EXTENSION is > 0. +Since the accessed memory may span multiple pages and those pages might have +different storage keys, it is possible that a protection exception occurs +after memory has been modified. In this case, if the exception is injected, +the TEID does not indicate suppression. Absolute read/write: ^^^^^^^^^^^^^^^^^^^^
arch/s390/kvm/gaccess.c +18 -4
@@ -491,8 +491,8 @@ enum prot_type { PROT_TYPE_IEP = 4, }; -static int trans_exc (struct kvm_vcpu *vcpu,int code,unsigned long gva, -u8 ar,enum gacc_mode mode,enum prot_type prot) +static int trans_exc_ending (struct kvm_vcpu *vcpu,int code,unsigned long gva,u8 ar, +enum gacc_mode mode,enum prot_type prot,bool terminate) {struct kvm_s390_pgm_info *pgm = &vcpu->arch.pgm;struct trans_exc_code_bits *tec;
@@ -520,6 +520,11 @@ static int trans_exc(struct kvm_vcpu *vcpu, int code, unsigned long gva, tec->b61 =1 ;break ; } +if (terminate) { + tec->b56 =0 ; + tec->b60 =0 ; + tec->b61 =0 ; + } fallthrough;case PGM_ASCE_TYPE :case PGM_PAGE_TRANSLATION :
@@ -552,6 +557,12 @@ static int trans_exc(struct kvm_vcpu *vcpu, int code, unsigned long gva,return code; } +static int trans_exc (struct kvm_vcpu *vcpu,int code,unsigned long gva,u8 ar, +enum gacc_mode mode,enum prot_type prot) +{ +return trans_exc_ending (vcpu, code, gva, ar, mode, prot, false); +} +static int get_vcpu_asce (struct kvm_vcpu *vcpu,union asce *asce,unsigned long ga,u8 ar,enum gacc_mode mode) {
@@ -1109,8 +1120,11 @@ int access_guest_with_key(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar, data += fragment_len; ga =kvm_s390_logical_to_effective (vcpu, ga + fragment_len); } -if (rc >0 ) - rc =trans_exc (vcpu, rc, ga, ar, mode, prot); +if (rc >0 ) { +bool terminate = (mode ==GACC_STORE ) && (idx >0 ); + + rc =trans_exc_ending (vcpu, rc, ga, ar, mode, prot, terminate); + } out_unlock:if (need_ipte_lock)ipte_unlock (vcpu);
Signature · 1 line
2.35.1
Christian Borntraeger
maintainer[GIT PULL 4/4] KVM: s390: selftest: Test suppression indication on key prot exception
In reply to Christian BorntraegerFrom: Janis Schoetterl-Glausch <[email protected]>
Check that suppression is not indicated on injection of a key checked protection exception caused by a memop after it already modified guest memory, as that violates the definition of suppression.
--- tools/testing/selftests/kvm/s390x/memop.c | 46 ++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/s390x/memop.c +45 -1
@@ -10,6 +10,8 @@#include <string.h> #include <sys/ioctl.h> +#include <linux/bits.h> +#include "test_util.h" #include "kvm_util.h"
@@ -194,6 +196,7 @@ static int err_memop_ioctl(struct test_vcpu vcpu, struct kvm_s390_mem_op *ksmo)#define SIDA_OFFSET (o) ._sida_offset = 1, .sida_offset = (o)#define AR (a) ._ar = 1, .ar = (a)#define KEY (a) .f_key = 1, .key = (a) +#define INJECT .f_inject = 1#define CHECK_N_DO (f, ...) ({ f(__VA_ARGS__, CHECK_ONLY); f(__VA_ARGS__); })
@@ -430,9 +433,18 @@ static void test_copy_key_fetch_prot(void)TEST_ASSERT (rv ==4 ,"Should result in protection exception" ); \ }) +static void guest_error_key (void ) +{ +GUEST_SYNC (STAGE_INITED ); +set_storage_key_range (mem1,PAGE_SIZE ,0x18 ); +set_storage_key_range (mem1 +PAGE_SIZE ,sizeof (mem1) -PAGE_SIZE ,0x98 ); +GUEST_SYNC (STAGE_SKEYS_SET ); +GUEST_SYNC (STAGE_IDLED ); +} +static void test_errors_key (void ) { -struct test_default t =test_default_init (guest_copy_key_fetch_prot); +struct test_default t =test_default_init (guest_error_key);HOST_SYNC (t.vcpu,STAGE_INITED );HOST_SYNC (t.vcpu,STAGE_SKEYS_SET );
@@ -446,6 +458,37 @@ static void test_errors_key(void)kvm_vm_free (t.kvm_vm); } +static void test_termination (void ) +{ +struct test_default t =test_default_init (guest_error_key); +uint64_t prefix; +uint64_t teid; +uint64_t teid_mask =BIT (63 -56 ) |BIT (63 -60 ) |BIT (63 -61 ); +uint64_t psw[2 ]; + +HOST_SYNC (t.vcpu,STAGE_INITED ); +HOST_SYNC (t.vcpu,STAGE_SKEYS_SET ); + +/* vcpu, mismatching keys after first page */ +ERR_PROT_MOP (t.vcpu,LOGICAL ,WRITE , mem1, t.size,GADDR_V (mem1),KEY (1 ),INJECT ); +/* +* The memop injected a program exception and the test needs to check the +* Translation-Exception Identification (TEID). It is necessary to run +* the guest in order to be able to read the TEID from guest memory. +* Set the guest program new PSW, so the guest state is not clobbered. +*/ + prefix = t.run->s.regs.prefix; + psw[0 ] = t.run->psw_mask; + psw[1 ] = t.run->psw_addr; +MOP (t.vm,ABSOLUTE ,WRITE , psw,sizeof (psw),GADDR (prefix +464 )); +HOST_SYNC (t.vcpu,STAGE_IDLED ); +MOP (t.vm,ABSOLUTE ,READ , &teid,sizeof (teid),GADDR (prefix +168 )); +/* Bits 56, 60, 61 form a code, 0 being the only one allowing for termination */ +ASSERT_EQ (teid & teid_mask,0 ); + +kvm_vm_free (t.kvm_vm); +} +static void test_errors_key_storage_prot_override (void ) {struct test_default t =test_default_init (guest_copy_key_fetch_prot);
@@ -668,6 +711,7 @@ int main(int argc, char *argv[])test_copy_key_fetch_prot ();test_copy_key_fetch_prot_override ();test_errors_key (); +test_termination ();test_errors_key_storage_prot_override ();test_errors_key_fetch_prot_override_not_enabled ();test_errors_key_fetch_prot_override_enabled ();
Signature · 1 line
2.35.1
Christian Borntraeger
maintainer[GIT PULL 2/4] selftests: drivers/s390x: Add uvdevice tests
In reply to Christian BorntraegerFrom: Steffen Eiden <[email protected]>
Adds some selftests to test ioctl error paths of the uv-uapi. The Kconfig S390_UV_UAPI must be selected and the Ultravisor facility must be available. The test can be executed by non-root, however, the uvdevice special file /dev/uv must be accessible for reading and writing which may imply root privileges.
./test-uv-device
TAP version 13
1..6
# Starting 6 tests from 3 test cases.
# RUN uvio_fixture.att.fault_ioctl_arg ...
# OK uvio_fixture.att.fault_ioctl_arg
ok 1 uvio_fixture.att.fault_ioctl_arg
# RUN uvio_fixture.att.fault_uvio_arg ...
# OK uvio_fixture.att.fault_uvio_arg
ok 2 uvio_fixture.att.fault_uvio_arg
# RUN uvio_fixture.att.inval_ioctl_cb ...
# OK uvio_fixture.att.inval_ioctl_cb
ok 3 uvio_fixture.att.inval_ioctl_cb
# RUN uvio_fixture.att.inval_ioctl_cmd ...
# OK uvio_fixture.att.inval_ioctl_cmd
ok 4 uvio_fixture.att.inval_ioctl_cmd
# RUN attest_fixture.att_inval_request ...
# OK attest_fixture.att_inval_request
ok 5 attest_fixture.att_inval_request
# RUN attest_fixture.att_inval_addr ...
# OK attest_fixture.att_inval_addr
ok 6 attest_fixture.att_inval_addr
# PASSED: 6 / 6 tests passed.
# Totals: pass:6 fail:0 xfail:0 xpass:0 skip:0 error:0
Message-Id: <[email protected]>
--- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/drivers/.gitignore | 1 + .../selftests/drivers/s390x/uvdevice/Makefile | 22 ++ .../selftests/drivers/s390x/uvdevice/config | 1 + .../drivers/s390x/uvdevice/test_uvdevice.c | 276 ++++++++++++++++++ 6 files changed, 302 insertions(+) create mode 100644 tools/testing/selftests/drivers/s390x/uvdevice/Makefile create mode 100644 tools/testing/selftests/drivers/s390x/uvdevice/config create mode 100644 tools/testing/selftests/drivers/s390x/uvdevice/test_uvdevice.c
MAINTAINERS +1 -0
@@ -10784,6 +10784,7 @@ F: arch/s390/kernel/uv.c F: arch/s390/kvm/ F: arch/s390/mm/gmap.c F: drivers/s390/char/uvdevice.c +F: tools/testing/selftests/drivers/s390x/uvdevice/ F: tools/testing/selftests/kvm/*/s390x/ F: tools/testing/selftests/kvm/s390x/
tools/testing/selftests/Makefile +1 -0
@@ -10,6 +10,7 @@ TARGETS += core TARGETS += cpufreq TARGETS += cpu-hotplug TARGETS += drivers/dma-buf +TARGETS += drivers/s390x/uvdevice TARGETS += efivarfs TARGETS += exec TARGETS += filesystems
tools/testing/selftests/drivers/.gitignore +1 -0
@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only /dma-buf/udmabuf +/s390x/uvdevice/test_uvdevice
tools/testing/selftests/drivers/s390x/uvdevice/Makefile new file +22 -0
@@ -0,0 +1,22 @@ +include ../../../../../build/Build.include + +UNAME_M := $(shell uname -m) + +ifneq ($(UNAME_M),s390x) +nothing: +.PHONY: all clean run_tests install +.SILENT: +else + +TEST_GEN_PROGS := test_uvdevice + +top_srcdir ?= ../../../../../.. +KSFT_KHDR_INSTALL := 1 +khdr_dir = $(top_srcdir)/usr/include +LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include + +CFLAGS += -Wall -Werror -static -I$(khdr_dir) -I$(LINUX_TOOL_ARCH_INCLUDE) + +include ../../../lib.mk + +endif
tools/testing/selftests/drivers/s390x/uvdevice/config new file +1 -0
@@ -0,0 +1 @@ +CONFIG_S390_UV_UAPI=y
tools/testing/selftests/drivers/s390x/uvdevice/test_uvdevice.c new file +276 -0
276 lines not on this page · raw message
Signature · 1 line
2.35.1
Paolo Bonzini
maintainerQuoted 1 line · Christian Borntraeger
git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-next-5.19-1
Pulled, thanks.
Paolo