From: sashiko-bot@kernel.org
To: "Sean Christopherson" <seanjc@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: Send reschedule IPIs instead of SMP function calls for non-waiting requests
Date: Tue, 17 Nov 2026 21:18:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-219682@kernel.org> (raw)
In-Reply-To: <20261117205428.3717-1-seanjc@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] KVM: per-CPU cpu_kick_mask corruption in
kvm_make_all_cpus_request()
- [High] KVM: s390 build failure in kvm_make_vcpu_request() with
CONFIG_KVM=m
--
commit 38c2c2306d98411374ab3430ab319733689457e7
Author: Sean Christopherson <seanjc@google.com>
KVM: Send reschedule IPIs instead of SMP function calls for non-waiting requests
This commit sends a reschedule IPI to each target vCPU instead of batching
IPIs via smp_call_function_many() when making non-waiting multi-vCPU
requests, allowing non-waiting requests to be made with interrupts disabled.
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index cf4cb586f1407..0b733746884ce 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
[ ... ]
> @@ -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);
[Severity: High]
Does calling smp_send_reschedule() here break the build on s390 when
CONFIG_KVM=m?
On s390, smp_send_reschedule() expands to arch_smp_send_reschedule(),
which is not exported to modules. __kvm_vcpu_kick() is guarded by
#ifndef CONFIG_S390 for that reason (see 0266c894b51c ("KVM: put back
#ifndef CONFIG_S390 around kvm_vcpu_kick")), whereas
kvm_make_vcpu_request() is built into kvm.ko on s390.
> __cpumask_set_cpu(cpu, tmp);
> + }
> }
> }
[Severity: High]
Can a non-waiting request in interrupt context clobber the per-CPU
cpu_kick_mask of an in-progress waiting request on the same CPU?
kvm_make_all_cpus_request() and kvm_make_vcpus_request_mask() only disable
preemption via get_cpu() while building cpu_kick_mask, leaving interrupts
enabled for waiting requests, and still clear and populate cpu_kick_mask
even when KVM_REQUEST_WAIT is not set:
virt/kvm/kvm_main.c:kvm_make_all_cpus_request() {
me = get_cpu();
cpus = this_cpu_cpumask_var_ptr(cpu_kick_mask);
cpumask_clear(cpus);
kvm_for_each_vcpu(i, vcpu, kvm)
kvm_make_vcpu_request(vcpu, req, cpus, me);
called = kvm_kick_many_cpus(cpus, !!(req & KVM_REQUEST_WAIT));
put_cpu();
...
}
If an interrupt fires mid-loop and makes a non-waiting multi-vCPU request
(for example on arm64 via irqfd_wakeup() -> kvm_arch_set_irq_inatomic() ->
... -> vgic_queue_irq_unlock()):
kvm_flush_remote_tlbs()
kvm_make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH)
cpumask_clear(cpus)
kvm_make_vcpu_request(vcpu0, ...)
kvm_vcpu_exiting_guest_mode(vcpu0)
cmpxchg(&vcpu0->mode, IN_GUEST_MODE, EXITING_GUEST_MODE)
__cpumask_set_cpu(vcpu0->cpu, cpus)
<hardirq>
irqfd_wakeup()
...
kvm_make_all_cpus_request(kvm, KVM_REQ_IRQ_PENDING)
cpumask_clear(cpus) <-- wipes vcpu0->cpu from cpu_kick_mask
kvm_make_vcpu_request(vcpu0, ...)
kvm_request_needs_ipi(vcpu0, ...) <-- false (EXITING_GUEST_MODE)
kvm_kick_many_cpus(cpus, true) <-- misses vcpu0->cpu
Because the outer request already transitioned vcpu0->mode from
IN_GUEST_MODE to EXITING_GUEST_MODE, the nested non-waiting request sees
mode != IN_GUEST_MODE and neither sends a reschedule IPI nor re-adds
vcpu0->cpu to cpu_kick_mask. When the interrupt returns,
kvm_kick_many_cpus() skips kicking and waiting for vcpu0, so the waiting
request (such as a remote TLB flush) can complete while vcpu0 is still in
guest mode or reading shadow page tables.
Only touching cpu_kick_mask when KVM_REQUEST_WAIT is set (and tracking
whether any CPU was kicked with a local boolean for the return value)
would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117205428.3717-1-seanjc@google.com?part=1
next prev parent reply other threads:[~2026-11-17 21:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 20:54 [PATCH] KVM: Send reschedule IPIs instead of SMP function calls for non-waiting requests Sean Christopherson
2026-11-17 21:18 ` sashiko-bot [this message]
2026-11-17 23:50 ` Sean Christopherson
2026-11-18 0:03 ` Oliver Upton
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=sashiko-outbox-219682@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.