Skip to content

Commit b41f863

Browse files
committed
KVM: VMX: Isolate pure loads from atomic XCHG when processing PIR
Rework KVM's processing of the PIR to use the same algorithm as posted MSIs, i.e. to do READ(x4) => XCHG(x4) instead of (READ+XCHG)(x4). Given KVM's long-standing, sub-optimal use of 32-bit accesses to the PIR, it's safe to say far more thought and investigation was put into handling the PIR for posted MSIs, i.e. there's no reason to assume KVM's existing logic is meaningful, let alone superior. Matching the processing done by posted MSIs will also allow deduplicating the code between KVM and posted MSIs. See the comment for handle_pending_pir() added by commit 1b03d82 ("x86/irq: Install posted MSI notification handler") for details on why isolating loads from XCHG is desirable. Suggested-by: Jim Mattson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 06b4d0e commit b41f863

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

arch/x86/kvm/lapic.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ static u8 count_vectors(void *bitmap)
657657

658658
bool __kvm_apic_update_irr(unsigned long *pir, void *regs, int *max_irr)
659659
{
660-
unsigned long pir_vals[NR_PIR_WORDS];
660+
unsigned long pir_vals[NR_PIR_WORDS], pending = 0;
661661
u32 *__pir = (void *)pir_vals;
662662
u32 i, vec;
663663
u32 irr_val, prev_irr_val;
@@ -668,6 +668,13 @@ bool __kvm_apic_update_irr(unsigned long *pir, void *regs, int *max_irr)
668668

669669
for (i = 0; i < NR_PIR_WORDS; i++) {
670670
pir_vals[i] = READ_ONCE(pir[i]);
671+
pending |= pir_vals[i];
672+
}
673+
674+
if (!pending)
675+
return false;
676+
677+
for (i = 0; i < NR_PIR_WORDS; i++) {
671678
if (!pir_vals[i])
672679
continue;
673680

0 commit comments

Comments
 (0)