From: Satish Kharat <satishkh@cisco.com>
To: seanjc@google.com
Cc: pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: Send reschedule IPIs instead of SMP function calls for non-waiting requests
Date: Wed, 18 Nov 2026 21:14:07 -0800 [thread overview]
Message-ID: <20261119051407.886480-1-satishkh@cisco.com> (raw)
In-Reply-To: <av5Crz-e2PaTNAjK@seanjc-mac.roam.internal>
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
prev parent reply other threads:[~2026-11-19 5:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 20:54 Sean Christopherson
2026-11-18 21:11 ` Satish Kharat
2026-11-19 0:28 ` Sean Christopherson
2026-11-19 5:14 ` Satish Kharat [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119051407.886480-1-satishkh@cisco.com \
--to=satishkh@cisco.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®