[PATCH] arm64/hw_breakpoint: Determine lengths from generic perf breakpoint macros

Mark Rutland mark.rutland at arm.com
Mon Feb 26 03:04:46 PST 2024


On Mon, Feb 26, 2024 at 08:19:39AM +0530, Anshuman Khandual wrote:
> On 2/23/24 18:22, Will Deacon wrote:
> > On Fri, Feb 23, 2024 at 05:01:02PM +0530, Anshuman Khandual wrote:
> >> Both platform i.e ARM_BREAKPOINT_LEN_X and generic i.e HW_BREAKPOINT_LEN_X
> >> macros are used interchangeably to convert event->attr.bp_len and platform
> >> breakpoint control arch_hw_breakpoint_ctrl->len. Let's be consistent while
> >> deriving one from the other. This does not cause any functional changes.
> >>
> >> Cc: Will Deacon <will at kernel.org>
> >> Cc: Mark Rutland <mark.rutland at arm.com>
> >> Cc: Catalin Marinas <catalin.marinas at arm.com>
> >> Cc: linux-arm-kernel at lists.infradead.org
> >> Cc: linux-kernel at vger.kernel.org
> >> Signed-off-by: Anshuman Khandual <anshuman.khandual at arm.com>
> >> ---
> >> This applies on v6.8-rc5
> >>
> >>  arch/arm64/kernel/hw_breakpoint.c | 16 ++++++++--------
> >>  1 file changed, 8 insertions(+), 8 deletions(-)
> >>
> >> diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
> >> index 35225632d70a..1ab9fc865ddd 100644
> >> --- a/arch/arm64/kernel/hw_breakpoint.c
> >> +++ b/arch/arm64/kernel/hw_breakpoint.c
> >> @@ -301,28 +301,28 @@ static int get_hbp_len(u8 hbp_len)
> >>  
> >>  	switch (hbp_len) {
> >>  	case ARM_BREAKPOINT_LEN_1:
> >> -		len_in_bytes = 1;
> >> +		len_in_bytes = HW_BREAKPOINT_LEN_1;
> > 
> > I don't think we should do this. The HW_BREAKPOINT_LEN_* definitions are
> > part of the user ABI and, although they correspond to the length in bytes,
> > that's not necessarily something we should rely on.
> 
> Why should not we rely on the user ABI macros if these byte lengths were
> initially derived from them. 

Why should we change the clear:
	
	len_in_bytes = 1;

... to the longer, and less clear:

	len_in_bytes = HW_BREAKPOINT_LEN_1;

... ?

> But also there are similar conversions in arch_bp_generic_fields().

Those are specifically for converting from the rch_hw_breakpoint_ctrl encodings
to the perf_event_attr encodings. There we don't care about the specific value
of the byte, just that we're using the correct encoding.

> These hard coded raw byte length numbers seems cryptic, where as in reality
> these are just inter converted from generic HW breakpoints lengths.

There are three distinct concepts here:

1. The length in bytes, as returned above by get_hbp_len()

2. The length as encoded in the ARM_BREAKPOINT_LEN_* encoding

3. The length as encoded in the HW_BREAKPOINT_LEN_* encoding.

I think you're arguing that since 1 and 3 happen to have the values we should
treat them as the same thing. I think that Will and I believe that they should
be kept distinct because they are distinct concepts.

I don't think this needs to change, and can be left as-is.

Mark.



More information about the linux-arm-kernel mailing list