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

1 // SPDX-License-Identifier: GPL-2.0
24 #include "kvm-s390.h"
66 __u8 reserved[0x0700 - 0x0268]; /* 0x0268 */
75 scb->ipa = 0x1000; in set_validity_icpt()
76 scb->ipb = ((__u32) reason_code) << 16; in set_validity_icpt()
77 scb->icptcode = ICPT_VALIDITY; in set_validity_icpt()
84 atomic_or(PROG_REQUEST, &vsie_page->scb_s.prog20); in prefix_unmapped()
91 if (vsie_page->scb_s.prog0c & PROG_IN_SIE) in prefix_unmapped_sync()
92 atomic_or(CPUSTAT_STOP_INT, &vsie_page->scb_s.cpuflags); in prefix_unmapped_sync()
93 while (vsie_page->scb_s.prog0c & PROG_IN_SIE) in prefix_unmapped_sync()
100 atomic_andnot(PROG_REQUEST, &vsie_page->scb_s.prog20); in prefix_mapped()
106 return !(atomic_read(&vsie_page->scb_s.prog20) & PROG_REQUEST); in prefix_is_mapped()
115 cpuflags = atomic_read(&vsie_page->scb_o->cpuflags); in update_intervention_requests()
116 atomic_andnot(bits, &vsie_page->scb_s.cpuflags); in update_intervention_requests()
117 atomic_or(cpuflags & bits, &vsie_page->scb_s.cpuflags); in update_intervention_requests()
123 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in prepare_cpuflags()
124 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in prepare_cpuflags()
125 int newflags, cpuflags = atomic_read(&scb_o->cpuflags); in prepare_cpuflags()
138 if (cpuflags & CPUSTAT_GED && test_kvm_facility(vcpu->kvm, 8)) in prepare_cpuflags()
140 if (cpuflags & CPUSTAT_GED2 && test_kvm_facility(vcpu->kvm, 78)) { in prepare_cpuflags()
145 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_GPERE)) in prepare_cpuflags()
147 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_GSLS)) in prepare_cpuflags()
149 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_IBS)) in prepare_cpuflags()
151 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_KSS)) in prepare_cpuflags()
154 atomic_set(&scb_s->cpuflags, newflags); in prepare_cpuflags()
168 return -EFAULT; in setup_apcb10()
170 apcb_s->apm[0] = apcb_h->apm[0] & tmp.apm[0]; in setup_apcb10()
171 apcb_s->aqm[0] = apcb_h->aqm[0] & tmp.aqm[0] & 0xffff000000000000UL; in setup_apcb10()
172 apcb_s->adm[0] = apcb_h->adm[0] & tmp.adm[0] & 0xffff000000000000UL; in setup_apcb10()
179 * setup_apcb00 - Copy to APCB FORMAT0 from APCB FORMAT0
185 * Returns 0 and -EFAULT on error reading guest apcb
196 return -EFAULT; in setup_apcb00()
205 * setup_apcb11 - Copy the FORMAT1 APCB from the guest to the shadow CRYCB
211 * Returns 0 and -EFAULT on error reading guest apcb
223 return -EFAULT; in setup_apcb11()
232 * setup_apcb - Create a shadow copy of the apcb.
253 return -EACCES; in setup_apcb()
255 return -EINVAL; in setup_apcb()
256 return setup_apcb11(vcpu, (unsigned long *)&crycb_s->apcb1, in setup_apcb()
258 (unsigned long *)&crycb_h->apcb1); in setup_apcb()
262 return setup_apcb10(vcpu, &crycb_s->apcb1, in setup_apcb()
264 &crycb_h->apcb1); in setup_apcb()
267 (unsigned long *) &crycb_s->apcb0, in setup_apcb()
269 (unsigned long *) &crycb_h->apcb0); in setup_apcb()
274 return -EACCES; in setup_apcb()
278 return setup_apcb10(vcpu, &crycb_s->apcb1, in setup_apcb()
280 &crycb_h->apcb1); in setup_apcb()
284 (unsigned long *) &crycb_s->apcb0, in setup_apcb()
286 (unsigned long *) &crycb_h->apcb0); in setup_apcb()
289 return -EINVAL; in setup_apcb()
293 * shadow_crycb - Create a shadow copy of the crycb block
298 * requested for guest 3 and enabled for guest 2.
300 * We accept format-1 or format-2, but we convert format-1 into format-2
302 * Using format-2 enables the firmware to choose the right format when
304 * There is nothing to do for format-0.
309 * Returns: - 0 if shadowed or nothing to do
310 * - > 0 if control has to be given to guest 2
314 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in shadow_crycb()
315 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in shadow_crycb()
316 const uint32_t crycbd_o = READ_ONCE(scb_o->crycbd); in shadow_crycb()
323 int key_msk = test_kvm_facility(vcpu->kvm, 76); in shadow_crycb()
325 int fmt_h = vcpu->arch.sie_block->crycbd & CRYCB_FORMAT_MASK; in shadow_crycb()
328 scb_s->crycbd = 0; in shadow_crycb()
330 apie_h = vcpu->arch.sie_block->eca & ECA_APIE; in shadow_crycb()
331 apie_s = apie_h & scb_o->eca; in shadow_crycb()
344 ret = setup_apcb(vcpu, &vsie_page->crycb, crycb_addr, in shadow_crycb()
345 vcpu->kvm->arch.crypto.crycb, in shadow_crycb()
349 scb_s->eca |= scb_o->eca & ECA_APIE; in shadow_crycb()
352 /* we may only allow it if enabled for guest 2 */ in shadow_crycb()
353 ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 & in shadow_crycb()
355 ecd_flags = scb_o->ecd & vcpu->arch.sie_block->ecd & in shadow_crycb()
362 vsie_page->crycb.dea_wrapping_key_mask, 56)) in shadow_crycb()
365 scb_s->ecb3 |= ecb3_flags; in shadow_crycb()
366 scb_s->ecd |= ecd_flags; in shadow_crycb()
369 b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask; in shadow_crycb()
371 vcpu->kvm->arch.crypto.crycb->dea_wrapping_key_mask; in shadow_crycb()
376 case -EINVAL: in shadow_crycb()
378 case -EFAULT: in shadow_crycb()
380 case -EACCES: in shadow_crycb()
383 scb_s->crycbd = (u32)virt_to_phys(&vsie_page->crycb) | CRYCB_FORMAT2; in shadow_crycb()
390 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in prepare_ibc()
391 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in prepare_ibc()
392 /* READ_ONCE does not work on bitfields - use a temporary variable */ in prepare_ibc()
393 const uint32_t __new_ibc = scb_o->ibc; in prepare_ibc()
397 scb_s->ibc = 0; in prepare_ibc()
399 if (vcpu->kvm->arch.model.ibc && new_ibc) { in prepare_ibc()
400 scb_s->ibc = new_ibc; in prepare_ibc()
402 if (scb_s->ibc < min_ibc) in prepare_ibc()
403 scb_s->ibc = min_ibc; in prepare_ibc()
405 if (scb_s->ibc > vcpu->kvm->arch.model.ibc) in prepare_ibc()
406 scb_s->ibc = vcpu->kvm->arch.model.ibc; in prepare_ibc()
413 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in unshadow_scb()
414 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in unshadow_scb()
417 scb_o->icptcode = scb_s->icptcode; in unshadow_scb()
418 scb_o->icptstatus = scb_s->icptstatus; in unshadow_scb()
419 scb_o->ipa = scb_s->ipa; in unshadow_scb()
420 scb_o->ipb = scb_s->ipb; in unshadow_scb()
421 scb_o->gbea = scb_s->gbea; in unshadow_scb()
424 scb_o->cputm = scb_s->cputm; in unshadow_scb()
425 scb_o->ckc = scb_s->ckc; in unshadow_scb()
426 scb_o->todpr = scb_s->todpr; in unshadow_scb()
429 scb_o->gpsw = scb_s->gpsw; in unshadow_scb()
430 scb_o->gg14 = scb_s->gg14; in unshadow_scb()
431 scb_o->gg15 = scb_s->gg15; in unshadow_scb()
432 memcpy(scb_o->gcr, scb_s->gcr, 128); in unshadow_scb()
433 scb_o->pp = scb_s->pp; in unshadow_scb()
436 if (test_kvm_facility(vcpu->kvm, 82)) { in unshadow_scb()
437 scb_o->fpf &= ~FPF_BPBC; in unshadow_scb()
438 scb_o->fpf |= scb_s->fpf & FPF_BPBC; in unshadow_scb()
442 switch (scb_s->icptcode) { in unshadow_scb()
447 (void *)((u64)scb_s + 0xc0), 0xf0 - 0xc0); in unshadow_scb()
451 if (scb_s->ihcpu != 0xffffU) in unshadow_scb()
452 scb_o->ihcpu = scb_s->ihcpu; in unshadow_scb()
459 * Returns: - 0 if the scb has been shadowed
460 * - > 0 if control has to be given to guest 2
464 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in shadow_scb()
465 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in shadow_scb()
466 /* READ_ONCE does not work on bitfields - use a temporary variable */ in shadow_scb()
467 const uint32_t __new_prefix = scb_o->prefix; in shadow_scb()
469 const bool wants_tx = READ_ONCE(scb_o->ecb) & ECB_TE; in shadow_scb()
470 bool had_tx = scb_s->ecb & ECB_TE; in shadow_scb()
475 scb_s->icptcode = 0; in shadow_scb()
476 scb_s->eca = 0; in shadow_scb()
477 scb_s->ecb = 0; in shadow_scb()
478 scb_s->ecb2 = 0; in shadow_scb()
479 scb_s->ecb3 = 0; in shadow_scb()
480 scb_s->ecd = 0; in shadow_scb()
481 scb_s->fac = 0; in shadow_scb()
482 scb_s->fpf = 0; in shadow_scb()
489 scb_s->cputm = scb_o->cputm; in shadow_scb()
490 scb_s->ckc = scb_o->ckc; in shadow_scb()
491 scb_s->todpr = scb_o->todpr; in shadow_scb()
492 scb_s->epoch = scb_o->epoch; in shadow_scb()
495 scb_s->gpsw = scb_o->gpsw; in shadow_scb()
496 scb_s->gg14 = scb_o->gg14; in shadow_scb()
497 scb_s->gg15 = scb_o->gg15; in shadow_scb()
498 memcpy(scb_s->gcr, scb_o->gcr, 128); in shadow_scb()
499 scb_s->pp = scb_o->pp; in shadow_scb()
502 scb_s->gbea = scb_o->gbea; in shadow_scb()
503 scb_s->lctl = scb_o->lctl; in shadow_scb()
504 scb_s->svcc = scb_o->svcc; in shadow_scb()
505 scb_s->ictl = scb_o->ictl; in shadow_scb()
511 if (!(atomic_read(&scb_s->cpuflags) & CPUSTAT_KSS)) in shadow_scb()
512 scb_s->ictl |= ICTL_ISKE | ICTL_SSKE | ICTL_RRBE; in shadow_scb()
514 scb_s->icpua = scb_o->icpua; in shadow_scb()
516 if (!(atomic_read(&scb_s->cpuflags) & CPUSTAT_SM)) in shadow_scb()
517 new_mso = READ_ONCE(scb_o->mso) & 0xfffffffffff00000UL; in shadow_scb()
519 if (scb_s->mso != new_mso || scb_s->prefix != new_prefix) in shadow_scb()
522 scb_s->msl = scb_o->msl & 0xfffffffffff00000UL; in shadow_scb()
523 scb_s->mso = new_mso; in shadow_scb()
524 scb_s->prefix = new_prefix; in shadow_scb()
527 if (scb_s->ihcpu != 0xffffU) in shadow_scb()
528 scb_s->ihcpu = scb_o->ihcpu; in shadow_scb()
531 scb_s->eca |= scb_o->eca & (ECA_MVPGI | ECA_PROTEXCI); in shadow_scb()
532 /* Host-protection-interruption introduced with ESOP */ in shadow_scb()
533 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_ESOP)) in shadow_scb()
534 scb_s->ecb |= scb_o->ecb & ECB_HOSTPROTINT; in shadow_scb()
541 if (test_kvm_facility(vcpu->kvm, 11)) in shadow_scb()
542 scb_s->ecb |= scb_o->ecb & ECB_PTF; in shadow_scb()
544 if (test_kvm_facility(vcpu->kvm, 73) && wants_tx) { in shadow_scb()
548 scb_s->ecb |= ECB_TE; in shadow_scb()
551 scb_s->ecb |= scb_o->ecb & ECB_SPECI; in shadow_scb()
553 if (test_kvm_facility(vcpu->kvm, 82)) in shadow_scb()
554 scb_s->fpf |= scb_o->fpf & FPF_BPBC; in shadow_scb()
556 if (test_kvm_facility(vcpu->kvm, 129)) { in shadow_scb()
557 scb_s->eca |= scb_o->eca & ECA_VX; in shadow_scb()
558 scb_s->ecd |= scb_o->ecd & ECD_HOSTREGMGMT; in shadow_scb()
560 /* Run-time-Instrumentation */ in shadow_scb()
561 if (test_kvm_facility(vcpu->kvm, 64)) in shadow_scb()
562 scb_s->ecb3 |= scb_o->ecb3 & ECB3_RI; in shadow_scb()
564 if (test_kvm_facility(vcpu->kvm, 130)) in shadow_scb()
565 scb_s->ecb2 |= scb_o->ecb2 & ECB2_IEP; in shadow_scb()
567 if (test_kvm_facility(vcpu->kvm, 133)) { in shadow_scb()
568 scb_s->ecb |= scb_o->ecb & ECB_GS; in shadow_scb()
569 scb_s->ecd |= scb_o->ecd & ECD_HOSTREGMGMT; in shadow_scb()
571 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_SIIF)) in shadow_scb()
572 scb_s->eca |= scb_o->eca & ECA_SII; in shadow_scb()
573 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_IB)) in shadow_scb()
574 scb_s->eca |= scb_o->eca & ECA_IB; in shadow_scb()
575 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_CEI)) in shadow_scb()
576 scb_s->eca |= scb_o->eca & ECA_CEI; in shadow_scb()
578 if (test_kvm_facility(vcpu->kvm, 139)) { in shadow_scb()
579 scb_s->ecd |= scb_o->ecd & ECD_MEF; in shadow_scb()
580 scb_s->epdx = scb_o->epdx; in shadow_scb()
584 if (test_kvm_facility(vcpu->kvm, 156)) in shadow_scb()
585 scb_s->ecd |= scb_o->ecd & ECD_ETOKENF; in shadow_scb()
587 scb_s->hpid = HPID_VSIE; in shadow_scb()
588 scb_s->cpnc = scb_o->cpnc; in shadow_scb()
601 struct kvm *kvm = gmap->private; in kvm_s390_vsie_gmap_notifier()
612 for (i = 0; i < kvm->arch.vsie.page_count; i++) { in kvm_s390_vsie_gmap_notifier()
613 cur = READ_ONCE(kvm->arch.vsie.pages[i]); in kvm_s390_vsie_gmap_notifier()
616 if (READ_ONCE(cur->gmap) != gmap) in kvm_s390_vsie_gmap_notifier()
618 prefix = cur->scb_s.prefix << GUEST_PREFIX_SHIFT; in kvm_s390_vsie_gmap_notifier()
620 prefix += cur->scb_s.mso; in kvm_s390_vsie_gmap_notifier()
621 if (prefix <= end && start <= prefix + 2 * PAGE_SIZE - 1) in kvm_s390_vsie_gmap_notifier()
627 * Map the first prefix page and if tx is enabled also the second prefix page.
633 * Returns: - 0 on if successfully mapped or already mapped
634 * - > 0 if control has to be given to guest 2
635 * - -EAGAIN if the caller can retry immediately
636 * - -ENOMEM if out of memory
640 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in map_prefix()
641 u64 prefix = scb_s->prefix << GUEST_PREFIX_SHIFT; in map_prefix()
651 prefix += scb_s->mso; in map_prefix()
653 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, prefix, NULL); in map_prefix()
654 if (!rc && (scb_s->ecb & ECB_TE)) in map_prefix()
655 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, in map_prefix()
663 if (rc > 0 || rc == -EFAULT) in map_prefix()
672 * Returns: - 0 on success
673 * - -EINVAL if the gpa is not valid guest storage
681 return -EINVAL; in pin_guest_page()
697 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in unpin_blocks()
700 hpa = (u64) scb_s->scaoh << 32 | scb_s->scaol; in unpin_blocks()
702 unpin_guest_page(vcpu->kvm, vsie_page->sca_gpa, hpa); in unpin_blocks()
703 vsie_page->sca_gpa = 0; in unpin_blocks()
704 scb_s->scaol = 0; in unpin_blocks()
705 scb_s->scaoh = 0; in unpin_blocks()
708 hpa = scb_s->itdba; in unpin_blocks()
710 unpin_guest_page(vcpu->kvm, vsie_page->itdba_gpa, hpa); in unpin_blocks()
711 vsie_page->itdba_gpa = 0; in unpin_blocks()
712 scb_s->itdba = 0; in unpin_blocks()
715 hpa = scb_s->gvrd; in unpin_blocks()
717 unpin_guest_page(vcpu->kvm, vsie_page->gvrd_gpa, hpa); in unpin_blocks()
718 vsie_page->gvrd_gpa = 0; in unpin_blocks()
719 scb_s->gvrd = 0; in unpin_blocks()
722 hpa = scb_s->riccbd; in unpin_blocks()
724 unpin_guest_page(vcpu->kvm, vsie_page->riccbd_gpa, hpa); in unpin_blocks()
725 vsie_page->riccbd_gpa = 0; in unpin_blocks()
726 scb_s->riccbd = 0; in unpin_blocks()
729 hpa = scb_s->sdnxo; in unpin_blocks()
731 unpin_guest_page(vcpu->kvm, vsie_page->sdnx_gpa, hpa); in unpin_blocks()
732 vsie_page->sdnx_gpa = 0; in unpin_blocks()
733 scb_s->sdnxo = 0; in unpin_blocks()
747 * Returns: - 0 if all blocks were pinned.
748 * - > 0 if control has to be given to guest 2
749 * - -ENOMEM if out of memory
753 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in pin_blocks()
754 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in pin_blocks()
759 gpa = READ_ONCE(scb_o->scaol) & ~0xfUL; in pin_blocks()
760 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_64BSCAO)) in pin_blocks()
761 gpa |= (u64) READ_ONCE(scb_o->scaoh) << 32; in pin_blocks()
768 ((gpa + sizeof(struct bsca_block) - 1) & PAGE_MASK)) in pin_blocks()
771 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
777 vsie_page->sca_gpa = gpa; in pin_blocks()
778 scb_s->scaoh = (u32)((u64)hpa >> 32); in pin_blocks()
779 scb_s->scaol = (u32)(u64)hpa; in pin_blocks()
782 gpa = READ_ONCE(scb_o->itdba) & ~0xffUL; in pin_blocks()
783 if (gpa && (scb_s->ecb & ECB_TE)) { in pin_blocks()
789 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
794 vsie_page->itdba_gpa = gpa; in pin_blocks()
795 scb_s->itdba = hpa; in pin_blocks()
798 gpa = READ_ONCE(scb_o->gvrd) & ~0x1ffUL; in pin_blocks()
799 if (gpa && (scb_s->eca & ECA_VX) && !(scb_s->ecd & ECD_HOSTREGMGMT)) { in pin_blocks()
808 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
813 vsie_page->gvrd_gpa = gpa; in pin_blocks()
814 scb_s->gvrd = hpa; in pin_blocks()
817 gpa = READ_ONCE(scb_o->riccbd) & ~0x3fUL; in pin_blocks()
818 if (gpa && (scb_s->ecb3 & ECB3_RI)) { in pin_blocks()
824 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
830 vsie_page->riccbd_gpa = gpa; in pin_blocks()
831 scb_s->riccbd = hpa; in pin_blocks()
833 if (((scb_s->ecb & ECB_GS) && !(scb_s->ecd & ECD_HOSTREGMGMT)) || in pin_blocks()
834 (scb_s->ecd & ECD_ETOKENF)) { in pin_blocks()
837 gpa = READ_ONCE(scb_o->sdnxo) & ~0xfUL; in pin_blocks()
838 sdnxc = READ_ONCE(scb_o->sdnxo) & 0xfUL; in pin_blocks()
847 if (gpa & ((1 << sdnxc) - 1)) { in pin_blocks()
854 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
859 vsie_page->sdnx_gpa = gpa; in pin_blocks()
860 scb_s->sdnxo = hpa | sdnxc; in pin_blocks()
872 hpa_t hpa = virt_to_phys(vsie_page->scb_o); in unpin_scb()
875 unpin_guest_page(vcpu->kvm, gpa, hpa); in unpin_scb()
876 vsie_page->scb_o = NULL; in unpin_scb()
880 * Pin the scb at gpa provided by guest 2 at vsie_page->scb_o.
882 * Returns: - 0 if the scb was pinned.
883 * - > 0 if control has to be given to guest 2
891 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_scb()
897 vsie_page->scb_o = phys_to_virt(hpa); in pin_scb()
904 * Returns: - > 0 if control has to be given to guest 2
913 /* 0-51: virtual address */ in inject_fault()
915 /* 52-53: store / fetch */ in inject_fault()
917 /* 62-63: asce id (always primary == 0) */ in inject_fault()
933 * Returns: - 0 if the fault was resolved
934 * - > 0 if control has to be given to guest 2
935 * - < 0 if an error occurred
941 if ((current->thread.gmap_int_code & PGM_INT_CODE_MASK) == PGM_PROTECTION) in handle_fault()
944 current->thread.gmap_teid.addr * PAGE_SIZE, 1); in handle_fault()
946 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, in handle_fault()
947 current->thread.gmap_teid.addr * PAGE_SIZE, NULL); in handle_fault()
950 current->thread.gmap_teid.addr * PAGE_SIZE, in handle_fault()
953 vsie_page->fault_addr = current->thread.gmap_teid.addr * PAGE_SIZE; in handle_fault()
960 * one superfluous SIE re-entry and direct exit.
967 if (vsie_page->fault_addr) in handle_last_fault()
968 kvm_s390_shadow_fault(vcpu, vsie_page->gmap, in handle_last_fault()
969 vsie_page->fault_addr, NULL); in handle_last_fault()
970 vsie_page->fault_addr = 0; in handle_last_fault()
975 vsie_page->scb_s.icptcode = 0; in clear_vsie_icpt()
981 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in retry_vsie_icpt()
982 int ilen = insn_length(scb_s->ipa >> 8); in retry_vsie_icpt()
985 if (scb_s->icptstatus & 1) { in retry_vsie_icpt()
986 ilen = (scb_s->icptstatus >> 4) & 0x6; in retry_vsie_icpt()
990 scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, ilen); in retry_vsie_icpt()
996 * Retry instruction execution if enabled for and provided by guest 2.
998 * Returns: - 0 if handled (retry or guest 2 icpt)
999 * - > 0 if control has to be given to guest 2
1003 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in handle_stfle()
1004 __u32 fac = READ_ONCE(vsie_page->scb_o->fac); in handle_stfle()
1007 * Alternate-STFLE-Interpretive-Execution facilities are not supported in handle_stfle()
1008 * -> format-0 flcb in handle_stfle()
1010 if (fac && test_kvm_facility(vcpu->kvm, 7)) { in handle_stfle()
1013 * The facility list origin (FLO) is in bits 1 - 28 of the FLD in handle_stfle()
1018 * format-0 -> size of nested guest's facility list == guest's size in handle_stfle()
1020 * using a format-0 for the guest, too. in handle_stfle()
1022 if (read_guest_real(vcpu, fac, &vsie_page->fac, in handle_stfle()
1025 scb_s->fac = (u32)virt_to_phys(&vsie_page->fac); in handle_stfle()
1043 return vsie_page->scb_s.gg15; in vsie_get_register()
1045 return vsie_page->scb_s.gg14; in vsie_get_register()
1047 return vcpu->run->s.regs.gprs[reg]; in vsie_get_register()
1053 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in vsie_handle_mvpg()
1055 u64 *pei_block = &vsie_page->scb_o->mcic; in vsie_handle_mvpg()
1059 cr0.val = vcpu->arch.sie_block->gcr[0]; in vsie_handle_mvpg()
1060 edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8); in vsie_handle_mvpg()
1061 mask = _kvm_s390_logical_to_effective(&scb_s->gpsw, PAGE_MASK); in vsie_handle_mvpg()
1062 prefix = scb_s->prefix << GUEST_PREFIX_SHIFT; in vsie_handle_mvpg()
1064 dest = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 20) & mask; in vsie_handle_mvpg()
1065 dest = _kvm_s390_real_to_abs(prefix, dest) + scb_s->mso; in vsie_handle_mvpg()
1066 src = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 16) & mask; in vsie_handle_mvpg()
1067 src = _kvm_s390_real_to_abs(prefix, src) + scb_s->mso; in vsie_handle_mvpg()
1069 rc_dest = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, dest, &pei_dest); in vsie_handle_mvpg()
1070 rc_src = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, src, &pei_src); in vsie_handle_mvpg()
1072 * Either everything went well, or something non-critical went wrong in vsie_handle_mvpg()
1075 if (rc_dest == -EAGAIN || rc_src == -EAGAIN || (!rc_dest && !rc_src)) { in vsie_handle_mvpg()
1077 return -EAGAIN; in vsie_handle_mvpg()
1126 * Returns: - 0 everything went fine
1127 * - > 0 if control has to be given to guest 2
1128 * - < 0 if an error occurred
1131 __releases(vcpu->kvm->srcu) in do_vsie_run()
1132 __acquires(vcpu->kvm->srcu) in do_vsie_run()
1134 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in do_vsie_run()
1135 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in do_vsie_run()
1152 if (test_kvm_facility(vcpu->kvm, 82) && in do_vsie_run()
1153 vcpu->arch.sie_block->fpf & FPF_BPBC) in do_vsie_run()
1166 vcpu->arch.sie_block->prog0c |= PROG_IN_SIE; in do_vsie_run()
1167 current->thread.gmap_int_code = 0; in do_vsie_run()
1170 rc = sie64a(scb_s, vcpu->run->s.regs.gprs, vsie_page->gmap->asce); in do_vsie_run()
1172 vcpu->arch.sie_block->prog0c &= ~PROG_IN_SIE; in do_vsie_run()
1184 if (rc == -EINTR) { in do_vsie_run()
1186 kvm_s390_reinject_machine_check(vcpu, &vsie_page->mcck_info); in do_vsie_run()
1192 else if (current->thread.gmap_int_code) in do_vsie_run()
1195 switch (scb_s->icptcode) { in do_vsie_run()
1197 if (scb_s->ipa == 0xb2b0) in do_vsie_run()
1201 /* stop not requested by g2 - must have been a kick */ in do_vsie_run()
1202 if (!(atomic_read(&scb_o->cpuflags) & CPUSTAT_STOP_INT)) in do_vsie_run()
1206 if ((scb_s->ipa & 0xf000) != 0xf000) in do_vsie_run()
1207 scb_s->ipa += 0x1000; in do_vsie_run()
1210 if (scb_s->ipa == 0xb254) in do_vsie_run()
1219 if (vsie_page->gmap) in release_gmap_shadow()
1220 gmap_put(vsie_page->gmap); in release_gmap_shadow()
1221 WRITE_ONCE(vsie_page->gmap, NULL); in release_gmap_shadow()
1233 asce = vcpu->arch.sie_block->gcr[1]; in acquire_gmap_shadow()
1234 cr0.val = vcpu->arch.sie_block->gcr[0]; in acquire_gmap_shadow()
1235 edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8); in acquire_gmap_shadow()
1236 edat += edat && test_kvm_facility(vcpu->kvm, 78); in acquire_gmap_shadow()
1243 if (vsie_page->gmap && gmap_shadow_valid(vsie_page->gmap, asce, edat)) { in acquire_gmap_shadow()
1244 vcpu->kvm->stat.gmap_shadow_reuse++; in acquire_gmap_shadow()
1248 /* release the old shadow - if any, and mark the prefix as unmapped */ in acquire_gmap_shadow()
1250 gmap = gmap_shadow(vcpu->arch.gmap, asce, edat); in acquire_gmap_shadow()
1253 vcpu->kvm->stat.gmap_shadow_create++; in acquire_gmap_shadow()
1254 WRITE_ONCE(vsie_page->gmap, gmap); in acquire_gmap_shadow()
1264 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in register_shadow_scb()
1266 WRITE_ONCE(vcpu->arch.vsie_block, &vsie_page->scb_s); in register_shadow_scb()
1269 * therefore the vsie -> Simulate Wait state. in register_shadow_scb()
1274 * automatically be adjusted on tod clock changes via kvm_sync_clock. in register_shadow_scb()
1277 scb_s->epoch += vcpu->kvm->arch.epoch; in register_shadow_scb()
1279 if (scb_s->ecd & ECD_MEF) { in register_shadow_scb()
1280 scb_s->epdx += vcpu->kvm->arch.epdx; in register_shadow_scb()
1281 if (scb_s->epoch < vcpu->kvm->arch.epoch) in register_shadow_scb()
1282 scb_s->epdx += 1; in register_shadow_scb()
1294 WRITE_ONCE(vcpu->arch.vsie_block, NULL); in unregister_shadow_scb()
1301 * Returns: - 0 if no errors occurred
1302 * - > 0 if control has to be given to guest 2
1303 * - -ENOMEM if out of memory
1307 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in vsie_run()
1318 atomic_andnot(PROG_BLOCK_SIE, &scb_s->prog20); in vsie_run()
1320 if (rc == -EAGAIN) in vsie_run()
1326 if (rc || scb_s->icptcode) in vsie_run()
1331 * but rewind the PSW to re-enter SIE once that's completed in vsie_run()
1343 if (rc == -EFAULT) { in vsie_run()
1354 scb_s->icptcode = ICPT_PROGI; in vsie_run()
1355 scb_s->iprcc = PGM_ADDRESSING; in vsie_run()
1356 scb_s->pgmilc = 4; in vsie_run()
1357 scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, 4); in vsie_run()
1366 if (test_bit(VSIE_PAGE_IN_USE, &vsie_page->flags)) in try_get_vsie_page()
1368 return !test_and_set_bit(VSIE_PAGE_IN_USE, &vsie_page->flags); in try_get_vsie_page()
1374 clear_bit(VSIE_PAGE_IN_USE, &vsie_page->flags); in put_vsie_page()
1380 * Returns: - address of a vsie page (cached or new one)
1381 * - NULL if the same scb address is already used by another VCPU
1382 * - ERR_PTR(-ENOMEM) if out of memory
1390 vsie_page = radix_tree_lookup(&kvm->arch.vsie.addr_to_page, addr >> 9); in get_vsie_page()
1394 if (vsie_page->scb_gpa == addr) in get_vsie_page()
1408 nr_vcpus = atomic_read(&kvm->online_vcpus); in get_vsie_page()
1410 mutex_lock(&kvm->arch.vsie.mutex); in get_vsie_page()
1411 if (kvm->arch.vsie.page_count < nr_vcpus) { in get_vsie_page()
1414 mutex_unlock(&kvm->arch.vsie.mutex); in get_vsie_page()
1415 return ERR_PTR(-ENOMEM); in get_vsie_page()
1417 __set_bit(VSIE_PAGE_IN_USE, &vsie_page->flags); in get_vsie_page()
1418 kvm->arch.vsie.pages[kvm->arch.vsie.page_count] = vsie_page; in get_vsie_page()
1419 kvm->arch.vsie.page_count++; in get_vsie_page()
1423 vsie_page = kvm->arch.vsie.pages[kvm->arch.vsie.next]; in get_vsie_page()
1426 kvm->arch.vsie.next++; in get_vsie_page()
1427 kvm->arch.vsie.next %= nr_vcpus; in get_vsie_page()
1429 if (vsie_page->scb_gpa != ULONG_MAX) in get_vsie_page()
1430 radix_tree_delete(&kvm->arch.vsie.addr_to_page, in get_vsie_page()
1431 vsie_page->scb_gpa >> 9); in get_vsie_page()
1434 vsie_page->scb_gpa = ULONG_MAX; in get_vsie_page()
1437 if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9, in get_vsie_page()
1440 mutex_unlock(&kvm->arch.vsie.mutex); in get_vsie_page()
1443 vsie_page->scb_gpa = addr; in get_vsie_page()
1444 mutex_unlock(&kvm->arch.vsie.mutex); in get_vsie_page()
1446 memset(&vsie_page->scb_s, 0, sizeof(struct kvm_s390_sie_block)); in get_vsie_page()
1448 vsie_page->fault_addr = 0; in get_vsie_page()
1449 vsie_page->scb_s.ihcpu = 0xffffU; in get_vsie_page()
1459 vcpu->stat.instruction_sie++; in kvm_s390_handle_vsie()
1460 if (!test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_SIEF2)) in kvm_s390_handle_vsie()
1461 return -EOPNOTSUPP; in kvm_s390_handle_vsie()
1462 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) in kvm_s390_handle_vsie()
1478 vsie_page = get_vsie_page(vcpu->kvm, scb_addr); in kvm_s390_handle_vsie()
1482 /* double use of sie control block - simply do nothing */ in kvm_s390_handle_vsie()
1511 mutex_init(&kvm->arch.vsie.mutex); in kvm_s390_vsie_init()
1512 INIT_RADIX_TREE(&kvm->arch.vsie.addr_to_page, GFP_KERNEL_ACCOUNT); in kvm_s390_vsie_init()
1521 mutex_lock(&kvm->arch.vsie.mutex); in kvm_s390_vsie_destroy()
1522 for (i = 0; i < kvm->arch.vsie.page_count; i++) { in kvm_s390_vsie_destroy()
1523 vsie_page = kvm->arch.vsie.pages[i]; in kvm_s390_vsie_destroy()
1524 kvm->arch.vsie.pages[i] = NULL; in kvm_s390_vsie_destroy()
1527 if (vsie_page->scb_gpa != ULONG_MAX) in kvm_s390_vsie_destroy()
1528 radix_tree_delete(&kvm->arch.vsie.addr_to_page, in kvm_s390_vsie_destroy()
1529 vsie_page->scb_gpa >> 9); in kvm_s390_vsie_destroy()
1532 kvm->arch.vsie.page_count = 0; in kvm_s390_vsie_destroy()
1533 mutex_unlock(&kvm->arch.vsie.mutex); in kvm_s390_vsie_destroy()
1538 struct kvm_s390_sie_block *scb = READ_ONCE(vcpu->arch.vsie_block); in kvm_s390_vsie_kick()
1545 atomic_or(PROG_BLOCK_SIE, &scb->prog20); in kvm_s390_vsie_kick()
1546 if (scb->prog0c & PROG_IN_SIE) in kvm_s390_vsie_kick()
1547 atomic_or(CPUSTAT_STOP_INT, &scb->cpuflags); in kvm_s390_vsie_kick()