* [PATCH] kvm: s390: Improve floating IRQ injection behavior
@ 2026-08-13 14:56 Janosch Frank
2026-08-13 16:43 ` Christian Borntraeger
0 siblings, 1 reply; 2+ messages in thread
From: Janosch Frank @ 2026-08-13 14:56 UTC (permalink / raw)
To: kvm; +Cc: imbrenda, linux-s390, borntraeger
Floating IRQs can be handled by any VCPU that opened its masks. The
current design does not check if the mask is open when a floating IRQ
is injected via the FLIC. It will wakeup the last VCPU that went
sleeping hoping it's the correct one.
Improve this by at least checking if the VCPU has pending IRQs and if
not try to find another VCPU which can take the IRQ.
Also add a function to distribute floating IRQs which can be called on
VCPU enter or exit. It will check for pending floating IRQs and wakeup
sleeping VCPUs which have pending IRQs.
This is not the final fix around this topic but we'll eventually
inject a pending IRQ. The current code can easily deadlock a VM and
with this fix we work around that.
This will fix this test's hangs as well as another hang that's already
been present before I added the new test code. See:
https://lore.kernel.org/kvm/20260813144058.7125-1-frankja@linux.ibm.com/T/#u
Fixes: 352ccf890a3e ("KVM: s390: improve interrupt cpu for wakeup")
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
Currently this is in the entry path and therefore might affect
latency. I chose to do it this way as we inject IRQs into the current
cpu a couple of lines above the distribute_float_irqs() call which
should mean we have a higher chance that no other floating IRQs are
pending since we already handled an IRQ.
A simple boot of a smp guest resulted in 275 injects via the new code.
I haven't done any performance tests yet.
---
arch/s390/include/asm/kvm_host_s390.h | 1 +
arch/s390/kvm/s390/interrupt.c | 34 ++++++++++++++++++++++++++-
arch/s390/kvm/s390/s390.c | 3 +++
arch/s390/kvm/s390/s390.h | 1 +
4 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/arch/s390/include/asm/kvm_host_s390.h b/arch/s390/include/asm/kvm_host_s390.h
index cd692f8fb764..a86863e621b7 100644
--- a/arch/s390/include/asm/kvm_host_s390.h
+++ b/arch/s390/include/asm/kvm_host_s390.h
@@ -412,6 +412,7 @@ struct kvm_vm_stat {
u64 gmap_shadow_r3_entry;
u64 gmap_shadow_sg_entry;
u64 gmap_shadow_pg_entry;
+ u64 inject_redist;
};
struct kvm_arch_memory_slot {
diff --git a/arch/s390/kvm/s390/interrupt.c b/arch/s390/kvm/s390/interrupt.c
index 0381ae981703..663fc2e3eca5 100644
--- a/arch/s390/kvm/s390/interrupt.c
+++ b/arch/s390/kvm/s390/interrupt.c
@@ -372,6 +372,37 @@ static unsigned long deliverable_irqs(struct kvm_vcpu *vcpu)
return active_mask;
}
+void distribute_float_irqs(struct kvm *kvm)
+{
+ struct kvm_vcpu *dst_vcpu;
+ int sigcpu, online_vcpus;
+
+ if (!READ_ONCE(kvm->arch.float_int.pending_irqs))
+ return;
+
+ online_vcpus = atomic_read(&kvm->online_vcpus);
+
+ /*
+ * Not too worried about synchronization for idle_mask. We
+ * might burn too many cycles but apart from that waking a
+ * vcpu is not harmful.
+ */
+ sigcpu = find_first_bit(kvm->arch.idle_mask, online_vcpus);
+ /* Well nobody's sleeping so someone will likely take the IRQ soon */
+ if (sigcpu == online_vcpus)
+ return;
+
+ do {
+ dst_vcpu = kvm_get_vcpu(kvm, sigcpu);
+ if (deliverable_irqs(dst_vcpu)) {
+ kvm->stat.inject_redist++;
+ kvm_s390_vcpu_wakeup(dst_vcpu);
+ break;
+ }
+ sigcpu = find_next_bit(kvm->arch.idle_mask, online_vcpus, ++sigcpu);
+ } while (sigcpu < online_vcpus);
+}
+
static void __set_cpu_idle(struct kvm_vcpu *vcpu)
{
kvm_s390_set_cpuflags(vcpu, CPUSTAT_WAIT);
@@ -1933,7 +1964,8 @@ static void __floating_irq_kick(struct kvm *kvm, u64 type)
for (sigcpu = kvm->arch.float_int.last_sleep_cpu; ; sigcpu++) {
sigcpu %= online_vcpus;
dst_vcpu = kvm_get_vcpu(kvm, sigcpu);
- if (!is_vcpu_stopped(dst_vcpu))
+ if (!is_vcpu_stopped(dst_vcpu) &&
+ deliverable_irqs(dst_vcpu))
break;
/* avoid endless loops if all vcpus are stopped */
if (nr_tries++ >= online_vcpus)
diff --git a/arch/s390/kvm/s390/s390.c b/arch/s390/kvm/s390/s390.c
index b0839e887221..2ee0ab6b926a 100644
--- a/arch/s390/kvm/s390/s390.c
+++ b/arch/s390/kvm/s390/s390.c
@@ -87,6 +87,7 @@ const struct kvm_stats_desc kvm_vm_stats_desc[] = {
STATS_DESC_COUNTER(VM, gmap_shadow_r3_entry),
STATS_DESC_COUNTER(VM, gmap_shadow_sg_entry),
STATS_DESC_COUNTER(VM, gmap_shadow_pg_entry),
+ STATS_DESC_COUNTER(VM, inject_redist),
};
const struct kvm_stats_header kvm_vm_stats_header = {
@@ -4549,6 +4550,8 @@ static int vcpu_pre_run(struct kvm_vcpu *vcpu)
rc = kvm_s390_deliver_pending_interrupts(vcpu);
if (rc || guestdbg_exit_pending(vcpu))
return rc;
+
+ distribute_float_irqs(vcpu->kvm);
}
rc = kvm_s390_handle_requests(vcpu);
diff --git a/arch/s390/kvm/s390/s390.h b/arch/s390/kvm/s390/s390.h
index d284a263ba70..e518339fb290 100644
--- a/arch/s390/kvm/s390/s390.h
+++ b/arch/s390/kvm/s390/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 distribute_float_irqs(struct kvm *kvm);
int __must_check kvm_s390_inject_vm(struct kvm *kvm,
struct kvm_s390_interrupt *s390int,
struct kvm_s390_interrupt_info *inti);
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] kvm: s390: Improve floating IRQ injection behavior
2026-08-13 14:56 [PATCH] kvm: s390: Improve floating IRQ injection behavior Janosch Frank
@ 2026-08-13 16:43 ` Christian Borntraeger
0 siblings, 0 replies; 2+ messages in thread
From: Christian Borntraeger @ 2026-08-13 16:43 UTC (permalink / raw)
To: Janosch Frank, kvm; +Cc: imbrenda, linux-s390
Am 13.08.26 um 16:56 schrieb Janosch Frank:
kvm_s390_set_cpuflags(vcpu, CPUSTAT_WAIT);
> @@ -1933,7 +1964,8 @@ static void __floating_irq_kick(struct kvm *kvm, u64 type)
> for (sigcpu = kvm->arch.float_int.last_sleep_cpu; ; sigcpu++) {
> sigcpu %= online_vcpus;
> dst_vcpu = kvm_get_vcpu(kvm, sigcpu);
> - if (!is_vcpu_stopped(dst_vcpu))
> + if (!is_vcpu_stopped(dst_vcpu) &&
> + deliverable_irqs(dst_vcpu))
We have the type. Wouldnt it be better to actually check if type is deliverable?
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-13 16:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-13 14:56 [PATCH] kvm: s390: Improve floating IRQ injection behavior Janosch Frank
2026-08-13 16:43 ` Christian Borntraeger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox