Thread (45 messages) 45 messages, 6 authors, 10d ago

Re: [PATCH v17 01/13] x86/mce: Fix hardware debug register corruption on task migration

flat view

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Date: 2026-09-23 08:56:47
Also in: kvm, linux-doc, linux-perf-users, lkml

On Tue, 22 Sep 2026 17:27:40 -0700
Borislav Petkov [off-list ref] wrote:
On Tue, Sep 22, 2026 at 01:24:55PM +0900, Masami Hiramatsu (Google) wrote:
quoted
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

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: cd840e424f27 ("x86/entry, mce: Disallow #DB during #MC")
Assisted-by: Antigravity:gemini-3.8-flash
verify_tags: WARNING: Zapping LLM ads tag: ['Antigravity:gemini-3.8-flash'].

Needs to be:

Assisted-by: LLM

Please fix all your patches.
Ah, let me fix it.
quoted
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
Changes in v15:
 - Move local_db_save() to the entry of exc_machine_check_kernel() and
   restore it on early return from mce_check_crashing_cpu() to prevent
   nested #DB on watched variables.
Changes in v14:
 - Newly added.
---
 arch/x86/kernel/cpu/mce/core.c |   27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)
Yah, makes sense.

I'm thinking this needs to be CC:stable and I should take it in now.
OK. thanks for review!
Peter?

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

-- 
Masami Hiramatsu (Google) [off-list ref]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help