FAILED: patch "[PATCH] KVM: x86/xen: Take kvm->srcu in __kvm_xen_has_interrupt()" failed to apply to 6.1-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x aa8ad943f242ef14d136c5440b1178de77466c9e
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026110400-cinch-argue-06fe@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From aa8ad943f242ef14d136c5440b1178de77466c9e Mon Sep 17 00:00:00 2001
From: David Woodhouse <[email protected]>
Date: Mon, 31 Aug 2026 22:26:41 +0100
Subject: [PATCH] KVM: x86/xen: Take kvm->srcu in __kvm_xen_has_interrupt()
kvm_gpc_check() checks the cached memslot generation against the current one, which dereferences kvm->memslots and therefore requires kvm->srcu to be held. __kvm_xen_has_interrupt() does not take it.
Most callers do happen to hold kvm->srcu, but not all of them:
- kvm_emulate_halt() on the VM-Exit path, via kvm_vcpu_has_events() and kvm_cpu_has_extint(). vcpu_enter_guest() drops the vCPU's SRCU lock before entering the guest, so it is not held on the way back out.
- kvm_vcpu_block() -> kvm_vcpu_check_block() -> kvm_arch_vcpu_runnable(), which is the case the existing comment in this function describes.
On a PROVE_RCU kernel the former produces:
WARNING: suspicious RCU usage
include/linux/kvm_host.h:1092 suspicious rcu_dereference_check() usage!
...
kvm_gpc_check+0x344/0x3e0 [kvm] __kvm_xen_has_interrupt+0x83/0x310 [kvm] kvm_cpu_has_extint+0x1ff/0x370 [kvm] kvm_cpu_has_interrupt+0x16/0x100 [kvm] kvm_vcpu_has_events+0x4ce/0x690 [kvm] kvm_emulate_halt+0x52/0x1f0 [kvm] vmx_vcpu_run+0x988/0x2630 [kvm_intel]
Use guard(srcu) so that the three existing early returns don't each need an explicit unlock. SRCU read sections nest, so this is harmless on the paths which already hold it, and srcu_read_lock() does not sleep, so it is also safe in the atomic case which this function already handles.
arch/x86/kvm/xen.c +10 -0
@@ -732,6 +732,16 @@ int __kvm_xen_has_interrupt(struct kvm_vcpu *v)BUILD_BUG_ON (sizeof (rc) != sizeof_field(struct compat_vcpu_info, evtchn_upcall_pending)); +/* +* kvm_gpc_check() checks the memslot generation, so kvm->srcu must be +* held. Most callers hold it already, but this is also reached from +* kvm_emulate_halt() on the VM-Exit path and from kvm_vcpu_block(), +* where vcpu_enter_guest() has already dropped the vCPU's SRCU lock. +* Taking SRCU does not sleep, so it is safe even in the atomic case +* which is handled below. +*/ +guard (srcu)(&v->kvm->srcu); +read_lock_irqsave (&gpc->lock, flags);while (!kvm_gpc_check (gpc,sizeof (struct vcpu_info ))) {read_unlock_irqrestore (&gpc->lock, flags);
Sasha Levin
maintainerPATCH 1/1 KVM: x86/xen: Take kvm->srcu in __kvm_xen_has_interrupt()
From: David Woodhouse <[email protected]>
[ Upstream commit aa8ad943f242ef14d136c5440b1178de77466c9e ]
kvm_gpc_check() checks the cached memslot generation against the current one, which dereferences kvm->memslots and therefore requires kvm->srcu to be held. __kvm_xen_has_interrupt() does not take it.
Most callers do happen to hold kvm->srcu, but not all of them:
- kvm_emulate_halt() on the VM-Exit path, via kvm_vcpu_has_events() and kvm_cpu_has_extint(). vcpu_enter_guest() drops the vCPU's SRCU lock before entering the guest, so it is not held on the way back out.
- kvm_vcpu_block() -> kvm_vcpu_check_block() -> kvm_arch_vcpu_runnable(), which is the case the existing comment in this function describes.
On a PROVE_RCU kernel the former produces:
WARNING: suspicious RCU usage
include/linux/kvm_host.h:1092 suspicious rcu_dereference_check() usage!
...
kvm_gpc_check+0x344/0x3e0 [kvm] __kvm_xen_has_interrupt+0x83/0x310 [kvm] kvm_cpu_has_extint+0x1ff/0x370 [kvm] kvm_cpu_has_interrupt+0x16/0x100 [kvm] kvm_vcpu_has_events+0x4ce/0x690 [kvm] kvm_emulate_halt+0x52/0x1f0 [kvm] vmx_vcpu_run+0x988/0x2630 [kvm_intel]
Use guard(srcu) so that the three existing early returns don't each need an explicit unlock. SRCU read sections nest, so this is harmless on the paths which already hold it, and srcu_read_lock() does not sleep, so it is also safe in the atomic case which this function already handles.
--- arch/x86/kvm/xen.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/x86/kvm/xen.c +10 -0
@@ -416,6 +416,16 @@ int __kvm_xen_has_interrupt(struct kvm_vcpu *v)BUILD_BUG_ON (sizeof (rc) != sizeof_field(struct compat_vcpu_info, evtchn_upcall_pending)); +/* +* kvm_gpc_check() checks the memslot generation, so kvm->srcu must be +* held. Most callers hold it already, but this is also reached from +* kvm_emulate_halt() on the VM-Exit path and from kvm_vcpu_block(), +* where vcpu_enter_guest() has already dropped the vCPU's SRCU lock. +* Taking SRCU does not sleep, so it is safe even in the atomic case +* which is handled below. +*/ +guard (srcu)(&v->kvm->srcu); +read_lock_irqsave (&gpc->lock, flags);while (!kvm_gfn_to_pfn_cache_check (v->kvm, gpc, gpc->gpa,sizeof (struct vcpu_info ))) {
Signature · 1 line
2.53.0