diff options
author | Catalin Marinas <catalin.marinas@arm.com> | 2016-11-29 10:38:57 -0500 |
---|---|---|
committer | Catalin Marinas <catalin.marinas@arm.com> | 2016-11-29 10:38:57 -0500 |
commit | 00cc2e07453796dc99a32c390ded964f33ac7e89 (patch) | |
tree | 3021c842270e2873e7ae4b183000dc8c0c7012b7 /tools | |
parent | 1650ac49c2a0fb8188a2c8eac36537640ed57892 (diff) | |
parent | f43365ee17f8d22b1f887d2b26faa0837ca85138 (diff) |
Merge Will Deacon's for-next/perf branch into for-next/core
* will/for-next/perf:
selftests: arm64: add test for unaligned/inexact watchpoint handling
arm64: Allow hw watchpoint of length 3,5,6 and 7
arm64: hw_breakpoint: Handle inexact watchpoint addresses
arm64: Allow hw watchpoint at varied offset from base address
hw_breakpoint: Allow watchpoint of length 3,5,6 and 7
Diffstat (limited to 'tools')
-rw-r--r-- | tools/include/uapi/linux/hw_breakpoint.h | 4 | ||||
-rw-r--r-- | tools/testing/selftests/breakpoints/Makefile | 5 | ||||
-rw-r--r-- | tools/testing/selftests/breakpoints/breakpoint_test_arm64.c | 236 |
3 files changed, 244 insertions, 1 deletions
diff --git a/tools/include/uapi/linux/hw_breakpoint.h b/tools/include/uapi/linux/hw_breakpoint.h index b04000a2296a..2b65efd19a46 100644 --- a/tools/include/uapi/linux/hw_breakpoint.h +++ b/tools/include/uapi/linux/hw_breakpoint.h | |||
@@ -4,7 +4,11 @@ | |||
4 | enum { | 4 | enum { |
5 | HW_BREAKPOINT_LEN_1 = 1, | 5 | HW_BREAKPOINT_LEN_1 = 1, |
6 | HW_BREAKPOINT_LEN_2 = 2, | 6 | HW_BREAKPOINT_LEN_2 = 2, |
7 | HW_BREAKPOINT_LEN_3 = 3, | ||
7 | HW_BREAKPOINT_LEN_4 = 4, | 8 | HW_BREAKPOINT_LEN_4 = 4, |
9 | HW_BREAKPOINT_LEN_5 = 5, | ||
10 | HW_BREAKPOINT_LEN_6 = 6, | ||
11 | HW_BREAKPOINT_LEN_7 = 7, | ||
8 | HW_BREAKPOINT_LEN_8 = 8, | 12 | HW_BREAKPOINT_LEN_8 = 8, |
9 | }; | 13 | }; |
10 | 14 | ||
diff --git a/tools/testing/selftests/breakpoints/Makefile b/tools/testing/selftests/breakpoints/Makefile index 74e533fd4bc5..61b79e8df1f4 100644 --- a/tools/testing/selftests/breakpoints/Makefile +++ b/tools/testing/selftests/breakpoints/Makefile | |||
@@ -5,6 +5,9 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) | |||
5 | ifeq ($(ARCH),x86) | 5 | ifeq ($(ARCH),x86) |
6 | TEST_PROGS := breakpoint_test | 6 | TEST_PROGS := breakpoint_test |
7 | endif | 7 | endif |
8 | ifeq ($(ARCH),aarch64) | ||
9 | TEST_PROGS := breakpoint_test_arm64 | ||
10 | endif | ||
8 | 11 | ||
9 | TEST_PROGS += step_after_suspend_test | 12 | TEST_PROGS += step_after_suspend_test |
10 | 13 | ||
@@ -13,4 +16,4 @@ all: $(TEST_PROGS) | |||
13 | include ../lib.mk | 16 | include ../lib.mk |
14 | 17 | ||
15 | clean: | 18 | clean: |
16 | rm -fr breakpoint_test step_after_suspend_test | 19 | rm -fr breakpoint_test breakpoint_test_arm64 step_after_suspend_test |
diff --git a/tools/testing/selftests/breakpoints/breakpoint_test_arm64.c b/tools/testing/selftests/breakpoints/breakpoint_test_arm64.c new file mode 100644 index 000000000000..3897e996541e --- /dev/null +++ b/tools/testing/selftests/breakpoints/breakpoint_test_arm64.c | |||
@@ -0,0 +1,236 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Google, Inc. | ||
3 | * | ||
4 | * This software is licensed under the terms of the GNU General Public | ||
5 | * License version 2, as published by the Free Software Foundation, and | ||
6 | * may be copied, distributed, and modified under those terms. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * Original Code by Pavel Labath <labath@google.com> | ||
14 | * | ||
15 | * Code modified by Pratyush Anand <panand@redhat.com> | ||
16 | * for testing different byte select for each access size. | ||
17 | * | ||
18 | */ | ||
19 | |||
20 | #define _GNU_SOURCE | ||
21 | |||
22 | #include <sys/types.h> | ||
23 | #include <sys/wait.h> | ||
24 | #include <sys/ptrace.h> | ||
25 | #include <sys/param.h> | ||
26 | #include <sys/uio.h> | ||
27 | #include <stdint.h> | ||
28 | #include <stdbool.h> | ||
29 | #include <stddef.h> | ||
30 | #include <string.h> | ||
31 | #include <stdio.h> | ||
32 | #include <unistd.h> | ||
33 | #include <elf.h> | ||
34 | #include <errno.h> | ||
35 | #include <signal.h> | ||
36 | |||
37 | #include "../kselftest.h" | ||
38 | |||
39 | static volatile uint8_t var[96] __attribute__((__aligned__(32))); | ||
40 | |||
41 | static void child(int size, int wr) | ||
42 | { | ||
43 | volatile uint8_t *addr = &var[32 + wr]; | ||
44 | |||
45 | if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) { | ||
46 | perror("ptrace(PTRACE_TRACEME) failed"); | ||
47 | _exit(1); | ||
48 | } | ||
49 | |||
50 | if (raise(SIGSTOP) != 0) { | ||
51 | perror("raise(SIGSTOP) failed"); | ||
52 | _exit(1); | ||
53 | } | ||
54 | |||
55 | if ((uintptr_t) addr % size) { | ||
56 | perror("Wrong address write for the given size\n"); | ||
57 | _exit(1); | ||
58 | } | ||
59 | switch (size) { | ||
60 | case 1: | ||
61 | *addr = 47; | ||
62 | break; | ||
63 | case 2: | ||
64 | *(uint16_t *)addr = 47; | ||
65 | break; | ||
66 | case 4: | ||
67 | *(uint32_t *)addr = 47; | ||
68 | break; | ||
69 | case 8: | ||
70 | *(uint64_t *)addr = 47; | ||
71 | break; | ||
72 | case 16: | ||
73 | __asm__ volatile ("stp x29, x30, %0" : "=m" (addr[0])); | ||
74 | break; | ||
75 | case 32: | ||
76 | __asm__ volatile ("stp q29, q30, %0" : "=m" (addr[0])); | ||
77 | break; | ||
78 | } | ||
79 | |||
80 | _exit(0); | ||
81 | } | ||
82 | |||
83 | static bool set_watchpoint(pid_t pid, int size, int wp) | ||
84 | { | ||
85 | const volatile uint8_t *addr = &var[32 + wp]; | ||
86 | const int offset = (uintptr_t)addr % 8; | ||
87 | const unsigned int byte_mask = ((1 << size) - 1) << offset; | ||
88 | const unsigned int type = 2; /* Write */ | ||
89 | const unsigned int enable = 1; | ||
90 | const unsigned int control = byte_mask << 5 | type << 3 | enable; | ||
91 | struct user_hwdebug_state dreg_state; | ||
92 | struct iovec iov; | ||
93 | |||
94 | memset(&dreg_state, 0, sizeof(dreg_state)); | ||
95 | dreg_state.dbg_regs[0].addr = (uintptr_t)(addr - offset); | ||
96 | dreg_state.dbg_regs[0].ctrl = control; | ||
97 | iov.iov_base = &dreg_state; | ||
98 | iov.iov_len = offsetof(struct user_hwdebug_state, dbg_regs) + | ||
99 | sizeof(dreg_state.dbg_regs[0]); | ||
100 | if (ptrace(PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == 0) | ||
101 | return true; | ||
102 | |||
103 | if (errno == EIO) { | ||
104 | printf("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) " | ||
105 | "not supported on this hardware\n"); | ||
106 | ksft_exit_skip(); | ||
107 | } | ||
108 | perror("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) failed"); | ||
109 | return false; | ||
110 | } | ||
111 | |||
112 | static bool run_test(int wr_size, int wp_size, int wr, int wp) | ||
113 | { | ||
114 | int status; | ||
115 | siginfo_t siginfo; | ||
116 | pid_t pid = fork(); | ||
117 | pid_t wpid; | ||
118 | |||
119 | if (pid < 0) { | ||
120 | perror("fork() failed"); | ||
121 | return false; | ||
122 | } | ||
123 | if (pid == 0) | ||
124 | child(wr_size, wr); | ||
125 | |||
126 | wpid = waitpid(pid, &status, __WALL); | ||
127 | if (wpid != pid) { | ||
128 | perror("waitpid() failed"); | ||
129 | return false; | ||
130 | } | ||
131 | if (!WIFSTOPPED(status)) { | ||
132 | printf("child did not stop\n"); | ||
133 | return false; | ||
134 | } | ||
135 | if (WSTOPSIG(status) != SIGSTOP) { | ||
136 | printf("child did not stop with SIGSTOP\n"); | ||
137 | return false; | ||
138 | } | ||
139 | |||
140 | if (!set_watchpoint(pid, wp_size, wp)) | ||
141 | return false; | ||
142 | |||
143 | if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) { | ||
144 | perror("ptrace(PTRACE_SINGLESTEP) failed"); | ||
145 | return false; | ||
146 | } | ||
147 | |||
148 | alarm(3); | ||
149 | wpid = waitpid(pid, &status, __WALL); | ||
150 | if (wpid != pid) { | ||
151 | perror("waitpid() failed"); | ||
152 | return false; | ||
153 | } | ||
154 | alarm(0); | ||
155 | if (WIFEXITED(status)) { | ||
156 | printf("child did not single-step\t"); | ||
157 | return false; | ||
158 | } | ||
159 | if (!WIFSTOPPED(status)) { | ||
160 | printf("child did not stop\n"); | ||
161 | return false; | ||
162 | } | ||
163 | if (WSTOPSIG(status) != SIGTRAP) { | ||
164 | printf("child did not stop with SIGTRAP\n"); | ||
165 | return false; | ||
166 | } | ||
167 | if (ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo) != 0) { | ||
168 | perror("ptrace(PTRACE_GETSIGINFO)"); | ||
169 | return false; | ||
170 | } | ||
171 | if (siginfo.si_code != TRAP_HWBKPT) { | ||
172 | printf("Unexpected si_code %d\n", siginfo.si_code); | ||
173 | return false; | ||
174 | } | ||
175 | |||
176 | kill(pid, SIGKILL); | ||
177 | wpid = waitpid(pid, &status, 0); | ||
178 | if (wpid != pid) { | ||
179 | perror("waitpid() failed"); | ||
180 | return false; | ||
181 | } | ||
182 | return true; | ||
183 | } | ||
184 | |||
185 | static void sigalrm(int sig) | ||
186 | { | ||
187 | } | ||
188 | |||
189 | int main(int argc, char **argv) | ||
190 | { | ||
191 | int opt; | ||
192 | bool succeeded = true; | ||
193 | struct sigaction act; | ||
194 | int wr, wp, size; | ||
195 | bool result; | ||
196 | |||
197 | act.sa_handler = sigalrm; | ||
198 | sigemptyset(&act.sa_mask); | ||
199 | act.sa_flags = 0; | ||
200 | sigaction(SIGALRM, &act, NULL); | ||
201 | for (size = 1; size <= 32; size = size*2) { | ||
202 | for (wr = 0; wr <= 32; wr = wr + size) { | ||
203 | for (wp = wr - size; wp <= wr + size; wp = wp + size) { | ||
204 | printf("Test size = %d write offset = %d watchpoint offset = %d\t", size, wr, wp); | ||
205 | result = run_test(size, MIN(size, 8), wr, wp); | ||
206 | if ((result && wr == wp) || (!result && wr != wp)) { | ||
207 | printf("[OK]\n"); | ||
208 | ksft_inc_pass_cnt(); | ||
209 | } else { | ||
210 | printf("[FAILED]\n"); | ||
211 | ksft_inc_fail_cnt(); | ||
212 | succeeded = false; | ||
213 | } | ||
214 | } | ||
215 | } | ||
216 | } | ||
217 | |||
218 | for (size = 1; size <= 32; size = size*2) { | ||
219 | printf("Test size = %d write offset = %d watchpoint offset = -8\t", size, -size); | ||
220 | |||
221 | if (run_test(size, 8, -size, -8)) { | ||
222 | printf("[OK]\n"); | ||
223 | ksft_inc_pass_cnt(); | ||
224 | } else { | ||
225 | printf("[FAILED]\n"); | ||
226 | ksft_inc_fail_cnt(); | ||
227 | succeeded = false; | ||
228 | } | ||
229 | } | ||
230 | |||
231 | ksft_print_cnts(); | ||
232 | if (succeeded) | ||
233 | ksft_exit_pass(); | ||
234 | else | ||
235 | ksft_exit_fail(); | ||
236 | } | ||