Skip to contentSkip to conversation

arm64: hw_breakpoint: warn on invalid breakpoint length

PATCH In review Osama Abdelkader 3 participants 3 messages Dec 13, 2025 – Jan 5

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 arm64: hw_breakpoint: warn on invalid breakpoint length

Some tools (e.g. perf) incorrectly assume that breakpoints should be sizeof(long), but this is wrong for AArch64 where breakpoints must be 4 bytes. Add a warning when we silently fix up the parameter so tool developers can get notified.

This addresses the FIXME comment by adding diagnostic output rather than breaking existing tools by returning -EINVAL.

---
v2: fix warning messageline splitting

---
 arch/arm64/kernel/hw_breakpoint.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/arm64/kernel/hw_breakpoint.c +6 -4
index ab76b36dce82..cce306145d78 100644
@@ -475,11 +475,13 @@ static int arch_build_bp_info(struct perf_event *bp,
 				return -EINVAL;
 		} else if (hw->ctrl.len != ARM_BREAKPOINT_LEN_4) {
 			/*
-			 * FIXME: Some tools (I'm looking at you perf) assume
-			 *	  that breakpoints should be sizeof(long). This
-			 *	  is nonsense. For now, we fix up the parameter
-			 *	  but we should probably return -EINVAL instead.
+			 * Some tools (e.g. perf) incorrectly assume that
+			 * breakpoints should be sizeof(long). This is wrong
+			 * for AArch64 where breakpoints must be 4 bytes.
+			 * Warn the user and fix up the parameter.
 			 */
+			pr_warn_once("hw_breakpoint: invalid AArch64 breakpoint length %d, fixing to 4 bytes\n",
+				     hw->ctrl.len);
 			hw->ctrl.len = ARM_BREAKPOINT_LEN_4;
 		}
 	}
Signature · 1 line
2.43.0
#1 lore raw

Hi,

Quoted 4 lines · Osama Abdelkader

Some tools (e.g. perf) incorrectly assume that breakpoints should be sizeof(long), but this is wrong for AArch64 where breakpoints must be 4 bytes. Add a warning when we silently fix up the parameter so tool developers can get notified.

To be clear, the perf tool has fixed the issue since:

fa6cc3f93258 ("perf parse-events: Vary default_breakpoint_len on i386 and arm64")

The latest perf can pass the correct length (4) for instruction breakpoint.

Quoted 15 lines

This addresses the FIXME comment by adding diagnostic output rather than breaking existing tools by returning -EINVAL.

---
v2: fix warning messageline splitting

---
 arch/arm64/kernel/hw_breakpoint.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/arm64/kernel/hw_breakpoint.c +0 -0
index ab76b36dce82..cce306145d78 100644

arch/arm64/kernel/hw_breakpoint.c static int arch_build_bp_info(struct perf_event *bp, · line 481

Quoted 7 lines
arch/arm64/kernel/hw_breakpoint.c +0 -4
@@ -475,11 +475,13 @@ static int arch_build_bp_info(struct perf_event *bp,
 				return -EINVAL;
 		} else if (hw->ctrl.len != ARM_BREAKPOINT_LEN_4) {
 			/*
-			 * FIXME: Some tools (I'm looking at you perf) assume
-			 *	  that breakpoints should be sizeof(long). This
-			 *	  is nonsense. For now, we fix up the parameter
-			 *	  but we should probably return -EINVAL instead.

This FIXME is still valid for me. IMO, if really want to remove the comment, a reasonable solution is:

1) Backport two patches (fa6cc3f93258 and 70b27c756f9) onto the stable kernel code base for fixing perf tool.

2) Based on perf tool has fixed the issue on the mainline kernel and stable kernels, we can change to return -EINVAL instead.

arch/arm64/kernel/hw_breakpoint.c static int arch_build_bp_info(struct perf_event *bp, · line 484

Quoted 7 lines
arch/arm64/kernel/hw_breakpoint.c +6 -0
+			 * Some tools (e.g. perf) incorrectly assume that
+			 * breakpoints should be sizeof(long). This is wrong
+			 * for AArch64 where breakpoints must be 4 bytes.
+			 * Warn the user and fix up the parameter.
 			 */
+			pr_warn_once("hw_breakpoint: invalid AArch64 breakpoint length %d, fixing to 4 bytes\n",
+				     hw->ctrl.len);

AFAIK, since I started to use Armv5 CPUs, Arm instructions (not Thumb ones) are always 4-byte length. Not sure if the log is useful or not, I would leave this to maintainers.

Thanks,
Leo

Quoted 7 lines
arch/arm64/kernel/hw_breakpoint.c +0 -0
 			hw->ctrl.len = ARM_BREAKPOINT_LEN_4;
 		}
 	}
Signature · 1 line
2.43.0
maintainer
#2 lore raw
In reply to Osama Abdelkader
Quoted 25 lines · Osama Abdelkader

Some tools (e.g. perf) incorrectly assume that breakpoints should be sizeof(long), but this is wrong for AArch64 where breakpoints must be 4 bytes. Add a warning when we silently fix up the parameter so tool developers can get notified.

This addresses the FIXME comment by adding diagnostic output rather than breaking existing tools by returning -EINVAL.

---
v2: fix warning messageline splitting

---
 arch/arm64/kernel/hw_breakpoint.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/arm64/kernel/hw_breakpoint.c +0 -2
index ab76b36dce82..cce306145d78 100644
@@ -475,11 +475,13 @@ static int arch_build_bp_info(struct perf_event *bp,
 				return -EINVAL;
 		} else if (hw->ctrl.len != ARM_BREAKPOINT_LEN_4) {
 			/*
-			 * FIXME: Some tools (I'm looking at you perf) assume
-			 *	  that breakpoints should be sizeof(long). This

arch/arm64/kernel/hw_breakpoint.c static int arch_build_bp_info(struct perf_event *bp, · line 485

Quoted 10 lines
arch/arm64/kernel/hw_breakpoint.c +6 -2
-			 *	  is nonsense. For now, we fix up the parameter
-			 *	  but we should probably return -EINVAL instead.
+			 * Some tools (e.g. perf) incorrectly assume that
+			 * breakpoints should be sizeof(long). This is wrong
+			 * for AArch64 where breakpoints must be 4 bytes.
+			 * Warn the user and fix up the parameter.
 			 */
+			pr_warn_once("hw_breakpoint: invalid AArch64 breakpoint length %d, fixing to 4 bytes\n",
+				     hw->ctrl.len);
 			hw->ctrl.len = ARM_BREAKPOINT_LEN_4;

This is user triggerable so I don't see why printing a message is a good idea. Just remove the FIXME tag if it bothers you -- we can't really change the behaviour at this point.

Will