blob: 9ddb6fddb4e01b52850ba173d53a24914b4eb4c9 [file] [log] [blame]
Steven Rostedt (VMware)179a0cc2018-08-16 11:20:54 -04001// SPDX-License-Identifier: GPL-2.0
Alexei Starovoitov25415172015-03-25 12:49:20 -07002/* Copyright (c) 2011-2015 PLUMgrid, http://plumgrid.com
Alexei Starovoitov0515e592016-09-01 18:37:22 -07003 * Copyright (c) 2016 Facebook
Alexei Starovoitov25415172015-03-25 12:49:20 -07004 */
5#include <linux/kernel.h>
6#include <linux/types.h>
7#include <linux/slab.h>
8#include <linux/bpf.h>
Alexei Starovoitov0515e592016-09-01 18:37:22 -07009#include <linux/bpf_perf_event.h>
Alexei Starovoitov25415172015-03-25 12:49:20 -070010#include <linux/filter.h>
11#include <linux/uaccess.h>
Alexei Starovoitov9c959c82015-03-25 12:49:22 -070012#include <linux/ctype.h>
Josef Bacik9802d862017-12-11 11:36:48 -050013#include <linux/kprobes.h>
Yonghong Song41bdc4b2018-05-24 11:21:09 -070014#include <linux/syscalls.h>
Masami Hiramatsu540adea2018-01-13 02:55:03 +090015#include <linux/error-injection.h>
Josef Bacik9802d862017-12-11 11:36:48 -050016
17#include "trace_probe.h"
Alexei Starovoitov25415172015-03-25 12:49:20 -070018#include "trace.h"
19
Matt Mullinsa38d1102018-12-12 16:42:37 -080020#ifdef CONFIG_MODULES
21struct bpf_trace_module {
22 struct module *module;
23 struct list_head list;
24};
25
26static LIST_HEAD(bpf_trace_modules);
27static DEFINE_MUTEX(bpf_module_mutex);
28
29static struct bpf_raw_event_map *bpf_get_raw_tracepoint_module(const char *name)
30{
31 struct bpf_raw_event_map *btp, *ret = NULL;
32 struct bpf_trace_module *btm;
33 unsigned int i;
34
35 mutex_lock(&bpf_module_mutex);
36 list_for_each_entry(btm, &bpf_trace_modules, list) {
37 for (i = 0; i < btm->module->num_bpf_raw_events; ++i) {
38 btp = &btm->module->bpf_raw_events[i];
39 if (!strcmp(btp->tp->name, name)) {
40 if (try_module_get(btm->module))
41 ret = btp;
42 goto out;
43 }
44 }
45 }
46out:
47 mutex_unlock(&bpf_module_mutex);
48 return ret;
49}
50#else
51static struct bpf_raw_event_map *bpf_get_raw_tracepoint_module(const char *name)
52{
53 return NULL;
54}
55#endif /* CONFIG_MODULES */
56
Gianluca Borello035226b2017-10-26 01:47:42 +000057u64 bpf_get_stackid(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
Yonghong Songc195651e2018-04-28 22:28:08 -070058u64 bpf_get_stack(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
Gianluca Borello035226b2017-10-26 01:47:42 +000059
Alexei Starovoitov25415172015-03-25 12:49:20 -070060/**
61 * trace_call_bpf - invoke BPF program
Yonghong Songe87c6bc2017-10-23 23:53:08 -070062 * @call: tracepoint event
Alexei Starovoitov25415172015-03-25 12:49:20 -070063 * @ctx: opaque context pointer
64 *
65 * kprobe handlers execute BPF programs via this helper.
66 * Can be used from static tracepoints in the future.
67 *
68 * Return: BPF programs always return an integer which is interpreted by
69 * kprobe handler as:
70 * 0 - return from kprobe (event is filtered out)
71 * 1 - store kprobe event into ring buffer
72 * Other values are reserved and currently alias to 1
73 */
Yonghong Songe87c6bc2017-10-23 23:53:08 -070074unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
Alexei Starovoitov25415172015-03-25 12:49:20 -070075{
76 unsigned int ret;
77
78 if (in_nmi()) /* not supported yet */
79 return 1;
80
81 preempt_disable();
82
83 if (unlikely(__this_cpu_inc_return(bpf_prog_active) != 1)) {
84 /*
85 * since some bpf program is already running on this cpu,
86 * don't call into another bpf program (same or different)
87 * and don't send kprobe event into ring-buffer,
88 * so return zero here
89 */
90 ret = 0;
91 goto out;
92 }
93
Yonghong Songe87c6bc2017-10-23 23:53:08 -070094 /*
95 * Instead of moving rcu_read_lock/rcu_dereference/rcu_read_unlock
96 * to all call sites, we did a bpf_prog_array_valid() there to check
97 * whether call->prog_array is empty or not, which is
98 * a heurisitc to speed up execution.
99 *
100 * If bpf_prog_array_valid() fetched prog_array was
101 * non-NULL, we go into trace_call_bpf() and do the actual
102 * proper rcu_dereference() under RCU lock.
103 * If it turns out that prog_array is NULL then, we bail out.
104 * For the opposite, if the bpf_prog_array_valid() fetched pointer
105 * was NULL, you'll skip the prog_array with the risk of missing
106 * out of events when it was updated in between this and the
107 * rcu_dereference() which is accepted risk.
108 */
109 ret = BPF_PROG_RUN_ARRAY_CHECK(call->prog_array, ctx, BPF_PROG_RUN);
Alexei Starovoitov25415172015-03-25 12:49:20 -0700110
111 out:
112 __this_cpu_dec(bpf_prog_active);
113 preempt_enable();
114
115 return ret;
116}
117EXPORT_SYMBOL_GPL(trace_call_bpf);
118
Josef Bacik9802d862017-12-11 11:36:48 -0500119#ifdef CONFIG_BPF_KPROBE_OVERRIDE
120BPF_CALL_2(bpf_override_return, struct pt_regs *, regs, unsigned long, rc)
121{
Josef Bacik9802d862017-12-11 11:36:48 -0500122 regs_set_return_value(regs, rc);
Masami Hiramatsu540adea2018-01-13 02:55:03 +0900123 override_function_with_return(regs);
Josef Bacik9802d862017-12-11 11:36:48 -0500124 return 0;
125}
126
127static const struct bpf_func_proto bpf_override_return_proto = {
128 .func = bpf_override_return,
129 .gpl_only = true,
130 .ret_type = RET_INTEGER,
131 .arg1_type = ARG_PTR_TO_CTX,
132 .arg2_type = ARG_ANYTHING,
133};
134#endif
135
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200136BPF_CALL_3(bpf_probe_read, void *, dst, u32, size, const void *, unsafe_ptr)
Alexei Starovoitov25415172015-03-25 12:49:20 -0700137{
Gianluca Borelloeb33f2c2017-11-22 18:32:54 +0000138 int ret;
Alexei Starovoitov25415172015-03-25 12:49:20 -0700139
Daniel Borkmann074f528e2016-04-13 00:10:52 +0200140 ret = probe_kernel_read(dst, unsafe_ptr, size);
141 if (unlikely(ret < 0))
142 memset(dst, 0, size);
143
144 return ret;
Alexei Starovoitov25415172015-03-25 12:49:20 -0700145}
146
147static const struct bpf_func_proto bpf_probe_read_proto = {
148 .func = bpf_probe_read,
149 .gpl_only = true,
150 .ret_type = RET_INTEGER,
Alexei Starovoitov39f19ebb2017-01-09 10:19:50 -0800151 .arg1_type = ARG_PTR_TO_UNINIT_MEM,
Yonghong Song9c019e22017-11-12 14:49:10 -0800152 .arg2_type = ARG_CONST_SIZE_OR_ZERO,
Alexei Starovoitov25415172015-03-25 12:49:20 -0700153 .arg3_type = ARG_ANYTHING,
154};
155
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200156BPF_CALL_3(bpf_probe_write_user, void *, unsafe_ptr, const void *, src,
157 u32, size)
Sargun Dhillon96ae5222016-07-25 05:54:46 -0700158{
Sargun Dhillon96ae5222016-07-25 05:54:46 -0700159 /*
160 * Ensure we're in user context which is safe for the helper to
161 * run. This helper has no business in a kthread.
162 *
163 * access_ok() should prevent writing to non-user memory, but in
164 * some situations (nommu, temporary switch, etc) access_ok() does
165 * not provide enough validation, hence the check on KERNEL_DS.
166 */
167
168 if (unlikely(in_interrupt() ||
169 current->flags & (PF_KTHREAD | PF_EXITING)))
170 return -EPERM;
Al Virodb68ce12017-03-20 21:08:07 -0400171 if (unlikely(uaccess_kernel()))
Sargun Dhillon96ae5222016-07-25 05:54:46 -0700172 return -EPERM;
173 if (!access_ok(VERIFY_WRITE, unsafe_ptr, size))
174 return -EPERM;
175
176 return probe_kernel_write(unsafe_ptr, src, size);
177}
178
179static const struct bpf_func_proto bpf_probe_write_user_proto = {
180 .func = bpf_probe_write_user,
181 .gpl_only = true,
182 .ret_type = RET_INTEGER,
183 .arg1_type = ARG_ANYTHING,
Alexei Starovoitov39f19ebb2017-01-09 10:19:50 -0800184 .arg2_type = ARG_PTR_TO_MEM,
185 .arg3_type = ARG_CONST_SIZE,
Sargun Dhillon96ae5222016-07-25 05:54:46 -0700186};
187
188static const struct bpf_func_proto *bpf_get_probe_write_proto(void)
189{
190 pr_warn_ratelimited("%s[%d] is installing a program with bpf_probe_write_user helper that may corrupt user memory!",
191 current->comm, task_pid_nr(current));
192
193 return &bpf_probe_write_user_proto;
194}
195
Alexei Starovoitov9c959c82015-03-25 12:49:22 -0700196/*
John Fastabend7bda4b42017-07-02 02:13:29 +0200197 * Only limited trace_printk() conversion specifiers allowed:
198 * %d %i %u %x %ld %li %lu %lx %lld %lli %llu %llx %p %s
Alexei Starovoitov9c959c82015-03-25 12:49:22 -0700199 */
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200200BPF_CALL_5(bpf_trace_printk, char *, fmt, u32, fmt_size, u64, arg1,
201 u64, arg2, u64, arg3)
Alexei Starovoitov9c959c82015-03-25 12:49:22 -0700202{
Alexei Starovoitov8d3b7dc2015-08-28 15:56:23 -0700203 bool str_seen = false;
Alexei Starovoitov9c959c82015-03-25 12:49:22 -0700204 int mod[3] = {};
205 int fmt_cnt = 0;
Alexei Starovoitov8d3b7dc2015-08-28 15:56:23 -0700206 u64 unsafe_addr;
207 char buf[64];
Alexei Starovoitov9c959c82015-03-25 12:49:22 -0700208 int i;
209
210 /*
211 * bpf_check()->check_func_arg()->check_stack_boundary()
212 * guarantees that fmt points to bpf program stack,
213 * fmt_size bytes of it were initialized and fmt_size > 0
214 */
215 if (fmt[--fmt_size] != 0)
216 return -EINVAL;
217
218 /* check format string for allowed specifiers */
219 for (i = 0; i < fmt_size; i++) {
220 if ((!isprint(fmt[i]) && !isspace(fmt[i])) || !isascii(fmt[i]))
221 return -EINVAL;
222
223 if (fmt[i] != '%')
224 continue;
225
226 if (fmt_cnt >= 3)
227 return -EINVAL;
228
229 /* fmt[i] != 0 && fmt[last] == 0, so we can access fmt[i + 1] */
230 i++;
231 if (fmt[i] == 'l') {
232 mod[fmt_cnt]++;
233 i++;
Alexei Starovoitov8d3b7dc2015-08-28 15:56:23 -0700234 } else if (fmt[i] == 'p' || fmt[i] == 's') {
Alexei Starovoitov9c959c82015-03-25 12:49:22 -0700235 mod[fmt_cnt]++;
Martynas Pumputis1efb6ee2018-11-23 17:43:26 +0100236 /* disallow any further format extensions */
237 if (fmt[i + 1] != 0 &&
238 !isspace(fmt[i + 1]) &&
239 !ispunct(fmt[i + 1]))
Alexei Starovoitov9c959c82015-03-25 12:49:22 -0700240 return -EINVAL;
241 fmt_cnt++;
Martynas Pumputis1efb6ee2018-11-23 17:43:26 +0100242 if (fmt[i] == 's') {
Alexei Starovoitov8d3b7dc2015-08-28 15:56:23 -0700243 if (str_seen)
244 /* allow only one '%s' per fmt string */
245 return -EINVAL;
246 str_seen = true;
247
248 switch (fmt_cnt) {
249 case 1:
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200250 unsafe_addr = arg1;
251 arg1 = (long) buf;
Alexei Starovoitov8d3b7dc2015-08-28 15:56:23 -0700252 break;
253 case 2:
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200254 unsafe_addr = arg2;
255 arg2 = (long) buf;
Alexei Starovoitov8d3b7dc2015-08-28 15:56:23 -0700256 break;
257 case 3:
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200258 unsafe_addr = arg3;
259 arg3 = (long) buf;
Alexei Starovoitov8d3b7dc2015-08-28 15:56:23 -0700260 break;
261 }
262 buf[0] = 0;
263 strncpy_from_unsafe(buf,
264 (void *) (long) unsafe_addr,
265 sizeof(buf));
266 }
Alexei Starovoitov9c959c82015-03-25 12:49:22 -0700267 continue;
268 }
269
270 if (fmt[i] == 'l') {
271 mod[fmt_cnt]++;
272 i++;
273 }
274
John Fastabend7bda4b42017-07-02 02:13:29 +0200275 if (fmt[i] != 'i' && fmt[i] != 'd' &&
276 fmt[i] != 'u' && fmt[i] != 'x')
Alexei Starovoitov9c959c82015-03-25 12:49:22 -0700277 return -EINVAL;
278 fmt_cnt++;
279 }
280
Daniel Borkmann88a5c692017-08-16 01:45:33 +0200281/* Horrid workaround for getting va_list handling working with different
282 * argument type combinations generically for 32 and 64 bit archs.
283 */
284#define __BPF_TP_EMIT() __BPF_ARG3_TP()
285#define __BPF_TP(...) \
Yonghong Songeefa864a2018-01-17 09:19:32 -0800286 __trace_printk(0 /* Fake ip */, \
Daniel Borkmann88a5c692017-08-16 01:45:33 +0200287 fmt, ##__VA_ARGS__)
288
289#define __BPF_ARG1_TP(...) \
290 ((mod[0] == 2 || (mod[0] == 1 && __BITS_PER_LONG == 64)) \
291 ? __BPF_TP(arg1, ##__VA_ARGS__) \
292 : ((mod[0] == 1 || (mod[0] == 0 && __BITS_PER_LONG == 32)) \
293 ? __BPF_TP((long)arg1, ##__VA_ARGS__) \
294 : __BPF_TP((u32)arg1, ##__VA_ARGS__)))
295
296#define __BPF_ARG2_TP(...) \
297 ((mod[1] == 2 || (mod[1] == 1 && __BITS_PER_LONG == 64)) \
298 ? __BPF_ARG1_TP(arg2, ##__VA_ARGS__) \
299 : ((mod[1] == 1 || (mod[1] == 0 && __BITS_PER_LONG == 32)) \
300 ? __BPF_ARG1_TP((long)arg2, ##__VA_ARGS__) \
301 : __BPF_ARG1_TP((u32)arg2, ##__VA_ARGS__)))
302
303#define __BPF_ARG3_TP(...) \
304 ((mod[2] == 2 || (mod[2] == 1 && __BITS_PER_LONG == 64)) \
305 ? __BPF_ARG2_TP(arg3, ##__VA_ARGS__) \
306 : ((mod[2] == 1 || (mod[2] == 0 && __BITS_PER_LONG == 32)) \
307 ? __BPF_ARG2_TP((long)arg3, ##__VA_ARGS__) \
308 : __BPF_ARG2_TP((u32)arg3, ##__VA_ARGS__)))
309
310 return __BPF_TP_EMIT();
Alexei Starovoitov9c959c82015-03-25 12:49:22 -0700311}
312
313static const struct bpf_func_proto bpf_trace_printk_proto = {
314 .func = bpf_trace_printk,
315 .gpl_only = true,
316 .ret_type = RET_INTEGER,
Alexei Starovoitov39f19ebb2017-01-09 10:19:50 -0800317 .arg1_type = ARG_PTR_TO_MEM,
318 .arg2_type = ARG_CONST_SIZE,
Alexei Starovoitov9c959c82015-03-25 12:49:22 -0700319};
320
Alexei Starovoitov0756ea32015-06-12 19:39:13 -0700321const struct bpf_func_proto *bpf_get_trace_printk_proto(void)
322{
323 /*
324 * this program might be calling bpf_trace_printk,
325 * so allocate per-cpu printk buffers
326 */
327 trace_printk_init_buffers();
328
329 return &bpf_trace_printk_proto;
330}
331
Yonghong Song908432c2017-10-05 09:19:20 -0700332static __always_inline int
333get_map_perf_counter(struct bpf_map *map, u64 flags,
334 u64 *value, u64 *enabled, u64 *running)
Kaixu Xia35578d72015-08-06 07:02:35 +0000335{
Kaixu Xia35578d72015-08-06 07:02:35 +0000336 struct bpf_array *array = container_of(map, struct bpf_array, map);
Daniel Borkmann6816a7f2016-06-28 12:18:25 +0200337 unsigned int cpu = smp_processor_id();
338 u64 index = flags & BPF_F_INDEX_MASK;
Daniel Borkmann3b1efb12016-06-15 22:47:14 +0200339 struct bpf_event_entry *ee;
Kaixu Xia35578d72015-08-06 07:02:35 +0000340
Daniel Borkmann6816a7f2016-06-28 12:18:25 +0200341 if (unlikely(flags & ~(BPF_F_INDEX_MASK)))
342 return -EINVAL;
343 if (index == BPF_F_CURRENT_CPU)
344 index = cpu;
Kaixu Xia35578d72015-08-06 07:02:35 +0000345 if (unlikely(index >= array->map.max_entries))
346 return -E2BIG;
347
Daniel Borkmann3b1efb12016-06-15 22:47:14 +0200348 ee = READ_ONCE(array->ptrs[index]);
Daniel Borkmann1ca1cc92016-06-28 12:18:23 +0200349 if (!ee)
Kaixu Xia35578d72015-08-06 07:02:35 +0000350 return -ENOENT;
351
Yonghong Song908432c2017-10-05 09:19:20 -0700352 return perf_event_read_local(ee->event, value, enabled, running);
353}
354
355BPF_CALL_2(bpf_perf_event_read, struct bpf_map *, map, u64, flags)
356{
357 u64 value = 0;
358 int err;
359
360 err = get_map_perf_counter(map, flags, &value, NULL, NULL);
Kaixu Xia35578d72015-08-06 07:02:35 +0000361 /*
Alexei Starovoitovf91840a2017-06-02 21:03:52 -0700362 * this api is ugly since we miss [-22..-2] range of valid
363 * counter values, but that's uapi
Kaixu Xia35578d72015-08-06 07:02:35 +0000364 */
Alexei Starovoitovf91840a2017-06-02 21:03:52 -0700365 if (err)
366 return err;
367 return value;
Kaixu Xia35578d72015-08-06 07:02:35 +0000368}
369
Alexei Starovoitov62544ce2015-10-22 17:10:14 -0700370static const struct bpf_func_proto bpf_perf_event_read_proto = {
Kaixu Xia35578d72015-08-06 07:02:35 +0000371 .func = bpf_perf_event_read,
Alexei Starovoitov1075ef52015-10-23 14:58:19 -0700372 .gpl_only = true,
Kaixu Xia35578d72015-08-06 07:02:35 +0000373 .ret_type = RET_INTEGER,
374 .arg1_type = ARG_CONST_MAP_PTR,
375 .arg2_type = ARG_ANYTHING,
376};
377
Yonghong Song908432c2017-10-05 09:19:20 -0700378BPF_CALL_4(bpf_perf_event_read_value, struct bpf_map *, map, u64, flags,
379 struct bpf_perf_event_value *, buf, u32, size)
380{
381 int err = -EINVAL;
382
383 if (unlikely(size != sizeof(struct bpf_perf_event_value)))
384 goto clear;
385 err = get_map_perf_counter(map, flags, &buf->counter, &buf->enabled,
386 &buf->running);
387 if (unlikely(err))
388 goto clear;
389 return 0;
390clear:
391 memset(buf, 0, size);
392 return err;
393}
394
395static const struct bpf_func_proto bpf_perf_event_read_value_proto = {
396 .func = bpf_perf_event_read_value,
397 .gpl_only = true,
398 .ret_type = RET_INTEGER,
399 .arg1_type = ARG_CONST_MAP_PTR,
400 .arg2_type = ARG_ANYTHING,
401 .arg3_type = ARG_PTR_TO_UNINIT_MEM,
402 .arg4_type = ARG_CONST_SIZE,
403};
404
Daniel Borkmann283ca522017-12-12 02:25:30 +0100405static DEFINE_PER_CPU(struct perf_sample_data, bpf_trace_sd);
Daniel Borkmann20b9d7a2017-06-11 00:50:40 +0200406
Daniel Borkmann8e7a3922016-07-14 18:08:04 +0200407static __always_inline u64
408__bpf_perf_event_output(struct pt_regs *regs, struct bpf_map *map,
Daniel Borkmann283ca522017-12-12 02:25:30 +0100409 u64 flags, struct perf_sample_data *sd)
Alexei Starovoitova43eec32015-10-20 20:02:34 -0700410{
Alexei Starovoitova43eec32015-10-20 20:02:34 -0700411 struct bpf_array *array = container_of(map, struct bpf_array, map);
Daniel Borkmannd7931332016-06-28 12:18:24 +0200412 unsigned int cpu = smp_processor_id();
Daniel Borkmann1e337592016-04-18 21:01:23 +0200413 u64 index = flags & BPF_F_INDEX_MASK;
Daniel Borkmann3b1efb12016-06-15 22:47:14 +0200414 struct bpf_event_entry *ee;
Alexei Starovoitova43eec32015-10-20 20:02:34 -0700415 struct perf_event *event;
Alexei Starovoitova43eec32015-10-20 20:02:34 -0700416
Daniel Borkmann1e337592016-04-18 21:01:23 +0200417 if (index == BPF_F_CURRENT_CPU)
Daniel Borkmannd7931332016-06-28 12:18:24 +0200418 index = cpu;
Alexei Starovoitova43eec32015-10-20 20:02:34 -0700419 if (unlikely(index >= array->map.max_entries))
420 return -E2BIG;
421
Daniel Borkmann3b1efb12016-06-15 22:47:14 +0200422 ee = READ_ONCE(array->ptrs[index]);
Daniel Borkmann1ca1cc92016-06-28 12:18:23 +0200423 if (!ee)
Alexei Starovoitova43eec32015-10-20 20:02:34 -0700424 return -ENOENT;
425
Daniel Borkmann3b1efb12016-06-15 22:47:14 +0200426 event = ee->event;
Alexei Starovoitova43eec32015-10-20 20:02:34 -0700427 if (unlikely(event->attr.type != PERF_TYPE_SOFTWARE ||
428 event->attr.config != PERF_COUNT_SW_BPF_OUTPUT))
429 return -EINVAL;
430
Daniel Borkmannd7931332016-06-28 12:18:24 +0200431 if (unlikely(event->oncpu != cpu))
Alexei Starovoitova43eec32015-10-20 20:02:34 -0700432 return -EOPNOTSUPP;
433
Daniel Borkmann20b9d7a2017-06-11 00:50:40 +0200434 perf_event_output(event, sd, regs);
Alexei Starovoitova43eec32015-10-20 20:02:34 -0700435 return 0;
436}
437
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200438BPF_CALL_5(bpf_perf_event_output, struct pt_regs *, regs, struct bpf_map *, map,
439 u64, flags, void *, data, u64, size)
Daniel Borkmann8e7a3922016-07-14 18:08:04 +0200440{
Daniel Borkmann283ca522017-12-12 02:25:30 +0100441 struct perf_sample_data *sd = this_cpu_ptr(&bpf_trace_sd);
Daniel Borkmann8e7a3922016-07-14 18:08:04 +0200442 struct perf_raw_record raw = {
443 .frag = {
444 .size = size,
445 .data = data,
446 },
447 };
448
449 if (unlikely(flags & ~(BPF_F_INDEX_MASK)))
450 return -EINVAL;
451
Daniel Borkmann283ca522017-12-12 02:25:30 +0100452 perf_sample_data_init(sd, 0, 0);
453 sd->raw = &raw;
454
455 return __bpf_perf_event_output(regs, map, flags, sd);
Daniel Borkmann8e7a3922016-07-14 18:08:04 +0200456}
457
Alexei Starovoitova43eec32015-10-20 20:02:34 -0700458static const struct bpf_func_proto bpf_perf_event_output_proto = {
459 .func = bpf_perf_event_output,
Alexei Starovoitov1075ef52015-10-23 14:58:19 -0700460 .gpl_only = true,
Alexei Starovoitova43eec32015-10-20 20:02:34 -0700461 .ret_type = RET_INTEGER,
462 .arg1_type = ARG_PTR_TO_CTX,
463 .arg2_type = ARG_CONST_MAP_PTR,
464 .arg3_type = ARG_ANYTHING,
Alexei Starovoitov39f19ebb2017-01-09 10:19:50 -0800465 .arg4_type = ARG_PTR_TO_MEM,
Gianluca Borelloa60dd352017-11-22 18:32:56 +0000466 .arg5_type = ARG_CONST_SIZE_OR_ZERO,
Alexei Starovoitova43eec32015-10-20 20:02:34 -0700467};
468
Daniel Borkmannbd570ff2016-04-18 21:01:24 +0200469static DEFINE_PER_CPU(struct pt_regs, bpf_pt_regs);
Daniel Borkmann283ca522017-12-12 02:25:30 +0100470static DEFINE_PER_CPU(struct perf_sample_data, bpf_misc_sd);
Daniel Borkmannbd570ff2016-04-18 21:01:24 +0200471
Daniel Borkmann555c8a82016-07-14 18:08:05 +0200472u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
473 void *ctx, u64 ctx_size, bpf_ctx_copy_t ctx_copy)
Daniel Borkmannbd570ff2016-04-18 21:01:24 +0200474{
Daniel Borkmann283ca522017-12-12 02:25:30 +0100475 struct perf_sample_data *sd = this_cpu_ptr(&bpf_misc_sd);
Daniel Borkmannbd570ff2016-04-18 21:01:24 +0200476 struct pt_regs *regs = this_cpu_ptr(&bpf_pt_regs);
Daniel Borkmann555c8a82016-07-14 18:08:05 +0200477 struct perf_raw_frag frag = {
478 .copy = ctx_copy,
479 .size = ctx_size,
480 .data = ctx,
481 };
482 struct perf_raw_record raw = {
483 .frag = {
Andrew Morton183fc152016-07-18 15:50:58 -0700484 {
485 .next = ctx_size ? &frag : NULL,
486 },
Daniel Borkmann555c8a82016-07-14 18:08:05 +0200487 .size = meta_size,
488 .data = meta,
489 },
490 };
Daniel Borkmannbd570ff2016-04-18 21:01:24 +0200491
492 perf_fetch_caller_regs(regs);
Daniel Borkmann283ca522017-12-12 02:25:30 +0100493 perf_sample_data_init(sd, 0, 0);
494 sd->raw = &raw;
Daniel Borkmannbd570ff2016-04-18 21:01:24 +0200495
Daniel Borkmann283ca522017-12-12 02:25:30 +0100496 return __bpf_perf_event_output(regs, map, flags, sd);
Daniel Borkmannbd570ff2016-04-18 21:01:24 +0200497}
498
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200499BPF_CALL_0(bpf_get_current_task)
Alexei Starovoitov606274c2016-07-06 22:38:36 -0700500{
501 return (long) current;
502}
503
504static const struct bpf_func_proto bpf_get_current_task_proto = {
505 .func = bpf_get_current_task,
506 .gpl_only = true,
507 .ret_type = RET_INTEGER,
508};
509
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200510BPF_CALL_2(bpf_current_task_under_cgroup, struct bpf_map *, map, u32, idx)
Sargun Dhillon60d20f92016-08-12 08:56:52 -0700511{
Sargun Dhillon60d20f92016-08-12 08:56:52 -0700512 struct bpf_array *array = container_of(map, struct bpf_array, map);
513 struct cgroup *cgrp;
Sargun Dhillon60d20f92016-08-12 08:56:52 -0700514
Sargun Dhillon60d20f92016-08-12 08:56:52 -0700515 if (unlikely(idx >= array->map.max_entries))
516 return -E2BIG;
517
518 cgrp = READ_ONCE(array->ptrs[idx]);
519 if (unlikely(!cgrp))
520 return -EAGAIN;
521
522 return task_under_cgroup_hierarchy(current, cgrp);
523}
524
525static const struct bpf_func_proto bpf_current_task_under_cgroup_proto = {
526 .func = bpf_current_task_under_cgroup,
527 .gpl_only = false,
528 .ret_type = RET_INTEGER,
529 .arg1_type = ARG_CONST_MAP_PTR,
530 .arg2_type = ARG_ANYTHING,
531};
532
Gianluca Borelloa5e8c072017-01-18 17:55:49 +0000533BPF_CALL_3(bpf_probe_read_str, void *, dst, u32, size,
534 const void *, unsafe_ptr)
535{
536 int ret;
537
538 /*
539 * The strncpy_from_unsafe() call will likely not fill the entire
540 * buffer, but that's okay in this circumstance as we're probing
541 * arbitrary memory anyway similar to bpf_probe_read() and might
542 * as well probe the stack. Thus, memory is explicitly cleared
543 * only in error case, so that improper users ignoring return
544 * code altogether don't copy garbage; otherwise length of string
545 * is returned that can be used for bpf_perf_event_output() et al.
546 */
547 ret = strncpy_from_unsafe(dst, unsafe_ptr, size);
548 if (unlikely(ret < 0))
549 memset(dst, 0, size);
550
551 return ret;
552}
553
554static const struct bpf_func_proto bpf_probe_read_str_proto = {
555 .func = bpf_probe_read_str,
556 .gpl_only = true,
557 .ret_type = RET_INTEGER,
558 .arg1_type = ARG_PTR_TO_UNINIT_MEM,
Gianluca Borello5c4e1202017-11-22 18:32:55 +0000559 .arg2_type = ARG_CONST_SIZE_OR_ZERO,
Gianluca Borelloa5e8c072017-01-18 17:55:49 +0000560 .arg3_type = ARG_ANYTHING,
561};
562
Andrey Ignatov5e43f892018-03-30 15:08:00 -0700563static const struct bpf_func_proto *
564tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
Alexei Starovoitov25415172015-03-25 12:49:20 -0700565{
566 switch (func_id) {
567 case BPF_FUNC_map_lookup_elem:
568 return &bpf_map_lookup_elem_proto;
569 case BPF_FUNC_map_update_elem:
570 return &bpf_map_update_elem_proto;
571 case BPF_FUNC_map_delete_elem:
572 return &bpf_map_delete_elem_proto;
573 case BPF_FUNC_probe_read:
574 return &bpf_probe_read_proto;
Alexei Starovoitovd9847d32015-03-25 12:49:21 -0700575 case BPF_FUNC_ktime_get_ns:
576 return &bpf_ktime_get_ns_proto;
Alexei Starovoitov04fd61ab2015-05-19 16:59:03 -0700577 case BPF_FUNC_tail_call:
578 return &bpf_tail_call_proto;
Alexei Starovoitovffeedaf2015-06-12 19:39:12 -0700579 case BPF_FUNC_get_current_pid_tgid:
580 return &bpf_get_current_pid_tgid_proto;
Alexei Starovoitov606274c2016-07-06 22:38:36 -0700581 case BPF_FUNC_get_current_task:
582 return &bpf_get_current_task_proto;
Alexei Starovoitovffeedaf2015-06-12 19:39:12 -0700583 case BPF_FUNC_get_current_uid_gid:
584 return &bpf_get_current_uid_gid_proto;
585 case BPF_FUNC_get_current_comm:
586 return &bpf_get_current_comm_proto;
Alexei Starovoitov9c959c82015-03-25 12:49:22 -0700587 case BPF_FUNC_trace_printk:
Alexei Starovoitov0756ea32015-06-12 19:39:13 -0700588 return bpf_get_trace_printk_proto();
Alexei Starovoitovab1973d2015-06-12 19:39:14 -0700589 case BPF_FUNC_get_smp_processor_id:
590 return &bpf_get_smp_processor_id_proto;
Daniel Borkmann2d0e30c2016-10-21 12:46:33 +0200591 case BPF_FUNC_get_numa_node_id:
592 return &bpf_get_numa_node_id_proto;
Kaixu Xia35578d72015-08-06 07:02:35 +0000593 case BPF_FUNC_perf_event_read:
594 return &bpf_perf_event_read_proto;
Sargun Dhillon96ae5222016-07-25 05:54:46 -0700595 case BPF_FUNC_probe_write_user:
596 return bpf_get_probe_write_proto();
Sargun Dhillon60d20f92016-08-12 08:56:52 -0700597 case BPF_FUNC_current_task_under_cgroup:
598 return &bpf_current_task_under_cgroup_proto;
Alexei Starovoitov8937bd82016-08-11 18:17:18 -0700599 case BPF_FUNC_get_prandom_u32:
600 return &bpf_get_prandom_u32_proto;
Gianluca Borelloa5e8c072017-01-18 17:55:49 +0000601 case BPF_FUNC_probe_read_str:
602 return &bpf_probe_read_str_proto;
Yonghong Song34ea38c2018-06-04 08:53:41 -0700603#ifdef CONFIG_CGROUPS
Yonghong Songbf6fa2c82018-06-03 15:59:41 -0700604 case BPF_FUNC_get_current_cgroup_id:
605 return &bpf_get_current_cgroup_id_proto;
Yonghong Song34ea38c2018-06-04 08:53:41 -0700606#endif
Alexei Starovoitov9fd82b612016-04-06 18:43:26 -0700607 default:
608 return NULL;
609 }
610}
611
Andrey Ignatov5e43f892018-03-30 15:08:00 -0700612static const struct bpf_func_proto *
613kprobe_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
Alexei Starovoitov9fd82b612016-04-06 18:43:26 -0700614{
615 switch (func_id) {
Alexei Starovoitova43eec32015-10-20 20:02:34 -0700616 case BPF_FUNC_perf_event_output:
617 return &bpf_perf_event_output_proto;
Alexei Starovoitovd5a3b1f2016-02-17 19:58:58 -0800618 case BPF_FUNC_get_stackid:
619 return &bpf_get_stackid_proto;
Yonghong Songc195651e2018-04-28 22:28:08 -0700620 case BPF_FUNC_get_stack:
621 return &bpf_get_stack_proto;
Yonghong Song908432c2017-10-05 09:19:20 -0700622 case BPF_FUNC_perf_event_read_value:
623 return &bpf_perf_event_read_value_proto;
Josef Bacik9802d862017-12-11 11:36:48 -0500624#ifdef CONFIG_BPF_KPROBE_OVERRIDE
625 case BPF_FUNC_override_return:
626 return &bpf_override_return_proto;
627#endif
Alexei Starovoitov25415172015-03-25 12:49:20 -0700628 default:
Andrey Ignatov5e43f892018-03-30 15:08:00 -0700629 return tracing_func_proto(func_id, prog);
Alexei Starovoitov25415172015-03-25 12:49:20 -0700630 }
631}
632
633/* bpf+kprobe programs can access fields of 'struct pt_regs' */
Alexei Starovoitov19de99f2016-06-15 18:25:38 -0700634static bool kprobe_prog_is_valid_access(int off, int size, enum bpf_access_type type,
Andrey Ignatov5e43f892018-03-30 15:08:00 -0700635 const struct bpf_prog *prog,
Yonghong Song23994632017-06-22 15:07:39 -0700636 struct bpf_insn_access_aux *info)
Alexei Starovoitov25415172015-03-25 12:49:20 -0700637{
Alexei Starovoitov25415172015-03-25 12:49:20 -0700638 if (off < 0 || off >= sizeof(struct pt_regs))
639 return false;
Alexei Starovoitov25415172015-03-25 12:49:20 -0700640 if (type != BPF_READ)
641 return false;
Alexei Starovoitov25415172015-03-25 12:49:20 -0700642 if (off % size != 0)
643 return false;
Daniel Borkmann2d071c62017-01-15 01:34:25 +0100644 /*
645 * Assertion for 32 bit to make sure last 8 byte access
646 * (BPF_DW) to the last 4 byte member is disallowed.
647 */
648 if (off + size > sizeof(struct pt_regs))
649 return false;
650
Alexei Starovoitov25415172015-03-25 12:49:20 -0700651 return true;
652}
653
Jakub Kicinski7de16e32017-10-16 16:40:53 -0700654const struct bpf_verifier_ops kprobe_verifier_ops = {
Alexei Starovoitov25415172015-03-25 12:49:20 -0700655 .get_func_proto = kprobe_prog_func_proto,
656 .is_valid_access = kprobe_prog_is_valid_access,
657};
658
Jakub Kicinski7de16e32017-10-16 16:40:53 -0700659const struct bpf_prog_ops kprobe_prog_ops = {
660};
661
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200662BPF_CALL_5(bpf_perf_event_output_tp, void *, tp_buff, struct bpf_map *, map,
663 u64, flags, void *, data, u64, size)
Alexei Starovoitov9940d672016-04-06 18:43:27 -0700664{
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200665 struct pt_regs *regs = *(struct pt_regs **)tp_buff;
666
Alexei Starovoitov9940d672016-04-06 18:43:27 -0700667 /*
668 * r1 points to perf tracepoint buffer where first 8 bytes are hidden
669 * from bpf program and contain a pointer to 'struct pt_regs'. Fetch it
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200670 * from there and call the same bpf_perf_event_output() helper inline.
Alexei Starovoitov9940d672016-04-06 18:43:27 -0700671 */
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200672 return ____bpf_perf_event_output(regs, map, flags, data, size);
Alexei Starovoitov9940d672016-04-06 18:43:27 -0700673}
674
675static const struct bpf_func_proto bpf_perf_event_output_proto_tp = {
676 .func = bpf_perf_event_output_tp,
677 .gpl_only = true,
678 .ret_type = RET_INTEGER,
679 .arg1_type = ARG_PTR_TO_CTX,
680 .arg2_type = ARG_CONST_MAP_PTR,
681 .arg3_type = ARG_ANYTHING,
Alexei Starovoitov39f19ebb2017-01-09 10:19:50 -0800682 .arg4_type = ARG_PTR_TO_MEM,
Gianluca Borelloa60dd352017-11-22 18:32:56 +0000683 .arg5_type = ARG_CONST_SIZE_OR_ZERO,
Alexei Starovoitov9940d672016-04-06 18:43:27 -0700684};
685
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200686BPF_CALL_3(bpf_get_stackid_tp, void *, tp_buff, struct bpf_map *, map,
687 u64, flags)
Alexei Starovoitov9940d672016-04-06 18:43:27 -0700688{
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200689 struct pt_regs *regs = *(struct pt_regs **)tp_buff;
Alexei Starovoitov9940d672016-04-06 18:43:27 -0700690
Daniel Borkmannf3694e02016-09-09 02:45:31 +0200691 /*
692 * Same comment as in bpf_perf_event_output_tp(), only that this time
693 * the other helper's function body cannot be inlined due to being
694 * external, thus we need to call raw helper function.
695 */
696 return bpf_get_stackid((unsigned long) regs, (unsigned long) map,
697 flags, 0, 0);
Alexei Starovoitov9940d672016-04-06 18:43:27 -0700698}
699
700static const struct bpf_func_proto bpf_get_stackid_proto_tp = {
701 .func = bpf_get_stackid_tp,
702 .gpl_only = true,
703 .ret_type = RET_INTEGER,
704 .arg1_type = ARG_PTR_TO_CTX,
705 .arg2_type = ARG_CONST_MAP_PTR,
706 .arg3_type = ARG_ANYTHING,
707};
708
Yonghong Songc195651e2018-04-28 22:28:08 -0700709BPF_CALL_4(bpf_get_stack_tp, void *, tp_buff, void *, buf, u32, size,
710 u64, flags)
711{
712 struct pt_regs *regs = *(struct pt_regs **)tp_buff;
713
714 return bpf_get_stack((unsigned long) regs, (unsigned long) buf,
715 (unsigned long) size, flags, 0);
716}
717
718static const struct bpf_func_proto bpf_get_stack_proto_tp = {
719 .func = bpf_get_stack_tp,
720 .gpl_only = true,
721 .ret_type = RET_INTEGER,
722 .arg1_type = ARG_PTR_TO_CTX,
723 .arg2_type = ARG_PTR_TO_UNINIT_MEM,
724 .arg3_type = ARG_CONST_SIZE_OR_ZERO,
725 .arg4_type = ARG_ANYTHING,
726};
727
Andrey Ignatov5e43f892018-03-30 15:08:00 -0700728static const struct bpf_func_proto *
729tp_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
Alexei Starovoitov9fd82b612016-04-06 18:43:26 -0700730{
731 switch (func_id) {
732 case BPF_FUNC_perf_event_output:
Alexei Starovoitov9940d672016-04-06 18:43:27 -0700733 return &bpf_perf_event_output_proto_tp;
Alexei Starovoitov9fd82b612016-04-06 18:43:26 -0700734 case BPF_FUNC_get_stackid:
Alexei Starovoitov9940d672016-04-06 18:43:27 -0700735 return &bpf_get_stackid_proto_tp;
Yonghong Songc195651e2018-04-28 22:28:08 -0700736 case BPF_FUNC_get_stack:
737 return &bpf_get_stack_proto_tp;
Alexei Starovoitov9fd82b612016-04-06 18:43:26 -0700738 default:
Andrey Ignatov5e43f892018-03-30 15:08:00 -0700739 return tracing_func_proto(func_id, prog);
Alexei Starovoitov9fd82b612016-04-06 18:43:26 -0700740 }
741}
742
Alexei Starovoitov19de99f2016-06-15 18:25:38 -0700743static bool tp_prog_is_valid_access(int off, int size, enum bpf_access_type type,
Andrey Ignatov5e43f892018-03-30 15:08:00 -0700744 const struct bpf_prog *prog,
Yonghong Song23994632017-06-22 15:07:39 -0700745 struct bpf_insn_access_aux *info)
Alexei Starovoitov9fd82b612016-04-06 18:43:26 -0700746{
747 if (off < sizeof(void *) || off >= PERF_MAX_TRACE_SIZE)
748 return false;
749 if (type != BPF_READ)
750 return false;
751 if (off % size != 0)
752 return false;
Daniel Borkmann2d071c62017-01-15 01:34:25 +0100753
754 BUILD_BUG_ON(PERF_MAX_TRACE_SIZE % sizeof(__u64));
Alexei Starovoitov9fd82b612016-04-06 18:43:26 -0700755 return true;
756}
757
Jakub Kicinski7de16e32017-10-16 16:40:53 -0700758const struct bpf_verifier_ops tracepoint_verifier_ops = {
Alexei Starovoitov9fd82b612016-04-06 18:43:26 -0700759 .get_func_proto = tp_prog_func_proto,
760 .is_valid_access = tp_prog_is_valid_access,
761};
762
Jakub Kicinski7de16e32017-10-16 16:40:53 -0700763const struct bpf_prog_ops tracepoint_prog_ops = {
764};
765
Yonghong Songf005afe2018-03-20 11:19:17 -0700766BPF_CALL_3(bpf_perf_prog_read_value, struct bpf_perf_event_data_kern *, ctx,
767 struct bpf_perf_event_value *, buf, u32, size)
768{
769 int err = -EINVAL;
770
771 if (unlikely(size != sizeof(struct bpf_perf_event_value)))
772 goto clear;
773 err = perf_event_read_local(ctx->event, &buf->counter, &buf->enabled,
774 &buf->running);
775 if (unlikely(err))
776 goto clear;
777 return 0;
778clear:
779 memset(buf, 0, size);
780 return err;
781}
782
783static const struct bpf_func_proto bpf_perf_prog_read_value_proto = {
784 .func = bpf_perf_prog_read_value,
785 .gpl_only = true,
786 .ret_type = RET_INTEGER,
787 .arg1_type = ARG_PTR_TO_CTX,
788 .arg2_type = ARG_PTR_TO_UNINIT_MEM,
789 .arg3_type = ARG_CONST_SIZE,
790};
791
Andrey Ignatov5e43f892018-03-30 15:08:00 -0700792static const struct bpf_func_proto *
793pe_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
Yonghong Songf005afe2018-03-20 11:19:17 -0700794{
795 switch (func_id) {
796 case BPF_FUNC_perf_event_output:
797 return &bpf_perf_event_output_proto_tp;
798 case BPF_FUNC_get_stackid:
799 return &bpf_get_stackid_proto_tp;
Yonghong Songc195651e2018-04-28 22:28:08 -0700800 case BPF_FUNC_get_stack:
801 return &bpf_get_stack_proto_tp;
Yonghong Songf005afe2018-03-20 11:19:17 -0700802 case BPF_FUNC_perf_prog_read_value:
803 return &bpf_perf_prog_read_value_proto;
804 default:
Andrey Ignatov5e43f892018-03-30 15:08:00 -0700805 return tracing_func_proto(func_id, prog);
Yonghong Songf005afe2018-03-20 11:19:17 -0700806 }
807}
808
Alexei Starovoitovc4f66992018-03-28 12:05:37 -0700809/*
810 * bpf_raw_tp_regs are separate from bpf_pt_regs used from skb/xdp
811 * to avoid potential recursive reuse issue when/if tracepoints are added
Yonghong Songc195651e2018-04-28 22:28:08 -0700812 * inside bpf_*_event_output, bpf_get_stackid and/or bpf_get_stack
Alexei Starovoitovc4f66992018-03-28 12:05:37 -0700813 */
814static DEFINE_PER_CPU(struct pt_regs, bpf_raw_tp_regs);
815BPF_CALL_5(bpf_perf_event_output_raw_tp, struct bpf_raw_tracepoint_args *, args,
816 struct bpf_map *, map, u64, flags, void *, data, u64, size)
817{
818 struct pt_regs *regs = this_cpu_ptr(&bpf_raw_tp_regs);
819
820 perf_fetch_caller_regs(regs);
821 return ____bpf_perf_event_output(regs, map, flags, data, size);
822}
823
824static const struct bpf_func_proto bpf_perf_event_output_proto_raw_tp = {
825 .func = bpf_perf_event_output_raw_tp,
826 .gpl_only = true,
827 .ret_type = RET_INTEGER,
828 .arg1_type = ARG_PTR_TO_CTX,
829 .arg2_type = ARG_CONST_MAP_PTR,
830 .arg3_type = ARG_ANYTHING,
831 .arg4_type = ARG_PTR_TO_MEM,
832 .arg5_type = ARG_CONST_SIZE_OR_ZERO,
833};
834
835BPF_CALL_3(bpf_get_stackid_raw_tp, struct bpf_raw_tracepoint_args *, args,
836 struct bpf_map *, map, u64, flags)
837{
838 struct pt_regs *regs = this_cpu_ptr(&bpf_raw_tp_regs);
839
840 perf_fetch_caller_regs(regs);
841 /* similar to bpf_perf_event_output_tp, but pt_regs fetched differently */
842 return bpf_get_stackid((unsigned long) regs, (unsigned long) map,
843 flags, 0, 0);
844}
845
846static const struct bpf_func_proto bpf_get_stackid_proto_raw_tp = {
847 .func = bpf_get_stackid_raw_tp,
848 .gpl_only = true,
849 .ret_type = RET_INTEGER,
850 .arg1_type = ARG_PTR_TO_CTX,
851 .arg2_type = ARG_CONST_MAP_PTR,
852 .arg3_type = ARG_ANYTHING,
853};
854
Yonghong Songc195651e2018-04-28 22:28:08 -0700855BPF_CALL_4(bpf_get_stack_raw_tp, struct bpf_raw_tracepoint_args *, args,
856 void *, buf, u32, size, u64, flags)
857{
858 struct pt_regs *regs = this_cpu_ptr(&bpf_raw_tp_regs);
859
860 perf_fetch_caller_regs(regs);
861 return bpf_get_stack((unsigned long) regs, (unsigned long) buf,
862 (unsigned long) size, flags, 0);
863}
864
865static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = {
866 .func = bpf_get_stack_raw_tp,
867 .gpl_only = true,
868 .ret_type = RET_INTEGER,
869 .arg1_type = ARG_PTR_TO_CTX,
870 .arg2_type = ARG_PTR_TO_MEM,
871 .arg3_type = ARG_CONST_SIZE_OR_ZERO,
872 .arg4_type = ARG_ANYTHING,
873};
874
Andrey Ignatov5e43f892018-03-30 15:08:00 -0700875static const struct bpf_func_proto *
876raw_tp_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
Alexei Starovoitovc4f66992018-03-28 12:05:37 -0700877{
878 switch (func_id) {
879 case BPF_FUNC_perf_event_output:
880 return &bpf_perf_event_output_proto_raw_tp;
881 case BPF_FUNC_get_stackid:
882 return &bpf_get_stackid_proto_raw_tp;
Yonghong Songc195651e2018-04-28 22:28:08 -0700883 case BPF_FUNC_get_stack:
884 return &bpf_get_stack_proto_raw_tp;
Alexei Starovoitovc4f66992018-03-28 12:05:37 -0700885 default:
Andrey Ignatov5e43f892018-03-30 15:08:00 -0700886 return tracing_func_proto(func_id, prog);
Alexei Starovoitovc4f66992018-03-28 12:05:37 -0700887 }
888}
889
890static bool raw_tp_prog_is_valid_access(int off, int size,
891 enum bpf_access_type type,
Andrey Ignatov5e43f892018-03-30 15:08:00 -0700892 const struct bpf_prog *prog,
Alexei Starovoitovc4f66992018-03-28 12:05:37 -0700893 struct bpf_insn_access_aux *info)
894{
895 /* largest tracepoint in the kernel has 12 args */
896 if (off < 0 || off >= sizeof(__u64) * 12)
897 return false;
898 if (type != BPF_READ)
899 return false;
900 if (off % size != 0)
901 return false;
902 return true;
903}
904
905const struct bpf_verifier_ops raw_tracepoint_verifier_ops = {
906 .get_func_proto = raw_tp_prog_func_proto,
907 .is_valid_access = raw_tp_prog_is_valid_access,
908};
909
910const struct bpf_prog_ops raw_tracepoint_prog_ops = {
911};
912
Alexei Starovoitov0515e592016-09-01 18:37:22 -0700913static bool pe_prog_is_valid_access(int off, int size, enum bpf_access_type type,
Andrey Ignatov5e43f892018-03-30 15:08:00 -0700914 const struct bpf_prog *prog,
Yonghong Song23994632017-06-22 15:07:39 -0700915 struct bpf_insn_access_aux *info)
Alexei Starovoitov0515e592016-09-01 18:37:22 -0700916{
Teng Qin95da0cd2018-03-06 10:55:01 -0800917 const int size_u64 = sizeof(u64);
Yonghong Song31fd8582017-06-13 15:52:13 -0700918
Alexei Starovoitov0515e592016-09-01 18:37:22 -0700919 if (off < 0 || off >= sizeof(struct bpf_perf_event_data))
920 return false;
921 if (type != BPF_READ)
922 return false;
Daniel Borkmannbc231052018-06-02 23:06:39 +0200923 if (off % size != 0) {
924 if (sizeof(unsigned long) != 4)
925 return false;
926 if (size != 8)
927 return false;
928 if (off % size != 4)
929 return false;
930 }
Yonghong Song31fd8582017-06-13 15:52:13 -0700931
Daniel Borkmannf96da092017-07-02 02:13:27 +0200932 switch (off) {
933 case bpf_ctx_range(struct bpf_perf_event_data, sample_period):
Teng Qin95da0cd2018-03-06 10:55:01 -0800934 bpf_ctx_record_field_size(info, size_u64);
935 if (!bpf_ctx_narrow_access_ok(off, size, size_u64))
936 return false;
937 break;
938 case bpf_ctx_range(struct bpf_perf_event_data, addr):
939 bpf_ctx_record_field_size(info, size_u64);
940 if (!bpf_ctx_narrow_access_ok(off, size, size_u64))
Yonghong Song23994632017-06-22 15:07:39 -0700941 return false;
Daniel Borkmannf96da092017-07-02 02:13:27 +0200942 break;
943 default:
Alexei Starovoitov0515e592016-09-01 18:37:22 -0700944 if (size != sizeof(long))
945 return false;
946 }
Daniel Borkmannf96da092017-07-02 02:13:27 +0200947
Alexei Starovoitov0515e592016-09-01 18:37:22 -0700948 return true;
949}
950
Daniel Borkmann6b8cc1d2017-01-12 11:51:32 +0100951static u32 pe_prog_convert_ctx_access(enum bpf_access_type type,
952 const struct bpf_insn *si,
Alexei Starovoitov0515e592016-09-01 18:37:22 -0700953 struct bpf_insn *insn_buf,
Daniel Borkmannf96da092017-07-02 02:13:27 +0200954 struct bpf_prog *prog, u32 *target_size)
Alexei Starovoitov0515e592016-09-01 18:37:22 -0700955{
956 struct bpf_insn *insn = insn_buf;
957
Daniel Borkmann6b8cc1d2017-01-12 11:51:32 +0100958 switch (si->off) {
Alexei Starovoitov0515e592016-09-01 18:37:22 -0700959 case offsetof(struct bpf_perf_event_data, sample_period):
Daniel Borkmannf035a512016-09-09 02:45:29 +0200960 *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct bpf_perf_event_data_kern,
Daniel Borkmann6b8cc1d2017-01-12 11:51:32 +0100961 data), si->dst_reg, si->src_reg,
Alexei Starovoitov0515e592016-09-01 18:37:22 -0700962 offsetof(struct bpf_perf_event_data_kern, data));
Daniel Borkmann6b8cc1d2017-01-12 11:51:32 +0100963 *insn++ = BPF_LDX_MEM(BPF_DW, si->dst_reg, si->dst_reg,
Daniel Borkmannf96da092017-07-02 02:13:27 +0200964 bpf_target_off(struct perf_sample_data, period, 8,
965 target_size));
Alexei Starovoitov0515e592016-09-01 18:37:22 -0700966 break;
Teng Qin95da0cd2018-03-06 10:55:01 -0800967 case offsetof(struct bpf_perf_event_data, addr):
968 *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct bpf_perf_event_data_kern,
969 data), si->dst_reg, si->src_reg,
970 offsetof(struct bpf_perf_event_data_kern, data));
971 *insn++ = BPF_LDX_MEM(BPF_DW, si->dst_reg, si->dst_reg,
972 bpf_target_off(struct perf_sample_data, addr, 8,
973 target_size));
974 break;
Alexei Starovoitov0515e592016-09-01 18:37:22 -0700975 default:
Daniel Borkmannf035a512016-09-09 02:45:29 +0200976 *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct bpf_perf_event_data_kern,
Daniel Borkmann6b8cc1d2017-01-12 11:51:32 +0100977 regs), si->dst_reg, si->src_reg,
Alexei Starovoitov0515e592016-09-01 18:37:22 -0700978 offsetof(struct bpf_perf_event_data_kern, regs));
Daniel Borkmann6b8cc1d2017-01-12 11:51:32 +0100979 *insn++ = BPF_LDX_MEM(BPF_SIZEOF(long), si->dst_reg, si->dst_reg,
980 si->off);
Alexei Starovoitov0515e592016-09-01 18:37:22 -0700981 break;
982 }
983
984 return insn - insn_buf;
985}
986
Jakub Kicinski7de16e32017-10-16 16:40:53 -0700987const struct bpf_verifier_ops perf_event_verifier_ops = {
Yonghong Songf005afe2018-03-20 11:19:17 -0700988 .get_func_proto = pe_prog_func_proto,
Alexei Starovoitov0515e592016-09-01 18:37:22 -0700989 .is_valid_access = pe_prog_is_valid_access,
990 .convert_ctx_access = pe_prog_convert_ctx_access,
991};
Jakub Kicinski7de16e32017-10-16 16:40:53 -0700992
993const struct bpf_prog_ops perf_event_prog_ops = {
994};
Yonghong Songe87c6bc2017-10-23 23:53:08 -0700995
996static DEFINE_MUTEX(bpf_event_mutex);
997
Yonghong Songc8c088b2017-11-30 13:47:54 -0800998#define BPF_TRACE_MAX_PROGS 64
999
Yonghong Songe87c6bc2017-10-23 23:53:08 -07001000int perf_event_attach_bpf_prog(struct perf_event *event,
1001 struct bpf_prog *prog)
1002{
1003 struct bpf_prog_array __rcu *old_array;
1004 struct bpf_prog_array *new_array;
1005 int ret = -EEXIST;
1006
Josef Bacik9802d862017-12-11 11:36:48 -05001007 /*
Masami Hiramatsub4da3342018-01-13 02:54:04 +09001008 * Kprobe override only works if they are on the function entry,
1009 * and only if they are on the opt-in list.
Josef Bacik9802d862017-12-11 11:36:48 -05001010 */
1011 if (prog->kprobe_override &&
Masami Hiramatsub4da3342018-01-13 02:54:04 +09001012 (!trace_kprobe_on_func_entry(event->tp_event) ||
Josef Bacik9802d862017-12-11 11:36:48 -05001013 !trace_kprobe_error_injectable(event->tp_event)))
1014 return -EINVAL;
1015
Yonghong Songe87c6bc2017-10-23 23:53:08 -07001016 mutex_lock(&bpf_event_mutex);
1017
1018 if (event->prog)
Yonghong Song07c41a22017-10-30 13:50:22 -07001019 goto unlock;
Yonghong Songe87c6bc2017-10-23 23:53:08 -07001020
Yonghong Song07c41a22017-10-30 13:50:22 -07001021 old_array = event->tp_event->prog_array;
Yonghong Songc8c088b2017-11-30 13:47:54 -08001022 if (old_array &&
1023 bpf_prog_array_length(old_array) >= BPF_TRACE_MAX_PROGS) {
1024 ret = -E2BIG;
1025 goto unlock;
1026 }
1027
Yonghong Songe87c6bc2017-10-23 23:53:08 -07001028 ret = bpf_prog_array_copy(old_array, NULL, prog, &new_array);
1029 if (ret < 0)
Yonghong Song07c41a22017-10-30 13:50:22 -07001030 goto unlock;
Yonghong Songe87c6bc2017-10-23 23:53:08 -07001031
1032 /* set the new array to event->tp_event and set event->prog */
1033 event->prog = prog;
1034 rcu_assign_pointer(event->tp_event->prog_array, new_array);
1035 bpf_prog_array_free(old_array);
1036
Yonghong Song07c41a22017-10-30 13:50:22 -07001037unlock:
Yonghong Songe87c6bc2017-10-23 23:53:08 -07001038 mutex_unlock(&bpf_event_mutex);
1039 return ret;
1040}
1041
1042void perf_event_detach_bpf_prog(struct perf_event *event)
1043{
1044 struct bpf_prog_array __rcu *old_array;
1045 struct bpf_prog_array *new_array;
1046 int ret;
1047
1048 mutex_lock(&bpf_event_mutex);
1049
1050 if (!event->prog)
Yonghong Song07c41a22017-10-30 13:50:22 -07001051 goto unlock;
Yonghong Songe87c6bc2017-10-23 23:53:08 -07001052
Yonghong Song07c41a22017-10-30 13:50:22 -07001053 old_array = event->tp_event->prog_array;
Yonghong Songe87c6bc2017-10-23 23:53:08 -07001054 ret = bpf_prog_array_copy(old_array, event->prog, NULL, &new_array);
Sean Young170a7e32018-05-27 12:24:08 +01001055 if (ret == -ENOENT)
1056 goto unlock;
Yonghong Songe87c6bc2017-10-23 23:53:08 -07001057 if (ret < 0) {
1058 bpf_prog_array_delete_safe(old_array, event->prog);
1059 } else {
1060 rcu_assign_pointer(event->tp_event->prog_array, new_array);
1061 bpf_prog_array_free(old_array);
1062 }
1063
1064 bpf_prog_put(event->prog);
1065 event->prog = NULL;
1066
Yonghong Song07c41a22017-10-30 13:50:22 -07001067unlock:
Yonghong Songe87c6bc2017-10-23 23:53:08 -07001068 mutex_unlock(&bpf_event_mutex);
1069}
Yonghong Songf371b302017-12-11 11:39:02 -08001070
Yonghong Songf4e22982017-12-13 10:35:37 -08001071int perf_event_query_prog_array(struct perf_event *event, void __user *info)
Yonghong Songf371b302017-12-11 11:39:02 -08001072{
1073 struct perf_event_query_bpf __user *uquery = info;
1074 struct perf_event_query_bpf query = {};
Yonghong Song3a38bb92018-04-10 09:37:32 -07001075 u32 *ids, prog_cnt, ids_len;
Yonghong Songf371b302017-12-11 11:39:02 -08001076 int ret;
1077
1078 if (!capable(CAP_SYS_ADMIN))
1079 return -EPERM;
1080 if (event->attr.type != PERF_TYPE_TRACEPOINT)
1081 return -EINVAL;
1082 if (copy_from_user(&query, uquery, sizeof(query)))
1083 return -EFAULT;
Yonghong Song3a38bb92018-04-10 09:37:32 -07001084
1085 ids_len = query.ids_len;
1086 if (ids_len > BPF_TRACE_MAX_PROGS)
Daniel Borkmann9c481b92018-02-14 15:31:00 +01001087 return -E2BIG;
Yonghong Song3a38bb92018-04-10 09:37:32 -07001088 ids = kcalloc(ids_len, sizeof(u32), GFP_USER | __GFP_NOWARN);
1089 if (!ids)
1090 return -ENOMEM;
1091 /*
1092 * The above kcalloc returns ZERO_SIZE_PTR when ids_len = 0, which
1093 * is required when user only wants to check for uquery->prog_cnt.
1094 * There is no need to check for it since the case is handled
1095 * gracefully in bpf_prog_array_copy_info.
1096 */
Yonghong Songf371b302017-12-11 11:39:02 -08001097
1098 mutex_lock(&bpf_event_mutex);
1099 ret = bpf_prog_array_copy_info(event->tp_event->prog_array,
Yonghong Song3a38bb92018-04-10 09:37:32 -07001100 ids,
1101 ids_len,
1102 &prog_cnt);
Yonghong Songf371b302017-12-11 11:39:02 -08001103 mutex_unlock(&bpf_event_mutex);
1104
Yonghong Song3a38bb92018-04-10 09:37:32 -07001105 if (copy_to_user(&uquery->prog_cnt, &prog_cnt, sizeof(prog_cnt)) ||
1106 copy_to_user(uquery->ids, ids, ids_len * sizeof(u32)))
1107 ret = -EFAULT;
1108
1109 kfree(ids);
Yonghong Songf371b302017-12-11 11:39:02 -08001110 return ret;
1111}
Alexei Starovoitovc4f66992018-03-28 12:05:37 -07001112
1113extern struct bpf_raw_event_map __start__bpf_raw_tp[];
1114extern struct bpf_raw_event_map __stop__bpf_raw_tp[];
1115
Matt Mullinsa38d1102018-12-12 16:42:37 -08001116struct bpf_raw_event_map *bpf_get_raw_tracepoint(const char *name)
Alexei Starovoitovc4f66992018-03-28 12:05:37 -07001117{
1118 struct bpf_raw_event_map *btp = __start__bpf_raw_tp;
1119
1120 for (; btp < __stop__bpf_raw_tp; btp++) {
1121 if (!strcmp(btp->tp->name, name))
1122 return btp;
1123 }
Matt Mullinsa38d1102018-12-12 16:42:37 -08001124
1125 return bpf_get_raw_tracepoint_module(name);
1126}
1127
1128void bpf_put_raw_tracepoint(struct bpf_raw_event_map *btp)
1129{
1130 struct module *mod = __module_address((unsigned long)btp);
1131
1132 if (mod)
1133 module_put(mod);
Alexei Starovoitovc4f66992018-03-28 12:05:37 -07001134}
1135
1136static __always_inline
1137void __bpf_trace_run(struct bpf_prog *prog, u64 *args)
1138{
1139 rcu_read_lock();
1140 preempt_disable();
1141 (void) BPF_PROG_RUN(prog, args);
1142 preempt_enable();
1143 rcu_read_unlock();
1144}
1145
1146#define UNPACK(...) __VA_ARGS__
1147#define REPEAT_1(FN, DL, X, ...) FN(X)
1148#define REPEAT_2(FN, DL, X, ...) FN(X) UNPACK DL REPEAT_1(FN, DL, __VA_ARGS__)
1149#define REPEAT_3(FN, DL, X, ...) FN(X) UNPACK DL REPEAT_2(FN, DL, __VA_ARGS__)
1150#define REPEAT_4(FN, DL, X, ...) FN(X) UNPACK DL REPEAT_3(FN, DL, __VA_ARGS__)
1151#define REPEAT_5(FN, DL, X, ...) FN(X) UNPACK DL REPEAT_4(FN, DL, __VA_ARGS__)
1152#define REPEAT_6(FN, DL, X, ...) FN(X) UNPACK DL REPEAT_5(FN, DL, __VA_ARGS__)
1153#define REPEAT_7(FN, DL, X, ...) FN(X) UNPACK DL REPEAT_6(FN, DL, __VA_ARGS__)
1154#define REPEAT_8(FN, DL, X, ...) FN(X) UNPACK DL REPEAT_7(FN, DL, __VA_ARGS__)
1155#define REPEAT_9(FN, DL, X, ...) FN(X) UNPACK DL REPEAT_8(FN, DL, __VA_ARGS__)
1156#define REPEAT_10(FN, DL, X, ...) FN(X) UNPACK DL REPEAT_9(FN, DL, __VA_ARGS__)
1157#define REPEAT_11(FN, DL, X, ...) FN(X) UNPACK DL REPEAT_10(FN, DL, __VA_ARGS__)
1158#define REPEAT_12(FN, DL, X, ...) FN(X) UNPACK DL REPEAT_11(FN, DL, __VA_ARGS__)
1159#define REPEAT(X, FN, DL, ...) REPEAT_##X(FN, DL, __VA_ARGS__)
1160
1161#define SARG(X) u64 arg##X
1162#define COPY(X) args[X] = arg##X
1163
1164#define __DL_COM (,)
1165#define __DL_SEM (;)
1166
1167#define __SEQ_0_11 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
1168
1169#define BPF_TRACE_DEFN_x(x) \
1170 void bpf_trace_run##x(struct bpf_prog *prog, \
1171 REPEAT(x, SARG, __DL_COM, __SEQ_0_11)) \
1172 { \
1173 u64 args[x]; \
1174 REPEAT(x, COPY, __DL_SEM, __SEQ_0_11); \
1175 __bpf_trace_run(prog, args); \
1176 } \
1177 EXPORT_SYMBOL_GPL(bpf_trace_run##x)
1178BPF_TRACE_DEFN_x(1);
1179BPF_TRACE_DEFN_x(2);
1180BPF_TRACE_DEFN_x(3);
1181BPF_TRACE_DEFN_x(4);
1182BPF_TRACE_DEFN_x(5);
1183BPF_TRACE_DEFN_x(6);
1184BPF_TRACE_DEFN_x(7);
1185BPF_TRACE_DEFN_x(8);
1186BPF_TRACE_DEFN_x(9);
1187BPF_TRACE_DEFN_x(10);
1188BPF_TRACE_DEFN_x(11);
1189BPF_TRACE_DEFN_x(12);
1190
1191static int __bpf_probe_register(struct bpf_raw_event_map *btp, struct bpf_prog *prog)
1192{
1193 struct tracepoint *tp = btp->tp;
1194
1195 /*
1196 * check that program doesn't access arguments beyond what's
1197 * available in this tracepoint
1198 */
1199 if (prog->aux->max_ctx_offset > btp->num_args * sizeof(u64))
1200 return -EINVAL;
1201
1202 return tracepoint_probe_register(tp, (void *)btp->bpf_func, prog);
1203}
1204
1205int bpf_probe_register(struct bpf_raw_event_map *btp, struct bpf_prog *prog)
1206{
1207 int err;
1208
1209 mutex_lock(&bpf_event_mutex);
1210 err = __bpf_probe_register(btp, prog);
1211 mutex_unlock(&bpf_event_mutex);
1212 return err;
1213}
1214
1215int bpf_probe_unregister(struct bpf_raw_event_map *btp, struct bpf_prog *prog)
1216{
1217 int err;
1218
1219 mutex_lock(&bpf_event_mutex);
1220 err = tracepoint_probe_unregister(btp->tp, (void *)btp->bpf_func, prog);
1221 mutex_unlock(&bpf_event_mutex);
1222 return err;
1223}
Yonghong Song41bdc4b2018-05-24 11:21:09 -07001224
1225int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,
1226 u32 *fd_type, const char **buf,
1227 u64 *probe_offset, u64 *probe_addr)
1228{
1229 bool is_tracepoint, is_syscall_tp;
1230 struct bpf_prog *prog;
1231 int flags, err = 0;
1232
1233 prog = event->prog;
1234 if (!prog)
1235 return -ENOENT;
1236
1237 /* not supporting BPF_PROG_TYPE_PERF_EVENT yet */
1238 if (prog->type == BPF_PROG_TYPE_PERF_EVENT)
1239 return -EOPNOTSUPP;
1240
1241 *prog_id = prog->aux->id;
1242 flags = event->tp_event->flags;
1243 is_tracepoint = flags & TRACE_EVENT_FL_TRACEPOINT;
1244 is_syscall_tp = is_syscall_trace_event(event->tp_event);
1245
1246 if (is_tracepoint || is_syscall_tp) {
1247 *buf = is_tracepoint ? event->tp_event->tp->name
1248 : event->tp_event->name;
1249 *fd_type = BPF_FD_TYPE_TRACEPOINT;
1250 *probe_offset = 0x0;
1251 *probe_addr = 0x0;
1252 } else {
1253 /* kprobe/uprobe */
1254 err = -EOPNOTSUPP;
1255#ifdef CONFIG_KPROBE_EVENTS
1256 if (flags & TRACE_EVENT_FL_KPROBE)
1257 err = bpf_get_kprobe_info(event, fd_type, buf,
1258 probe_offset, probe_addr,
1259 event->attr.type == PERF_TYPE_TRACEPOINT);
1260#endif
1261#ifdef CONFIG_UPROBE_EVENTS
1262 if (flags & TRACE_EVENT_FL_UPROBE)
1263 err = bpf_get_uprobe_info(event, fd_type, buf,
1264 probe_offset,
1265 event->attr.type == PERF_TYPE_TRACEPOINT);
1266#endif
1267 }
1268
1269 return err;
1270}
Matt Mullinsa38d1102018-12-12 16:42:37 -08001271
1272#ifdef CONFIG_MODULES
1273int bpf_event_notify(struct notifier_block *nb, unsigned long op, void *module)
1274{
1275 struct bpf_trace_module *btm, *tmp;
1276 struct module *mod = module;
1277
1278 if (mod->num_bpf_raw_events == 0 ||
1279 (op != MODULE_STATE_COMING && op != MODULE_STATE_GOING))
1280 return 0;
1281
1282 mutex_lock(&bpf_module_mutex);
1283
1284 switch (op) {
1285 case MODULE_STATE_COMING:
1286 btm = kzalloc(sizeof(*btm), GFP_KERNEL);
1287 if (btm) {
1288 btm->module = module;
1289 list_add(&btm->list, &bpf_trace_modules);
1290 }
1291 break;
1292 case MODULE_STATE_GOING:
1293 list_for_each_entry_safe(btm, tmp, &bpf_trace_modules, list) {
1294 if (btm->module == module) {
1295 list_del(&btm->list);
1296 kfree(btm);
1297 break;
1298 }
1299 }
1300 break;
1301 }
1302
1303 mutex_unlock(&bpf_module_mutex);
1304
1305 return 0;
1306}
1307
1308static struct notifier_block bpf_module_nb = {
1309 .notifier_call = bpf_event_notify,
1310};
1311
1312int __init bpf_event_init(void)
1313{
1314 register_module_notifier(&bpf_module_nb);
1315 return 0;
1316}
1317
1318fs_initcall(bpf_event_init);
1319#endif /* CONFIG_MODULES */