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

1 // SPDX-License-Identifier: GPL-2.0
23 #include "kvm-s390.h"
49 __u8 reserved[0x0700 - 0x0258]; /* 0x0258 */
58 scb->ipa = 0x1000; in set_validity_icpt()
59 scb->ipb = ((__u32) reason_code) << 16; in set_validity_icpt()
60 scb->icptcode = ICPT_VALIDITY; in set_validity_icpt()
67 atomic_or(PROG_REQUEST, &vsie_page->scb_s.prog20); in prefix_unmapped()
74 if (vsie_page->scb_s.prog0c & PROG_IN_SIE) in prefix_unmapped_sync()
75 atomic_or(CPUSTAT_STOP_INT, &vsie_page->scb_s.cpuflags); in prefix_unmapped_sync()
76 while (vsie_page->scb_s.prog0c & PROG_IN_SIE) in prefix_unmapped_sync()
83 atomic_andnot(PROG_REQUEST, &vsie_page->scb_s.prog20); in prefix_mapped()
89 return !(atomic_read(&vsie_page->scb_s.prog20) & PROG_REQUEST); in prefix_is_mapped()
98 cpuflags = atomic_read(&vsie_page->scb_o->cpuflags); in update_intervention_requests()
99 atomic_andnot(bits, &vsie_page->scb_s.cpuflags); in update_intervention_requests()
100 atomic_or(cpuflags & bits, &vsie_page->scb_s.cpuflags); in update_intervention_requests()
106 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in prepare_cpuflags()
107 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in prepare_cpuflags()
108 int newflags, cpuflags = atomic_read(&scb_o->cpuflags); in prepare_cpuflags()
121 if (cpuflags & CPUSTAT_GED && test_kvm_facility(vcpu->kvm, 8)) in prepare_cpuflags()
123 if (cpuflags & CPUSTAT_GED2 && test_kvm_facility(vcpu->kvm, 78)) { in prepare_cpuflags()
128 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_GPERE)) in prepare_cpuflags()
130 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_GSLS)) in prepare_cpuflags()
132 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_IBS)) in prepare_cpuflags()
134 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_KSS)) in prepare_cpuflags()
137 atomic_set(&scb_s->cpuflags, newflags); in prepare_cpuflags()
151 return -EFAULT; in setup_apcb10()
153 apcb_s->apm[0] = apcb_h->apm[0] & tmp.apm[0]; in setup_apcb10()
154 apcb_s->aqm[0] = apcb_h->aqm[0] & tmp.aqm[0] & 0xffff000000000000UL; in setup_apcb10()
155 apcb_s->adm[0] = apcb_h->adm[0] & tmp.adm[0] & 0xffff000000000000UL; in setup_apcb10()
162 * setup_apcb00 - Copy to APCB FORMAT0 from APCB FORMAT0
168 * Returns 0 and -EFAULT on error reading guest apcb
179 return -EFAULT; in setup_apcb00()
188 * setup_apcb11 - Copy the FORMAT1 APCB from the guest to the shadow CRYCB
194 * Returns 0 and -EFAULT on error reading guest apcb
206 return -EFAULT; in setup_apcb11()
215 * setup_apcb - Create a shadow copy of the apcb.
236 return -EACCES; in setup_apcb()
238 return -EINVAL; in setup_apcb()
239 return setup_apcb11(vcpu, (unsigned long *)&crycb_s->apcb1, in setup_apcb()
241 (unsigned long *)&crycb_h->apcb1); in setup_apcb()
245 return setup_apcb10(vcpu, &crycb_s->apcb1, in setup_apcb()
247 &crycb_h->apcb1); in setup_apcb()
250 (unsigned long *) &crycb_s->apcb0, in setup_apcb()
252 (unsigned long *) &crycb_h->apcb0); in setup_apcb()
257 return -EACCES; in setup_apcb()
261 return setup_apcb10(vcpu, &crycb_s->apcb1, in setup_apcb()
263 &crycb_h->apcb1); in setup_apcb()
267 (unsigned long *) &crycb_s->apcb0, in setup_apcb()
269 (unsigned long *) &crycb_h->apcb0); in setup_apcb()
272 return -EINVAL; in setup_apcb()
276 * shadow_crycb - Create a shadow copy of the crycb block
281 * requested for guest 3 and enabled for guest 2.
283 * We accept format-1 or format-2, but we convert format-1 into format-2
285 * Using format-2 enables the firmware to choose the right format when
287 * There is nothing to do for format-0.
292 * Returns: - 0 if shadowed or nothing to do
293 * - > 0 if control has to be given to guest 2
297 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in shadow_crycb()
298 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in shadow_crycb()
299 const uint32_t crycbd_o = READ_ONCE(scb_o->crycbd); in shadow_crycb()
306 int key_msk = test_kvm_facility(vcpu->kvm, 76); in shadow_crycb()
308 int fmt_h = vcpu->arch.sie_block->crycbd & CRYCB_FORMAT_MASK; in shadow_crycb()
311 scb_s->crycbd = 0; in shadow_crycb()
313 apie_h = vcpu->arch.sie_block->eca & ECA_APIE; in shadow_crycb()
314 apie_s = apie_h & scb_o->eca; in shadow_crycb()
327 ret = setup_apcb(vcpu, &vsie_page->crycb, crycb_addr, in shadow_crycb()
328 vcpu->kvm->arch.crypto.crycb, in shadow_crycb()
332 scb_s->eca |= scb_o->eca & ECA_APIE; in shadow_crycb()
335 /* we may only allow it if enabled for guest 2 */ in shadow_crycb()
336 ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 & in shadow_crycb()
338 ecd_flags = scb_o->ecd & vcpu->arch.sie_block->ecd & ECD_ECC; in shadow_crycb()
344 vsie_page->crycb.dea_wrapping_key_mask, 56)) in shadow_crycb()
347 scb_s->ecb3 |= ecb3_flags; in shadow_crycb()
348 scb_s->ecd |= ecd_flags; in shadow_crycb()
351 b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask; in shadow_crycb()
353 vcpu->kvm->arch.crypto.crycb->dea_wrapping_key_mask; in shadow_crycb()
358 case -EINVAL: in shadow_crycb()
360 case -EFAULT: in shadow_crycb()
362 case -EACCES: in shadow_crycb()
365 scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | CRYCB_FORMAT2; in shadow_crycb()
372 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in prepare_ibc()
373 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in prepare_ibc()
374 /* READ_ONCE does not work on bitfields - use a temporary variable */ in prepare_ibc()
375 const uint32_t __new_ibc = scb_o->ibc; in prepare_ibc()
379 scb_s->ibc = 0; in prepare_ibc()
381 if (vcpu->kvm->arch.model.ibc && new_ibc) { in prepare_ibc()
382 scb_s->ibc = new_ibc; in prepare_ibc()
384 if (scb_s->ibc < min_ibc) in prepare_ibc()
385 scb_s->ibc = min_ibc; in prepare_ibc()
387 if (scb_s->ibc > vcpu->kvm->arch.model.ibc) in prepare_ibc()
388 scb_s->ibc = vcpu->kvm->arch.model.ibc; in prepare_ibc()
395 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in unshadow_scb()
396 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in unshadow_scb()
399 scb_o->icptcode = scb_s->icptcode; in unshadow_scb()
400 scb_o->icptstatus = scb_s->icptstatus; in unshadow_scb()
401 scb_o->ipa = scb_s->ipa; in unshadow_scb()
402 scb_o->ipb = scb_s->ipb; in unshadow_scb()
403 scb_o->gbea = scb_s->gbea; in unshadow_scb()
406 scb_o->cputm = scb_s->cputm; in unshadow_scb()
407 scb_o->ckc = scb_s->ckc; in unshadow_scb()
408 scb_o->todpr = scb_s->todpr; in unshadow_scb()
411 scb_o->gpsw = scb_s->gpsw; in unshadow_scb()
412 scb_o->gg14 = scb_s->gg14; in unshadow_scb()
413 scb_o->gg15 = scb_s->gg15; in unshadow_scb()
414 memcpy(scb_o->gcr, scb_s->gcr, 128); in unshadow_scb()
415 scb_o->pp = scb_s->pp; in unshadow_scb()
418 if (test_kvm_facility(vcpu->kvm, 82)) { in unshadow_scb()
419 scb_o->fpf &= ~FPF_BPBC; in unshadow_scb()
420 scb_o->fpf |= scb_s->fpf & FPF_BPBC; in unshadow_scb()
424 switch (scb_s->icptcode) { in unshadow_scb()
429 (void *)((u64)scb_s + 0xc0), 0xf0 - 0xc0); in unshadow_scb()
433 if (scb_s->ihcpu != 0xffffU) in unshadow_scb()
434 scb_o->ihcpu = scb_s->ihcpu; in unshadow_scb()
441 * Returns: - 0 if the scb has been shadowed
442 * - > 0 if control has to be given to guest 2
446 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in shadow_scb()
447 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in shadow_scb()
448 /* READ_ONCE does not work on bitfields - use a temporary variable */ in shadow_scb()
449 const uint32_t __new_prefix = scb_o->prefix; in shadow_scb()
451 const bool wants_tx = READ_ONCE(scb_o->ecb) & ECB_TE; in shadow_scb()
452 bool had_tx = scb_s->ecb & ECB_TE; in shadow_scb()
457 scb_s->icptcode = 0; in shadow_scb()
458 scb_s->eca = 0; in shadow_scb()
459 scb_s->ecb = 0; in shadow_scb()
460 scb_s->ecb2 = 0; in shadow_scb()
461 scb_s->ecb3 = 0; in shadow_scb()
462 scb_s->ecd = 0; in shadow_scb()
463 scb_s->fac = 0; in shadow_scb()
464 scb_s->fpf = 0; in shadow_scb()
471 scb_s->cputm = scb_o->cputm; in shadow_scb()
472 scb_s->ckc = scb_o->ckc; in shadow_scb()
473 scb_s->todpr = scb_o->todpr; in shadow_scb()
474 scb_s->epoch = scb_o->epoch; in shadow_scb()
477 scb_s->gpsw = scb_o->gpsw; in shadow_scb()
478 scb_s->gg14 = scb_o->gg14; in shadow_scb()
479 scb_s->gg15 = scb_o->gg15; in shadow_scb()
480 memcpy(scb_s->gcr, scb_o->gcr, 128); in shadow_scb()
481 scb_s->pp = scb_o->pp; in shadow_scb()
484 scb_s->gbea = scb_o->gbea; in shadow_scb()
485 scb_s->lctl = scb_o->lctl; in shadow_scb()
486 scb_s->svcc = scb_o->svcc; in shadow_scb()
487 scb_s->ictl = scb_o->ictl; in shadow_scb()
493 if (!(atomic_read(&scb_s->cpuflags) & CPUSTAT_KSS)) in shadow_scb()
494 scb_s->ictl |= ICTL_ISKE | ICTL_SSKE | ICTL_RRBE; in shadow_scb()
496 scb_s->icpua = scb_o->icpua; in shadow_scb()
498 if (!(atomic_read(&scb_s->cpuflags) & CPUSTAT_SM)) in shadow_scb()
499 new_mso = READ_ONCE(scb_o->mso) & 0xfffffffffff00000UL; in shadow_scb()
501 if (scb_s->mso != new_mso || scb_s->prefix != new_prefix) in shadow_scb()
504 scb_s->msl = scb_o->msl & 0xfffffffffff00000UL; in shadow_scb()
505 scb_s->mso = new_mso; in shadow_scb()
506 scb_s->prefix = new_prefix; in shadow_scb()
509 if (scb_s->ihcpu != 0xffffU) in shadow_scb()
510 scb_s->ihcpu = scb_o->ihcpu; in shadow_scb()
513 scb_s->eca |= scb_o->eca & (ECA_MVPGI | ECA_PROTEXCI); in shadow_scb()
514 /* Host-protection-interruption introduced with ESOP */ in shadow_scb()
515 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_ESOP)) in shadow_scb()
516 scb_s->ecb |= scb_o->ecb & ECB_HOSTPROTINT; in shadow_scb()
523 if (test_kvm_facility(vcpu->kvm, 11)) in shadow_scb()
524 scb_s->ecb |= scb_o->ecb & ECB_PTF; in shadow_scb()
526 if (test_kvm_facility(vcpu->kvm, 73) && wants_tx) { in shadow_scb()
530 scb_s->ecb |= ECB_TE; in shadow_scb()
533 scb_s->ecb |= scb_o->ecb & ECB_SPECI; in shadow_scb()
535 if (test_kvm_facility(vcpu->kvm, 82)) in shadow_scb()
536 scb_s->fpf |= scb_o->fpf & FPF_BPBC; in shadow_scb()
538 if (test_kvm_facility(vcpu->kvm, 129)) { in shadow_scb()
539 scb_s->eca |= scb_o->eca & ECA_VX; in shadow_scb()
540 scb_s->ecd |= scb_o->ecd & ECD_HOSTREGMGMT; in shadow_scb()
542 /* Run-time-Instrumentation */ in shadow_scb()
543 if (test_kvm_facility(vcpu->kvm, 64)) in shadow_scb()
544 scb_s->ecb3 |= scb_o->ecb3 & ECB3_RI; in shadow_scb()
546 if (test_kvm_facility(vcpu->kvm, 130)) in shadow_scb()
547 scb_s->ecb2 |= scb_o->ecb2 & ECB2_IEP; in shadow_scb()
549 if (test_kvm_facility(vcpu->kvm, 133)) { in shadow_scb()
550 scb_s->ecb |= scb_o->ecb & ECB_GS; in shadow_scb()
551 scb_s->ecd |= scb_o->ecd & ECD_HOSTREGMGMT; in shadow_scb()
553 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_SIIF)) in shadow_scb()
554 scb_s->eca |= scb_o->eca & ECA_SII; in shadow_scb()
555 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_IB)) in shadow_scb()
556 scb_s->eca |= scb_o->eca & ECA_IB; in shadow_scb()
557 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_CEI)) in shadow_scb()
558 scb_s->eca |= scb_o->eca & ECA_CEI; in shadow_scb()
560 if (test_kvm_facility(vcpu->kvm, 139)) { in shadow_scb()
561 scb_s->ecd |= scb_o->ecd & ECD_MEF; in shadow_scb()
562 scb_s->epdx = scb_o->epdx; in shadow_scb()
566 if (test_kvm_facility(vcpu->kvm, 156)) in shadow_scb()
567 scb_s->ecd |= scb_o->ecd & ECD_ETOKENF; in shadow_scb()
569 scb_s->hpid = HPID_VSIE; in shadow_scb()
570 scb_s->cpnc = scb_o->cpnc; in shadow_scb()
583 struct kvm *kvm = gmap->private; in kvm_s390_vsie_gmap_notifier()
595 for (i = 0; i < kvm->arch.vsie.page_count; i++) { in kvm_s390_vsie_gmap_notifier()
596 page = READ_ONCE(kvm->arch.vsie.pages[i]); in kvm_s390_vsie_gmap_notifier()
600 if (READ_ONCE(cur->gmap) != gmap) in kvm_s390_vsie_gmap_notifier()
602 prefix = cur->scb_s.prefix << GUEST_PREFIX_SHIFT; in kvm_s390_vsie_gmap_notifier()
604 prefix += cur->scb_s.mso; in kvm_s390_vsie_gmap_notifier()
605 if (prefix <= end && start <= prefix + 2 * PAGE_SIZE - 1) in kvm_s390_vsie_gmap_notifier()
611 * Map the first prefix page and if tx is enabled also the second prefix page.
617 * Returns: - 0 on if successfully mapped or already mapped
618 * - > 0 if control has to be given to guest 2
619 * - -EAGAIN if the caller can retry immediately
620 * - -ENOMEM if out of memory
624 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in map_prefix()
625 u64 prefix = scb_s->prefix << GUEST_PREFIX_SHIFT; in map_prefix()
635 prefix += scb_s->mso; in map_prefix()
637 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, prefix, NULL); in map_prefix()
638 if (!rc && (scb_s->ecb & ECB_TE)) in map_prefix()
639 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, in map_prefix()
647 if (rc > 0 || rc == -EFAULT) in map_prefix()
656 * Returns: - 0 on success
657 * - -EINVAL if the gpa is not valid guest storage
665 return -EINVAL; in pin_guest_page()
681 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in unpin_blocks()
684 hpa = (u64) scb_s->scaoh << 32 | scb_s->scaol; in unpin_blocks()
686 unpin_guest_page(vcpu->kvm, vsie_page->sca_gpa, hpa); in unpin_blocks()
687 vsie_page->sca_gpa = 0; in unpin_blocks()
688 scb_s->scaol = 0; in unpin_blocks()
689 scb_s->scaoh = 0; in unpin_blocks()
692 hpa = scb_s->itdba; in unpin_blocks()
694 unpin_guest_page(vcpu->kvm, vsie_page->itdba_gpa, hpa); in unpin_blocks()
695 vsie_page->itdba_gpa = 0; in unpin_blocks()
696 scb_s->itdba = 0; in unpin_blocks()
699 hpa = scb_s->gvrd; in unpin_blocks()
701 unpin_guest_page(vcpu->kvm, vsie_page->gvrd_gpa, hpa); in unpin_blocks()
702 vsie_page->gvrd_gpa = 0; in unpin_blocks()
703 scb_s->gvrd = 0; in unpin_blocks()
706 hpa = scb_s->riccbd; in unpin_blocks()
708 unpin_guest_page(vcpu->kvm, vsie_page->riccbd_gpa, hpa); in unpin_blocks()
709 vsie_page->riccbd_gpa = 0; in unpin_blocks()
710 scb_s->riccbd = 0; in unpin_blocks()
713 hpa = scb_s->sdnxo; in unpin_blocks()
715 unpin_guest_page(vcpu->kvm, vsie_page->sdnx_gpa, hpa); in unpin_blocks()
716 vsie_page->sdnx_gpa = 0; in unpin_blocks()
717 scb_s->sdnxo = 0; in unpin_blocks()
731 * Returns: - 0 if all blocks were pinned.
732 * - > 0 if control has to be given to guest 2
733 * - -ENOMEM if out of memory
737 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in pin_blocks()
738 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in pin_blocks()
743 gpa = READ_ONCE(scb_o->scaol) & ~0xfUL; in pin_blocks()
744 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_64BSCAO)) in pin_blocks()
745 gpa |= (u64) READ_ONCE(scb_o->scaoh) << 32; in pin_blocks()
752 ((gpa + sizeof(struct bsca_block) - 1) & PAGE_MASK)) in pin_blocks()
755 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
761 vsie_page->sca_gpa = gpa; in pin_blocks()
762 scb_s->scaoh = (u32)((u64)hpa >> 32); in pin_blocks()
763 scb_s->scaol = (u32)(u64)hpa; in pin_blocks()
766 gpa = READ_ONCE(scb_o->itdba) & ~0xffUL; in pin_blocks()
767 if (gpa && (scb_s->ecb & ECB_TE)) { in pin_blocks()
773 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
778 vsie_page->itdba_gpa = gpa; in pin_blocks()
779 scb_s->itdba = hpa; in pin_blocks()
782 gpa = READ_ONCE(scb_o->gvrd) & ~0x1ffUL; in pin_blocks()
783 if (gpa && (scb_s->eca & ECA_VX) && !(scb_s->ecd & ECD_HOSTREGMGMT)) { in pin_blocks()
792 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
797 vsie_page->gvrd_gpa = gpa; in pin_blocks()
798 scb_s->gvrd = hpa; in pin_blocks()
801 gpa = READ_ONCE(scb_o->riccbd) & ~0x3fUL; in pin_blocks()
802 if (gpa && (scb_s->ecb3 & ECB3_RI)) { in pin_blocks()
808 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
814 vsie_page->riccbd_gpa = gpa; in pin_blocks()
815 scb_s->riccbd = hpa; in pin_blocks()
817 if (((scb_s->ecb & ECB_GS) && !(scb_s->ecd & ECD_HOSTREGMGMT)) || in pin_blocks()
818 (scb_s->ecd & ECD_ETOKENF)) { in pin_blocks()
821 gpa = READ_ONCE(scb_o->sdnxo) & ~0xfUL; in pin_blocks()
822 sdnxc = READ_ONCE(scb_o->sdnxo) & 0xfUL; in pin_blocks()
831 if (gpa & ((1 << sdnxc) - 1)) { in pin_blocks()
838 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
843 vsie_page->sdnx_gpa = gpa; in pin_blocks()
844 scb_s->sdnxo = hpa | sdnxc; in pin_blocks()
856 hpa_t hpa = (hpa_t) vsie_page->scb_o; in unpin_scb()
859 unpin_guest_page(vcpu->kvm, gpa, hpa); in unpin_scb()
860 vsie_page->scb_o = NULL; in unpin_scb()
864 * Pin the scb at gpa provided by guest 2 at vsie_page->scb_o.
866 * Returns: - 0 if the scb was pinned.
867 * - > 0 if control has to be given to guest 2
875 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_scb()
881 vsie_page->scb_o = phys_to_virt(hpa); in pin_scb()
888 * Returns: - > 0 if control has to be given to guest 2
897 /* 0-51: virtual address */ in inject_fault()
899 /* 52-53: store / fetch */ in inject_fault()
901 /* 62-63: asce id (always primary == 0) */ in inject_fault()
917 * Returns: - 0 if the fault was resolved
918 * - > 0 if control has to be given to guest 2
919 * - < 0 if an error occurred
925 if (current->thread.gmap_int_code == PGM_PROTECTION) in handle_fault()
928 current->thread.gmap_addr, 1); in handle_fault()
930 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, in handle_fault()
931 current->thread.gmap_addr, NULL); in handle_fault()
934 current->thread.gmap_addr, in handle_fault()
935 current->thread.gmap_write_flag); in handle_fault()
937 vsie_page->fault_addr = current->thread.gmap_addr; in handle_fault()
944 * one superfluous SIE re-entry and direct exit.
951 if (vsie_page->fault_addr) in handle_last_fault()
952 kvm_s390_shadow_fault(vcpu, vsie_page->gmap, in handle_last_fault()
953 vsie_page->fault_addr, NULL); in handle_last_fault()
954 vsie_page->fault_addr = 0; in handle_last_fault()
959 vsie_page->scb_s.icptcode = 0; in clear_vsie_icpt()
965 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in retry_vsie_icpt()
966 int ilen = insn_length(scb_s->ipa >> 8); in retry_vsie_icpt()
969 if (scb_s->icptstatus & 1) { in retry_vsie_icpt()
970 ilen = (scb_s->icptstatus >> 4) & 0x6; in retry_vsie_icpt()
974 scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, ilen); in retry_vsie_icpt()
980 * Retry instruction execution if enabled for and provided by guest 2.
982 * Returns: - 0 if handled (retry or guest 2 icpt)
983 * - > 0 if control has to be given to guest 2
987 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in handle_stfle()
988 __u32 fac = READ_ONCE(vsie_page->scb_o->fac); in handle_stfle()
991 * Alternate-STFLE-Interpretive-Execution facilities are not supported in handle_stfle()
992 * -> format-0 flcb in handle_stfle()
994 if (fac && test_kvm_facility(vcpu->kvm, 7)) { in handle_stfle()
997 * The facility list origin (FLO) is in bits 1 - 28 of the FLD in handle_stfle()
1002 * format-0 -> size of nested guest's facility list == guest's size in handle_stfle()
1004 * using a format-0 for the guest, too. in handle_stfle()
1006 if (read_guest_real(vcpu, fac, &vsie_page->fac, in handle_stfle()
1009 scb_s->fac = (__u32)(__u64) &vsie_page->fac; in handle_stfle()
1027 return vsie_page->scb_s.gg15; in vsie_get_register()
1029 return vsie_page->scb_s.gg14; in vsie_get_register()
1031 return vcpu->run->s.regs.gprs[reg]; in vsie_get_register()
1037 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in vsie_handle_mvpg()
1039 u64 *pei_block = &vsie_page->scb_o->mcic; in vsie_handle_mvpg()
1043 cr0.val = vcpu->arch.sie_block->gcr[0]; in vsie_handle_mvpg()
1044 edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8); in vsie_handle_mvpg()
1045 mask = _kvm_s390_logical_to_effective(&scb_s->gpsw, PAGE_MASK); in vsie_handle_mvpg()
1046 prefix = scb_s->prefix << GUEST_PREFIX_SHIFT; in vsie_handle_mvpg()
1048 dest = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 20) & mask; in vsie_handle_mvpg()
1049 dest = _kvm_s390_real_to_abs(prefix, dest) + scb_s->mso; in vsie_handle_mvpg()
1050 src = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 16) & mask; in vsie_handle_mvpg()
1051 src = _kvm_s390_real_to_abs(prefix, src) + scb_s->mso; in vsie_handle_mvpg()
1053 rc_dest = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, dest, &pei_dest); in vsie_handle_mvpg()
1054 rc_src = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, src, &pei_src); in vsie_handle_mvpg()
1056 * Either everything went well, or something non-critical went wrong in vsie_handle_mvpg()
1059 if (rc_dest == -EAGAIN || rc_src == -EAGAIN || (!rc_dest && !rc_src)) { in vsie_handle_mvpg()
1061 return -EAGAIN; in vsie_handle_mvpg()
1110 * Returns: - 0 everything went fine
1111 * - > 0 if control has to be given to guest 2
1112 * - < 0 if an error occurred
1115 __releases(vcpu->kvm->srcu) in do_vsie_run()
1116 __acquires(vcpu->kvm->srcu) in do_vsie_run()
1118 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in do_vsie_run()
1119 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in do_vsie_run()
1136 if (test_kvm_facility(vcpu->kvm, 82) && in do_vsie_run()
1137 vcpu->arch.sie_block->fpf & FPF_BPBC) in do_vsie_run()
1150 vcpu->arch.sie_block->prog0c |= PROG_IN_SIE; in do_vsie_run()
1155 rc = sie64a(scb_s, vcpu->run->s.regs.gprs); in do_vsie_run()
1157 vcpu->arch.sie_block->prog0c &= ~PROG_IN_SIE; in do_vsie_run()
1169 if (rc == -EINTR) { in do_vsie_run()
1171 kvm_s390_reinject_machine_check(vcpu, &vsie_page->mcck_info); in do_vsie_run()
1177 else if (rc == -EFAULT) in do_vsie_run()
1180 switch (scb_s->icptcode) { in do_vsie_run()
1182 if (scb_s->ipa == 0xb2b0) in do_vsie_run()
1186 /* stop not requested by g2 - must have been a kick */ in do_vsie_run()
1187 if (!(atomic_read(&scb_o->cpuflags) & CPUSTAT_STOP_INT)) in do_vsie_run()
1191 if ((scb_s->ipa & 0xf000) != 0xf000) in do_vsie_run()
1192 scb_s->ipa += 0x1000; in do_vsie_run()
1195 if (scb_s->ipa == 0xb254) in do_vsie_run()
1204 if (vsie_page->gmap) in release_gmap_shadow()
1205 gmap_put(vsie_page->gmap); in release_gmap_shadow()
1206 WRITE_ONCE(vsie_page->gmap, NULL); in release_gmap_shadow()
1218 asce = vcpu->arch.sie_block->gcr[1]; in acquire_gmap_shadow()
1219 cr0.val = vcpu->arch.sie_block->gcr[0]; in acquire_gmap_shadow()
1220 edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8); in acquire_gmap_shadow()
1221 edat += edat && test_kvm_facility(vcpu->kvm, 78); in acquire_gmap_shadow()
1228 if (vsie_page->gmap && gmap_shadow_valid(vsie_page->gmap, asce, edat)) { in acquire_gmap_shadow()
1229 vcpu->kvm->stat.gmap_shadow_reuse++; in acquire_gmap_shadow()
1233 /* release the old shadow - if any, and mark the prefix as unmapped */ in acquire_gmap_shadow()
1235 gmap = gmap_shadow(vcpu->arch.gmap, asce, edat); in acquire_gmap_shadow()
1238 vcpu->kvm->stat.gmap_shadow_create++; in acquire_gmap_shadow()
1239 WRITE_ONCE(vsie_page->gmap, gmap); in acquire_gmap_shadow()
1249 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in register_shadow_scb()
1251 WRITE_ONCE(vcpu->arch.vsie_block, &vsie_page->scb_s); in register_shadow_scb()
1254 * therefore the vsie -> Simulate Wait state. in register_shadow_scb()
1259 * automatically be adjusted on tod clock changes via kvm_sync_clock. in register_shadow_scb()
1262 scb_s->epoch += vcpu->kvm->arch.epoch; in register_shadow_scb()
1264 if (scb_s->ecd & ECD_MEF) { in register_shadow_scb()
1265 scb_s->epdx += vcpu->kvm->arch.epdx; in register_shadow_scb()
1266 if (scb_s->epoch < vcpu->kvm->arch.epoch) in register_shadow_scb()
1267 scb_s->epdx += 1; in register_shadow_scb()
1279 WRITE_ONCE(vcpu->arch.vsie_block, NULL); in unregister_shadow_scb()
1286 * Returns: - 0 if no errors occurred
1287 * - > 0 if control has to be given to guest 2
1288 * - -ENOMEM if out of memory
1292 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in vsie_run()
1300 gmap_enable(vsie_page->gmap); in vsie_run()
1303 gmap_enable(vcpu->arch.gmap); in vsie_run()
1305 atomic_andnot(PROG_BLOCK_SIE, &scb_s->prog20); in vsie_run()
1307 if (rc == -EAGAIN) in vsie_run()
1309 if (rc || scb_s->icptcode || signal_pending(current) || in vsie_run()
1316 if (rc == -EFAULT) { in vsie_run()
1327 scb_s->icptcode = ICPT_PROGI; in vsie_run()
1328 scb_s->iprcc = PGM_ADDRESSING; in vsie_run()
1329 scb_s->pgmilc = 4; in vsie_run()
1330 scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, 4); in vsie_run()
1339 * Returns: - address of a vsie page (cached or new one)
1340 * - NULL if the same scb address is already used by another VCPU
1341 * - ERR_PTR(-ENOMEM) if out of memory
1350 page = radix_tree_lookup(&kvm->arch.vsie.addr_to_page, addr >> 9); in get_vsie_page()
1362 nr_vcpus = atomic_read(&kvm->online_vcpus); in get_vsie_page()
1364 mutex_lock(&kvm->arch.vsie.mutex); in get_vsie_page()
1365 if (kvm->arch.vsie.page_count < nr_vcpus) { in get_vsie_page()
1368 mutex_unlock(&kvm->arch.vsie.mutex); in get_vsie_page()
1369 return ERR_PTR(-ENOMEM); in get_vsie_page()
1372 kvm->arch.vsie.pages[kvm->arch.vsie.page_count] = page; in get_vsie_page()
1373 kvm->arch.vsie.page_count++; in get_vsie_page()
1377 page = kvm->arch.vsie.pages[kvm->arch.vsie.next]; in get_vsie_page()
1381 kvm->arch.vsie.next++; in get_vsie_page()
1382 kvm->arch.vsie.next %= nr_vcpus; in get_vsie_page()
1384 radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9); in get_vsie_page()
1386 page->index = addr; in get_vsie_page()
1388 if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9, page)) { in get_vsie_page()
1390 mutex_unlock(&kvm->arch.vsie.mutex); in get_vsie_page()
1393 mutex_unlock(&kvm->arch.vsie.mutex); in get_vsie_page()
1396 memset(&vsie_page->scb_s, 0, sizeof(struct kvm_s390_sie_block)); in get_vsie_page()
1398 vsie_page->fault_addr = 0; in get_vsie_page()
1399 vsie_page->scb_s.ihcpu = 0xffffU; in get_vsie_page()
1417 vcpu->stat.instruction_sie++; in kvm_s390_handle_vsie()
1418 if (!test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_SIEF2)) in kvm_s390_handle_vsie()
1419 return -EOPNOTSUPP; in kvm_s390_handle_vsie()
1420 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) in kvm_s390_handle_vsie()
1434 vsie_page = get_vsie_page(vcpu->kvm, scb_addr); in kvm_s390_handle_vsie()
1438 /* double use of sie control block - simply do nothing */ in kvm_s390_handle_vsie()
1459 put_vsie_page(vcpu->kvm, vsie_page); in kvm_s390_handle_vsie()
1467 mutex_init(&kvm->arch.vsie.mutex); in kvm_s390_vsie_init()
1468 INIT_RADIX_TREE(&kvm->arch.vsie.addr_to_page, GFP_KERNEL_ACCOUNT); in kvm_s390_vsie_init()
1478 mutex_lock(&kvm->arch.vsie.mutex); in kvm_s390_vsie_destroy()
1479 for (i = 0; i < kvm->arch.vsie.page_count; i++) { in kvm_s390_vsie_destroy()
1480 page = kvm->arch.vsie.pages[i]; in kvm_s390_vsie_destroy()
1481 kvm->arch.vsie.pages[i] = NULL; in kvm_s390_vsie_destroy()
1485 radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9); in kvm_s390_vsie_destroy()
1488 kvm->arch.vsie.page_count = 0; in kvm_s390_vsie_destroy()
1489 mutex_unlock(&kvm->arch.vsie.mutex); in kvm_s390_vsie_destroy()
1494 struct kvm_s390_sie_block *scb = READ_ONCE(vcpu->arch.vsie_block); in kvm_s390_vsie_kick()
1501 atomic_or(PROG_BLOCK_SIE, &scb->prog20); in kvm_s390_vsie_kick()
1502 if (scb->prog0c & PROG_IN_SIE) in kvm_s390_vsie_kick()
1503 atomic_or(CPUSTAT_STOP_INT, &scb->cpuflags); in kvm_s390_vsie_kick()