[PATCH v2 2/3] KVM: SVM: Use "is AVIC-addressable" helper to sanity check load()/put()

From: Sean Christopherson

Date: Wed Sep 23 2026 - 13:57:23 EST


Use avic_is_addressable_vcpu() instead of open coding a check on the bounds
of the allocated table for the sanity checks when loading/putting AVIC
state for a vCPU. If KVM botches the allocation, then KVM will already
have performed an OOB write in avic_init_backing_page(), i.e. being super
paranoid in load()/put() doesn't provide meaningful protection in practice.

Cc: Naveen N Rao (AMD) <naveen@xxxxxxxxxx>
Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
arch/x86/kvm/svm/avic.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
index 0e4b5eb6ac82..4173a30dfe60 100644
--- a/arch/x86/kvm/svm/avic.c
+++ b/arch/x86/kvm/svm/avic.c
@@ -1049,8 +1049,7 @@ static void __avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu,
if (WARN_ON(h_physical_id & ~AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK))
return;

- if (WARN_ON_ONCE(vcpu->vcpu_id * sizeof(entry) >=
- PAGE_SIZE << avic_get_physical_id_table_order(vcpu->kvm)))
+ if (WARN_ON_ONCE(!avic_is_addressable_vcpu(vcpu)))
return;

/*
@@ -1112,8 +1111,7 @@ static void __avic_vcpu_put(struct kvm_vcpu *vcpu, enum avic_vcpu_action action)

lockdep_assert_preemption_disabled();

- if (WARN_ON_ONCE(vcpu->vcpu_id * sizeof(entry) >=
- PAGE_SIZE << avic_get_physical_id_table_order(vcpu->kvm)))
+ if (WARN_ON_ONCE(!avic_is_addressable_vcpu(vcpu)))
return;

/*
--
2.55.0.1082.g2b9226bbc0-goog