Skip to content

Commit 2c31aa7

Browse files
committed
KVM: x86: Don't clear PIT's IRQ line status when destroying PIT
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>
1 parent 61423c4 commit 2c31aa7

File tree

5 files changed

+0
-33
lines changed

5 files changed

+0
-33
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,8 +2208,6 @@ static inline int __kvm_irq_line_state(unsigned long *irq_state,
22082208
return !!(*irq_state);
22092209
}
22102210

2211-
void kvm_pic_clear_all(struct kvm_pic *pic, int irq_source_id);
2212-
22132211
void kvm_inject_nmi(struct kvm_vcpu *vcpu);
22142212
int kvm_get_nr_pending_nmis(struct kvm_vcpu *vcpu);
22152213

arch/x86/kvm/i8254.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -641,14 +641,6 @@ static void kvm_pit_reset(struct kvm_pit *pit)
641641
kvm_pit_reset_reinject(pit);
642642
}
643643

644-
static void kvm_pit_clear_all(struct kvm *kvm)
645-
{
646-
mutex_lock(&kvm->irq_lock);
647-
kvm_ioapic_clear_all(kvm->arch.vioapic, KVM_PIT_IRQ_SOURCE_ID);
648-
kvm_pic_clear_all(kvm->arch.vpic, KVM_PIT_IRQ_SOURCE_ID);
649-
mutex_unlock(&kvm->irq_lock);
650-
}
651-
652644
static void pit_mask_notifer(struct kvm_irq_mask_notifier *kimn, bool mask)
653645
{
654646
struct kvm_pit *pit = container_of(kimn, struct kvm_pit, mask_notifier);
@@ -803,7 +795,6 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
803795
kvm_pit_set_reinject(pit, false);
804796
kthread_destroy_worker(pit->worker);
805797
fail_kthread:
806-
kvm_pit_clear_all(kvm);
807798
kfree(pit);
808799
return NULL;
809800
}
@@ -820,7 +811,6 @@ void kvm_free_pit(struct kvm *kvm)
820811
kvm_pit_set_reinject(pit, false);
821812
hrtimer_cancel(&pit->pit_state.timer);
822813
kthread_destroy_worker(pit->worker);
823-
kvm_pit_clear_all(kvm);
824814
kfree(pit);
825815
}
826816
}

arch/x86/kvm/i8259.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,6 @@ int kvm_pic_set_irq(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm,
206206
return ret;
207207
}
208208

209-
void kvm_pic_clear_all(struct kvm_pic *s, int irq_source_id)
210-
{
211-
int i;
212-
213-
pic_lock(s);
214-
for (i = 0; i < PIC_NUM_PINS; i++)
215-
__clear_bit(irq_source_id, &s->irq_states[i]);
216-
pic_unlock(s);
217-
}
218-
219209
/*
220210
* acknowledge interrupt 'irq'
221211
*/

arch/x86/kvm/ioapic.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -498,16 +498,6 @@ int kvm_ioapic_set_irq(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm,
498498
return ret;
499499
}
500500

501-
void kvm_ioapic_clear_all(struct kvm_ioapic *ioapic, int irq_source_id)
502-
{
503-
int i;
504-
505-
spin_lock(&ioapic->lock);
506-
for (i = 0; i < KVM_IOAPIC_NUM_PINS; i++)
507-
__clear_bit(irq_source_id, &ioapic->irq_states[i]);
508-
spin_unlock(&ioapic->lock);
509-
}
510-
511501
static void kvm_ioapic_eoi_inject_work(struct work_struct *work)
512502
{
513503
int i;

arch/x86/kvm/ioapic.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ void kvm_ioapic_destroy(struct kvm *kvm);
114114
int kvm_ioapic_set_irq(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm,
115115
int irq_source_id, int level, bool line_status);
116116

117-
void kvm_ioapic_clear_all(struct kvm_ioapic *ioapic, int irq_source_id);
118117
void kvm_get_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state);
119118
void kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state);
120119
void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu,

0 commit comments

Comments
 (0)