From: sashiko-bot@kernel.org
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v20 01/11] x86/hw_breakpoints: Add arch_modify_local_hw_breakpoint_addr() API
Date: Mon, 16 Nov 2026 05:47:57 +0000 [thread overview]
Message-ID: <sashiko-outbox-216226@kernel.org> (raw)
In-Reply-To: <179480676405.38065.17662254533654266956.stgit@devnote2>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] x86/hw_breakpoints: arch_modify_local_hw_breakpoint_addr()
corrupts DRs
--
commit 490e341c5679ea8c1cf5b3a39b5b39ecc93de7d0
Author: Jinchao Wang <wangjinchao600@gmail.com>
x86/hw_breakpoints: Add arch_modify_local_hw_breakpoint_addr() API
This commit adds arch_modify_local_hw_breakpoint_addr() to update the
address of an installed per-CPU hardware breakpoint on the local CPU
without releasing and re-allocating its debug register slot.
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 f846c15f21ca1..3f63f7899f95e 100644
> --- a/arch/x86/kernel/hw_breakpoint.c
> +++ b/arch/x86/kernel/hw_breakpoint.c
> @@ -133,6 +133,57 @@ int arch_install_hw_breakpoint(struct perf_event *bp)
> return 0;
> }
>
> +/*
> + * Modify the address of an installed perf counter breakpoint on local CPU.
> + *
> + * This updates the debug address register and per-CPU shadow state without
> + * changing slot allocation or DR7. The core layer (modify_local_hw_breakpoint_addr())
> + * manages updating bp->attr.bp_addr and counter_arch_bp(bp)->address.
> + *
> + * Atomic: called with IRQs disabled and handles variables and registers
> + * local to this CPU.
> + */
> +int arch_modify_local_hw_breakpoint_addr(struct perf_event *bp,
> + unsigned long addr)
> +{
> + struct arch_hw_breakpoint *info = counter_arch_bp(bp);
> + struct arch_hw_breakpoint hw;
> + struct perf_event_attr attr = bp->attr;
> + unsigned long dr7;
> + int i, ret;
> +
> + lockdep_assert_irqs_disabled();
> +
> + attr.bp_addr = addr;
> + ret = hw_breakpoint_arch_parse(bp, &attr, &hw);
> + if (ret)
> + return ret;
> +
> + for (i = 0; i < HBP_NUM; i++) {
> + if (this_cpu_read(bp_per_reg[i]) == bp)
> + break;
> + }
> +
> + if (WARN_ONCE(i == HBP_NUM, "Can't find any breakpoint slot"))
> + return -ENOENT;
> +
> + /*
> + * Temporarily clear the breakpoint enable bit in DR7 before updating the
> + * debug address register, and re-enable it afterward, to comply with the
> + * x86 hardware specification and avoid spurious #DB exceptions.
> + */
> + dr7 = this_cpu_read(cpu_dr7);
> + set_debugreg(dr7 & ~__encode_dr7(i, info->len, info->type), 7);
> +
> + this_cpu_write(cpu_debugreg[i], addr);
> + barrier();
> + set_debugreg(addr, i);
> +
> + set_debugreg(dr7, 7);
[Severity: High]
Can arch_modify_local_hw_breakpoint_addr() corrupt hardware debug
registers or prematurely re-enable hardware DR7 when host breakpoints are
temporarily disabled or switched to KVM guest state?
Several paths disable hardware DR7 (writing DR7_FIXED_1) or replace
hardware DR0-DR3 without clearing the per-CPU shadow cpu_dr7:
arch/x86/kvm/x86.c:vcpu_enter_guest() {
...
if (unlikely(vcpu->arch.switch_db_regs &&
!(vcpu->arch.switch_db_regs & KVM_DEBUGREG_AUTO_SWITCH))) {
set_debugreg(DR7_FIXED_1, 7);
set_debugreg(vcpu->arch.eff_db[0], 0);
set_debugreg(vcpu->arch.eff_db[1], 1);
set_debugreg(vcpu->arch.eff_db[2], 2);
set_debugreg(vcpu->arch.eff_db[3], 3);
}
...
}
vcpu_enter_guest() runs in normal context with IRQs disabled and invokes
instrumentable functions and tracepoints (such as trace_kvm_entry and
trace_kvm_exit) before sync_dirty_debug_regs() and
hw_breakpoint_restore(). If a wprobe trigger calls
arch_modify_local_hw_breakpoint_addr() in this window, set_debugreg(addr,
i) overwrites the guest's hardware DR[i] with the host kernel address
(which sync_dirty_debug_regs() then saves into vcpu->arch.db[i], leaking
the host address to the guest), and set_debugreg(dr7, 7) activates host
cpu_dr7 while the remaining hardware DR[j] registers still hold guest
addresses.
Similarly, if called while use_temporary_mm() -> hw_breakpoint_disable()
or local_db_save() has suppressed hardware breakpoints, writing cpu_dr7
back to hardware DR7 re-enables the breakpoints prematurely while temp_mm
is loaded (with 0UL in the other DR registers) or while inside a #DB
exception context.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179480675130.38065.3086970856119381693.stgit@devnote2?part=1
next prev parent reply other threads:[~2026-11-16 5:47 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 5:25 [PATCH v20 00/11] tracing: wprobe: x86: Add wprobe for watchpoint Masami Hiramatsu (Google)
2026-11-16 5:26 ` [PATCH v20 01/11] x86/hw_breakpoints: Add arch_modify_local_hw_breakpoint_addr() API Masami Hiramatsu (Google)
2026-11-16 5:47 ` sashiko-bot [this message]
2026-11-16 5:26 ` [PATCH v20 02/11] HWBP: Add modify_local_hw_breakpoint_addr() API Masami Hiramatsu (Google)
2026-11-16 5:57 ` sashiko-bot
2026-11-16 5:26 ` [PATCH v20 03/11] perf/hw_breakpoint: Add register_wide_hw_breakpoint_cpuslocked() API Masami Hiramatsu (Google)
2026-11-16 5:44 ` sashiko-bot
2026-11-16 5:26 ` [PATCH v20 04/11] tracing/wprobe: Add wprobe (watchpoint probe) trace event support Masami Hiramatsu (Google)
2026-11-16 5:56 ` sashiko-bot
2026-11-16 5:26 ` [PATCH v20 05/11] x86: hw_breakpoint: Add a kconfig to clarify when a breakpoint fires Masami Hiramatsu (Google)
2026-11-16 5:34 ` sashiko-bot
2026-11-16 5:27 ` [PATCH v20 06/11] selftests: tracing: Add a basic testcase for wprobe Masami Hiramatsu (Google)
2026-11-16 5:34 ` sashiko-bot
2026-11-16 5:27 ` [PATCH v20 07/11] selftests: tracing: Add syntax " Masami Hiramatsu (Google)
2026-11-16 5:42 ` sashiko-bot
2026-11-16 5:27 ` [PATCH v20 08/11] tracing/wprobe: Add set_wprobe and clear_wprobe event triggers Masami Hiramatsu (Google)
2026-11-16 5:27 ` [PATCH v20 09/11] selftests: tracing: Add wprobe trigger testcases Masami Hiramatsu (Google)
2026-11-16 5:52 ` sashiko-bot
2026-11-16 5:27 ` [PATCH v20 10/11] tracing/wprobe: Support BTF typecast in fetchargs Masami Hiramatsu (Google)
2026-11-16 5:52 ` sashiko-bot
2026-11-16 5:27 ` [PATCH v20 11/11] tracing/wprobe: Support BTF struct offset resolution in set_wprobe trigger Masami Hiramatsu (Google)
2026-11-16 5:50 ` sashiko-bot
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=sashiko-outbox-216226@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@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