From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: sashiko-reviews@lists.linux.dev
Cc: sashiko-bot@kernel.org, linux-trace-kernel@vger.kernel.org,
linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v15 03/12] x86/hw_breakpoints: Add arch_modify_local_hw_breakpoint_addr() API
Date: Mon, 14 Sep 2026 14:13:18 +0900 [thread overview]
Message-ID: <20260914141318.0a8d12d9cceb3a50bb3d36f5@kernel.org> (raw)
In-Reply-To: <20260907040203.BA2941F00A3A@smtp.kernel.org>
On Mon, 07 Sep 2026 04:02:03 +0000
sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] Modifying a debug address register while the breakpoint is enabled in DR7 violates the Intel SDM. This can occur due to a race condition with an NMI because the `cpu_dr7` shadow state is not temporarily updated.
> --
>
> commit ca38cc4e9ed0533dfe16175c78dba60903420a8b
> Author: Jinchao Wang <wangjinchao600@gmail.com>
>
> x86/hw_breakpoints: Add arch_modify_local_hw_breakpoint_addr() API
>
> Wprobe needs to move an active per-CPU watchpoint without releasing and
> reserving its hardware slot.
>
> Add arch_modify_local_hw_breakpoint_addr() as the architecture backend for
> modify_local_hw_breakpoint_addr(). It validates the new address, finds the
> installed local slot, and updates the hardware debug register and per-CPU
> shadow register.
>
> Link: https://lore.kernel.org/all/59637b96946653393a7ad3c7de094094796b39c2.1785067572.git.wangjinchao600@gmail.com/
>
> > diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c
> > index 312550be3ad2b..99f0926298a85 100644
> > --- a/arch/x86/kernel/hw_breakpoint.c
> > +++ b/arch/x86/kernel/hw_breakpoint.c
> [ ... ]
> > @@ -129,6 +129,62 @@ int arch_install_hw_breakpoint(struct perf_event *bp)
> [ ... ]
> > + do {
> > + seq = this_cpu_inc_return(cpu_dr7_seq);
> > +
> > + /* Disable breakpoint in DR7 before updating address register */
> > + dr7 = this_cpu_read(cpu_dr7);
> > + set_debugreg((dr7 & ~__encode_dr7(i, info->len, info->type)) | DR7_FIXED_1, 7);
>
> [Severity: High]
> Does arch_modify_local_hw_breakpoint_addr() need to clear the breakpoint in
> the shadow cpu_dr7 state as well?
Ah, OK, let's update cpu_dr7 too.
>
> Since the breakpoint isn't cleared in the cpu_dr7 shadow state, could an NMI
> that interrupts execution here inadvertently re-enable the breakpoint
> prematurely?
>
> If an NMI handler (such as kgdb or perf) modifies breakpoints, it increments
> cpu_dr7_seq and invokes local_db_save() and local_db_restore(). When the NMI
> completes, local_db_restore() detects the sequence mismatch and restores
> hardware DR7 using the cpu_dr7 shadow cache. Because cpu_dr7 still has this
> breakpoint enabled, the target breakpoint gets re-enabled in hardware DR7
> before the execution below resumes.
>
> > + barrier();
> > +
> > + this_cpu_write(cpu_debugreg[i], addr);
> > + barrier();
> > + set_debugreg(addr, i);
>
> [Severity: High]
> If an NMI prematurely restored DR7 as described above, won't this modify the
> debug address register while the breakpoint is enabled in DR7?
This also needs to update cpu_dr7.
Thank you,
>
> Modifying a debug address register while its corresponding DR7 enable bit is
> set violates the Intel SDM and causes spurious #DB exceptions.
>
> While the sequence loop retry mechanism will catch the mismatch, it only does
> so after this instruction has already executed, which is too late to prevent
> the spurious exception.
>
> > + barrier();
> > +
> > + /* Re-enable breakpoint in DR7 */
> > + set_debugreg(this_cpu_read(cpu_dr7) | DR7_FIXED_1, 7);
> > + barrier();
> > + } while (seq != this_cpu_read(cpu_dr7_seq));
> > +
> > + return 0;
> > +}
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/178875277830.93794.14247844688761142429.stgit@devnote2?part=3
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2026-09-14 5:13 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 3:46 [PATCH v15 00/12] tracing: wprobe: x86: Add wprobe for watchpoint Masami Hiramatsu (Google)
2026-09-07 3:46 ` [PATCH v15 01/12] x86/mce: Fix hardware debug register corruption on task migration Masami Hiramatsu (Google)
2026-09-07 3:57 ` sashiko-bot
2026-09-07 3:46 ` [PATCH v15 02/12] x86/hw_breakpoints: Make DR7 updates NMI safe Masami Hiramatsu (Google)
2026-09-07 4:00 ` sashiko-bot
2026-09-14 1:02 ` Masami Hiramatsu
2026-09-14 2:49 ` Masami Hiramatsu
2026-09-07 3:46 ` [PATCH v15 03/12] x86/hw_breakpoints: Add arch_modify_local_hw_breakpoint_addr() API Masami Hiramatsu (Google)
2026-09-07 4:02 ` sashiko-bot
2026-09-14 5:13 ` Masami Hiramatsu [this message]
2026-09-07 3:47 ` [PATCH v15 04/12] HWBP: Add modify_local_hw_breakpoint_addr() API Masami Hiramatsu (Google)
2026-09-07 4:04 ` sashiko-bot
2026-09-07 3:47 ` [PATCH v15 05/12] tracing/wprobe: Add wprobe (watchpoint probe) trace event support Masami Hiramatsu (Google)
2026-09-07 4:15 ` sashiko-bot
2026-09-14 5:25 ` Masami Hiramatsu
2026-09-07 3:47 ` [PATCH v15 06/12] x86: hw_breakpoint: Add a kconfig to clarify when a breakpoint fires Masami Hiramatsu (Google)
2026-09-07 3:52 ` sashiko-bot
2026-09-07 3:47 ` [PATCH v15 07/12] selftests: tracing: Add a basic testcase for wprobe Masami Hiramatsu (Google)
2026-09-07 3:53 ` sashiko-bot
2026-09-07 3:47 ` [PATCH v15 08/12] selftests: tracing: Add syntax " Masami Hiramatsu (Google)
2026-09-07 3:58 ` sashiko-bot
2026-09-07 3:47 ` [PATCH v15 09/12] tracing/wprobe: Add set_wprobe and clear_wprobe event triggers Masami Hiramatsu (Google)
2026-09-07 4:10 ` sashiko-bot
2026-09-14 6:46 ` Masami Hiramatsu
2026-09-07 3:48 ` [PATCH v15 10/12] selftests: tracing: Add wprobe trigger testcase Masami Hiramatsu (Google)
2026-09-07 3:58 ` sashiko-bot
2026-09-07 3:48 ` [PATCH v15 11/12] tracing/wprobe: Support BTF typecast in fetchargs Masami Hiramatsu (Google)
2026-09-07 4:03 ` sashiko-bot
2026-09-07 3:48 ` [PATCH v15 12/12] tracing/wprobe: Support BTF struct offset resolution in set_wprobe trigger Masami Hiramatsu (Google)
2026-09-07 4:06 ` sashiko-bot
2026-09-11 7:27 ` [PATCH v15 00/12] tracing: wprobe: x86: Add wprobe for watchpoint Jinchao Wang
2026-09-12 13:36 ` Masami Hiramatsu
2026-09-14 6:16 ` Jinchao Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260914141318.0a8d12d9cceb3a50bb3d36f5@kernel.org \
--to=mhiramat@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=sashiko-bot@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox