* [PATCH] KVM: Send reschedule IPIs instead of SMP function calls for non-waiting requests
@ 2026-11-17 20:54 Sean Christopherson
2026-11-18 21:11 ` Satish Kharat
0 siblings, 1 reply; 2+ messages in thread
From: Sean Christopherson @ 2026-11-17 20:54 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Sean Christopherson, kvm, linux-kernel, Satish Kharat
When kicking multiple vCPUs for a non-waiting request, send a reschedule
IPI to each vCPU instead of batching IPIs via a single SMP function call so
that KVM can make non-waiting requests with IRQs disabled. I.e. handle
multi-vCPU kicks the same way KVM handles single-vCPU kicks, for the exact
same reason.
Avoiding SMP function calls for non-waiting requests fixes a potential
deadlock if KVM VMX triggers KVM_REQ_UNBLOCK to all vCPUs when starting
device assignmennt:
WARNING: kernel/smp.c:943 at smp_call_function_many_cond
kvm_make_all_cpus_request [kvm]
kvm_arch_irq_bypass_add_producer [kvm]
__connect [irqbypass]
irq_bypass_register_producer [irqbypass]
vfio_msi_set_vector_signal [vfio_pci_core]
Send reschedule IPIs immediately to avoid having to re-walk the set of CPUs,
even though it makes the code slightly convoluted. It's also generally
advantageous to kick vCPUs as soon as possible, e.g. so that the target
vCPU(s) can react to pending events/actions, but that's purely nice-to-have
as there are very few paths in KVM that kick multiple vCPUs for non-waiting
requests.
Fixes: 77e1b8332d1d ("KVM: x86: Decouple device assignment from IRQ bypass")
Cc: stable@vger.kernel.org
Reported-by: Satish Kharat <satishkh@cisco.com>
Closes: https://lore.kernel.org/all/20261116-b4-kvm-irq-bypass-irqs-20261116-v1-1-6cc721a062fd@cisco.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
virt/kvm/kvm_main.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index cf4cb586f140..0b733746884c 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -218,7 +218,10 @@ static inline bool kvm_kick_many_cpus(struct cpumask *cpus, bool wait)
if (cpumask_empty(cpus))
return false;
- smp_call_function_many(cpus, ack_kick, NULL, wait);
+ /* See kvm_vcpu_kick() and kvm_make_vcpu_request() for details. */
+ if (wait)
+ smp_call_function_many(cpus, ack_kick, NULL, wait);
+
return true;
}
@@ -241,12 +244,20 @@ static void kvm_make_vcpu_request(struct kvm_vcpu *vcpu, unsigned int req,
* satisfied if the vCPU migrates. Entering READING_SHADOW_PAGE_TABLES
* after this point is also OK, as the requirement is only that KVM wait
* for vCPUs that were reading SPTEs _before_ any changes were
- * finalized. See kvm_vcpu_kick() for more details on handling requests.
+ * finalized.
+ *
+ * See kvm_vcpu_kick() for more details on handling requests, including
+ * the use of a reschedule IPI for non-waiting requests. If waiting is
+ * required, batch the SMP function call until after all to-be-kicked
+ * CPUs are gathered, to avoid waiting multiple times.
*/
if (kvm_request_needs_ipi(vcpu, req)) {
cpu = READ_ONCE(vcpu->cpu);
- if (cpu != -1 && cpu != current_cpu)
+ if (cpu != -1 && cpu != current_cpu) {
+ if (!(req & KVM_REQUEST_WAIT))
+ smp_send_reschedule(cpu);
__cpumask_set_cpu(cpu, tmp);
+ }
}
}
base-commit: d21eef2084a9af87ac2a783bc7c2b175ba114e4e
--
2.56.1.703.gf848ed807c-goog
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] KVM: Send reschedule IPIs instead of SMP function calls for non-waiting requests
2026-11-17 20:54 [PATCH] KVM: Send reschedule IPIs instead of SMP function calls for non-waiting requests Sean Christopherson
@ 2026-11-18 21:11 ` Satish Kharat
0 siblings, 0 replies; 2+ messages in thread
From: Satish Kharat @ 2026-11-18 21:11 UTC (permalink / raw)
To: seanjc; +Cc: pbonzini, kvm, linux-kernel
Hi Sean,
I tested this in place of my IRQ-bypass patch. The latter was reverted in
the test source, and I loaded a kvm.ko built with your change against the
running test kernel.
On an Intel UCS C220 M7, a four-vCPU guest used an ENIC VF through VFIO.
With the other three vCPUs busy, reloading the guest VF driver traced
vfio_msi_set_vector_signal() through vt_pi_start_bypass() to
kvm_make_all_cpus_request() with local IRQs disabled. The trace then showed
three reschedule IPIs from kvm_make_vcpu_request(), with no SMP function
call in that callback and no warning. Posted-interrupt updates occurred.
Three more VF reload cycles passed bidirectional traffic after VF traffic
became ready.
On an Intel UCS C240 M6 with the same test kernel and patched kvm.ko,
irqfd_test, irq_test, vmx_posted_intr_test and smptest passed. I restored
the original KVM modules on both hosts after testing.
One source-review question: should the direct IPI path check
cpu_online(cpu), as __kvm_vcpu_kick() does? The old batched helper filters
offline CPUs, while x86 native_smp_send_reschedule() warns for one. A
target vCPU could leave guest mode and its CPU could go offline between
the request check and the IPI. I did not test CPU hotplug, and this would
not imply a lost request.
Tested-by: Satish Kharat <satishkh@cisco.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 21:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 20:54 [PATCH] KVM: Send reschedule IPIs instead of SMP function calls for non-waiting requests Sean Christopherson
2026-11-18 21:11 ` Satish Kharat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®