[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20250911191648.f1e9f0fbb6856416e3865b9c@kernel.org>
Date: Thu, 11 Sep 2025 19:16:48 +0900
From: Masami Hiramatsu (Google) <mhiramat@...nel.org>
To: Jinchao Wang <wangjinchao600@...il.com>
Cc: Thomas Gleixner <tglx@...utronix.de>, Peter Zijlstra
<peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>, Borislav Petkov
<bp@...en8.de>, Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
"H. Peter Anvin" <hpa@...or.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] x86/hw_breakpoint: Add arch_reinstall_hw_breakpoint
On Wed, 10 Sep 2025 17:39:35 +0800
Jinchao Wang <wangjinchao600@...il.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@...nel.org>
Thanks,
> Signed-off-by: Jinchao Wang <wangjinchao600@...il.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@...nel.org>
Powered by blists - more mailing lists