* [PATCH v2 0/2] i8253: Fix PIT shutdown quirk on Hyper-V @ 2018-11-04 3:48 Michael Kelley 2018-11-04 3:48 ` [PATCH v2 1/2] i8253: Add support for PIT shutdown quirk Michael Kelley 2018-11-04 3:48 ` [PATCH v2 2/2] x86/hyper-v: Enable " Michael Kelley 0 siblings, 2 replies; 5+ messages in thread From: Michael Kelley @ 2018-11-04 3:48 UTC (permalink / raw) To: gregkh@linuxfoundation.org, devel@linuxdriverproject.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, daniel.lezcano@linaro.org, virtualization@lists.linux-foundation.org, jgross@suse.com, akataria@vmware.com, olaf@aepfle.de, apw@canonical.com, vkuznets, jasowang@redhat.com, marcelo.cerri@canonical.com, KY Srinivasan Cc: Michael Kelley 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. Account for this quirk by adding a global variable in the i8253 code that controls whether the counter register is zero'ed. Then in Hyper-V initialization code, override the default setting so the counter register is not zero'ed. Changes in v2: * Instead of a function call to check if running on Hyper-V, use a global variable to control whether the counter register is zero'ed. [Juergen Gross & Thomas Gleixner] Michael Kelley (2): i8253: Add support for PIT shutdown quirk x86/hyper-v: Enable PIT shutdown quirk arch/x86/kernel/cpu/mshyperv.c | 11 +++++++++++ drivers/clocksource/i8253.c | 14 ++++++++++++-- include/linux/i8253.h | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) -- 1.8.3.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] i8253: Add support for PIT shutdown quirk 2018-11-04 3:48 [PATCH v2 0/2] i8253: Fix PIT shutdown quirk on Hyper-V Michael Kelley @ 2018-11-04 3:48 ` Michael Kelley 2018-11-04 10:09 ` [tip:x86/urgent] clockevents/drivers/i8253: " tip-bot for Michael Kelley 2018-11-04 3:48 ` [PATCH v2 2/2] x86/hyper-v: Enable " Michael Kelley 1 sibling, 1 reply; 5+ messages in thread From: Michael Kelley @ 2018-11-04 3:48 UTC (permalink / raw) To: gregkh@linuxfoundation.org, devel@linuxdriverproject.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, daniel.lezcano@linaro.org, virtualization@lists.linux-foundation.org, jgross@suse.com, akataria@vmware.com, olaf@aepfle.de, apw@canonical.com, vkuznets, jasowang@redhat.com, marcelo.cerri@canonical.com, KY Srinivasan Cc: Michael Kelley Add support for platforms where pit_shutdown() doesn't work because of a quirk in the PIT emulation. On these platforms setting the counter register to zero causes the PIT to start running again, negating the shutdown. Provide a global variable that controls whether the counter register is zero'ed, which platform specific code can override. Signed-off-by: Michael Kelley <mikelley@microsoft.com> --- drivers/clocksource/i8253.c | 14 ++++++++++++-- include/linux/i8253.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/clocksource/i8253.c b/drivers/clocksource/i8253.c index 9c38895..2a4202a 100644 --- a/drivers/clocksource/i8253.c +++ b/drivers/clocksource/i8253.c @@ -20,6 +20,13 @@ DEFINE_RAW_SPINLOCK(i8253_lock); EXPORT_SYMBOL(i8253_lock); +/* + * Handle PIT quirk in pit_shutdown() where zeroing the counter register + * restarts the PIT, negating the shutdown. On platforms with the quirk, + * platform specific code can set this to false. + */ +bool i8253_clear_counter __ro_after_init = true; + #ifdef CONFIG_CLKSRC_I8253 /* * Since the PIT overflows every tick, its not very useful @@ -109,8 +116,11 @@ 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); + + if (i8253_clear_counter) { + outb_p(0, PIT_CH0); + outb_p(0, PIT_CH0); + } raw_spin_unlock(&i8253_lock); return 0; diff --git a/include/linux/i8253.h b/include/linux/i8253.h index e6bb36a..31c4be5 100644 --- a/include/linux/i8253.h +++ b/include/linux/i8253.h @@ -21,6 +21,7 @@ #define PIT_LATCH ((PIT_TICK_RATE + HZ/2) / HZ) extern raw_spinlock_t i8253_lock; +extern bool i8253_clear_counter; extern struct clock_event_device i8253_clockevent; extern void clockevent_i8253_init(bool oneshot); -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [tip:x86/urgent] clockevents/drivers/i8253: Add support for PIT shutdown quirk 2018-11-04 3:48 ` [PATCH v2 1/2] i8253: Add support for PIT shutdown quirk Michael Kelley @ 2018-11-04 10:09 ` tip-bot for Michael Kelley 0 siblings, 0 replies; 5+ messages in thread From: tip-bot for Michael Kelley @ 2018-11-04 10:09 UTC (permalink / raw) To: linux-tip-commits Cc: marcelo.cerri, mikelley, devel, olaf, jgross, jasowang, mingo, apw, tglx, daniel.lezcano, hpa, vkuznets, gregkh, akataria, kys, virtualization, linux-kernel Commit-ID: 35b69a420bfb56b7b74cb635ea903db05e357bec Gitweb: https://git.kernel.org/tip/35b69a420bfb56b7b74cb635ea903db05e357bec Author: Michael Kelley <mikelley@microsoft.com> AuthorDate: Sun, 4 Nov 2018 03:48:54 +0000 Committer: Thomas Gleixner <tglx@linutronix.de> CommitDate: Sun, 4 Nov 2018 11:04:46 +0100 clockevents/drivers/i8253: Add support for PIT shutdown quirk Add support for platforms where pit_shutdown() doesn't work because of a quirk in the PIT emulation. On these platforms setting the counter register to zero causes the PIT to start running again, negating the shutdown. Provide a global variable that controls whether the counter register is zero'ed, which platform specific code can override. Signed-off-by: Michael Kelley <mikelley@microsoft.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org> Cc: "devel@linuxdriverproject.org" <devel@linuxdriverproject.org> Cc: "daniel.lezcano@linaro.org" <daniel.lezcano@linaro.org> Cc: "virtualization@lists.linux-foundation.org" <virtualization@lists.linux-foundation.org> Cc: "jgross@suse.com" <jgross@suse.com> Cc: "akataria@vmware.com" <akataria@vmware.com> Cc: "olaf@aepfle.de" <olaf@aepfle.de> Cc: "apw@canonical.com" <apw@canonical.com> Cc: vkuznets <vkuznets@redhat.com> Cc: "jasowang@redhat.com" <jasowang@redhat.com> Cc: "marcelo.cerri@canonical.com" <marcelo.cerri@canonical.com> Cc: KY Srinivasan <kys@microsoft.com> Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/1541303219-11142-2-git-send-email-mikelley@microsoft.com --- drivers/clocksource/i8253.c | 14 ++++++++++++-- include/linux/i8253.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/clocksource/i8253.c b/drivers/clocksource/i8253.c index 9c38895542f4..d4350bb10b83 100644 --- a/drivers/clocksource/i8253.c +++ b/drivers/clocksource/i8253.c @@ -20,6 +20,13 @@ DEFINE_RAW_SPINLOCK(i8253_lock); EXPORT_SYMBOL(i8253_lock); +/* + * Handle PIT quirk in pit_shutdown() where zeroing the counter register + * restarts the PIT, negating the shutdown. On platforms with the quirk, + * platform specific code can set this to false. + */ +bool i8253_clear_counter_on_shutdown __ro_after_init = true; + #ifdef CONFIG_CLKSRC_I8253 /* * Since the PIT overflows every tick, its not very useful @@ -109,8 +116,11 @@ 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); + + if (i8253_clear_counter_on_shutdown) { + outb_p(0, PIT_CH0); + outb_p(0, PIT_CH0); + } raw_spin_unlock(&i8253_lock); return 0; diff --git a/include/linux/i8253.h b/include/linux/i8253.h index e6bb36a97519..8336b2f6f834 100644 --- a/include/linux/i8253.h +++ b/include/linux/i8253.h @@ -21,6 +21,7 @@ #define PIT_LATCH ((PIT_TICK_RATE + HZ/2) / HZ) extern raw_spinlock_t i8253_lock; +extern bool i8253_clear_counter_on_shutdown; extern struct clock_event_device i8253_clockevent; extern void clockevent_i8253_init(bool oneshot); ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] x86/hyper-v: Enable PIT shutdown quirk 2018-11-04 3:48 [PATCH v2 0/2] i8253: Fix PIT shutdown quirk on Hyper-V Michael Kelley 2018-11-04 3:48 ` [PATCH v2 1/2] i8253: Add support for PIT shutdown quirk Michael Kelley @ 2018-11-04 3:48 ` Michael Kelley 2018-11-04 10:10 ` [tip:x86/urgent] " tip-bot for Michael Kelley 1 sibling, 1 reply; 5+ messages in thread From: Michael Kelley @ 2018-11-04 3:48 UTC (permalink / raw) To: gregkh@linuxfoundation.org, devel@linuxdriverproject.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, daniel.lezcano@linaro.org, virtualization@lists.linux-foundation.org, jgross@suse.com, akataria@vmware.com, olaf@aepfle.de, apw@canonical.com, vkuznets, jasowang@redhat.com, marcelo.cerri@canonical.com, KY Srinivasan Cc: Michael Kelley Hyper-V emulation of the PIT has a quirk such that the normal PIT shutdown path doesn't work. Enable the PIT code that handles this quirk. Signed-off-by: Michael Kelley <mikelley@microsoft.com> --- arch/x86/kernel/cpu/mshyperv.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 1c72f38..65b2f88 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -20,6 +20,7 @@ #include <linux/interrupt.h> #include <linux/irq.h> #include <linux/kexec.h> +#include <linux/i8253.h> #include <asm/processor.h> #include <asm/hypervisor.h> #include <asm/hyperv-tlfs.h> @@ -295,6 +296,16 @@ static void __init ms_hyperv_init_platform(void) if (efi_enabled(EFI_BOOT)) x86_platform.get_nmi_reason = hv_get_nmi_reason; + /* + * Hyper-V VMs have a PIT emulation quirk such that zeroing the + * counter register during PIT shutdown restarts the PIT. So it + * continues to interrupt @18.2 HZ. Setting i8253_clear_counter + * to false tells pit_shutdown() not to zero the counter so that + * the PIT really is shutdown. Generation 2 VMs don't have a PIT, + * and setting this value has no effect. + */ + i8253_clear_counter = false; + #if IS_ENABLED(CONFIG_HYPERV) /* * Setup the hook to get control post apic initialization. -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [tip:x86/urgent] x86/hyper-v: Enable PIT shutdown quirk 2018-11-04 3:48 ` [PATCH v2 2/2] x86/hyper-v: Enable " Michael Kelley @ 2018-11-04 10:10 ` tip-bot for Michael Kelley 0 siblings, 0 replies; 5+ messages in thread From: tip-bot for Michael Kelley @ 2018-11-04 10:10 UTC (permalink / raw) To: linux-tip-commits Cc: jasowang, virtualization, olaf, daniel.lezcano, apw, jgross, mingo, mikelley, hpa, vkuznets, tglx, kys, linux-kernel, devel, akataria, gregkh, marcelo.cerri Commit-ID: 1de72c706488b7be664a601cf3843bd01e327e58 Gitweb: https://git.kernel.org/tip/1de72c706488b7be664a601cf3843bd01e327e58 Author: Michael Kelley <mikelley@microsoft.com> AuthorDate: Sun, 4 Nov 2018 03:48:57 +0000 Committer: Thomas Gleixner <tglx@linutronix.de> CommitDate: Sun, 4 Nov 2018 11:04:46 +0100 x86/hyper-v: Enable PIT shutdown quirk Hyper-V emulation of the PIT has a quirk such that the normal PIT shutdown path doesn't work, because clearing the counter register restarts the timer. Disable the counter clearing on PIT shutdown. Signed-off-by: Michael Kelley <mikelley@microsoft.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org> Cc: "devel@linuxdriverproject.org" <devel@linuxdriverproject.org> Cc: "daniel.lezcano@linaro.org" <daniel.lezcano@linaro.org> Cc: "virtualization@lists.linux-foundation.org" <virtualization@lists.linux-foundation.org> Cc: "jgross@suse.com" <jgross@suse.com> Cc: "akataria@vmware.com" <akataria@vmware.com> Cc: "olaf@aepfle.de" <olaf@aepfle.de> Cc: "apw@canonical.com" <apw@canonical.com> Cc: vkuznets <vkuznets@redhat.com> Cc: "jasowang@redhat.com" <jasowang@redhat.com> Cc: "marcelo.cerri@canonical.com" <marcelo.cerri@canonical.com> Cc: KY Srinivasan <kys@microsoft.com> Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/1541303219-11142-3-git-send-email-mikelley@microsoft.com --- arch/x86/kernel/cpu/mshyperv.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 1c72f3819eb1..e81a2db42df7 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -20,6 +20,7 @@ #include <linux/interrupt.h> #include <linux/irq.h> #include <linux/kexec.h> +#include <linux/i8253.h> #include <asm/processor.h> #include <asm/hypervisor.h> #include <asm/hyperv-tlfs.h> @@ -295,6 +296,16 @@ static void __init ms_hyperv_init_platform(void) if (efi_enabled(EFI_BOOT)) x86_platform.get_nmi_reason = hv_get_nmi_reason; + /* + * Hyper-V VMs have a PIT emulation quirk such that zeroing the + * counter register during PIT shutdown restarts the PIT. So it + * continues to interrupt @18.2 HZ. Setting i8253_clear_counter + * to false tells pit_shutdown() not to zero the counter so that + * the PIT really is shutdown. Generation 2 VMs don't have a PIT, + * and setting this value has no effect. + */ + i8253_clear_counter_on_shutdown = false; + #if IS_ENABLED(CONFIG_HYPERV) /* * Setup the hook to get control post apic initialization. ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-11-04 10:11 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-11-04 3:48 [PATCH v2 0/2] i8253: Fix PIT shutdown quirk on Hyper-V Michael Kelley 2018-11-04 3:48 ` [PATCH v2 1/2] i8253: Add support for PIT shutdown quirk Michael Kelley 2018-11-04 10:09 ` [tip:x86/urgent] clockevents/drivers/i8253: " tip-bot for Michael Kelley 2018-11-04 3:48 ` [PATCH v2 2/2] x86/hyper-v: Enable " Michael Kelley 2018-11-04 10:10 ` [tip:x86/urgent] " tip-bot for Michael Kelley
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).