Introduce hw_breakpoint_modify_local() as a generic helper to modify an
existing hardware breakpoint. The function invokes
hw_breakpoint_arch_parse() and delegates the reinstall step to the
architecture via arch_reinstall_hw_breakpoint().
A weak default implementation of arch_reinstall_hw_breakpoint() is
provided, returning -EOPNOTSUPP on architectures without support.
This makes the interface arch-independent while allowing x86 (and others)
to provide their own implementation.
Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
---
include/linux/hw_breakpoint.h | 1 +
kernel/events/hw_breakpoint.c | 18 ++++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/include/linux/hw_breakpoint.h b/include/linux/hw_breakpoint.h
index db199d653dd1..9453b5bdb443 100644
--- a/include/linux/hw_breakpoint.h
+++ b/include/linux/hw_breakpoint.h
@@ -67,6 +67,7 @@ extern int
modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *attr,
bool check);
+int hw_breakpoint_modify_local(struct perf_event *bp, struct perf_event_attr *attr);
/*
* Kernel breakpoints are not associated with any particular thread.
*/
diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c
index 8ec2cb688903..ff428739f71e 100644
--- a/kernel/events/hw_breakpoint.c
+++ b/kernel/events/hw_breakpoint.c
@@ -983,6 +983,24 @@ static void hw_breakpoint_del(struct perf_event *bp, int flags)
arch_uninstall_hw_breakpoint(bp);
}
+int hw_breakpoint_modify_local(struct perf_event *bp, struct perf_event_attr *attr)
+{
+ int err;
+
+ err = hw_breakpoint_arch_parse(bp, attr, counter_arch_bp(bp));
+ if (err)
+ return err;
+
+ return arch_reinstall_hw_breakpoint(bp);
+}
+EXPORT_SYMBOL(hw_breakpoint_modify_local);
+
+/* weak fallback for arches without support */
+__weak int arch_reinstall_hw_breakpoint(struct perf_event *bp)
+{
+ return -EOPNOTSUPP;
+}
+
static void hw_breakpoint_start(struct perf_event *bp, int flags)
{
bp->hw.state = 0;
--
2.43.0
Hi Jinchao,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Jinchao-Wang/mm-ksw-add-build-system-support/20250904-082544
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20250904002126.1514566-7-wangjinchao600%40gmail.com
patch subject: [PATCH v2 06/18] perf/hw_breakpoint: add arch-independent hw_breakpoint_modify_local()
config: sh-randconfig-001-20250905 (https://download.01.org/0day-ci/archive/20250906/202509060154.f5xlnJ2n-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250906/202509060154.f5xlnJ2n-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202509060154.f5xlnJ2n-lkp@intel.com/
All errors (new ones prefixed by >>):
kernel/events/hw_breakpoint.c: In function 'hw_breakpoint_modify_local':
>> kernel/events/hw_breakpoint.c:994:16: error: implicit declaration of function 'arch_reinstall_hw_breakpoint'; did you mean 'arch_uninstall_hw_breakpoint'? [-Wimplicit-function-declaration]
994 | return arch_reinstall_hw_breakpoint(bp);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
| arch_uninstall_hw_breakpoint
kernel/events/hw_breakpoint.c: At top level:
kernel/events/hw_breakpoint.c:999:12: warning: no previous prototype for 'arch_reinstall_hw_breakpoint' [-Wmissing-prototypes]
999 | __weak int arch_reinstall_hw_breakpoint(struct perf_event *bp)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +994 kernel/events/hw_breakpoint.c
985
986 int hw_breakpoint_modify_local(struct perf_event *bp, struct perf_event_attr *attr)
987 {
988 int err;
989
990 err = hw_breakpoint_arch_parse(bp, attr, counter_arch_bp(bp));
991 if (err)
992 return err;
993
> 994 return arch_reinstall_hw_breakpoint(bp);
995 }
996 EXPORT_SYMBOL(hw_breakpoint_modify_local);
997
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Jinchao,
kernel test robot noticed the following build warnings:
[auto build test WARNING on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Jinchao-Wang/mm-ksw-add-build-system-support/20250904-082544
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20250904002126.1514566-7-wangjinchao600%40gmail.com
patch subject: [PATCH v2 06/18] perf/hw_breakpoint: add arch-independent hw_breakpoint_modify_local()
config: sh-randconfig-001-20250905 (https://download.01.org/0day-ci/archive/20250905/202509052351.KuHBWdAF-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250905/202509052351.KuHBWdAF-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202509052351.KuHBWdAF-lkp@intel.com/
All warnings (new ones prefixed by >>):
kernel/events/hw_breakpoint.c: In function 'hw_breakpoint_modify_local':
kernel/events/hw_breakpoint.c:994:16: error: implicit declaration of function 'arch_reinstall_hw_breakpoint'; did you mean 'arch_uninstall_hw_breakpoint'? [-Wimplicit-function-declaration]
994 | return arch_reinstall_hw_breakpoint(bp);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
| arch_uninstall_hw_breakpoint
kernel/events/hw_breakpoint.c: At top level:
>> kernel/events/hw_breakpoint.c:999:12: warning: no previous prototype for 'arch_reinstall_hw_breakpoint' [-Wmissing-prototypes]
999 | __weak int arch_reinstall_hw_breakpoint(struct perf_event *bp)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/arch_reinstall_hw_breakpoint +999 kernel/events/hw_breakpoint.c
997
998 /* weak fallback for arches without support */
> 999 __weak int arch_reinstall_hw_breakpoint(struct perf_event *bp)
1000 {
1001 return -EOPNOTSUPP;
1002 }
1003
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
On Thu, Sep 04, 2025 at 08:21:03AM +0800, Jinchao Wang wrote:
> Introduce hw_breakpoint_modify_local() as a generic helper to modify an
> existing hardware breakpoint. The function invokes
> hw_breakpoint_arch_parse() and delegates the reinstall step to the
> architecture via arch_reinstall_hw_breakpoint().
>
> A weak default implementation of arch_reinstall_hw_breakpoint() is
> provided, returning -EOPNOTSUPP on architectures without support.
>
> This makes the interface arch-independent while allowing x86 (and others)
> to provide their own implementation.
>
> Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
> ---
> include/linux/hw_breakpoint.h | 1 +
> kernel/events/hw_breakpoint.c | 18 ++++++++++++++++++
> 2 files changed, 19 insertions(+)
>
> diff --git a/include/linux/hw_breakpoint.h b/include/linux/hw_breakpoint.h
> index db199d653dd1..9453b5bdb443 100644
> --- a/include/linux/hw_breakpoint.h
> +++ b/include/linux/hw_breakpoint.h
> @@ -67,6 +67,7 @@ extern int
> modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *attr,
> bool check);
>
> +int hw_breakpoint_modify_local(struct perf_event *bp, struct perf_event_attr *attr);
> /*
> * Kernel breakpoints are not associated with any particular thread.
> */
> diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c
> index 8ec2cb688903..ff428739f71e 100644
> --- a/kernel/events/hw_breakpoint.c
> +++ b/kernel/events/hw_breakpoint.c
> @@ -983,6 +983,24 @@ static void hw_breakpoint_del(struct perf_event *bp, int flags)
> arch_uninstall_hw_breakpoint(bp);
> }
>
> +int hw_breakpoint_modify_local(struct perf_event *bp, struct perf_event_attr *attr)
> +{
> + int err;
> +
> + err = hw_breakpoint_arch_parse(bp, attr, counter_arch_bp(bp));
> + if (err)
> + return err;
> +
> + return arch_reinstall_hw_breakpoint(bp);
> +}
> +EXPORT_SYMBOL(hw_breakpoint_modify_local);
> +
> +/* weak fallback for arches without support */
> +__weak int arch_reinstall_hw_breakpoint(struct perf_event *bp)
> +{
> + return -EOPNOTSUPP;
> +}
Again, so much fail :/
So we have:
{register,modify,unregister}_user_hw_breakpoint()
and
{register,unregister}_wide_hw_breakpoint()
And you choose to extend this latter with hw_breakpoint_modify_local()
instead of sticking with the naming scheme and say adding:
modify_wide_hw_breakpoint_local().
Also, again, that EXPORT is a fail, these other interfaces are all
EXPORT_SYMBOL_GPL().
Also note that modify_user_hw_breakpoint() doesn't seem to need new arch
hooks. Yet you fail to explain why you think you do.
On Thu, Sep 04, 2025 at 08:44:48AM +0200, Peter Zijlstra wrote:
> On Thu, Sep 04, 2025 at 08:21:03AM +0800, Jinchao Wang wrote:
> > Introduce hw_breakpoint_modify_local() as a generic helper to modify an
> > existing hardware breakpoint. The function invokes
> > hw_breakpoint_arch_parse() and delegates the reinstall step to the
> > architecture via arch_reinstall_hw_breakpoint().
> >
> > A weak default implementation of arch_reinstall_hw_breakpoint() is
> > provided, returning -EOPNOTSUPP on architectures without support.
> >
> > This makes the interface arch-independent while allowing x86 (and others)
> > to provide their own implementation.
> >
> > Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
> > ---
> > include/linux/hw_breakpoint.h | 1 +
> > kernel/events/hw_breakpoint.c | 18 ++++++++++++++++++
> > 2 files changed, 19 insertions(+)
> >
> > diff --git a/include/linux/hw_breakpoint.h b/include/linux/hw_breakpoint.h
> > index db199d653dd1..9453b5bdb443 100644
> > --- a/include/linux/hw_breakpoint.h
> > +++ b/include/linux/hw_breakpoint.h
> > @@ -67,6 +67,7 @@ extern int
> > modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *attr,
> > bool check);
> >
> > +int hw_breakpoint_modify_local(struct perf_event *bp, struct perf_event_attr *attr);
> > /*
> > * Kernel breakpoints are not associated with any particular thread.
> > */
> > diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c
> > index 8ec2cb688903..ff428739f71e 100644
> > --- a/kernel/events/hw_breakpoint.c
> > +++ b/kernel/events/hw_breakpoint.c
> > @@ -983,6 +983,24 @@ static void hw_breakpoint_del(struct perf_event *bp, int flags)
> > arch_uninstall_hw_breakpoint(bp);
> > }
> >
> > +int hw_breakpoint_modify_local(struct perf_event *bp, struct perf_event_attr *attr)
> > +{
> > + int err;
> > +
> > + err = hw_breakpoint_arch_parse(bp, attr, counter_arch_bp(bp));
> > + if (err)
> > + return err;
> > +
> > + return arch_reinstall_hw_breakpoint(bp);
> > +}
> > +EXPORT_SYMBOL(hw_breakpoint_modify_local);
> > +
> > +/* weak fallback for arches without support */
> > +__weak int arch_reinstall_hw_breakpoint(struct perf_event *bp)
> > +{
> > + return -EOPNOTSUPP;
> > +}
>
> Again, so much fail :/
>
> So we have:
>
> {register,modify,unregister}_user_hw_breakpoint()
>
> and
>
> {register,unregister}_wide_hw_breakpoint()
>
> And you choose to extend this latter with hw_breakpoint_modify_local()
> instead of sticking with the naming scheme and say adding:
>
> modify_wide_hw_breakpoint_local().
>
> Also, again, that EXPORT is a fail, these other interfaces are all
> EXPORT_SYMBOL_GPL().
>
Thanks for your patience.
I was misled by another family:
- hw_breakpoint_add
- hw_breakpoint_del
- hw_breakpoint_start
- hw_breakpoint_stop
Since this logic was also added in the wprobe series by Masami, I will
adopt his version instead.
> Also note that modify_user_hw_breakpoint() doesn't seem to need new arch
> hooks. Yet you fail to explain why you think you do.
Thanks for feedback, I will study existing code to better handle the arch
dependencies.
© 2016 - 2026 Red Hat, Inc.