Skip to content

Commit cb5aa63

Browse files
brooniectmarinas
authored andcommitted
kselftest/arm64: Add a smoke test for ptracing hardware break/watch points
There was a report that the hardware breakpoints and watch points weren't reporting the debug architecture version as expected, they were reporting a version of 0 which is not defined in the architecture. This happens when running in a KVM guest if the host has a debug architecture version not supported by KVM, it in turn confuses GDB which rejects any debug architecture version it does not know about. Add a test that covers that situation and while we're at it reports the debug architecture version and number of slots available to aid with figuring out problems that may arise. Signed-off-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 44c026a commit cb5aa63

File tree

1 file changed

+31
-1
lines changed
  • tools/testing/selftests/arm64/abi

1 file changed

+31
-1
lines changed

tools/testing/selftests/arm64/abi/ptrace.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include "../../kselftest.h"
2222

23-
#define EXPECTED_TESTS 7
23+
#define EXPECTED_TESTS 11
2424

2525
#define MAX_TPIDRS 2
2626

@@ -132,6 +132,34 @@ static void test_tpidr(pid_t child)
132132
}
133133
}
134134

135+
static void test_hw_debug(pid_t child, int type, const char *type_name)
136+
{
137+
struct user_hwdebug_state state;
138+
struct iovec iov;
139+
int slots, arch, ret;
140+
141+
iov.iov_len = sizeof(state);
142+
iov.iov_base = &state;
143+
144+
/* Should be able to read the values */
145+
ret = ptrace(PTRACE_GETREGSET, child, type, &iov);
146+
ksft_test_result(ret == 0, "read_%s\n", type_name);
147+
148+
if (ret == 0) {
149+
/* Low 8 bits is the number of slots, next 4 bits the arch */
150+
slots = state.dbg_info & 0xff;
151+
arch = (state.dbg_info >> 8) & 0xf;
152+
153+
ksft_print_msg("%s version %d with %d slots\n", type_name,
154+
arch, slots);
155+
156+
/* Zero is not currently architecturally valid */
157+
ksft_test_result(arch, "%s_arch_set\n", type_name);
158+
} else {
159+
ksft_test_result_skip("%s_arch_set\n");
160+
}
161+
}
162+
135163
static int do_child(void)
136164
{
137165
if (ptrace(PTRACE_TRACEME, -1, NULL, NULL))
@@ -207,6 +235,8 @@ static int do_parent(pid_t child)
207235
ksft_print_msg("Parent is %d, child is %d\n", getpid(), child);
208236

209237
test_tpidr(child);
238+
test_hw_debug(child, NT_ARM_HW_WATCH, "NT_ARM_HW_WATCH");
239+
test_hw_debug(child, NT_ARM_HW_BREAK, "NT_ARM_HW_BREAK");
210240

211241
ret = EXIT_SUCCESS;
212242

0 commit comments

Comments
 (0)