Skip to content

Commit 0924ab2

Browse files
jan-kiszkaavikivity
authored andcommitted
KVM: x86: Prevent starting PIT timers in the absence of irqchip support
User space may create the PIT and forgets about setting up the irqchips. In that case, firing PIT IRQs will crash the host: BUG: unable to handle kernel NULL pointer dereference at 0000000000000128 IP: [<ffffffffa10f6280>] kvm_set_irq+0x30/0x170 [kvm] ... Call Trace: [<ffffffffa11228c1>] pit_do_work+0x51/0xd0 [kvm] [<ffffffff81071431>] process_one_work+0x111/0x4d0 [<ffffffff81071bb2>] worker_thread+0x152/0x340 [<ffffffff81075c8e>] kthread+0x7e/0x90 [<ffffffff815a4474>] kernel_thread_helper+0x4/0x10 Prevent this by checking the irqchip mode before starting a timer. We can't deny creating the PIT if the irqchips aren't set up yet as current user land expects this order to work. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
1 parent 4962516 commit 0924ab2

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎arch/x86/kvm/i8254.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,15 @@ static enum hrtimer_restart pit_timer_fn(struct hrtimer *data)
338338
return HRTIMER_NORESTART;
339339
}
340340

341-
static void create_pit_timer(struct kvm_kpit_state *ps, u32 val, int is_period)
341+
static void create_pit_timer(struct kvm *kvm, u32 val, int is_period)
342342
{
343+
struct kvm_kpit_state *ps = &kvm->arch.vpit->pit_state;
343344
struct kvm_timer *pt = &ps->pit_timer;
344345
s64 interval;
345346

347+
if (!irqchip_in_kernel(kvm))
348+
return;
349+
346350
interval = muldiv64(val, NSEC_PER_SEC, KVM_PIT_FREQ);
347351

348352
pr_debug("create pit timer, interval is %llu nsec\n", interval);
@@ -394,13 +398,13 @@ static void pit_load_count(struct kvm *kvm, int channel, u32 val)
394398
/* FIXME: enhance mode 4 precision */
395399
case 4:
396400
if (!(ps->flags & KVM_PIT_FLAGS_HPET_LEGACY)) {
397-
create_pit_timer(ps, val, 0);
401+
create_pit_timer(kvm, val, 0);
398402
}
399403
break;
400404
case 2:
401405
case 3:
402406
if (!(ps->flags & KVM_PIT_FLAGS_HPET_LEGACY)){
403-
create_pit_timer(ps, val, 1);
407+
create_pit_timer(kvm, val, 1);
404408
}
405409
break;
406410
default:

0 commit comments

Comments
 (0)