s390/sclp: Detect KSS facility
[linux-2.6-block.git] / arch / s390 / kvm / vsie.c
CommitLineData
a3508fbe
DH
1/*
2 * kvm nested virtualization support for s390x
3 *
4 * Copyright IBM Corp. 2016
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): David Hildenbrand <dahi@linux.vnet.ibm.com>
11 */
12#include <linux/vmalloc.h>
13#include <linux/kvm_host.h>
14#include <linux/bug.h>
15#include <linux/list.h>
16#include <linux/bitmap.h>
174cd4b1
IM
17#include <linux/sched/signal.h>
18
a3508fbe
DH
19#include <asm/gmap.h>
20#include <asm/mmu_context.h>
21#include <asm/sclp.h>
22#include <asm/nmi.h>
66b630d5 23#include <asm/dis.h>
a3508fbe
DH
24#include "kvm-s390.h"
25#include "gaccess.h"
26
27struct vsie_page {
28 struct kvm_s390_sie_block scb_s; /* 0x0000 */
29 /* the pinned originial scb */
30 struct kvm_s390_sie_block *scb_o; /* 0x0200 */
31 /* the shadow gmap in use by the vsie_page */
32 struct gmap *gmap; /* 0x0208 */
1b7029be
DH
33 /* address of the last reported fault to guest2 */
34 unsigned long fault_addr; /* 0x0210 */
35 __u8 reserved[0x0700 - 0x0218]; /* 0x0218 */
bbeaa58b 36 struct kvm_s390_crypto_cb crycb; /* 0x0700 */
66b630d5 37 __u8 fac[S390_ARCH_FAC_LIST_SIZE_BYTE]; /* 0x0800 */
a3508fbe
DH
38} __packed;
39
40/* trigger a validity icpt for the given scb */
41static int set_validity_icpt(struct kvm_s390_sie_block *scb,
42 __u16 reason_code)
43{
44 scb->ipa = 0x1000;
45 scb->ipb = ((__u32) reason_code) << 16;
46 scb->icptcode = ICPT_VALIDITY;
47 return 1;
48}
49
50/* mark the prefix as unmapped, this will block the VSIE */
51static void prefix_unmapped(struct vsie_page *vsie_page)
52{
53 atomic_or(PROG_REQUEST, &vsie_page->scb_s.prog20);
54}
55
56/* mark the prefix as unmapped and wait until the VSIE has been left */
57static void prefix_unmapped_sync(struct vsie_page *vsie_page)
58{
59 prefix_unmapped(vsie_page);
60 if (vsie_page->scb_s.prog0c & PROG_IN_SIE)
61 atomic_or(CPUSTAT_STOP_INT, &vsie_page->scb_s.cpuflags);
62 while (vsie_page->scb_s.prog0c & PROG_IN_SIE)
63 cpu_relax();
64}
65
66/* mark the prefix as mapped, this will allow the VSIE to run */
67static void prefix_mapped(struct vsie_page *vsie_page)
68{
69 atomic_andnot(PROG_REQUEST, &vsie_page->scb_s.prog20);
70}
71
06d68a6c
DH
72/* test if the prefix is mapped into the gmap shadow */
73static int prefix_is_mapped(struct vsie_page *vsie_page)
74{
75 return !(atomic_read(&vsie_page->scb_s.prog20) & PROG_REQUEST);
76}
a3508fbe
DH
77
78/* copy the updated intervention request bits into the shadow scb */
79static void update_intervention_requests(struct vsie_page *vsie_page)
80{
81 const int bits = CPUSTAT_STOP_INT | CPUSTAT_IO_INT | CPUSTAT_EXT_INT;
82 int cpuflags;
83
84 cpuflags = atomic_read(&vsie_page->scb_o->cpuflags);
85 atomic_andnot(bits, &vsie_page->scb_s.cpuflags);
86 atomic_or(cpuflags & bits, &vsie_page->scb_s.cpuflags);
87}
88
89/* shadow (filter and validate) the cpuflags */
90static int prepare_cpuflags(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
91{
92 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
93 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
94 int newflags, cpuflags = atomic_read(&scb_o->cpuflags);
95
96 /* we don't allow ESA/390 guests */
97 if (!(cpuflags & CPUSTAT_ZARCH))
98 return set_validity_icpt(scb_s, 0x0001U);
99
100 if (cpuflags & (CPUSTAT_RRF | CPUSTAT_MCDS))
101 return set_validity_icpt(scb_s, 0x0001U);
102 else if (cpuflags & (CPUSTAT_SLSV | CPUSTAT_SLSR))
103 return set_validity_icpt(scb_s, 0x0007U);
104
105 /* intervention requests will be set later */
106 newflags = CPUSTAT_ZARCH;
535ef81c
DH
107 if (cpuflags & CPUSTAT_GED && test_kvm_facility(vcpu->kvm, 8))
108 newflags |= CPUSTAT_GED;
109 if (cpuflags & CPUSTAT_GED2 && test_kvm_facility(vcpu->kvm, 78)) {
110 if (cpuflags & CPUSTAT_GED)
111 return set_validity_icpt(scb_s, 0x0001U);
112 newflags |= CPUSTAT_GED2;
113 }
77d18f6d
DH
114 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_GPERE))
115 newflags |= cpuflags & CPUSTAT_P;
a1b7b9b2
DH
116 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_GSLS))
117 newflags |= cpuflags & CPUSTAT_SM;
7fd7f39d
DH
118 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_IBS))
119 newflags |= cpuflags & CPUSTAT_IBS;
a3508fbe
DH
120
121 atomic_set(&scb_s->cpuflags, newflags);
122 return 0;
123}
124
bbeaa58b
DH
125/*
126 * Create a shadow copy of the crycb block and setup key wrapping, if
127 * requested for guest 3 and enabled for guest 2.
128 *
129 * We only accept format-1 (no AP in g2), but convert it into format-2
130 * There is nothing to do for format-0.
131 *
132 * Returns: - 0 if shadowed or nothing to do
133 * - > 0 if control has to be given to guest 2
134 */
135static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
136{
137 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
138 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
139 u32 crycb_addr = scb_o->crycbd & 0x7ffffff8U;
140 unsigned long *b1, *b2;
141 u8 ecb3_flags;
142
143 scb_s->crycbd = 0;
144 if (!(scb_o->crycbd & vcpu->arch.sie_block->crycbd & CRYCB_FORMAT1))
145 return 0;
146 /* format-1 is supported with message-security-assist extension 3 */
147 if (!test_kvm_facility(vcpu->kvm, 76))
148 return 0;
149 /* we may only allow it if enabled for guest 2 */
150 ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
151 (ECB3_AES | ECB3_DEA);
152 if (!ecb3_flags)
153 return 0;
154
155 if ((crycb_addr & PAGE_MASK) != ((crycb_addr + 128) & PAGE_MASK))
156 return set_validity_icpt(scb_s, 0x003CU);
157 else if (!crycb_addr)
158 return set_validity_icpt(scb_s, 0x0039U);
159
160 /* copy only the wrapping keys */
161 if (read_guest_real(vcpu, crycb_addr + 72, &vsie_page->crycb, 56))
162 return set_validity_icpt(scb_s, 0x0035U);
163
164 scb_s->ecb3 |= ecb3_flags;
165 scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | CRYCB_FORMAT1 |
166 CRYCB_FORMAT2;
167
168 /* xor both blocks in one run */
169 b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask;
170 b2 = (unsigned long *)
171 vcpu->kvm->arch.crypto.crycb->dea_wrapping_key_mask;
172 /* as 56%8 == 0, bitmap_xor won't overwrite any data */
173 bitmap_xor(b1, b1, b2, BITS_PER_BYTE * 56);
174 return 0;
175}
176
3573602b
DH
177/* shadow (round up/down) the ibc to avoid validity icpt */
178static void prepare_ibc(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
179{
180 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
181 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
182 __u64 min_ibc = (sclp.ibc >> 16) & 0x0fffU;
183
184 scb_s->ibc = 0;
185 /* ibc installed in g2 and requested for g3 */
186 if (vcpu->kvm->arch.model.ibc && (scb_o->ibc & 0x0fffU)) {
187 scb_s->ibc = scb_o->ibc & 0x0fffU;
188 /* takte care of the minimum ibc level of the machine */
189 if (scb_s->ibc < min_ibc)
190 scb_s->ibc = min_ibc;
191 /* take care of the maximum ibc level set for the guest */
192 if (scb_s->ibc > vcpu->kvm->arch.model.ibc)
193 scb_s->ibc = vcpu->kvm->arch.model.ibc;
194 }
195}
196
a3508fbe
DH
197/* unshadow the scb, copying parameters back to the real scb */
198static void unshadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
199{
200 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
201 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
202
203 /* interception */
204 scb_o->icptcode = scb_s->icptcode;
205 scb_o->icptstatus = scb_s->icptstatus;
206 scb_o->ipa = scb_s->ipa;
207 scb_o->ipb = scb_s->ipb;
208 scb_o->gbea = scb_s->gbea;
209
210 /* timer */
211 scb_o->cputm = scb_s->cputm;
212 scb_o->ckc = scb_s->ckc;
213 scb_o->todpr = scb_s->todpr;
214
215 /* guest state */
216 scb_o->gpsw = scb_s->gpsw;
217 scb_o->gg14 = scb_s->gg14;
218 scb_o->gg15 = scb_s->gg15;
219 memcpy(scb_o->gcr, scb_s->gcr, 128);
220 scb_o->pp = scb_s->pp;
221
222 /* interrupt intercept */
223 switch (scb_s->icptcode) {
224 case ICPT_PROGI:
225 case ICPT_INSTPROGI:
226 case ICPT_EXTINT:
227 memcpy((void *)((u64)scb_o + 0xc0),
228 (void *)((u64)scb_s + 0xc0), 0xf0 - 0xc0);
229 break;
230 case ICPT_PARTEXEC:
231 /* MVPG only */
232 memcpy((void *)((u64)scb_o + 0xc0),
233 (void *)((u64)scb_s + 0xc0), 0xd0 - 0xc0);
234 break;
235 }
236
237 if (scb_s->ihcpu != 0xffffU)
238 scb_o->ihcpu = scb_s->ihcpu;
239}
240
241/*
242 * Setup the shadow scb by copying and checking the relevant parts of the g2
243 * provided scb.
244 *
245 * Returns: - 0 if the scb has been shadowed
246 * - > 0 if control has to be given to guest 2
247 */
248static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
249{
250 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
251 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
0c9d8683 252 bool had_tx = scb_s->ecb & ECB_TE;
a1b7b9b2 253 unsigned long new_mso = 0;
a3508fbe
DH
254 int rc;
255
256 /* make sure we don't have any leftovers when reusing the scb */
257 scb_s->icptcode = 0;
258 scb_s->eca = 0;
259 scb_s->ecb = 0;
260 scb_s->ecb2 = 0;
261 scb_s->ecb3 = 0;
262 scb_s->ecd = 0;
66b630d5 263 scb_s->fac = 0;
a3508fbe
DH
264
265 rc = prepare_cpuflags(vcpu, vsie_page);
266 if (rc)
267 goto out;
268
269 /* timer */
270 scb_s->cputm = scb_o->cputm;
271 scb_s->ckc = scb_o->ckc;
272 scb_s->todpr = scb_o->todpr;
273 scb_s->epoch = scb_o->epoch;
274
275 /* guest state */
276 scb_s->gpsw = scb_o->gpsw;
277 scb_s->gg14 = scb_o->gg14;
278 scb_s->gg15 = scb_o->gg15;
279 memcpy(scb_s->gcr, scb_o->gcr, 128);
280 scb_s->pp = scb_o->pp;
281
282 /* interception / execution handling */
283 scb_s->gbea = scb_o->gbea;
284 scb_s->lctl = scb_o->lctl;
285 scb_s->svcc = scb_o->svcc;
286 scb_s->ictl = scb_o->ictl;
287 /*
288 * SKEY handling functions can't deal with false setting of PTE invalid
289 * bits. Therefore we cannot provide interpretation and would later
290 * have to provide own emulation handlers.
291 */
292 scb_s->ictl |= ICTL_ISKE | ICTL_SSKE | ICTL_RRBE;
293 scb_s->icpua = scb_o->icpua;
294
a1b7b9b2
DH
295 if (!(atomic_read(&scb_s->cpuflags) & CPUSTAT_SM))
296 new_mso = scb_o->mso & 0xfffffffffff00000UL;
06d68a6c
DH
297 /* if the hva of the prefix changes, we have to remap the prefix */
298 if (scb_s->mso != new_mso || scb_s->prefix != scb_o->prefix)
299 prefix_unmapped(vsie_page);
a3508fbe
DH
300 /* SIE will do mso/msl validity and exception checks for us */
301 scb_s->msl = scb_o->msl & 0xfffffffffff00000UL;
06d68a6c 302 scb_s->mso = new_mso;
a3508fbe
DH
303 scb_s->prefix = scb_o->prefix;
304
305 /* We have to definetly flush the tlb if this scb never ran */
306 if (scb_s->ihcpu != 0xffffU)
307 scb_s->ihcpu = scb_o->ihcpu;
308
309 /* MVPG and Protection Exception Interpretation are always available */
0c9d8683 310 scb_s->eca |= scb_o->eca & (ECA_MVPGI | ECA_PROTEXCI);
4ceafa90
DH
311 /* Host-protection-interruption introduced with ESOP */
312 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_ESOP))
0c9d8683 313 scb_s->ecb |= scb_o->ecb & ECB_HOSTPROTINT;
166ecb3d
DH
314 /* transactional execution */
315 if (test_kvm_facility(vcpu->kvm, 73)) {
316 /* remap the prefix is tx is toggled on */
0c9d8683 317 if ((scb_o->ecb & ECB_TE) && !had_tx)
166ecb3d 318 prefix_unmapped(vsie_page);
0c9d8683 319 scb_s->ecb |= scb_o->ecb & ECB_TE;
166ecb3d 320 }
c9bc1eab
DH
321 /* SIMD */
322 if (test_kvm_facility(vcpu->kvm, 129)) {
0c9d8683
DH
323 scb_s->eca |= scb_o->eca & ECA_VX;
324 scb_s->ecd |= scb_o->ecd & ECD_HOSTREGMGMT;
c9bc1eab 325 }
588438cb
DH
326 /* Run-time-Instrumentation */
327 if (test_kvm_facility(vcpu->kvm, 64))
0c9d8683 328 scb_s->ecb3 |= scb_o->ecb3 & ECB3_RI;
cd1836f5
JF
329 /* Instruction Execution Prevention */
330 if (test_kvm_facility(vcpu->kvm, 130))
0c9d8683 331 scb_s->ecb2 |= scb_o->ecb2 & ECB2_IEP;
4e0b1ab7
FZ
332 /* Guarded Storage */
333 if (test_kvm_facility(vcpu->kvm, 133)) {
334 scb_s->ecb |= scb_o->ecb & ECB_GS;
335 scb_s->ecd |= scb_o->ecd & ECD_HOSTREGMGMT;
336 }
0615a326 337 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_SIIF))
0c9d8683 338 scb_s->eca |= scb_o->eca & ECA_SII;
5630a8e8 339 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_IB))
0c9d8683 340 scb_s->eca |= scb_o->eca & ECA_IB;
13ee3f67 341 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_CEI))
0c9d8683 342 scb_s->eca |= scb_o->eca & ECA_CEI;
a3508fbe 343
3573602b 344 prepare_ibc(vcpu, vsie_page);
bbeaa58b 345 rc = shadow_crycb(vcpu, vsie_page);
a3508fbe
DH
346out:
347 if (rc)
348 unshadow_scb(vcpu, vsie_page);
349 return rc;
350}
351
352void kvm_s390_vsie_gmap_notifier(struct gmap *gmap, unsigned long start,
353 unsigned long end)
354{
355 struct kvm *kvm = gmap->private;
356 struct vsie_page *cur;
357 unsigned long prefix;
358 struct page *page;
359 int i;
360
361 if (!gmap_is_shadow(gmap))
362 return;
363 if (start >= 1UL << 31)
364 /* We are only interested in prefix pages */
365 return;
366
367 /*
368 * Only new shadow blocks are added to the list during runtime,
369 * therefore we can safely reference them all the time.
370 */
371 for (i = 0; i < kvm->arch.vsie.page_count; i++) {
372 page = READ_ONCE(kvm->arch.vsie.pages[i]);
373 if (!page)
374 continue;
375 cur = page_to_virt(page);
376 if (READ_ONCE(cur->gmap) != gmap)
377 continue;
378 prefix = cur->scb_s.prefix << GUEST_PREFIX_SHIFT;
379 /* with mso/msl, the prefix lies at an offset */
380 prefix += cur->scb_s.mso;
166ecb3d 381 if (prefix <= end && start <= prefix + 2 * PAGE_SIZE - 1)
a3508fbe
DH
382 prefix_unmapped_sync(cur);
383 }
384}
385
386/*
166ecb3d 387 * Map the first prefix page and if tx is enabled also the second prefix page.
a3508fbe
DH
388 *
389 * The prefix will be protected, a gmap notifier will inform about unmaps.
390 * The shadow scb must not be executed until the prefix is remapped, this is
391 * guaranteed by properly handling PROG_REQUEST.
392 *
393 * Returns: - 0 on if successfully mapped or already mapped
394 * - > 0 if control has to be given to guest 2
395 * - -EAGAIN if the caller can retry immediately
396 * - -ENOMEM if out of memory
397 */
398static int map_prefix(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
399{
400 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
401 u64 prefix = scb_s->prefix << GUEST_PREFIX_SHIFT;
402 int rc;
403
06d68a6c
DH
404 if (prefix_is_mapped(vsie_page))
405 return 0;
406
a3508fbe
DH
407 /* mark it as mapped so we can catch any concurrent unmappers */
408 prefix_mapped(vsie_page);
409
410 /* with mso/msl, the prefix lies at offset *mso* */
411 prefix += scb_s->mso;
412
413 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, prefix);
0c9d8683 414 if (!rc && (scb_s->ecb & ECB_TE))
166ecb3d
DH
415 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap,
416 prefix + PAGE_SIZE);
a3508fbe
DH
417 /*
418 * We don't have to mprotect, we will be called for all unshadows.
419 * SIE will detect if protection applies and trigger a validity.
420 */
421 if (rc)
422 prefix_unmapped(vsie_page);
423 if (rc > 0 || rc == -EFAULT)
424 rc = set_validity_icpt(scb_s, 0x0037U);
425 return rc;
426}
427
428/*
429 * Pin the guest page given by gpa and set hpa to the pinned host address.
430 * Will always be pinned writable.
431 *
432 * Returns: - 0 on success
433 * - -EINVAL if the gpa is not valid guest storage
434 * - -ENOMEM if out of memory
435 */
436static int pin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t *hpa)
437{
438 struct page *page;
439 hva_t hva;
440 int rc;
441
442 hva = gfn_to_hva(kvm, gpa_to_gfn(gpa));
443 if (kvm_is_error_hva(hva))
444 return -EINVAL;
445 rc = get_user_pages_fast(hva, 1, 1, &page);
446 if (rc < 0)
447 return rc;
448 else if (rc != 1)
449 return -ENOMEM;
450 *hpa = (hpa_t) page_to_virt(page) + (gpa & ~PAGE_MASK);
451 return 0;
452}
453
454/* Unpins a page previously pinned via pin_guest_page, marking it as dirty. */
455static void unpin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t hpa)
456{
457 struct page *page;
458
459 page = virt_to_page(hpa);
460 set_page_dirty_lock(page);
461 put_page(page);
462 /* mark the page always as dirty for migration */
463 mark_page_dirty(kvm, gpa_to_gfn(gpa));
464}
465
466/* unpin all blocks previously pinned by pin_blocks(), marking them dirty */
467static void unpin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
468{
469 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
470 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
471 hpa_t hpa;
472 gpa_t gpa;
473
474 hpa = (u64) scb_s->scaoh << 32 | scb_s->scaol;
475 if (hpa) {
476 gpa = scb_o->scaol & ~0xfUL;
19c439b5
DH
477 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_64BSCAO))
478 gpa |= (u64) scb_o->scaoh << 32;
a3508fbe
DH
479 unpin_guest_page(vcpu->kvm, gpa, hpa);
480 scb_s->scaol = 0;
481 scb_s->scaoh = 0;
482 }
166ecb3d
DH
483
484 hpa = scb_s->itdba;
485 if (hpa) {
486 gpa = scb_o->itdba & ~0xffUL;
487 unpin_guest_page(vcpu->kvm, gpa, hpa);
488 scb_s->itdba = 0;
489 }
c9bc1eab
DH
490
491 hpa = scb_s->gvrd;
492 if (hpa) {
493 gpa = scb_o->gvrd & ~0x1ffUL;
494 unpin_guest_page(vcpu->kvm, gpa, hpa);
495 scb_s->gvrd = 0;
496 }
588438cb
DH
497
498 hpa = scb_s->riccbd;
499 if (hpa) {
500 gpa = scb_o->riccbd & ~0x3fUL;
501 unpin_guest_page(vcpu->kvm, gpa, hpa);
502 scb_s->riccbd = 0;
503 }
4e0b1ab7
FZ
504
505 hpa = scb_s->sdnxo;
506 if (hpa) {
507 gpa = scb_o->sdnxo;
508 unpin_guest_page(vcpu->kvm, gpa, hpa);
509 scb_s->sdnxo = 0;
510 }
a3508fbe
DH
511}
512
513/*
514 * Instead of shadowing some blocks, we can simply forward them because the
515 * addresses in the scb are 64 bit long.
516 *
517 * This works as long as the data lies in one page. If blocks ever exceed one
518 * page, we have to fall back to shadowing.
519 *
520 * As we reuse the sca, the vcpu pointers contained in it are invalid. We must
521 * therefore not enable any facilities that access these pointers (e.g. SIGPIF).
522 *
523 * Returns: - 0 if all blocks were pinned.
524 * - > 0 if control has to be given to guest 2
525 * - -ENOMEM if out of memory
526 */
527static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
528{
529 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
530 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
531 hpa_t hpa;
532 gpa_t gpa;
533 int rc = 0;
534
535 gpa = scb_o->scaol & ~0xfUL;
19c439b5
DH
536 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_64BSCAO))
537 gpa |= (u64) scb_o->scaoh << 32;
a3508fbe
DH
538 if (gpa) {
539 if (!(gpa & ~0x1fffUL))
540 rc = set_validity_icpt(scb_s, 0x0038U);
541 else if ((gpa & ~0x1fffUL) == kvm_s390_get_prefix(vcpu))
542 rc = set_validity_icpt(scb_s, 0x0011U);
543 else if ((gpa & PAGE_MASK) !=
544 ((gpa + sizeof(struct bsca_block) - 1) & PAGE_MASK))
545 rc = set_validity_icpt(scb_s, 0x003bU);
546 if (!rc) {
547 rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
548 if (rc == -EINVAL)
549 rc = set_validity_icpt(scb_s, 0x0034U);
550 }
551 if (rc)
552 goto unpin;
553 scb_s->scaoh = (u32)((u64)hpa >> 32);
554 scb_s->scaol = (u32)(u64)hpa;
555 }
166ecb3d
DH
556
557 gpa = scb_o->itdba & ~0xffUL;
0c9d8683 558 if (gpa && (scb_s->ecb & ECB_TE)) {
166ecb3d
DH
559 if (!(gpa & ~0x1fffU)) {
560 rc = set_validity_icpt(scb_s, 0x0080U);
561 goto unpin;
562 }
563 /* 256 bytes cannot cross page boundaries */
564 rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
565 if (rc == -EINVAL)
566 rc = set_validity_icpt(scb_s, 0x0080U);
567 if (rc)
568 goto unpin;
569 scb_s->itdba = hpa;
570 }
c9bc1eab
DH
571
572 gpa = scb_o->gvrd & ~0x1ffUL;
0c9d8683 573 if (gpa && (scb_s->eca & ECA_VX) && !(scb_s->ecd & ECD_HOSTREGMGMT)) {
c9bc1eab
DH
574 if (!(gpa & ~0x1fffUL)) {
575 rc = set_validity_icpt(scb_s, 0x1310U);
576 goto unpin;
577 }
578 /*
579 * 512 bytes vector registers cannot cross page boundaries
580 * if this block gets bigger, we have to shadow it.
581 */
582 rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
583 if (rc == -EINVAL)
584 rc = set_validity_icpt(scb_s, 0x1310U);
585 if (rc)
586 goto unpin;
587 scb_s->gvrd = hpa;
588 }
588438cb
DH
589
590 gpa = scb_o->riccbd & ~0x3fUL;
0c9d8683 591 if (gpa && (scb_s->ecb3 & ECB3_RI)) {
588438cb
DH
592 if (!(gpa & ~0x1fffUL)) {
593 rc = set_validity_icpt(scb_s, 0x0043U);
594 goto unpin;
595 }
596 /* 64 bytes cannot cross page boundaries */
597 rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
598 if (rc == -EINVAL)
599 rc = set_validity_icpt(scb_s, 0x0043U);
600 /* Validity 0x0044 will be checked by SIE */
601 if (rc)
602 goto unpin;
4d21cef3 603 scb_s->riccbd = hpa;
588438cb 604 }
4e0b1ab7
FZ
605 if ((scb_s->ecb & ECB_GS) && !(scb_s->ecd & ECD_HOSTREGMGMT)) {
606 unsigned long sdnxc;
607
608 gpa = scb_o->sdnxo & ~0xfUL;
609 sdnxc = scb_o->sdnxo & 0xfUL;
610 if (!gpa || !(gpa & ~0x1fffUL)) {
611 rc = set_validity_icpt(scb_s, 0x10b0U);
612 goto unpin;
613 }
614 if (sdnxc < 6 || sdnxc > 12) {
615 rc = set_validity_icpt(scb_s, 0x10b1U);
616 goto unpin;
617 }
618 if (gpa & ((1 << sdnxc) - 1)) {
619 rc = set_validity_icpt(scb_s, 0x10b2U);
620 goto unpin;
621 }
622 /* Due to alignment rules (checked above) this cannot
623 * cross page boundaries
624 */
625 rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
626 if (rc == -EINVAL)
627 rc = set_validity_icpt(scb_s, 0x10b0U);
628 if (rc)
629 goto unpin;
fe722d13 630 scb_s->sdnxo = hpa | sdnxc;
4e0b1ab7 631 }
a3508fbe
DH
632 return 0;
633unpin:
634 unpin_blocks(vcpu, vsie_page);
635 return rc;
636}
637
638/* unpin the scb provided by guest 2, marking it as dirty */
639static void unpin_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,
640 gpa_t gpa)
641{
642 hpa_t hpa = (hpa_t) vsie_page->scb_o;
643
644 if (hpa)
645 unpin_guest_page(vcpu->kvm, gpa, hpa);
646 vsie_page->scb_o = NULL;
647}
648
649/*
650 * Pin the scb at gpa provided by guest 2 at vsie_page->scb_o.
651 *
652 * Returns: - 0 if the scb was pinned.
653 * - > 0 if control has to be given to guest 2
654 * - -ENOMEM if out of memory
655 */
656static int pin_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,
657 gpa_t gpa)
658{
659 hpa_t hpa;
660 int rc;
661
662 rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
663 if (rc == -EINVAL) {
664 rc = kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
665 if (!rc)
666 rc = 1;
667 }
668 if (!rc)
669 vsie_page->scb_o = (struct kvm_s390_sie_block *) hpa;
670 return rc;
671}
672
673/*
674 * Inject a fault into guest 2.
675 *
676 * Returns: - > 0 if control has to be given to guest 2
677 * < 0 if an error occurred during injection.
678 */
679static int inject_fault(struct kvm_vcpu *vcpu, __u16 code, __u64 vaddr,
680 bool write_flag)
681{
682 struct kvm_s390_pgm_info pgm = {
683 .code = code,
684 .trans_exc_code =
685 /* 0-51: virtual address */
686 (vaddr & 0xfffffffffffff000UL) |
687 /* 52-53: store / fetch */
688 (((unsigned int) !write_flag) + 1) << 10,
689 /* 62-63: asce id (alway primary == 0) */
690 .exc_access_id = 0, /* always primary */
691 .op_access_id = 0, /* not MVPG */
692 };
693 int rc;
694
695 if (code == PGM_PROTECTION)
696 pgm.trans_exc_code |= 0x4UL;
697
698 rc = kvm_s390_inject_prog_irq(vcpu, &pgm);
699 return rc ? rc : 1;
700}
701
702/*
703 * Handle a fault during vsie execution on a gmap shadow.
704 *
705 * Returns: - 0 if the fault was resolved
706 * - > 0 if control has to be given to guest 2
707 * - < 0 if an error occurred
708 */
709static int handle_fault(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
710{
711 int rc;
712
713 if (current->thread.gmap_int_code == PGM_PROTECTION)
714 /* we can directly forward all protection exceptions */
715 return inject_fault(vcpu, PGM_PROTECTION,
716 current->thread.gmap_addr, 1);
717
718 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap,
719 current->thread.gmap_addr);
720 if (rc > 0) {
721 rc = inject_fault(vcpu, rc,
722 current->thread.gmap_addr,
723 current->thread.gmap_write_flag);
1b7029be
DH
724 if (rc >= 0)
725 vsie_page->fault_addr = current->thread.gmap_addr;
a3508fbe
DH
726 }
727 return rc;
728}
729
1b7029be
DH
730/*
731 * Retry the previous fault that required guest 2 intervention. This avoids
732 * one superfluous SIE re-entry and direct exit.
733 *
734 * Will ignore any errors. The next SIE fault will do proper fault handling.
735 */
736static void handle_last_fault(struct kvm_vcpu *vcpu,
737 struct vsie_page *vsie_page)
738{
739 if (vsie_page->fault_addr)
740 kvm_s390_shadow_fault(vcpu, vsie_page->gmap,
741 vsie_page->fault_addr);
742 vsie_page->fault_addr = 0;
743}
744
a3508fbe
DH
745static inline void clear_vsie_icpt(struct vsie_page *vsie_page)
746{
747 vsie_page->scb_s.icptcode = 0;
748}
749
66b630d5
DH
750/* rewind the psw and clear the vsie icpt, so we can retry execution */
751static void retry_vsie_icpt(struct vsie_page *vsie_page)
752{
753 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
754 int ilen = insn_length(scb_s->ipa >> 8);
755
756 /* take care of EXECUTE instructions */
757 if (scb_s->icptstatus & 1) {
758 ilen = (scb_s->icptstatus >> 4) & 0x6;
759 if (!ilen)
760 ilen = 4;
761 }
762 scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, ilen);
763 clear_vsie_icpt(vsie_page);
764}
765
766/*
767 * Try to shadow + enable the guest 2 provided facility list.
768 * Retry instruction execution if enabled for and provided by guest 2.
769 *
770 * Returns: - 0 if handled (retry or guest 2 icpt)
771 * - > 0 if control has to be given to guest 2
772 */
773static int handle_stfle(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
774{
775 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
776 __u32 fac = vsie_page->scb_o->fac & 0x7ffffff8U;
777
778 if (fac && test_kvm_facility(vcpu->kvm, 7)) {
779 retry_vsie_icpt(vsie_page);
780 if (read_guest_real(vcpu, fac, &vsie_page->fac,
781 sizeof(vsie_page->fac)))
782 return set_validity_icpt(scb_s, 0x1090U);
783 scb_s->fac = (__u32)(__u64) &vsie_page->fac;
784 }
785 return 0;
786}
787
a3508fbe
DH
788/*
789 * Run the vsie on a shadow scb and a shadow gmap, without any further
790 * sanity checks, handling SIE faults.
791 *
792 * Returns: - 0 everything went fine
793 * - > 0 if control has to be given to guest 2
794 * - < 0 if an error occurred
795 */
796static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
797{
798 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
799 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
800 int rc;
801
1b7029be
DH
802 handle_last_fault(vcpu, vsie_page);
803
a3508fbe
DH
804 if (need_resched())
805 schedule();
806 if (test_cpu_flag(CIF_MCCK_PENDING))
807 s390_handle_mcck();
808
809 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
810 local_irq_disable();
6edaa530 811 guest_enter_irqoff();
a3508fbe
DH
812 local_irq_enable();
813
814 rc = sie64a(scb_s, vcpu->run->s.regs.gprs);
815
816 local_irq_disable();
6edaa530 817 guest_exit_irqoff();
a3508fbe
DH
818 local_irq_enable();
819 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
820
821 if (rc > 0)
822 rc = 0; /* we could still have an icpt */
823 else if (rc == -EFAULT)
824 return handle_fault(vcpu, vsie_page);
825
826 switch (scb_s->icptcode) {
66b630d5
DH
827 case ICPT_INST:
828 if (scb_s->ipa == 0xb2b0)
829 rc = handle_stfle(vcpu, vsie_page);
830 break;
a3508fbe
DH
831 case ICPT_STOP:
832 /* stop not requested by g2 - must have been a kick */
833 if (!(atomic_read(&scb_o->cpuflags) & CPUSTAT_STOP_INT))
834 clear_vsie_icpt(vsie_page);
835 break;
836 case ICPT_VALIDITY:
837 if ((scb_s->ipa & 0xf000) != 0xf000)
838 scb_s->ipa += 0x1000;
839 break;
840 }
841 return rc;
842}
843
844static void release_gmap_shadow(struct vsie_page *vsie_page)
845{
846 if (vsie_page->gmap)
847 gmap_put(vsie_page->gmap);
848 WRITE_ONCE(vsie_page->gmap, NULL);
06d68a6c 849 prefix_unmapped(vsie_page);
a3508fbe
DH
850}
851
852static int acquire_gmap_shadow(struct kvm_vcpu *vcpu,
853 struct vsie_page *vsie_page)
854{
855 unsigned long asce;
856 union ctlreg0 cr0;
857 struct gmap *gmap;
858 int edat;
859
860 asce = vcpu->arch.sie_block->gcr[1];
861 cr0.val = vcpu->arch.sie_block->gcr[0];
862 edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8);
863 edat += edat && test_kvm_facility(vcpu->kvm, 78);
864
06d68a6c
DH
865 /*
866 * ASCE or EDAT could have changed since last icpt, or the gmap
867 * we're holding has been unshadowed. If the gmap is still valid,
868 * we can safely reuse it.
869 */
870 if (vsie_page->gmap && gmap_shadow_valid(vsie_page->gmap, asce, edat))
871 return 0;
872
873 /* release the old shadow - if any, and mark the prefix as unmapped */
874 release_gmap_shadow(vsie_page);
a3508fbe
DH
875 gmap = gmap_shadow(vcpu->arch.gmap, asce, edat);
876 if (IS_ERR(gmap))
877 return PTR_ERR(gmap);
878 gmap->private = vcpu->kvm;
879 WRITE_ONCE(vsie_page->gmap, gmap);
880 return 0;
881}
882
adbf1698
DH
883/*
884 * Register the shadow scb at the VCPU, e.g. for kicking out of vsie.
885 */
886static void register_shadow_scb(struct kvm_vcpu *vcpu,
887 struct vsie_page *vsie_page)
888{
91473b48
DH
889 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
890
adbf1698 891 WRITE_ONCE(vcpu->arch.vsie_block, &vsie_page->scb_s);
b917ae57
DH
892 /*
893 * External calls have to lead to a kick of the vcpu and
894 * therefore the vsie -> Simulate Wait state.
895 */
896 atomic_or(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags);
91473b48
DH
897 /*
898 * We have to adjust the g3 epoch by the g2 epoch. The epoch will
899 * automatically be adjusted on tod clock changes via kvm_sync_clock.
900 */
901 preempt_disable();
902 scb_s->epoch += vcpu->kvm->arch.epoch;
903 preempt_enable();
adbf1698
DH
904}
905
906/*
907 * Unregister a shadow scb from a VCPU.
908 */
909static void unregister_shadow_scb(struct kvm_vcpu *vcpu)
910{
b917ae57 911 atomic_andnot(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags);
adbf1698
DH
912 WRITE_ONCE(vcpu->arch.vsie_block, NULL);
913}
914
a3508fbe
DH
915/*
916 * Run the vsie on a shadowed scb, managing the gmap shadow, handling
917 * prefix pages and faults.
918 *
919 * Returns: - 0 if no errors occurred
920 * - > 0 if control has to be given to guest 2
921 * - -ENOMEM if out of memory
922 */
923static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
924{
925 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
926 int rc = 0;
927
928 while (1) {
929 rc = acquire_gmap_shadow(vcpu, vsie_page);
930 if (!rc)
931 rc = map_prefix(vcpu, vsie_page);
932 if (!rc) {
933 gmap_enable(vsie_page->gmap);
934 update_intervention_requests(vsie_page);
935 rc = do_vsie_run(vcpu, vsie_page);
936 gmap_enable(vcpu->arch.gmap);
937 }
adbf1698 938 atomic_andnot(PROG_BLOCK_SIE, &scb_s->prog20);
a3508fbe
DH
939
940 if (rc == -EAGAIN)
941 rc = 0;
942 if (rc || scb_s->icptcode || signal_pending(current) ||
943 kvm_s390_vcpu_has_irq(vcpu, 0))
944 break;
0b925159 945 }
a3508fbe
DH
946
947 if (rc == -EFAULT) {
948 /*
949 * Addressing exceptions are always presentes as intercepts.
950 * As addressing exceptions are suppressing and our guest 3 PSW
951 * points at the responsible instruction, we have to
952 * forward the PSW and set the ilc. If we can't read guest 3
953 * instruction, we can use an arbitrary ilc. Let's always use
954 * ilen = 4 for now, so we can avoid reading in guest 3 virtual
955 * memory. (we could also fake the shadow so the hardware
956 * handles it).
957 */
958 scb_s->icptcode = ICPT_PROGI;
959 scb_s->iprcc = PGM_ADDRESSING;
960 scb_s->pgmilc = 4;
961 scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, 4);
962 }
963 return rc;
964}
965
966/*
967 * Get or create a vsie page for a scb address.
968 *
969 * Returns: - address of a vsie page (cached or new one)
970 * - NULL if the same scb address is already used by another VCPU
971 * - ERR_PTR(-ENOMEM) if out of memory
972 */
973static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
974{
975 struct vsie_page *vsie_page;
976 struct page *page;
977 int nr_vcpus;
978
979 rcu_read_lock();
980 page = radix_tree_lookup(&kvm->arch.vsie.addr_to_page, addr >> 9);
981 rcu_read_unlock();
982 if (page) {
983 if (page_ref_inc_return(page) == 2)
984 return page_to_virt(page);
985 page_ref_dec(page);
986 }
987
988 /*
989 * We want at least #online_vcpus shadows, so every VCPU can execute
990 * the VSIE in parallel.
991 */
992 nr_vcpus = atomic_read(&kvm->online_vcpus);
993
994 mutex_lock(&kvm->arch.vsie.mutex);
995 if (kvm->arch.vsie.page_count < nr_vcpus) {
66b630d5 996 page = alloc_page(GFP_KERNEL | __GFP_ZERO | GFP_DMA);
a3508fbe
DH
997 if (!page) {
998 mutex_unlock(&kvm->arch.vsie.mutex);
999 return ERR_PTR(-ENOMEM);
1000 }
1001 page_ref_inc(page);
1002 kvm->arch.vsie.pages[kvm->arch.vsie.page_count] = page;
1003 kvm->arch.vsie.page_count++;
1004 } else {
1005 /* reuse an existing entry that belongs to nobody */
1006 while (true) {
1007 page = kvm->arch.vsie.pages[kvm->arch.vsie.next];
1008 if (page_ref_inc_return(page) == 2)
1009 break;
1010 page_ref_dec(page);
1011 kvm->arch.vsie.next++;
1012 kvm->arch.vsie.next %= nr_vcpus;
1013 }
1014 radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9);
1015 }
1016 page->index = addr;
1017 /* double use of the same address */
1018 if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9, page)) {
1019 page_ref_dec(page);
1020 mutex_unlock(&kvm->arch.vsie.mutex);
1021 return NULL;
1022 }
1023 mutex_unlock(&kvm->arch.vsie.mutex);
1024
1025 vsie_page = page_to_virt(page);
1026 memset(&vsie_page->scb_s, 0, sizeof(struct kvm_s390_sie_block));
06d68a6c 1027 release_gmap_shadow(vsie_page);
1b7029be 1028 vsie_page->fault_addr = 0;
a3508fbe
DH
1029 vsie_page->scb_s.ihcpu = 0xffffU;
1030 return vsie_page;
1031}
1032
1033/* put a vsie page acquired via get_vsie_page */
1034static void put_vsie_page(struct kvm *kvm, struct vsie_page *vsie_page)
1035{
1036 struct page *page = pfn_to_page(__pa(vsie_page) >> PAGE_SHIFT);
1037
1038 page_ref_dec(page);
1039}
1040
1041int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu)
1042{
1043 struct vsie_page *vsie_page;
1044 unsigned long scb_addr;
1045 int rc;
1046
1047 vcpu->stat.instruction_sie++;
1048 if (!test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_SIEF2))
1049 return -EOPNOTSUPP;
1050 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
1051 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
1052
1053 BUILD_BUG_ON(sizeof(struct vsie_page) != 4096);
1054 scb_addr = kvm_s390_get_base_disp_s(vcpu, NULL);
1055
1056 /* 512 byte alignment */
1057 if (unlikely(scb_addr & 0x1ffUL))
1058 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
1059
1060 if (signal_pending(current) || kvm_s390_vcpu_has_irq(vcpu, 0))
1061 return 0;
1062
1063 vsie_page = get_vsie_page(vcpu->kvm, scb_addr);
1064 if (IS_ERR(vsie_page))
1065 return PTR_ERR(vsie_page);
1066 else if (!vsie_page)
1067 /* double use of sie control block - simply do nothing */
1068 return 0;
1069
1070 rc = pin_scb(vcpu, vsie_page, scb_addr);
1071 if (rc)
1072 goto out_put;
1073 rc = shadow_scb(vcpu, vsie_page);
1074 if (rc)
1075 goto out_unpin_scb;
1076 rc = pin_blocks(vcpu, vsie_page);
1077 if (rc)
1078 goto out_unshadow;
adbf1698 1079 register_shadow_scb(vcpu, vsie_page);
a3508fbe 1080 rc = vsie_run(vcpu, vsie_page);
adbf1698 1081 unregister_shadow_scb(vcpu);
a3508fbe
DH
1082 unpin_blocks(vcpu, vsie_page);
1083out_unshadow:
1084 unshadow_scb(vcpu, vsie_page);
1085out_unpin_scb:
1086 unpin_scb(vcpu, vsie_page, scb_addr);
1087out_put:
1088 put_vsie_page(vcpu->kvm, vsie_page);
1089
1090 return rc < 0 ? rc : 0;
1091}
1092
1093/* Init the vsie data structures. To be called when a vm is initialized. */
1094void kvm_s390_vsie_init(struct kvm *kvm)
1095{
1096 mutex_init(&kvm->arch.vsie.mutex);
1097 INIT_RADIX_TREE(&kvm->arch.vsie.addr_to_page, GFP_KERNEL);
1098}
1099
1100/* Destroy the vsie data structures. To be called when a vm is destroyed. */
1101void kvm_s390_vsie_destroy(struct kvm *kvm)
1102{
06d68a6c 1103 struct vsie_page *vsie_page;
a3508fbe
DH
1104 struct page *page;
1105 int i;
1106
1107 mutex_lock(&kvm->arch.vsie.mutex);
1108 for (i = 0; i < kvm->arch.vsie.page_count; i++) {
1109 page = kvm->arch.vsie.pages[i];
1110 kvm->arch.vsie.pages[i] = NULL;
06d68a6c
DH
1111 vsie_page = page_to_virt(page);
1112 release_gmap_shadow(vsie_page);
a3508fbe
DH
1113 /* free the radix tree entry */
1114 radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9);
1115 __free_page(page);
1116 }
1117 kvm->arch.vsie.page_count = 0;
1118 mutex_unlock(&kvm->arch.vsie.mutex);
1119}
adbf1698
DH
1120
1121void kvm_s390_vsie_kick(struct kvm_vcpu *vcpu)
1122{
1123 struct kvm_s390_sie_block *scb = READ_ONCE(vcpu->arch.vsie_block);
1124
1125 /*
1126 * Even if the VCPU lets go of the shadow sie block reference, it is
1127 * still valid in the cache. So we can safely kick it.
1128 */
1129 if (scb) {
1130 atomic_or(PROG_BLOCK_SIE, &scb->prog20);
1131 if (scb->prog0c & PROG_IN_SIE)
1132 atomic_or(CPUSTAT_STOP_INT, &scb->cpuflags);
1133 }
1134}