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_arch_init(struct kvm_vm *vm, void *arg)
10 {
11 }
12 
13 void ucall_arch_uninit(struct kvm_vm *vm)
14 {
15 }
16 
17 void ucall_arch_do_ucall(vm_vaddr_t uc)
18 {
19 	/* Exit via DIAGNOSE 0x501 (normally used for breakpoints) */
20 	asm volatile ("diag 0,%0,0x501" : : "a"(uc) : "memory");
21 }
22 
23 void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu)
24 {
25 	struct kvm_run *run = vcpu->run;
26 
27 	if (run->exit_reason == KVM_EXIT_S390_SIEIC &&
28 	    run->s390_sieic.icptcode == 4 &&
29 	    (run->s390_sieic.ipa >> 8) == 0x83 &&    /* 0x83 means DIAGNOSE */
30 	    (run->s390_sieic.ipb >> 16) == 0x501) {
31 		int reg = run->s390_sieic.ipa & 0xf;
32 
33 		return addr_gva2hva(vcpu->vm, run->s.regs.gprs[reg]);
34 	}
35 	return NULL;
36 }
37