Skip to content

Commit 574ef75

Browse files
rnavsean-jc
authored andcommitted
KVM: SVM: Limit AVIC physical max index based on configured max_vcpu_ids
KVM allows VMMs to specify the maximum possible APIC ID for a virtual machine through KVM_CAP_MAX_VCPU_ID capability so as to limit data structures related to APIC/x2APIC. Utilize the same to set the AVIC physical max index in the VMCB, similar to VMX. This helps hardware limit the number of entries to be scanned in the physical APIC ID table speeding up IPI broadcasts for virtual machines with smaller number of vCPUs. Unlike VMX, SVM AVIC requires a single page to be allocated for the Physical APIC ID table and the Logical APIC ID table, so retain the existing approach of allocating those during VM init. Signed-off-by: Naveen N Rao (AMD) <naveen@kernel.org> Link: https://lore.kernel.org/r/adb07ccdb3394cd79cb372ba6bcc69a4e4d4ef54.1757009416.git.naveen@kernel.org Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent c53c632 commit 574ef75

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

arch/x86/kvm/svm/avic.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ static void avic_set_x2apic_msr_interception(struct vcpu_svm *svm,
161161
static void avic_activate_vmcb(struct vcpu_svm *svm)
162162
{
163163
struct vmcb *vmcb = svm->vmcb01.ptr;
164+
struct kvm *kvm = svm->vcpu.kvm;
164165

165166
vmcb->control.int_ctl &= ~(AVIC_ENABLE_MASK | X2APIC_MODE_MASK);
166167
vmcb->control.avic_physical_id &= ~AVIC_PHYSICAL_MAX_INDEX_MASK;
@@ -176,7 +177,8 @@ static void avic_activate_vmcb(struct vcpu_svm *svm)
176177
*/
177178
if (x2avic_enabled && apic_x2apic_mode(svm->vcpu.arch.apic)) {
178179
vmcb->control.int_ctl |= X2APIC_MODE_MASK;
179-
vmcb->control.avic_physical_id |= X2AVIC_MAX_PHYSICAL_ID;
180+
vmcb->control.avic_physical_id |= min(kvm->arch.max_vcpu_ids - 1,
181+
X2AVIC_MAX_PHYSICAL_ID);
180182
/* Disabling MSR intercept for x2APIC registers */
181183
avic_set_x2apic_msr_interception(svm, false);
182184
} else {
@@ -187,7 +189,8 @@ static void avic_activate_vmcb(struct vcpu_svm *svm)
187189
kvm_make_request(KVM_REQ_TLB_FLUSH_CURRENT, &svm->vcpu);
188190

189191
/* For xAVIC and hybrid-xAVIC modes */
190-
vmcb->control.avic_physical_id |= AVIC_MAX_PHYSICAL_ID;
192+
vmcb->control.avic_physical_id |= min(kvm->arch.max_vcpu_ids - 1,
193+
AVIC_MAX_PHYSICAL_ID);
191194
/* Enabling MSR intercept for x2APIC registers */
192195
avic_set_x2apic_msr_interception(svm, true);
193196
}

0 commit comments

Comments
 (0)