Skip to content

Commit 3ec7a1b

Browse files
sean-jcbonzini
authored andcommitted
KVM: SVM: Fix a benign off-by-one bug in AVIC physical table mask
Define the "physical table max index mask" as bits 8:0, not 9:0. x2AVIC currently supports a max of 512 entries, i.e. the max index is 511, and the inputs to GENMASK_ULL() are inclusive. The bug is benign as bit 9 is reserved and never set by KVM, i.e. KVM is just clearing bits that are guaranteed to be zero. Note, as of this writing, APM "Rev. 3.39-October 2022" incorrectly states that bits 11:8 are reserved in Table B-1. VMCB Layout, Control Area. I.e. that table wasn't updated when x2AVIC support was added. Opportunistically fix the comment for the max AVIC ID to align with the code, and clean up comment formatting too. Fixes: 4d1d794 ("KVM: SVM: Introduce logic to (de)activate x2AVIC mode") Cc: [email protected] Cc: Alejandro Jimenez <[email protected]> Cc: Suravee Suthikulpanit <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Reviewed-by: Suravee Suthikulpanit <[email protected]> Tested-by: Suravee Suthikulpanit <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 3dc40cf commit 3ec7a1b

File tree

1 file changed

+7
-5
lines changed
  • arch/x86/include/asm

1 file changed

+7
-5
lines changed

arch/x86/include/asm/svm.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,22 @@ enum avic_ipi_failure_cause {
261261
AVIC_IPI_FAILURE_INVALID_BACKING_PAGE,
262262
};
263263

264-
#define AVIC_PHYSICAL_MAX_INDEX_MASK GENMASK_ULL(9, 0)
264+
#define AVIC_PHYSICAL_MAX_INDEX_MASK GENMASK_ULL(8, 0)
265265

266266
/*
267-
* For AVIC, the max index allowed for physical APIC ID
268-
* table is 0xff (255).
267+
* For AVIC, the max index allowed for physical APIC ID table is 0xfe (254), as
268+
* 0xff is a broadcast to all CPUs, i.e. can't be targeted individually.
269269
*/
270270
#define AVIC_MAX_PHYSICAL_ID 0XFEULL
271271

272272
/*
273-
* For x2AVIC, the max index allowed for physical APIC ID
274-
* table is 0x1ff (511).
273+
* For x2AVIC, the max index allowed for physical APIC ID table is 0x1ff (511).
275274
*/
276275
#define X2AVIC_MAX_PHYSICAL_ID 0x1FFUL
277276

277+
static_assert((AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == AVIC_MAX_PHYSICAL_ID);
278+
static_assert((X2AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == X2AVIC_MAX_PHYSICAL_ID);
279+
278280
#define AVIC_HPA_MASK ~((0xFFFULL << 52) | 0xFFF)
279281
#define VMCB_AVIC_APIC_BAR_MASK 0xFFFFFFFFFF000ULL
280282

0 commit comments

Comments
 (0)