linux/arch/x86/kernel
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
..
acpi - Get rid of static_cpu_has() - one less API to care about testing CPU 2026-08-18 19:09:42 -07:00
apic - Get rid of static_cpu_has() - one less API to care about testing CPU 2026-08-18 19:09:42 -07:00
cpu x86/mce: Fix hardware debug register corruption on task migration 2026-09-23 11:28:56 -07:00
fpu - Get rid of static_cpu_has() - one less API to care about testing CPU 2026-08-18 19:09:42 -07:00
kprobes x86/kprobes: Fix crash when probing CS CALL instructions 2026-09-17 09:48:42 +02:00
.gitignore
alternative.c x86/kprobes: Fix crash when probing CS CALL instructions 2026-09-17 09:48:42 +02:00
amd_gart_64.c dma-direct: pass attrs to dma_capable() for DMA_ATTR_CC_SHARED checks 2026-07-31 08:40:59 +02:00
amd_nb.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
amd_node.c x86/amd_node: Fix PCI device reference counting in amd_smn_init() 2026-09-10 18:05:43 -07:00
aperture_64.c
apm_32.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
asm-offsets_32.c
asm-offsets_64.c
asm-offsets.c x86/entry/vdso32: Remove open-coded DWARF in sigreturn.S 2026-01-13 16:37:58 -08:00
audit_64.c
bootflag.c
callthunks.c x86/paravirt: Remove not needed includes of paravirt.h 2026-01-12 11:26:52 +01:00
cet.c
cfi.c x86/kcfi: Optimize call sequence 2026-07-30 12:59:22 +02:00
check.c
cpuid.c x86/cpuid: Rename cpuid_leaf()/cpuid_subleaf() APIs 2026-05-08 23:10:14 +02:00
crash_dump_32.c
crash_dump_64.c
crash.c x86/crash: Use crash_prepare_headers() helper to simplify code 2026-06-30 18:49:06 +03:00
devicetree.c x86/dt: Parse the Wakeup Mailbox for Intel processors 2026-05-28 20:01:25 +00:00
doublefault_32.c
dumpstack_32.c
dumpstack_64.c
dumpstack.c x86/dumpstack: Prevent KASAN false positive warnings in __show_regs() 2025-10-29 13:07:21 +01:00
e820.c x86/boot/e820: Re-enable BIOS fallback if e820 table is empty 2026-05-07 10:04:54 +02:00
early_printk.c
early-quirks.c
ebda.c
eisa.c
espfix_64.c
fred.c x86/fred: Remove kernel log message when initializing exceptions 2026-03-27 16:38:24 +01:00
ftrace_32.S
ftrace_64.S x86/fgraph: Fix return_to_handler regs.rsp value 2026-01-30 13:40:08 -08:00
ftrace.c x86/ftrace: Relocate %rip-relative percpu refs in dynamic trampolines 2026-05-27 15:23:37 -07:00
head_32.S arch, mm: consolidate empty_zero_page 2026-04-05 13:53:01 -07:00
head_64.S arch, mm: consolidate empty_zero_page 2026-04-05 13:53:01 -07:00
head32.c
head64.c
hpet.c clocksource: Rewrite watchdog code completely 2026-03-20 13:36:32 +01:00
hw_breakpoint.c x86: Restrict KVM-induced symbol exports to KVM modules where obvious/possible 2025-11-12 15:29:38 -08:00
i8237.c syscore: Pass context data to callbacks 2025-11-14 10:01:52 +01:00
i8253.c x86/cpu: Remove unused !CONFIG_X86_TSC code 2026-06-11 10:25:34 +02:00
i8259.c x86/irq: Move IOAPIC misrouted and PIC/APIC error counts into irq_stats 2026-05-26 16:21:12 +02:00
ibt_selftest.S
idt.c x86/kvm/vmx: Fix x86_64 CFI build 2026-05-28 11:31:50 +02:00
io_delay.c
ioport.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
irq_32.c
irq_64.c
irq_work.c x86/irq: Make irqstats array based 2026-05-26 16:21:12 +02:00
irq.c x86/irq: Add missing 's' back to thermal event printout 2026-06-13 15:47:59 +02:00
irqflags.S
irqinit.c
itmt.c x86/itmt: Don't make ITMT enablement depend on debugfs 2026-09-02 09:17:50 +02:00
jailhouse.c treewide: Explicitly include the x86 CPUID headers 2026-05-06 14:29:59 +02:00
jump_label.c
kdebugfs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
kexec-bzimage64.c crash_dump/dm-crypt: don't print in arch-specific code 2026-04-02 23:36:24 -07:00
kgdb.c kgdb: update outdated references to kgdb_wait() 2026-04-21 16:41:54 +01:00
ksysfs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
kvm.c * Fix pkey_alloc() return value when pkeys are not supported 2026-08-18 17:44:09 -07:00
kvmclock.c x86/kvmclock: Implement read_snapshot() for kvmclock clocksource 2026-06-05 14:25:03 +02:00
ldt.c x86/cpu: Hide and rename static_cpu_has() 2026-07-06 21:34:26 -07:00
machine_kexec_32.c
machine_kexec_64.c x86/tdx: Disable the TDX module during kexec and kdump 2026-04-27 15:13:39 -07:00
Makefile x86/cpu: Remove unused !CONFIG_X86_TSC code 2026-06-11 10:25:34 +02:00
mmconf-fam10h_64.c
module.c x86/alternative: Drop smp_locks glue 2026-07-13 09:23:36 -07:00
mpparse.c
msr.c x86/msr: Document the I/O-like write semantics in the msr driver 2026-07-20 19:57:33 -07:00
nmi_selftest.c
nmi.c Interrupt core code changes: 2026-06-15 13:19:41 +05:30
paravirt-spinlocks.c x86/paravirt: Trace contended_release on unlock 2026-08-07 17:58:10 +02:00
paravirt.c x86/cpu updates for v7.2: 2026-06-15 15:25:17 +05:30
pci-dma.c dma-direct: make dma_direct_map_phys() honor DMA_ATTR_CC_SHARED 2026-07-31 08:44:03 +02:00
pcspeaker.c
perf_regs.c
platform-quirks.c
pmem.c x86/pmem: Check for platform_device_alloc() retval 2026-06-04 08:31:56 -07:00
probe_roms.c
process_32.c x86/process/32: Use correct type for 'gs' variable in __show_regs() to avoid zero-extension 2026-03-31 09:50:10 +02:00
process_64.c x86/cpu: Hide and rename static_cpu_has() 2026-07-06 21:34:26 -07:00
process.c x86/cpu: Hide and rename static_cpu_has() 2026-07-06 21:34:26 -07:00
process.h
ptrace.c
pvclock.c
quirks.c
reboot_fixups_32.c
reboot.c Arm: 2026-04-17 07:18:03 -07:00
relocate_kernel_32.S
relocate_kernel_64.S x86/kexec: Push kjump return address even for non-kjump kexec 2026-05-08 17:00:12 +02:00
resource.c pcmcia: remove obsolete host controller drivers 2026-03-30 07:28:13 +02:00
rethook.c objtool: Remove newlines and tabs from annotation macros 2025-12-03 19:42:37 +01:00
rtc.c x86: rtc: Drop PNP device check 2026-02-26 18:48:43 +01:00
setup_percpu.c
setup.c Bootconfig updates for v7.3: 2026-08-25 08:59:09 -07:00
sev_verify_cbit.S
shstk.c x86/shstk: Prevent deadlock during shstk sigreturn 2026-04-20 22:54:24 +02:00
signal_32.c x86/cpu: Hide and rename static_cpu_has() 2026-07-06 21:34:26 -07:00
signal_64.c
signal.c
smp.c x86/irq: Make irqstats array based 2026-05-26 16:21:12 +02:00
smpboot.c x86/alternative: Drop smp_locks glue 2026-07-13 09:23:36 -07:00
stacktrace.c
static_call.c x86/paravirt: Use static_call() for the paravirt spinlock ops 2026-08-07 17:58:09 +02:00
step.c
sys_ia32.c fs: fix archiecture-specific compat_ftruncate64 2026-03-23 12:41:57 +01:00
sys_x86_64.c
tboot.c
time.c x86/cpu: Hide and rename static_cpu_has() 2026-07-06 21:34:26 -07:00
tls.c x86/tls: Clean up 'sel' variable usage in do_set_thread_area() 2026-03-31 09:50:11 +02:00
tls.h
trace_clock.c
trace.c
traps.c x86/fpu: Remove MATH_EMULATION and related glue code 2026-05-08 07:33:03 +02:00
tsc_msr.c x86/tsc: Stop using 32-bit MSR interfaces 2026-07-02 11:54:52 +02:00
tsc_sync.c
tsc.c x86/tsc: Stop using 32-bit MSR interfaces 2026-07-02 11:54:52 +02:00
umip.c x86/traps: Consolidate user fixups in the #GP handler 2026-03-19 15:11:13 -07:00
unwind_frame.c
unwind_guess.c
unwind_orc.c objtool/x86: Reorder ORC register numbering 2026-03-18 09:38:52 +01:00
uprobes.c uprobes/x86: Move optimized uprobe from nop5 to nop10 2026-07-03 16:30:36 +02:00
verify_cpu.S
vm86_32.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
vmcore_info_32.c
vmcore_info_64.c
vmlinux.lds.S - Get rid of static_cpu_has() - one less API to care about testing CPU 2026-08-18 19:09:42 -07:00
vsmp_64.c x86/paravirt: Remove not needed includes of paravirt.h 2026-01-12 11:26:52 +01:00
x86_init.c x86/realmode: Make the location of the trampoline configurable 2026-05-28 20:01:25 +00:00