Re: [PATCH v3 13/62] KVM: SVM: Drop redundant check in AVIC code on ID during vCPU creation

Naveen N Rao
2025-06-17T14:50:20Z

On Wed, Jun 11, 2025 at 03:45:16PM -0700, Sean Christopherson wrote:
> static int avic_init_backing_page(struct kvm_vcpu *vcpu)
> {
> - u64 *entry, new_entry;
> - int id = vcpu->vcpu_id;
> + struct kvm_svm *kvm_svm = to_kvm_svm(vcpu->kvm);
> struct vcpu_svm *svm = to_svm(vcpu);
> + u32 id = vcpu->vcpu_id;
> + u64 *table, new_entry;
>
> /*
> * Inhibit AVIC if the vCPU ID is bigger than what is supported by AVIC
> @@ -291,6 +277,9 @@ static int avic_init_backing_page(struct kvm_vcpu *vcpu)
> return 0;
> }
>
> + BUILD_BUG_ON((AVIC_MAX_PHYSICAL_ID + 1) * sizeof(*table) > PAGE_SIZE ||
> + (X2AVIC_MAX_PHYSICAL_ID + 1) * sizeof(*table) > PAGE_SIZE);
^^^^^^^^^^^^^^
Renaming new_entry to just 'entry' and using sizeof(entry) makes this
more readable for me. Otherwise, for this patch:
Reviewed-by: Naveen N Rao (AMD) <naveen@kernel.org>

As an aside, there are a few static asserts to validate some of the
related macros. Can this also be a static_assert(), or is there is
reason to prefer BUILD_BUG_ON()?

- Naveen