Skip to content

Commit 06b4d0e

Browse files
committed
KVM: VMX: Process PIR using 64-bit accesses on 64-bit kernels
Process the PIR at the natural kernel width, i.e. in 64-bit chunks on 64-bit kernels, so that the worst case of having a posted IRQ in each chunk of the vIRR only requires 4 loads and xchgs from/to the PIR, not 8. Deliberately use a "continue" to skip empty entries so that the code is a carbon copy of handle_pending_pir(), in anticipation of deduplicating KVM and posted MSI logic. Suggested-by: Jim Mattson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent f145931 commit 06b4d0e

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

arch/x86/kvm/lapic.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -657,26 +657,32 @@ static u8 count_vectors(void *bitmap)
657657

658658
bool __kvm_apic_update_irr(unsigned long *pir, void *regs, int *max_irr)
659659
{
660-
u32 *__pir = (void *)pir;
660+
unsigned long pir_vals[NR_PIR_WORDS];
661+
u32 *__pir = (void *)pir_vals;
661662
u32 i, vec;
662-
u32 pir_val, irr_val, prev_irr_val;
663+
u32 irr_val, prev_irr_val;
663664
int max_updated_irr;
664665

665666
max_updated_irr = -1;
666667
*max_irr = -1;
667668

669+
for (i = 0; i < NR_PIR_WORDS; i++) {
670+
pir_vals[i] = READ_ONCE(pir[i]);
671+
if (!pir_vals[i])
672+
continue;
673+
674+
pir_vals[i] = xchg(&pir[i], 0);
675+
}
676+
668677
for (i = vec = 0; i <= 7; i++, vec += 32) {
669678
u32 *p_irr = (u32 *)(regs + APIC_IRR + i * 0x10);
670679

671680
irr_val = READ_ONCE(*p_irr);
672-
pir_val = READ_ONCE(__pir[i]);
673-
674-
if (pir_val) {
675-
pir_val = xchg(&__pir[i], 0);
676681

682+
if (__pir[i]) {
677683
prev_irr_val = irr_val;
678684
do {
679-
irr_val = prev_irr_val | pir_val;
685+
irr_val = prev_irr_val | __pir[i];
680686
} while (prev_irr_val != irr_val &&
681687
!try_cmpxchg(p_irr, &prev_irr_val, irr_val));
682688

0 commit comments

Comments
 (0)