KVM: x86: Track kvm_vcpu_arch.pending_ioapic_eoi as a u8 to drop dead BUG_ON()
Sean Christopherson
maintainerPATCH v2 1/1 KVM: x86: Track kvm_vcpu_arch.pending_ioapic_eoi as a u8 to drop dead BUG_ON()
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.
---
v2: Use a u8 to make it impossible for the test to be out-of-bounds. [Paolo]
v1: https://lore.kernel.org/all/[email protected]
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(-)
arch/x86/include/asm/kvm_host.h +1 -1
@@ -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;
arch/x86/kvm/lapic.c +2 -2
@@ -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;
arch/x86/kvm/lapic.h +1 -1
@@ -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);
arch/x86/kvm/vmx/vmx.c +1 -2
@@ -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 ; }
arch/x86/kvm/x86.c +0 -1
@@ -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
Signature · 1 line
2.55.0.679.g6767b8d81c-goog
Quoted 6 lines · Sean Christopherson
Track the vector associated with
KVM_EXIT_IOAPIC_EOIas 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).
Quoted 7 lines
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 <[email protected]>
Paolo
Quoted 95 lines
Signed-off-by Sean Christopherson <[email protected]>---
v2: Use a u8 to make it impossible for the test to be out-of-bounds. [Paolo]
v1: https://lore.kernel.org/all/[email protected]
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(-)arch/x86/include/asm/kvm_host.h +1
-1@@ -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;arch/x86/kvm/lapic.c +2
-2@@ -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;arch/x86/kvm/lapic.h +1
-1@@ -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);arch/x86/kvm/vmx/vmx.c +1
-2@@ -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 ; }arch/x86/kvm/x86.c +0
-1@@ -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
Quoted 5 lines · Sean Christopherson
Track the vector associated with
KVM_EXIT_IOAPIC_EOIas 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).
Quoted 9 lines
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 <[email protected]>Signed-off-by Sean Christopherson <[email protected]>
Quoted 10 lines · Sean Christopherson
Track the vector associated with
KVM_EXIT_IOAPIC_EOIas 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.[...]
Applied to kvm-x86 misc, thanks!
[1/1] KVM: x86: Track kvm_vcpu_arch.pending_ioapic_eoi as a u8 to drop dead BUG_ON()
https://github.com/kvm-x86/linux/commit/926a9ea9bdf0