Lines Matching +full:ipa +full:- +full:clock +full:- +full:enabled +full:- +full:valid
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()
145 return -EFAULT; in setup_apcb10()
147 apcb_s->apm[0] = apcb_h->apm[0] & tmp.apm[0]; in setup_apcb10()
148 apcb_s->aqm[0] = apcb_h->aqm[0] & tmp.aqm[0] & 0xffff000000000000UL; in setup_apcb10()
149 apcb_s->adm[0] = apcb_h->adm[0] & tmp.adm[0] & 0xffff000000000000UL; in setup_apcb10()
156 * setup_apcb00 - Copy to APCB FORMAT0 from APCB FORMAT0
162 * Returns 0 and -EFAULT on error reading guest apcb
169 return -EFAULT; in setup_apcb00()
177 * setup_apcb11 - Copy the FORMAT1 APCB from the guest to the shadow CRYCB
183 * Returns 0 and -EFAULT on error reading guest apcb
191 return -EFAULT; in setup_apcb11()
199 * setup_apcb - Create a shadow copy of the apcb.
224 return -EACCES; in setup_apcb()
226 return -EINVAL; in setup_apcb()
227 return setup_apcb11(vcpu, (unsigned long *)&crycb_s->apcb1, in setup_apcb()
228 (unsigned long) &crycb->apcb1, in setup_apcb()
229 (unsigned long *)&crycb_h->apcb1); in setup_apcb()
233 return setup_apcb10(vcpu, &crycb_s->apcb1, in setup_apcb()
234 (unsigned long) &crycb->apcb0, in setup_apcb()
235 &crycb_h->apcb1); in setup_apcb()
238 (unsigned long *) &crycb_s->apcb0, in setup_apcb()
239 (unsigned long) &crycb->apcb0, in setup_apcb()
240 (unsigned long *) &crycb_h->apcb0); in setup_apcb()
245 return -EACCES; in setup_apcb()
249 return setup_apcb10(vcpu, &crycb_s->apcb1, in setup_apcb()
250 (unsigned long) &crycb->apcb0, in setup_apcb()
251 &crycb_h->apcb1); in setup_apcb()
255 (unsigned long *) &crycb_s->apcb0, in setup_apcb()
256 (unsigned long) &crycb->apcb0, in setup_apcb()
257 (unsigned long *) &crycb_h->apcb0); in setup_apcb()
260 return -EINVAL; in setup_apcb()
264 * shadow_crycb - Create a shadow copy of the crycb block
269 * requested for guest 3 and enabled for guest 2.
271 * We accept format-1 or format-2, but we convert format-1 into format-2
273 * Using format-2 enables the firmware to choose the right format when
275 * There is nothing to do for format-0.
280 * Returns: - 0 if shadowed or nothing to do
281 * - > 0 if control has to be given to guest 2
285 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in shadow_crycb()
286 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in shadow_crycb()
287 const uint32_t crycbd_o = READ_ONCE(scb_o->crycbd); in shadow_crycb()
294 int key_msk = test_kvm_facility(vcpu->kvm, 76); in shadow_crycb()
296 int fmt_h = vcpu->arch.sie_block->crycbd & CRYCB_FORMAT_MASK; in shadow_crycb()
299 scb_s->crycbd = 0; in shadow_crycb()
301 apie_h = vcpu->arch.sie_block->eca & ECA_APIE; in shadow_crycb()
302 apie_s = apie_h & scb_o->eca; in shadow_crycb()
315 ret = setup_apcb(vcpu, &vsie_page->crycb, crycb_addr, in shadow_crycb()
316 vcpu->kvm->arch.crypto.crycb, in shadow_crycb()
320 scb_s->eca |= scb_o->eca & ECA_APIE; in shadow_crycb()
323 /* we may only allow it if enabled for guest 2 */ in shadow_crycb()
324 ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 & in shadow_crycb()
326 ecd_flags = scb_o->ecd & vcpu->arch.sie_block->ecd & ECD_ECC; in shadow_crycb()
332 vsie_page->crycb.dea_wrapping_key_mask, 56)) in shadow_crycb()
335 scb_s->ecb3 |= ecb3_flags; in shadow_crycb()
336 scb_s->ecd |= ecd_flags; in shadow_crycb()
339 b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask; in shadow_crycb()
341 vcpu->kvm->arch.crypto.crycb->dea_wrapping_key_mask; in shadow_crycb()
346 case -EINVAL: in shadow_crycb()
348 case -EFAULT: in shadow_crycb()
350 case -EACCES: in shadow_crycb()
353 scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | CRYCB_FORMAT2; in shadow_crycb()
360 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in prepare_ibc()
361 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in prepare_ibc()
362 /* READ_ONCE does not work on bitfields - use a temporary variable */ in prepare_ibc()
363 const uint32_t __new_ibc = scb_o->ibc; in prepare_ibc()
367 scb_s->ibc = 0; in prepare_ibc()
369 if (vcpu->kvm->arch.model.ibc && new_ibc) { in prepare_ibc()
370 scb_s->ibc = new_ibc; in prepare_ibc()
372 if (scb_s->ibc < min_ibc) in prepare_ibc()
373 scb_s->ibc = min_ibc; in prepare_ibc()
375 if (scb_s->ibc > vcpu->kvm->arch.model.ibc) in prepare_ibc()
376 scb_s->ibc = vcpu->kvm->arch.model.ibc; in prepare_ibc()
383 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in unshadow_scb()
384 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in unshadow_scb()
387 scb_o->icptcode = scb_s->icptcode; in unshadow_scb()
388 scb_o->icptstatus = scb_s->icptstatus; in unshadow_scb()
389 scb_o->ipa = scb_s->ipa; in unshadow_scb()
390 scb_o->ipb = scb_s->ipb; in unshadow_scb()
391 scb_o->gbea = scb_s->gbea; in unshadow_scb()
394 scb_o->cputm = scb_s->cputm; in unshadow_scb()
395 scb_o->ckc = scb_s->ckc; in unshadow_scb()
396 scb_o->todpr = scb_s->todpr; in unshadow_scb()
399 scb_o->gpsw = scb_s->gpsw; in unshadow_scb()
400 scb_o->gg14 = scb_s->gg14; in unshadow_scb()
401 scb_o->gg15 = scb_s->gg15; in unshadow_scb()
402 memcpy(scb_o->gcr, scb_s->gcr, 128); in unshadow_scb()
403 scb_o->pp = scb_s->pp; in unshadow_scb()
406 if (test_kvm_facility(vcpu->kvm, 82)) { in unshadow_scb()
407 scb_o->fpf &= ~FPF_BPBC; in unshadow_scb()
408 scb_o->fpf |= scb_s->fpf & FPF_BPBC; in unshadow_scb()
412 switch (scb_s->icptcode) { in unshadow_scb()
417 (void *)((u64)scb_s + 0xc0), 0xf0 - 0xc0); in unshadow_scb()
422 (void *)((u64)scb_s + 0xc0), 0xd0 - 0xc0); in unshadow_scb()
426 if (scb_s->ihcpu != 0xffffU) in unshadow_scb()
427 scb_o->ihcpu = scb_s->ihcpu; in unshadow_scb()
434 * Returns: - 0 if the scb has been shadowed
435 * - > 0 if control has to be given to guest 2
439 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in shadow_scb()
440 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in shadow_scb()
441 /* READ_ONCE does not work on bitfields - use a temporary variable */ in shadow_scb()
442 const uint32_t __new_prefix = scb_o->prefix; in shadow_scb()
444 const bool wants_tx = READ_ONCE(scb_o->ecb) & ECB_TE; in shadow_scb()
445 bool had_tx = scb_s->ecb & ECB_TE; in shadow_scb()
450 scb_s->icptcode = 0; in shadow_scb()
451 scb_s->eca = 0; in shadow_scb()
452 scb_s->ecb = 0; in shadow_scb()
453 scb_s->ecb2 = 0; in shadow_scb()
454 scb_s->ecb3 = 0; in shadow_scb()
455 scb_s->ecd = 0; in shadow_scb()
456 scb_s->fac = 0; in shadow_scb()
457 scb_s->fpf = 0; in shadow_scb()
464 scb_s->cputm = scb_o->cputm; in shadow_scb()
465 scb_s->ckc = scb_o->ckc; in shadow_scb()
466 scb_s->todpr = scb_o->todpr; in shadow_scb()
467 scb_s->epoch = scb_o->epoch; in shadow_scb()
470 scb_s->gpsw = scb_o->gpsw; in shadow_scb()
471 scb_s->gg14 = scb_o->gg14; in shadow_scb()
472 scb_s->gg15 = scb_o->gg15; in shadow_scb()
473 memcpy(scb_s->gcr, scb_o->gcr, 128); in shadow_scb()
474 scb_s->pp = scb_o->pp; in shadow_scb()
477 scb_s->gbea = scb_o->gbea; in shadow_scb()
478 scb_s->lctl = scb_o->lctl; in shadow_scb()
479 scb_s->svcc = scb_o->svcc; in shadow_scb()
480 scb_s->ictl = scb_o->ictl; in shadow_scb()
486 if (!(atomic_read(&scb_s->cpuflags) & CPUSTAT_KSS)) in shadow_scb()
487 scb_s->ictl |= ICTL_ISKE | ICTL_SSKE | ICTL_RRBE; in shadow_scb()
489 scb_s->icpua = scb_o->icpua; in shadow_scb()
491 if (!(atomic_read(&scb_s->cpuflags) & CPUSTAT_SM)) in shadow_scb()
492 new_mso = READ_ONCE(scb_o->mso) & 0xfffffffffff00000UL; in shadow_scb()
494 if (scb_s->mso != new_mso || scb_s->prefix != new_prefix) in shadow_scb()
497 scb_s->msl = scb_o->msl & 0xfffffffffff00000UL; in shadow_scb()
498 scb_s->mso = new_mso; in shadow_scb()
499 scb_s->prefix = new_prefix; in shadow_scb()
502 if (scb_s->ihcpu != 0xffffU) in shadow_scb()
503 scb_s->ihcpu = scb_o->ihcpu; in shadow_scb()
506 scb_s->eca |= scb_o->eca & (ECA_MVPGI | ECA_PROTEXCI); in shadow_scb()
507 /* Host-protection-interruption introduced with ESOP */ in shadow_scb()
508 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_ESOP)) in shadow_scb()
509 scb_s->ecb |= scb_o->ecb & ECB_HOSTPROTINT; in shadow_scb()
511 if (test_kvm_facility(vcpu->kvm, 73) && wants_tx) { in shadow_scb()
515 scb_s->ecb |= ECB_TE; in shadow_scb()
518 if (test_kvm_facility(vcpu->kvm, 82)) in shadow_scb()
519 scb_s->fpf |= scb_o->fpf & FPF_BPBC; in shadow_scb()
521 if (test_kvm_facility(vcpu->kvm, 129)) { in shadow_scb()
522 scb_s->eca |= scb_o->eca & ECA_VX; in shadow_scb()
523 scb_s->ecd |= scb_o->ecd & ECD_HOSTREGMGMT; in shadow_scb()
525 /* Run-time-Instrumentation */ in shadow_scb()
526 if (test_kvm_facility(vcpu->kvm, 64)) in shadow_scb()
527 scb_s->ecb3 |= scb_o->ecb3 & ECB3_RI; in shadow_scb()
529 if (test_kvm_facility(vcpu->kvm, 130)) in shadow_scb()
530 scb_s->ecb2 |= scb_o->ecb2 & ECB2_IEP; in shadow_scb()
532 if (test_kvm_facility(vcpu->kvm, 133)) { in shadow_scb()
533 scb_s->ecb |= scb_o->ecb & ECB_GS; in shadow_scb()
534 scb_s->ecd |= scb_o->ecd & ECD_HOSTREGMGMT; in shadow_scb()
536 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_SIIF)) in shadow_scb()
537 scb_s->eca |= scb_o->eca & ECA_SII; in shadow_scb()
538 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_IB)) in shadow_scb()
539 scb_s->eca |= scb_o->eca & ECA_IB; in shadow_scb()
540 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_CEI)) in shadow_scb()
541 scb_s->eca |= scb_o->eca & ECA_CEI; in shadow_scb()
543 if (test_kvm_facility(vcpu->kvm, 139)) in shadow_scb()
544 scb_s->ecd |= scb_o->ecd & ECD_MEF; in shadow_scb()
547 if (test_kvm_facility(vcpu->kvm, 156)) in shadow_scb()
548 scb_s->ecd |= scb_o->ecd & ECD_ETOKENF; in shadow_scb()
550 scb_s->hpid = HPID_VSIE; in shadow_scb()
551 scb_s->cpnc = scb_o->cpnc; in shadow_scb()
564 struct kvm *kvm = gmap->private; in kvm_s390_vsie_gmap_notifier()
580 for (i = 0; i < kvm->arch.vsie.page_count; i++) { in kvm_s390_vsie_gmap_notifier()
581 page = READ_ONCE(kvm->arch.vsie.pages[i]); in kvm_s390_vsie_gmap_notifier()
585 if (READ_ONCE(cur->gmap) != gmap) in kvm_s390_vsie_gmap_notifier()
587 prefix = cur->scb_s.prefix << GUEST_PREFIX_SHIFT; in kvm_s390_vsie_gmap_notifier()
589 prefix += cur->scb_s.mso; in kvm_s390_vsie_gmap_notifier()
590 if (prefix <= end && start <= prefix + 2 * PAGE_SIZE - 1) in kvm_s390_vsie_gmap_notifier()
596 * Map the first prefix page and if tx is enabled also the second prefix page.
602 * Returns: - 0 on if successfully mapped or already mapped
603 * - > 0 if control has to be given to guest 2
604 * - -EAGAIN if the caller can retry immediately
605 * - -ENOMEM if out of memory
609 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in map_prefix()
610 u64 prefix = scb_s->prefix << GUEST_PREFIX_SHIFT; in map_prefix()
620 prefix += scb_s->mso; in map_prefix()
622 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, prefix); in map_prefix()
623 if (!rc && (scb_s->ecb & ECB_TE)) in map_prefix()
624 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, in map_prefix()
632 if (rc > 0 || rc == -EFAULT) in map_prefix()
641 * Returns: - 0 on success
642 * - -EINVAL if the gpa is not valid guest storage
650 return -EINVAL; in pin_guest_page()
666 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in unpin_blocks()
669 hpa = (u64) scb_s->scaoh << 32 | scb_s->scaol; in unpin_blocks()
671 unpin_guest_page(vcpu->kvm, vsie_page->sca_gpa, hpa); in unpin_blocks()
672 vsie_page->sca_gpa = 0; in unpin_blocks()
673 scb_s->scaol = 0; in unpin_blocks()
674 scb_s->scaoh = 0; in unpin_blocks()
677 hpa = scb_s->itdba; in unpin_blocks()
679 unpin_guest_page(vcpu->kvm, vsie_page->itdba_gpa, hpa); in unpin_blocks()
680 vsie_page->itdba_gpa = 0; in unpin_blocks()
681 scb_s->itdba = 0; in unpin_blocks()
684 hpa = scb_s->gvrd; in unpin_blocks()
686 unpin_guest_page(vcpu->kvm, vsie_page->gvrd_gpa, hpa); in unpin_blocks()
687 vsie_page->gvrd_gpa = 0; in unpin_blocks()
688 scb_s->gvrd = 0; in unpin_blocks()
691 hpa = scb_s->riccbd; in unpin_blocks()
693 unpin_guest_page(vcpu->kvm, vsie_page->riccbd_gpa, hpa); in unpin_blocks()
694 vsie_page->riccbd_gpa = 0; in unpin_blocks()
695 scb_s->riccbd = 0; in unpin_blocks()
698 hpa = scb_s->sdnxo; in unpin_blocks()
700 unpin_guest_page(vcpu->kvm, vsie_page->sdnx_gpa, hpa); in unpin_blocks()
701 vsie_page->sdnx_gpa = 0; in unpin_blocks()
702 scb_s->sdnxo = 0; in unpin_blocks()
716 * Returns: - 0 if all blocks were pinned.
717 * - > 0 if control has to be given to guest 2
718 * - -ENOMEM if out of memory
722 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in pin_blocks()
723 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in pin_blocks()
728 gpa = READ_ONCE(scb_o->scaol) & ~0xfUL; in pin_blocks()
729 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_64BSCAO)) in pin_blocks()
730 gpa |= (u64) READ_ONCE(scb_o->scaoh) << 32; in pin_blocks()
737 ((gpa + sizeof(struct bsca_block) - 1) & PAGE_MASK)) in pin_blocks()
740 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
746 vsie_page->sca_gpa = gpa; in pin_blocks()
747 scb_s->scaoh = (u32)((u64)hpa >> 32); in pin_blocks()
748 scb_s->scaol = (u32)(u64)hpa; in pin_blocks()
751 gpa = READ_ONCE(scb_o->itdba) & ~0xffUL; in pin_blocks()
752 if (gpa && (scb_s->ecb & ECB_TE)) { in pin_blocks()
758 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
763 vsie_page->itdba_gpa = gpa; in pin_blocks()
764 scb_s->itdba = hpa; in pin_blocks()
767 gpa = READ_ONCE(scb_o->gvrd) & ~0x1ffUL; in pin_blocks()
768 if (gpa && (scb_s->eca & ECA_VX) && !(scb_s->ecd & ECD_HOSTREGMGMT)) { in pin_blocks()
777 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
782 vsie_page->gvrd_gpa = gpa; in pin_blocks()
783 scb_s->gvrd = hpa; in pin_blocks()
786 gpa = READ_ONCE(scb_o->riccbd) & ~0x3fUL; in pin_blocks()
787 if (gpa && (scb_s->ecb3 & ECB3_RI)) { in pin_blocks()
793 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
799 vsie_page->riccbd_gpa = gpa; in pin_blocks()
800 scb_s->riccbd = hpa; in pin_blocks()
802 if (((scb_s->ecb & ECB_GS) && !(scb_s->ecd & ECD_HOSTREGMGMT)) || in pin_blocks()
803 (scb_s->ecd & ECD_ETOKENF)) { in pin_blocks()
806 gpa = READ_ONCE(scb_o->sdnxo) & ~0xfUL; in pin_blocks()
807 sdnxc = READ_ONCE(scb_o->sdnxo) & 0xfUL; in pin_blocks()
816 if (gpa & ((1 << sdnxc) - 1)) { in pin_blocks()
823 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
828 vsie_page->sdnx_gpa = gpa; in pin_blocks()
829 scb_s->sdnxo = hpa | sdnxc; in pin_blocks()
841 hpa_t hpa = (hpa_t) vsie_page->scb_o; in unpin_scb()
844 unpin_guest_page(vcpu->kvm, gpa, hpa); in unpin_scb()
845 vsie_page->scb_o = NULL; in unpin_scb()
849 * Pin the scb at gpa provided by guest 2 at vsie_page->scb_o.
851 * Returns: - 0 if the scb was pinned.
852 * - > 0 if control has to be given to guest 2
860 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_scb()
866 vsie_page->scb_o = (struct kvm_s390_sie_block *) hpa; in pin_scb()
873 * Returns: - > 0 if control has to be given to guest 2
882 /* 0-51: virtual address */ in inject_fault()
884 /* 52-53: store / fetch */ in inject_fault()
886 /* 62-63: asce id (alway primary == 0) */ in inject_fault()
902 * Returns: - 0 if the fault was resolved
903 * - > 0 if control has to be given to guest 2
904 * - < 0 if an error occurred
910 if (current->thread.gmap_int_code == PGM_PROTECTION) in handle_fault()
913 current->thread.gmap_addr, 1); in handle_fault()
915 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, in handle_fault()
916 current->thread.gmap_addr); in handle_fault()
919 current->thread.gmap_addr, in handle_fault()
920 current->thread.gmap_write_flag); in handle_fault()
922 vsie_page->fault_addr = current->thread.gmap_addr; in handle_fault()
929 * one superfluous SIE re-entry and direct exit.
936 if (vsie_page->fault_addr) in handle_last_fault()
937 kvm_s390_shadow_fault(vcpu, vsie_page->gmap, in handle_last_fault()
938 vsie_page->fault_addr); in handle_last_fault()
939 vsie_page->fault_addr = 0; in handle_last_fault()
944 vsie_page->scb_s.icptcode = 0; in clear_vsie_icpt()
950 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in retry_vsie_icpt()
951 int ilen = insn_length(scb_s->ipa >> 8); in retry_vsie_icpt()
954 if (scb_s->icptstatus & 1) { in retry_vsie_icpt()
955 ilen = (scb_s->icptstatus >> 4) & 0x6; in retry_vsie_icpt()
959 scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, ilen); in retry_vsie_icpt()
965 * Retry instruction execution if enabled for and provided by guest 2.
967 * Returns: - 0 if handled (retry or guest 2 icpt)
968 * - > 0 if control has to be given to guest 2
972 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in handle_stfle()
973 __u32 fac = READ_ONCE(vsie_page->scb_o->fac) & 0x7ffffff8U; in handle_stfle()
975 if (fac && test_kvm_facility(vcpu->kvm, 7)) { in handle_stfle()
977 if (read_guest_real(vcpu, fac, &vsie_page->fac, in handle_stfle()
978 sizeof(vsie_page->fac))) in handle_stfle()
980 scb_s->fac = (__u32)(__u64) &vsie_page->fac; in handle_stfle()
989 * Returns: - 0 everything went fine
990 * - > 0 if control has to be given to guest 2
991 * - < 0 if an error occurred
994 __releases(vcpu->kvm->srcu) in do_vsie_run()
995 __acquires(vcpu->kvm->srcu) in do_vsie_run()
997 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in do_vsie_run()
998 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in do_vsie_run()
1004 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); in do_vsie_run()
1015 if (test_kvm_facility(vcpu->kvm, 82) && in do_vsie_run()
1016 vcpu->arch.sie_block->fpf & FPF_BPBC) in do_vsie_run()
1029 vcpu->arch.sie_block->prog0c |= PROG_IN_SIE; in do_vsie_run()
1032 rc = sie64a(scb_s, vcpu->run->s.regs.gprs); in do_vsie_run()
1034 vcpu->arch.sie_block->prog0c &= ~PROG_IN_SIE; in do_vsie_run()
1044 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); in do_vsie_run()
1046 if (rc == -EINTR) { in do_vsie_run()
1048 kvm_s390_reinject_machine_check(vcpu, &vsie_page->mcck_info); in do_vsie_run()
1054 else if (rc == -EFAULT) in do_vsie_run()
1057 switch (scb_s->icptcode) { in do_vsie_run()
1059 if (scb_s->ipa == 0xb2b0) in do_vsie_run()
1063 /* stop not requested by g2 - must have been a kick */ in do_vsie_run()
1064 if (!(atomic_read(&scb_o->cpuflags) & CPUSTAT_STOP_INT)) in do_vsie_run()
1068 if ((scb_s->ipa & 0xf000) != 0xf000) in do_vsie_run()
1069 scb_s->ipa += 0x1000; in do_vsie_run()
1077 if (vsie_page->gmap) in release_gmap_shadow()
1078 gmap_put(vsie_page->gmap); in release_gmap_shadow()
1079 WRITE_ONCE(vsie_page->gmap, NULL); in release_gmap_shadow()
1091 asce = vcpu->arch.sie_block->gcr[1]; in acquire_gmap_shadow()
1092 cr0.val = vcpu->arch.sie_block->gcr[0]; in acquire_gmap_shadow()
1093 edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8); in acquire_gmap_shadow()
1094 edat += edat && test_kvm_facility(vcpu->kvm, 78); in acquire_gmap_shadow()
1098 * we're holding has been unshadowed. If the gmap is still valid, in acquire_gmap_shadow()
1101 if (vsie_page->gmap && gmap_shadow_valid(vsie_page->gmap, asce, edat)) in acquire_gmap_shadow()
1104 /* release the old shadow - if any, and mark the prefix as unmapped */ in acquire_gmap_shadow()
1106 gmap = gmap_shadow(vcpu->arch.gmap, asce, edat); in acquire_gmap_shadow()
1109 gmap->private = vcpu->kvm; in acquire_gmap_shadow()
1110 WRITE_ONCE(vsie_page->gmap, gmap); in acquire_gmap_shadow()
1120 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in register_shadow_scb()
1122 WRITE_ONCE(vcpu->arch.vsie_block, &vsie_page->scb_s); in register_shadow_scb()
1125 * therefore the vsie -> Simulate Wait state. in register_shadow_scb()
1130 * automatically be adjusted on tod clock changes via kvm_sync_clock. in register_shadow_scb()
1133 scb_s->epoch += vcpu->kvm->arch.epoch; in register_shadow_scb()
1135 if (scb_s->ecd & ECD_MEF) { in register_shadow_scb()
1136 scb_s->epdx += vcpu->kvm->arch.epdx; in register_shadow_scb()
1137 if (scb_s->epoch < vcpu->kvm->arch.epoch) in register_shadow_scb()
1138 scb_s->epdx += 1; in register_shadow_scb()
1150 WRITE_ONCE(vcpu->arch.vsie_block, NULL); in unregister_shadow_scb()
1157 * Returns: - 0 if no errors occurred
1158 * - > 0 if control has to be given to guest 2
1159 * - -ENOMEM if out of memory
1163 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in vsie_run()
1171 gmap_enable(vsie_page->gmap); in vsie_run()
1174 gmap_enable(vcpu->arch.gmap); in vsie_run()
1176 atomic_andnot(PROG_BLOCK_SIE, &scb_s->prog20); in vsie_run()
1178 if (rc == -EAGAIN) in vsie_run()
1180 if (rc || scb_s->icptcode || signal_pending(current) || in vsie_run()
1187 if (rc == -EFAULT) { in vsie_run()
1198 scb_s->icptcode = ICPT_PROGI; in vsie_run()
1199 scb_s->iprcc = PGM_ADDRESSING; in vsie_run()
1200 scb_s->pgmilc = 4; in vsie_run()
1201 scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, 4); in vsie_run()
1210 * Returns: - address of a vsie page (cached or new one)
1211 * - NULL if the same scb address is already used by another VCPU
1212 * - ERR_PTR(-ENOMEM) if out of memory
1221 page = radix_tree_lookup(&kvm->arch.vsie.addr_to_page, addr >> 9); in get_vsie_page()
1233 nr_vcpus = atomic_read(&kvm->online_vcpus); in get_vsie_page()
1235 mutex_lock(&kvm->arch.vsie.mutex); in get_vsie_page()
1236 if (kvm->arch.vsie.page_count < nr_vcpus) { in get_vsie_page()
1239 mutex_unlock(&kvm->arch.vsie.mutex); in get_vsie_page()
1240 return ERR_PTR(-ENOMEM); in get_vsie_page()
1243 kvm->arch.vsie.pages[kvm->arch.vsie.page_count] = page; in get_vsie_page()
1244 kvm->arch.vsie.page_count++; in get_vsie_page()
1248 page = kvm->arch.vsie.pages[kvm->arch.vsie.next]; in get_vsie_page()
1252 kvm->arch.vsie.next++; in get_vsie_page()
1253 kvm->arch.vsie.next %= nr_vcpus; in get_vsie_page()
1255 radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9); in get_vsie_page()
1257 page->index = addr; in get_vsie_page()
1259 if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9, page)) { in get_vsie_page()
1261 mutex_unlock(&kvm->arch.vsie.mutex); in get_vsie_page()
1264 mutex_unlock(&kvm->arch.vsie.mutex); in get_vsie_page()
1267 memset(&vsie_page->scb_s, 0, sizeof(struct kvm_s390_sie_block)); in get_vsie_page()
1269 vsie_page->fault_addr = 0; in get_vsie_page()
1270 vsie_page->scb_s.ihcpu = 0xffffU; in get_vsie_page()
1288 vcpu->stat.instruction_sie++; in kvm_s390_handle_vsie()
1289 if (!test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_SIEF2)) in kvm_s390_handle_vsie()
1290 return -EOPNOTSUPP; in kvm_s390_handle_vsie()
1291 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) in kvm_s390_handle_vsie()
1305 vsie_page = get_vsie_page(vcpu->kvm, scb_addr); in kvm_s390_handle_vsie()
1309 /* double use of sie control block - simply do nothing */ in kvm_s390_handle_vsie()
1330 put_vsie_page(vcpu->kvm, vsie_page); in kvm_s390_handle_vsie()
1338 mutex_init(&kvm->arch.vsie.mutex); in kvm_s390_vsie_init()
1339 INIT_RADIX_TREE(&kvm->arch.vsie.addr_to_page, GFP_KERNEL); in kvm_s390_vsie_init()
1349 mutex_lock(&kvm->arch.vsie.mutex); in kvm_s390_vsie_destroy()
1350 for (i = 0; i < kvm->arch.vsie.page_count; i++) { in kvm_s390_vsie_destroy()
1351 page = kvm->arch.vsie.pages[i]; in kvm_s390_vsie_destroy()
1352 kvm->arch.vsie.pages[i] = NULL; in kvm_s390_vsie_destroy()
1356 radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9); in kvm_s390_vsie_destroy()
1359 kvm->arch.vsie.page_count = 0; in kvm_s390_vsie_destroy()
1360 mutex_unlock(&kvm->arch.vsie.mutex); in kvm_s390_vsie_destroy()
1365 struct kvm_s390_sie_block *scb = READ_ONCE(vcpu->arch.vsie_block); in kvm_s390_vsie_kick()
1369 * still valid in the cache. So we can safely kick it. in kvm_s390_vsie_kick()
1372 atomic_or(PROG_BLOCK_SIE, &scb->prog20); in kvm_s390_vsie_kick()
1373 if (scb->prog0c & PROG_IN_SIE) in kvm_s390_vsie_kick()
1374 atomic_or(CPUSTAT_STOP_INT, &scb->cpuflags); in kvm_s390_vsie_kick()