]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: x86: Don't clear PIT's IRQ line status when destroying PIT
authorSean Christopherson <seanjc@google.com>
Wed, 11 Jun 2025 21:35:50 +0000 (14:35 -0700)
committerSean Christopherson <seanjc@google.com>
Fri, 20 Jun 2025 20:52:48 +0000 (13:52 -0700)
Don't bother clearing the PIT's IRQ line status when destroying the PIT,
as userspace can't possibly rely on KVM to lower the IRQ line in any sane
use case, and it's not at all obvious that clearing the PIT's IRQ line is
correct/desirable in kvm_create_pit()'s error path.

When called from kvm_arch_pre_destroy_vm(), the entire VM is being torn
down and thus {kvm_pic,kvm_ioapic}.irq_states are unreachable.

As for the error path in kvm_create_pit(), the only way the PIT's bit in
irq_states can be set is if userspace raises the associated IRQ before
KVM_CREATE_PIT{2} completes.  Forcefully clearing the bit would clobber
userspace's input, nonsensical though that input may be.  Not to mention
that no known VMM will continue on if PIT creation fails.

Acked-by: Kai Huang <kai.huang@intel.com>
Link: https://lore.kernel.org/r/20250611213557.294358-12-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/i8254.c
arch/x86/kvm/i8259.c
arch/x86/kvm/ioapic.c
arch/x86/kvm/ioapic.h

index 4d68680f7051ba33573c0da3e6cfc7cab23eab3c..a4649a234f05be97e07bfe0134410eed497b3a53 100644 (file)
@@ -2208,8 +2208,6 @@ static inline int __kvm_irq_line_state(unsigned long *irq_state,
        return !!(*irq_state);
 }
 
-void kvm_pic_clear_all(struct kvm_pic *pic, int irq_source_id);
-
 void kvm_inject_nmi(struct kvm_vcpu *vcpu);
 int kvm_get_nr_pending_nmis(struct kvm_vcpu *vcpu);
 
index fa8187608cfc0e40b0e81c449586f0d5da8ae605..d1b79b418c0542d2bd17b1cbb9dd72f0b40a5519 100644 (file)
@@ -641,14 +641,6 @@ static void kvm_pit_reset(struct kvm_pit *pit)
        kvm_pit_reset_reinject(pit);
 }
 
-static void kvm_pit_clear_all(struct kvm *kvm)
-{
-       mutex_lock(&kvm->irq_lock);
-       kvm_ioapic_clear_all(kvm->arch.vioapic, KVM_PIT_IRQ_SOURCE_ID);
-       kvm_pic_clear_all(kvm->arch.vpic, KVM_PIT_IRQ_SOURCE_ID);
-       mutex_unlock(&kvm->irq_lock);
-}
-
 static void pit_mask_notifer(struct kvm_irq_mask_notifier *kimn, bool mask)
 {
        struct kvm_pit *pit = container_of(kimn, struct kvm_pit, mask_notifier);
@@ -803,7 +795,6 @@ fail_register_pit:
        kvm_pit_set_reinject(pit, false);
        kthread_destroy_worker(pit->worker);
 fail_kthread:
-       kvm_pit_clear_all(kvm);
        kfree(pit);
        return NULL;
 }
@@ -820,7 +811,6 @@ void kvm_free_pit(struct kvm *kvm)
                kvm_pit_set_reinject(pit, false);
                hrtimer_cancel(&pit->pit_state.timer);
                kthread_destroy_worker(pit->worker);
-               kvm_pit_clear_all(kvm);
                kfree(pit);
        }
 }
index 0150aec4f523c71c6218f4110784874b6a036dcd..4de055efc4eec87886c74e20df2c2a212a2079cc 100644 (file)
@@ -206,16 +206,6 @@ int kvm_pic_set_irq(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm,
        return ret;
 }
 
-void kvm_pic_clear_all(struct kvm_pic *s, int irq_source_id)
-{
-       int i;
-
-       pic_lock(s);
-       for (i = 0; i < PIC_NUM_PINS; i++)
-               __clear_bit(irq_source_id, &s->irq_states[i]);
-       pic_unlock(s);
-}
-
 /*
  * acknowledge interrupt 'irq'
  */
index 8c8a8062eb19aea731b8bd25055cd6a38963d6ac..65626da1407fa2026244cbda9cc1801bdc5154ba 100644 (file)
@@ -498,16 +498,6 @@ int kvm_ioapic_set_irq(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm,
        return ret;
 }
 
-void kvm_ioapic_clear_all(struct kvm_ioapic *ioapic, int irq_source_id)
-{
-       int i;
-
-       spin_lock(&ioapic->lock);
-       for (i = 0; i < KVM_IOAPIC_NUM_PINS; i++)
-               __clear_bit(irq_source_id, &ioapic->irq_states[i]);
-       spin_unlock(&ioapic->lock);
-}
-
 static void kvm_ioapic_eoi_inject_work(struct work_struct *work)
 {
        int i;
index 289cca3aec6993043316ad4dbd065f4f2c911fdc..dc92bd7c37bc43ce3acc65cabeec752b12987dac 100644 (file)
@@ -114,7 +114,6 @@ void kvm_ioapic_destroy(struct kvm *kvm);
 int kvm_ioapic_set_irq(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm,
                       int irq_source_id, int level, bool line_status);
 
-void kvm_ioapic_clear_all(struct kvm_ioapic *ioapic, int irq_source_id);
 void kvm_get_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state);
 void kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state);
 void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu,