Skip to contentSkip to conversation

ARM64: More flexible HW watchpoint

PATCH Superseded Pratyush Anand 3 participants 8 messages Oct 12, 2016 – Oct 13, 2016

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover ARM64: More flexible HW watchpoint

Currently, we do not support all the byte select option provided by ARM64 specs for a HW watchpoint.

This patch set will help user to instrument a watchpoint with all possible byte select options.

Pratyush Anand (4):
hw_breakpoint: Allow watchpoint of length 3,5,6 and 7
arm64: Allow hw watchpoint at varied offset from base address
arm64: Allow hw watchpoint of length 3,5,6 and 7
selftests: arm64: add test for unaligned watchpoint address handling

 arch/arm64/include/asm/hw_breakpoint.h             |   6 +-
 arch/arm64/kernel/hw_breakpoint.c                  |  79 ++++++--
 arch/arm64/kernel/ptrace.c                         |   5 +-
 include/uapi/linux/hw_breakpoint.h                 |   4 +
 tools/include/uapi/linux/hw_breakpoint.h           |   4 +
 tools/testing/selftests/breakpoints/Makefile       |   5 +-
 .../selftests/breakpoints/breakpoint_test_arm64.c  | 223 +++++++++++++++++++++
 7 files changed, 300 insertions(+), 26 deletions(-)
 create mode 100644 tools/testing/selftests/breakpoints/breakpoint_test_arm64.c
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/4 hw_breakpoint: Allow watchpoint of length 3,5,6 and 7

We only support breakpoint/watchpoint of length 1, 2, 4 and 8. If we can support other length as well, then user may watch more data with less number of watchpoints (provided hardware supports it). For example: if we have to watch only 4th, 5th and 6th byte from a 64 bit aligned address, we will have to use two slots to implement it currently. One slot will watch a half word at offset 4 and other a byte at offset 6. If we can have a watchpoint of length 3 then we can watch it with single slot as well.

ARM64 hardware does support such functionality, therefore adding these new definitions in generic layer.

---
 include/uapi/linux/hw_breakpoint.h       | 4 ++++
 tools/include/uapi/linux/hw_breakpoint.h | 4 ++++
 2 files changed, 8 insertions(+)
include/uapi/linux/hw_breakpoint.h +4 -0
index b04000a2296a..2b65efd19a46 100644
@@ -4,7 +4,11 @@
 enum {
 	HW_BREAKPOINT_LEN_1 = 1,
 	HW_BREAKPOINT_LEN_2 = 2,
+	HW_BREAKPOINT_LEN_3 = 3,
 	HW_BREAKPOINT_LEN_4 = 4,
+	HW_BREAKPOINT_LEN_5 = 5,
+	HW_BREAKPOINT_LEN_6 = 6,
+	HW_BREAKPOINT_LEN_7 = 7,
 	HW_BREAKPOINT_LEN_8 = 8,
 };
 
tools/include/uapi/linux/hw_breakpoint.h +4 -0
index b04000a2296a..2b65efd19a46 100644
@@ -4,7 +4,11 @@
 enum {
 	HW_BREAKPOINT_LEN_1 = 1,
 	HW_BREAKPOINT_LEN_2 = 2,
+	HW_BREAKPOINT_LEN_3 = 3,
 	HW_BREAKPOINT_LEN_4 = 4,
+	HW_BREAKPOINT_LEN_5 = 5,
+	HW_BREAKPOINT_LEN_6 = 6,
+	HW_BREAKPOINT_LEN_7 = 7,
 	HW_BREAKPOINT_LEN_8 = 8,
 };
 
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/4 arm64: Allow hw watchpoint at varied offset from base address

In reply to Pratyush Anand

ARM64 hardware supports watchpoint at any double word aligned address. However, it can select any consecutive bytes from offset 0 to 7 from that base address. For example, if base address is programmed as 0x420030 and byte select is 0x1C, then access of 0x420032,0x420033 and 0x420034 will generate a watchpoint exception.

Currently, we do not have such modularity. We can only program byte, halfword, word and double word access exception from any base address.

This patch adds support to overcome above limitations.

---
 arch/arm64/include/asm/hw_breakpoint.h |  2 +-
 arch/arm64/kernel/hw_breakpoint.c      | 43 +++++++++++++++++-----------------
 arch/arm64/kernel/ptrace.c             |  5 ++--
 3 files changed, 25 insertions(+), 25 deletions(-)
arch/arm64/include/asm/hw_breakpoint.h +1 -1
index 115ea2a64520..4f4e58bee9bc 100644
@@ -118,7 +118,7 @@ struct perf_event;
 struct pmu;
 
 extern int arch_bp_generic_fields(struct arch_hw_breakpoint_ctrl ctrl,
-				  int *gen_len, int *gen_type);
+				  int *gen_len, int *gen_type, int *offset);
 extern int arch_check_bp_in_kernelspace(struct perf_event *bp);
 extern int arch_validate_hwbkpt_settings(struct perf_event *bp);
 extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused,
arch/arm64/kernel/hw_breakpoint.c +21 -22

85 lines not on this page · raw message

arch/arm64/kernel/ptrace.c +3 -2
index e0c81da60f76..0eb366a94382 100644
@@ -327,13 +327,13 @@ static int ptrace_hbp_fill_attr_ctrl(unsigned int note_type,
 				     struct arch_hw_breakpoint_ctrl ctrl,
 				     struct perf_event_attr *attr)
 {
-	int err, len, type, disabled = !ctrl.enabled;
+	int err, len, type, offset, disabled = !ctrl.enabled;
 
 	attr->disabled = disabled;
 	if (disabled)
 		return 0;
 
-	err = arch_bp_generic_fields(ctrl, &len, &type);
+	err = arch_bp_generic_fields(ctrl, &len, &type, &offset);
 	if (err)
 		return err;
 
@@ -352,6 +352,7 @@ static int ptrace_hbp_fill_attr_ctrl(unsigned int note_type,
 
 	attr->bp_len	= len;
 	attr->bp_type	= type;
+	attr->bp_addr	+= offset;
 
 	return 0;
 }
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/4 arm64: Allow hw watchpoint of length 3,5,6 and 7

In reply to Pratyush Anand

Since, arm64 can support all offset within a double word limit. Therefore, now support other lengths within that range as well.

---
 arch/arm64/include/asm/hw_breakpoint.h |  4 ++++
 arch/arm64/kernel/hw_breakpoint.c      | 36 ++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
arch/arm64/include/asm/hw_breakpoint.h +4 -0
index 4f4e58bee9bc..7a18c8520588 100644
@@ -76,7 +76,11 @@ static inline void decode_ctrl_reg(u32 reg,
 /* Lengths */
 #define ARM_BREAKPOINT_LEN_1	0x1
 #define ARM_BREAKPOINT_LEN_2	0x3
+#define ARM_BREAKPOINT_LEN_3	0x7
 #define ARM_BREAKPOINT_LEN_4	0xf
+#define ARM_BREAKPOINT_LEN_5	0x1f
+#define ARM_BREAKPOINT_LEN_6	0x3f
+#define ARM_BREAKPOINT_LEN_7	0x7f
 #define ARM_BREAKPOINT_LEN_8	0xff
 
 /* Kernel stepping */
arch/arm64/kernel/hw_breakpoint.c +36 -0
index c888c23149ad..7ff2c3cfeb46 100644
@@ -317,9 +317,21 @@ static int get_hbp_len(u8 hbp_len)
 	case ARM_BREAKPOINT_LEN_2:
 		len_in_bytes = 2;
 		break;
+	case ARM_BREAKPOINT_LEN_3:
+		len_in_bytes = 3;
+		break;
 	case ARM_BREAKPOINT_LEN_4:
 		len_in_bytes = 4;
 		break;
+	case ARM_BREAKPOINT_LEN_5:
+		len_in_bytes = 5;
+		break;
+	case ARM_BREAKPOINT_LEN_6:
+		len_in_bytes = 6;
+		break;
+	case ARM_BREAKPOINT_LEN_7:
+		len_in_bytes = 7;
+		break;
 	case ARM_BREAKPOINT_LEN_8:
 		len_in_bytes = 8;
 		break;
@@ -379,9 +391,21 @@ int arch_bp_generic_fields(struct arch_hw_breakpoint_ctrl ctrl,
 	case ARM_BREAKPOINT_LEN_2:
 		*gen_len = HW_BREAKPOINT_LEN_2;
 		break;
+	case ARM_BREAKPOINT_LEN_3:
+		*gen_len = HW_BREAKPOINT_LEN_3;
+		break;
 	case ARM_BREAKPOINT_LEN_4:
 		*gen_len = HW_BREAKPOINT_LEN_4;
 		break;
+	case ARM_BREAKPOINT_LEN_5:
+		*gen_len = HW_BREAKPOINT_LEN_5;
+		break;
+	case ARM_BREAKPOINT_LEN_6:
+		*gen_len = HW_BREAKPOINT_LEN_6;
+		break;
+	case ARM_BREAKPOINT_LEN_7:
+		*gen_len = HW_BREAKPOINT_LEN_7;
+		break;
 	case ARM_BREAKPOINT_LEN_8:
 		*gen_len = HW_BREAKPOINT_LEN_8;
 		break;
@@ -425,9 +449,21 @@ static int arch_build_bp_info(struct perf_event *bp)
 	case HW_BREAKPOINT_LEN_2:
 		info->ctrl.len = ARM_BREAKPOINT_LEN_2;
 		break;
+	case HW_BREAKPOINT_LEN_3:
+		info->ctrl.len = ARM_BREAKPOINT_LEN_3;
+		break;
 	case HW_BREAKPOINT_LEN_4:
 		info->ctrl.len = ARM_BREAKPOINT_LEN_4;
 		break;
+	case HW_BREAKPOINT_LEN_5:
+		info->ctrl.len = ARM_BREAKPOINT_LEN_5;
+		break;
+	case HW_BREAKPOINT_LEN_6:
+		info->ctrl.len = ARM_BREAKPOINT_LEN_6;
+		break;
+	case HW_BREAKPOINT_LEN_7:
+		info->ctrl.len = ARM_BREAKPOINT_LEN_7;
+		break;
 	case HW_BREAKPOINT_LEN_8:
 		info->ctrl.len = ARM_BREAKPOINT_LEN_8;
 		break;
Signature · 1 line
2.7.4
#4 lore raw

Re: [PATCH 3/4] arm64: Allow hw watchpoint of length 3,5,6 and 7

Quoted 2 lines · Pratyush Anand

Since, arm64 can support all offset within a double word limit. Therefore, now support other lengths within that range as well.

How does ptracer (like GDB) detect kernel has already supported all byte address select values? I suppose ptrace(NT_ARM_HW_WATCH, ) with len is 3 or 5 fail on current kernel but is of success after your patches applied.

GDB is aware of the byte address select limitation in kernel, so it always sets 1,2,4,8 in len in ctrl. GDB needs to know whether the limitation is still there or not.

Signature · 1 line
Yao (??)
#5 lore raw

Re: [PATCH 3/4] arm64: Allow hw watchpoint of length 3,5,6 and 7

Quoted 9 lines · Yao Qi
Quoted 2 lines · Pratyush Anand

Since, arm64 can support all offset within a double word limit. Therefore, now support other lengths within that range as well.

How does ptracer (like GDB) detect kernel has already supported all byte address select values? I suppose ptrace(NT_ARM_HW_WATCH, ) with len is 3 or 5 fail on current kernel but is of success after your patches applied.

Thanks for testing these patches.

I do not know if we can know that other than the failure of ptrace(PTRACE_SETREGSET, .., NT_ARM_HW_WATCH, ..). I do not see any such option in man ptrace.

Quoted 4 lines

GDB is aware of the byte address select limitation in kernel, so it always sets 1,2,4,8 in len in ctrl. GDB needs to know whether the limitation is still there or not.

Not sure if other than "kernel version" anything will help here.

~Pratyush

#6 lore raw

Re: [PATCH 3/4] arm64: Allow hw watchpoint of length 3,5,6 and 7

Quoted 17 lines · Pratyush Anand
Quoted 8 lines · Yao Qi
Quoted 4 lines · Pratyush Anand

Since, arm64 can support all offset within a double word limit. Therefore,
now support other lengths within that range as well.

Quoted 5 lines

How does ptracer (like GDB) detect kernel has already supported all byte address select values? I suppose ptrace(NT_ARM_HW_WATCH, ) with len is 3 or 5 fail on current kernel but is of success after your patches applied.

Quoted 5 lines

Thanks for testing these patches.

I do not know if we can know that other than the failure of ptrace(PTRACE_SETREGSET, .., NT_ARM_HW_WATCH, ..). I do not see any such option in man ptrace.

That's how I intend to implement support for this in LLDB. if (setExactWatchpoint())
return true; // watchpoint set, new kernel
if (setApproxWatchpoint())
return true; // watchpoint set, old kernel
return false; // watchpoints not working

seems straight-forward enough to me.

#7 lore raw

PATCH 4/4 selftests: arm64: add test for unaligned watchpoint address handling

In reply to Pratyush Anand

ARM64 hardware expects 64bit aligned address for watchpoint invocation. However, it provides byte selection method to select any number of consecutive byte set within the range of 1-8.

This patch adds support to test all such byte selection option for different memory write sizes.

---
 tools/testing/selftests/breakpoints/Makefile       |   5 +-
 .../selftests/breakpoints/breakpoint_test_arm64.c  | 223 +++++++++++++++++++++
 2 files changed, 227 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/breakpoints/breakpoint_test_arm64.c
tools/testing/selftests/breakpoints/Makefile +4 -1
index 74e533fd4bc5..61b79e8df1f4 100644
@@ -5,6 +5,9 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
 ifeq ($(ARCH),x86)
 TEST_PROGS := breakpoint_test
 endif
+ifeq ($(ARCH),aarch64)
+TEST_PROGS := breakpoint_test_arm64
+endif
 
 TEST_PROGS += step_after_suspend_test
 
@@ -13,4 +16,4 @@ all: $(TEST_PROGS)
 include ../lib.mk
 
 clean:
-	rm -fr breakpoint_test step_after_suspend_test
+	rm -fr breakpoint_test breakpoint_test_arm64 step_after_suspend_test
tools/testing/selftests/breakpoints/breakpoint_test_arm64.c new file +223 -0

223 lines not on this page · raw message

Signature · 1 line
2.7.4