Skip to content

Commit 3989a6d

Browse files
sean-jcbonzini
authored andcommitted
KVM: SVM: Initialize AVIC VMCB fields if AVIC is enabled with in-kernel APIC
Initialize all per-vCPU AVIC control fields in the VMCB if AVIC is enabled in KVM and the VM has an in-kernel local APIC, i.e. if it's _possible_ the vCPU could activate AVIC at any point in its lifecycle. Configuring the VMCB if and only if AVIC is active "works" purely because of optimizations in kvm_create_lapic() to speculatively set apicv_active if AVIC is enabled *and* to defer updates until the first KVM_RUN. In quotes because KVM likely won't do the right thing if kvm_apicv_activated() is false, i.e. if a vCPU is created while APICv is inhibited at the VM level for whatever reason. E.g. if the inhibit is *removed* before KVM_REQ_APICV_UPDATE is handled in KVM_RUN, then __kvm_vcpu_update_apicv() will elide calls to vendor code due to seeing "apicv_active == activate". Cleaning up the initialization code will also allow fixing a bug where KVM incorrectly leaves CR8 interception enabled when AVIC is activated without creating a mess with respect to whether AVIC is activated or not. Cc: stable@vger.kernel.org Fixes: 67034bb ("KVM: SVM: Add irqchip_split() checks before enabling AVIC") Fixes: 6c3e442 ("svm: Add support for dynamic APICv") Reviewed-by: Naveen N Rao (AMD) <naveen@kernel.org> Reviewed-by: Jim Mattson <jmattson@google.com> Link: https://patch.msgid.link/20260203190711.458413-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent e2ffe85 commit 3989a6d

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

arch/x86/kvm/svm/avic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ void avic_init_vmcb(struct vcpu_svm *svm, struct vmcb *vmcb)
368368
vmcb->control.avic_physical_id = __sme_set(__pa(kvm_svm->avic_physical_id_table));
369369
vmcb->control.avic_vapic_bar = APIC_DEFAULT_PHYS_BASE;
370370

371-
if (kvm_apicv_activated(svm->vcpu.kvm))
371+
if (kvm_vcpu_apicv_active(&svm->vcpu))
372372
avic_activate_vmcb(svm);
373373
else
374374
avic_deactivate_vmcb(svm);

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ static void init_vmcb(struct kvm_vcpu *vcpu, bool init_event)
11891189
if (guest_cpu_cap_has(vcpu, X86_FEATURE_ERAPS))
11901190
svm->vmcb->control.erap_ctl |= ERAP_CONTROL_ALLOW_LARGER_RAP;
11911191

1192-
if (kvm_vcpu_apicv_active(vcpu))
1192+
if (enable_apicv && irqchip_in_kernel(vcpu->kvm))
11931193
avic_init_vmcb(svm, vmcb);
11941194

11951195
if (vnmi)

0 commit comments

Comments
 (0)