浏览代码

KVM: limit lapic periodic timer frequency

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>
Marcelo Tosatti 16 年之前
父节点
当前提交
1444885a04
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      arch/x86/kvm/lapic.c

+ 9 - 0
arch/x86/kvm/lapic.c

@@ -670,6 +670,15 @@ static void start_apic_timer(struct kvm_lapic *apic)
 
 
 	if (!apic->lapic_timer.period)
 	if (!apic->lapic_timer.period)
 		return;
 		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,
 	hrtimer_start(&apic->lapic_timer.timer,
 		      ktime_add_ns(now, apic->lapic_timer.period),
 		      ktime_add_ns(now, apic->lapic_timer.period),