Re: [PATCH] perf/hw_breakpoint: Return EOPNOTSUPP for unsupported breakpoint type
From: Ian Rogers
Date: Mon Mar 03 2025 - 12:24:36 EST
On Mon, Mar 3, 2025 at 1:25 AM Saket Kumar Bhaskar <skb99@xxxxxxxxxxxxx> wrote:
>
> Currently, __reserve_bp_slot() returns -ENOSPC for unsupported
> breakpoint types on the architecture. For example, powerpc
> does not support hardware instruction breakpoints. This causes
> the perf_skip BPF selftest to fail, as neither ENOENT nor
> EOPNOTSUPP is returned by perf_event_open for unsupported
> breakpoint types. As a result, the test that should be skipped
> for this arch is not correctly identified.
>
> To resolve this, hw_breakpoint_event_init() should exit early by
> checking for unsupported breakpoint types using
> hw_breakpoint_slots_cached() and return the appropriate error
> (-EOPNOTSUPP).
Hi Saket,
This looks good to me! Did you happen to run "perf test" as there are
a couple of tests there covering breakpoint behavior and I wonder if
we may need to update them? Particularly there are some comments about
PowerPC just not working:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/tests/bp_account.c#n24
Thanks,
Ian
> Signed-off-by: Saket Kumar Bhaskar <skb99@xxxxxxxxxxxxx>
> ---
> kernel/events/hw_breakpoint.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c
> index bc4a61029b6d..8ec2cb688903 100644
> --- a/kernel/events/hw_breakpoint.c
> +++ b/kernel/events/hw_breakpoint.c
> @@ -950,9 +950,10 @@ static int hw_breakpoint_event_init(struct perf_event *bp)
> return -ENOENT;
>
> /*
> - * no branch sampling for breakpoint events
> + * Check if breakpoint type is supported before proceeding.
> + * Also, no branch sampling for breakpoint events.
> */
> - if (has_branch_stack(bp))
> + if (!hw_breakpoint_slots_cached(find_slot_idx(bp->attr.bp_type)) || has_branch_stack(bp))
> return -EOPNOTSUPP;
>
> err = register_perf_hw_breakpoint(bp);
> --
> 2.43.5
>