]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: SVM: Drop vcpu_svm's pointless avic_backing_page field
authorSean Christopherson <seanjc@google.com>
Wed, 11 Jun 2025 22:45:14 +0000 (15:45 -0700)
committerSean Christopherson <seanjc@google.com>
Fri, 20 Jun 2025 20:52:58 +0000 (13:52 -0700)
Drop vcpu_svm's avic_backing_page pointer and instead grab the physical
address of KVM's vAPIC page directly from the source.  Getting a physical
address from a kernel virtual address is not an expensive operation, and
getting the physical address from a struct page is *more* expensive for
CONFIG_SPARSEMEM=y kernels.  Regardless, none of the paths that consume
the address are hot paths, i.e. shaving cycles is not a priority.

Eliminating the "cache" means KVM doesn't have to worry about the cache
being invalid, which will simplify a future fix when dealing with vCPU IDs
that are too big.

WARN if KVM attempts to allocate a vCPU's AVIC backing page without an
in-kernel local APIC.  avic_init_vcpu() bails early if the APIC is not
in-kernel, and KVM disallows enabling an in-kernel APIC after vCPUs have
been created, i.e. it should be impossible to reach
avic_init_backing_page() without the vAPIC being allocated.

Tested-by: Sairaj Kodilkar <sarunkod@amd.com>
Reviewed-by: Naveen N Rao (AMD) <naveen@kernel.org>
Link: https://lore.kernel.org/r/20250611224604.313496-13-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/svm/avic.c
arch/x86/kvm/svm/svm.h

index 75317c189409663d081a03fbddc7164a7d7f9f44..f0401c1e355c822bc08d96dc171e971e8cc5f660 100644 (file)
@@ -237,7 +237,7 @@ free_avic:
 
 static phys_addr_t avic_get_backing_page_address(struct vcpu_svm *svm)
 {
-       return __sme_set(page_to_phys(svm->avic_backing_page));
+       return __sme_set(__pa(svm->vcpu.arch.apic->regs));
 }
 
 void avic_init_vmcb(struct vcpu_svm *svm, struct vmcb *vmcb)
@@ -282,7 +282,7 @@ static int avic_init_backing_page(struct kvm_vcpu *vcpu)
            (id > X2AVIC_MAX_PHYSICAL_ID))
                return -EINVAL;
 
-       if (!vcpu->arch.apic->regs)
+       if (WARN_ON_ONCE(!vcpu->arch.apic->regs))
                return -EINVAL;
 
        if (kvm_apicv_activated(vcpu->kvm)) {
@@ -299,8 +299,6 @@ static int avic_init_backing_page(struct kvm_vcpu *vcpu)
                        return ret;
        }
 
-       svm->avic_backing_page = virt_to_page(vcpu->arch.apic->regs);
-
        /* Setting AVIC backing page address in the phy APIC ID table */
        entry = avic_get_physical_id_entry(vcpu, id);
        if (!entry)
index cc27877d69ae10d6154a1b75e5e1a8bb6961d6a6..1585288200f4db0600be4cbb3f1d01e7400a7acb 100644 (file)
@@ -306,7 +306,6 @@ struct vcpu_svm {
 
        u32 ldr_reg;
        u32 dfr_reg;
-       struct page *avic_backing_page;
        u64 *avic_physical_id_cache;
 
        /*