Re: [PATCH 01/62] kvm: Make pi_enable_wakeup_handler() easier to analyze
From: Sean Christopherson
Date: Tue Feb 24 2026 - 13:22:30 EST
For the scope, please use:
KVM: VMX:
On Mon, Feb 23, 2026, Bart Van Assche wrote:
> The Clang thread-safety analyzer does not support comparing expressions
> that use per_cpu(). Hence introduce a new local variable to capture the
> address of a per-cpu spinlock. This patch prepares for enabling the
> Clang thread-safety analyzer.
>
> Cc: Sean Christopherson <seanjc@xxxxxxxxxx>
> Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx>
> Cc: kvm@xxxxxxxxxxxxxxx
> Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
> ---
> arch/x86/kvm/vmx/posted_intr.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c
> index 4a6d9a17da23..f8711b7b85a8 100644
> --- a/arch/x86/kvm/vmx/posted_intr.c
> +++ b/arch/x86/kvm/vmx/posted_intr.c
> @@ -164,6 +164,7 @@ static void pi_enable_wakeup_handler(struct kvm_vcpu *vcpu)
> struct pi_desc *pi_desc = vcpu_to_pi_desc(vcpu);
> struct vcpu_vt *vt = to_vt(vcpu);
> struct pi_desc old, new;
> + raw_spinlock_t *wakeup_lock;
>
> lockdep_assert_irqs_disabled();
>
> @@ -179,11 +180,11 @@ static void pi_enable_wakeup_handler(struct kvm_vcpu *vcpu)
> * entirety of the sched_out critical section, i.e. the wakeup handler
> * can't run while the scheduler locks are held.
> */
> - raw_spin_lock_nested(&per_cpu(wakeup_vcpus_on_cpu_lock, vcpu->cpu),
> - PI_LOCK_SCHED_OUT);
> + wakeup_lock = &per_cpu(wakeup_vcpus_on_cpu_lock, vcpu->cpu);
Addressing this piecemeal doesn't seem maintainable in the long term. The odds
of unintentionally regressing the coverage with a cleanup are rather high. Or
we'll end up with confused and/or grumpy developers because they're required to
write code in a very specific way because of what are effectively shortcomings
in the compiler.
> + raw_spin_lock_nested(wakeup_lock, PI_LOCK_SCHED_OUT);
> list_add_tail(&vt->pi_wakeup_list,
> &per_cpu(wakeup_vcpus_on_cpu, vcpu->cpu));
> - raw_spin_unlock(&per_cpu(wakeup_vcpus_on_cpu_lock, vcpu->cpu));
> + raw_spin_unlock(wakeup_lock);
>
> WARN(pi_test_sn(pi_desc), "PI descriptor SN field set before blocking");
>