* [PATCH v2] KVM: x86: Track kvm_vcpu_arch.pending_ioapic_eoi as a u8 to drop dead BUG_ON()
@ 2026-08-06 17:14 Sean Christopherson
2026-08-06 18:31 ` Paolo Bonzini
2026-08-06 21:51 ` Huang, Kai
0 siblings, 2 replies; 3+ messages in thread
From: Sean Christopherson @ 2026-08-06 17:14 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel
Track the vector associated with KVM_EXIT_IOAPIC_EOI as a u8, as the vector
is zero-initialized and is only ever set to a legal vector. I.e. unlike
many of the other vector variables in KVM, it can't be -1 (and can't be
greater than 255, though that should hold true for all vectors in KVM).
Drop the now fully dead BUG_ON(), which aside from being completely
unnecessary, was also useless, as it wouldn't guard against a negative
value, i.e. wouldn't detect KVM's magic -1 value.
For all intents and purposes, no functional change intended.
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
v2: Use a u8 to make it impossible for the test to be out-of-bounds. [Paolo]
v1: https://lore.kernel.org/all/20260618185515.2021642-1-seanjc@google.com
arch/x86/include/asm/kvm_host.h | 2 +-
arch/x86/kvm/lapic.c | 4 ++--
arch/x86/kvm/lapic.h | 2 +-
arch/x86/kvm/vmx/vmx.c | 3 +--
arch/x86/kvm/x86.c | 1 -
5 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 283847619ff8..9614314fd237 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -973,7 +973,7 @@ struct kvm_vcpu_arch {
bool pv_unhalted;
} pv;
- int pending_ioapic_eoi;
+ u8 pending_ioapic_eoi;
int pending_external_vector;
int highest_stale_pending_ioapic_eoi;
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 586a5cee29e1..87bb8e5f4ca1 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1552,7 +1552,7 @@ static bool kvm_ioapic_handles_vector(struct kvm_lapic *apic, int vector)
return test_bit(vector, apic->vcpu->arch.ioapic_handled_vectors);
}
-static void kvm_ioapic_send_eoi(struct kvm_lapic *apic, int vector)
+static void kvm_ioapic_send_eoi(struct kvm_lapic *apic, u8 vector)
{
int __maybe_unused trigger_mode;
@@ -1622,7 +1622,7 @@ static int apic_set_eoi(struct kvm_lapic *apic)
* this interface assumes a trap-like exit, which has already finished
* desired side effect including vISR and vPPR update.
*/
-void kvm_apic_set_eoi_accelerated(struct kvm_vcpu *vcpu, int vector)
+void kvm_apic_set_eoi_accelerated(struct kvm_vcpu *vcpu, u8 vector)
{
struct kvm_lapic *apic = vcpu->arch.apic;
diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
index bd1098c89d99..db071d0b172d 100644
--- a/arch/x86/kvm/lapic.h
+++ b/arch/x86/kvm/lapic.h
@@ -177,7 +177,7 @@ u64 kvm_get_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu);
void kvm_set_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu, u64 data);
void kvm_apic_write_nodecode(struct kvm_vcpu *vcpu, u32 offset);
-void kvm_apic_set_eoi_accelerated(struct kvm_vcpu *vcpu, int vector);
+void kvm_apic_set_eoi_accelerated(struct kvm_vcpu *vcpu, u8 vector);
int kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr);
void kvm_lapic_sync_from_vapic(struct kvm_vcpu *vcpu);
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index e3bfe6aca1a0..c1fdfccd20fa 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -5886,10 +5886,9 @@ static int handle_apic_access(struct kvm_vcpu *vcpu)
static int handle_apic_eoi_induced(struct kvm_vcpu *vcpu)
{
unsigned long exit_qualification = vmx_get_exit_qual(vcpu);
- int vector = exit_qualification & 0xff;
/* EOI-induced VM exit is trap-like and thus no need to adjust IP */
- kvm_apic_set_eoi_accelerated(vcpu, vector);
+ kvm_apic_set_eoi_accelerated(vcpu, exit_qualification & 0xff);
return 1;
}
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index d94b59140c45..8b23f342a1fa 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8151,7 +8151,6 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
if (kvm_check_request(KVM_REQ_NMI, vcpu))
process_nmi(vcpu);
if (kvm_check_request(KVM_REQ_IOAPIC_EOI_EXIT, vcpu)) {
- BUG_ON(vcpu->arch.pending_ioapic_eoi > 255);
if (test_bit(vcpu->arch.pending_ioapic_eoi,
vcpu->arch.ioapic_handled_vectors)) {
vcpu->run->exit_reason = KVM_EXIT_IOAPIC_EOI;
base-commit: a806d364ef288a6443a1337820ea8410a7ccc6b3
--
2.55.0.679.g6767b8d81c-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] KVM: x86: Track kvm_vcpu_arch.pending_ioapic_eoi as a u8 to drop dead BUG_ON()
2026-08-06 17:14 [PATCH v2] KVM: x86: Track kvm_vcpu_arch.pending_ioapic_eoi as a u8 to drop dead BUG_ON() Sean Christopherson
@ 2026-08-06 18:31 ` Paolo Bonzini
2026-08-06 21:51 ` Huang, Kai
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2026-08-06 18:31 UTC (permalink / raw)
To: Sean Christopherson; +Cc: kvm, linux-kernel
On Thu, Aug 6, 2026 at 7:14 PM Sean Christopherson <seanjc@google.com> wrote:
>
> Track the vector associated with KVM_EXIT_IOAPIC_EOI as a u8, as the vector
> is zero-initialized and is only ever set to a legal vector. I.e. unlike
> many of the other vector variables in KVM, it can't be -1 (and can't be
> greater than 255, though that should hold true for all vectors in KVM).
>
> Drop the now fully dead BUG_ON(), which aside from being completely
> unnecessary, was also useless, as it wouldn't guard against a negative
> value, i.e. wouldn't detect KVM's magic -1 value.
>
> For all intents and purposes, no functional change intended.
>
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Paolo
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>
> v2: Use a u8 to make it impossible for the test to be out-of-bounds. [Paolo]
>
> v1: https://lore.kernel.org/all/20260618185515.2021642-1-seanjc@google.com
>
> arch/x86/include/asm/kvm_host.h | 2 +-
> arch/x86/kvm/lapic.c | 4 ++--
> arch/x86/kvm/lapic.h | 2 +-
> arch/x86/kvm/vmx/vmx.c | 3 +--
> arch/x86/kvm/x86.c | 1 -
> 5 files changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 283847619ff8..9614314fd237 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -973,7 +973,7 @@ struct kvm_vcpu_arch {
> bool pv_unhalted;
> } pv;
>
> - int pending_ioapic_eoi;
> + u8 pending_ioapic_eoi;
> int pending_external_vector;
> int highest_stale_pending_ioapic_eoi;
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index 586a5cee29e1..87bb8e5f4ca1 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -1552,7 +1552,7 @@ static bool kvm_ioapic_handles_vector(struct kvm_lapic *apic, int vector)
> return test_bit(vector, apic->vcpu->arch.ioapic_handled_vectors);
> }
>
> -static void kvm_ioapic_send_eoi(struct kvm_lapic *apic, int vector)
> +static void kvm_ioapic_send_eoi(struct kvm_lapic *apic, u8 vector)
> {
> int __maybe_unused trigger_mode;
>
> @@ -1622,7 +1622,7 @@ static int apic_set_eoi(struct kvm_lapic *apic)
> * this interface assumes a trap-like exit, which has already finished
> * desired side effect including vISR and vPPR update.
> */
> -void kvm_apic_set_eoi_accelerated(struct kvm_vcpu *vcpu, int vector)
> +void kvm_apic_set_eoi_accelerated(struct kvm_vcpu *vcpu, u8 vector)
> {
> struct kvm_lapic *apic = vcpu->arch.apic;
>
> diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
> index bd1098c89d99..db071d0b172d 100644
> --- a/arch/x86/kvm/lapic.h
> +++ b/arch/x86/kvm/lapic.h
> @@ -177,7 +177,7 @@ u64 kvm_get_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu);
> void kvm_set_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu, u64 data);
>
> void kvm_apic_write_nodecode(struct kvm_vcpu *vcpu, u32 offset);
> -void kvm_apic_set_eoi_accelerated(struct kvm_vcpu *vcpu, int vector);
> +void kvm_apic_set_eoi_accelerated(struct kvm_vcpu *vcpu, u8 vector);
>
> int kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr);
> void kvm_lapic_sync_from_vapic(struct kvm_vcpu *vcpu);
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index e3bfe6aca1a0..c1fdfccd20fa 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -5886,10 +5886,9 @@ static int handle_apic_access(struct kvm_vcpu *vcpu)
> static int handle_apic_eoi_induced(struct kvm_vcpu *vcpu)
> {
> unsigned long exit_qualification = vmx_get_exit_qual(vcpu);
> - int vector = exit_qualification & 0xff;
>
> /* EOI-induced VM exit is trap-like and thus no need to adjust IP */
> - kvm_apic_set_eoi_accelerated(vcpu, vector);
> + kvm_apic_set_eoi_accelerated(vcpu, exit_qualification & 0xff);
> return 1;
> }
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index d94b59140c45..8b23f342a1fa 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -8151,7 +8151,6 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
> if (kvm_check_request(KVM_REQ_NMI, vcpu))
> process_nmi(vcpu);
> if (kvm_check_request(KVM_REQ_IOAPIC_EOI_EXIT, vcpu)) {
> - BUG_ON(vcpu->arch.pending_ioapic_eoi > 255);
> if (test_bit(vcpu->arch.pending_ioapic_eoi,
> vcpu->arch.ioapic_handled_vectors)) {
> vcpu->run->exit_reason = KVM_EXIT_IOAPIC_EOI;
>
> base-commit: a806d364ef288a6443a1337820ea8410a7ccc6b3
> --
> 2.55.0.679.g6767b8d81c-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] KVM: x86: Track kvm_vcpu_arch.pending_ioapic_eoi as a u8 to drop dead BUG_ON()
2026-08-06 17:14 [PATCH v2] KVM: x86: Track kvm_vcpu_arch.pending_ioapic_eoi as a u8 to drop dead BUG_ON() Sean Christopherson
2026-08-06 18:31 ` Paolo Bonzini
@ 2026-08-06 21:51 ` Huang, Kai
1 sibling, 0 replies; 3+ messages in thread
From: Huang, Kai @ 2026-08-06 21:51 UTC (permalink / raw)
To: pbonzini@redhat.com, seanjc@google.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org
On Thu, 2026-08-06 at 10:14 -0700, Sean Christopherson wrote:
> Track the vector associated with KVM_EXIT_IOAPIC_EOI as a u8, as the vector
> is zero-initialized and is only ever set to a legal vector. I.e. unlike
> many of the other vector variables in KVM, it can't be -1 (and can't be
> greater than 255, though that should hold true for all vectors in KVM).
>
> Drop the now fully dead BUG_ON(), which aside from being completely
> unnecessary, was also useless, as it wouldn't guard against a negative
> value, i.e. wouldn't detect KVM's magic -1 value.
>
> For all intents and purposes, no functional change intended.
>
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
>
Reviewed-by: Kai Huang <kai.huang@intel.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-06 21:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-06 17:14 [PATCH v2] KVM: x86: Track kvm_vcpu_arch.pending_ioapic_eoi as a u8 to drop dead BUG_ON() Sean Christopherson
2026-08-06 18:31 ` Paolo Bonzini
2026-08-06 21:51 ` Huang, Kai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox