Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Frederic Weisbecker | 2da3e16 | 2009-11-05 23:06:50 +0100 | [diff] [blame] | 2 | #ifndef _LINUX_HW_BREAKPOINT_H |
| 3 | #define _LINUX_HW_BREAKPOINT_H |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 4 | |
Frederic Weisbecker | e6db487 | 2009-11-23 15:42:32 +0100 | [diff] [blame] | 5 | #include <linux/perf_event.h> |
David Howells | d2709c7 | 2012-11-19 22:21:03 +0000 | [diff] [blame] | 6 | #include <uapi/linux/hw_breakpoint.h> |
Frederic Weisbecker | e6db487 | 2009-11-23 15:42:32 +0100 | [diff] [blame] | 7 | |
Frederic Weisbecker | fa7c27e | 2009-11-23 22:30:12 +0100 | [diff] [blame] | 8 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 9 | |
Jason Wessel | 3c502e7 | 2010-11-04 17:33:01 -0500 | [diff] [blame] | 10 | extern int __init init_hw_breakpoint(void); |
| 11 | |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 12 | static inline void hw_breakpoint_init(struct perf_event_attr *attr) |
| 13 | { |
Frederic Weisbecker | ed872d0 | 2009-12-07 03:14:17 +0100 | [diff] [blame] | 14 | memset(attr, 0, sizeof(*attr)); |
| 15 | |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 16 | attr->type = PERF_TYPE_BREAKPOINT; |
| 17 | attr->size = sizeof(*attr); |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 18 | /* |
| 19 | * As it's for in-kernel or ptrace use, we want it to be pinned |
| 20 | * and to call its callback every hits. |
| 21 | */ |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 22 | attr->pinned = 1; |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 23 | attr->sample_period = 1; |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 24 | } |
| 25 | |
Frederic Weisbecker | 73266fc | 2010-04-22 05:05:45 +0200 | [diff] [blame] | 26 | static inline void ptrace_breakpoint_init(struct perf_event_attr *attr) |
| 27 | { |
| 28 | hw_breakpoint_init(attr); |
| 29 | attr->exclude_kernel = 1; |
| 30 | } |
| 31 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 32 | static inline unsigned long hw_breakpoint_addr(struct perf_event *bp) |
| 33 | { |
| 34 | return bp->attr.bp_addr; |
| 35 | } |
| 36 | |
| 37 | static inline int hw_breakpoint_type(struct perf_event *bp) |
| 38 | { |
| 39 | return bp->attr.bp_type; |
| 40 | } |
| 41 | |
Mahesh Salgaonkar | cd75764 | 2010-01-30 10:25:18 +0530 | [diff] [blame] | 42 | static inline unsigned long hw_breakpoint_len(struct perf_event *bp) |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 43 | { |
| 44 | return bp->attr.bp_len; |
| 45 | } |
| 46 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 47 | extern struct perf_event * |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 48 | register_user_hw_breakpoint(struct perf_event_attr *attr, |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 49 | perf_overflow_handler_t triggered, |
Avi Kivity | 4dc0da8 | 2011-06-29 18:42:35 +0300 | [diff] [blame] | 50 | void *context, |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 51 | struct task_struct *tsk); |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 52 | |
| 53 | /* FIXME: only change from the attr, and don't unregister */ |
Frederic Weisbecker | 44234ad | 2009-12-09 09:25:48 +0100 | [diff] [blame] | 54 | extern int |
Frederic Weisbecker | 2f0993e | 2009-12-05 07:06:10 +0100 | [diff] [blame] | 55 | modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr); |
Milind Chabbi | 32ff77e | 2018-03-12 14:45:47 +0100 | [diff] [blame] | 56 | extern int |
| 57 | modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *attr, |
| 58 | bool check); |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 59 | |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 60 | /* |
| 61 | * Kernel breakpoints are not associated with any particular thread. |
| 62 | */ |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 63 | extern struct perf_event * |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 64 | register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr, |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 65 | perf_overflow_handler_t triggered, |
Avi Kivity | 4dc0da8 | 2011-06-29 18:42:35 +0300 | [diff] [blame] | 66 | void *context, |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 67 | int cpu); |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 68 | |
Tejun Heo | 44ee635 | 2010-02-17 10:50:50 +0900 | [diff] [blame] | 69 | extern struct perf_event * __percpu * |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 70 | register_wide_hw_breakpoint(struct perf_event_attr *attr, |
Avi Kivity | 4dc0da8 | 2011-06-29 18:42:35 +0300 | [diff] [blame] | 71 | perf_overflow_handler_t triggered, |
| 72 | void *context); |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 73 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 74 | extern int register_perf_hw_breakpoint(struct perf_event *bp); |
| 75 | extern int __register_perf_hw_breakpoint(struct perf_event *bp); |
| 76 | extern void unregister_hw_breakpoint(struct perf_event *bp); |
Tejun Heo | 44ee635 | 2010-02-17 10:50:50 +0900 | [diff] [blame] | 77 | extern void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events); |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 78 | |
Jason Wessel | 5352ae63 | 2010-01-28 17:04:43 -0600 | [diff] [blame] | 79 | extern int dbg_reserve_bp_slot(struct perf_event *bp); |
| 80 | extern int dbg_release_bp_slot(struct perf_event *bp); |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 81 | extern int reserve_bp_slot(struct perf_event *bp); |
| 82 | extern void release_bp_slot(struct perf_event *bp); |
| 83 | |
| 84 | extern void flush_ptrace_hw_breakpoint(struct task_struct *tsk); |
| 85 | |
Frederic Weisbecker | 687b16f | 2009-11-13 13:16:15 +0100 | [diff] [blame] | 86 | static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp) |
| 87 | { |
| 88 | return &bp->hw.info; |
| 89 | } |
| 90 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 91 | #else /* !CONFIG_HAVE_HW_BREAKPOINT */ |
| 92 | |
Jason Wessel | 3c502e7 | 2010-11-04 17:33:01 -0500 | [diff] [blame] | 93 | static inline int __init init_hw_breakpoint(void) { return 0; } |
| 94 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 95 | static inline struct perf_event * |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 96 | register_user_hw_breakpoint(struct perf_event_attr *attr, |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 97 | perf_overflow_handler_t triggered, |
Avi Kivity | 4dc0da8 | 2011-06-29 18:42:35 +0300 | [diff] [blame] | 98 | void *context, |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 99 | struct task_struct *tsk) { return NULL; } |
Frederic Weisbecker | 44234ad | 2009-12-09 09:25:48 +0100 | [diff] [blame] | 100 | static inline int |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 101 | modify_user_hw_breakpoint(struct perf_event *bp, |
Frederic Weisbecker | 99ac64c | 2009-12-11 11:58:42 +0100 | [diff] [blame] | 102 | struct perf_event_attr *attr) { return -ENOSYS; } |
Milind Chabbi | 32ff77e | 2018-03-12 14:45:47 +0100 | [diff] [blame] | 103 | static inline int |
| 104 | modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *attr, |
| 105 | bool check) { return -ENOSYS; } |
| 106 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 107 | static inline struct perf_event * |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 108 | register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr, |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 109 | perf_overflow_handler_t triggered, |
Avi Kivity | 4dc0da8 | 2011-06-29 18:42:35 +0300 | [diff] [blame] | 110 | void *context, |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 111 | int cpu) { return NULL; } |
Tejun Heo | 44ee635 | 2010-02-17 10:50:50 +0900 | [diff] [blame] | 112 | static inline struct perf_event * __percpu * |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 113 | register_wide_hw_breakpoint(struct perf_event_attr *attr, |
Avi Kivity | 4dc0da8 | 2011-06-29 18:42:35 +0300 | [diff] [blame] | 114 | perf_overflow_handler_t triggered, |
| 115 | void *context) { return NULL; } |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 116 | static inline int |
| 117 | register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; } |
| 118 | static inline int |
| 119 | __register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; } |
| 120 | static inline void unregister_hw_breakpoint(struct perf_event *bp) { } |
| 121 | static inline void |
Tejun Heo | 44ee635 | 2010-02-17 10:50:50 +0900 | [diff] [blame] | 122 | unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events) { } |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 123 | static inline int |
| 124 | reserve_bp_slot(struct perf_event *bp) {return -ENOSYS; } |
| 125 | static inline void release_bp_slot(struct perf_event *bp) { } |
| 126 | |
| 127 | static inline void flush_ptrace_hw_breakpoint(struct task_struct *tsk) { } |
| 128 | |
Frederic Weisbecker | 687b16f | 2009-11-13 13:16:15 +0100 | [diff] [blame] | 129 | static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp) |
| 130 | { |
| 131 | return NULL; |
| 132 | } |
| 133 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 134 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 135 | #endif /* _LINUX_HW_BREAKPOINT_H */ |