Lines Matching +full:segment +full:- +full:no +full:- +full:remap

1 // SPDX-License-Identifier: GPL-2.0
22 #include "kvm-s390.h"
48 __u8 reserved[0x0700 - 0x0258]; /* 0x0258 */
57 scb->ipa = 0x1000; in set_validity_icpt()
58 scb->ipb = ((__u32) reason_code) << 16; in set_validity_icpt()
59 scb->icptcode = ICPT_VALIDITY; in set_validity_icpt()
66 atomic_or(PROG_REQUEST, &vsie_page->scb_s.prog20); in prefix_unmapped()
73 if (vsie_page->scb_s.prog0c & PROG_IN_SIE) in prefix_unmapped_sync()
74 atomic_or(CPUSTAT_STOP_INT, &vsie_page->scb_s.cpuflags); in prefix_unmapped_sync()
75 while (vsie_page->scb_s.prog0c & PROG_IN_SIE) in prefix_unmapped_sync()
82 atomic_andnot(PROG_REQUEST, &vsie_page->scb_s.prog20); in prefix_mapped()
88 return !(atomic_read(&vsie_page->scb_s.prog20) & PROG_REQUEST); in prefix_is_mapped()
97 cpuflags = atomic_read(&vsie_page->scb_o->cpuflags); in update_intervention_requests()
98 atomic_andnot(bits, &vsie_page->scb_s.cpuflags); in update_intervention_requests()
99 atomic_or(cpuflags & bits, &vsie_page->scb_s.cpuflags); in update_intervention_requests()
105 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in prepare_cpuflags()
106 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in prepare_cpuflags()
107 int newflags, cpuflags = atomic_read(&scb_o->cpuflags); in prepare_cpuflags()
120 if (cpuflags & CPUSTAT_GED && test_kvm_facility(vcpu->kvm, 8)) in prepare_cpuflags()
122 if (cpuflags & CPUSTAT_GED2 && test_kvm_facility(vcpu->kvm, 78)) { in prepare_cpuflags()
127 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_GPERE)) in prepare_cpuflags()
129 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_GSLS)) in prepare_cpuflags()
131 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_IBS)) in prepare_cpuflags()
133 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_KSS)) in prepare_cpuflags()
136 atomic_set(&scb_s->cpuflags, newflags); in prepare_cpuflags()
146 return -EFAULT; in setup_apcb10()
148 apcb_s->apm[0] = apcb_h->apm[0] & tmp.apm[0]; in setup_apcb10()
149 apcb_s->aqm[0] = apcb_h->aqm[0] & tmp.aqm[0] & 0xffff000000000000UL; in setup_apcb10()
150 apcb_s->adm[0] = apcb_h->adm[0] & tmp.adm[0] & 0xffff000000000000UL; in setup_apcb10()
157 * setup_apcb00 - Copy to APCB FORMAT0 from APCB FORMAT0
163 * Returns 0 and -EFAULT on error reading guest apcb
170 return -EFAULT; in setup_apcb00()
178 * setup_apcb11 - Copy the FORMAT1 APCB from the guest to the shadow CRYCB
184 * Returns 0 and -EFAULT on error reading guest apcb
192 return -EFAULT; in setup_apcb11()
200 * setup_apcb - Create a shadow copy of the apcb.
225 return -EACCES; in setup_apcb()
227 return -EINVAL; in setup_apcb()
228 return setup_apcb11(vcpu, (unsigned long *)&crycb_s->apcb1, in setup_apcb()
229 (unsigned long) &crycb->apcb1, in setup_apcb()
230 (unsigned long *)&crycb_h->apcb1); in setup_apcb()
234 return setup_apcb10(vcpu, &crycb_s->apcb1, in setup_apcb()
235 (unsigned long) &crycb->apcb0, in setup_apcb()
236 &crycb_h->apcb1); in setup_apcb()
239 (unsigned long *) &crycb_s->apcb0, in setup_apcb()
240 (unsigned long) &crycb->apcb0, in setup_apcb()
241 (unsigned long *) &crycb_h->apcb0); in setup_apcb()
246 return -EACCES; in setup_apcb()
250 return setup_apcb10(vcpu, &crycb_s->apcb1, in setup_apcb()
251 (unsigned long) &crycb->apcb0, in setup_apcb()
252 &crycb_h->apcb1); in setup_apcb()
256 (unsigned long *) &crycb_s->apcb0, in setup_apcb()
257 (unsigned long) &crycb->apcb0, in setup_apcb()
258 (unsigned long *) &crycb_h->apcb0); in setup_apcb()
261 return -EINVAL; in setup_apcb()
265 * shadow_crycb - Create a shadow copy of the crycb block
272 * We accept format-1 or format-2, but we convert format-1 into format-2
274 * Using format-2 enables the firmware to choose the right format when
276 * There is nothing to do for format-0.
281 * Returns: - 0 if shadowed or nothing to do
282 * - > 0 if control has to be given to guest 2
286 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in shadow_crycb()
287 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in shadow_crycb()
288 const uint32_t crycbd_o = READ_ONCE(scb_o->crycbd); in shadow_crycb()
295 int key_msk = test_kvm_facility(vcpu->kvm, 76); in shadow_crycb()
297 int fmt_h = vcpu->arch.sie_block->crycbd & CRYCB_FORMAT_MASK; in shadow_crycb()
300 scb_s->crycbd = 0; in shadow_crycb()
302 apie_h = vcpu->arch.sie_block->eca & ECA_APIE; in shadow_crycb()
303 apie_s = apie_h & scb_o->eca; in shadow_crycb()
316 ret = setup_apcb(vcpu, &vsie_page->crycb, crycb_addr, in shadow_crycb()
317 vcpu->kvm->arch.crypto.crycb, in shadow_crycb()
321 scb_s->eca |= scb_o->eca & ECA_APIE; in shadow_crycb()
325 ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 & in shadow_crycb()
327 ecd_flags = scb_o->ecd & vcpu->arch.sie_block->ecd & ECD_ECC; in shadow_crycb()
333 vsie_page->crycb.dea_wrapping_key_mask, 56)) in shadow_crycb()
336 scb_s->ecb3 |= ecb3_flags; in shadow_crycb()
337 scb_s->ecd |= ecd_flags; in shadow_crycb()
340 b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask; in shadow_crycb()
342 vcpu->kvm->arch.crypto.crycb->dea_wrapping_key_mask; in shadow_crycb()
347 case -EINVAL: in shadow_crycb()
349 case -EFAULT: in shadow_crycb()
351 case -EACCES: in shadow_crycb()
354 scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | CRYCB_FORMAT2; in shadow_crycb()
361 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in prepare_ibc()
362 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in prepare_ibc()
363 /* READ_ONCE does not work on bitfields - use a temporary variable */ in prepare_ibc()
364 const uint32_t __new_ibc = scb_o->ibc; in prepare_ibc()
368 scb_s->ibc = 0; in prepare_ibc()
370 if (vcpu->kvm->arch.model.ibc && new_ibc) { in prepare_ibc()
371 scb_s->ibc = new_ibc; in prepare_ibc()
373 if (scb_s->ibc < min_ibc) in prepare_ibc()
374 scb_s->ibc = min_ibc; in prepare_ibc()
376 if (scb_s->ibc > vcpu->kvm->arch.model.ibc) in prepare_ibc()
377 scb_s->ibc = vcpu->kvm->arch.model.ibc; in prepare_ibc()
384 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in unshadow_scb()
385 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in unshadow_scb()
388 scb_o->icptcode = scb_s->icptcode; in unshadow_scb()
389 scb_o->icptstatus = scb_s->icptstatus; in unshadow_scb()
390 scb_o->ipa = scb_s->ipa; in unshadow_scb()
391 scb_o->ipb = scb_s->ipb; in unshadow_scb()
392 scb_o->gbea = scb_s->gbea; in unshadow_scb()
395 scb_o->cputm = scb_s->cputm; in unshadow_scb()
396 scb_o->ckc = scb_s->ckc; in unshadow_scb()
397 scb_o->todpr = scb_s->todpr; in unshadow_scb()
400 scb_o->gpsw = scb_s->gpsw; in unshadow_scb()
401 scb_o->gg14 = scb_s->gg14; in unshadow_scb()
402 scb_o->gg15 = scb_s->gg15; in unshadow_scb()
403 memcpy(scb_o->gcr, scb_s->gcr, 128); in unshadow_scb()
404 scb_o->pp = scb_s->pp; in unshadow_scb()
407 if (test_kvm_facility(vcpu->kvm, 82)) { in unshadow_scb()
408 scb_o->fpf &= ~FPF_BPBC; in unshadow_scb()
409 scb_o->fpf |= scb_s->fpf & FPF_BPBC; in unshadow_scb()
413 switch (scb_s->icptcode) { in unshadow_scb()
418 (void *)((u64)scb_s + 0xc0), 0xf0 - 0xc0); in unshadow_scb()
422 if (scb_s->ihcpu != 0xffffU) in unshadow_scb()
423 scb_o->ihcpu = scb_s->ihcpu; in unshadow_scb()
430 * Returns: - 0 if the scb has been shadowed
431 * - > 0 if control has to be given to guest 2
435 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in shadow_scb()
436 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in shadow_scb()
437 /* READ_ONCE does not work on bitfields - use a temporary variable */ in shadow_scb()
438 const uint32_t __new_prefix = scb_o->prefix; in shadow_scb()
440 const bool wants_tx = READ_ONCE(scb_o->ecb) & ECB_TE; in shadow_scb()
441 bool had_tx = scb_s->ecb & ECB_TE; in shadow_scb()
446 scb_s->icptcode = 0; in shadow_scb()
447 scb_s->eca = 0; in shadow_scb()
448 scb_s->ecb = 0; in shadow_scb()
449 scb_s->ecb2 = 0; in shadow_scb()
450 scb_s->ecb3 = 0; in shadow_scb()
451 scb_s->ecd = 0; in shadow_scb()
452 scb_s->fac = 0; in shadow_scb()
453 scb_s->fpf = 0; in shadow_scb()
460 scb_s->cputm = scb_o->cputm; in shadow_scb()
461 scb_s->ckc = scb_o->ckc; in shadow_scb()
462 scb_s->todpr = scb_o->todpr; in shadow_scb()
463 scb_s->epoch = scb_o->epoch; in shadow_scb()
466 scb_s->gpsw = scb_o->gpsw; in shadow_scb()
467 scb_s->gg14 = scb_o->gg14; in shadow_scb()
468 scb_s->gg15 = scb_o->gg15; in shadow_scb()
469 memcpy(scb_s->gcr, scb_o->gcr, 128); in shadow_scb()
470 scb_s->pp = scb_o->pp; in shadow_scb()
473 scb_s->gbea = scb_o->gbea; in shadow_scb()
474 scb_s->lctl = scb_o->lctl; in shadow_scb()
475 scb_s->svcc = scb_o->svcc; in shadow_scb()
476 scb_s->ictl = scb_o->ictl; in shadow_scb()
482 if (!(atomic_read(&scb_s->cpuflags) & CPUSTAT_KSS)) in shadow_scb()
483 scb_s->ictl |= ICTL_ISKE | ICTL_SSKE | ICTL_RRBE; in shadow_scb()
485 scb_s->icpua = scb_o->icpua; in shadow_scb()
487 if (!(atomic_read(&scb_s->cpuflags) & CPUSTAT_SM)) in shadow_scb()
488 new_mso = READ_ONCE(scb_o->mso) & 0xfffffffffff00000UL; in shadow_scb()
489 /* if the hva of the prefix changes, we have to remap the prefix */ in shadow_scb()
490 if (scb_s->mso != new_mso || scb_s->prefix != new_prefix) in shadow_scb()
493 scb_s->msl = scb_o->msl & 0xfffffffffff00000UL; in shadow_scb()
494 scb_s->mso = new_mso; in shadow_scb()
495 scb_s->prefix = new_prefix; in shadow_scb()
498 if (scb_s->ihcpu != 0xffffU) in shadow_scb()
499 scb_s->ihcpu = scb_o->ihcpu; in shadow_scb()
502 scb_s->eca |= scb_o->eca & (ECA_MVPGI | ECA_PROTEXCI); in shadow_scb()
503 /* Host-protection-interruption introduced with ESOP */ in shadow_scb()
504 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_ESOP)) in shadow_scb()
505 scb_s->ecb |= scb_o->ecb & ECB_HOSTPROTINT; in shadow_scb()
512 if (test_kvm_facility(vcpu->kvm, 11)) in shadow_scb()
513 scb_s->ecb |= scb_o->ecb & ECB_PTF; in shadow_scb()
515 if (test_kvm_facility(vcpu->kvm, 73) && wants_tx) { in shadow_scb()
516 /* remap the prefix is tx is toggled on */ in shadow_scb()
519 scb_s->ecb |= ECB_TE; in shadow_scb()
522 scb_s->ecb |= scb_o->ecb & ECB_SPECI; in shadow_scb()
524 if (test_kvm_facility(vcpu->kvm, 82)) in shadow_scb()
525 scb_s->fpf |= scb_o->fpf & FPF_BPBC; in shadow_scb()
527 if (test_kvm_facility(vcpu->kvm, 129)) { in shadow_scb()
528 scb_s->eca |= scb_o->eca & ECA_VX; in shadow_scb()
529 scb_s->ecd |= scb_o->ecd & ECD_HOSTREGMGMT; in shadow_scb()
531 /* Run-time-Instrumentation */ in shadow_scb()
532 if (test_kvm_facility(vcpu->kvm, 64)) in shadow_scb()
533 scb_s->ecb3 |= scb_o->ecb3 & ECB3_RI; in shadow_scb()
535 if (test_kvm_facility(vcpu->kvm, 130)) in shadow_scb()
536 scb_s->ecb2 |= scb_o->ecb2 & ECB2_IEP; in shadow_scb()
538 if (test_kvm_facility(vcpu->kvm, 133)) { in shadow_scb()
539 scb_s->ecb |= scb_o->ecb & ECB_GS; in shadow_scb()
540 scb_s->ecd |= scb_o->ecd & ECD_HOSTREGMGMT; in shadow_scb()
542 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_SIIF)) in shadow_scb()
543 scb_s->eca |= scb_o->eca & ECA_SII; in shadow_scb()
544 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_IB)) in shadow_scb()
545 scb_s->eca |= scb_o->eca & ECA_IB; in shadow_scb()
546 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_CEI)) in shadow_scb()
547 scb_s->eca |= scb_o->eca & ECA_CEI; in shadow_scb()
549 if (test_kvm_facility(vcpu->kvm, 139)) { in shadow_scb()
550 scb_s->ecd |= scb_o->ecd & ECD_MEF; in shadow_scb()
551 scb_s->epdx = scb_o->epdx; in shadow_scb()
555 if (test_kvm_facility(vcpu->kvm, 156)) in shadow_scb()
556 scb_s->ecd |= scb_o->ecd & ECD_ETOKENF; in shadow_scb()
558 scb_s->hpid = HPID_VSIE; in shadow_scb()
559 scb_s->cpnc = scb_o->cpnc; in shadow_scb()
572 struct kvm *kvm = gmap->private; in kvm_s390_vsie_gmap_notifier()
588 for (i = 0; i < kvm->arch.vsie.page_count; i++) { in kvm_s390_vsie_gmap_notifier()
589 page = READ_ONCE(kvm->arch.vsie.pages[i]); in kvm_s390_vsie_gmap_notifier()
593 if (READ_ONCE(cur->gmap) != gmap) in kvm_s390_vsie_gmap_notifier()
595 prefix = cur->scb_s.prefix << GUEST_PREFIX_SHIFT; in kvm_s390_vsie_gmap_notifier()
597 prefix += cur->scb_s.mso; in kvm_s390_vsie_gmap_notifier()
598 if (prefix <= end && start <= prefix + 2 * PAGE_SIZE - 1) in kvm_s390_vsie_gmap_notifier()
610 * Returns: - 0 on if successfully mapped or already mapped
611 * - > 0 if control has to be given to guest 2
612 * - -EAGAIN if the caller can retry immediately
613 * - -ENOMEM if out of memory
617 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in map_prefix()
618 u64 prefix = scb_s->prefix << GUEST_PREFIX_SHIFT; in map_prefix()
628 prefix += scb_s->mso; in map_prefix()
630 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, prefix, NULL); in map_prefix()
631 if (!rc && (scb_s->ecb & ECB_TE)) in map_prefix()
632 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, in map_prefix()
640 if (rc > 0 || rc == -EFAULT) in map_prefix()
649 * Returns: - 0 on success
650 * - -EINVAL if the gpa is not valid guest storage
658 return -EINVAL; in pin_guest_page()
674 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in unpin_blocks()
677 hpa = (u64) scb_s->scaoh << 32 | scb_s->scaol; in unpin_blocks()
679 unpin_guest_page(vcpu->kvm, vsie_page->sca_gpa, hpa); in unpin_blocks()
680 vsie_page->sca_gpa = 0; in unpin_blocks()
681 scb_s->scaol = 0; in unpin_blocks()
682 scb_s->scaoh = 0; in unpin_blocks()
685 hpa = scb_s->itdba; in unpin_blocks()
687 unpin_guest_page(vcpu->kvm, vsie_page->itdba_gpa, hpa); in unpin_blocks()
688 vsie_page->itdba_gpa = 0; in unpin_blocks()
689 scb_s->itdba = 0; in unpin_blocks()
692 hpa = scb_s->gvrd; in unpin_blocks()
694 unpin_guest_page(vcpu->kvm, vsie_page->gvrd_gpa, hpa); in unpin_blocks()
695 vsie_page->gvrd_gpa = 0; in unpin_blocks()
696 scb_s->gvrd = 0; in unpin_blocks()
699 hpa = scb_s->riccbd; in unpin_blocks()
701 unpin_guest_page(vcpu->kvm, vsie_page->riccbd_gpa, hpa); in unpin_blocks()
702 vsie_page->riccbd_gpa = 0; in unpin_blocks()
703 scb_s->riccbd = 0; in unpin_blocks()
706 hpa = scb_s->sdnxo; in unpin_blocks()
708 unpin_guest_page(vcpu->kvm, vsie_page->sdnx_gpa, hpa); in unpin_blocks()
709 vsie_page->sdnx_gpa = 0; in unpin_blocks()
710 scb_s->sdnxo = 0; in unpin_blocks()
724 * Returns: - 0 if all blocks were pinned.
725 * - > 0 if control has to be given to guest 2
726 * - -ENOMEM if out of memory
730 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in pin_blocks()
731 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in pin_blocks()
736 gpa = READ_ONCE(scb_o->scaol) & ~0xfUL; in pin_blocks()
737 if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_64BSCAO)) in pin_blocks()
738 gpa |= (u64) READ_ONCE(scb_o->scaoh) << 32; in pin_blocks()
745 ((gpa + sizeof(struct bsca_block) - 1) & PAGE_MASK)) in pin_blocks()
748 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
754 vsie_page->sca_gpa = gpa; in pin_blocks()
755 scb_s->scaoh = (u32)((u64)hpa >> 32); in pin_blocks()
756 scb_s->scaol = (u32)(u64)hpa; in pin_blocks()
759 gpa = READ_ONCE(scb_o->itdba) & ~0xffUL; in pin_blocks()
760 if (gpa && (scb_s->ecb & ECB_TE)) { in pin_blocks()
766 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
771 vsie_page->itdba_gpa = gpa; in pin_blocks()
772 scb_s->itdba = hpa; in pin_blocks()
775 gpa = READ_ONCE(scb_o->gvrd) & ~0x1ffUL; in pin_blocks()
776 if (gpa && (scb_s->eca & ECA_VX) && !(scb_s->ecd & ECD_HOSTREGMGMT)) { in pin_blocks()
785 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
790 vsie_page->gvrd_gpa = gpa; in pin_blocks()
791 scb_s->gvrd = hpa; in pin_blocks()
794 gpa = READ_ONCE(scb_o->riccbd) & ~0x3fUL; in pin_blocks()
795 if (gpa && (scb_s->ecb3 & ECB3_RI)) { in pin_blocks()
801 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
807 vsie_page->riccbd_gpa = gpa; in pin_blocks()
808 scb_s->riccbd = hpa; in pin_blocks()
810 if (((scb_s->ecb & ECB_GS) && !(scb_s->ecd & ECD_HOSTREGMGMT)) || in pin_blocks()
811 (scb_s->ecd & ECD_ETOKENF)) { in pin_blocks()
814 gpa = READ_ONCE(scb_o->sdnxo) & ~0xfUL; in pin_blocks()
815 sdnxc = READ_ONCE(scb_o->sdnxo) & 0xfUL; in pin_blocks()
824 if (gpa & ((1 << sdnxc) - 1)) { in pin_blocks()
831 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_blocks()
836 vsie_page->sdnx_gpa = gpa; in pin_blocks()
837 scb_s->sdnxo = hpa | sdnxc; in pin_blocks()
849 hpa_t hpa = (hpa_t) vsie_page->scb_o; in unpin_scb()
852 unpin_guest_page(vcpu->kvm, gpa, hpa); in unpin_scb()
853 vsie_page->scb_o = NULL; in unpin_scb()
857 * Pin the scb at gpa provided by guest 2 at vsie_page->scb_o.
859 * Returns: - 0 if the scb was pinned.
860 * - > 0 if control has to be given to guest 2
868 rc = pin_guest_page(vcpu->kvm, gpa, &hpa); in pin_scb()
874 vsie_page->scb_o = (struct kvm_s390_sie_block *) hpa; in pin_scb()
881 * Returns: - > 0 if control has to be given to guest 2
890 /* 0-51: virtual address */ in inject_fault()
892 /* 52-53: store / fetch */ in inject_fault()
894 /* 62-63: asce id (alway primary == 0) */ in inject_fault()
910 * Returns: - 0 if the fault was resolved
911 * - > 0 if control has to be given to guest 2
912 * - < 0 if an error occurred
918 if (current->thread.gmap_int_code == PGM_PROTECTION) in handle_fault()
921 current->thread.gmap_addr, 1); in handle_fault()
923 rc = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, in handle_fault()
924 current->thread.gmap_addr, NULL); in handle_fault()
927 current->thread.gmap_addr, in handle_fault()
928 current->thread.gmap_write_flag); in handle_fault()
930 vsie_page->fault_addr = current->thread.gmap_addr; in handle_fault()
937 * one superfluous SIE re-entry and direct exit.
944 if (vsie_page->fault_addr) in handle_last_fault()
945 kvm_s390_shadow_fault(vcpu, vsie_page->gmap, in handle_last_fault()
946 vsie_page->fault_addr, NULL); in handle_last_fault()
947 vsie_page->fault_addr = 0; in handle_last_fault()
952 vsie_page->scb_s.icptcode = 0; in clear_vsie_icpt()
958 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in retry_vsie_icpt()
959 int ilen = insn_length(scb_s->ipa >> 8); in retry_vsie_icpt()
962 if (scb_s->icptstatus & 1) { in retry_vsie_icpt()
963 ilen = (scb_s->icptstatus >> 4) & 0x6; in retry_vsie_icpt()
967 scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, ilen); in retry_vsie_icpt()
975 * Returns: - 0 if handled (retry or guest 2 icpt)
976 * - > 0 if control has to be given to guest 2
980 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in handle_stfle()
981 __u32 fac = READ_ONCE(vsie_page->scb_o->fac) & 0x7ffffff8U; in handle_stfle()
983 if (fac && test_kvm_facility(vcpu->kvm, 7)) { in handle_stfle()
985 if (read_guest_real(vcpu, fac, &vsie_page->fac, in handle_stfle()
986 sizeof(vsie_page->fac))) in handle_stfle()
988 scb_s->fac = (__u32)(__u64) &vsie_page->fac; in handle_stfle()
1002 /* no need to validate the parameter and/or perform error handling */ in vsie_get_register()
1006 return vsie_page->scb_s.gg15; in vsie_get_register()
1008 return vsie_page->scb_s.gg14; in vsie_get_register()
1010 return vcpu->run->s.regs.gprs[reg]; in vsie_get_register()
1016 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in vsie_handle_mvpg()
1018 u64 *pei_block = &vsie_page->scb_o->mcic; in vsie_handle_mvpg()
1022 cr0.val = vcpu->arch.sie_block->gcr[0]; in vsie_handle_mvpg()
1023 edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8); in vsie_handle_mvpg()
1024 mask = _kvm_s390_logical_to_effective(&scb_s->gpsw, PAGE_MASK); in vsie_handle_mvpg()
1025 prefix = scb_s->prefix << GUEST_PREFIX_SHIFT; in vsie_handle_mvpg()
1027 dest = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 20) & mask; in vsie_handle_mvpg()
1028 dest = _kvm_s390_real_to_abs(prefix, dest) + scb_s->mso; in vsie_handle_mvpg()
1029 src = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 16) & mask; in vsie_handle_mvpg()
1030 src = _kvm_s390_real_to_abs(prefix, src) + scb_s->mso; in vsie_handle_mvpg()
1032 rc_dest = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, dest, &pei_dest); in vsie_handle_mvpg()
1033 rc_src = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, src, &pei_src); in vsie_handle_mvpg()
1035 * Either everything went well, or something non-critical went wrong in vsie_handle_mvpg()
1038 if (rc_dest == -EAGAIN || rc_src == -EAGAIN || (!rc_dest && !rc_src)) { in vsie_handle_mvpg()
1040 return -EAGAIN; in vsie_handle_mvpg()
1058 * also for segment and region table faults if EDAT applies. in vsie_handle_mvpg()
1089 * Returns: - 0 everything went fine
1090 * - > 0 if control has to be given to guest 2
1091 * - < 0 if an error occurred
1094 __releases(vcpu->kvm->srcu) in do_vsie_run()
1095 __acquires(vcpu->kvm->srcu) in do_vsie_run()
1097 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in do_vsie_run()
1098 struct kvm_s390_sie_block *scb_o = vsie_page->scb_o; in do_vsie_run()
1115 if (test_kvm_facility(vcpu->kvm, 82) && in do_vsie_run()
1116 vcpu->arch.sie_block->fpf & FPF_BPBC) in do_vsie_run()
1129 vcpu->arch.sie_block->prog0c |= PROG_IN_SIE; in do_vsie_run()
1134 rc = sie64a(scb_s, vcpu->run->s.regs.gprs); in do_vsie_run()
1136 vcpu->arch.sie_block->prog0c &= ~PROG_IN_SIE; in do_vsie_run()
1148 if (rc == -EINTR) { in do_vsie_run()
1150 kvm_s390_reinject_machine_check(vcpu, &vsie_page->mcck_info); in do_vsie_run()
1156 else if (rc == -EFAULT) in do_vsie_run()
1159 switch (scb_s->icptcode) { in do_vsie_run()
1161 if (scb_s->ipa == 0xb2b0) in do_vsie_run()
1165 /* stop not requested by g2 - must have been a kick */ in do_vsie_run()
1166 if (!(atomic_read(&scb_o->cpuflags) & CPUSTAT_STOP_INT)) in do_vsie_run()
1170 if ((scb_s->ipa & 0xf000) != 0xf000) in do_vsie_run()
1171 scb_s->ipa += 0x1000; in do_vsie_run()
1174 if (scb_s->ipa == 0xb254) in do_vsie_run()
1183 if (vsie_page->gmap) in release_gmap_shadow()
1184 gmap_put(vsie_page->gmap); in release_gmap_shadow()
1185 WRITE_ONCE(vsie_page->gmap, NULL); in release_gmap_shadow()
1197 asce = vcpu->arch.sie_block->gcr[1]; in acquire_gmap_shadow()
1198 cr0.val = vcpu->arch.sie_block->gcr[0]; in acquire_gmap_shadow()
1199 edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8); in acquire_gmap_shadow()
1200 edat += edat && test_kvm_facility(vcpu->kvm, 78); in acquire_gmap_shadow()
1207 if (vsie_page->gmap && gmap_shadow_valid(vsie_page->gmap, asce, edat)) in acquire_gmap_shadow()
1210 /* release the old shadow - if any, and mark the prefix as unmapped */ in acquire_gmap_shadow()
1212 gmap = gmap_shadow(vcpu->arch.gmap, asce, edat); in acquire_gmap_shadow()
1215 gmap->private = vcpu->kvm; in acquire_gmap_shadow()
1216 WRITE_ONCE(vsie_page->gmap, gmap); in acquire_gmap_shadow()
1226 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in register_shadow_scb()
1228 WRITE_ONCE(vcpu->arch.vsie_block, &vsie_page->scb_s); in register_shadow_scb()
1231 * therefore the vsie -> Simulate Wait state. in register_shadow_scb()
1239 scb_s->epoch += vcpu->kvm->arch.epoch; in register_shadow_scb()
1241 if (scb_s->ecd & ECD_MEF) { in register_shadow_scb()
1242 scb_s->epdx += vcpu->kvm->arch.epdx; in register_shadow_scb()
1243 if (scb_s->epoch < vcpu->kvm->arch.epoch) in register_shadow_scb()
1244 scb_s->epdx += 1; in register_shadow_scb()
1256 WRITE_ONCE(vcpu->arch.vsie_block, NULL); in unregister_shadow_scb()
1263 * Returns: - 0 if no errors occurred
1264 * - > 0 if control has to be given to guest 2
1265 * - -ENOMEM if out of memory
1269 struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; in vsie_run()
1277 gmap_enable(vsie_page->gmap); in vsie_run()
1280 gmap_enable(vcpu->arch.gmap); in vsie_run()
1282 atomic_andnot(PROG_BLOCK_SIE, &scb_s->prog20); in vsie_run()
1284 if (rc == -EAGAIN) in vsie_run()
1286 if (rc || scb_s->icptcode || signal_pending(current) || in vsie_run()
1293 if (rc == -EFAULT) { in vsie_run()
1304 scb_s->icptcode = ICPT_PROGI; in vsie_run()
1305 scb_s->iprcc = PGM_ADDRESSING; in vsie_run()
1306 scb_s->pgmilc = 4; in vsie_run()
1307 scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, 4); in vsie_run()
1316 * Returns: - address of a vsie page (cached or new one)
1317 * - NULL if the same scb address is already used by another VCPU
1318 * - ERR_PTR(-ENOMEM) if out of memory
1327 page = radix_tree_lookup(&kvm->arch.vsie.addr_to_page, addr >> 9); in get_vsie_page()
1339 nr_vcpus = atomic_read(&kvm->online_vcpus); in get_vsie_page()
1341 mutex_lock(&kvm->arch.vsie.mutex); in get_vsie_page()
1342 if (kvm->arch.vsie.page_count < nr_vcpus) { in get_vsie_page()
1345 mutex_unlock(&kvm->arch.vsie.mutex); in get_vsie_page()
1346 return ERR_PTR(-ENOMEM); in get_vsie_page()
1349 kvm->arch.vsie.pages[kvm->arch.vsie.page_count] = page; in get_vsie_page()
1350 kvm->arch.vsie.page_count++; in get_vsie_page()
1354 page = kvm->arch.vsie.pages[kvm->arch.vsie.next]; in get_vsie_page()
1358 kvm->arch.vsie.next++; in get_vsie_page()
1359 kvm->arch.vsie.next %= nr_vcpus; in get_vsie_page()
1361 radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9); in get_vsie_page()
1363 page->index = addr; in get_vsie_page()
1365 if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9, page)) { in get_vsie_page()
1367 mutex_unlock(&kvm->arch.vsie.mutex); in get_vsie_page()
1370 mutex_unlock(&kvm->arch.vsie.mutex); in get_vsie_page()
1373 memset(&vsie_page->scb_s, 0, sizeof(struct kvm_s390_sie_block)); in get_vsie_page()
1375 vsie_page->fault_addr = 0; in get_vsie_page()
1376 vsie_page->scb_s.ihcpu = 0xffffU; in get_vsie_page()
1394 vcpu->stat.instruction_sie++; in kvm_s390_handle_vsie()
1395 if (!test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_SIEF2)) in kvm_s390_handle_vsie()
1396 return -EOPNOTSUPP; in kvm_s390_handle_vsie()
1397 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) in kvm_s390_handle_vsie()
1411 vsie_page = get_vsie_page(vcpu->kvm, scb_addr); in kvm_s390_handle_vsie()
1415 /* double use of sie control block - simply do nothing */ in kvm_s390_handle_vsie()
1436 put_vsie_page(vcpu->kvm, vsie_page); in kvm_s390_handle_vsie()
1444 mutex_init(&kvm->arch.vsie.mutex); in kvm_s390_vsie_init()
1445 INIT_RADIX_TREE(&kvm->arch.vsie.addr_to_page, GFP_KERNEL_ACCOUNT); in kvm_s390_vsie_init()
1455 mutex_lock(&kvm->arch.vsie.mutex); in kvm_s390_vsie_destroy()
1456 for (i = 0; i < kvm->arch.vsie.page_count; i++) { in kvm_s390_vsie_destroy()
1457 page = kvm->arch.vsie.pages[i]; in kvm_s390_vsie_destroy()
1458 kvm->arch.vsie.pages[i] = NULL; in kvm_s390_vsie_destroy()
1462 radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9); in kvm_s390_vsie_destroy()
1465 kvm->arch.vsie.page_count = 0; in kvm_s390_vsie_destroy()
1466 mutex_unlock(&kvm->arch.vsie.mutex); in kvm_s390_vsie_destroy()
1471 struct kvm_s390_sie_block *scb = READ_ONCE(vcpu->arch.vsie_block); in kvm_s390_vsie_kick()
1478 atomic_or(PROG_BLOCK_SIE, &scb->prog20); in kvm_s390_vsie_kick()
1479 if (scb->prog0c & PROG_IN_SIE) in kvm_s390_vsie_kick()
1480 atomic_or(CPUSTAT_STOP_INT, &scb->cpuflags); in kvm_s390_vsie_kick()