Files
erofs-linux/include/uapi/linux
Alexei Starovoitov 2541517c32 tracing, perf: Implement BPF programs attached to kprobes
BPF programs, attached to kprobes, provide a safe way to execute
user-defined BPF byte-code programs without being able to crash or
hang the kernel in any way. The BPF engine makes sure that such
programs have a finite execution time and that they cannot break
out of their sandbox.

The user interface is to attach to a kprobe via the perf syscall:

	struct perf_event_attr attr = {
		.type	= PERF_TYPE_TRACEPOINT,
		.config	= event_id,
		...
	};

	event_fd = perf_event_open(&attr,...);
	ioctl(event_fd, PERF_EVENT_IOC_SET_BPF, prog_fd);

'prog_fd' is a file descriptor associated with BPF program
previously loaded.

'event_id' is an ID of the kprobe created.

Closing 'event_fd':

	close(event_fd);

... automatically detaches BPF program from it.

BPF programs can call in-kernel helper functions to:

  - lookup/update/delete elements in maps

  - probe_read - wraper of probe_kernel_read() used to access any
    kernel data structures

BPF programs receive 'struct pt_regs *' as an input ('struct pt_regs' is
architecture dependent) and return 0 to ignore the event and 1 to store
kprobe event into the ring buffer.

Note, kprobes are a fundamentally _not_ a stable kernel ABI,
so BPF programs attached to kprobes must be recompiled for
every kernel version and user must supply correct LINUX_VERSION_CODE
in attr.kern_version during bpf_prog_load() call.

Signed-off-by: Alexei Starovoitov <[email protected]>
Reviewed-by: Steven Rostedt <[email protected]>
Reviewed-by: Masami Hiramatsu <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Daniel Borkmann <[email protected]>
Cc: David S. Miller <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
2015-04-02 13:25:49 +02:00
..
…
…
…
…
…
…
…
2015-02-02 18:09:42 +01:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2014-11-19 14:48:02 -06:00
…
…
2014-12-08 12:55:57 +08:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2014-12-16 11:19:42 -05:00
…
…
…
…
2014-12-22 16:12:36 -05:00
2015-01-05 22:44:46 -05:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2014-12-02 13:52:53 -07:00
…
…
…
2015-02-17 14:34:51 -08:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2015-01-20 13:51:06 +01:00
2014-12-13 12:42:52 -08:00
…
…
…
…
…
…
2015-02-02 18:46:51 -08:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2015-01-21 19:21:30 +01:00
…
…
…
…
…
…
…
…
…
…
…
…
…
2015-02-07 18:43:16 +08:00
…
…
…
…
…
…
…
…
…
…
…
…
…
2014-12-10 17:41:10 -08:00
…
…
…
2014-12-09 14:10:41 +08:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2015-02-10 12:38:14 -07:00
…
2014-12-09 12:05:24 +02:00
…
…
…
…
…
…
…
…