linux/arch/x86/kernel/cpu
Masami Hiramatsu (Google) b8d1d5b63a x86/mce: Fix hardware debug register corruption on task migration
In exc_machine_check_user(), local_db_save() and local_db_restore() are
invoked in the outer entry stubs (DEFINE_IDTENTRY_MCE_USER,
DEFINE_FREDENTRY_MCE, and DEFINE_IDTENTRY_RAW), surrounding
exc_machine_check_user().

However, exc_machine_check_user() calls irqentry_exit_to_user_mode(), which
handles pending thread work and may schedule() if TIF_NEED_RESCHED is set. If
the task migrates to another CPU during schedule(), local_db_restore() runs on
the new CPU with the dr7 state saved from the old CPU. This corrupts the new
CPU's DR7 hardware debug register and leaves the old CPU's DR7 disabled.  In
short, local_db_save() and local_db_restore() pair must be run on the same
CPU.

To fix this, move local_db_save() and local_db_restore() inside
exc_machine_check_user() and exc_machine_check_kernel(). In
exc_machine_check_user(), DR7 is saved and restored strictly around
do_machine_check() to avoid schedule() during migration. In
exc_machine_check_kernel(), local_db_save() is called at the entry point to
prevent early memory accesses from triggering nested #DB exceptions, and
restored on all exits.

Fixes: cd840e424f ("x86/entry, mce: Disallow #DB during #MC")
Assisted-by: LLM
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: <stable@kernel.org>
Link: https://patch.msgid.link/179005109564.388919.3937970081044095776.stgit@devnote2
2026-09-23 11:28:56 -07:00
..
mce x86/mce: Fix hardware debug register corruption on task migration 2026-09-23 11:28:56 -07:00
microcode x86/microcode/intel: Reject problematic loading on Granite Rapids systems 2026-09-17 16:54:20 -07:00
mtrr x86/mtrr: Stop using 32-bit MSR interfaces 2026-07-17 11:25:49 +02:00
resctrl - How refreshing: no new features but a whole pile of fixes to more or less 2026-08-18 18:32:24 -07:00
sgx mm: use linear_page_[index, delta]() consistently 2026-08-04 19:19:01 -07:00
.gitignore
acrn.c x86/irq: Make irqstats array based 2026-05-26 16:21:12 +02:00
amd_cache_disable.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
amd.c x86/msr updates for v7.3: 2026-08-18 14:02:15 -07:00
aperfmperf.c syscore: Pass context data to callbacks 2025-11-14 10:01:52 +01:00
bhyve.c x86/cpu: Detect FreeBSD Bhyve hypervisor 2025-09-15 14:06:44 +02:00
bugs.c - Get rid of static_cpu_has() - one less API to care about testing CPU 2026-08-18 19:09:42 -07:00
bus_lock.c sysctl: remove CONFIG_PROC_SYSCTL, it just mirrors CONFIG_SYSCTL 2026-08-05 15:28:23 +02:00
cacheinfo.c x86/cpu: Hide and rename static_cpu_has() 2026-07-06 21:34:26 -07:00
centaur.c x86/cpu: Stop using 32-bit MSR interfaces 2026-07-02 11:54:52 +02:00
common.c - Get rid of static_cpu_has() - one less API to care about testing CPU 2026-08-18 19:09:42 -07:00
cpu.h x86/cpu: Remove obsolete aperfmperf_get_khz() declaration 2026-06-05 15:10:25 +02:00
cpuid_0x2_table.c x86/cpu: Consolidate CPUID leaf 0x2 tables 2025-03-25 10:23:04 +01:00
cpuid_parser.c x86/CPU: Rename struct cpuid_read_output to struct cpuid_output 2026-08-05 07:40:33 -07:00
cpuid_parser.h x86/CPU: Rename struct cpuid_read_output to struct cpuid_output 2026-08-05 07:40:33 -07:00
cpuid-deps.c x86/mm: Disable broadcast TLB flush when PCID is disabled 2026-05-20 14:15:07 -07:00
cyrix.c x86/cpu: Drop vestigial PBE logic in AMD/Hygon/Centaur/Cyrix 2025-12-14 09:57:13 +01:00
debugfs.c x86/cpu: Prefix hexadecimal values with 0x in cpu_debug_show() 2025-02-27 13:26:53 +01:00
feat_ctl.c x86/featctl: Stop using 32-bit MSR interfaces 2026-07-17 11:30:36 +02:00
hygon.c x86/hygon: Stop using 32-bit MSR interfaces 2026-07-02 11:54:51 +02:00
hypervisor.c xen: Drop CONFIG_XEN_PVHVM 2026-08-06 13:18:31 +02:00
intel_epb.c syscore: Pass context data to callbacks 2025-11-14 10:01:52 +01:00
intel.c - The usual pile of smallish cleanups and fixlets all over the place 2026-08-18 18:34:58 -07:00
Makefile x86/cpu: Remove Makefile rule for removed UMC CPU support 2026-07-11 18:07:30 -07:00
match.c x86/topo: Map vendor CPU types to generic Linux such types 2026-07-23 14:23:15 -07:00
mkcapflags.sh
mshyperv.c clocksource: hyper-v: Remove support for stimer interrupts in message mode 2026-08-24 00:36:14 +00:00
perfctr-watchdog.c
powerflags.c
proc.c cpufreq: Allow arch_freq_get_on_cpu to return an error 2025-02-17 18:09:20 +00:00
rdrand.c
scattered.c x86/cpu/scattered: Sort it properly 2026-07-31 18:52:49 -07:00
topology_amd.c x86/topo: Map vendor CPU types to generic Linux such types 2026-07-23 14:23:15 -07:00
topology_common.c - Get rid of static_cpu_has() - one less API to care about testing CPU 2026-08-18 19:09:42 -07:00
topology_ext.c x86/cpuid: Rename cpuid_leaf()/cpuid_subleaf() APIs 2026-05-08 23:10:14 +02:00
topology.c x86/topology: use bitmap_weight_from() 2026-03-23 13:33:51 -04:00
topology.h x86/topo: Map vendor CPU types to generic Linux such types 2026-07-23 14:23:15 -07:00
transmeta.c - Get rid of static_cpu_has() - one less API to care about testing CPU 2026-08-18 19:09:42 -07:00
tsx.c x86/tsx: Get the tsx= command line parameter with early_param() 2025-10-24 18:35:17 +02:00
umwait.c syscore: Pass context data to callbacks 2025-11-14 10:01:52 +01:00
vmware.c treewide: Explicitly include the x86 CPUID headers 2026-05-06 14:29:59 +02:00
vortex.c
zhaoxin.c x86/cpu: Stop using 32-bit MSR interfaces 2026-07-02 11:54:52 +02:00