Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: selftests: Implement ucall() for s390x

On s390x, we can neither exit via PIO nor MMIO, but have to use an
instruction like DIAGNOSE. Now that ucall() is implemented, we can
use it in the sync_reg_test on s390x, too.

Reviewed-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Link: https://lore.kernel.org/r/20190731151525.17156-3-thuth@redhat.com
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>

authored by

Thomas Huth and committed by
Christian Borntraeger
f90f57b3 2040f414

+61 -3
+1 -1
tools/testing/selftests/kvm/Makefile
··· 10 10 LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c 11 11 LIBKVM_x86_64 = lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/ucall.c 12 12 LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c 13 - LIBKVM_s390x = lib/s390x/processor.c 13 + LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c 14 14 15 15 TEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test 16 16 TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test
+56
tools/testing/selftests/kvm/lib/s390x/ucall.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * ucall support. A ucall is a "hypercall to userspace". 4 + * 5 + * Copyright (C) 2019 Red Hat, Inc. 6 + */ 7 + #include "kvm_util.h" 8 + 9 + void ucall_init(struct kvm_vm *vm, void *arg) 10 + { 11 + } 12 + 13 + void ucall_uninit(struct kvm_vm *vm) 14 + { 15 + } 16 + 17 + void ucall(uint64_t cmd, int nargs, ...) 18 + { 19 + struct ucall uc = { 20 + .cmd = cmd, 21 + }; 22 + va_list va; 23 + int i; 24 + 25 + nargs = nargs <= UCALL_MAX_ARGS ? nargs : UCALL_MAX_ARGS; 26 + 27 + va_start(va, nargs); 28 + for (i = 0; i < nargs; ++i) 29 + uc.args[i] = va_arg(va, uint64_t); 30 + va_end(va); 31 + 32 + /* Exit via DIAGNOSE 0x501 (normally used for breakpoints) */ 33 + asm volatile ("diag 0,%0,0x501" : : "a"(&uc) : "memory"); 34 + } 35 + 36 + uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc) 37 + { 38 + struct kvm_run *run = vcpu_state(vm, vcpu_id); 39 + struct ucall ucall = {}; 40 + 41 + if (run->exit_reason == KVM_EXIT_S390_SIEIC && 42 + run->s390_sieic.icptcode == 4 && 43 + (run->s390_sieic.ipa >> 8) == 0x83 && /* 0x83 means DIAGNOSE */ 44 + (run->s390_sieic.ipb >> 16) == 0x501) { 45 + int reg = run->s390_sieic.ipa & 0xf; 46 + 47 + memcpy(&ucall, addr_gva2hva(vm, run->s.regs.gprs[reg]), 48 + sizeof(ucall)); 49 + 50 + vcpu_run_complete_io(vm, vcpu_id); 51 + if (uc) 52 + memcpy(uc, &ucall, sizeof(ucall)); 53 + } 54 + 55 + return ucall.cmd; 56 + }
+4 -2
tools/testing/selftests/kvm/s390x/sync_regs_test.c
··· 25 25 26 26 static void guest_code(void) 27 27 { 28 + register u64 stage asm("11") = 0; 29 + 28 30 for (;;) { 29 - asm volatile ("diag 0,0,0x501"); 30 - asm volatile ("ahi 11,1"); 31 + GUEST_SYNC(0); 32 + asm volatile ("ahi %0,1" : : "r"(stage)); 31 33 } 32 34 } 33 35