Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

toops: Sync tools/include/uapi/linux/bpf.h with the kernel

The way we're using kernel headers in tools/ now, with a copy that is
made to the same path prefixed by "tools/" plus checking if that copy
got stale, i.e. if the kernel counterpart changed, helps in keeping
track with new features that may be useful for tools to exploit.

For instance, looking at all the changes to bpf.h since it was last
copied to tools/include brings this to toolers' attention:

Need to investigate this one to check how to run a program via perf, setting up
a BPF event, that will take advantage of the way perf already calls clang/LLVM,
sets up the event and runs the workload in a single command line, helping in
debugging such semi cooperative programs:

96ae52279594 ("bpf: Add bpf_probe_write_user BPF helper to be called in tracers")

This one needs further investigation about using the feature it improves
in 'perf trace' to do some tcpdumpin' mixed with syscalls, tracepoints,
probe points, callgraphs, etc:

555c8a8623a3 ("bpf: avoid stack copy and use skb ctx for event output")

Add tracing just packets that are related to some container to that mix:

4a482f34afcc ("cgroup: bpf: Add bpf_skb_in_cgroup_proto")
4ed8ec521ed5 ("cgroup: bpf: Add BPF_MAP_TYPE_CGROUP_ARRAY")

Definetely needs to have example programs accessing task_struct from a bpf proggie
started from 'perf trace':

606274c5abd8 ("bpf: introduce bpf_get_current_task() helper")

Core networking related, XDP:

6ce96ca348a9 ("bpf: add XDP_TX xdp_action for direct forwarding")
6a773a15a1e8 ("bpf: add XDP prog type for early driver filter")
13c5c240f789 ("bpf: add bpf_get_hash_recalc helper")
d2485c4242a8 ("bpf: add bpf_skb_change_type helper")
6578171a7ff0 ("bpf: add bpf_skb_change_proto helper")

Changes detected by the tools build system:

$ make -C tools/perf O=/tmp/build/perf install-bin
make: Entering directory '/home/acme/git/linux/tools/perf'
BUILD: Doing 'make -j4' parallel build
Warning: tools/include/uapi/linux/bpf.h differs from kernel
INSTALL GTK UI
CC /tmp/build/perf/bench/mem-memcpy-x86-64-asm.o
<SNIP>
$

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Brenden Blanco <bblanco@plumgrid.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Sargun Dhillon <sargun@sargun.me>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-difq4ts1xvww6eyfs9e7zlft@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+85 -1
+85 -1
tools/include/uapi/linux/bpf.h
··· 84 84 BPF_MAP_TYPE_PERCPU_HASH, 85 85 BPF_MAP_TYPE_PERCPU_ARRAY, 86 86 BPF_MAP_TYPE_STACK_TRACE, 87 + BPF_MAP_TYPE_CGROUP_ARRAY, 87 88 }; 88 89 89 90 enum bpf_prog_type { ··· 94 93 BPF_PROG_TYPE_SCHED_CLS, 95 94 BPF_PROG_TYPE_SCHED_ACT, 96 95 BPF_PROG_TYPE_TRACEPOINT, 96 + BPF_PROG_TYPE_XDP, 97 97 }; 98 98 99 99 #define BPF_PSEUDO_MAP_FD 1 ··· 315 313 */ 316 314 BPF_FUNC_skb_get_tunnel_opt, 317 315 BPF_FUNC_skb_set_tunnel_opt, 316 + 317 + /** 318 + * bpf_skb_change_proto(skb, proto, flags) 319 + * Change protocol of the skb. Currently supported is 320 + * v4 -> v6, v6 -> v4 transitions. The helper will also 321 + * resize the skb. eBPF program is expected to fill the 322 + * new headers via skb_store_bytes and lX_csum_replace. 323 + * @skb: pointer to skb 324 + * @proto: new skb->protocol type 325 + * @flags: reserved 326 + * Return: 0 on success or negative error 327 + */ 328 + BPF_FUNC_skb_change_proto, 329 + 330 + /** 331 + * bpf_skb_change_type(skb, type) 332 + * Change packet type of skb. 333 + * @skb: pointer to skb 334 + * @type: new skb->pkt_type type 335 + * Return: 0 on success or negative error 336 + */ 337 + BPF_FUNC_skb_change_type, 338 + 339 + /** 340 + * bpf_skb_in_cgroup(skb, map, index) - Check cgroup2 membership of skb 341 + * @skb: pointer to skb 342 + * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type 343 + * @index: index of the cgroup in the bpf_map 344 + * Return: 345 + * == 0 skb failed the cgroup2 descendant test 346 + * == 1 skb succeeded the cgroup2 descendant test 347 + * < 0 error 348 + */ 349 + BPF_FUNC_skb_in_cgroup, 350 + 351 + /** 352 + * bpf_get_hash_recalc(skb) 353 + * Retrieve and possibly recalculate skb->hash. 354 + * @skb: pointer to skb 355 + * Return: hash 356 + */ 357 + BPF_FUNC_get_hash_recalc, 358 + 359 + /** 360 + * u64 bpf_get_current_task(void) 361 + * Returns current task_struct 362 + * Return: current 363 + */ 364 + BPF_FUNC_get_current_task, 365 + 366 + /** 367 + * bpf_probe_write_user(void *dst, void *src, int len) 368 + * safely attempt to write to a location 369 + * @dst: destination address in userspace 370 + * @src: source address on stack 371 + * @len: number of bytes to copy 372 + * Return: 0 on success or negative error 373 + */ 374 + BPF_FUNC_probe_write_user, 375 + 318 376 __BPF_FUNC_MAX_ID, 319 377 }; 320 378 ··· 409 347 #define BPF_F_ZERO_CSUM_TX (1ULL << 1) 410 348 #define BPF_F_DONT_FRAGMENT (1ULL << 2) 411 349 412 - /* BPF_FUNC_perf_event_output flags. */ 350 + /* BPF_FUNC_perf_event_output and BPF_FUNC_perf_event_read flags. */ 413 351 #define BPF_F_INDEX_MASK 0xffffffffULL 414 352 #define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK 353 + /* BPF_FUNC_perf_event_output for sk_buff input context. */ 354 + #define BPF_F_CTXLEN_MASK (0xfffffULL << 32) 415 355 416 356 /* user accessible mirror of in-kernel sk_buff. 417 357 * new fields can only be added to the end of this structure ··· 448 384 __u8 tunnel_ttl; 449 385 __u16 tunnel_ext; 450 386 __u32 tunnel_label; 387 + }; 388 + 389 + /* User return codes for XDP prog type. 390 + * A valid XDP program must return one of these defined values. All other 391 + * return codes are reserved for future use. Unknown return codes will result 392 + * in packet drop. 393 + */ 394 + enum xdp_action { 395 + XDP_ABORTED = 0, 396 + XDP_DROP, 397 + XDP_PASS, 398 + XDP_TX, 399 + }; 400 + 401 + /* user accessible metadata for XDP packet hook 402 + * new fields must be added to the end of this structure 403 + */ 404 + struct xdp_md { 405 + __u32 data; 406 + __u32 data_end; 451 407 }; 452 408 453 409 #endif /* _UAPI__LINUX_BPF_H__ */