Service call handling is a two stage process for PV vms. First we receive the secure instruction intercept and then the secure instruction notification intercept. The secure instruction intercept (104) is analogous to the non-pv instruction intercept (4) with the difference that we're not allowed to inject an IRQ when re-entering SIE. We have to wait for the notification intercept (108) which tells us that we're allowed to inject. Unfortunately we never considered this difference and hence the IRQ injection code will try to inject on the secure instruction intercept where service IRQs are masked. It's time to move injection to the instruction notification and skip injection on the instruction interception path. Signed-off-by: Janosch Frank --- arch/s390/kvm/intercept.c | 9 +++++++ arch/s390/kvm/interrupt.c | 50 ++++++++++++++++++++++++++++++++------- arch/s390/kvm/kvm-s390.h | 1 + 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/arch/s390/kvm/intercept.c b/arch/s390/kvm/intercept.c index 1980df61ef30..e1de3f471ffd 100644 --- a/arch/s390/kvm/intercept.c +++ b/arch/s390/kvm/intercept.c @@ -536,6 +536,15 @@ static int handle_pv_sclp(struct kvm_vcpu *vcpu) set_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs); clear_bit(IRQ_PEND_EXT_SERVICE, &fi->masked_irqs); spin_unlock_irqrestore(&fi->lock, flags); + + /* + * We missed the floating IRQ kick since we can only inject + * when we end up here and not when the irq was injected via + * the FLIC. + * + * Now that we have cleared the masking we can kick cpus. + */ + kvm_s390_pv_sclp_kick(vcpu); return 0; } diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index 87caad037765..b3e4bfeacff2 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -1960,10 +1960,7 @@ static void vcpu_intervention_kick(struct kvm_vcpu *vcpu, u64 type) kvm_s390_vcpu_wakeup(vcpu); } -/* - * Find a destination VCPU for a floating irq and kick it. - */ -static void __floating_irq_kick(struct kvm *kvm, u64 type, int isc) +static void kick_cpu_irq(struct kvm *kvm, u64 type, u64 parm) { struct kvm_vcpu *dst_vcpu; int sigcpu, online_vcpus, nr_tries = 0; @@ -1974,7 +1971,7 @@ static void __floating_irq_kick(struct kvm *kvm, u64 type, int isc) if (!online_vcpus) return; - irq_pend_mask = inti_to_irq_pend_mask(type, isc); + irq_pend_mask = inti_to_irq_pend_mask(type, parm); for (sigcpu = kvm->arch.float_int.last_sleep_cpu; ; sigcpu++) { sigcpu %= online_vcpus; dst_vcpu = kvm_get_vcpu(kvm, sigcpu); @@ -1998,10 +1995,46 @@ static void __floating_irq_kick(struct kvm *kvm, u64 type, int isc) vcpu_intervention_kick(dst_vcpu, type); } +void kvm_s390_pv_sclp_kick(struct kvm_vcpu *vcpu) +{ + /* + * The cpu that called sclp likely will also take the IRQ, no + * need to kick anyone. + */ + if (likely(deliverable_irqs(vcpu) & BIT(IRQ_PEND_EXT_SERVICE))) + return; + + /* + * For the other cases we might have sleeping cpus with open + * masks. Time to find and kick them. + */ + kick_cpu_irq(vcpu->kvm, KVM_S390_INT_SERVICE, -1); +} + +/* + * Find a destination VCPU for a floating irq and kick it. + */ +static void __floating_irq_kick(struct kvm *kvm, u64 type, u64 parm) +{ + struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; + + /* + * No need to kick on non-ev service IRQs for PV VMs, we're + * not allowed to inject anyway. We need to wait for the sclp + * instruction notification AFTER re-entry of the vcpu that + * handled the instruction intercept. + */ + if (type == KVM_S390_INT_SERVICE && !(parm & SCCB_EVENT_PENDING) && + test_bit(IRQ_PEND_EXT_SERVICE, &fi->masked_irqs)) + return; + + kick_cpu_irq(kvm, type, parm); +} + static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti) { u64 type = READ_ONCE(inti->type); - int isc = -1; + u64 parm = -1; int rc; switch (type) { @@ -2012,6 +2045,7 @@ static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti) rc = __inject_virtio(kvm, inti); break; case KVM_S390_INT_SERVICE: + parm = inti->ext.ext_params & SCCB_EVENT_PENDING; rc = __inject_service(kvm, inti); break; case KVM_S390_INT_PFAULT_DONE: @@ -2019,7 +2053,7 @@ static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti) break; case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: /* Grab isc here since __inject_io() might free inti */ - isc = int_word_to_isc(inti->io.io_int_word); + parm = int_word_to_isc(inti->io.io_int_word); rc = __inject_io(kvm, inti); break; default: @@ -2028,7 +2062,7 @@ static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti) if (rc) return rc; - __floating_irq_kick(kvm, type, isc); + __floating_irq_kick(kvm, type, parm); return 0; } diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h index 6d2842fb71a3..8e886bcef4a0 100644 --- a/arch/s390/kvm/kvm-s390.h +++ b/arch/s390/kvm/kvm-s390.h @@ -375,6 +375,7 @@ enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer); int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu); void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu); void kvm_s390_clear_float_irqs(struct kvm *kvm); +void kvm_s390_pv_sclp_kick(struct kvm_vcpu *vcpu); int __must_check kvm_s390_inject_vm(struct kvm *kvm, struct kvm_s390_interrupt *s390int, struct kvm_s390_interrupt_info *inti); -- 2.53.0