12 #define __SANE_USERSPACE_TYPES__ 18 #include <sys/ioctl.h> 23 #include <linux/compiler.h> 24 #include <linux/hw_breakpoint.h> 44 #if defined (__x86_64__) 47 ".globl __test_function\n" 51 #elif defined (__aarch64__) 54 ".globl __test_function\n" 74 siginfo_t *oh __maybe_unused,
75 void *uc __maybe_unused)
79 ioctl(
fd1, PERF_EVENT_IOC_DISABLE, 0);
80 ioctl(
fd2, PERF_EVENT_IOC_DISABLE, 0);
81 ioctl(
fd3, PERF_EVENT_IOC_DISABLE, 0);
86 siginfo_t *oh __maybe_unused,
87 void *uc __maybe_unused)
100 ioctl(
fd1, PERF_EVENT_IOC_DISABLE, 0);
101 ioctl(
fd2, PERF_EVENT_IOC_DISABLE, 0);
102 ioctl(
fd3, PERF_EVENT_IOC_DISABLE, 0);
106 static int __event(
bool is_x,
void *addr,
int sig)
108 struct perf_event_attr pe;
111 memset(&pe, 0,
sizeof(
struct perf_event_attr));
112 pe.type = PERF_TYPE_BREAKPOINT;
113 pe.size =
sizeof(
struct perf_event_attr);
116 pe.bp_type = is_x ? HW_BREAKPOINT_X : HW_BREAKPOINT_W;
117 pe.bp_addr = (
unsigned long) addr;
118 pe.bp_len =
sizeof(long);
120 pe.sample_period = 1;
121 pe.sample_type = PERF_SAMPLE_IP;
122 pe.wakeup_events = 1;
125 pe.exclude_kernel = 1;
131 pr_debug(
"failed opening event %llx\n", pe.config);
135 fcntl(fd, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC);
136 fcntl(fd, F_SETSIG, sig);
137 fcntl(fd, F_SETOWN, getpid());
139 ioctl(fd, PERF_EVENT_IOC_RESET, 0);
146 return __event(
true, addr, sig);
151 return __event(
false, addr, sig);
159 ret = read(fd, &count,
sizeof(
long long));
160 if (ret !=
sizeof(
long long)) {
161 pr_debug(
"failed to read: %d\n", ret);
171 long long count1, count2, count3;
174 memset(&sa, 0,
sizeof(
struct sigaction));
176 sa.sa_flags = SA_SIGINFO;
178 if (sigaction(SIGIO, &sa, NULL) < 0) {
179 pr_debug(
"failed setting up signal handler\n");
184 if (sigaction(SIGUSR1, &sa, NULL) < 0) {
185 pr_debug(
"failed setting up signal handler 2\n");
244 ioctl(
fd1, PERF_EVENT_IOC_ENABLE, 0);
245 ioctl(
fd2, PERF_EVENT_IOC_ENABLE, 0);
246 ioctl(
fd3, PERF_EVENT_IOC_ENABLE, 0);
254 ioctl(
fd1, PERF_EVENT_IOC_DISABLE, 0);
255 ioctl(
fd2, PERF_EVENT_IOC_DISABLE, 0);
256 ioctl(
fd3, PERF_EVENT_IOC_DISABLE, 0);
266 pr_debug(
"count1 %lld, count2 %lld, count3 %lld, overflow %d, overflows_2 %d\n",
271 pr_debug(
"failed: RF EFLAG recursion issue detected\n");
273 pr_debug(
"failed: wrong count for bp1%lld\n", count1);
277 pr_debug(
"failed: wrong overflow hit\n");
280 pr_debug(
"failed: wrong overflow_2 hit\n");
283 pr_debug(
"failed: wrong count for bp2\n");
286 pr_debug(
"failed: wrong count for bp3\n");
299 #if defined(__powerpc__) || defined(__s390x__) bool test__bp_signal_is_supported(void)
static long long bp_count(int fd)
int test__bp_signal(struct test *test __maybe_unused, int subtest __maybe_unused)
static void sig_handler_2(int signum __maybe_unused, siginfo_t *oh __maybe_unused, void *uc __maybe_unused)
static void __test_function(volatile long *ptr)
static int sys_perf_event_open(struct perf_event_attr *attr, pid_t pid, int cpu, int group_fd, unsigned long flags)
static int bp_event(void *addr, int sig)
x86 movsq based memset() in arch/x86/lib/memset_64.S") MEMSET_FN(memset_erms
#define pr_debug(fmt,...)
static int wp_event(void *addr, int sig)
unsigned long perf_event_open_cloexec_flag(void)
static void sig_handler(int signum __maybe_unused, siginfo_t *oh __maybe_unused, void *uc __maybe_unused)
static noinline int test_function(void)
static int __event(bool is_x, void *addr, int sig)