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

From: Michael Kelley
Date: Thu Nov 01 2018 - 13:32:37 EST


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.

Signed-off-by: Michael Kelley <mikelley@xxxxxxxxxxxxx>
---
drivers/clocksource/i8253.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/clocksource/i8253.c b/drivers/clocksource/i8253.c
index 9c38895..62025c8 100644
--- a/drivers/clocksource/i8253.c
+++ b/drivers/clocksource/i8253.c
@@ -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;
--
1.8.3.1