KVM: s390: get rid of constant condition in ipte_unlock_simple
[deliverable/linux.git] / arch / s390 / kvm / diag.c
CommitLineData
e28acfea 1/*
a53c8fab 2 * handling diagnose instructions
e28acfea 3 *
a53c8fab 4 * Copyright IBM Corp. 2008, 2011
e28acfea
CB
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License (version 2 only)
8 * as published by the Free Software Foundation.
9 *
10 * Author(s): Carsten Otte <cotte@de.ibm.com>
11 * Christian Borntraeger <borntraeger@de.ibm.com>
12 */
13
14#include <linux/kvm.h>
15#include <linux/kvm_host.h>
deedabb2 16#include <asm/pgalloc.h>
10ccaa1e 17#include <asm/virtio-ccw.h>
e28acfea 18#include "kvm-s390.h"
5786fffa 19#include "trace.h"
ade38c31 20#include "trace-s390.h"
3c038e6b 21#include "gaccess.h"
e28acfea 22
388186bc
CB
23static int diag_release_pages(struct kvm_vcpu *vcpu)
24{
25 unsigned long start, end;
fda902cb 26 unsigned long prefix = kvm_s390_get_prefix(vcpu);
388186bc 27
5a32c1af
CB
28 start = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4];
29 end = vcpu->run->s.regs.gprs[vcpu->arch.sie_block->ipa & 0xf] + 4096;
388186bc
CB
30
31 if (start & ~PAGE_MASK || end & ~PAGE_MASK || start > end
32 || start < 2 * PAGE_SIZE)
33 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
34
35 VCPU_EVENT(vcpu, 5, "diag release pages %lX %lX", start, end);
36 vcpu->stat.diagnose_10++;
37
38 /* we checked for start > end above */
39 if (end < prefix || start >= prefix + 2 * PAGE_SIZE) {
6e0a0431 40 gmap_discard(vcpu->arch.gmap, start, end);
388186bc
CB
41 } else {
42 if (start < prefix)
6e0a0431 43 gmap_discard(vcpu->arch.gmap, start, prefix);
388186bc 44 if (end >= prefix)
6e0a0431
MS
45 gmap_discard(vcpu->arch.gmap,
46 prefix + 2 * PAGE_SIZE, end);
388186bc
CB
47 }
48 return 0;
49}
50
3c038e6b
DD
51static int __diag_page_ref_service(struct kvm_vcpu *vcpu)
52{
53 struct prs_parm {
54 u16 code;
55 u16 subcode;
56 u16 parm_len;
57 u16 parm_version;
58 u64 token_addr;
59 u64 select_mask;
60 u64 compare_mask;
61 u64 zarch;
62 };
63 struct prs_parm parm;
64 int rc;
65 u16 rx = (vcpu->arch.sie_block->ipa & 0xf0) >> 4;
66 u16 ry = (vcpu->arch.sie_block->ipa & 0x0f);
3c038e6b
DD
67
68 if (vcpu->run->s.regs.gprs[rx] & 7)
69 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
81480cc1
HC
70 rc = read_guest(vcpu, vcpu->run->s.regs.gprs[rx], &parm, sizeof(parm));
71 if (rc)
72 return kvm_s390_inject_prog_cond(vcpu, rc);
3c038e6b
DD
73 if (parm.parm_version != 2 || parm.parm_len < 5 || parm.code != 0x258)
74 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
75
76 switch (parm.subcode) {
77 case 0: /* TOKEN */
78 if (vcpu->arch.pfault_token != KVM_S390_PFAULT_TOKEN_INVALID) {
79 /*
80 * If the pagefault handshake is already activated,
81 * the token must not be changed. We have to return
82 * decimal 8 instead, as mandated in SC24-6084.
83 */
84 vcpu->run->s.regs.gprs[ry] = 8;
85 return 0;
86 }
87
88 if ((parm.compare_mask & parm.select_mask) != parm.compare_mask ||
89 parm.token_addr & 7 || parm.zarch != 0x8000000000000000ULL)
90 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
91
81480cc1 92 if (kvm_is_error_gpa(vcpu->kvm, parm.token_addr))
3c038e6b
DD
93 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
94
95 vcpu->arch.pfault_token = parm.token_addr;
96 vcpu->arch.pfault_select = parm.select_mask;
97 vcpu->arch.pfault_compare = parm.compare_mask;
98 vcpu->run->s.regs.gprs[ry] = 0;
99 rc = 0;
100 break;
101 case 1: /*
102 * CANCEL
103 * Specification allows to let already pending tokens survive
104 * the cancel, therefore to reduce code complexity, we assume
105 * all outstanding tokens are already pending.
106 */
107 if (parm.token_addr || parm.select_mask ||
108 parm.compare_mask || parm.zarch)
109 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
110
111 vcpu->run->s.regs.gprs[ry] = 0;
112 /*
113 * If the pfault handling was not established or is already
114 * canceled SC24-6084 requests to return decimal 4.
115 */
116 if (vcpu->arch.pfault_token == KVM_S390_PFAULT_TOKEN_INVALID)
117 vcpu->run->s.regs.gprs[ry] = 4;
118 else
119 vcpu->arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID;
120
121 rc = 0;
122 break;
123 default:
124 rc = -EOPNOTSUPP;
125 break;
126 }
127
128 return rc;
129}
130
e28acfea
CB
131static int __diag_time_slice_end(struct kvm_vcpu *vcpu)
132{
133 VCPU_EVENT(vcpu, 5, "%s", "diag time slice end");
134 vcpu->stat.diagnose_44++;
8733ac36 135 kvm_vcpu_on_spin(vcpu);
e28acfea
CB
136 return 0;
137}
138
41628d33
KW
139static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
140{
141 struct kvm *kvm = vcpu->kvm;
142 struct kvm_vcpu *tcpu;
143 int tid;
144 int i;
145
146 tid = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4];
147 vcpu->stat.diagnose_9c++;
148 VCPU_EVENT(vcpu, 5, "diag time slice end directed to %d", tid);
149
150 if (tid == vcpu->vcpu_id)
151 return 0;
152
153 kvm_for_each_vcpu(i, tcpu, kvm)
154 if (tcpu->vcpu_id == tid) {
155 kvm_vcpu_yield_to(tcpu);
156 break;
157 }
158
159 return 0;
160}
161
e28acfea
CB
162static int __diag_ipl_functions(struct kvm_vcpu *vcpu)
163{
164 unsigned int reg = vcpu->arch.sie_block->ipa & 0xf;
5a32c1af 165 unsigned long subcode = vcpu->run->s.regs.gprs[reg] & 0xffff;
e28acfea
CB
166
167 VCPU_EVENT(vcpu, 5, "diag ipl functions, subcode %lx", subcode);
168 switch (subcode) {
169 case 3:
170 vcpu->run->s390_reset_flags = KVM_S390_RESET_CLEAR;
171 break;
172 case 4:
173 vcpu->run->s390_reset_flags = 0;
174 break;
175 default:
b8e660b8 176 return -EOPNOTSUPP;
e28acfea
CB
177 }
178
6352e4d2
DH
179 if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm))
180 kvm_s390_vcpu_stop(vcpu);
e28acfea
CB
181 vcpu->run->s390_reset_flags |= KVM_S390_RESET_SUBSYSTEM;
182 vcpu->run->s390_reset_flags |= KVM_S390_RESET_IPL;
183 vcpu->run->s390_reset_flags |= KVM_S390_RESET_CPU_INIT;
184 vcpu->run->exit_reason = KVM_EXIT_S390_RESET;
33e19115 185 VCPU_EVENT(vcpu, 3, "requesting userspace resets %llx",
e28acfea 186 vcpu->run->s390_reset_flags);
ade38c31 187 trace_kvm_s390_request_resets(vcpu->run->s390_reset_flags);
e28acfea
CB
188 return -EREMOTE;
189}
190
10ccaa1e
CH
191static int __diag_virtio_hypercall(struct kvm_vcpu *vcpu)
192{
800c1065 193 int ret;
10ccaa1e
CH
194
195 /* No virtio-ccw notification? Get out quickly. */
196 if (!vcpu->kvm->arch.css_support ||
197 (vcpu->run->s.regs.gprs[1] != KVM_S390_VIRTIO_CCW_NOTIFY))
198 return -EOPNOTSUPP;
199
10ccaa1e
CH
200 /*
201 * The layout is as follows:
202 * - gpr 2 contains the subchannel id (passed as addr)
203 * - gpr 3 contains the virtqueue index (passed as datamatch)
85dfe87e 204 * - gpr 4 contains the index on the bus (optionally)
10ccaa1e 205 */
85dfe87e 206 ret = kvm_io_bus_write_cookie(vcpu->kvm, KVM_VIRTIO_CCW_NOTIFY_BUS,
ff1f3cb4 207 vcpu->run->s.regs.gprs[2] & 0xffffffff,
85dfe87e
CH
208 8, &vcpu->run->s.regs.gprs[3],
209 vcpu->run->s.regs.gprs[4]);
85dfe87e
CH
210
211 /*
212 * Return cookie in gpr 2, but don't overwrite the register if the
213 * diagnose will be handled by userspace.
214 */
215 if (ret != -EOPNOTSUPP)
216 vcpu->run->s.regs.gprs[2] = ret;
217 /* kvm_io_bus_write_cookie returns -EOPNOTSUPP if it found no match. */
10ccaa1e
CH
218 return ret < 0 ? ret : 0;
219}
220
e28acfea
CB
221int kvm_s390_handle_diag(struct kvm_vcpu *vcpu)
222{
743db27c 223 int code = kvm_s390_get_base_disp_rs(vcpu) & 0xffff;
e28acfea 224
93e1750f
TH
225 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
226 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
227
5786fffa 228 trace_kvm_s390_handle_diag(vcpu, code);
e28acfea 229 switch (code) {
388186bc
CB
230 case 0x10:
231 return diag_release_pages(vcpu);
e28acfea
CB
232 case 0x44:
233 return __diag_time_slice_end(vcpu);
41628d33
KW
234 case 0x9c:
235 return __diag_time_slice_end_directed(vcpu);
3c038e6b
DD
236 case 0x258:
237 return __diag_page_ref_service(vcpu);
e28acfea
CB
238 case 0x308:
239 return __diag_ipl_functions(vcpu);
10ccaa1e
CH
240 case 0x500:
241 return __diag_virtio_hypercall(vcpu);
e28acfea 242 default:
b8e660b8 243 return -EOPNOTSUPP;
e28acfea
CB
244 }
245}
This page took 0.459101 seconds and 5 git commands to generate.