Lines Matching +full:class +full:- +full:dg
1 // SPDX-License-Identifier: GPL-2.0
10 #define KMSG_COMPONENT "kvm-s390"
22 #include <asm/asm-offsets.h>
32 #include "kvm-s390.h"
34 #include "trace-s390.h"
52 read_lock(&vcpu->kvm->arch.sca_lock); in sca_ext_call_pending()
53 if (vcpu->kvm->arch.use_esca) { in sca_ext_call_pending()
54 struct esca_block *sca = vcpu->kvm->arch.sca; in sca_ext_call_pending()
56 sca->cpu[vcpu->vcpu_id].sigp_ctrl; in sca_ext_call_pending()
61 struct bsca_block *sca = vcpu->kvm->arch.sca; in sca_ext_call_pending()
63 sca->cpu[vcpu->vcpu_id].sigp_ctrl; in sca_ext_call_pending()
68 read_unlock(&vcpu->kvm->arch.sca_lock); in sca_ext_call_pending()
81 read_lock(&vcpu->kvm->arch.sca_lock); in sca_inject_ext_call()
82 if (vcpu->kvm->arch.use_esca) { in sca_inject_ext_call()
83 struct esca_block *sca = vcpu->kvm->arch.sca; in sca_inject_ext_call()
85 &(sca->cpu[vcpu->vcpu_id].sigp_ctrl); in sca_inject_ext_call()
93 rc = cmpxchg(&sigp_ctrl->value, old_val.value, new_val.value); in sca_inject_ext_call()
95 struct bsca_block *sca = vcpu->kvm->arch.sca; in sca_inject_ext_call()
97 &(sca->cpu[vcpu->vcpu_id].sigp_ctrl); in sca_inject_ext_call()
105 rc = cmpxchg(&sigp_ctrl->value, old_val.value, new_val.value); in sca_inject_ext_call()
107 read_unlock(&vcpu->kvm->arch.sca_lock); in sca_inject_ext_call()
111 return -EBUSY; in sca_inject_ext_call()
124 read_lock(&vcpu->kvm->arch.sca_lock); in sca_clear_ext_call()
125 if (vcpu->kvm->arch.use_esca) { in sca_clear_ext_call()
126 struct esca_block *sca = vcpu->kvm->arch.sca; in sca_clear_ext_call()
128 &(sca->cpu[vcpu->vcpu_id].sigp_ctrl); in sca_clear_ext_call()
132 rc = cmpxchg(&sigp_ctrl->value, old.value, 0); in sca_clear_ext_call()
134 struct bsca_block *sca = vcpu->kvm->arch.sca; in sca_clear_ext_call()
136 &(sca->cpu[vcpu->vcpu_id].sigp_ctrl); in sca_clear_ext_call()
140 rc = cmpxchg(&sigp_ctrl->value, old.value, 0); in sca_clear_ext_call()
142 read_unlock(&vcpu->kvm->arch.sca_lock); in sca_clear_ext_call()
148 return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_EXT); in psw_extint_disabled()
153 return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_IO); in psw_ioint_disabled()
158 return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_MCHECK); in psw_mchk_disabled()
171 !(vcpu->arch.sie_block->gcr[0] & CR0_CLOCK_COMPARATOR_SUBMASK)) in ckc_interrupts_enabled()
181 const u64 now = kvm_s390_get_tod_clock_fast(vcpu->kvm); in ckc_irq_pending()
182 const u64 ckc = vcpu->arch.sie_block->ckc; in ckc_irq_pending()
184 if (vcpu->arch.sie_block->gcr[0] & CR0_CLOCK_COMPARATOR_SIGN) { in ckc_irq_pending()
196 (vcpu->arch.sie_block->gcr[0] & CR0_CPU_TIMER_SUBMASK); in cpu_timer_interrupts_enabled()
230 * gisa_set_iam - change the GISA interruption alert mask
240 * -EBUSY in case the gisa is part of the alert list
247 word = READ_ONCE(gisa->u64.word[0]); in gisa_set_iam()
249 return -EBUSY; in gisa_set_iam()
251 } while (cmpxchg(&gisa->u64.word[0], word, _word) != word); in gisa_set_iam()
257 * gisa_clear_ipm - clear the GISA interruption pending mask
270 word = READ_ONCE(gisa->u64.word[0]); in gisa_clear_ipm()
272 } while (cmpxchg(&gisa->u64.word[0], word, _word) != word); in gisa_clear_ipm()
276 * gisa_get_ipm_or_restore_iam - return IPM or restore GISA IAM
291 word = READ_ONCE(gi->origin->u64.word[0]); in gisa_get_ipm_or_restore_iam()
292 alert_mask = READ_ONCE(gi->alert.mask); in gisa_get_ipm_or_restore_iam()
297 } while (cmpxchg(&gi->origin->u64.word[0], word, _word) != word); in gisa_get_ipm_or_restore_iam()
304 return READ_ONCE(gisa->next_alert) != (u32)(u64)gisa; in gisa_in_alert_list()
314 return READ_ONCE(gisa->ipm); in gisa_get_ipm()
329 unsigned long pending = vcpu->kvm->arch.float_int.pending_irqs | in pending_irqs_no_gisa()
330 vcpu->arch.local_int.pending_irqs; in pending_irqs_no_gisa()
332 pending &= ~vcpu->kvm->arch.float_int.masked_irqs; in pending_irqs_no_gisa()
338 struct kvm_s390_gisa_interrupt *gi = &vcpu->kvm->arch.gisa_int; in pending_irqs()
342 if (gi->origin) in pending_irqs()
343 pending_mask |= gisa_get_ipm(gi->origin) << IRQ_PEND_IO_ISC_7; in pending_irqs()
349 return IRQ_PEND_IO_ISC_0 - isc; in isc_to_irq_type()
354 return IRQ_PEND_IO_ISC_0 - irq_type; in irq_type_to_isc()
363 if (!(vcpu->arch.sie_block->gcr[6] & isc_to_isc_bits(i))) in disable_iscs()
383 if (!(vcpu->arch.sie_block->gcr[0] & CR0_EXTERNAL_CALL_SUBMASK)) in deliverable_irqs()
385 if (!(vcpu->arch.sie_block->gcr[0] & CR0_EMERGENCY_SIGNAL_SUBMASK)) in deliverable_irqs()
387 if (!(vcpu->arch.sie_block->gcr[0] & CR0_CLOCK_COMPARATOR_SUBMASK)) in deliverable_irqs()
389 if (!(vcpu->arch.sie_block->gcr[0] & CR0_CPU_TIMER_SUBMASK)) in deliverable_irqs()
391 if (!(vcpu->arch.sie_block->gcr[0] & CR0_SERVICE_SIGNAL_SUBMASK)) { in deliverable_irqs()
399 vcpu->arch.sie_block->iictl != IICTL_CODE_NONE) in deliverable_irqs()
407 if (!(vcpu->arch.sie_block->gcr[14] & in deliverable_irqs()
408 (vcpu->kvm->arch.float_int.mchk.cr14 | in deliverable_irqs()
409 vcpu->arch.local_int.irq.mchk.cr14))) in deliverable_irqs()
424 set_bit(vcpu->vcpu_idx, vcpu->kvm->arch.idle_mask); in __set_cpu_idle()
430 clear_bit(vcpu->vcpu_idx, vcpu->kvm->arch.idle_mask); in __unset_cpu_idle()
437 vcpu->arch.sie_block->lctl = 0x0000; in __reset_intercept_indicators()
438 vcpu->arch.sie_block->ictl &= ~(ICTL_LPSW | ICTL_STCTL | ICTL_PINT); in __reset_intercept_indicators()
441 vcpu->arch.sie_block->lctl |= (LCTL_CR0 | LCTL_CR9 | in __reset_intercept_indicators()
443 vcpu->arch.sie_block->ictl |= (ICTL_STCTL | ICTL_PINT); in __reset_intercept_indicators()
454 vcpu->arch.sie_block->lctl |= LCTL_CR6; in set_intercept_indicators_io()
464 vcpu->arch.sie_block->lctl |= LCTL_CR0; in set_intercept_indicators_ext()
472 vcpu->arch.sie_block->ictl |= ICTL_LPSW; in set_intercept_indicators_mchk()
474 vcpu->arch.sie_block->lctl |= LCTL_CR14; in set_intercept_indicators_mchk()
483 /* Set interception request for non-deliverable interrupts */
494 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __deliver_cpu_timer()
497 vcpu->stat.deliver_cputm++; in __deliver_cpu_timer()
498 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_CPU_TIMER, in __deliver_cpu_timer()
501 vcpu->arch.sie_block->iictl = IICTL_CODE_EXT; in __deliver_cpu_timer()
502 vcpu->arch.sie_block->eic = EXT_IRQ_CPU_TIMER; in __deliver_cpu_timer()
508 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in __deliver_cpu_timer()
510 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in __deliver_cpu_timer()
512 clear_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs); in __deliver_cpu_timer()
513 return rc ? -EFAULT : 0; in __deliver_cpu_timer()
518 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __deliver_ckc()
521 vcpu->stat.deliver_ckc++; in __deliver_ckc()
522 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_CLOCK_COMP, in __deliver_ckc()
525 vcpu->arch.sie_block->iictl = IICTL_CODE_EXT; in __deliver_ckc()
526 vcpu->arch.sie_block->eic = EXT_IRQ_CLK_COMP; in __deliver_ckc()
532 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in __deliver_ckc()
534 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in __deliver_ckc()
536 clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); in __deliver_ckc()
537 return rc ? -EFAULT : 0; in __deliver_ckc()
542 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __deliver_pfault_init()
546 spin_lock(&li->lock); in __deliver_pfault_init()
547 ext = li->irq.ext; in __deliver_pfault_init()
548 clear_bit(IRQ_PEND_PFAULT_INIT, &li->pending_irqs); in __deliver_pfault_init()
549 li->irq.ext.ext_params2 = 0; in __deliver_pfault_init()
550 spin_unlock(&li->lock); in __deliver_pfault_init()
554 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, in __deliver_pfault_init()
561 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in __deliver_pfault_init()
563 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in __deliver_pfault_init()
565 return rc ? -EFAULT : 0; in __deliver_pfault_init()
584 vcpu->arch.sie_block->iictl = IICTL_CODE_MCHK; in __write_machine_check()
585 vcpu->arch.sie_block->mcic = mchk->mcic; in __write_machine_check()
586 vcpu->arch.sie_block->faddr = mchk->failing_storage_address; in __write_machine_check()
587 vcpu->arch.sie_block->edc = mchk->ext_damage_code; in __write_machine_check()
591 mci.val = mchk->mcic; in __write_machine_check()
594 save_access_regs(vcpu->run->s.regs.acrs); in __write_machine_check()
595 if (MACHINE_HAS_GS && vcpu->arch.gs_enabled) in __write_machine_check()
596 save_gs_cb(current->thread.gs_cb); in __write_machine_check()
601 /* Only bits 0 through 63-LC are used for address formation */ in __write_machine_check()
603 if (test_kvm_facility(vcpu->kvm, 133)) { in __write_machine_check()
623 if (!rc && mci.vr && ext_sa_addr && test_kvm_facility(vcpu->kvm, 129)) { in __write_machine_check()
624 if (write_guest_abs(vcpu, ext_sa_addr, vcpu->run->s.regs.vrs, in __write_machine_check()
630 if (!rc && mci.gs && ext_sa_addr && test_kvm_facility(vcpu->kvm, 133) in __write_machine_check()
633 &vcpu->run->s.regs.gscb, 32)) in __write_machine_check()
642 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in __write_machine_check()
644 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in __write_machine_check()
647 /* Register-save areas */ in __write_machine_check()
649 convert_vx_to_fp(fprs, (__vector128 *) vcpu->run->s.regs.vrs); in __write_machine_check()
653 vcpu->run->s.regs.fprs, 128); in __write_machine_check()
656 vcpu->run->s.regs.gprs, 128); in __write_machine_check()
657 rc |= put_guest_lc(vcpu, current->thread.fpu.fpc, in __write_machine_check()
659 rc |= put_guest_lc(vcpu, vcpu->arch.sie_block->todpr, in __write_machine_check()
663 rc |= put_guest_lc(vcpu, vcpu->arch.sie_block->ckc >> 8, in __write_machine_check()
666 &vcpu->run->s.regs.acrs, 64); in __write_machine_check()
668 &vcpu->arch.sie_block->gcr, 128); in __write_machine_check()
671 rc |= put_guest_lc(vcpu, mchk->ext_damage_code, in __write_machine_check()
673 rc |= put_guest_lc(vcpu, mchk->failing_storage_address, in __write_machine_check()
675 rc |= write_guest_lc(vcpu, __LC_PSW_SAVE_AREA, &mchk->fixed_logout, in __write_machine_check()
676 sizeof(mchk->fixed_logout)); in __write_machine_check()
677 return rc ? -EFAULT : 0; in __write_machine_check()
682 struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; in __deliver_machine_check()
683 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __deliver_machine_check()
688 spin_lock(&fi->lock); in __deliver_machine_check()
689 spin_lock(&li->lock); in __deliver_machine_check()
690 if (test_bit(IRQ_PEND_MCHK_EX, &li->pending_irqs) || in __deliver_machine_check()
691 test_bit(IRQ_PEND_MCHK_REP, &li->pending_irqs)) { in __deliver_machine_check()
698 mchk = li->irq.mchk; in __deliver_machine_check()
699 clear_bit(IRQ_PEND_MCHK_EX, &li->pending_irqs); in __deliver_machine_check()
700 clear_bit(IRQ_PEND_MCHK_REP, &li->pending_irqs); in __deliver_machine_check()
701 memset(&li->irq.mchk, 0, sizeof(mchk)); in __deliver_machine_check()
710 if (test_and_clear_bit(IRQ_PEND_MCHK_REP, &fi->pending_irqs)) { in __deliver_machine_check()
711 mchk.mcic |= fi->mchk.mcic; in __deliver_machine_check()
712 mchk.cr14 |= fi->mchk.cr14; in __deliver_machine_check()
713 memset(&fi->mchk, 0, sizeof(mchk)); in __deliver_machine_check()
716 spin_unlock(&li->lock); in __deliver_machine_check()
717 spin_unlock(&fi->lock); in __deliver_machine_check()
722 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, in __deliver_machine_check()
725 vcpu->stat.deliver_machine_check++; in __deliver_machine_check()
733 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __deliver_restart()
737 vcpu->stat.deliver_restart_signal++; in __deliver_restart()
738 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_RESTART, 0, 0); in __deliver_restart()
741 vcpu->arch.sie_block->iictl = IICTL_CODE_RESTART; in __deliver_restart()
745 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in __deliver_restart()
747 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in __deliver_restart()
749 clear_bit(IRQ_PEND_RESTART, &li->pending_irqs); in __deliver_restart()
750 return rc ? -EFAULT : 0; in __deliver_restart()
755 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __deliver_set_prefix()
758 spin_lock(&li->lock); in __deliver_set_prefix()
759 prefix = li->irq.prefix; in __deliver_set_prefix()
760 li->irq.prefix.address = 0; in __deliver_set_prefix()
761 clear_bit(IRQ_PEND_SET_PREFIX, &li->pending_irqs); in __deliver_set_prefix()
762 spin_unlock(&li->lock); in __deliver_set_prefix()
764 vcpu->stat.deliver_prefix_signal++; in __deliver_set_prefix()
765 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, in __deliver_set_prefix()
775 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __deliver_emergency_signal()
779 spin_lock(&li->lock); in __deliver_emergency_signal()
780 cpu_addr = find_first_bit(li->sigp_emerg_pending, KVM_MAX_VCPUS); in __deliver_emergency_signal()
781 clear_bit(cpu_addr, li->sigp_emerg_pending); in __deliver_emergency_signal()
782 if (bitmap_empty(li->sigp_emerg_pending, KVM_MAX_VCPUS)) in __deliver_emergency_signal()
783 clear_bit(IRQ_PEND_EXT_EMERGENCY, &li->pending_irqs); in __deliver_emergency_signal()
784 spin_unlock(&li->lock); in __deliver_emergency_signal()
787 vcpu->stat.deliver_emergency_signal++; in __deliver_emergency_signal()
788 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_EMERGENCY, in __deliver_emergency_signal()
791 vcpu->arch.sie_block->iictl = IICTL_CODE_EXT; in __deliver_emergency_signal()
792 vcpu->arch.sie_block->eic = EXT_IRQ_EMERGENCY_SIG; in __deliver_emergency_signal()
793 vcpu->arch.sie_block->extcpuaddr = cpu_addr; in __deliver_emergency_signal()
801 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in __deliver_emergency_signal()
803 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in __deliver_emergency_signal()
804 return rc ? -EFAULT : 0; in __deliver_emergency_signal()
809 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __deliver_external_call()
813 spin_lock(&li->lock); in __deliver_external_call()
814 extcall = li->irq.extcall; in __deliver_external_call()
815 li->irq.extcall.code = 0; in __deliver_external_call()
816 clear_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs); in __deliver_external_call()
817 spin_unlock(&li->lock); in __deliver_external_call()
820 vcpu->stat.deliver_external_call++; in __deliver_external_call()
821 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, in __deliver_external_call()
825 vcpu->arch.sie_block->iictl = IICTL_CODE_EXT; in __deliver_external_call()
826 vcpu->arch.sie_block->eic = EXT_IRQ_EXTERNAL_CALL; in __deliver_external_call()
827 vcpu->arch.sie_block->extcpuaddr = extcall.code; in __deliver_external_call()
835 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in __deliver_external_call()
836 rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, &vcpu->arch.sie_block->gpsw, in __deliver_external_call()
838 return rc ? -EFAULT : 0; in __deliver_external_call()
845 vcpu->arch.sie_block->iictl = IICTL_CODE_SPECIFICATION; in __deliver_prog_pv()
848 vcpu->arch.sie_block->iictl = IICTL_CODE_OPERAND; in __deliver_prog_pv()
851 return -EINVAL; in __deliver_prog_pv()
858 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __deliver_prog()
863 spin_lock(&li->lock); in __deliver_prog()
864 pgm_info = li->irq.pgm; in __deliver_prog()
865 clear_bit(IRQ_PEND_PROG, &li->pending_irqs); in __deliver_prog()
866 memset(&li->irq.pgm, 0, sizeof(pgm_info)); in __deliver_prog()
867 spin_unlock(&li->lock); in __deliver_prog()
872 vcpu->stat.deliver_program++; in __deliver_prog()
873 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_PROGRAM_INT, in __deliver_prog()
964 rc |= put_guest_lc(vcpu, vcpu->arch.sie_block->gbea, in __deliver_prog()
969 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in __deliver_prog()
971 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in __deliver_prog()
972 return rc ? -EFAULT : 0; in __deliver_prog()
983 vcpu->arch.sie_block->iictl = IICTL_CODE_EXT; in write_sclp()
984 vcpu->arch.sie_block->eic = EXT_IRQ_SERVICE_SIG; in write_sclp()
985 vcpu->arch.sie_block->eiparams = parm; in write_sclp()
992 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in write_sclp()
994 &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); in write_sclp()
998 return rc ? -EFAULT : 0; in write_sclp()
1003 struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; in __deliver_service()
1006 spin_lock(&fi->lock); in __deliver_service()
1007 if (test_bit(IRQ_PEND_EXT_SERVICE, &fi->masked_irqs) || in __deliver_service()
1008 !(test_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs))) { in __deliver_service()
1009 spin_unlock(&fi->lock); in __deliver_service()
1012 ext = fi->srv_signal; in __deliver_service()
1013 memset(&fi->srv_signal, 0, sizeof(ext)); in __deliver_service()
1014 clear_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs); in __deliver_service()
1015 clear_bit(IRQ_PEND_EXT_SERVICE_EV, &fi->pending_irqs); in __deliver_service()
1017 set_bit(IRQ_PEND_EXT_SERVICE, &fi->masked_irqs); in __deliver_service()
1018 spin_unlock(&fi->lock); in __deliver_service()
1022 vcpu->stat.deliver_service_signal++; in __deliver_service()
1023 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_SERVICE, in __deliver_service()
1031 struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; in __deliver_service_ev()
1034 spin_lock(&fi->lock); in __deliver_service_ev()
1035 if (!(test_bit(IRQ_PEND_EXT_SERVICE_EV, &fi->pending_irqs))) { in __deliver_service_ev()
1036 spin_unlock(&fi->lock); in __deliver_service_ev()
1039 ext = fi->srv_signal; in __deliver_service_ev()
1041 fi->srv_signal.ext_params &= ~SCCB_EVENT_PENDING; in __deliver_service_ev()
1042 clear_bit(IRQ_PEND_EXT_SERVICE_EV, &fi->pending_irqs); in __deliver_service_ev()
1043 spin_unlock(&fi->lock); in __deliver_service_ev()
1046 vcpu->stat.deliver_service_signal++; in __deliver_service_ev()
1047 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_SERVICE, in __deliver_service_ev()
1055 struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; in __deliver_pfault_done()
1059 spin_lock(&fi->lock); in __deliver_pfault_done()
1060 inti = list_first_entry_or_null(&fi->lists[FIRQ_LIST_PFAULT], in __deliver_pfault_done()
1064 list_del(&inti->list); in __deliver_pfault_done()
1065 fi->counters[FIRQ_CNTR_PFAULT] -= 1; in __deliver_pfault_done()
1067 if (list_empty(&fi->lists[FIRQ_LIST_PFAULT])) in __deliver_pfault_done()
1068 clear_bit(IRQ_PEND_PFAULT_DONE, &fi->pending_irqs); in __deliver_pfault_done()
1069 spin_unlock(&fi->lock); in __deliver_pfault_done()
1072 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, in __deliver_pfault_done()
1074 inti->ext.ext_params2); in __deliver_pfault_done()
1076 inti->ext.ext_params2); in __deliver_pfault_done()
1083 &vcpu->arch.sie_block->gpsw, in __deliver_pfault_done()
1086 &vcpu->arch.sie_block->gpsw, in __deliver_pfault_done()
1088 rc |= put_guest_lc(vcpu, inti->ext.ext_params2, in __deliver_pfault_done()
1092 return rc ? -EFAULT : 0; in __deliver_pfault_done()
1097 struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; in __deliver_virtio()
1101 spin_lock(&fi->lock); in __deliver_virtio()
1102 inti = list_first_entry_or_null(&fi->lists[FIRQ_LIST_VIRTIO], in __deliver_virtio()
1108 inti->ext.ext_params, inti->ext.ext_params2); in __deliver_virtio()
1109 vcpu->stat.deliver_virtio++; in __deliver_virtio()
1110 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, in __deliver_virtio()
1111 inti->type, in __deliver_virtio()
1112 inti->ext.ext_params, in __deliver_virtio()
1113 inti->ext.ext_params2); in __deliver_virtio()
1114 list_del(&inti->list); in __deliver_virtio()
1115 fi->counters[FIRQ_CNTR_VIRTIO] -= 1; in __deliver_virtio()
1117 if (list_empty(&fi->lists[FIRQ_LIST_VIRTIO])) in __deliver_virtio()
1118 clear_bit(IRQ_PEND_VIRTIO, &fi->pending_irqs); in __deliver_virtio()
1119 spin_unlock(&fi->lock); in __deliver_virtio()
1127 &vcpu->arch.sie_block->gpsw, in __deliver_virtio()
1130 &vcpu->arch.sie_block->gpsw, in __deliver_virtio()
1132 rc |= put_guest_lc(vcpu, inti->ext.ext_params, in __deliver_virtio()
1134 rc |= put_guest_lc(vcpu, inti->ext.ext_params2, in __deliver_virtio()
1138 return rc ? -EFAULT : 0; in __deliver_virtio()
1146 vcpu->arch.sie_block->iictl = IICTL_CODE_IO; in __do_deliver_io()
1147 vcpu->arch.sie_block->subchannel_id = io->subchannel_id; in __do_deliver_io()
1148 vcpu->arch.sie_block->subchannel_nr = io->subchannel_nr; in __do_deliver_io()
1149 vcpu->arch.sie_block->io_int_parm = io->io_int_parm; in __do_deliver_io()
1150 vcpu->arch.sie_block->io_int_word = io->io_int_word; in __do_deliver_io()
1154 rc = put_guest_lc(vcpu, io->subchannel_id, (u16 *)__LC_SUBCHANNEL_ID); in __do_deliver_io()
1155 rc |= put_guest_lc(vcpu, io->subchannel_nr, (u16 *)__LC_SUBCHANNEL_NR); in __do_deliver_io()
1156 rc |= put_guest_lc(vcpu, io->io_int_parm, (u32 *)__LC_IO_INT_PARM); in __do_deliver_io()
1157 rc |= put_guest_lc(vcpu, io->io_int_word, (u32 *)__LC_IO_INT_WORD); in __do_deliver_io()
1159 &vcpu->arch.sie_block->gpsw, in __do_deliver_io()
1162 &vcpu->arch.sie_block->gpsw, in __do_deliver_io()
1164 return rc ? -EFAULT : 0; in __do_deliver_io()
1172 struct kvm_s390_gisa_interrupt *gi = &vcpu->kvm->arch.gisa_int; in __deliver_io()
1178 fi = &vcpu->kvm->arch.float_int; in __deliver_io()
1180 spin_lock(&fi->lock); in __deliver_io()
1182 isc_list = &fi->lists[isc]; in __deliver_io()
1187 if (inti->type & KVM_S390_INT_IO_AI_MASK) in __deliver_io()
1191 inti->io.subchannel_id >> 8, in __deliver_io()
1192 inti->io.subchannel_id >> 1 & 0x3, in __deliver_io()
1193 inti->io.subchannel_nr); in __deliver_io()
1195 vcpu->stat.deliver_io++; in __deliver_io()
1196 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, in __deliver_io()
1197 inti->type, in __deliver_io()
1198 ((__u32)inti->io.subchannel_id << 16) | in __deliver_io()
1199 inti->io.subchannel_nr, in __deliver_io()
1200 ((__u64)inti->io.io_int_parm << 32) | in __deliver_io()
1201 inti->io.io_int_word); in __deliver_io()
1202 list_del(&inti->list); in __deliver_io()
1203 fi->counters[FIRQ_CNTR_IO] -= 1; in __deliver_io()
1206 clear_bit(irq_type, &fi->pending_irqs); in __deliver_io()
1207 spin_unlock(&fi->lock); in __deliver_io()
1210 rc = __do_deliver_io(vcpu, &(inti->io)); in __deliver_io()
1215 if (gi->origin && gisa_tac_ipm_gisc(gi->origin, isc)) { in __deliver_io()
1223 vcpu->stat.deliver_io++; in __deliver_io()
1224 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, in __deliver_io()
1239 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in kvm_s390_ext_call_pending()
1242 return test_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs); in kvm_s390_ext_call_pending()
1258 (vcpu->arch.sie_block->gcr[0] & CR0_EXTERNAL_CALL_SUBMASK)) in kvm_s390_vcpu_has_irq()
1273 const u64 now = kvm_s390_get_tod_clock_fast(vcpu->kvm); in __calculate_sltime()
1274 const u64 ckc = vcpu->arch.sie_block->ckc; in __calculate_sltime()
1278 if (vcpu->arch.sie_block->gcr[0] & CR0_CLOCK_COMPARATOR_SIGN) { in __calculate_sltime()
1280 sltime = tod_to_ns((s64)ckc - (s64)now); in __calculate_sltime()
1282 sltime = tod_to_ns(ckc - now); in __calculate_sltime()
1305 struct kvm_s390_gisa_interrupt *gi = &vcpu->kvm->arch.gisa_int; in kvm_s390_handle_wait()
1308 vcpu->stat.exit_wait_state++; in kvm_s390_handle_wait()
1316 return -EOPNOTSUPP; /* disabled wait */ in kvm_s390_handle_wait()
1319 if (gi->origin && in kvm_s390_handle_wait()
1321 vcpu->arch.sie_block->gcr[6] >> 24)) in kvm_s390_handle_wait()
1336 hrtimer_start(&vcpu->arch.ckc_timer, sltime, HRTIMER_MODE_REL); in kvm_s390_handle_wait()
1341 vcpu->valid_wakeup = false; in kvm_s390_handle_wait()
1345 hrtimer_cancel(&vcpu->arch.ckc_timer); in kvm_s390_handle_wait()
1351 vcpu->valid_wakeup = true; in kvm_s390_vcpu_wakeup()
1381 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in kvm_s390_clear_local_irqs()
1383 spin_lock(&li->lock); in kvm_s390_clear_local_irqs()
1384 li->pending_irqs = 0; in kvm_s390_clear_local_irqs()
1385 bitmap_zero(li->sigp_emerg_pending, KVM_MAX_VCPUS); in kvm_s390_clear_local_irqs()
1386 memset(&li->irq, 0, sizeof(li->irq)); in kvm_s390_clear_local_irqs()
1387 spin_unlock(&li->lock); in kvm_s390_clear_local_irqs()
1394 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in kvm_s390_deliver_pending_interrupts()
1402 clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); in kvm_s390_deliver_pending_interrupts()
1404 set_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); in kvm_s390_deliver_pending_interrupts()
1407 clear_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs); in kvm_s390_deliver_pending_interrupts()
1409 set_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs); in kvm_s390_deliver_pending_interrupts()
1467 clear_bit(irq_type, &li->pending_irqs); in kvm_s390_deliver_pending_interrupts()
1478 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __inject_prog()
1480 vcpu->stat.inject_program++; in __inject_prog()
1481 VCPU_EVENT(vcpu, 3, "inject: program irq code 0x%x", irq->u.pgm.code); in __inject_prog()
1482 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_PROGRAM_INT, in __inject_prog()
1483 irq->u.pgm.code, 0); in __inject_prog()
1485 if (!(irq->u.pgm.flags & KVM_S390_PGM_FLAGS_ILC_VALID)) { in __inject_prog()
1487 irq->u.pgm.flags &= ~KVM_S390_PGM_FLAGS_ILC_MASK; in __inject_prog()
1488 irq->u.pgm.flags |= kvm_s390_get_ilen(vcpu); in __inject_prog()
1489 irq->u.pgm.flags |= KVM_S390_PGM_FLAGS_ILC_VALID; in __inject_prog()
1492 if (irq->u.pgm.code == PGM_PER) { in __inject_prog()
1493 li->irq.pgm.code |= PGM_PER; in __inject_prog()
1494 li->irq.pgm.flags = irq->u.pgm.flags; in __inject_prog()
1496 li->irq.pgm.per_address = irq->u.pgm.per_address; in __inject_prog()
1497 li->irq.pgm.per_code = irq->u.pgm.per_code; in __inject_prog()
1498 li->irq.pgm.per_atmid = irq->u.pgm.per_atmid; in __inject_prog()
1499 li->irq.pgm.per_access_id = irq->u.pgm.per_access_id; in __inject_prog()
1500 } else if (!(irq->u.pgm.code & PGM_PER)) { in __inject_prog()
1501 li->irq.pgm.code = (li->irq.pgm.code & PGM_PER) | in __inject_prog()
1502 irq->u.pgm.code; in __inject_prog()
1503 li->irq.pgm.flags = irq->u.pgm.flags; in __inject_prog()
1504 /* only modify non-PER information */ in __inject_prog()
1505 li->irq.pgm.trans_exc_code = irq->u.pgm.trans_exc_code; in __inject_prog()
1506 li->irq.pgm.mon_code = irq->u.pgm.mon_code; in __inject_prog()
1507 li->irq.pgm.data_exc_code = irq->u.pgm.data_exc_code; in __inject_prog()
1508 li->irq.pgm.mon_class_nr = irq->u.pgm.mon_class_nr; in __inject_prog()
1509 li->irq.pgm.exc_access_id = irq->u.pgm.exc_access_id; in __inject_prog()
1510 li->irq.pgm.op_access_id = irq->u.pgm.op_access_id; in __inject_prog()
1512 li->irq.pgm = irq->u.pgm; in __inject_prog()
1514 set_bit(IRQ_PEND_PROG, &li->pending_irqs); in __inject_prog()
1520 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __inject_pfault_init()
1522 vcpu->stat.inject_pfault_init++; in __inject_pfault_init()
1524 irq->u.ext.ext_params2); in __inject_pfault_init()
1525 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_PFAULT_INIT, in __inject_pfault_init()
1526 irq->u.ext.ext_params, in __inject_pfault_init()
1527 irq->u.ext.ext_params2); in __inject_pfault_init()
1529 li->irq.ext = irq->u.ext; in __inject_pfault_init()
1530 set_bit(IRQ_PEND_PFAULT_INIT, &li->pending_irqs); in __inject_pfault_init()
1537 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __inject_extcall()
1538 struct kvm_s390_extcall_info *extcall = &li->irq.extcall; in __inject_extcall()
1539 uint16_t src_id = irq->u.extcall.code; in __inject_extcall()
1541 vcpu->stat.inject_external_call++; in __inject_extcall()
1542 VCPU_EVENT(vcpu, 4, "inject: external call source-cpu:%u", in __inject_extcall()
1544 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_EXTERNAL_CALL, in __inject_extcall()
1548 if (kvm_get_vcpu_by_id(vcpu->kvm, src_id) == NULL) in __inject_extcall()
1549 return -EINVAL; in __inject_extcall()
1554 if (test_and_set_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs)) in __inject_extcall()
1555 return -EBUSY; in __inject_extcall()
1556 *extcall = irq->u.extcall; in __inject_extcall()
1563 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __inject_set_prefix()
1564 struct kvm_s390_prefix_info *prefix = &li->irq.prefix; in __inject_set_prefix()
1566 vcpu->stat.inject_set_prefix++; in __inject_set_prefix()
1568 irq->u.prefix.address); in __inject_set_prefix()
1569 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_SIGP_SET_PREFIX, in __inject_set_prefix()
1570 irq->u.prefix.address, 0); in __inject_set_prefix()
1573 return -EBUSY; in __inject_set_prefix()
1575 *prefix = irq->u.prefix; in __inject_set_prefix()
1576 set_bit(IRQ_PEND_SET_PREFIX, &li->pending_irqs); in __inject_set_prefix()
1583 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __inject_sigp_stop()
1584 struct kvm_s390_stop_info *stop = &li->irq.stop; in __inject_sigp_stop()
1587 vcpu->stat.inject_stop_signal++; in __inject_sigp_stop()
1588 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_SIGP_STOP, 0, 0); in __inject_sigp_stop()
1590 if (irq->u.stop.flags & ~KVM_S390_STOP_SUPP_FLAGS) in __inject_sigp_stop()
1591 return -EINVAL; in __inject_sigp_stop()
1594 if (irq->u.stop.flags & KVM_S390_STOP_FLAG_STORE_STATUS) in __inject_sigp_stop()
1600 if (test_and_set_bit(IRQ_PEND_SIGP_STOP, &li->pending_irqs)) in __inject_sigp_stop()
1601 return -EBUSY; in __inject_sigp_stop()
1602 stop->flags = irq->u.stop.flags; in __inject_sigp_stop()
1609 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __inject_sigp_restart()
1611 vcpu->stat.inject_restart++; in __inject_sigp_restart()
1613 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_RESTART, 0, 0); in __inject_sigp_restart()
1615 set_bit(IRQ_PEND_RESTART, &li->pending_irqs); in __inject_sigp_restart()
1622 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __inject_sigp_emergency()
1624 vcpu->stat.inject_emergency_signal++; in __inject_sigp_emergency()
1626 irq->u.emerg.code); in __inject_sigp_emergency()
1627 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_EMERGENCY, in __inject_sigp_emergency()
1628 irq->u.emerg.code, 0); in __inject_sigp_emergency()
1631 if (kvm_get_vcpu_by_id(vcpu->kvm, irq->u.emerg.code) == NULL) in __inject_sigp_emergency()
1632 return -EINVAL; in __inject_sigp_emergency()
1634 set_bit(irq->u.emerg.code, li->sigp_emerg_pending); in __inject_sigp_emergency()
1635 set_bit(IRQ_PEND_EXT_EMERGENCY, &li->pending_irqs); in __inject_sigp_emergency()
1642 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __inject_mchk()
1643 struct kvm_s390_mchk_info *mchk = &li->irq.mchk; in __inject_mchk()
1645 vcpu->stat.inject_mchk++; in __inject_mchk()
1647 irq->u.mchk.mcic); in __inject_mchk()
1648 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_MCHK, 0, in __inject_mchk()
1649 irq->u.mchk.mcic); in __inject_mchk()
1659 mchk->cr14 |= irq->u.mchk.cr14; in __inject_mchk()
1660 mchk->mcic |= irq->u.mchk.mcic; in __inject_mchk()
1661 mchk->ext_damage_code |= irq->u.mchk.ext_damage_code; in __inject_mchk()
1662 mchk->failing_storage_address = irq->u.mchk.failing_storage_address; in __inject_mchk()
1663 memcpy(&mchk->fixed_logout, &irq->u.mchk.fixed_logout, in __inject_mchk()
1664 sizeof(mchk->fixed_logout)); in __inject_mchk()
1665 if (mchk->mcic & MCHK_EX_MASK) in __inject_mchk()
1666 set_bit(IRQ_PEND_MCHK_EX, &li->pending_irqs); in __inject_mchk()
1667 else if (mchk->mcic & MCHK_REP_MASK) in __inject_mchk()
1668 set_bit(IRQ_PEND_MCHK_REP, &li->pending_irqs); in __inject_mchk()
1674 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __inject_ckc()
1676 vcpu->stat.inject_ckc++; in __inject_ckc()
1678 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_CLOCK_COMP, in __inject_ckc()
1681 set_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); in __inject_ckc()
1688 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in __inject_cpu_timer()
1690 vcpu->stat.inject_cputm++; in __inject_cpu_timer()
1692 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_CPU_TIMER, in __inject_cpu_timer()
1695 set_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs); in __inject_cpu_timer()
1703 struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; in get_io_int()
1704 struct list_head *isc_list = &fi->lists[FIRQ_LIST_IO_ISC_0 + isc]; in get_io_int()
1709 spin_lock(&fi->lock); in get_io_int()
1711 if (schid && (id != iter->io.subchannel_id || in get_io_int()
1712 nr != iter->io.subchannel_nr)) in get_io_int()
1715 list_del_init(&iter->list); in get_io_int()
1716 fi->counters[FIRQ_CNTR_IO] -= 1; in get_io_int()
1718 clear_bit(isc_to_irq_type(isc), &fi->pending_irqs); in get_io_int()
1719 spin_unlock(&fi->lock); in get_io_int()
1722 spin_unlock(&fi->lock); in get_io_int()
1741 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int; in get_top_gisa_isc()
1747 if (!gi->origin) in get_top_gisa_isc()
1750 active_mask = (isc_mask & gisa_get_ipm(gi->origin) << 24) << 32; in get_top_gisa_isc()
1752 isc = __fls(active_mask) ^ (BITS_PER_LONG - 1); in get_top_gisa_isc()
1753 if (gisa_tac_ipm_gisc(gi->origin, isc)) in get_top_gisa_isc()
1758 return -EINVAL; in get_top_gisa_isc()
1776 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int; in kvm_s390_get_io_int()
1792 if (int_word_to_isc(inti->io.io_int_word) <= isc) { in kvm_s390_get_io_int()
1794 gisa_set_ipm_gisc(gi->origin, isc); in kvm_s390_get_io_int()
1800 tmp_inti->type = KVM_S390_INT_IO(1, 0, 0, 0); in kvm_s390_get_io_int()
1801 tmp_inti->io.io_int_word = isc_to_int_word(isc); in kvm_s390_get_io_int()
1806 gisa_set_ipm_gisc(gi->origin, isc); in kvm_s390_get_io_int()
1814 struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; in __inject_service()
1816 kvm->stat.inject_service_signal++; in __inject_service()
1817 spin_lock(&fi->lock); in __inject_service()
1818 fi->srv_signal.ext_params |= inti->ext.ext_params & SCCB_EVENT_PENDING; in __inject_service()
1821 if (fi->srv_signal.ext_params & SCCB_EVENT_PENDING) in __inject_service()
1822 set_bit(IRQ_PEND_EXT_SERVICE_EV, &fi->pending_irqs); in __inject_service()
1832 if (fi->srv_signal.ext_params & SCCB_MASK) in __inject_service()
1834 fi->srv_signal.ext_params |= inti->ext.ext_params & SCCB_MASK; in __inject_service()
1835 set_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs); in __inject_service()
1837 spin_unlock(&fi->lock); in __inject_service()
1845 struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; in __inject_virtio()
1847 kvm->stat.inject_virtio++; in __inject_virtio()
1848 spin_lock(&fi->lock); in __inject_virtio()
1849 if (fi->counters[FIRQ_CNTR_VIRTIO] >= KVM_S390_MAX_VIRTIO_IRQS) { in __inject_virtio()
1850 spin_unlock(&fi->lock); in __inject_virtio()
1851 return -EBUSY; in __inject_virtio()
1853 fi->counters[FIRQ_CNTR_VIRTIO] += 1; in __inject_virtio()
1854 list_add_tail(&inti->list, &fi->lists[FIRQ_LIST_VIRTIO]); in __inject_virtio()
1855 set_bit(IRQ_PEND_VIRTIO, &fi->pending_irqs); in __inject_virtio()
1856 spin_unlock(&fi->lock); in __inject_virtio()
1863 struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; in __inject_pfault_done()
1865 kvm->stat.inject_pfault_done++; in __inject_pfault_done()
1866 spin_lock(&fi->lock); in __inject_pfault_done()
1867 if (fi->counters[FIRQ_CNTR_PFAULT] >= in __inject_pfault_done()
1869 spin_unlock(&fi->lock); in __inject_pfault_done()
1870 return -EBUSY; in __inject_pfault_done()
1872 fi->counters[FIRQ_CNTR_PFAULT] += 1; in __inject_pfault_done()
1873 list_add_tail(&inti->list, &fi->lists[FIRQ_LIST_PFAULT]); in __inject_pfault_done()
1874 set_bit(IRQ_PEND_PFAULT_DONE, &fi->pending_irqs); in __inject_pfault_done()
1875 spin_unlock(&fi->lock); in __inject_pfault_done()
1883 struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; in __inject_float_mchk()
1885 kvm->stat.inject_float_mchk++; in __inject_float_mchk()
1886 spin_lock(&fi->lock); in __inject_float_mchk()
1887 fi->mchk.cr14 |= inti->mchk.cr14 & (1UL << CR_PENDING_SUBCLASS); in __inject_float_mchk()
1888 fi->mchk.mcic |= inti->mchk.mcic; in __inject_float_mchk()
1889 set_bit(IRQ_PEND_MCHK_REP, &fi->pending_irqs); in __inject_float_mchk()
1890 spin_unlock(&fi->lock); in __inject_float_mchk()
1897 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int; in __inject_io()
1902 kvm->stat.inject_io++; in __inject_io()
1903 isc = int_word_to_isc(inti->io.io_int_word); in __inject_io()
1911 if (gi->origin && inti->type & KVM_S390_INT_IO_AI_MASK) { in __inject_io()
1913 gisa_set_ipm_gisc(gi->origin, isc); in __inject_io()
1918 fi = &kvm->arch.float_int; in __inject_io()
1919 spin_lock(&fi->lock); in __inject_io()
1920 if (fi->counters[FIRQ_CNTR_IO] >= KVM_S390_MAX_FLOAT_IRQS) { in __inject_io()
1921 spin_unlock(&fi->lock); in __inject_io()
1922 return -EBUSY; in __inject_io()
1924 fi->counters[FIRQ_CNTR_IO] += 1; in __inject_io()
1926 if (inti->type & KVM_S390_INT_IO_AI_MASK) in __inject_io()
1930 inti->io.subchannel_id >> 8, in __inject_io()
1931 inti->io.subchannel_id >> 1 & 0x3, in __inject_io()
1932 inti->io.subchannel_nr); in __inject_io()
1933 list = &fi->lists[FIRQ_LIST_IO_ISC_0 + isc]; in __inject_io()
1934 list_add_tail(&inti->list, list); in __inject_io()
1935 set_bit(isc_to_irq_type(isc), &fi->pending_irqs); in __inject_io()
1936 spin_unlock(&fi->lock); in __inject_io()
1948 online_vcpus = atomic_read(&kvm->online_vcpus); in __floating_irq_kick()
1953 sigcpu = find_first_bit(kvm->arch.idle_mask, online_vcpus); in __floating_irq_kick()
1956 sigcpu = kvm->arch.float_int.next_rr_cpu++; in __floating_irq_kick()
1957 kvm->arch.float_int.next_rr_cpu %= online_vcpus; in __floating_irq_kick()
1972 kvm->arch.gisa_int.origin) || in __floating_irq_kick()
1985 u64 type = READ_ONCE(inti->type); in __inject_vm()
2005 rc = -EINVAL; in __inject_vm()
2022 return -ENOMEM; in kvm_s390_inject_vm()
2024 inti->type = s390int->type; in kvm_s390_inject_vm()
2025 switch (inti->type) { in kvm_s390_inject_vm()
2028 s390int->parm, s390int->parm64); in kvm_s390_inject_vm()
2029 inti->ext.ext_params = s390int->parm; in kvm_s390_inject_vm()
2030 inti->ext.ext_params2 = s390int->parm64; in kvm_s390_inject_vm()
2033 VM_EVENT(kvm, 4, "inject: sclp parm:%x", s390int->parm); in kvm_s390_inject_vm()
2034 inti->ext.ext_params = s390int->parm; in kvm_s390_inject_vm()
2037 inti->ext.ext_params2 = s390int->parm64; in kvm_s390_inject_vm()
2041 s390int->parm64); in kvm_s390_inject_vm()
2042 inti->mchk.cr14 = s390int->parm; /* upper bits are not used */ in kvm_s390_inject_vm()
2043 inti->mchk.mcic = s390int->parm64; in kvm_s390_inject_vm()
2046 inti->io.subchannel_id = s390int->parm >> 16; in kvm_s390_inject_vm()
2047 inti->io.subchannel_nr = s390int->parm & 0x0000ffffu; in kvm_s390_inject_vm()
2048 inti->io.io_int_parm = s390int->parm64 >> 32; in kvm_s390_inject_vm()
2049 inti->io.io_int_word = s390int->parm64 & 0x00000000ffffffffull; in kvm_s390_inject_vm()
2053 return -EINVAL; in kvm_s390_inject_vm()
2055 trace_kvm_s390_inject_vm(s390int->type, s390int->parm, s390int->parm64, in kvm_s390_inject_vm()
2073 irq->type = s390int->type; in s390int_to_s390irq()
2074 switch (irq->type) { in s390int_to_s390irq()
2076 if (s390int->parm & 0xffff0000) in s390int_to_s390irq()
2077 return -EINVAL; in s390int_to_s390irq()
2078 irq->u.pgm.code = s390int->parm; in s390int_to_s390irq()
2081 irq->u.prefix.address = s390int->parm; in s390int_to_s390irq()
2084 irq->u.stop.flags = s390int->parm; in s390int_to_s390irq()
2087 if (s390int->parm & 0xffff0000) in s390int_to_s390irq()
2088 return -EINVAL; in s390int_to_s390irq()
2089 irq->u.extcall.code = s390int->parm; in s390int_to_s390irq()
2092 if (s390int->parm & 0xffff0000) in s390int_to_s390irq()
2093 return -EINVAL; in s390int_to_s390irq()
2094 irq->u.emerg.code = s390int->parm; in s390int_to_s390irq()
2097 irq->u.mchk.mcic = s390int->parm64; in s390int_to_s390irq()
2100 irq->u.ext.ext_params = s390int->parm; in s390int_to_s390irq()
2101 irq->u.ext.ext_params2 = s390int->parm64; in s390int_to_s390irq()
2108 return -EINVAL; in s390int_to_s390irq()
2115 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in kvm_s390_is_stop_irq_pending()
2117 return test_bit(IRQ_PEND_SIGP_STOP, &li->pending_irqs); in kvm_s390_is_stop_irq_pending()
2122 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in kvm_s390_is_restart_irq_pending()
2124 return test_bit(IRQ_PEND_RESTART, &li->pending_irqs); in kvm_s390_is_restart_irq_pending()
2129 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in kvm_s390_clear_stop_irq()
2131 spin_lock(&li->lock); in kvm_s390_clear_stop_irq()
2132 li->irq.stop.flags = 0; in kvm_s390_clear_stop_irq()
2133 clear_bit(IRQ_PEND_SIGP_STOP, &li->pending_irqs); in kvm_s390_clear_stop_irq()
2134 spin_unlock(&li->lock); in kvm_s390_clear_stop_irq()
2141 switch (irq->type) { in do_inject_vcpu()
2176 rc = -EINVAL; in do_inject_vcpu()
2184 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in kvm_s390_inject_vcpu()
2187 spin_lock(&li->lock); in kvm_s390_inject_vcpu()
2189 spin_unlock(&li->lock); in kvm_s390_inject_vcpu()
2200 list_del(&inti->list); in clear_irq_list()
2208 irq->type = inti->type; in inti_to_irq()
2209 switch (inti->type) { in inti_to_irq()
2213 irq->u.ext = inti->ext; in inti_to_irq()
2216 irq->u.io = inti->io; in inti_to_irq()
2223 struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; in kvm_s390_clear_float_irqs()
2226 mutex_lock(&kvm->lock); in kvm_s390_clear_float_irqs()
2228 fi->masked_irqs = 0; in kvm_s390_clear_float_irqs()
2229 mutex_unlock(&kvm->lock); in kvm_s390_clear_float_irqs()
2230 spin_lock(&fi->lock); in kvm_s390_clear_float_irqs()
2231 fi->pending_irqs = 0; in kvm_s390_clear_float_irqs()
2232 memset(&fi->srv_signal, 0, sizeof(fi->srv_signal)); in kvm_s390_clear_float_irqs()
2233 memset(&fi->mchk, 0, sizeof(fi->mchk)); in kvm_s390_clear_float_irqs()
2235 clear_irq_list(&fi->lists[i]); in kvm_s390_clear_float_irqs()
2237 fi->counters[i] = 0; in kvm_s390_clear_float_irqs()
2238 spin_unlock(&fi->lock); in kvm_s390_clear_float_irqs()
2244 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int; in get_all_floating_irqs()
2255 return -EINVAL; in get_all_floating_irqs()
2258 * We are already using -ENOMEM to signal in get_all_floating_irqs()
2264 return -ENOBUFS; in get_all_floating_irqs()
2268 if (gi->origin && gisa_get_ipm(gi->origin)) { in get_all_floating_irqs()
2272 ret = -ENOMEM; in get_all_floating_irqs()
2275 if (gisa_tac_ipm_gisc(gi->origin, i)) { in get_all_floating_irqs()
2277 irq->type = KVM_S390_INT_IO(1, 0, 0, 0); in get_all_floating_irqs()
2278 irq->u.io.io_int_word = isc_to_int_word(i); in get_all_floating_irqs()
2283 fi = &kvm->arch.float_int; in get_all_floating_irqs()
2284 spin_lock(&fi->lock); in get_all_floating_irqs()
2286 list_for_each_entry(inti, &fi->lists[i], list) { in get_all_floating_irqs()
2289 ret = -ENOMEM; in get_all_floating_irqs()
2296 if (test_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs) || in get_all_floating_irqs()
2297 test_bit(IRQ_PEND_EXT_SERVICE_EV, &fi->pending_irqs)) { in get_all_floating_irqs()
2300 ret = -ENOMEM; in get_all_floating_irqs()
2304 irq->type = KVM_S390_INT_SERVICE; in get_all_floating_irqs()
2305 irq->u.ext = fi->srv_signal; in get_all_floating_irqs()
2308 if (test_bit(IRQ_PEND_MCHK_REP, &fi->pending_irqs)) { in get_all_floating_irqs()
2311 ret = -ENOMEM; in get_all_floating_irqs()
2315 irq->type = KVM_S390_MCHK; in get_all_floating_irqs()
2316 irq->u.mchk = fi->mchk; in get_all_floating_irqs()
2321 spin_unlock(&fi->lock); in get_all_floating_irqs()
2325 ret = -EFAULT; in get_all_floating_irqs()
2334 struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; in flic_ais_mode_get_all()
2337 if (attr->attr < sizeof(ais)) in flic_ais_mode_get_all()
2338 return -EINVAL; in flic_ais_mode_get_all()
2341 return -EOPNOTSUPP; in flic_ais_mode_get_all()
2343 mutex_lock(&fi->ais_lock); in flic_ais_mode_get_all()
2344 ais.simm = fi->simm; in flic_ais_mode_get_all()
2345 ais.nimm = fi->nimm; in flic_ais_mode_get_all()
2346 mutex_unlock(&fi->ais_lock); in flic_ais_mode_get_all()
2348 if (copy_to_user((void __user *)attr->addr, &ais, sizeof(ais))) in flic_ais_mode_get_all()
2349 return -EFAULT; in flic_ais_mode_get_all()
2358 switch (attr->group) { in flic_get_attr()
2360 r = get_all_floating_irqs(dev->kvm, (u8 __user *) attr->addr, in flic_get_attr()
2361 attr->attr); in flic_get_attr()
2364 r = flic_ais_mode_get_all(dev->kvm, attr); in flic_get_attr()
2367 r = -EINVAL; in flic_get_attr()
2381 if (get_user(inti->type, (u64 __user *)addr)) in copy_irq_from_user()
2382 return -EFAULT; in copy_irq_from_user()
2384 switch (inti->type) { in copy_irq_from_user()
2389 target = (void *) &inti->ext; in copy_irq_from_user()
2390 source = &uptr->u.ext; in copy_irq_from_user()
2391 size = sizeof(inti->ext); in copy_irq_from_user()
2394 target = (void *) &inti->io; in copy_irq_from_user()
2395 source = &uptr->u.io; in copy_irq_from_user()
2396 size = sizeof(inti->io); in copy_irq_from_user()
2399 target = (void *) &inti->mchk; in copy_irq_from_user()
2400 source = &uptr->u.mchk; in copy_irq_from_user()
2401 size = sizeof(inti->mchk); in copy_irq_from_user()
2404 return -EINVAL; in copy_irq_from_user()
2408 return -EFAULT; in copy_irq_from_user()
2418 int len = attr->attr; in enqueue_floating_irq()
2421 return -EINVAL; in enqueue_floating_irq()
2423 return -EINVAL; in enqueue_floating_irq()
2428 return -ENOMEM; in enqueue_floating_irq()
2430 r = copy_irq_from_user(inti, attr->addr); in enqueue_floating_irq()
2435 r = __inject_vm(dev->kvm, inti); in enqueue_floating_irq()
2440 len -= sizeof(struct kvm_s390_irq); in enqueue_floating_irq()
2441 attr->addr += sizeof(struct kvm_s390_irq); in enqueue_floating_irq()
2452 return kvm->arch.adapters[id]; in get_io_adapter()
2462 (void __user *)attr->addr, sizeof(adapter_info))) in register_io_adapter()
2463 return -EFAULT; in register_io_adapter()
2466 return -EINVAL; in register_io_adapter()
2471 if (dev->kvm->arch.adapters[adapter_info.id] != NULL) in register_io_adapter()
2472 return -EINVAL; in register_io_adapter()
2476 return -ENOMEM; in register_io_adapter()
2478 adapter->id = adapter_info.id; in register_io_adapter()
2479 adapter->isc = adapter_info.isc; in register_io_adapter()
2480 adapter->maskable = adapter_info.maskable; in register_io_adapter()
2481 adapter->masked = false; in register_io_adapter()
2482 adapter->swap = adapter_info.swap; in register_io_adapter()
2483 adapter->suppressible = (adapter_info.flags) & in register_io_adapter()
2485 dev->kvm->arch.adapters[adapter->id] = adapter; in register_io_adapter()
2495 if (!adapter || !adapter->maskable) in kvm_s390_mask_adapter()
2496 return -EINVAL; in kvm_s390_mask_adapter()
2497 ret = adapter->masked; in kvm_s390_mask_adapter()
2498 adapter->masked = masked; in kvm_s390_mask_adapter()
2507 kfree(kvm->arch.adapters[i]); in kvm_s390_destroy_adapters()
2517 if (copy_from_user(&req, (void __user *)attr->addr, sizeof(req))) in modify_io_adapter()
2518 return -EFAULT; in modify_io_adapter()
2520 adapter = get_io_adapter(dev->kvm, req.id); in modify_io_adapter()
2522 return -EINVAL; in modify_io_adapter()
2525 ret = kvm_s390_mask_adapter(dev->kvm, req.id, req.mask); in modify_io_adapter()
2530 * The following operations are no longer needed and therefore no-ops. in modify_io_adapter()
2539 ret = -EINVAL; in modify_io_adapter()
2551 if (attr->flags) in clear_io_irq()
2552 return -EINVAL; in clear_io_irq()
2553 if (attr->attr != sizeof(schid)) in clear_io_irq()
2554 return -EINVAL; in clear_io_irq()
2555 if (copy_from_user(&schid, (void __user *) attr->addr, sizeof(schid))) in clear_io_irq()
2556 return -EFAULT; in clear_io_irq()
2558 return -EINVAL; in clear_io_irq()
2570 struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; in modify_ais_mode()
2575 return -EOPNOTSUPP; in modify_ais_mode()
2577 if (copy_from_user(&req, (void __user *)attr->addr, sizeof(req))) in modify_ais_mode()
2578 return -EFAULT; in modify_ais_mode()
2581 return -EINVAL; in modify_ais_mode()
2584 (fi->simm & AIS_MODE_MASK(req.isc)) ? in modify_ais_mode()
2585 (fi->nimm & AIS_MODE_MASK(req.isc)) ? in modify_ais_mode()
2589 mutex_lock(&fi->ais_lock); in modify_ais_mode()
2592 fi->simm &= ~AIS_MODE_MASK(req.isc); in modify_ais_mode()
2593 fi->nimm &= ~AIS_MODE_MASK(req.isc); in modify_ais_mode()
2596 fi->simm |= AIS_MODE_MASK(req.isc); in modify_ais_mode()
2597 fi->nimm &= ~AIS_MODE_MASK(req.isc); in modify_ais_mode()
2600 ret = -EINVAL; in modify_ais_mode()
2602 mutex_unlock(&fi->ais_lock); in modify_ais_mode()
2610 struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; in kvm_s390_inject_airq()
2614 .parm64 = isc_to_int_word(adapter->isc), in kvm_s390_inject_airq()
2618 if (!test_kvm_facility(kvm, 72) || !adapter->suppressible) in kvm_s390_inject_airq()
2621 mutex_lock(&fi->ais_lock); in kvm_s390_inject_airq()
2622 if (fi->nimm & AIS_MODE_MASK(adapter->isc)) { in kvm_s390_inject_airq()
2623 trace_kvm_s390_airq_suppressed(adapter->id, adapter->isc); in kvm_s390_inject_airq()
2628 if (!ret && (fi->simm & AIS_MODE_MASK(adapter->isc))) { in kvm_s390_inject_airq()
2629 fi->nimm |= AIS_MODE_MASK(adapter->isc); in kvm_s390_inject_airq()
2630 trace_kvm_s390_modify_ais_mode(adapter->isc, in kvm_s390_inject_airq()
2634 mutex_unlock(&fi->ais_lock); in kvm_s390_inject_airq()
2640 unsigned int id = attr->attr; in flic_inject_airq()
2644 return -EINVAL; in flic_inject_airq()
2651 struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; in flic_ais_mode_set_all()
2655 return -EOPNOTSUPP; in flic_ais_mode_set_all()
2657 if (copy_from_user(&ais, (void __user *)attr->addr, sizeof(ais))) in flic_ais_mode_set_all()
2658 return -EFAULT; in flic_ais_mode_set_all()
2660 mutex_lock(&fi->ais_lock); in flic_ais_mode_set_all()
2661 fi->simm = ais.simm; in flic_ais_mode_set_all()
2662 fi->nimm = ais.nimm; in flic_ais_mode_set_all()
2663 mutex_unlock(&fi->ais_lock); in flic_ais_mode_set_all()
2674 switch (attr->group) { in flic_set_attr()
2679 kvm_s390_clear_float_irqs(dev->kvm); in flic_set_attr()
2682 dev->kvm->arch.gmap->pfault_enabled = 1; in flic_set_attr()
2685 dev->kvm->arch.gmap->pfault_enabled = 0; in flic_set_attr()
2691 synchronize_srcu(&dev->kvm->srcu); in flic_set_attr()
2692 kvm_for_each_vcpu(i, vcpu, dev->kvm) in flic_set_attr()
2702 r = clear_io_irq(dev->kvm, attr); in flic_set_attr()
2705 r = modify_ais_mode(dev->kvm, attr); in flic_set_attr()
2708 r = flic_inject_airq(dev->kvm, attr); in flic_set_attr()
2711 r = flic_ais_mode_set_all(dev->kvm, attr); in flic_set_attr()
2714 r = -EINVAL; in flic_set_attr()
2723 switch (attr->group) { in flic_has_attr()
2737 return -ENXIO; in flic_has_attr()
2743 return -EINVAL; in flic_create()
2744 if (dev->kvm->arch.flic) in flic_create()
2745 return -EINVAL; in flic_create()
2746 dev->kvm->arch.flic = dev; in flic_create()
2752 dev->kvm->arch.flic = NULL; in flic_destroy()
2758 .name = "kvm-flic",
2772 return swap ? (bit ^ (BITS_PER_LONG - 1)) : bit; in get_ind_bit()
2779 mmap_read_lock(kvm->mm); in get_map_page()
2780 get_user_pages_remote(kvm->mm, uaddr, 1, FOLL_WRITE, in get_map_page()
2782 mmap_read_unlock(kvm->mm); in get_map_page()
2795 ind_page = get_map_page(kvm, adapter_int->ind_addr); in adapter_indicators_set()
2797 return -1; in adapter_indicators_set()
2798 summary_page = get_map_page(kvm, adapter_int->summary_addr); in adapter_indicators_set()
2801 return -1; in adapter_indicators_set()
2804 idx = srcu_read_lock(&kvm->srcu); in adapter_indicators_set()
2806 bit = get_ind_bit(adapter_int->ind_addr, in adapter_indicators_set()
2807 adapter_int->ind_offset, adapter->swap); in adapter_indicators_set()
2809 mark_page_dirty(kvm, adapter_int->ind_addr >> PAGE_SHIFT); in adapter_indicators_set()
2812 bit = get_ind_bit(adapter_int->summary_addr, in adapter_indicators_set()
2813 adapter_int->summary_offset, adapter->swap); in adapter_indicators_set()
2815 mark_page_dirty(kvm, adapter_int->summary_addr >> PAGE_SHIFT); in adapter_indicators_set()
2817 srcu_read_unlock(&kvm->srcu, idx); in adapter_indicators_set()
2825 * < 0 - not injected due to error
2826 * = 0 - coalesced, summary indicator already active
2827 * > 0 - injected interrupt
2836 /* We're only interested in the 0->1 transition. */ in set_adapter_int()
2839 adapter = get_io_adapter(kvm, e->adapter.adapter_id); in set_adapter_int()
2841 return -1; in set_adapter_int()
2842 ret = adapter_indicators_set(kvm, adapter, &e->adapter); in set_adapter_int()
2843 if ((ret > 0) && !adapter->masked) { in set_adapter_int()
2864 mci.val = mcck_info->mcic; in kvm_s390_reinject_machine_check()
2867 if (mci.dg) in kvm_s390_reinject_machine_check()
2873 mchk->cr14 = cr14; in kvm_s390_reinject_machine_check()
2874 mchk->mcic = mcck_info->mcic; in kvm_s390_reinject_machine_check()
2875 mchk->ext_damage_code = mcck_info->ext_damage_code; in kvm_s390_reinject_machine_check()
2876 mchk->failing_storage_address = mcck_info->failing_storage_address; in kvm_s390_reinject_machine_check()
2880 rc = __inject_vm(vcpu->kvm, &inti); in kvm_s390_reinject_machine_check()
2895 switch (ue->type) { in kvm_set_routing_entry()
2898 e->set = set_adapter_int; in kvm_set_routing_entry()
2899 uaddr = gmap_translate(kvm->arch.gmap, ue->u.adapter.summary_addr); in kvm_set_routing_entry()
2900 if (uaddr == -EFAULT) in kvm_set_routing_entry()
2901 return -EFAULT; in kvm_set_routing_entry()
2902 e->adapter.summary_addr = uaddr; in kvm_set_routing_entry()
2903 uaddr = gmap_translate(kvm->arch.gmap, ue->u.adapter.ind_addr); in kvm_set_routing_entry()
2904 if (uaddr == -EFAULT) in kvm_set_routing_entry()
2905 return -EFAULT; in kvm_set_routing_entry()
2906 e->adapter.ind_addr = uaddr; in kvm_set_routing_entry()
2907 e->adapter.summary_offset = ue->u.adapter.summary_offset; in kvm_set_routing_entry()
2908 e->adapter.ind_offset = ue->u.adapter.ind_offset; in kvm_set_routing_entry()
2909 e->adapter.adapter_id = ue->u.adapter.adapter_id; in kvm_set_routing_entry()
2912 return -EINVAL; in kvm_set_routing_entry()
2919 return -EINVAL; in kvm_set_msi()
2924 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in kvm_s390_set_irq_state()
2931 return -ENOMEM; in kvm_s390_set_irq_state()
2934 r = -EFAULT; in kvm_s390_set_irq_state()
2942 spin_lock(&li->lock); in kvm_s390_set_irq_state()
2943 if (li->pending_irqs) { in kvm_s390_set_irq_state()
2944 r = -EBUSY; in kvm_s390_set_irq_state()
2955 spin_unlock(&li->lock); in kvm_s390_set_irq_state()
2969 irq->type = KVM_S390_MCHK; in store_local_irq()
2970 irq->u.mchk = li->irq.mchk; in store_local_irq()
2973 irq->type = KVM_S390_PROGRAM_INT; in store_local_irq()
2974 irq->u.pgm = li->irq.pgm; in store_local_irq()
2977 irq->type = KVM_S390_INT_PFAULT_INIT; in store_local_irq()
2978 irq->u.ext = li->irq.ext; in store_local_irq()
2981 irq->type = KVM_S390_INT_EXTERNAL_CALL; in store_local_irq()
2982 irq->u.extcall = li->irq.extcall; in store_local_irq()
2985 irq->type = KVM_S390_INT_CLOCK_COMP; in store_local_irq()
2988 irq->type = KVM_S390_INT_CPU_TIMER; in store_local_irq()
2991 irq->type = KVM_S390_SIGP_STOP; in store_local_irq()
2992 irq->u.stop = li->irq.stop; in store_local_irq()
2995 irq->type = KVM_S390_RESTART; in store_local_irq()
2998 irq->type = KVM_S390_SIGP_SET_PREFIX; in store_local_irq()
2999 irq->u.prefix = li->irq.prefix; in store_local_irq()
3008 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; in kvm_s390_get_irq_state()
3015 spin_lock(&li->lock); in kvm_s390_get_irq_state()
3016 pending_irqs = li->pending_irqs; in kvm_s390_get_irq_state()
3017 memcpy(&sigp_emerg_pending, &li->sigp_emerg_pending, in kvm_s390_get_irq_state()
3019 spin_unlock(&li->lock); in kvm_s390_get_irq_state()
3026 return -ENOBUFS; in kvm_s390_get_irq_state()
3027 store_local_irq(&vcpu->arch.local_int, &irq, irq_type); in kvm_s390_get_irq_state()
3029 return -EFAULT; in kvm_s390_get_irq_state()
3037 return -ENOBUFS; in kvm_s390_get_irq_state()
3041 return -EFAULT; in kvm_s390_get_irq_state()
3048 return -ENOBUFS; in kvm_s390_get_irq_state()
3053 return -EFAULT; in kvm_s390_get_irq_state()
3062 int vcpu_idx, online_vcpus = atomic_read(&kvm->online_vcpus); in __airqs_kick_single_vcpu()
3063 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int; in __airqs_kick_single_vcpu()
3067 for_each_set_bit(vcpu_idx, kvm->arch.idle_mask, online_vcpus) { in __airqs_kick_single_vcpu()
3071 vcpu_isc_mask = (u8)(vcpu->arch.sie_block->gcr[6] >> 24); in __airqs_kick_single_vcpu()
3074 if (test_and_set_bit(vcpu_idx, gi->kicked_mask)) in __airqs_kick_single_vcpu()
3087 container_of(gi->origin, struct sie_page2, gisa)->kvm; in gisa_vcpu_kicker()
3093 hrtimer_forward_now(timer, ns_to_ktime(gi->expires)); in gisa_vcpu_kicker()
3123 * for guests not in the yet cut-off alert list. When in the in process_gib_alert_list()
3124 * final loop, store the NULL_GISA_ADDR instead. This will re- in process_gib_alert_list()
3127 origin = xchg(&gib->alert_list_origin, in process_gib_alert_list()
3130 * Loop through the just cut-off alert list and start the in process_gib_alert_list()
3136 origin = gisa->next_alert; in process_gib_alert_list()
3137 gisa->next_alert = (u32)(u64)gisa; in process_gib_alert_list()
3138 kvm = container_of(gisa, struct sie_page2, gisa)->kvm; in process_gib_alert_list()
3139 gi = &kvm->arch.gisa_int; in process_gib_alert_list()
3140 if (hrtimer_active(&gi->timer)) in process_gib_alert_list()
3141 hrtimer_cancel(&gi->timer); in process_gib_alert_list()
3142 hrtimer_start(&gi->timer, 0, HRTIMER_MODE_REL); in process_gib_alert_list()
3150 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int; in kvm_s390_gisa_clear()
3152 if (!gi->origin) in kvm_s390_gisa_clear()
3154 gisa_clear_ipm(gi->origin); in kvm_s390_gisa_clear()
3155 VM_EVENT(kvm, 3, "gisa 0x%pK cleared", gi->origin); in kvm_s390_gisa_clear()
3160 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int; in kvm_s390_gisa_init()
3164 gi->origin = &kvm->arch.sie_page2->gisa; in kvm_s390_gisa_init()
3165 gi->alert.mask = 0; in kvm_s390_gisa_init()
3166 spin_lock_init(&gi->alert.ref_lock); in kvm_s390_gisa_init()
3167 gi->expires = 50 * 1000; /* 50 usec */ in kvm_s390_gisa_init()
3168 hrtimer_init(&gi->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in kvm_s390_gisa_init()
3169 gi->timer.function = gisa_vcpu_kicker; in kvm_s390_gisa_init()
3170 memset(gi->origin, 0, sizeof(struct kvm_s390_gisa)); in kvm_s390_gisa_init()
3171 gi->origin->next_alert = (u32)(u64)gi->origin; in kvm_s390_gisa_init()
3172 VM_EVENT(kvm, 3, "gisa 0x%pK initialized", gi->origin); in kvm_s390_gisa_init()
3177 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int; in kvm_s390_gisa_enable()
3182 if (gi->origin) in kvm_s390_gisa_enable()
3189 mutex_lock(&vcpu->mutex); in kvm_s390_gisa_enable()
3190 vcpu->arch.sie_block->gd = gisa_desc; in kvm_s390_gisa_enable()
3191 vcpu->arch.sie_block->eca |= ECA_AIV; in kvm_s390_gisa_enable()
3192 VCPU_EVENT(vcpu, 3, "AIV gisa format-%u enabled for cpu %03u", in kvm_s390_gisa_enable()
3193 vcpu->arch.sie_block->gd & 0x3, vcpu->vcpu_id); in kvm_s390_gisa_enable()
3194 mutex_unlock(&vcpu->mutex); in kvm_s390_gisa_enable()
3200 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int; in kvm_s390_gisa_destroy()
3201 struct kvm_s390_gisa *gisa = gi->origin; in kvm_s390_gisa_destroy()
3203 if (!gi->origin) in kvm_s390_gisa_destroy()
3205 if (gi->alert.mask) in kvm_s390_gisa_destroy()
3207 kvm, gi->alert.mask); in kvm_s390_gisa_destroy()
3208 while (gisa_in_alert_list(gi->origin)) in kvm_s390_gisa_destroy()
3210 hrtimer_cancel(&gi->timer); in kvm_s390_gisa_destroy()
3211 gi->origin = NULL; in kvm_s390_gisa_destroy()
3217 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int; in kvm_s390_gisa_disable()
3221 if (!gi->origin) in kvm_s390_gisa_disable()
3224 mutex_lock(&vcpu->mutex); in kvm_s390_gisa_disable()
3225 vcpu->arch.sie_block->eca &= ~ECA_AIV; in kvm_s390_gisa_disable()
3226 vcpu->arch.sie_block->gd = 0U; in kvm_s390_gisa_disable()
3227 mutex_unlock(&vcpu->mutex); in kvm_s390_gisa_disable()
3228 VCPU_EVENT(vcpu, 3, "AIV disabled for cpu %03u", vcpu->vcpu_id); in kvm_s390_gisa_disable()
3234 * kvm_s390_gisc_register - register a guest ISC
3237 * @gisc: the guest interruption sub class to register
3247 * -ENODEV in case the vm uses no GISA
3248 * -ERANGE in case the guest ISC is invalid
3252 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int; in kvm_s390_gisc_register()
3254 if (!gi->origin) in kvm_s390_gisc_register()
3255 return -ENODEV; in kvm_s390_gisc_register()
3257 return -ERANGE; in kvm_s390_gisc_register()
3259 spin_lock(&gi->alert.ref_lock); in kvm_s390_gisc_register()
3260 gi->alert.ref_count[gisc]++; in kvm_s390_gisc_register()
3261 if (gi->alert.ref_count[gisc] == 1) { in kvm_s390_gisc_register()
3262 gi->alert.mask |= 0x80 >> gisc; in kvm_s390_gisc_register()
3263 gisa_set_iam(gi->origin, gi->alert.mask); in kvm_s390_gisc_register()
3265 spin_unlock(&gi->alert.ref_lock); in kvm_s390_gisc_register()
3267 return gib->nisc; in kvm_s390_gisc_register()
3272 * kvm_s390_gisc_unregister - unregister a guest ISC
3275 * @gisc: the guest interruption sub class to register
3285 * -ENODEV in case the vm uses no GISA
3286 * -ERANGE in case the guest ISC is invalid
3287 * -EINVAL in case the guest ISC is not registered
3291 struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int; in kvm_s390_gisc_unregister()
3294 if (!gi->origin) in kvm_s390_gisc_unregister()
3295 return -ENODEV; in kvm_s390_gisc_unregister()
3297 return -ERANGE; in kvm_s390_gisc_unregister()
3299 spin_lock(&gi->alert.ref_lock); in kvm_s390_gisc_unregister()
3300 if (gi->alert.ref_count[gisc] == 0) { in kvm_s390_gisc_unregister()
3301 rc = -EINVAL; in kvm_s390_gisc_unregister()
3304 gi->alert.ref_count[gisc]--; in kvm_s390_gisc_unregister()
3305 if (gi->alert.ref_count[gisc] == 0) { in kvm_s390_gisc_unregister()
3306 gi->alert.mask &= ~(0x80 >> gisc); in kvm_s390_gisc_unregister()
3307 gisa_set_iam(gi->origin, gi->alert.mask); in kvm_s390_gisc_unregister()
3310 spin_unlock(&gi->alert.ref_lock); in kvm_s390_gisc_unregister()
3322 gaite = (struct zpci_gaite *)aift->gait + in aen_host_forward()
3324 if (gaite->count == 0) in aen_host_forward()
3326 if (gaite->aisb != 0) in aen_host_forward()
3327 set_bit_inv(gaite->aisbo, phys_to_virt(gaite->aisb)); in aen_host_forward()
3332 gi = &kvm->arch.gisa_int; in aen_host_forward()
3334 if (!(gi->origin->g1.simm & AIS_MODE_MASK(gaite->gisc)) || in aen_host_forward()
3335 !(gi->origin->g1.nimm & AIS_MODE_MASK(gaite->gisc))) { in aen_host_forward()
3336 gisa_set_ipm_gisc(gi->origin, gaite->gisc); in aen_host_forward()
3337 if (hrtimer_active(&gi->timer)) in aen_host_forward()
3338 hrtimer_cancel(&gi->timer); in aen_host_forward()
3339 hrtimer_start(&gi->timer, 0, HRTIMER_MODE_REL); in aen_host_forward()
3340 kvm->stat.aen_forward++; in aen_host_forward()
3350 spin_lock_irqsave(&aift->gait_lock, flags); in aen_process_gait()
3352 if (!aift->gait) { in aen_process_gait()
3353 spin_unlock_irqrestore(&aift->gait_lock, flags); in aen_process_gait()
3359 si = airq_iv_scan(aift->sbv, si, airq_iv_end(aift->sbv)); in aen_process_gait()
3360 if (si == -1UL) { in aen_process_gait()
3362 /* Re-enable interrupts. */ in aen_process_gait()
3372 /* Scan again after re-enabling interrupts */ in aen_process_gait()
3379 spin_unlock_irqrestore(&aift->gait_lock, flags); in aen_process_gait()
3389 if ((info->forward || info->error) && in gib_alert_irq_handler()
3391 aen_process_gait(info->isc); in gib_alert_irq_handler()
3392 if (info->aism != 0) in gib_alert_irq_handler()
3409 mutex_lock(&aift->aift_lock); in kvm_s390_gib_destroy()
3411 mutex_unlock(&aift->aift_lock); in kvm_s390_gib_destroy()
3430 rc = -ENOMEM; in kvm_s390_gib_init()
3437 rc = -EIO; in kvm_s390_gib_init()
3441 gib->nisc = nisc; in kvm_s390_gib_init()
3446 rc = -EIO; in kvm_s390_gib_init()
3453 rc = -EIO; in kvm_s390_gib_init()
3458 KVM_EVENT(3, "gib 0x%pK (nisc=%d) initialized", gib, gib->nisc); in kvm_s390_gib_init()