Skip to contentSkip to conversation

i8253: Fix PIT shutdown quirk on Hyper-V

PATCH Superseded Michael Kelley 1 participant 1 message Nov 1, 2018 Clocksource, clockevent drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 i8253: Fix PIT shutdown quirk on Hyper-V

pit_shutdown() doesn't work on Hyper-V because of a quirk in the PIT emulation. This problem exists in all versions of Hyper-V and had not been noticed previously. When the counter register is set to zero, the emulated PIT continues to interrupt @18.2 HZ. So skip setting the counter register when running on Hyper-V.

---
 drivers/clocksource/i8253.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/clocksource/i8253.c +12 -2
index 9c38895..62025c8 100644
@@ -10,6 +10,7 @@
 #include <linux/module.h>
 #include <linux/i8253.h>
 #include <linux/smp.h>
+#include <linux/hypervisor.h>
 
 /*
  * Protects access to I/O ports
@@ -109,8 +110,17 @@ static int pit_shutdown(struct clock_event_device *evt)
 	raw_spin_lock(&i8253_lock);
 
 	outb_p(0x30, PIT_MODE);
-	outb_p(0, PIT_CH0);
-	outb_p(0, PIT_CH0);
+
+	/*
+	 * A quirk in Hyper-V's emulation of the PIT causes the PIT
+	 * to continue to run and interrupt @18.2 Hz when the counter
+	 * register is set to zero. So skip setting the counter
+	 * register when running as a guest on Hyper-V.
+	 */
+	if (!hypervisor_is_mshyperv()) {
+		outb_p(0, PIT_CH0);
+		outb_p(0, PIT_CH0);
+	}
 
 	raw_spin_unlock(&i8253_lock);
 	return 0;
Signature · 1 line
1.8.3.1