linux/arch/x86/kernel
Zhang Rui 8462805788 x86/apic: Always explicitly disarm TSC-deadline timer
commit ffd95846c6 upstream.

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
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-10-22 15:39:29 +02:00
..
acpi x86/i8259: Skip probing when ACPI/MADT advertises PCAT compatibility 2023-11-08 17:30:46 +01:00
apic x86/apic: Always explicitly disarm TSC-deadline timer 2024-10-22 15:39:29 +02:00
cpu x86/resctrl: Annotate get_mem_config() functions as __init 2024-10-22 15:39:29 +02:00
fpu x86/fpu: Set X86_FEATURE_OSXSAVE feature after enabling OSXSAVE in CR4 2023-08-30 16:23:17 +02:00
kprobes x86/ibt,ftrace: Search for __fentry__ location 2024-10-17 15:07:37 +02:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
alternative.c x86/alternative: Make custom return thunk unconditional 2024-03-01 13:16:49 +01:00
amd_gart_64.c dma-mapping: split <linux/dma-mapping.h> 2020-10-06 07:07:03 +02:00
amd_nb.c x86/amd_nb: Check for invalid SMN reads 2024-07-05 09:12:45 +02:00
apb_timer.c x86/apb_timer: Drop unused TSC calibration 2020-05-27 13:05:59 +02:00
aperture_64.c
apm_32.c x86/APM: drop the duplicate APM_MINOR_DEV macro 2023-09-19 12:20:17 +02:00
asm-offsets_32.c x86/stackprotector/32: Make the canary into a regular percpu variable 2024-04-13 12:58:45 +02:00
asm-offsets_64.c x86/xen: Drop USERGS_SYSRET64 paravirt call 2024-05-25 16:19:05 +02:00
asm-offsets.c x86: remove address space overrides using set_fs() 2020-09-08 22:21:36 -04:00
audit_64.c x86/audit: Fix a -Wmissing-prototypes warning for ia32_classify_syscall() 2020-05-19 18:03:07 +02:00
bootflag.c
cc_platform.c x86/sev: Add an x86 version of cc_platform_has() 2021-11-18 14:04:32 +01:00
check.c
cpuid.c
crash_core_32.c mm: reorder includes after introduction of linux/pgtable.h 2020-06-09 09:39:13 -07:00
crash_core_64.c mm: reorder includes after introduction of linux/pgtable.h 2020-06-09 09:39:13 -07:00
crash_dump_32.c
crash_dump_64.c
crash.c x86/crash: Disable virt in core NMI crash handler to avoid double shootdown 2023-03-11 16:39:58 +01:00
devicetree.c x86/of: Return consistent error type from x86_of_pci_irq_enable() 2024-08-19 05:40:40 +02:00
doublefault_32.c x86/stackprotector/32: Make the canary into a regular percpu variable 2024-04-13 12:58:45 +02:00
dumpstack_32.c x86/32: Remove CONFIG_DOUBLEFAULT 2020-04-14 14:24:05 +02:00
dumpstack_64.c x86/dumpstack/64: Add noinstr version of get_stack_info() 2020-09-09 11:33:19 +02:00
dumpstack.c x86/show_trace_log_lvl: Ensure stack pointer is aligned, again 2023-05-30 12:57:58 +01:00
e820.c x86/boot: Fix memremap of setup_indirect structures 2022-03-16 14:16:02 +01:00
early_printk.c mm: reorder includes after introduction of linux/pgtable.h 2020-06-09 09:39:13 -07:00
early-quirks.c x86/gpu: Reserve stolen memory for first integrated Intel GPU 2022-01-27 10:53:41 +01:00
ebda.c
eisa.c
espfix_64.c mm: introduce include/linux/pgtable.h 2020-06-09 09:39:13 -07:00
ftrace_32.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
ftrace_64.S x86/ibt,ftrace: Make function-graph play nice 2022-09-20 12:38:33 +02:00
ftrace.c x86/returnthunk: Allow different return thunks 2024-03-01 13:16:49 +01:00
head32.c
head64.c x86/head/64: Re-enable stack protection 2024-04-13 12:59:58 +02:00
head_32.S x86/stackprotector/32: Make the canary into a regular percpu variable 2024-04-13 12:58:45 +02:00
head_64.S x86/head/64: Re-enable stack protection 2024-04-13 12:59:58 +02:00
hpet.c rtc: Check return value from mc146818_get_time() 2022-12-14 11:31:55 +01:00
hw_breakpoint.c x86/debug: Prevent data breakpoints on cpu_dr7 2021-02-10 09:29:22 +01:00
i8237.c
i8253.c
i8259.c x86/i8259: Skip probing when ACPI/MADT advertises PCAT compatibility 2023-11-08 17:30:46 +01:00
idt.c This feature enhances the current guest memory encryption support 2020-10-14 10:21:34 -07:00
ima_arch.c ima: force signature verification when CONFIG_KEXEC_SIG is configured 2022-07-21 21:20:11 +02:00
io_delay.c
ioport.c x86/ioperm: Prevent a memory leak when fork fails 2020-05-28 21:36:20 +02:00
irq_32.c x86/irq: Rework handle_irq() for 64-bit 2020-06-11 15:15:12 +02:00
irq_64.c x86/irq: Make run_on_irqstack_cond() typesafe 2020-09-22 22:13:34 +02:00
irq_work.c x86/entry: Convert various system vectors 2020-06-11 15:15:14 +02:00
irq.c x86/irq: Ensure PI wakeup handler is unregistered before module unload 2021-11-18 14:03:41 +01:00
irqflags.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
irqinit.c x86/i8259: Mark legacy PIC interrupts with IRQ_LEVEL 2023-02-01 08:23:27 +01:00
itmt.c sysctl: pass kernel pointers to ->proc_handler 2020-04-27 02:07:40 -04:00
jailhouse.c locking/seqlock, headers: Untangle the spaghetti monster 2020-08-06 16:13:13 +02:00
jump_label.c x86/jump_label: Move 'inline' keyword placement 2020-03-27 11:05:41 +01:00
kdebugfs.c x86/boot: Fix memremap of setup_indirect structures 2022-03-16 14:16:02 +01:00
kexec-bzimage64.c x86/kexec: Use up-to-dated screen_info copy to fill boot params 2020-10-14 17:05:03 +02:00
kgdb.c x86/debug: Change thread.debugreg6 to thread.virtual_dr6 2020-09-04 15:12:58 +02:00
ksysfs.c x86/boot: Fix memremap of setup_indirect structures 2022-03-16 14:16:02 +01:00
kvm.c x86, kvm: use proper ASM macros for kvm_vcpu_is_preempted 2022-07-25 11:26:52 +02:00
kvmclock.c x86/kvm: Do not try to disable kvmclock if it was not enabled 2024-01-25 14:37:52 -08:00
ldt.c x86/ldt: use "pr_info_once()" instead of open-coding it badly 2020-07-05 12:50:20 -07:00
machine_kexec_32.c mm: don't include asm/pgtable.h if linux/mm.h is already included 2020-06-09 09:39:13 -07:00
machine_kexec_64.c mm: don't include asm/pgtable.h if linux/mm.h is already included 2020-06-09 09:39:13 -07:00
Makefile x86/head/64: Re-enable stack protection 2024-04-13 12:59:58 +02:00
mmconf-fam10h_64.c
module.c x86: Undo return-thunk damage 2022-07-25 11:26:36 +02:00
mpparse.c Surgery of the MSI interrupt handling to prepare the support of upcoming 2020-10-12 11:40:41 -07:00
msr.c x86/MSR: Filter MSR writes through X86_IOC_WRMSR_REGS ioctl too 2021-03-04 11:37:26 +01:00
nmi_selftest.c
nmi.c x86/bugs: Use ALTERNATIVE() instead of mds_user_clear static key 2024-04-13 12:58:57 +02:00
paravirt_patch.c x86/xen: Drop USERGS_SYSRET64 paravirt call 2024-05-25 16:19:05 +02:00
paravirt-spinlocks.c
paravirt.c x86/xen: Drop USERGS_SYSRET64 paravirt call 2024-05-25 16:19:05 +02:00
pci-dma.c dma-mapping: move dma-debug.h to kernel/dma/ 2020-10-06 07:07:05 +02:00
pci-iommu_table.c
pci-swiotlb.c
pcspeaker.c
perf_regs.c perf/arch: Remove perf_sample_data::regs_user_copy 2020-11-09 18:12:34 +01:00
platform-quirks.c
pmem.c x86/pmem: Fix platform-device leak in error path 2022-08-21 15:15:33 +02:00
probe_roms.c maccess: make get_kernel_nofault() check for minimal type compatibility 2020-06-18 12:10:37 -07:00
process_32.c x86/resctl: fix scheduler confusion with 'current' 2023-03-11 16:40:19 +01:00
process_64.c x86/resctl: fix scheduler confusion with 'current' 2023-03-11 16:40:19 +01:00
process.c x86: Increase brk randomness entropy for 64-bit systems 2024-09-04 13:17:36 +02:00
process.h
ptrace.c x86/debug: Change thread.debugreg6 to thread.virtual_dr6 2020-09-04 15:12:58 +02:00
pvclock.c x86/vdso: Use generic VDSO clock mode storage 2020-02-17 14:40:23 +01:00
quirks.c x86, powerpc: Rename memcpy_mcsafe() to copy_mc_to_{user, kernel}() 2020-10-06 11:18:04 +02:00
reboot_fixups_32.c
reboot.c x86/reboot: Disable virtualization in an emergency if SVM is supported 2023-03-11 16:39:58 +01:00
relocate_kernel_32.S x86/kexec: Disable RET on kexec 2022-07-25 11:26:51 +02:00
relocate_kernel_64.S x86/kexec: Disable RET on kexec 2022-07-25 11:26:51 +02:00
resource.c
rtc.c
setup_percpu.c x86/stackprotector/32: Make the canary into a regular percpu variable 2024-04-13 12:58:45 +02:00
setup.c x86/mm: Fix RESERVE_BRK() for older binutils 2023-11-08 17:30:46 +01:00
sev_verify_cbit.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
sev-es-shared.c x86/sev: Check for user-space IOIO pointing to kernel space 2023-10-25 11:54:19 +02:00
sev-es.c x86/sev: Check IOBM for IOIO exceptions from user-space 2023-10-25 11:54:19 +02:00
signal_compat.c arm64: mte: Add specific SIGSEGV codes 2020-09-04 12:46:06 +01:00
signal.c entry: Add support for TIF_NOTIFY_SIGNAL 2023-01-04 11:39:18 +01:00
smp.c x86/reboot: Disable SVM, not just VMX, when stopping CPUs 2023-03-11 16:39:58 +01:00
smpboot.c x86/smp: Use dedicated cache-line for mwait_play_dead() 2023-07-27 08:43:30 +02:00
stacktrace.c stacktrace: Remove reliable argument from arch_stack_walk() callback 2020-09-18 14:24:16 +01:00
static_call.c x86/returnthunk: Allow different return thunks 2024-03-01 13:16:49 +01:00
step.c ptrace: Reimplement PTRACE_KILL by always sending SIGKILL 2022-06-09 10:20:49 +02:00
sys_ia32.c x86: switch to kernel_clone() 2020-08-20 13:12:58 +02:00
sys_x86_64.c x86/mm: Cleanup the control_va_addr_alignment() __setup handler 2022-06-09 10:21:06 +02:00
sysfb_efi.c efi: sysfb_efi: Add quirk for Lenovo Yoga Book X91F/L 2023-04-20 12:10:27 +02:00
sysfb_simplefb.c x86/sysfb: Fix check for bad VRAM size 2020-01-20 10:57:53 +01:00
sysfb.c
tboot.c mm/gup: prevent gup_fast from racing with COW during fork 2020-12-30 11:53:54 +01:00
time.c x86: stop playing stack games in profile_pc() 2024-07-05 09:12:51 +02:00
tls.c x86/stackprotector/32: Make the canary into a regular percpu variable 2024-04-13 12:58:45 +02:00
tls.h x86: switch to ->regset_get() 2020-07-27 14:31:07 -04:00
topology.c x86/headers: Remove APIC headers from <asm/smp.h> 2020-08-06 16:13:09 +02:00
trace_clock.c
tracepoint.c x86/entry: Convert reschedule interrupt to IDTENTRY_SYSVEC_SIMPLE 2020-06-11 15:15:16 +02:00
traps.c x86/CPU/AMD: Fix the DIV(0) initial fix attempt 2023-08-26 15:26:58 +02:00
tsc_msr.c Misc fixes and small updates all around the place: 2020-08-15 10:38:03 -07:00
tsc_sync.c x86/tsc: Trust initial offset in architectural TSC-adjust MSRs 2024-06-16 13:31:59 +02:00
tsc.c clocksource: Reduce clocksource-skew threshold 2022-01-27 10:54:05 +01:00
umip.c x86/insn: Rename insn_decode() to insn_decode_from_regs() 2022-07-25 11:26:10 +02:00
unwind_frame.c fork-v5.9 2020-08-04 14:47:45 -07:00
unwind_guess.c
unwind_orc.c x86/unwind/orc: Fix unreliable stack dump with gcov 2022-11-03 23:57:51 +09:00
uprobes.c uprobes/x86: Allow to probe a NOP instruction with 0x66 prefix 2023-01-14 10:15:21 +01:00
verify_cpu.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
vm86_32.c mmap locking API: use coccinelle to convert mmap_sem rwsem call sites 2020-06-09 09:39:14 -07:00
vmlinux.lds.S x86: Fix .brk attribute in linker script 2023-11-08 17:30:48 +01:00
vsmp_64.c
x86_init.c x86/rtc: Remove __init for runtime functions 2023-04-20 12:10:28 +02:00