From nobody Fri Oct 2 01:14:44 2026 Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25E3F383C86 for ; Thu, 6 Aug 2026 17:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786036444; cv=none; b=b0cPV/MSLaCJUqBvZXO01Z+DiT2+DdACo7sIvLK7g47HfPiSdp8m0xeT0TYENYT/xxHYRs+ZNRkvfTYGyYUO09MW2wRlf5I+jFlurUB/1M5Wt/HWjnRwbEZ3eUoPD0iZX+PRgqH9WSN4MQOUR0IWPMTTLUlvpaDIKxZiFYhHA1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786036444; c=relaxed/simple; bh=BSW9VlWy7RGXWGfVtlph3tBzT27DKzeu81yVoq7tL7k=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=IzLg0oSdp8a55CekOsXNbS2Gydt7Qw6RMl51N1t7Rw0H+LwZCRogpZDpuOrdjCmWCV+PMT4U9Puc4D0sqAH2maprCZHtSOOEEOm2E1l0E+hX0YScOVahKLcBA6+3Jz5WkWI8t7EPOJpL/fqOMYRz2tSI27R+HDPrhjiSCIcRXjo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=eHufdsZF; arc=none smtp.client-ip=209.85.215.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eHufdsZF" Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-cb7049fa552so1616239a12.2 for ; Thu, 06 Aug 2026 10:14:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786036442; x=1786641242; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date :reply-to:from:to:cc:subject:date:message-id:reply-to:content-type; bh=nIsR1jQAsco29/Iy31lyCdc88bdktGG5sWNT7XHMcn8=; b=eHufdsZFgaAm4KP6XTnpdU11Gbnc19hoo8ZG4VeRli01yLDu64dAG0skFD7drZiIgg Fi9Pt6QY00UvsMD+45iM7/huDwHD+nKqsZdunss8sq3aoYw71FH17o5Adezeett8ASZm 5+MtgMISOT8iLWSIr5m3lM+cmYvub3gIado154ZDwA2ESQAArRmGPeFHXWrhC3UR4Z/0 E9c2v+KjxMDpQ1qd4ibTcjwsHUYr5nZEABzH8A19wuQtE0JpcNySkFO+MfVeUtxcf9Kn ky61dVMdV/swjSL98i4IJedN5dFSyQF18+7aemyEX+tJKnQFAAA7lN+b8lQYbeBdKhoC LB9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786036442; x=1786641242; h=content-type:cc:to:from:subject:message-id:mime-version:date :reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=nIsR1jQAsco29/Iy31lyCdc88bdktGG5sWNT7XHMcn8=; b=Lae4viZw/7PhwLYqdFYeHNYyXUxKSOwK8oqtvl92R+m6gtmKqVQOoKMRQo6bEzhFcD YVFZoKQ6fI5/P23TzpfRSgStJtBU6CGGHS/wZKx9eNG1d36tDkyoM0TmeXgmbmua/Oig 9BgCfB/pIZaQsTTvuWsyXpo4O+nlvkILuhIudO9x2pnFNiUrSF0f7EVkwu6UG6jQdilH Bc+c8M1H2HcrUkI6VlIzAku3VKsgp05Zn3cL6bVZzbVubQXY2XTIv40gBdrGk4sx34RA 7IrORHeu/nrMETvYjrgPeZn2PQQHw1r/43LyxrcjdkVNHT8MVezJFOIw7gTNyfaxcqWK 8raQ== X-Forwarded-Encrypted: i=1; AHgh+Rp/LTudRW5cV3njRKvfKSw7ipUVU4NJp/sH29jKVKxfqDN5Hs3F7YWs1HEr1vIf1Qgc3Hm93oUWQkkrP1o=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/MRVnOmMrhMiHxyX/3RPCNIK7EcHP+tZ9X0t9vdIJRCm3B5h/ Nb0r0OxgCIqdfF0pWZUXHbLmGqqjZ8ne3E1N8eVoZKW74IlUeY4iFCHumlFDuE6thtmM6Wt2+pB EF/RjLw== X-Received: from pfbgo23.prod.google.com ([2002:a05:6a00:3b17:b0:847:87ec:2a9f]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:4507:b0:842:6004:3fd5 with SMTP id d2e1a72fcca58-84f4fe9f556mr3837725b3a.25.1786036441692; Thu, 06 Aug 2026 10:14:01 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 6 Aug 2026 10:14:00 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.679.g6767b8d81c-goog Message-ID: <20260806171400.4119301-1-seanjc@google.com> Subject: [PATCH v2] KVM: x86: Track kvm_vcpu_arch.pending_ioapic_eoi as a u8 to drop dead BUG_ON() From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Sean Christopherson Reviewed-by: Kai Huang Reviewed-by: Paolo Bonzini --- 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_hos= t.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; =20 - int pending_ioapic_eoi; + u8 pending_ioapic_eoi; int pending_external_vector; int highest_stale_pending_ioapic_eoi; =20 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_lapi= c *apic, int vector) return test_bit(vector, apic->vcpu->arch.ioapic_handled_vectors); } =20 -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; =20 @@ -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 =3D vcpu->arch.apic; =20 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); =20 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); =20 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 =3D vmx_get_exit_qual(vcpu); - int vector =3D exit_qualification & 0xff; =20 /* 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; } =20 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 =3D KVM_EXIT_IOAPIC_EOI; base-commit: a806d364ef288a6443a1337820ea8410a7ccc6b3 --=20 2.55.0.679.g6767b8d81c-goog