2 * kvm nested virtualization support for s390x
4 * Copyright IBM Corp. 2016
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.
10 * Author(s): David Hildenbrand <dahi@linux.vnet.ibm.com>
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>
18 #include <asm/mmu_context.h>
25 struct kvm_s390_sie_block scb_s; /* 0x0000 */
26 /* the pinned originial scb */
27 struct kvm_s390_sie_block *scb_o; /* 0x0200 */
28 /* the shadow gmap in use by the vsie_page */
29 struct gmap *gmap; /* 0x0208 */
30 __u8 reserved[0x1000 - 0x0210]; /* 0x0210 */
33 /* trigger a validity icpt for the given scb */
34 static int set_validity_icpt(struct kvm_s390_sie_block *scb,
38 scb->ipb = ((__u32) reason_code) << 16;
39 scb->icptcode = ICPT_VALIDITY;
43 /* mark the prefix as unmapped, this will block the VSIE */
44 static void prefix_unmapped(struct vsie_page *vsie_page)
46 atomic_or(PROG_REQUEST, &vsie_page->scb_s.prog20);
49 /* mark the prefix as unmapped and wait until the VSIE has been left */
50 static void prefix_unmapped_sync(struct vsie_page *vsie_page)
52 prefix_unmapped(vsie_page);
53 if (vsie_page->scb_s.prog0c & PROG_IN_SIE)
54 atomic_or(CPUSTAT_STOP_INT, &vsie_page->scb_s.cpuflags);
55 while (vsie_page->scb_s.prog0c & PROG_IN_SIE)
59 /* mark the prefix as mapped, this will allow the VSIE to run */
60 static void prefix_mapped(struct vsie_page *vsie_page)
62 atomic_andnot(PROG_REQUEST, &vsie_page->scb_s.prog20);
65 /* test if the prefix is mapped into the gmap shadow */
66 static int prefix_is_mapped(struct vsie_page *vsie_page)
68 return !(atomic_read(&vsie_page->scb_s.prog20) & PROG_REQUEST);
71 /* copy the updated intervention request bits into the shadow scb */
72 static void update_intervention_requests(struct vsie_page *vsie_page)
74 const int bits = CPUSTAT_STOP_INT | CPUSTAT_IO_INT | CPUSTAT_EXT_INT;
77 cpuflags = atomic_read(&vsie_page->scb_o->cpuflags);
78 atomic_andnot(bits, &vsie_page->scb_s.cpuflags);
79 atomic_or(cpuflags & bits, &vsie_page->scb_s.cpuflags);
82 /* shadow (filter and validate) the cpuflags */
83 static int prepare_cpuflags(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
85 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
86 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
87 int newflags, cpuflags = atomic_read(&scb_o->cpuflags);
89 /* we don't allow ESA/390 guests */
90 if (!(cpuflags & CPUSTAT_ZARCH))
91 return set_validity_icpt(scb_s, 0x0001U);
93 if (cpuflags & (CPUSTAT_RRF | CPUSTAT_MCDS))
94 return set_validity_icpt(scb_s, 0x0001U);
95 else if (cpuflags & (CPUSTAT_SLSV | CPUSTAT_SLSR))
96 return set_validity_icpt(scb_s, 0x0007U);
98 /* intervention requests will be set later */
99 newflags = CPUSTAT_ZARCH;
100 if (cpuflags & CPUSTAT_GED && test_kvm_facility(vcpu->kvm, 8))
101 newflags |= CPUSTAT_GED;
102 if (cpuflags & CPUSTAT_GED2 && test_kvm_facility(vcpu->kvm, 78)) {
103 if (cpuflags & CPUSTAT_GED)
104 return set_validity_icpt(scb_s, 0x0001U);
105 newflags |= CPUSTAT_GED2;
108 atomic_set(&scb_s->cpuflags, newflags);
112 /* shadow (round up/down) the ibc to avoid validity icpt */
113 static void prepare_ibc(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
115 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
116 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
117 __u64 min_ibc = (sclp.ibc >> 16) & 0x0fffU;
120 /* ibc installed in g2 and requested for g3 */
121 if (vcpu->kvm->arch.model.ibc && (scb_o->ibc & 0x0fffU)) {
122 scb_s->ibc = scb_o->ibc & 0x0fffU;
123 /* takte care of the minimum ibc level of the machine */
124 if (scb_s->ibc < min_ibc)
125 scb_s->ibc = min_ibc;
126 /* take care of the maximum ibc level set for the guest */
127 if (scb_s->ibc > vcpu->kvm->arch.model.ibc)
128 scb_s->ibc = vcpu->kvm->arch.model.ibc;
132 /* unshadow the scb, copying parameters back to the real scb */
133 static void unshadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
135 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
136 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
139 scb_o->icptcode = scb_s->icptcode;
140 scb_o->icptstatus = scb_s->icptstatus;
141 scb_o->ipa = scb_s->ipa;
142 scb_o->ipb = scb_s->ipb;
143 scb_o->gbea = scb_s->gbea;
146 scb_o->cputm = scb_s->cputm;
147 scb_o->ckc = scb_s->ckc;
148 scb_o->todpr = scb_s->todpr;
151 scb_o->gpsw = scb_s->gpsw;
152 scb_o->gg14 = scb_s->gg14;
153 scb_o->gg15 = scb_s->gg15;
154 memcpy(scb_o->gcr, scb_s->gcr, 128);
155 scb_o->pp = scb_s->pp;
157 /* interrupt intercept */
158 switch (scb_s->icptcode) {
162 memcpy((void *)((u64)scb_o + 0xc0),
163 (void *)((u64)scb_s + 0xc0), 0xf0 - 0xc0);
167 memcpy((void *)((u64)scb_o + 0xc0),
168 (void *)((u64)scb_s + 0xc0), 0xd0 - 0xc0);
172 if (scb_s->ihcpu != 0xffffU)
173 scb_o->ihcpu = scb_s->ihcpu;
177 * Setup the shadow scb by copying and checking the relevant parts of the g2
180 * Returns: - 0 if the scb has been shadowed
181 * - > 0 if control has to be given to guest 2
183 static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
185 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
186 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
187 unsigned long new_mso;
190 /* make sure we don't have any leftovers when reusing the scb */
198 rc = prepare_cpuflags(vcpu, vsie_page);
203 scb_s->cputm = scb_o->cputm;
204 scb_s->ckc = scb_o->ckc;
205 scb_s->todpr = scb_o->todpr;
206 scb_s->epoch = scb_o->epoch;
209 scb_s->gpsw = scb_o->gpsw;
210 scb_s->gg14 = scb_o->gg14;
211 scb_s->gg15 = scb_o->gg15;
212 memcpy(scb_s->gcr, scb_o->gcr, 128);
213 scb_s->pp = scb_o->pp;
215 /* interception / execution handling */
216 scb_s->gbea = scb_o->gbea;
217 scb_s->lctl = scb_o->lctl;
218 scb_s->svcc = scb_o->svcc;
219 scb_s->ictl = scb_o->ictl;
221 * SKEY handling functions can't deal with false setting of PTE invalid
222 * bits. Therefore we cannot provide interpretation and would later
223 * have to provide own emulation handlers.
225 scb_s->ictl |= ICTL_ISKE | ICTL_SSKE | ICTL_RRBE;
226 scb_s->icpua = scb_o->icpua;
228 new_mso = scb_o->mso & 0xfffffffffff00000UL;
229 /* if the hva of the prefix changes, we have to remap the prefix */
230 if (scb_s->mso != new_mso || scb_s->prefix != scb_o->prefix)
231 prefix_unmapped(vsie_page);
232 /* SIE will do mso/msl validity and exception checks for us */
233 scb_s->msl = scb_o->msl & 0xfffffffffff00000UL;
234 scb_s->mso = new_mso;
235 scb_s->prefix = scb_o->prefix;
237 /* We have to definetly flush the tlb if this scb never ran */
238 if (scb_s->ihcpu != 0xffffU)
239 scb_s->ihcpu = scb_o->ihcpu;
241 /* MVPG and Protection Exception Interpretation are always available */
242 scb_s->eca |= scb_o->eca & 0x01002000U;
244 prepare_ibc(vcpu, vsie_page);
247 unshadow_scb(vcpu, vsie_page);
251 void kvm_s390_vsie_gmap_notifier(struct gmap *gmap, unsigned long start,
254 struct kvm *kvm = gmap->private;
255 struct vsie_page *cur;
256 unsigned long prefix;
260 if (!gmap_is_shadow(gmap))
262 if (start >= 1UL << 31)
263 /* We are only interested in prefix pages */
267 * Only new shadow blocks are added to the list during runtime,
268 * therefore we can safely reference them all the time.
270 for (i = 0; i < kvm->arch.vsie.page_count; i++) {
271 page = READ_ONCE(kvm->arch.vsie.pages[i]);
274 cur = page_to_virt(page);
275 if (READ_ONCE(cur->gmap) != gmap)
277 prefix = cur->scb_s.prefix << GUEST_PREFIX_SHIFT;
278 /* with mso/msl, the prefix lies at an offset */
279 prefix += cur->scb_s.mso;
280 if (prefix <= end && start <= prefix + PAGE_SIZE - 1)
281 prefix_unmapped_sync(cur);
286 * Map the first prefix page.
288 * The prefix will be protected, a gmap notifier will inform about unmaps.
289 * The shadow scb must not be executed until the prefix is remapped, this is
290 * guaranteed by properly handling PROG_REQUEST.
292 * Returns: - 0 on if successfully mapped or already mapped
293 * - > 0 if control has to be given to guest 2
294 * - -EAGAIN if the caller can retry immediately
295 * - -ENOMEM if out of memory
297 static int map_prefix(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
299 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
300 u64 prefix = scb_s->prefix << GUEST_PREFIX_SHIFT;
303 if (prefix_is_mapped(vsie_page))
306 /* mark it as mapped so we can catch any concurrent unmappers */
307 prefix_mapped(vsie_page);
309 /* with mso/msl, the prefix lies at offset *mso* */
310 prefix += scb_s->mso;
312 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, prefix);
314 * We don't have to mprotect, we will be called for all unshadows.
315 * SIE will detect if protection applies and trigger a validity.
318 prefix_unmapped(vsie_page);
319 if (rc > 0 || rc == -EFAULT)
320 rc = set_validity_icpt(scb_s, 0x0037U);
325 * Pin the guest page given by gpa and set hpa to the pinned host address.
326 * Will always be pinned writable.
328 * Returns: - 0 on success
329 * - -EINVAL if the gpa is not valid guest storage
330 * - -ENOMEM if out of memory
332 static int pin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t *hpa)
338 hva = gfn_to_hva(kvm, gpa_to_gfn(gpa));
339 if (kvm_is_error_hva(hva))
341 rc = get_user_pages_fast(hva, 1, 1, &page);
346 *hpa = (hpa_t) page_to_virt(page) + (gpa & ~PAGE_MASK);
350 /* Unpins a page previously pinned via pin_guest_page, marking it as dirty. */
351 static void unpin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t hpa)
355 page = virt_to_page(hpa);
356 set_page_dirty_lock(page);
358 /* mark the page always as dirty for migration */
359 mark_page_dirty(kvm, gpa_to_gfn(gpa));
362 /* unpin all blocks previously pinned by pin_blocks(), marking them dirty */
363 static void unpin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
365 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
366 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
370 hpa = (u64) scb_s->scaoh << 32 | scb_s->scaol;
372 gpa = scb_o->scaol & ~0xfUL;
373 unpin_guest_page(vcpu->kvm, gpa, hpa);
380 * Instead of shadowing some blocks, we can simply forward them because the
381 * addresses in the scb are 64 bit long.
383 * This works as long as the data lies in one page. If blocks ever exceed one
384 * page, we have to fall back to shadowing.
386 * As we reuse the sca, the vcpu pointers contained in it are invalid. We must
387 * therefore not enable any facilities that access these pointers (e.g. SIGPIF).
389 * Returns: - 0 if all blocks were pinned.
390 * - > 0 if control has to be given to guest 2
391 * - -ENOMEM if out of memory
393 static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
395 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
396 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
401 gpa = scb_o->scaol & ~0xfUL;
403 if (!(gpa & ~0x1fffUL))
404 rc = set_validity_icpt(scb_s, 0x0038U);
405 else if ((gpa & ~0x1fffUL) == kvm_s390_get_prefix(vcpu))
406 rc = set_validity_icpt(scb_s, 0x0011U);
407 else if ((gpa & PAGE_MASK) !=
408 ((gpa + sizeof(struct bsca_block) - 1) & PAGE_MASK))
409 rc = set_validity_icpt(scb_s, 0x003bU);
411 rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
413 rc = set_validity_icpt(scb_s, 0x0034U);
417 scb_s->scaoh = (u32)((u64)hpa >> 32);
418 scb_s->scaol = (u32)(u64)hpa;
422 unpin_blocks(vcpu, vsie_page);
426 /* unpin the scb provided by guest 2, marking it as dirty */
427 static void unpin_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,
430 hpa_t hpa = (hpa_t) vsie_page->scb_o;
433 unpin_guest_page(vcpu->kvm, gpa, hpa);
434 vsie_page->scb_o = NULL;
438 * Pin the scb at gpa provided by guest 2 at vsie_page->scb_o.
440 * Returns: - 0 if the scb was pinned.
441 * - > 0 if control has to be given to guest 2
442 * - -ENOMEM if out of memory
444 static int pin_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,
450 rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
452 rc = kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
457 vsie_page->scb_o = (struct kvm_s390_sie_block *) hpa;
462 * Inject a fault into guest 2.
464 * Returns: - > 0 if control has to be given to guest 2
465 * < 0 if an error occurred during injection.
467 static int inject_fault(struct kvm_vcpu *vcpu, __u16 code, __u64 vaddr,
470 struct kvm_s390_pgm_info pgm = {
473 /* 0-51: virtual address */
474 (vaddr & 0xfffffffffffff000UL) |
475 /* 52-53: store / fetch */
476 (((unsigned int) !write_flag) + 1) << 10,
477 /* 62-63: asce id (alway primary == 0) */
478 .exc_access_id = 0, /* always primary */
479 .op_access_id = 0, /* not MVPG */
483 if (code == PGM_PROTECTION)
484 pgm.trans_exc_code |= 0x4UL;
486 rc = kvm_s390_inject_prog_irq(vcpu, &pgm);
491 * Handle a fault during vsie execution on a gmap shadow.
493 * Returns: - 0 if the fault was resolved
494 * - > 0 if control has to be given to guest 2
495 * - < 0 if an error occurred
497 static int handle_fault(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
501 if (current->thread.gmap_int_code == PGM_PROTECTION)
502 /* we can directly forward all protection exceptions */
503 return inject_fault(vcpu, PGM_PROTECTION,
504 current->thread.gmap_addr, 1);
506 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap,
507 current->thread.gmap_addr);
509 rc = inject_fault(vcpu, rc,
510 current->thread.gmap_addr,
511 current->thread.gmap_write_flag);
516 static inline void clear_vsie_icpt(struct vsie_page *vsie_page)
518 vsie_page->scb_s.icptcode = 0;
522 * Run the vsie on a shadow scb and a shadow gmap, without any further
523 * sanity checks, handling SIE faults.
525 * Returns: - 0 everything went fine
526 * - > 0 if control has to be given to guest 2
527 * - < 0 if an error occurred
529 static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
531 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
532 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
537 if (test_cpu_flag(CIF_MCCK_PENDING))
540 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
545 rc = sie64a(scb_s, vcpu->run->s.regs.gprs);
550 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
553 rc = 0; /* we could still have an icpt */
554 else if (rc == -EFAULT)
555 return handle_fault(vcpu, vsie_page);
557 switch (scb_s->icptcode) {
559 /* stop not requested by g2 - must have been a kick */
560 if (!(atomic_read(&scb_o->cpuflags) & CPUSTAT_STOP_INT))
561 clear_vsie_icpt(vsie_page);
564 if ((scb_s->ipa & 0xf000) != 0xf000)
565 scb_s->ipa += 0x1000;
571 static void release_gmap_shadow(struct vsie_page *vsie_page)
574 gmap_put(vsie_page->gmap);
575 WRITE_ONCE(vsie_page->gmap, NULL);
576 prefix_unmapped(vsie_page);
579 static int acquire_gmap_shadow(struct kvm_vcpu *vcpu,
580 struct vsie_page *vsie_page)
587 asce = vcpu->arch.sie_block->gcr[1];
588 cr0.val = vcpu->arch.sie_block->gcr[0];
589 edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8);
590 edat += edat && test_kvm_facility(vcpu->kvm, 78);
593 * ASCE or EDAT could have changed since last icpt, or the gmap
594 * we're holding has been unshadowed. If the gmap is still valid,
595 * we can safely reuse it.
597 if (vsie_page->gmap && gmap_shadow_valid(vsie_page->gmap, asce, edat))
600 /* release the old shadow - if any, and mark the prefix as unmapped */
601 release_gmap_shadow(vsie_page);
602 gmap = gmap_shadow(vcpu->arch.gmap, asce, edat);
604 return PTR_ERR(gmap);
605 gmap->private = vcpu->kvm;
606 WRITE_ONCE(vsie_page->gmap, gmap);
611 * Run the vsie on a shadowed scb, managing the gmap shadow, handling
612 * prefix pages and faults.
614 * Returns: - 0 if no errors occurred
615 * - > 0 if control has to be given to guest 2
616 * - -ENOMEM if out of memory
618 static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
620 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
624 rc = acquire_gmap_shadow(vcpu, vsie_page);
626 rc = map_prefix(vcpu, vsie_page);
628 gmap_enable(vsie_page->gmap);
629 update_intervention_requests(vsie_page);
630 rc = do_vsie_run(vcpu, vsie_page);
631 gmap_enable(vcpu->arch.gmap);
636 if (rc || scb_s->icptcode || signal_pending(current) ||
637 kvm_s390_vcpu_has_irq(vcpu, 0))
643 * Addressing exceptions are always presentes as intercepts.
644 * As addressing exceptions are suppressing and our guest 3 PSW
645 * points at the responsible instruction, we have to
646 * forward the PSW and set the ilc. If we can't read guest 3
647 * instruction, we can use an arbitrary ilc. Let's always use
648 * ilen = 4 for now, so we can avoid reading in guest 3 virtual
649 * memory. (we could also fake the shadow so the hardware
652 scb_s->icptcode = ICPT_PROGI;
653 scb_s->iprcc = PGM_ADDRESSING;
655 scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, 4);
661 * Get or create a vsie page for a scb address.
663 * Returns: - address of a vsie page (cached or new one)
664 * - NULL if the same scb address is already used by another VCPU
665 * - ERR_PTR(-ENOMEM) if out of memory
667 static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
669 struct vsie_page *vsie_page;
674 page = radix_tree_lookup(&kvm->arch.vsie.addr_to_page, addr >> 9);
677 if (page_ref_inc_return(page) == 2)
678 return page_to_virt(page);
683 * We want at least #online_vcpus shadows, so every VCPU can execute
684 * the VSIE in parallel.
686 nr_vcpus = atomic_read(&kvm->online_vcpus);
688 mutex_lock(&kvm->arch.vsie.mutex);
689 if (kvm->arch.vsie.page_count < nr_vcpus) {
690 page = alloc_page(GFP_KERNEL | __GFP_ZERO);
692 mutex_unlock(&kvm->arch.vsie.mutex);
693 return ERR_PTR(-ENOMEM);
696 kvm->arch.vsie.pages[kvm->arch.vsie.page_count] = page;
697 kvm->arch.vsie.page_count++;
699 /* reuse an existing entry that belongs to nobody */
701 page = kvm->arch.vsie.pages[kvm->arch.vsie.next];
702 if (page_ref_inc_return(page) == 2)
705 kvm->arch.vsie.next++;
706 kvm->arch.vsie.next %= nr_vcpus;
708 radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9);
711 /* double use of the same address */
712 if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9, page)) {
714 mutex_unlock(&kvm->arch.vsie.mutex);
717 mutex_unlock(&kvm->arch.vsie.mutex);
719 vsie_page = page_to_virt(page);
720 memset(&vsie_page->scb_s, 0, sizeof(struct kvm_s390_sie_block));
721 release_gmap_shadow(vsie_page);
722 vsie_page->scb_s.ihcpu = 0xffffU;
726 /* put a vsie page acquired via get_vsie_page */
727 static void put_vsie_page(struct kvm *kvm, struct vsie_page *vsie_page)
729 struct page *page = pfn_to_page(__pa(vsie_page) >> PAGE_SHIFT);
734 int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu)
736 struct vsie_page *vsie_page;
737 unsigned long scb_addr;
740 vcpu->stat.instruction_sie++;
741 if (!test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_SIEF2))
743 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
744 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
746 BUILD_BUG_ON(sizeof(struct vsie_page) != 4096);
747 scb_addr = kvm_s390_get_base_disp_s(vcpu, NULL);
749 /* 512 byte alignment */
750 if (unlikely(scb_addr & 0x1ffUL))
751 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
753 if (signal_pending(current) || kvm_s390_vcpu_has_irq(vcpu, 0))
756 vsie_page = get_vsie_page(vcpu->kvm, scb_addr);
757 if (IS_ERR(vsie_page))
758 return PTR_ERR(vsie_page);
760 /* double use of sie control block - simply do nothing */
763 rc = pin_scb(vcpu, vsie_page, scb_addr);
766 rc = shadow_scb(vcpu, vsie_page);
769 rc = pin_blocks(vcpu, vsie_page);
772 rc = vsie_run(vcpu, vsie_page);
773 unpin_blocks(vcpu, vsie_page);
775 unshadow_scb(vcpu, vsie_page);
777 unpin_scb(vcpu, vsie_page, scb_addr);
779 put_vsie_page(vcpu->kvm, vsie_page);
781 return rc < 0 ? rc : 0;
784 /* Init the vsie data structures. To be called when a vm is initialized. */
785 void kvm_s390_vsie_init(struct kvm *kvm)
787 mutex_init(&kvm->arch.vsie.mutex);
788 INIT_RADIX_TREE(&kvm->arch.vsie.addr_to_page, GFP_KERNEL);
791 /* Destroy the vsie data structures. To be called when a vm is destroyed. */
792 void kvm_s390_vsie_destroy(struct kvm *kvm)
794 struct vsie_page *vsie_page;
798 mutex_lock(&kvm->arch.vsie.mutex);
799 for (i = 0; i < kvm->arch.vsie.page_count; i++) {
800 page = kvm->arch.vsie.pages[i];
801 kvm->arch.vsie.pages[i] = NULL;
802 vsie_page = page_to_virt(page);
803 release_gmap_shadow(vsie_page);
804 /* free the radix tree entry */
805 radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9);
808 kvm->arch.vsie.page_count = 0;
809 mutex_unlock(&kvm->arch.vsie.mutex);