Skip to content

Commit 3718799

Browse files
committed
KVM: x86: Drop guest/user-triggerable asserts on IRR/ISR vectors
Remove the ASSERT()s in apic_find_highest_i{r,s}r() that exist to detect illegal vectors (0-15 are reserved and never recognized by the local APIC), as the asserts, if they were ever to be enabled by #defining DEBUG, can be trivially triggered from both the guest and from userspace, and ultimately because the ASSERT()s are useless. In large part due to lack of emulation for the Error Status Register and its "delayed" read semantics, KVM doesn't filter out bad IRQs (IPIs or otherwise) when IRQs are sent or received. Instead, probably by dumb luck on KVM's part, KVM effectively ignores pending illegal vectors in the IRR due vector 0-15 having priority '0', and thus never being higher priority than PPR. As for ISR, a misbehaving userspace could stuff illegal vector bits, but again the end result is mostly benign (aside from userspace likely breaking the VM), as processing illegal vectors "works" and doesn't cause functional problems. Regardless of the safety and correctness of KVM's illegal vector handling, one thing is for certain: the ASSERT()s have done absolutely nothing to help detect such issues since they were added 18+ years ago by commit 97222cc ("KVM: Emulate local APIC in kernel"). For all intents and purposes, no functional change intended. Link: https://patch.msgid.link/20251206004311.479939-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent a497832 commit 3718799

1 file changed

Lines changed: 2 additions & 12 deletions

File tree

arch/x86/kvm/lapic.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -666,19 +666,14 @@ static inline int apic_search_irr(struct kvm_lapic *apic)
666666

667667
static inline int apic_find_highest_irr(struct kvm_lapic *apic)
668668
{
669-
int result;
670-
671669
/*
672670
* Note that irr_pending is just a hint. It will be always
673671
* true with virtual interrupt delivery enabled.
674672
*/
675673
if (!apic->irr_pending)
676674
return -1;
677675

678-
result = apic_search_irr(apic);
679-
ASSERT(result == -1 || result >= 16);
680-
681-
return result;
676+
return apic_search_irr(apic);
682677
}
683678

684679
static inline void apic_clear_irr(int vec, struct kvm_lapic *apic)
@@ -731,8 +726,6 @@ static inline void apic_set_isr(int vec, struct kvm_lapic *apic)
731726

732727
static inline int apic_find_highest_isr(struct kvm_lapic *apic)
733728
{
734-
int result;
735-
736729
/*
737730
* Note that isr_count is always 1, and highest_isr_cache
738731
* is always -1, with APIC virtualization enabled.
@@ -742,10 +735,7 @@ static inline int apic_find_highest_isr(struct kvm_lapic *apic)
742735
if (likely(apic->highest_isr_cache != -1))
743736
return apic->highest_isr_cache;
744737

745-
result = apic_find_highest_vector(apic->regs + APIC_ISR);
746-
ASSERT(result == -1 || result >= 16);
747-
748-
return result;
738+
return apic_find_highest_vector(apic->regs + APIC_ISR);
749739
}
750740

751741
static inline void apic_clear_isr(int vec, struct kvm_lapic *apic)

0 commit comments

Comments
 (0)