1
linux/arch/x86/kernel/apic
Zhang Rui ffd95846c6 x86/apic: Always explicitly disarm TSC-deadline timer
New processors have become pickier about the local APIC timer state
before entering low power modes. These low power modes are used (for
example) when you close your laptop lid and suspend. If you put your
laptop in a bag and it is not in this low power mode, it is likely
to get quite toasty while it quickly sucks the battery dry.

The problem boils down to some CPUs' inability to power down until the
CPU recognizes that the local APIC timer is shut down. The current
kernel code works in one-shot and periodic modes but does not work for
deadline mode. Deadline mode has been the supported and preferred mode
on Intel CPUs for over a decade and uses an MSR to drive the timer
instead of an APIC register.

Disable the TSC Deadline timer in lapic_timer_shutdown() by writing to
MSR_IA32_TSC_DEADLINE when in TSC-deadline mode. Also avoid writing
to the initial-count register (APIC_TMICT) which is ignored in
TSC-deadline mode.

Note: The APIC_LVTT|=APIC_LVT_MASKED operation should theoretically be
enough to tell the hardware that the timer will not fire in any of the
timer modes. But mitigating AMD erratum 411[1] also requires clearing
out APIC_TMICT. Solely setting APIC_LVT_MASKED is also ineffective in
practice on Intel Lunar Lake systems, which is the motivation for this
change.

1. 411 Processor May Exit Message-Triggered C1E State Without an Interrupt if Local APIC Timer Reaches Zero - https://www.amd.com/content/dam/amd/en/documents/archived-tech-docs/revision-guides/41322_10h_Rev_Gd.pdf

Fixes: 279f146143 ("x86: apic: Use tsc deadline for oneshot when available")
Suggested-by: Dave Hansen <dave.hansen@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Tested-by: Todd Brandt <todd.e.brandt@intel.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20241015061522.25288-1-rui.zhang%40intel.com
2024-10-15 05:45:18 -07:00
..
apic_common.c x86/apic: Remove yet another dubious callback 2024-02-15 22:07:41 +01:00
apic_flat_64.c x86/apic: Remove logical destination mode for 64-bit 2024-08-09 14:34:16 +02:00
apic_noop.c x86/apic: Remove check_apicid_used() and ioapic_phys_id_map() 2024-02-15 22:07:39 +01:00
apic_numachip.c x86/apic: Remove the pointless writeback of boot_cpu_physical_apicid 2024-02-15 22:07:41 +01:00
apic.c x86/apic: Always explicitly disarm TSC-deadline timer 2024-10-15 05:45:18 -07:00
bigsmp_32.c x86/apic: Remove the pointless writeback of boot_cpu_physical_apicid 2024-02-15 22:07:41 +01:00
hw_nmi.c
init.c
io_apic.c x86/ioapic: Cleanup remaining coding style issues 2024-08-07 18:13:29 +02:00
ipi.c Major microcode loader restructuring, cleanup and improvements by Thomas 2023-11-04 08:46:37 -10:00
local.h x86/apic: Remove yet another dubious callback 2024-02-15 22:07:41 +01:00
Makefile arch/x86: Fix typos 2024-01-03 11:46:22 +01:00
msi.c Revert "x86/apic/msi: Enable PCI/IMS" 2024-05-15 17:02:04 -05:00
probe_32.c x86/apic: Remove yet another dubious callback 2024-02-15 22:07:41 +01:00
probe_64.c
vector.c genirq/cpuhotplug, x86/vector: Prevent vector leak during CPU offline 2024-05-23 21:51:50 +02:00
x2apic_cluster.c x86/cpu: Improve readability of per-CPU cpumask initialization code 2024-04-10 07:02:33 +02:00
x2apic_phys.c x86/apic: Remove the pointless writeback of boot_cpu_physical_apicid 2024-02-15 22:07:41 +01:00
x2apic_uv_x.c x86/apic: Remove the pointless writeback of boot_cpu_physical_apicid 2024-02-15 22:07:41 +01:00