Skip to content

Commit c9bcd3e

Browse files
ssuthiku-amdbonzini
authored andcommitted
kvm: svm/avic: fix off-by-one in checking host APIC ID
Current logic does not allow VCPU to be loaded onto CPU with APIC ID 255. This should be allowed since the host physical APIC ID field in the AVIC Physical APIC table entry is an 8-bit value, and APIC ID 255 is valid in system with x2APIC enabled. Instead, do not allow VCPU load if the host APIC ID cannot be represented by an 8-bit value. Also, use the more appropriate AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK instead of AVIC_MAX_PHYSICAL_ID_COUNT. Signed-off-by: Suravee Suthikulpanit <[email protected]> Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 204c91e commit c9bcd3e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

arch/x86/kvm/svm.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2024,7 +2024,11 @@ static void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20242024
if (!kvm_vcpu_apicv_active(vcpu))
20252025
return;
20262026

2027-
if (WARN_ON(h_physical_id >= AVIC_MAX_PHYSICAL_ID_COUNT))
2027+
/*
2028+
* Since the host physical APIC id is 8 bits,
2029+
* we can support host APIC ID upto 255.
2030+
*/
2031+
if (WARN_ON(h_physical_id > AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK))
20282032
return;
20292033

20302034
entry = READ_ONCE(*(svm->avic_physical_id_cache));

0 commit comments

Comments
 (0)