From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Jinchao Wang <wangjinchao600@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] x86/hw_breakpoint: Add arch_reinstall_hw_breakpoint
Date: Thu, 11 Sep 2025 19:16:48 +0900 [thread overview]
Message-ID: <20250911191648.f1e9f0fbb6856416e3865b9c@kernel.org> (raw)
In-Reply-To: <20250910093951.1330637-2-wangjinchao600@gmail.com>
On Wed, 10 Sep 2025 17:39:35 +0800
Jinchao Wang <wangjinchao600@gmail.com> wrote:
> The new `arch_reinstall_hw_breakpoint` function can be used in an
> atomic context, unlike the more expensive free and re-allocation path.
>
> This patch adds `BP_SLOT_ACTION_REINSTALL` to the `enum` and updates the
> `manage_bp_slot` helper to correctly handle the action. This allows
> callers to efficiently re-establish an existing breakpoint.
>
Ah, this also looks good to me.
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Thanks,
> Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
> ---
> arch/x86/include/asm/hw_breakpoint.h | 2 ++
> arch/x86/kernel/hw_breakpoint.c | 21 +++++++++++++++++++++
> 2 files changed, 23 insertions(+)
>
> diff --git a/arch/x86/include/asm/hw_breakpoint.h b/arch/x86/include/asm/hw_breakpoint.h
> index bd437a30dbf2..d1cc6db8a59f 100644
> --- a/arch/x86/include/asm/hw_breakpoint.h
> +++ b/arch/x86/include/asm/hw_breakpoint.h
> @@ -20,6 +20,7 @@ struct arch_hw_breakpoint {
>
> enum bp_slot_action {
> BP_SLOT_ACTION_INSTALL,
> + BP_SLOT_ACTION_REINSTALL,
> BP_SLOT_ACTION_UNINSTALL,
> };
>
> @@ -64,6 +65,7 @@ extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused,
>
>
> int arch_install_hw_breakpoint(struct perf_event *bp);
> +int arch_reinstall_hw_breakpoint(struct perf_event *bp);
> void arch_uninstall_hw_breakpoint(struct perf_event *bp);
> void hw_breakpoint_pmu_read(struct perf_event *bp);
> void hw_breakpoint_pmu_unthrottle(struct perf_event *bp);
> diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c
> index 1736063a82b7..99223695cee8 100644
> --- a/arch/x86/kernel/hw_breakpoint.c
> +++ b/arch/x86/kernel/hw_breakpoint.c
> @@ -94,6 +94,10 @@ static int manage_bp_slot(struct perf_event *bp, enum bp_slot_action action)
> old_bp = NULL;
> new_bp = bp;
> break;
> + case BP_SLOT_ACTION_REINSTALL:
> + old_bp = bp;
> + new_bp = bp;
> + break;
> case BP_SLOT_ACTION_UNINSTALL:
> old_bp = bp;
> new_bp = NULL;
> @@ -192,6 +196,23 @@ int arch_install_hw_breakpoint(struct perf_event *bp)
> return arch_manage_bp(bp, BP_SLOT_ACTION_INSTALL);
> }
>
> +/*
> + * Reinstall a hardware breakpoint on the current CPU.
> + *
> + * This function is used to re-establish a perf counter hardware breakpoint.
> + * It finds the debug address register slot previously allocated for the
> + * breakpoint and re-enables it by writing the address to the debug register
> + * and setting the corresponding bits in the debug control register (DR7).
> + *
> + * It is expected that the breakpoint's event context lock is already held
> + * and interrupts are disabled, ensuring atomicity and safety from other
> + * event handlers.
> + */
> +int arch_reinstall_hw_breakpoint(struct perf_event *bp)
> +{
> + return arch_manage_bp(bp, BP_SLOT_ACTION_REINSTALL);
> +}
> +
> /*
> * Uninstall the breakpoint contained in the given counter.
> *
> --
> 2.43.0
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2025-09-11 10:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-10 9:39 [PATCH 1/2] x86/hw_breakpoint: Unify breakpoint install/uninstall Jinchao Wang
2025-09-10 9:39 ` [PATCH 2/2] x86/hw_breakpoint: Add arch_reinstall_hw_breakpoint Jinchao Wang
2025-09-11 10:16 ` Masami Hiramatsu [this message]
2025-09-10 14:47 ` [PATCH 1/2] x86/hw_breakpoint: Unify breakpoint install/uninstall Dave Hansen
2025-09-10 14:56 ` H. Peter Anvin
2025-09-11 0:42 ` Jinchao Wang
2025-09-11 8:03 ` Masami Hiramatsu
2025-09-12 1:05 ` 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=20250911191648.f1e9f0fbb6856416e3865b9c@kernel.org \
--to=mhiramat@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=wangjinchao600@gmail.com \
--cc=x86@kernel.org \
/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