KVM: SVM: Take and hold ir_list_lock when updating vCPU's Physical ID entry
authorSean Christopherson <seanjc@google.com>
Tue, 8 Aug 2023 23:31:31 +0000 (16:31 -0700)
committerSean Christopherson <seanjc@google.com>
Thu, 17 Aug 2023 18:31:37 +0000 (11:31 -0700)
commit4c08e737f056fec930b416a2bd37ed266d724f95
tree8ab5a24ad447e097c18c69b86c01b00b38518a97
parenta85cd52d720588b0060a0ebac5c7f497ad6bcd86
KVM: SVM: Take and hold ir_list_lock when updating vCPU's Physical ID entry

Hoist the acquisition of ir_list_lock from avic_update_iommu_vcpu_affinity()
to its two callers, avic_vcpu_load() and avic_vcpu_put(), specifically to
encapsulate the write to the vCPU's entry in the AVIC Physical ID table.
This will allow a future fix to pull information from the Physical ID entry
when updating the IRTE, without potentially consuming stale information,
i.e. without racing with the vCPU being (un)loaded.

Add a comment to call out that ir_list_lock does NOT protect against
multiple writers, specifically that reading the Physical ID entry in
avic_vcpu_put() outside of the lock is safe.

To preserve some semblance of independence from ir_list_lock, keep the
READ_ONCE() in avic_vcpu_load() even though acuiring the spinlock
effectively ensures the load(s) will be generated after acquiring the
lock.

Cc: stable@vger.kernel.org
Tested-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
Link: https://lore.kernel.org/r/20230808233132.2499764-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/svm/avic.c