From: sashiko-bot@kernel.org
To: "Dickson Wu" <dickson.wu@certik.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 5.10.y] KVM: x86: Acquire kvm->srcu when handling KVM_SET_VCPU_EVENTS
Date: Thu, 26 Nov 2026 02:57:32 +0000 [thread overview]
Message-ID: <sashiko-outbox-234666@kernel.org> (raw)
In-Reply-To: <CAFaZ9eoOtFxAansjaUbA-CDNQLcVAVJre2R9vaTQONG9MYUEng@mail.gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] KVM: x86: sync_regs() calls
kvm_vcpu_ioctl_x86_set_vcpu_events() without SRCU
- [Low] KVM: x86: malformed line-wrapped Fixes trailer in commit message
--
commit 05ed0e79c4f4c1c55cedf5e0e31a01d98645e969
Author: Sean Christopherson <seanjc@google.com>
> KVM: x86: Acquire kvm->srcu when handling KVM_SET_VCPU_EVENTS
>
> commit 4bcdd831d9d01e0fb64faea50732b59b2ee88da1 upstream.
>
> Grab kvm->srcu when processing KVM_SET_VCPU_EVENTS, as KVM will forcibly
> leave nested VMX/SVM if SMM mode is being toggled, and leaving nested VMX
> reads guest memory.
>
> Note, kvm_vcpu_ioctl_x86_set_vcpu_events() can also be called from KVM_RUN
> via sync_regs(), which already holds SRCU. I.e. trying to precisely use
> kvm_vcpu_srcu_read_lock() around the problematic SMM code would cause
> problems. Acquiring SRCU isn't all that expensive, so for simplicity,
> grab it unconditionally for KVM_SET_VCPU_EVENTS.
>
> =============================
> WARNING: suspicious RCU usage
> 6.10.0-rc7-332d2c1d713e-next-vm #552 Not tainted
> -----------------------------
> include/linux/kvm_host.h:1027 suspicious rcu_dereference_check() usage!
>
> other info that might help us debug this:
>
> rcu_scheduler_active = 2, debug_locks = 1
> 1 lock held by repro/1071:
> #0: ffff88811e424430 (&vcpu->mutex){+.+.}-{3:3}, at:
> kvm_vcpu_ioctl+0x7d/0x970 [kvm]
>
> stack backtrace:
> CPU: 15 PID: 1071 Comm: repro Not tainted 6.10.0-rc7-332d2c1d713e-next-vm #552
> Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015
> Call Trace:
> <TASK>
> dump_stack_lvl+0x7f/0x90
> lockdep_rcu_suspicious+0x13f/0x1a0
> kvm_vcpu_gfn_to_memslot+0x168/0x190 [kvm]
> kvm_vcpu_read_guest+0x3e/0x90 [kvm]
> nested_vmx_load_msr+0x6b/0x1d0 [kvm_intel]
> load_vmcs12_host_state+0x432/0xb40 [kvm_intel]
> vmx_leave_nested+0x30/0x40 [kvm_intel]
> kvm_vcpu_ioctl_x86_set_vcpu_events+0x15d/0x2b0 [kvm]
> kvm_arch_vcpu_ioctl+0x1107/0x1750 [kvm]
> ? mark_held_locks+0x49/0x70
> ? kvm_vcpu_ioctl+0x7d/0x970 [kvm]
> ? kvm_vcpu_ioctl+0x497/0x970 [kvm]
> kvm_vcpu_ioctl+0x497/0x970 [kvm]
> ? lock_acquire+0xba/0x2d0
> ? find_held_lock+0x2b/0x80
> ? do_user_addr_fault+0x40c/0x6f0
> ? lock_release+0xb7/0x270
> __x64_sys_ioctl+0x82/0xb0
> do_syscall_64+0x6c/0x170
> entry_SYSCALL_64_after_hwframe+0x4b/0x53
> RIP: 0033:0x7ff11eb1b539
> </TASK>
>
> Fixes: f7e570780efc ("KVM: x86: Forcibly leave nested virt when SMM
> state is toggled")
> Cc: stable@vger.kernel.org
> Link: https://lore.kernel.org/r/20240723232055.3643811-1-seanjc@google.com
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> [ adapted to 5.10: same as the 5.15.y backport, vcpu->srcu_idx since
> kvm_vcpu_srcu_read_lock() is missing ]
> Signed-off-by: Dickson Wu <dickson.wu@certik.com>
[Severity: Low]
The Fixes: trailer is wrapped across two lines. Should it be kept on a
single line?
Fixes: f7e570780efc ("KVM: x86: Forcibly leave nested virt when SMM state is toggled")
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 58660d5de1413..d44c974756258 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -4970,7 +4970,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
> if (copy_from_user(&events, argp, sizeof(struct kvm_vcpu_events)))
> break;
>
> + vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
> r = kvm_vcpu_ioctl_x86_set_vcpu_events(vcpu, &events);
> + srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
> break;
> }
> case KVM_GET_DEBUGREGS: {
[Severity: Medium]
Does taking vcpu->kvm->srcu only in KVM_SET_VCPU_EVENTS leave the
KVM_RUN -> sync_regs() path without SRCU protection in 5.10?
In mainline, kvm_arch_vcpu_ioctl_run() already holds vcpu->kvm->srcu when
calling sync_regs(), which is why upstream 4bcdd831d9d0 ("KVM: x86:
Acquire kvm->srcu when handling KVM_SET_VCPU_EVENTS") only locked around
the KVM_SET_VCPU_EVENTS ioctl handler. In 5.10, kvm_arch_vcpu_ioctl_run()
calls sync_regs() before vcpu_run() or complete_emulated_io() acquires
vcpu->kvm->srcu:
arch/x86/kvm/x86.c:sync_regs() {
...
if (vcpu->run->kvm_dirty_regs & KVM_SYNC_X86_EVENTS) {
if (kvm_vcpu_ioctl_x86_set_vcpu_events(
vcpu, &vcpu->run->s.regs.events))
return -EINVAL;
vcpu->run->kvm_dirty_regs &= ~KVM_SYNC_X86_EVENTS;
}
...
}
If userspace invokes KVM_RUN with KVM_SYNC_X86_EVENTS set in
kvm_dirty_regs and toggles SMM while the vCPU is in nested VMX guest mode,
kvm_vcpu_ioctl_x86_set_vcpu_events() -> vmx_leave_nested() ->
kvm_vcpu_read_guest() -> kvm_vcpu_gfn_to_memslot() dereferences memslots
without holding vcpu->kvm->srcu, triggering the same suspicious RCU usage
warning and risking a use-after-free against concurrent memslot updates.
Acquiring vcpu->kvm->srcu inside kvm_vcpu_ioctl_x86_set_vcpu_events() (as
__set_sregs() does in 5.10) or around the call in sync_regs() would cover
both callers.
--
Sashiko AI review · https://sashiko.dev/#/patchset/CAFaZ9eoOtFxAansjaUbA-CDNQLcVAVJre2R9vaTQONG9MYUEng@mail.gmail.com?part=1
prev parent reply other threads:[~2026-11-26 2:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 2:45 [PATCH 5.10.y] KVM: x86: Acquire kvm->srcu when handling KVM_SET_VCPU_EVENTS Dickson Wu
2026-11-26 2:57 ` sashiko-bot [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=sashiko-outbox-234666@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dickson.wu@certik.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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