2 * Protected Virtualization functions
4 * Copyright IBM Corp. 2020
6 * Janosch Frank <frankja@linux.ibm.com>
8 * This work is licensed under the terms of the GNU GPL, version 2 or (at
9 * your option) any later version. See the COPYING file in the top-level
12 #include "qemu/osdep.h"
14 #include <linux/kvm.h>
17 #include "qemu/error-report.h"
18 #include "sysemu/kvm.h"
19 #include "hw/s390x/ipl.h"
20 #include "hw/s390x/pv.h"
22 static int __s390_pv_cmd(uint32_t cmd
, const char *cmdname
, void *data
)
24 struct kvm_pv_cmd pv_cmd
= {
26 .data
= (uint64_t)data
,
31 rc
= kvm_vm_ioctl(kvm_state
, KVM_S390_PV_COMMAND
, &pv_cmd
);
32 } while (rc
== -EINTR
);
35 error_report("KVM PV command %d (%s) failed: header rc %x rrc %x "
36 "IOCTL rc: %d", cmd
, cmdname
, pv_cmd
.rc
, pv_cmd
.rrc
,
43 * This macro lets us pass the command as a string to the function so
44 * we can print it on an error.
46 #define s390_pv_cmd(cmd, data) __s390_pv_cmd(cmd, #cmd, data);
47 #define s390_pv_cmd_exit(cmd, data) \
51 rc = __s390_pv_cmd(cmd, #cmd, data);\
57 int s390_pv_vm_enable(void)
59 return s390_pv_cmd(KVM_PV_ENABLE
, NULL
);
62 void s390_pv_vm_disable(void)
64 s390_pv_cmd_exit(KVM_PV_DISABLE
, NULL
);
67 int s390_pv_set_sec_parms(uint64_t origin
, uint64_t length
)
69 struct kvm_s390_pv_sec_parm args
= {
74 return s390_pv_cmd(KVM_PV_SET_SEC_PARMS
, &args
);
78 * Called for each component in the SE type IPL parameter block 0.
80 int s390_pv_unpack(uint64_t addr
, uint64_t size
, uint64_t tweak
)
82 struct kvm_s390_pv_unp args
= {
88 return s390_pv_cmd(KVM_PV_UNPACK
, &args
);
91 void s390_pv_prep_reset(void)
93 s390_pv_cmd_exit(KVM_PV_PREP_RESET
, NULL
);
96 int s390_pv_verify(void)
98 return s390_pv_cmd(KVM_PV_VERIFY
, NULL
);
101 void s390_pv_unshare(void)
103 s390_pv_cmd_exit(KVM_PV_UNSHARE_ALL
, NULL
);
106 void s390_pv_inject_reset_error(CPUState
*cs
)
108 int r1
= (cs
->kvm_run
->s390_sieic
.ipa
& 0x00f0) >> 4;
109 CPUS390XState
*env
= &S390_CPU(cs
)->env
;
111 /* Report that we are unable to enter protected mode */
112 env
->regs
[r1
+ 1] = DIAG_308_RC_INVAL_FOR_PV
;