]> Git Repo - qemu.git/blame - hw/s390x/pv.c
qcow2.py: add licensing blurb
[qemu.git] / hw / s390x / pv.c
CommitLineData
c3347ed0
JF
1/*
2 * Protected Virtualization functions
3 *
4 * Copyright IBM Corp. 2020
5 * Author(s):
6 * Janosch Frank <[email protected]>
7 *
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
10 * directory.
11 */
12#include "qemu/osdep.h"
13
14#include <linux/kvm.h>
15
fbc1384c 16#include "cpu.h"
c3347ed0
JF
17#include "qemu/error-report.h"
18#include "sysemu/kvm.h"
fbc1384c 19#include "hw/s390x/ipl.h"
c3347ed0
JF
20#include "hw/s390x/pv.h"
21
22static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data)
23{
24 struct kvm_pv_cmd pv_cmd = {
25 .cmd = cmd,
26 .data = (uint64_t)data,
27 };
e8d12a55
CB
28 int rc;
29
30 do {
31 rc = kvm_vm_ioctl(kvm_state, KVM_S390_PV_COMMAND, &pv_cmd);
32 } while (rc == -EINTR);
c3347ed0
JF
33
34 if (rc) {
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,
37 rc);
38 }
39 return rc;
40}
41
42/*
43 * This macro lets us pass the command as a string to the function so
44 * we can print it on an error.
45 */
46#define s390_pv_cmd(cmd, data) __s390_pv_cmd(cmd, #cmd, data);
47#define s390_pv_cmd_exit(cmd, data) \
48{ \
49 int rc; \
50 \
51 rc = __s390_pv_cmd(cmd, #cmd, data);\
52 if (rc) { \
53 exit(1); \
54 } \
55}
56
57int s390_pv_vm_enable(void)
58{
59 return s390_pv_cmd(KVM_PV_ENABLE, NULL);
60}
61
62void s390_pv_vm_disable(void)
63{
64 s390_pv_cmd_exit(KVM_PV_DISABLE, NULL);
65}
66
67int s390_pv_set_sec_parms(uint64_t origin, uint64_t length)
68{
69 struct kvm_s390_pv_sec_parm args = {
70 .origin = origin,
71 .length = length,
72 };
73
74 return s390_pv_cmd(KVM_PV_SET_SEC_PARMS, &args);
75}
76
77/*
78 * Called for each component in the SE type IPL parameter block 0.
79 */
80int s390_pv_unpack(uint64_t addr, uint64_t size, uint64_t tweak)
81{
82 struct kvm_s390_pv_unp args = {
83 .addr = addr,
84 .size = size,
85 .tweak = tweak,
86 };
87
88 return s390_pv_cmd(KVM_PV_UNPACK, &args);
89}
90
9a432597 91void s390_pv_prep_reset(void)
c3347ed0
JF
92{
93 s390_pv_cmd_exit(KVM_PV_PREP_RESET, NULL);
94}
95
96int s390_pv_verify(void)
97{
98 return s390_pv_cmd(KVM_PV_VERIFY, NULL);
99}
100
101void s390_pv_unshare(void)
102{
103 s390_pv_cmd_exit(KVM_PV_UNSHARE_ALL, NULL);
104}
fbc1384c
CB
105
106void s390_pv_inject_reset_error(CPUState *cs)
107{
108 int r1 = (cs->kvm_run->s390_sieic.ipa & 0x00f0) >> 4;
109 CPUS390XState *env = &S390_CPU(cs)->env;
110
111 /* Report that we are unable to enter protected mode */
112 env->regs[r1 + 1] = DIAG_308_RC_INVAL_FOR_PV;
113}
This page took 0.03999 seconds and 4 git commands to generate.