KVM: limit lapic periodic timer frequency
authorMarcelo Tosatti <mtosatti@redhat.com>
Tue, 28 Jul 2009 02:41:01 +0000 (23:41 -0300)
committerAvi Kivity <avi@redhat.com>
Thu, 10 Sep 2009 05:33:17 +0000 (08:33 +0300)
Otherwise its possible to starve the host by programming lapic timer
with a very high frequency.

Cc: stable@kernel.org
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/kvm/lapic.c

index 66122bfc74a9b2864d4f5fb23dfd288ac6fe08ab..5b9d1ae09cadfb02f3aa14aca6906dd698d0ef4e 100644 (file)
@@ -670,6 +670,15 @@ static void start_apic_timer(struct kvm_lapic *apic)
 
        if (!apic->lapic_timer.period)
                return;
+       /*
+        * Do not allow the guest to program periodic timers with small
+        * interval, since the hrtimers are not throttled by the host
+        * scheduler.
+        */
+       if (apic_lvtt_period(apic)) {
+               if (apic->lapic_timer.period < NSEC_PER_MSEC/2)
+                       apic->lapic_timer.period = NSEC_PER_MSEC/2;
+       }
 
        hrtimer_start(&apic->lapic_timer.timer,
                      ktime_add_ns(now, apic->lapic_timer.period),