• Home
  • Raw
  • Download

Lines Matching +full:ipa +full:- +full:clock +full:- +full:enabled

1 // SPDX-License-Identifier: GPL-2.0
21 #include "kvm-s390.h"
47 __u8 reserved[0x0700 - 0x0258]; /* 0x0258 */
56 scb->ipa = 0x1000; in set_validity_icpt()
57 scb->ipb = ((__u32) reason_code) << 16; in set_validity_icpt()
58 scb->icptcode = ICPT_VALIDITY; in set_validity_icpt()
65 atomic_or(PROG_REQUEST, &vsie_page->scb_s.prog20); in prefix_unmapped()
72 if (vsie_page->scb_s.prog0c & PROG_IN_SIE) in prefix_unmapped_sync()
73 atomic_or(CPUSTAT_STOP_INT, &vsie_page->scb_s.cpuflags); in prefix_unmapped_sync()
74 while (vsie_page->scb_s.prog0c & PROG_IN_SIE) in prefix_unmapped_sync()
81 atomic_andnot(PROG_REQUEST, &vsie_page->scb_s.prog20); in prefix_mapped()
87 return !(atomic_read(&vsie_page->scb_s.prog20) & PROG_REQUEST); in prefix_is_mapped()
96 cpuflags = atomic_read(&vsie_page->scb_o->cpuflags); in update_intervention_requests()
97 atomic_andnot(bits, &vsie_page->scb_s.cpuflags); in update_intervention_requests()
98 atomic_or(cpuflags & bits, &vsie_page->scb_s.cpuflags); in update_intervention_requests()
104 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in prepare_cpuflags()
105 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in prepare_cpuflags()
106 int newflags, cpuflags = atomic_read(&scb_o->cpuflags); in prepare_cpuflags()
119 if (cpuflags & CPUSTAT_GED && test_kvm_facility(vcpu->kvm, 8)) in prepare_cpuflags()
121 if (cpuflags & CPUSTAT_GED2 && test_kvm_facility(vcpu->kvm, 78)) { in prepare_cpuflags()
126 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_GPERE)) in prepare_cpuflags()
128 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_GSLS)) in prepare_cpuflags()
130 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_IBS)) in prepare_cpuflags()
132 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_KSS)) in prepare_cpuflags()
135 atomic_set(&scb_s->cpuflags, newflags); in prepare_cpuflags()
141 * requested for guest 3 and enabled for guest 2.
143 * We only accept format-1 (no AP in g2), but convert it into format-2
144 * There is nothing to do for format-0.
146 * Returns: - 0 if shadowed or nothing to do
147 * - > 0 if control has to be given to guest 2
151 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in shadow_crycb()
152 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in shadow_crycb()
153 const uint32_t crycbd_o = READ_ONCE(scb_o->crycbd); in shadow_crycb()
158 scb_s->crycbd = 0; in shadow_crycb()
159 if (!(crycbd_o & vcpu->arch.sie_block->crycbd & CRYCB_FORMAT1)) in shadow_crycb()
161 /* format-1 is supported with message-security-assist extension 3 */ in shadow_crycb()
162 if (!test_kvm_facility(vcpu->kvm, 76)) in shadow_crycb()
164 /* we may only allow it if enabled for guest 2 */ in shadow_crycb()
165 ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 & in shadow_crycb()
177 vsie_page->crycb.dea_wrapping_key_mask, 56)) in shadow_crycb()
180 scb_s->ecb3 |= ecb3_flags; in shadow_crycb()
181 scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | CRYCB_FORMAT1 | in shadow_crycb()
185 b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask; in shadow_crycb()
187 vcpu->kvm->arch.crypto.crycb->dea_wrapping_key_mask; in shadow_crycb()
196 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in prepare_ibc()
197 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in prepare_ibc()
198 /* READ_ONCE does not work on bitfields - use a temporary variable */ in prepare_ibc()
199 const uint32_t __new_ibc = scb_o->ibc; in prepare_ibc()
203 scb_s->ibc = 0; in prepare_ibc()
205 if (vcpu->kvm->arch.model.ibc && new_ibc) { in prepare_ibc()
206 scb_s->ibc = new_ibc; in prepare_ibc()
208 if (scb_s->ibc < min_ibc) in prepare_ibc()
209 scb_s->ibc = min_ibc; in prepare_ibc()
211 if (scb_s->ibc > vcpu->kvm->arch.model.ibc) in prepare_ibc()
212 scb_s->ibc = vcpu->kvm->arch.model.ibc; in prepare_ibc()
219 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in unshadow_scb()
220 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in unshadow_scb()
223 scb_o->icptcode = scb_s->icptcode; in unshadow_scb()
224 scb_o->icptstatus = scb_s->icptstatus; in unshadow_scb()
225 scb_o->ipa = scb_s->ipa; in unshadow_scb()
226 scb_o->ipb = scb_s->ipb; in unshadow_scb()
227 scb_o->gbea = scb_s->gbea; in unshadow_scb()
230 scb_o->cputm = scb_s->cputm; in unshadow_scb()
231 scb_o->ckc = scb_s->ckc; in unshadow_scb()
232 scb_o->todpr = scb_s->todpr; in unshadow_scb()
235 scb_o->gpsw = scb_s->gpsw; in unshadow_scb()
236 scb_o->gg14 = scb_s->gg14; in unshadow_scb()
237 scb_o->gg15 = scb_s->gg15; in unshadow_scb()
238 memcpy(scb_o->gcr, scb_s->gcr, 128); in unshadow_scb()
239 scb_o->pp = scb_s->pp; in unshadow_scb()
242 if (test_kvm_facility(vcpu->kvm, 82)) { in unshadow_scb()
243 scb_o->fpf &= ~FPF_BPBC; in unshadow_scb()
244 scb_o->fpf |= scb_s->fpf & FPF_BPBC; in unshadow_scb()
248 switch (scb_s->icptcode) { in unshadow_scb()
253 (void *)((u64)scb_s + 0xc0), 0xf0 - 0xc0); in unshadow_scb()
258 (void *)((u64)scb_s + 0xc0), 0xd0 - 0xc0); in unshadow_scb()
262 if (scb_s->ihcpu != 0xffffU) in unshadow_scb()
263 scb_o->ihcpu = scb_s->ihcpu; in unshadow_scb()
270 * Returns: - 0 if the scb has been shadowed
271 * - > 0 if control has to be given to guest 2
275 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in shadow_scb()
276 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in shadow_scb()
277 /* READ_ONCE does not work on bitfields - use a temporary variable */ in shadow_scb()
278 const uint32_t __new_prefix = scb_o->prefix; in shadow_scb()
280 const bool wants_tx = READ_ONCE(scb_o->ecb) & ECB_TE; in shadow_scb()
281 bool had_tx = scb_s->ecb & ECB_TE; in shadow_scb()
286 scb_s->icptcode = 0; in shadow_scb()
287 scb_s->eca = 0; in shadow_scb()
288 scb_s->ecb = 0; in shadow_scb()
289 scb_s->ecb2 = 0; in shadow_scb()
290 scb_s->ecb3 = 0; in shadow_scb()
291 scb_s->ecd = 0; in shadow_scb()
292 scb_s->fac = 0; in shadow_scb()
293 scb_s->fpf = 0; in shadow_scb()
300 scb_s->cputm = scb_o->cputm; in shadow_scb()
301 scb_s->ckc = scb_o->ckc; in shadow_scb()
302 scb_s->todpr = scb_o->todpr; in shadow_scb()
303 scb_s->epoch = scb_o->epoch; in shadow_scb()
306 scb_s->gpsw = scb_o->gpsw; in shadow_scb()
307 scb_s->gg14 = scb_o->gg14; in shadow_scb()
308 scb_s->gg15 = scb_o->gg15; in shadow_scb()
309 memcpy(scb_s->gcr, scb_o->gcr, 128); in shadow_scb()
310 scb_s->pp = scb_o->pp; in shadow_scb()
313 scb_s->gbea = scb_o->gbea; in shadow_scb()
314 scb_s->lctl = scb_o->lctl; in shadow_scb()
315 scb_s->svcc = scb_o->svcc; in shadow_scb()
316 scb_s->ictl = scb_o->ictl; in shadow_scb()
322 if (!(atomic_read(&scb_s->cpuflags) & CPUSTAT_KSS)) in shadow_scb()
323 scb_s->ictl |= ICTL_ISKE | ICTL_SSKE | ICTL_RRBE; in shadow_scb()
325 scb_s->icpua = scb_o->icpua; in shadow_scb()
327 if (!(atomic_read(&scb_s->cpuflags) & CPUSTAT_SM)) in shadow_scb()
328 new_mso = READ_ONCE(scb_o->mso) & 0xfffffffffff00000UL; in shadow_scb()
330 if (scb_s->mso != new_mso || scb_s->prefix != new_prefix) in shadow_scb()
333 scb_s->msl = scb_o->msl & 0xfffffffffff00000UL; in shadow_scb()
334 scb_s->mso = new_mso; in shadow_scb()
335 scb_s->prefix = new_prefix; in shadow_scb()
338 if (scb_s->ihcpu != 0xffffU) in shadow_scb()
339 scb_s->ihcpu = scb_o->ihcpu; in shadow_scb()
342 scb_s->eca |= scb_o->eca & (ECA_MVPGI | ECA_PROTEXCI); in shadow_scb()
343 /* Host-protection-interruption introduced with ESOP */ in shadow_scb()
344 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_ESOP)) in shadow_scb()
345 scb_s->ecb |= scb_o->ecb & ECB_HOSTPROTINT; in shadow_scb()
347 if (test_kvm_facility(vcpu->kvm, 73) && wants_tx) { in shadow_scb()
351 scb_s->ecb |= ECB_TE; in shadow_scb()
354 if (test_kvm_facility(vcpu->kvm, 82)) in shadow_scb()
355 scb_s->fpf |= scb_o->fpf & FPF_BPBC; in shadow_scb()
357 if (test_kvm_facility(vcpu->kvm, 129)) { in shadow_scb()
358 scb_s->eca |= scb_o->eca & ECA_VX; in shadow_scb()
359 scb_s->ecd |= scb_o->ecd & ECD_HOSTREGMGMT; in shadow_scb()
361 /* Run-time-Instrumentation */ in shadow_scb()
362 if (test_kvm_facility(vcpu->kvm, 64)) in shadow_scb()
363 scb_s->ecb3 |= scb_o->ecb3 & ECB3_RI; in shadow_scb()
365 if (test_kvm_facility(vcpu->kvm, 130)) in shadow_scb()
366 scb_s->ecb2 |= scb_o->ecb2 & ECB2_IEP; in shadow_scb()
368 if (test_kvm_facility(vcpu->kvm, 133)) { in shadow_scb()
369 scb_s->ecb |= scb_o->ecb & ECB_GS; in shadow_scb()
370 scb_s->ecd |= scb_o->ecd & ECD_HOSTREGMGMT; in shadow_scb()
372 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_SIIF)) in shadow_scb()
373 scb_s->eca |= scb_o->eca & ECA_SII; in shadow_scb()
374 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_IB)) in shadow_scb()
375 scb_s->eca |= scb_o->eca & ECA_IB; in shadow_scb()
376 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_CEI)) in shadow_scb()
377 scb_s->eca |= scb_o->eca & ECA_CEI; in shadow_scb()
379 if (test_kvm_facility(vcpu->kvm, 139)) in shadow_scb()
380 scb_s->ecd |= scb_o->ecd & ECD_MEF; in shadow_scb()
383 if (test_kvm_facility(vcpu->kvm, 156)) in shadow_scb()
384 scb_s->ecd |= scb_o->ecd & ECD_ETOKENF; in shadow_scb()
397 struct kvm *kvm = gmap->private; in kvm_s390_vsie_gmap_notifier()
413 for (i = 0; i < kvm->arch.vsie.page_count; i++) { in kvm_s390_vsie_gmap_notifier()
414 page = READ_ONCE(kvm->arch.vsie.pages[i]); in kvm_s390_vsie_gmap_notifier()
418 if (READ_ONCE(cur->gmap) != gmap) in kvm_s390_vsie_gmap_notifier()
420 prefix = cur->scb_s.prefix << GUEST_PREFIX_SHIFT; in kvm_s390_vsie_gmap_notifier()
422 prefix += cur->scb_s.mso; in kvm_s390_vsie_gmap_notifier()
423 if (prefix <= end && start <= prefix + 2 * PAGE_SIZE - 1) in kvm_s390_vsie_gmap_notifier()
429 * Map the first prefix page and if tx is enabled also the second prefix page.
435 * Returns: - 0 on if successfully mapped or already mapped
436 * - > 0 if control has to be given to guest 2
437 * - -EAGAIN if the caller can retry immediately
438 * - -ENOMEM if out of memory
442 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in map_prefix()
443 u64 prefix = scb_s->prefix << GUEST_PREFIX_SHIFT; in map_prefix()
453 prefix += scb_s->mso; in map_prefix()
455 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, prefix); in map_prefix()
456 if (!rc && (scb_s->ecb & ECB_TE)) in map_prefix()
457 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, in map_prefix()
465 if (rc > 0 || rc == -EFAULT) in map_prefix()
474 * Returns: - 0 on success
475 * - -EINVAL if the gpa is not valid guest storage
483 return -EINVAL; in pin_guest_page()
499 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in unpin_blocks()
502 hpa = (u64) scb_s->scaoh << 32 | scb_s->scaol; in unpin_blocks()
504 unpin_guest_page(vcpu->kvm, vsie_page->sca_gpa, hpa); in unpin_blocks()
505 vsie_page->sca_gpa = 0; in unpin_blocks()
506 scb_s->scaol = 0; in unpin_blocks()
507 scb_s->scaoh = 0; in unpin_blocks()
510 hpa = scb_s->itdba; in unpin_blocks()
512 unpin_guest_page(vcpu->kvm, vsie_page->itdba_gpa, hpa); in unpin_blocks()
513 vsie_page->itdba_gpa = 0; in unpin_blocks()
514 scb_s->itdba = 0; in unpin_blocks()
517 hpa = scb_s->gvrd; in unpin_blocks()
519 unpin_guest_page(vcpu->kvm, vsie_page->gvrd_gpa, hpa); in unpin_blocks()
520 vsie_page->gvrd_gpa = 0; in unpin_blocks()
521 scb_s->gvrd = 0; in unpin_blocks()
524 hpa = scb_s->riccbd; in unpin_blocks()
526 unpin_guest_page(vcpu->kvm, vsie_page->riccbd_gpa, hpa); in unpin_blocks()
527 vsie_page->riccbd_gpa = 0; in unpin_blocks()
528 scb_s->riccbd = 0; in unpin_blocks()
531 hpa = scb_s->sdnxo; in unpin_blocks()
533 unpin_guest_page(vcpu->kvm, vsie_page->sdnx_gpa, hpa); in unpin_blocks()
534 vsie_page->sdnx_gpa = 0; in unpin_blocks()
535 scb_s->sdnxo = 0; in unpin_blocks()
549 * Returns: - 0 if all blocks were pinned.
550 * - > 0 if control has to be given to guest 2
551 * - -ENOMEM if out of memory
555 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in pin_blocks()
556 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in pin_blocks()
561 gpa = READ_ONCE(scb_o->scaol) & ~0xfUL; in pin_blocks()
562 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_64BSCAO)) in pin_blocks()
563 gpa |= (u64) READ_ONCE(scb_o->scaoh) << 32; in pin_blocks()
570 ((gpa + sizeof(struct bsca_block) - 1) & PAGE_MASK)) in pin_blocks()
573 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
579 vsie_page->sca_gpa = gpa; in pin_blocks()
580 scb_s->scaoh = (u32)((u64)hpa >> 32); in pin_blocks()
581 scb_s->scaol = (u32)(u64)hpa; in pin_blocks()
584 gpa = READ_ONCE(scb_o->itdba) & ~0xffUL; in pin_blocks()
585 if (gpa && (scb_s->ecb & ECB_TE)) { in pin_blocks()
591 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
596 vsie_page->itdba_gpa = gpa; in pin_blocks()
597 scb_s->itdba = hpa; in pin_blocks()
600 gpa = READ_ONCE(scb_o->gvrd) & ~0x1ffUL; in pin_blocks()
601 if (gpa && (scb_s->eca & ECA_VX) && !(scb_s->ecd & ECD_HOSTREGMGMT)) { in pin_blocks()
610 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
615 vsie_page->gvrd_gpa = gpa; in pin_blocks()
616 scb_s->gvrd = hpa; in pin_blocks()
619 gpa = READ_ONCE(scb_o->riccbd) & ~0x3fUL; in pin_blocks()
620 if (gpa && (scb_s->ecb3 & ECB3_RI)) { in pin_blocks()
626 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
632 vsie_page->riccbd_gpa = gpa; in pin_blocks()
633 scb_s->riccbd = hpa; in pin_blocks()
635 if (((scb_s->ecb & ECB_GS) && !(scb_s->ecd & ECD_HOSTREGMGMT)) || in pin_blocks()
636 (scb_s->ecd & ECD_ETOKENF)) { in pin_blocks()
639 gpa = READ_ONCE(scb_o->sdnxo) & ~0xfUL; in pin_blocks()
640 sdnxc = READ_ONCE(scb_o->sdnxo) & 0xfUL; in pin_blocks()
649 if (gpa & ((1 << sdnxc) - 1)) { in pin_blocks()
656 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
661 vsie_page->sdnx_gpa = gpa; in pin_blocks()
662 scb_s->sdnxo = hpa | sdnxc; in pin_blocks()
674 hpa_t hpa = (hpa_t) vsie_page->scb_o; in unpin_scb()
677 unpin_guest_page(vcpu->kvm, gpa, hpa); in unpin_scb()
678 vsie_page->scb_o = NULL; in unpin_scb()
682 * Pin the scb at gpa provided by guest 2 at vsie_page->scb_o.
684 * Returns: - 0 if the scb was pinned.
685 * - > 0 if control has to be given to guest 2
693 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_scb()
699 vsie_page->scb_o = (struct kvm_s390_sie_block *) hpa; in pin_scb()
706 * Returns: - > 0 if control has to be given to guest 2
715 /* 0-51: virtual address */ in inject_fault()
717 /* 52-53: store / fetch */ in inject_fault()
719 /* 62-63: asce id (alway primary == 0) */ in inject_fault()
735 * Returns: - 0 if the fault was resolved
736 * - > 0 if control has to be given to guest 2
737 * - < 0 if an error occurred
743 if (current->thread.gmap_int_code == PGM_PROTECTION) in handle_fault()
746 current->thread.gmap_addr, 1); in handle_fault()
748 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, in handle_fault()
749 current->thread.gmap_addr); in handle_fault()
752 current->thread.gmap_addr, in handle_fault()
753 current->thread.gmap_write_flag); in handle_fault()
755 vsie_page->fault_addr = current->thread.gmap_addr; in handle_fault()
762 * one superfluous SIE re-entry and direct exit.
769 if (vsie_page->fault_addr) in handle_last_fault()
770 kvm_s390_shadow_fault(vcpu, vsie_page->gmap, in handle_last_fault()
771 vsie_page->fault_addr); in handle_last_fault()
772 vsie_page->fault_addr = 0; in handle_last_fault()
777 vsie_page->scb_s.icptcode = 0; in clear_vsie_icpt()
783 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in retry_vsie_icpt()
784 int ilen = insn_length(scb_s->ipa >> 8); in retry_vsie_icpt()
787 if (scb_s->icptstatus & 1) { in retry_vsie_icpt()
788 ilen = (scb_s->icptstatus >> 4) & 0x6; in retry_vsie_icpt()
792 scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, ilen); in retry_vsie_icpt()
798 * Retry instruction execution if enabled for and provided by guest 2.
800 * Returns: - 0 if handled (retry or guest 2 icpt)
801 * - > 0 if control has to be given to guest 2
805 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in handle_stfle()
806 __u32 fac = READ_ONCE(vsie_page->scb_o->fac) & 0x7ffffff8U; in handle_stfle()
808 if (fac && test_kvm_facility(vcpu->kvm, 7)) { in handle_stfle()
810 if (read_guest_real(vcpu, fac, &vsie_page->fac, in handle_stfle()
811 sizeof(vsie_page->fac))) in handle_stfle()
813 scb_s->fac = (__u32)(__u64) &vsie_page->fac; in handle_stfle()
822 * Returns: - 0 everything went fine
823 * - > 0 if control has to be given to guest 2
824 * - < 0 if an error occurred
827 __releases(vcpu->kvm->srcu) in do_vsie_run()
828 __acquires(vcpu->kvm->srcu) in do_vsie_run()
830 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in do_vsie_run()
831 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in do_vsie_run()
842 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); in do_vsie_run()
853 if (test_kvm_facility(vcpu->kvm, 82) && in do_vsie_run()
854 vcpu->arch.sie_block->fpf & FPF_BPBC) in do_vsie_run()
861 rc = sie64a(scb_s, vcpu->run->s.regs.gprs); in do_vsie_run()
871 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); in do_vsie_run()
873 if (rc == -EINTR) { in do_vsie_run()
875 kvm_s390_reinject_machine_check(vcpu, &vsie_page->mcck_info); in do_vsie_run()
881 else if (rc == -EFAULT) in do_vsie_run()
884 switch (scb_s->icptcode) { in do_vsie_run()
886 if (scb_s->ipa == 0xb2b0) in do_vsie_run()
890 /* stop not requested by g2 - must have been a kick */ in do_vsie_run()
891 if (!(atomic_read(&scb_o->cpuflags) & CPUSTAT_STOP_INT)) in do_vsie_run()
895 if ((scb_s->ipa & 0xf000) != 0xf000) in do_vsie_run()
896 scb_s->ipa += 0x1000; in do_vsie_run()
904 if (vsie_page->gmap) in release_gmap_shadow()
905 gmap_put(vsie_page->gmap); in release_gmap_shadow()
906 WRITE_ONCE(vsie_page->gmap, NULL); in release_gmap_shadow()
918 asce = vcpu->arch.sie_block->gcr[1]; in acquire_gmap_shadow()
919 cr0.val = vcpu->arch.sie_block->gcr[0]; in acquire_gmap_shadow()
920 edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8); in acquire_gmap_shadow()
921 edat += edat && test_kvm_facility(vcpu->kvm, 78); in acquire_gmap_shadow()
928 if (vsie_page->gmap && gmap_shadow_valid(vsie_page->gmap, asce, edat)) in acquire_gmap_shadow()
931 /* release the old shadow - if any, and mark the prefix as unmapped */ in acquire_gmap_shadow()
933 gmap = gmap_shadow(vcpu->arch.gmap, asce, edat); in acquire_gmap_shadow()
936 gmap->private = vcpu->kvm; in acquire_gmap_shadow()
937 WRITE_ONCE(vsie_page->gmap, gmap); in acquire_gmap_shadow()
947 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in register_shadow_scb()
949 WRITE_ONCE(vcpu->arch.vsie_block, &vsie_page->scb_s); in register_shadow_scb()
952 * therefore the vsie -> Simulate Wait state. in register_shadow_scb()
957 * automatically be adjusted on tod clock changes via kvm_sync_clock. in register_shadow_scb()
960 scb_s->epoch += vcpu->kvm->arch.epoch; in register_shadow_scb()
962 if (scb_s->ecd & ECD_MEF) { in register_shadow_scb()
963 scb_s->epdx += vcpu->kvm->arch.epdx; in register_shadow_scb()
964 if (scb_s->epoch < vcpu->kvm->arch.epoch) in register_shadow_scb()
965 scb_s->epdx += 1; in register_shadow_scb()
977 WRITE_ONCE(vcpu->arch.vsie_block, NULL); in unregister_shadow_scb()
984 * Returns: - 0 if no errors occurred
985 * - > 0 if control has to be given to guest 2
986 * - -ENOMEM if out of memory
990 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in vsie_run()
998 gmap_enable(vsie_page->gmap); in vsie_run()
1001 gmap_enable(vcpu->arch.gmap); in vsie_run()
1003 atomic_andnot(PROG_BLOCK_SIE, &scb_s->prog20); in vsie_run()
1005 if (rc == -EAGAIN) in vsie_run()
1007 if (rc || scb_s->icptcode || signal_pending(current) || in vsie_run()
1012 if (rc == -EFAULT) { in vsie_run()
1023 scb_s->icptcode = ICPT_PROGI; in vsie_run()
1024 scb_s->iprcc = PGM_ADDRESSING; in vsie_run()
1025 scb_s->pgmilc = 4; in vsie_run()
1026 scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, 4); in vsie_run()
1035 * Returns: - address of a vsie page (cached or new one)
1036 * - NULL if the same scb address is already used by another VCPU
1037 * - ERR_PTR(-ENOMEM) if out of memory
1046 page = radix_tree_lookup(&kvm->arch.vsie.addr_to_page, addr >> 9); in get_vsie_page()
1058 nr_vcpus = atomic_read(&kvm->online_vcpus); in get_vsie_page()
1060 mutex_lock(&kvm->arch.vsie.mutex); in get_vsie_page()
1061 if (kvm->arch.vsie.page_count < nr_vcpus) { in get_vsie_page()
1064 mutex_unlock(&kvm->arch.vsie.mutex); in get_vsie_page()
1065 return ERR_PTR(-ENOMEM); in get_vsie_page()
1068 kvm->arch.vsie.pages[kvm->arch.vsie.page_count] = page; in get_vsie_page()
1069 kvm->arch.vsie.page_count++; in get_vsie_page()
1073 page = kvm->arch.vsie.pages[kvm->arch.vsie.next]; in get_vsie_page()
1077 kvm->arch.vsie.next++; in get_vsie_page()
1078 kvm->arch.vsie.next %= nr_vcpus; in get_vsie_page()
1080 radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9); in get_vsie_page()
1082 page->index = addr; in get_vsie_page()
1084 if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9, page)) { in get_vsie_page()
1086 mutex_unlock(&kvm->arch.vsie.mutex); in get_vsie_page()
1089 mutex_unlock(&kvm->arch.vsie.mutex); in get_vsie_page()
1092 memset(&vsie_page->scb_s, 0, sizeof(struct kvm_s390_sie_block)); in get_vsie_page()
1094 vsie_page->fault_addr = 0; in get_vsie_page()
1095 vsie_page->scb_s.ihcpu = 0xffffU; in get_vsie_page()
1113 vcpu->stat.instruction_sie++; in kvm_s390_handle_vsie()
1114 if (!test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_SIEF2)) in kvm_s390_handle_vsie()
1115 return -EOPNOTSUPP; in kvm_s390_handle_vsie()
1116 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) in kvm_s390_handle_vsie()
1129 vsie_page = get_vsie_page(vcpu->kvm, scb_addr); in kvm_s390_handle_vsie()
1133 /* double use of sie control block - simply do nothing */ in kvm_s390_handle_vsie()
1154 put_vsie_page(vcpu->kvm, vsie_page); in kvm_s390_handle_vsie()
1162 mutex_init(&kvm->arch.vsie.mutex); in kvm_s390_vsie_init()
1163 INIT_RADIX_TREE(&kvm->arch.vsie.addr_to_page, GFP_KERNEL); in kvm_s390_vsie_init()
1173 mutex_lock(&kvm->arch.vsie.mutex); in kvm_s390_vsie_destroy()
1174 for (i = 0; i < kvm->arch.vsie.page_count; i++) { in kvm_s390_vsie_destroy()
1175 page = kvm->arch.vsie.pages[i]; in kvm_s390_vsie_destroy()
1176 kvm->arch.vsie.pages[i] = NULL; in kvm_s390_vsie_destroy()
1180 radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9); in kvm_s390_vsie_destroy()
1183 kvm->arch.vsie.page_count = 0; in kvm_s390_vsie_destroy()
1184 mutex_unlock(&kvm->arch.vsie.mutex); in kvm_s390_vsie_destroy()
1189 struct kvm_s390_sie_block *scb = READ_ONCE(vcpu->arch.vsie_block); in kvm_s390_vsie_kick()
1196 atomic_or(PROG_BLOCK_SIE, &scb->prog20); in kvm_s390_vsie_kick()
1197 if (scb->prog0c & PROG_IN_SIE) in kvm_s390_vsie_kick()
1198 atomic_or(CPUSTAT_STOP_INT, &scb->cpuflags); in kvm_s390_vsie_kick()