mirror of https://gitee.com/openkylin/linux.git
powerpc/watchpoint: Add DAR outside test in perf-hwbreak.c selftest
So far we used to ignore exception if DAR points outside of user specified range. But now we are ignoring it only if actual load/store range does not overlap with user specified range. Include selftests for the same: # ./tools/testing/selftests/powerpc/ptrace/perf-hwbreak ... TESTED: No overlap TESTED: Partial overlap TESTED: Partial overlap TESTED: No overlap TESTED: Full overlap success: perf_hwbreak Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20191017093204.7511-7-ravi.bangoria@linux.ibm.com
This commit is contained in:
parent
c2837acfbf
commit
949758a2f4
|
@ -148,6 +148,121 @@ static int runtestsingle(int readwriteflag, int exclude_user, int arraytest)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int runtest_dar_outside(void)
|
||||
{
|
||||
void *target;
|
||||
volatile __u16 temp16;
|
||||
volatile __u64 temp64;
|
||||
struct perf_event_attr attr;
|
||||
int break_fd;
|
||||
unsigned long long breaks;
|
||||
int fail = 0;
|
||||
size_t res;
|
||||
|
||||
target = malloc(8);
|
||||
if (!target) {
|
||||
perror("malloc failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* setup counters */
|
||||
memset(&attr, 0, sizeof(attr));
|
||||
attr.disabled = 1;
|
||||
attr.type = PERF_TYPE_BREAKPOINT;
|
||||
attr.exclude_kernel = 1;
|
||||
attr.exclude_hv = 1;
|
||||
attr.exclude_guest = 1;
|
||||
attr.bp_type = HW_BREAKPOINT_RW;
|
||||
/* watch middle half of target array */
|
||||
attr.bp_addr = (__u64)(target + 2);
|
||||
attr.bp_len = 4;
|
||||
break_fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
|
||||
if (break_fd < 0) {
|
||||
free(target);
|
||||
perror("sys_perf_event_open");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Shouldn't hit. */
|
||||
ioctl(break_fd, PERF_EVENT_IOC_RESET);
|
||||
ioctl(break_fd, PERF_EVENT_IOC_ENABLE);
|
||||
temp16 = *((__u16 *)target);
|
||||
*((__u16 *)target) = temp16;
|
||||
ioctl(break_fd, PERF_EVENT_IOC_DISABLE);
|
||||
res = read(break_fd, &breaks, sizeof(unsigned long long));
|
||||
assert(res == sizeof(unsigned long long));
|
||||
if (breaks == 0) {
|
||||
printf("TESTED: No overlap\n");
|
||||
} else {
|
||||
printf("FAILED: No overlap: %lld != 0\n", breaks);
|
||||
fail = 1;
|
||||
}
|
||||
|
||||
/* Hit */
|
||||
ioctl(break_fd, PERF_EVENT_IOC_RESET);
|
||||
ioctl(break_fd, PERF_EVENT_IOC_ENABLE);
|
||||
temp16 = *((__u16 *)(target + 1));
|
||||
*((__u16 *)(target + 1)) = temp16;
|
||||
ioctl(break_fd, PERF_EVENT_IOC_DISABLE);
|
||||
res = read(break_fd, &breaks, sizeof(unsigned long long));
|
||||
assert(res == sizeof(unsigned long long));
|
||||
if (breaks == 2) {
|
||||
printf("TESTED: Partial overlap\n");
|
||||
} else {
|
||||
printf("FAILED: Partial overlap: %lld != 2\n", breaks);
|
||||
fail = 1;
|
||||
}
|
||||
|
||||
/* Hit */
|
||||
ioctl(break_fd, PERF_EVENT_IOC_RESET);
|
||||
ioctl(break_fd, PERF_EVENT_IOC_ENABLE);
|
||||
temp16 = *((__u16 *)(target + 5));
|
||||
*((__u16 *)(target + 5)) = temp16;
|
||||
ioctl(break_fd, PERF_EVENT_IOC_DISABLE);
|
||||
res = read(break_fd, &breaks, sizeof(unsigned long long));
|
||||
assert(res == sizeof(unsigned long long));
|
||||
if (breaks == 2) {
|
||||
printf("TESTED: Partial overlap\n");
|
||||
} else {
|
||||
printf("FAILED: Partial overlap: %lld != 2\n", breaks);
|
||||
fail = 1;
|
||||
}
|
||||
|
||||
/* Shouldn't Hit */
|
||||
ioctl(break_fd, PERF_EVENT_IOC_RESET);
|
||||
ioctl(break_fd, PERF_EVENT_IOC_ENABLE);
|
||||
temp16 = *((__u16 *)(target + 6));
|
||||
*((__u16 *)(target + 6)) = temp16;
|
||||
ioctl(break_fd, PERF_EVENT_IOC_DISABLE);
|
||||
res = read(break_fd, &breaks, sizeof(unsigned long long));
|
||||
assert(res == sizeof(unsigned long long));
|
||||
if (breaks == 0) {
|
||||
printf("TESTED: No overlap\n");
|
||||
} else {
|
||||
printf("FAILED: No overlap: %lld != 0\n", breaks);
|
||||
fail = 1;
|
||||
}
|
||||
|
||||
/* Hit */
|
||||
ioctl(break_fd, PERF_EVENT_IOC_RESET);
|
||||
ioctl(break_fd, PERF_EVENT_IOC_ENABLE);
|
||||
temp64 = *((__u64 *)target);
|
||||
*((__u64 *)target) = temp64;
|
||||
ioctl(break_fd, PERF_EVENT_IOC_DISABLE);
|
||||
res = read(break_fd, &breaks, sizeof(unsigned long long));
|
||||
assert(res == sizeof(unsigned long long));
|
||||
if (breaks == 2) {
|
||||
printf("TESTED: Full overlap\n");
|
||||
} else {
|
||||
printf("FAILED: Full overlap: %lld != 2\n", breaks);
|
||||
fail = 1;
|
||||
}
|
||||
|
||||
free(target);
|
||||
close(break_fd);
|
||||
return fail;
|
||||
}
|
||||
|
||||
static int runtest(void)
|
||||
{
|
||||
int rwflag;
|
||||
|
@ -172,7 +287,9 @@ static int runtest(void)
|
|||
return ret;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
ret = runtest_dar_outside();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue