Re: [PATCH] KVM: Send reschedule IPIs instead of SMP function calls for non-waiting requests
From: Satish Kharat
Date: Thu Nov 19 2026 - 00:14:35 EST
Hi Sean,
> Ugh, yeah, that WARN could be problematic. Thanks much!
I tried a guard on top of your patch. The non-waiting path checks
cpu_active() before sending a reschedule IPI. Both callers hold get_cpu()
through this helper and the send. CPU-down clears cpu_active() and then
waits for preempt-disabled readers before taking the CPU offline. That
appears to protect the interval between the check and the IPI.
This is the incremental diff I built and tested:
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -253,9 +253,12 @@
*/
if (kvm_request_needs_ipi(vcpu, req)) {
cpu = READ_ONCE(vcpu->cpu);
- if (cpu != -1 && cpu != current_cpu) {
- if (!(req & KVM_REQUEST_WAIT))
+ if (cpu != current_cpu && (unsigned int)cpu < nr_cpu_ids) {
+ if (!(req & KVM_REQUEST_WAIT)) {
+ if (!cpu_active(cpu))
+ return;
smp_send_reschedule(cpu);
+ }
__cpumask_set_cpu(cpu, tmp);
}
}
With a four-vCPU VFIO guest, three ENIC VF driver reloads passed
bidirectional traffic. During the same run, 20 CPU offline/online cycles completed. The
trace recorded 16 non-waiting KVM requests and 11 reschedule IPIs from
kvm_make_vcpu_request(), all on the VFIO IRQ-bypass registration path.
The traced IPIs did not target the CPU being offlined. There was no new
host warning. On a second Intel system, five irqfd_test/irq_test cycles
and ten CPU offline/online cycles passed, although its trace only saw
waiting requests.
I also tried to force two CPU-down orderings with a separate test-only
kvm.ko. It started offlining the target CPU from kernel work while the
non-waiting request was held (1) before cpu_active() and (2) after an
active result but before smp_send_reschedule(). In both runs the target
remained active throughout a 1.2-second hold; CPU-down completed after
the request returned. There was no new warning. These runs did not
exercise the inactive-CPU branch or reproduce an offline-CPU IPI.
Source inspection suggests a reason: CPU-down's hotplug write lock uses
RCU synchronization, which can wait for a preempt-disabled KVM request
before reaching sched_cpu_deactivate(). I did not trace that wait.
CPU-down could instead reach that point before a new KVM request starts.
I have not proved that such a request still sees a vCPU requiring an IPI.
Would you consider the guard worthwhile for that ordering, or does the
vCPU mode/CPU ordering exclude the target?
Thanks,
Satish