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

Merge tag 'for-netdev' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next

Daniel Borkmann says:

====================
pull-request: bpf-next 2022-10-18

We've added 33 non-merge commits during the last 14 day(s) which contain
a total of 31 files changed, 874 insertions(+), 538 deletions(-).

The main changes are:

1) Add RCU grace period chaining to BPF to wait for the completion
of access from both sleepable and non-sleepable BPF programs,
from Hou Tao & Paul E. McKenney.

2) Improve helper UAPI by explicitly defining BPF_FUNC_xxx integer
values. In the wild we have seen OS vendors doing buggy backports
where helper call numbers mismatched. This is an attempt to make
backports more foolproof, from Andrii Nakryiko.

3) Add libbpf *_opts API-variants for bpf_*_get_fd_by_id() functions,
from Roberto Sassu.

4) Fix libbpf's BTF dumper for structs with padding-only fields,
from Eduard Zingerman.

5) Fix various libbpf bugs which have been found from fuzzing with
malformed BPF object files, from Shung-Hsi Yu.

6) Clean up an unneeded check on existence of SSE2 in BPF x86-64 JIT,
from Jie Meng.

7) Fix various ASAN bugs in both libbpf and selftests when running
the BPF selftest suite on arm64, from Xu Kuohai.

8) Fix missing bpf_iter_vma_offset__destroy() call in BPF iter selftest
and use in-skeleton link pointer to remove an explicit bpf_link__destroy(),
from Jiri Olsa.

9) Fix BPF CI breakage by pointing to iptables-legacy instead of relying
on symlinked iptables which got upgraded to iptables-nft,
from Martin KaFai Lau.

10) Minor BPF selftest improvements all over the place, from various others.

* tag 'for-netdev' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (33 commits)
bpf/docs: Update README for most recent vmtest.sh
bpf: Use rcu_trace_implies_rcu_gp() for program array freeing
bpf: Use rcu_trace_implies_rcu_gp() in local storage map
bpf: Use rcu_trace_implies_rcu_gp() in bpf memory allocator
rcu-tasks: Provide rcu_trace_implies_rcu_gp()
selftests/bpf: Use sys_pidfd_open() helper when possible
libbpf: Fix null-pointer dereference in find_prog_by_sec_insn()
libbpf: Deal with section with no data gracefully
libbpf: Use elf_getshdrnum() instead of e_shnum
selftest/bpf: Fix error usage of ASSERT_OK in xdp_adjust_tail.c
selftests/bpf: Fix error failure of case test_xdp_adjust_tail_grow
selftest/bpf: Fix memory leak in kprobe_multi_test
selftests/bpf: Fix memory leak caused by not destroying skeleton
libbpf: Fix memory leak in parse_usdt_arg()
libbpf: Fix use-after-free in btf_dump_name_dups
selftests/bpf: S/iptables/iptables-legacy/ in the bpf_nf and xdp_synproxy test
selftests/bpf: Alphabetize DENYLISTs
selftests/bpf: Add tests for _opts variants of bpf_*_get_fd_by_id()
libbpf: Introduce bpf_link_get_fd_by_id_opts()
libbpf: Introduce bpf_btf_get_fd_by_id_opts()
...
====================

Link: https://lore.kernel.org/r/20221018210631.11211-1-daniel@iogearbox.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+874 -538
+1 -2
arch/x86/net/bpf_jit_comp.c
··· 1226 1226 1227 1227 /* speculation barrier */ 1228 1228 case BPF_ST | BPF_NOSPEC: 1229 - if (boot_cpu_has(X86_FEATURE_XMM2)) 1230 - EMIT_LFENCE(); 1229 + EMIT_LFENCE(); 1231 1230 break; 1232 1231 1233 1232 /* ST: *(u8*)(dst_reg + off) = imm */
+12
include/linux/rcupdate.h
··· 241 241 #endif /* #else #ifdef CONFIG_TASKS_RCU_GENERIC */ 242 242 243 243 /** 244 + * rcu_trace_implies_rcu_gp - does an RCU Tasks Trace grace period imply an RCU grace period? 245 + * 246 + * As an accident of implementation, an RCU Tasks Trace grace period also 247 + * acts as an RCU grace period. However, this could change at any time. 248 + * Code relying on this accident must call this function to verify that 249 + * this accident is still happening. 250 + * 251 + * You have been warned! 252 + */ 253 + static inline bool rcu_trace_implies_rcu_gp(void) { return true; } 254 + 255 + /** 244 256 * cond_resched_tasks_rcu_qs - Report potential quiescent states to RCU 245 257 * 246 258 * This macro resembles cond_resched(), except that it is defined to
+219 -213
include/uapi/linux/bpf.h
··· 5436 5436 * larger than the size of the ring buffer, or which cannot fit 5437 5437 * within a struct bpf_dynptr. 5438 5438 */ 5439 - #define __BPF_FUNC_MAPPER(FN) \ 5440 - FN(unspec), \ 5441 - FN(map_lookup_elem), \ 5442 - FN(map_update_elem), \ 5443 - FN(map_delete_elem), \ 5444 - FN(probe_read), \ 5445 - FN(ktime_get_ns), \ 5446 - FN(trace_printk), \ 5447 - FN(get_prandom_u32), \ 5448 - FN(get_smp_processor_id), \ 5449 - FN(skb_store_bytes), \ 5450 - FN(l3_csum_replace), \ 5451 - FN(l4_csum_replace), \ 5452 - FN(tail_call), \ 5453 - FN(clone_redirect), \ 5454 - FN(get_current_pid_tgid), \ 5455 - FN(get_current_uid_gid), \ 5456 - FN(get_current_comm), \ 5457 - FN(get_cgroup_classid), \ 5458 - FN(skb_vlan_push), \ 5459 - FN(skb_vlan_pop), \ 5460 - FN(skb_get_tunnel_key), \ 5461 - FN(skb_set_tunnel_key), \ 5462 - FN(perf_event_read), \ 5463 - FN(redirect), \ 5464 - FN(get_route_realm), \ 5465 - FN(perf_event_output), \ 5466 - FN(skb_load_bytes), \ 5467 - FN(get_stackid), \ 5468 - FN(csum_diff), \ 5469 - FN(skb_get_tunnel_opt), \ 5470 - FN(skb_set_tunnel_opt), \ 5471 - FN(skb_change_proto), \ 5472 - FN(skb_change_type), \ 5473 - FN(skb_under_cgroup), \ 5474 - FN(get_hash_recalc), \ 5475 - FN(get_current_task), \ 5476 - FN(probe_write_user), \ 5477 - FN(current_task_under_cgroup), \ 5478 - FN(skb_change_tail), \ 5479 - FN(skb_pull_data), \ 5480 - FN(csum_update), \ 5481 - FN(set_hash_invalid), \ 5482 - FN(get_numa_node_id), \ 5483 - FN(skb_change_head), \ 5484 - FN(xdp_adjust_head), \ 5485 - FN(probe_read_str), \ 5486 - FN(get_socket_cookie), \ 5487 - FN(get_socket_uid), \ 5488 - FN(set_hash), \ 5489 - FN(setsockopt), \ 5490 - FN(skb_adjust_room), \ 5491 - FN(redirect_map), \ 5492 - FN(sk_redirect_map), \ 5493 - FN(sock_map_update), \ 5494 - FN(xdp_adjust_meta), \ 5495 - FN(perf_event_read_value), \ 5496 - FN(perf_prog_read_value), \ 5497 - FN(getsockopt), \ 5498 - FN(override_return), \ 5499 - FN(sock_ops_cb_flags_set), \ 5500 - FN(msg_redirect_map), \ 5501 - FN(msg_apply_bytes), \ 5502 - FN(msg_cork_bytes), \ 5503 - FN(msg_pull_data), \ 5504 - FN(bind), \ 5505 - FN(xdp_adjust_tail), \ 5506 - FN(skb_get_xfrm_state), \ 5507 - FN(get_stack), \ 5508 - FN(skb_load_bytes_relative), \ 5509 - FN(fib_lookup), \ 5510 - FN(sock_hash_update), \ 5511 - FN(msg_redirect_hash), \ 5512 - FN(sk_redirect_hash), \ 5513 - FN(lwt_push_encap), \ 5514 - FN(lwt_seg6_store_bytes), \ 5515 - FN(lwt_seg6_adjust_srh), \ 5516 - FN(lwt_seg6_action), \ 5517 - FN(rc_repeat), \ 5518 - FN(rc_keydown), \ 5519 - FN(skb_cgroup_id), \ 5520 - FN(get_current_cgroup_id), \ 5521 - FN(get_local_storage), \ 5522 - FN(sk_select_reuseport), \ 5523 - FN(skb_ancestor_cgroup_id), \ 5524 - FN(sk_lookup_tcp), \ 5525 - FN(sk_lookup_udp), \ 5526 - FN(sk_release), \ 5527 - FN(map_push_elem), \ 5528 - FN(map_pop_elem), \ 5529 - FN(map_peek_elem), \ 5530 - FN(msg_push_data), \ 5531 - FN(msg_pop_data), \ 5532 - FN(rc_pointer_rel), \ 5533 - FN(spin_lock), \ 5534 - FN(spin_unlock), \ 5535 - FN(sk_fullsock), \ 5536 - FN(tcp_sock), \ 5537 - FN(skb_ecn_set_ce), \ 5538 - FN(get_listener_sock), \ 5539 - FN(skc_lookup_tcp), \ 5540 - FN(tcp_check_syncookie), \ 5541 - FN(sysctl_get_name), \ 5542 - FN(sysctl_get_current_value), \ 5543 - FN(sysctl_get_new_value), \ 5544 - FN(sysctl_set_new_value), \ 5545 - FN(strtol), \ 5546 - FN(strtoul), \ 5547 - FN(sk_storage_get), \ 5548 - FN(sk_storage_delete), \ 5549 - FN(send_signal), \ 5550 - FN(tcp_gen_syncookie), \ 5551 - FN(skb_output), \ 5552 - FN(probe_read_user), \ 5553 - FN(probe_read_kernel), \ 5554 - FN(probe_read_user_str), \ 5555 - FN(probe_read_kernel_str), \ 5556 - FN(tcp_send_ack), \ 5557 - FN(send_signal_thread), \ 5558 - FN(jiffies64), \ 5559 - FN(read_branch_records), \ 5560 - FN(get_ns_current_pid_tgid), \ 5561 - FN(xdp_output), \ 5562 - FN(get_netns_cookie), \ 5563 - FN(get_current_ancestor_cgroup_id), \ 5564 - FN(sk_assign), \ 5565 - FN(ktime_get_boot_ns), \ 5566 - FN(seq_printf), \ 5567 - FN(seq_write), \ 5568 - FN(sk_cgroup_id), \ 5569 - FN(sk_ancestor_cgroup_id), \ 5570 - FN(ringbuf_output), \ 5571 - FN(ringbuf_reserve), \ 5572 - FN(ringbuf_submit), \ 5573 - FN(ringbuf_discard), \ 5574 - FN(ringbuf_query), \ 5575 - FN(csum_level), \ 5576 - FN(skc_to_tcp6_sock), \ 5577 - FN(skc_to_tcp_sock), \ 5578 - FN(skc_to_tcp_timewait_sock), \ 5579 - FN(skc_to_tcp_request_sock), \ 5580 - FN(skc_to_udp6_sock), \ 5581 - FN(get_task_stack), \ 5582 - FN(load_hdr_opt), \ 5583 - FN(store_hdr_opt), \ 5584 - FN(reserve_hdr_opt), \ 5585 - FN(inode_storage_get), \ 5586 - FN(inode_storage_delete), \ 5587 - FN(d_path), \ 5588 - FN(copy_from_user), \ 5589 - FN(snprintf_btf), \ 5590 - FN(seq_printf_btf), \ 5591 - FN(skb_cgroup_classid), \ 5592 - FN(redirect_neigh), \ 5593 - FN(per_cpu_ptr), \ 5594 - FN(this_cpu_ptr), \ 5595 - FN(redirect_peer), \ 5596 - FN(task_storage_get), \ 5597 - FN(task_storage_delete), \ 5598 - FN(get_current_task_btf), \ 5599 - FN(bprm_opts_set), \ 5600 - FN(ktime_get_coarse_ns), \ 5601 - FN(ima_inode_hash), \ 5602 - FN(sock_from_file), \ 5603 - FN(check_mtu), \ 5604 - FN(for_each_map_elem), \ 5605 - FN(snprintf), \ 5606 - FN(sys_bpf), \ 5607 - FN(btf_find_by_name_kind), \ 5608 - FN(sys_close), \ 5609 - FN(timer_init), \ 5610 - FN(timer_set_callback), \ 5611 - FN(timer_start), \ 5612 - FN(timer_cancel), \ 5613 - FN(get_func_ip), \ 5614 - FN(get_attach_cookie), \ 5615 - FN(task_pt_regs), \ 5616 - FN(get_branch_snapshot), \ 5617 - FN(trace_vprintk), \ 5618 - FN(skc_to_unix_sock), \ 5619 - FN(kallsyms_lookup_name), \ 5620 - FN(find_vma), \ 5621 - FN(loop), \ 5622 - FN(strncmp), \ 5623 - FN(get_func_arg), \ 5624 - FN(get_func_ret), \ 5625 - FN(get_func_arg_cnt), \ 5626 - FN(get_retval), \ 5627 - FN(set_retval), \ 5628 - FN(xdp_get_buff_len), \ 5629 - FN(xdp_load_bytes), \ 5630 - FN(xdp_store_bytes), \ 5631 - FN(copy_from_user_task), \ 5632 - FN(skb_set_tstamp), \ 5633 - FN(ima_file_hash), \ 5634 - FN(kptr_xchg), \ 5635 - FN(map_lookup_percpu_elem), \ 5636 - FN(skc_to_mptcp_sock), \ 5637 - FN(dynptr_from_mem), \ 5638 - FN(ringbuf_reserve_dynptr), \ 5639 - FN(ringbuf_submit_dynptr), \ 5640 - FN(ringbuf_discard_dynptr), \ 5641 - FN(dynptr_read), \ 5642 - FN(dynptr_write), \ 5643 - FN(dynptr_data), \ 5644 - FN(tcp_raw_gen_syncookie_ipv4), \ 5645 - FN(tcp_raw_gen_syncookie_ipv6), \ 5646 - FN(tcp_raw_check_syncookie_ipv4), \ 5647 - FN(tcp_raw_check_syncookie_ipv6), \ 5648 - FN(ktime_get_tai_ns), \ 5649 - FN(user_ringbuf_drain), \ 5439 + #define ___BPF_FUNC_MAPPER(FN, ctx...) \ 5440 + FN(unspec, 0, ##ctx) \ 5441 + FN(map_lookup_elem, 1, ##ctx) \ 5442 + FN(map_update_elem, 2, ##ctx) \ 5443 + FN(map_delete_elem, 3, ##ctx) \ 5444 + FN(probe_read, 4, ##ctx) \ 5445 + FN(ktime_get_ns, 5, ##ctx) \ 5446 + FN(trace_printk, 6, ##ctx) \ 5447 + FN(get_prandom_u32, 7, ##ctx) \ 5448 + FN(get_smp_processor_id, 8, ##ctx) \ 5449 + FN(skb_store_bytes, 9, ##ctx) \ 5450 + FN(l3_csum_replace, 10, ##ctx) \ 5451 + FN(l4_csum_replace, 11, ##ctx) \ 5452 + FN(tail_call, 12, ##ctx) \ 5453 + FN(clone_redirect, 13, ##ctx) \ 5454 + FN(get_current_pid_tgid, 14, ##ctx) \ 5455 + FN(get_current_uid_gid, 15, ##ctx) \ 5456 + FN(get_current_comm, 16, ##ctx) \ 5457 + FN(get_cgroup_classid, 17, ##ctx) \ 5458 + FN(skb_vlan_push, 18, ##ctx) \ 5459 + FN(skb_vlan_pop, 19, ##ctx) \ 5460 + FN(skb_get_tunnel_key, 20, ##ctx) \ 5461 + FN(skb_set_tunnel_key, 21, ##ctx) \ 5462 + FN(perf_event_read, 22, ##ctx) \ 5463 + FN(redirect, 23, ##ctx) \ 5464 + FN(get_route_realm, 24, ##ctx) \ 5465 + FN(perf_event_output, 25, ##ctx) \ 5466 + FN(skb_load_bytes, 26, ##ctx) \ 5467 + FN(get_stackid, 27, ##ctx) \ 5468 + FN(csum_diff, 28, ##ctx) \ 5469 + FN(skb_get_tunnel_opt, 29, ##ctx) \ 5470 + FN(skb_set_tunnel_opt, 30, ##ctx) \ 5471 + FN(skb_change_proto, 31, ##ctx) \ 5472 + FN(skb_change_type, 32, ##ctx) \ 5473 + FN(skb_under_cgroup, 33, ##ctx) \ 5474 + FN(get_hash_recalc, 34, ##ctx) \ 5475 + FN(get_current_task, 35, ##ctx) \ 5476 + FN(probe_write_user, 36, ##ctx) \ 5477 + FN(current_task_under_cgroup, 37, ##ctx) \ 5478 + FN(skb_change_tail, 38, ##ctx) \ 5479 + FN(skb_pull_data, 39, ##ctx) \ 5480 + FN(csum_update, 40, ##ctx) \ 5481 + FN(set_hash_invalid, 41, ##ctx) \ 5482 + FN(get_numa_node_id, 42, ##ctx) \ 5483 + FN(skb_change_head, 43, ##ctx) \ 5484 + FN(xdp_adjust_head, 44, ##ctx) \ 5485 + FN(probe_read_str, 45, ##ctx) \ 5486 + FN(get_socket_cookie, 46, ##ctx) \ 5487 + FN(get_socket_uid, 47, ##ctx) \ 5488 + FN(set_hash, 48, ##ctx) \ 5489 + FN(setsockopt, 49, ##ctx) \ 5490 + FN(skb_adjust_room, 50, ##ctx) \ 5491 + FN(redirect_map, 51, ##ctx) \ 5492 + FN(sk_redirect_map, 52, ##ctx) \ 5493 + FN(sock_map_update, 53, ##ctx) \ 5494 + FN(xdp_adjust_meta, 54, ##ctx) \ 5495 + FN(perf_event_read_value, 55, ##ctx) \ 5496 + FN(perf_prog_read_value, 56, ##ctx) \ 5497 + FN(getsockopt, 57, ##ctx) \ 5498 + FN(override_return, 58, ##ctx) \ 5499 + FN(sock_ops_cb_flags_set, 59, ##ctx) \ 5500 + FN(msg_redirect_map, 60, ##ctx) \ 5501 + FN(msg_apply_bytes, 61, ##ctx) \ 5502 + FN(msg_cork_bytes, 62, ##ctx) \ 5503 + FN(msg_pull_data, 63, ##ctx) \ 5504 + FN(bind, 64, ##ctx) \ 5505 + FN(xdp_adjust_tail, 65, ##ctx) \ 5506 + FN(skb_get_xfrm_state, 66, ##ctx) \ 5507 + FN(get_stack, 67, ##ctx) \ 5508 + FN(skb_load_bytes_relative, 68, ##ctx) \ 5509 + FN(fib_lookup, 69, ##ctx) \ 5510 + FN(sock_hash_update, 70, ##ctx) \ 5511 + FN(msg_redirect_hash, 71, ##ctx) \ 5512 + FN(sk_redirect_hash, 72, ##ctx) \ 5513 + FN(lwt_push_encap, 73, ##ctx) \ 5514 + FN(lwt_seg6_store_bytes, 74, ##ctx) \ 5515 + FN(lwt_seg6_adjust_srh, 75, ##ctx) \ 5516 + FN(lwt_seg6_action, 76, ##ctx) \ 5517 + FN(rc_repeat, 77, ##ctx) \ 5518 + FN(rc_keydown, 78, ##ctx) \ 5519 + FN(skb_cgroup_id, 79, ##ctx) \ 5520 + FN(get_current_cgroup_id, 80, ##ctx) \ 5521 + FN(get_local_storage, 81, ##ctx) \ 5522 + FN(sk_select_reuseport, 82, ##ctx) \ 5523 + FN(skb_ancestor_cgroup_id, 83, ##ctx) \ 5524 + FN(sk_lookup_tcp, 84, ##ctx) \ 5525 + FN(sk_lookup_udp, 85, ##ctx) \ 5526 + FN(sk_release, 86, ##ctx) \ 5527 + FN(map_push_elem, 87, ##ctx) \ 5528 + FN(map_pop_elem, 88, ##ctx) \ 5529 + FN(map_peek_elem, 89, ##ctx) \ 5530 + FN(msg_push_data, 90, ##ctx) \ 5531 + FN(msg_pop_data, 91, ##ctx) \ 5532 + FN(rc_pointer_rel, 92, ##ctx) \ 5533 + FN(spin_lock, 93, ##ctx) \ 5534 + FN(spin_unlock, 94, ##ctx) \ 5535 + FN(sk_fullsock, 95, ##ctx) \ 5536 + FN(tcp_sock, 96, ##ctx) \ 5537 + FN(skb_ecn_set_ce, 97, ##ctx) \ 5538 + FN(get_listener_sock, 98, ##ctx) \ 5539 + FN(skc_lookup_tcp, 99, ##ctx) \ 5540 + FN(tcp_check_syncookie, 100, ##ctx) \ 5541 + FN(sysctl_get_name, 101, ##ctx) \ 5542 + FN(sysctl_get_current_value, 102, ##ctx) \ 5543 + FN(sysctl_get_new_value, 103, ##ctx) \ 5544 + FN(sysctl_set_new_value, 104, ##ctx) \ 5545 + FN(strtol, 105, ##ctx) \ 5546 + FN(strtoul, 106, ##ctx) \ 5547 + FN(sk_storage_get, 107, ##ctx) \ 5548 + FN(sk_storage_delete, 108, ##ctx) \ 5549 + FN(send_signal, 109, ##ctx) \ 5550 + FN(tcp_gen_syncookie, 110, ##ctx) \ 5551 + FN(skb_output, 111, ##ctx) \ 5552 + FN(probe_read_user, 112, ##ctx) \ 5553 + FN(probe_read_kernel, 113, ##ctx) \ 5554 + FN(probe_read_user_str, 114, ##ctx) \ 5555 + FN(probe_read_kernel_str, 115, ##ctx) \ 5556 + FN(tcp_send_ack, 116, ##ctx) \ 5557 + FN(send_signal_thread, 117, ##ctx) \ 5558 + FN(jiffies64, 118, ##ctx) \ 5559 + FN(read_branch_records, 119, ##ctx) \ 5560 + FN(get_ns_current_pid_tgid, 120, ##ctx) \ 5561 + FN(xdp_output, 121, ##ctx) \ 5562 + FN(get_netns_cookie, 122, ##ctx) \ 5563 + FN(get_current_ancestor_cgroup_id, 123, ##ctx) \ 5564 + FN(sk_assign, 124, ##ctx) \ 5565 + FN(ktime_get_boot_ns, 125, ##ctx) \ 5566 + FN(seq_printf, 126, ##ctx) \ 5567 + FN(seq_write, 127, ##ctx) \ 5568 + FN(sk_cgroup_id, 128, ##ctx) \ 5569 + FN(sk_ancestor_cgroup_id, 129, ##ctx) \ 5570 + FN(ringbuf_output, 130, ##ctx) \ 5571 + FN(ringbuf_reserve, 131, ##ctx) \ 5572 + FN(ringbuf_submit, 132, ##ctx) \ 5573 + FN(ringbuf_discard, 133, ##ctx) \ 5574 + FN(ringbuf_query, 134, ##ctx) \ 5575 + FN(csum_level, 135, ##ctx) \ 5576 + FN(skc_to_tcp6_sock, 136, ##ctx) \ 5577 + FN(skc_to_tcp_sock, 137, ##ctx) \ 5578 + FN(skc_to_tcp_timewait_sock, 138, ##ctx) \ 5579 + FN(skc_to_tcp_request_sock, 139, ##ctx) \ 5580 + FN(skc_to_udp6_sock, 140, ##ctx) \ 5581 + FN(get_task_stack, 141, ##ctx) \ 5582 + FN(load_hdr_opt, 142, ##ctx) \ 5583 + FN(store_hdr_opt, 143, ##ctx) \ 5584 + FN(reserve_hdr_opt, 144, ##ctx) \ 5585 + FN(inode_storage_get, 145, ##ctx) \ 5586 + FN(inode_storage_delete, 146, ##ctx) \ 5587 + FN(d_path, 147, ##ctx) \ 5588 + FN(copy_from_user, 148, ##ctx) \ 5589 + FN(snprintf_btf, 149, ##ctx) \ 5590 + FN(seq_printf_btf, 150, ##ctx) \ 5591 + FN(skb_cgroup_classid, 151, ##ctx) \ 5592 + FN(redirect_neigh, 152, ##ctx) \ 5593 + FN(per_cpu_ptr, 153, ##ctx) \ 5594 + FN(this_cpu_ptr, 154, ##ctx) \ 5595 + FN(redirect_peer, 155, ##ctx) \ 5596 + FN(task_storage_get, 156, ##ctx) \ 5597 + FN(task_storage_delete, 157, ##ctx) \ 5598 + FN(get_current_task_btf, 158, ##ctx) \ 5599 + FN(bprm_opts_set, 159, ##ctx) \ 5600 + FN(ktime_get_coarse_ns, 160, ##ctx) \ 5601 + FN(ima_inode_hash, 161, ##ctx) \ 5602 + FN(sock_from_file, 162, ##ctx) \ 5603 + FN(check_mtu, 163, ##ctx) \ 5604 + FN(for_each_map_elem, 164, ##ctx) \ 5605 + FN(snprintf, 165, ##ctx) \ 5606 + FN(sys_bpf, 166, ##ctx) \ 5607 + FN(btf_find_by_name_kind, 167, ##ctx) \ 5608 + FN(sys_close, 168, ##ctx) \ 5609 + FN(timer_init, 169, ##ctx) \ 5610 + FN(timer_set_callback, 170, ##ctx) \ 5611 + FN(timer_start, 171, ##ctx) \ 5612 + FN(timer_cancel, 172, ##ctx) \ 5613 + FN(get_func_ip, 173, ##ctx) \ 5614 + FN(get_attach_cookie, 174, ##ctx) \ 5615 + FN(task_pt_regs, 175, ##ctx) \ 5616 + FN(get_branch_snapshot, 176, ##ctx) \ 5617 + FN(trace_vprintk, 177, ##ctx) \ 5618 + FN(skc_to_unix_sock, 178, ##ctx) \ 5619 + FN(kallsyms_lookup_name, 179, ##ctx) \ 5620 + FN(find_vma, 180, ##ctx) \ 5621 + FN(loop, 181, ##ctx) \ 5622 + FN(strncmp, 182, ##ctx) \ 5623 + FN(get_func_arg, 183, ##ctx) \ 5624 + FN(get_func_ret, 184, ##ctx) \ 5625 + FN(get_func_arg_cnt, 185, ##ctx) \ 5626 + FN(get_retval, 186, ##ctx) \ 5627 + FN(set_retval, 187, ##ctx) \ 5628 + FN(xdp_get_buff_len, 188, ##ctx) \ 5629 + FN(xdp_load_bytes, 189, ##ctx) \ 5630 + FN(xdp_store_bytes, 190, ##ctx) \ 5631 + FN(copy_from_user_task, 191, ##ctx) \ 5632 + FN(skb_set_tstamp, 192, ##ctx) \ 5633 + FN(ima_file_hash, 193, ##ctx) \ 5634 + FN(kptr_xchg, 194, ##ctx) \ 5635 + FN(map_lookup_percpu_elem, 195, ##ctx) \ 5636 + FN(skc_to_mptcp_sock, 196, ##ctx) \ 5637 + FN(dynptr_from_mem, 197, ##ctx) \ 5638 + FN(ringbuf_reserve_dynptr, 198, ##ctx) \ 5639 + FN(ringbuf_submit_dynptr, 199, ##ctx) \ 5640 + FN(ringbuf_discard_dynptr, 200, ##ctx) \ 5641 + FN(dynptr_read, 201, ##ctx) \ 5642 + FN(dynptr_write, 202, ##ctx) \ 5643 + FN(dynptr_data, 203, ##ctx) \ 5644 + FN(tcp_raw_gen_syncookie_ipv4, 204, ##ctx) \ 5645 + FN(tcp_raw_gen_syncookie_ipv6, 205, ##ctx) \ 5646 + FN(tcp_raw_check_syncookie_ipv4, 206, ##ctx) \ 5647 + FN(tcp_raw_check_syncookie_ipv6, 207, ##ctx) \ 5648 + FN(ktime_get_tai_ns, 208, ##ctx) \ 5649 + FN(user_ringbuf_drain, 209, ##ctx) \ 5650 5650 /* */ 5651 + 5652 + /* backwards-compatibility macros for users of __BPF_FUNC_MAPPER that don't 5653 + * know or care about integer value that is now passed as second argument 5654 + */ 5655 + #define __BPF_FUNC_MAPPER_APPLY(name, value, FN) FN(name), 5656 + #define __BPF_FUNC_MAPPER(FN) ___BPF_FUNC_MAPPER(__BPF_FUNC_MAPPER_APPLY, FN) 5651 5657 5652 5658 /* integer value in 'imm' field of BPF_CALL instruction selects which helper 5653 5659 * function eBPF program intends to call 5654 5660 */ 5655 - #define __BPF_ENUM_FN(x) BPF_FUNC_ ## x 5661 + #define __BPF_ENUM_FN(x, y) BPF_FUNC_ ## x = y, 5656 5662 enum bpf_func_id { 5657 - __BPF_FUNC_MAPPER(__BPF_ENUM_FN) 5663 + ___BPF_FUNC_MAPPER(__BPF_ENUM_FN) 5658 5664 __BPF_FUNC_MAX_ID, 5659 5665 }; 5660 5666 #undef __BPF_ENUM_FN
+11 -2
kernel/bpf/bpf_local_storage.c
··· 88 88 { 89 89 struct bpf_local_storage *local_storage; 90 90 91 + /* If RCU Tasks Trace grace period implies RCU grace period, do 92 + * kfree(), else do kfree_rcu(). 93 + */ 91 94 local_storage = container_of(rcu, struct bpf_local_storage, rcu); 92 - kfree_rcu(local_storage, rcu); 95 + if (rcu_trace_implies_rcu_gp()) 96 + kfree(local_storage); 97 + else 98 + kfree_rcu(local_storage, rcu); 93 99 } 94 100 95 101 static void bpf_selem_free_rcu(struct rcu_head *rcu) ··· 103 97 struct bpf_local_storage_elem *selem; 104 98 105 99 selem = container_of(rcu, struct bpf_local_storage_elem, rcu); 106 - kfree_rcu(selem, rcu); 100 + if (rcu_trace_implies_rcu_gp()) 101 + kfree(selem); 102 + else 103 + kfree_rcu(selem, rcu); 107 104 } 108 105 109 106 /* local_storage->lock must be held and selem->local_storage == local_storage.
+7 -1
kernel/bpf/core.c
··· 2251 2251 { 2252 2252 struct bpf_prog_array *progs; 2253 2253 2254 + /* If RCU Tasks Trace grace period implies RCU grace period, there is 2255 + * no need to call kfree_rcu(), just call kfree() directly. 2256 + */ 2254 2257 progs = container_of(rcu, struct bpf_prog_array, rcu); 2255 - kfree_rcu(progs, rcu); 2258 + if (rcu_trace_implies_rcu_gp()) 2259 + kfree(progs); 2260 + else 2261 + kfree_rcu(progs, rcu); 2256 2262 } 2257 2263 2258 2264 void bpf_prog_array_free_sleepable(struct bpf_prog_array *progs)
+10 -5
kernel/bpf/memalloc.c
··· 222 222 223 223 static void __free_rcu_tasks_trace(struct rcu_head *head) 224 224 { 225 - struct bpf_mem_cache *c = container_of(head, struct bpf_mem_cache, rcu); 226 - 227 - call_rcu(&c->rcu, __free_rcu); 225 + /* If RCU Tasks Trace grace period implies RCU grace period, 226 + * there is no need to invoke call_rcu(). 227 + */ 228 + if (rcu_trace_implies_rcu_gp()) 229 + __free_rcu(head); 230 + else 231 + call_rcu(head, __free_rcu); 228 232 } 229 233 230 234 static void enque_to_free(struct bpf_mem_cache *c, void *obj) ··· 257 253 */ 258 254 __llist_add(llnode, &c->waiting_for_gp); 259 255 /* Use call_rcu_tasks_trace() to wait for sleepable progs to finish. 260 - * Then use call_rcu() to wait for normal progs to finish 261 - * and finally do free_one() on each element. 256 + * If RCU Tasks Trace grace period implies RCU grace period, free 257 + * these elements directly, else use call_rcu() to wait for normal 258 + * progs to finish and finally do free_one() on each element. 262 259 */ 263 260 call_rcu_tasks_trace(&c->rcu, __free_rcu_tasks_trace); 264 261 }
+2
kernel/rcu/tasks.h
··· 1535 1535 { 1536 1536 // Wait for late-stage exiting tasks to finish exiting. 1537 1537 // These might have passed the call to exit_tasks_rcu_finish(). 1538 + 1539 + // If you remove the following line, update rcu_trace_implies_rcu_gp()!!! 1538 1540 synchronize_rcu(); 1539 1541 // Any tasks that exit after this point will set 1540 1542 // TRC_NEED_QS_CHECKED in ->trc_reader_special.b.need_qs.
+32 -14
scripts/bpf_doc.py
··· 97 97 self.desc_unique_helpers = set() 98 98 self.define_unique_helpers = [] 99 99 self.helper_enum_vals = {} 100 + self.helper_enum_pos = {} 100 101 self.desc_syscalls = [] 101 102 self.enum_syscalls = [] 102 103 ··· 254 253 break 255 254 256 255 def parse_define_helpers(self): 257 - # Parse FN(...) in #define __BPF_FUNC_MAPPER to compare later with the 256 + # Parse FN(...) in #define ___BPF_FUNC_MAPPER to compare later with the 258 257 # number of unique function names present in description and use the 259 258 # correct enumeration value. 260 259 # Note: seek_to(..) discards the first line below the target search text, 261 - # resulting in FN(unspec) being skipped and not added to self.define_unique_helpers. 262 - self.seek_to('#define __BPF_FUNC_MAPPER(FN)', 260 + # resulting in FN(unspec, 0, ##ctx) being skipped and not added to 261 + # self.define_unique_helpers. 262 + self.seek_to('#define ___BPF_FUNC_MAPPER(FN, ctx...)', 263 263 'Could not find start of eBPF helper definition list') 264 264 # Searches for one FN(\w+) define or a backslash for newline 265 - p = re.compile('\s*FN\((\w+)\)|\\\\') 265 + p = re.compile('\s*FN\((\w+), (\d+), ##ctx\)|\\\\') 266 266 fn_defines_str = '' 267 - i = 1 # 'unspec' is skipped as mentioned above 267 + i = 0 268 268 while True: 269 269 capture = p.match(self.line) 270 270 if capture: 271 271 fn_defines_str += self.line 272 - self.helper_enum_vals[capture.expand(r'bpf_\1')] = i 272 + helper_name = capture.expand(r'bpf_\1') 273 + self.helper_enum_vals[helper_name] = int(capture[2]) 274 + self.helper_enum_pos[helper_name] = i 273 275 i += 1 274 276 else: 275 277 break 276 278 self.line = self.reader.readline() 277 279 # Find the number of occurences of FN(\w+) 278 - self.define_unique_helpers = re.findall('FN\(\w+\)', fn_defines_str) 280 + self.define_unique_helpers = re.findall('FN\(\w+, \d+, ##ctx\)', fn_defines_str) 279 281 280 - def assign_helper_values(self): 282 + def validate_helpers(self): 283 + last_helper = '' 281 284 seen_helpers = set() 285 + seen_enum_vals = set() 286 + i = 0 282 287 for helper in self.helpers: 283 288 proto = helper.proto_break_down() 284 289 name = proto['name'] 285 290 try: 286 291 enum_val = self.helper_enum_vals[name] 292 + enum_pos = self.helper_enum_pos[name] 287 293 except KeyError: 288 294 raise Exception("Helper %s is missing from enum bpf_func_id" % name) 289 295 296 + if name in seen_helpers: 297 + if last_helper != name: 298 + raise Exception("Helper %s has multiple descriptions which are not grouped together" % name) 299 + continue 300 + 290 301 # Enforce current practice of having the descriptions ordered 291 302 # by enum value. 303 + if enum_pos != i: 304 + raise Exception("Helper %s (ID %d) comment order (#%d) must be aligned with its position (#%d) in enum bpf_func_id" % (name, enum_val, i + 1, enum_pos + 1)) 305 + if enum_val in seen_enum_vals: 306 + raise Exception("Helper %s has duplicated value %d" % (name, enum_val)) 307 + 292 308 seen_helpers.add(name) 293 - desc_val = len(seen_helpers) 294 - if desc_val != enum_val: 295 - raise Exception("Helper %s comment order (#%d) must be aligned with its position (#%d) in enum bpf_func_id" % (name, desc_val, enum_val)) 309 + last_helper = name 310 + seen_enum_vals.add(enum_val) 296 311 297 312 helper.enum_val = enum_val 313 + i += 1 298 314 299 315 def run(self): 300 316 self.parse_desc_syscall() 301 317 self.parse_enum_syscall() 302 318 self.parse_desc_helpers() 303 319 self.parse_define_helpers() 304 - self.assign_helper_values() 320 + self.validate_helpers() 305 321 self.reader.close() 306 322 307 323 ############################################################################### ··· 441 423 """ 442 424 def __init__(self, parser): 443 425 self.elements = parser.helpers 444 - self.elem_number_check(parser.desc_unique_helpers, parser.define_unique_helpers, 'helper', '__BPF_FUNC_MAPPER') 426 + self.elem_number_check(parser.desc_unique_helpers, parser.define_unique_helpers, 'helper', '___BPF_FUNC_MAPPER') 445 427 446 428 def print_header(self): 447 429 header = '''\ ··· 654 636 """ 655 637 def __init__(self, parser): 656 638 self.elements = parser.helpers 657 - self.elem_number_check(parser.desc_unique_helpers, parser.define_unique_helpers, 'helper', '__BPF_FUNC_MAPPER') 639 + self.elem_number_check(parser.desc_unique_helpers, parser.define_unique_helpers, 'helper', '___BPF_FUNC_MAPPER') 658 640 659 641 type_fwds = [ 660 642 'struct bpf_fib_lookup',
+219 -213
tools/include/uapi/linux/bpf.h
··· 5436 5436 * larger than the size of the ring buffer, or which cannot fit 5437 5437 * within a struct bpf_dynptr. 5438 5438 */ 5439 - #define __BPF_FUNC_MAPPER(FN) \ 5440 - FN(unspec), \ 5441 - FN(map_lookup_elem), \ 5442 - FN(map_update_elem), \ 5443 - FN(map_delete_elem), \ 5444 - FN(probe_read), \ 5445 - FN(ktime_get_ns), \ 5446 - FN(trace_printk), \ 5447 - FN(get_prandom_u32), \ 5448 - FN(get_smp_processor_id), \ 5449 - FN(skb_store_bytes), \ 5450 - FN(l3_csum_replace), \ 5451 - FN(l4_csum_replace), \ 5452 - FN(tail_call), \ 5453 - FN(clone_redirect), \ 5454 - FN(get_current_pid_tgid), \ 5455 - FN(get_current_uid_gid), \ 5456 - FN(get_current_comm), \ 5457 - FN(get_cgroup_classid), \ 5458 - FN(skb_vlan_push), \ 5459 - FN(skb_vlan_pop), \ 5460 - FN(skb_get_tunnel_key), \ 5461 - FN(skb_set_tunnel_key), \ 5462 - FN(perf_event_read), \ 5463 - FN(redirect), \ 5464 - FN(get_route_realm), \ 5465 - FN(perf_event_output), \ 5466 - FN(skb_load_bytes), \ 5467 - FN(get_stackid), \ 5468 - FN(csum_diff), \ 5469 - FN(skb_get_tunnel_opt), \ 5470 - FN(skb_set_tunnel_opt), \ 5471 - FN(skb_change_proto), \ 5472 - FN(skb_change_type), \ 5473 - FN(skb_under_cgroup), \ 5474 - FN(get_hash_recalc), \ 5475 - FN(get_current_task), \ 5476 - FN(probe_write_user), \ 5477 - FN(current_task_under_cgroup), \ 5478 - FN(skb_change_tail), \ 5479 - FN(skb_pull_data), \ 5480 - FN(csum_update), \ 5481 - FN(set_hash_invalid), \ 5482 - FN(get_numa_node_id), \ 5483 - FN(skb_change_head), \ 5484 - FN(xdp_adjust_head), \ 5485 - FN(probe_read_str), \ 5486 - FN(get_socket_cookie), \ 5487 - FN(get_socket_uid), \ 5488 - FN(set_hash), \ 5489 - FN(setsockopt), \ 5490 - FN(skb_adjust_room), \ 5491 - FN(redirect_map), \ 5492 - FN(sk_redirect_map), \ 5493 - FN(sock_map_update), \ 5494 - FN(xdp_adjust_meta), \ 5495 - FN(perf_event_read_value), \ 5496 - FN(perf_prog_read_value), \ 5497 - FN(getsockopt), \ 5498 - FN(override_return), \ 5499 - FN(sock_ops_cb_flags_set), \ 5500 - FN(msg_redirect_map), \ 5501 - FN(msg_apply_bytes), \ 5502 - FN(msg_cork_bytes), \ 5503 - FN(msg_pull_data), \ 5504 - FN(bind), \ 5505 - FN(xdp_adjust_tail), \ 5506 - FN(skb_get_xfrm_state), \ 5507 - FN(get_stack), \ 5508 - FN(skb_load_bytes_relative), \ 5509 - FN(fib_lookup), \ 5510 - FN(sock_hash_update), \ 5511 - FN(msg_redirect_hash), \ 5512 - FN(sk_redirect_hash), \ 5513 - FN(lwt_push_encap), \ 5514 - FN(lwt_seg6_store_bytes), \ 5515 - FN(lwt_seg6_adjust_srh), \ 5516 - FN(lwt_seg6_action), \ 5517 - FN(rc_repeat), \ 5518 - FN(rc_keydown), \ 5519 - FN(skb_cgroup_id), \ 5520 - FN(get_current_cgroup_id), \ 5521 - FN(get_local_storage), \ 5522 - FN(sk_select_reuseport), \ 5523 - FN(skb_ancestor_cgroup_id), \ 5524 - FN(sk_lookup_tcp), \ 5525 - FN(sk_lookup_udp), \ 5526 - FN(sk_release), \ 5527 - FN(map_push_elem), \ 5528 - FN(map_pop_elem), \ 5529 - FN(map_peek_elem), \ 5530 - FN(msg_push_data), \ 5531 - FN(msg_pop_data), \ 5532 - FN(rc_pointer_rel), \ 5533 - FN(spin_lock), \ 5534 - FN(spin_unlock), \ 5535 - FN(sk_fullsock), \ 5536 - FN(tcp_sock), \ 5537 - FN(skb_ecn_set_ce), \ 5538 - FN(get_listener_sock), \ 5539 - FN(skc_lookup_tcp), \ 5540 - FN(tcp_check_syncookie), \ 5541 - FN(sysctl_get_name), \ 5542 - FN(sysctl_get_current_value), \ 5543 - FN(sysctl_get_new_value), \ 5544 - FN(sysctl_set_new_value), \ 5545 - FN(strtol), \ 5546 - FN(strtoul), \ 5547 - FN(sk_storage_get), \ 5548 - FN(sk_storage_delete), \ 5549 - FN(send_signal), \ 5550 - FN(tcp_gen_syncookie), \ 5551 - FN(skb_output), \ 5552 - FN(probe_read_user), \ 5553 - FN(probe_read_kernel), \ 5554 - FN(probe_read_user_str), \ 5555 - FN(probe_read_kernel_str), \ 5556 - FN(tcp_send_ack), \ 5557 - FN(send_signal_thread), \ 5558 - FN(jiffies64), \ 5559 - FN(read_branch_records), \ 5560 - FN(get_ns_current_pid_tgid), \ 5561 - FN(xdp_output), \ 5562 - FN(get_netns_cookie), \ 5563 - FN(get_current_ancestor_cgroup_id), \ 5564 - FN(sk_assign), \ 5565 - FN(ktime_get_boot_ns), \ 5566 - FN(seq_printf), \ 5567 - FN(seq_write), \ 5568 - FN(sk_cgroup_id), \ 5569 - FN(sk_ancestor_cgroup_id), \ 5570 - FN(ringbuf_output), \ 5571 - FN(ringbuf_reserve), \ 5572 - FN(ringbuf_submit), \ 5573 - FN(ringbuf_discard), \ 5574 - FN(ringbuf_query), \ 5575 - FN(csum_level), \ 5576 - FN(skc_to_tcp6_sock), \ 5577 - FN(skc_to_tcp_sock), \ 5578 - FN(skc_to_tcp_timewait_sock), \ 5579 - FN(skc_to_tcp_request_sock), \ 5580 - FN(skc_to_udp6_sock), \ 5581 - FN(get_task_stack), \ 5582 - FN(load_hdr_opt), \ 5583 - FN(store_hdr_opt), \ 5584 - FN(reserve_hdr_opt), \ 5585 - FN(inode_storage_get), \ 5586 - FN(inode_storage_delete), \ 5587 - FN(d_path), \ 5588 - FN(copy_from_user), \ 5589 - FN(snprintf_btf), \ 5590 - FN(seq_printf_btf), \ 5591 - FN(skb_cgroup_classid), \ 5592 - FN(redirect_neigh), \ 5593 - FN(per_cpu_ptr), \ 5594 - FN(this_cpu_ptr), \ 5595 - FN(redirect_peer), \ 5596 - FN(task_storage_get), \ 5597 - FN(task_storage_delete), \ 5598 - FN(get_current_task_btf), \ 5599 - FN(bprm_opts_set), \ 5600 - FN(ktime_get_coarse_ns), \ 5601 - FN(ima_inode_hash), \ 5602 - FN(sock_from_file), \ 5603 - FN(check_mtu), \ 5604 - FN(for_each_map_elem), \ 5605 - FN(snprintf), \ 5606 - FN(sys_bpf), \ 5607 - FN(btf_find_by_name_kind), \ 5608 - FN(sys_close), \ 5609 - FN(timer_init), \ 5610 - FN(timer_set_callback), \ 5611 - FN(timer_start), \ 5612 - FN(timer_cancel), \ 5613 - FN(get_func_ip), \ 5614 - FN(get_attach_cookie), \ 5615 - FN(task_pt_regs), \ 5616 - FN(get_branch_snapshot), \ 5617 - FN(trace_vprintk), \ 5618 - FN(skc_to_unix_sock), \ 5619 - FN(kallsyms_lookup_name), \ 5620 - FN(find_vma), \ 5621 - FN(loop), \ 5622 - FN(strncmp), \ 5623 - FN(get_func_arg), \ 5624 - FN(get_func_ret), \ 5625 - FN(get_func_arg_cnt), \ 5626 - FN(get_retval), \ 5627 - FN(set_retval), \ 5628 - FN(xdp_get_buff_len), \ 5629 - FN(xdp_load_bytes), \ 5630 - FN(xdp_store_bytes), \ 5631 - FN(copy_from_user_task), \ 5632 - FN(skb_set_tstamp), \ 5633 - FN(ima_file_hash), \ 5634 - FN(kptr_xchg), \ 5635 - FN(map_lookup_percpu_elem), \ 5636 - FN(skc_to_mptcp_sock), \ 5637 - FN(dynptr_from_mem), \ 5638 - FN(ringbuf_reserve_dynptr), \ 5639 - FN(ringbuf_submit_dynptr), \ 5640 - FN(ringbuf_discard_dynptr), \ 5641 - FN(dynptr_read), \ 5642 - FN(dynptr_write), \ 5643 - FN(dynptr_data), \ 5644 - FN(tcp_raw_gen_syncookie_ipv4), \ 5645 - FN(tcp_raw_gen_syncookie_ipv6), \ 5646 - FN(tcp_raw_check_syncookie_ipv4), \ 5647 - FN(tcp_raw_check_syncookie_ipv6), \ 5648 - FN(ktime_get_tai_ns), \ 5649 - FN(user_ringbuf_drain), \ 5439 + #define ___BPF_FUNC_MAPPER(FN, ctx...) \ 5440 + FN(unspec, 0, ##ctx) \ 5441 + FN(map_lookup_elem, 1, ##ctx) \ 5442 + FN(map_update_elem, 2, ##ctx) \ 5443 + FN(map_delete_elem, 3, ##ctx) \ 5444 + FN(probe_read, 4, ##ctx) \ 5445 + FN(ktime_get_ns, 5, ##ctx) \ 5446 + FN(trace_printk, 6, ##ctx) \ 5447 + FN(get_prandom_u32, 7, ##ctx) \ 5448 + FN(get_smp_processor_id, 8, ##ctx) \ 5449 + FN(skb_store_bytes, 9, ##ctx) \ 5450 + FN(l3_csum_replace, 10, ##ctx) \ 5451 + FN(l4_csum_replace, 11, ##ctx) \ 5452 + FN(tail_call, 12, ##ctx) \ 5453 + FN(clone_redirect, 13, ##ctx) \ 5454 + FN(get_current_pid_tgid, 14, ##ctx) \ 5455 + FN(get_current_uid_gid, 15, ##ctx) \ 5456 + FN(get_current_comm, 16, ##ctx) \ 5457 + FN(get_cgroup_classid, 17, ##ctx) \ 5458 + FN(skb_vlan_push, 18, ##ctx) \ 5459 + FN(skb_vlan_pop, 19, ##ctx) \ 5460 + FN(skb_get_tunnel_key, 20, ##ctx) \ 5461 + FN(skb_set_tunnel_key, 21, ##ctx) \ 5462 + FN(perf_event_read, 22, ##ctx) \ 5463 + FN(redirect, 23, ##ctx) \ 5464 + FN(get_route_realm, 24, ##ctx) \ 5465 + FN(perf_event_output, 25, ##ctx) \ 5466 + FN(skb_load_bytes, 26, ##ctx) \ 5467 + FN(get_stackid, 27, ##ctx) \ 5468 + FN(csum_diff, 28, ##ctx) \ 5469 + FN(skb_get_tunnel_opt, 29, ##ctx) \ 5470 + FN(skb_set_tunnel_opt, 30, ##ctx) \ 5471 + FN(skb_change_proto, 31, ##ctx) \ 5472 + FN(skb_change_type, 32, ##ctx) \ 5473 + FN(skb_under_cgroup, 33, ##ctx) \ 5474 + FN(get_hash_recalc, 34, ##ctx) \ 5475 + FN(get_current_task, 35, ##ctx) \ 5476 + FN(probe_write_user, 36, ##ctx) \ 5477 + FN(current_task_under_cgroup, 37, ##ctx) \ 5478 + FN(skb_change_tail, 38, ##ctx) \ 5479 + FN(skb_pull_data, 39, ##ctx) \ 5480 + FN(csum_update, 40, ##ctx) \ 5481 + FN(set_hash_invalid, 41, ##ctx) \ 5482 + FN(get_numa_node_id, 42, ##ctx) \ 5483 + FN(skb_change_head, 43, ##ctx) \ 5484 + FN(xdp_adjust_head, 44, ##ctx) \ 5485 + FN(probe_read_str, 45, ##ctx) \ 5486 + FN(get_socket_cookie, 46, ##ctx) \ 5487 + FN(get_socket_uid, 47, ##ctx) \ 5488 + FN(set_hash, 48, ##ctx) \ 5489 + FN(setsockopt, 49, ##ctx) \ 5490 + FN(skb_adjust_room, 50, ##ctx) \ 5491 + FN(redirect_map, 51, ##ctx) \ 5492 + FN(sk_redirect_map, 52, ##ctx) \ 5493 + FN(sock_map_update, 53, ##ctx) \ 5494 + FN(xdp_adjust_meta, 54, ##ctx) \ 5495 + FN(perf_event_read_value, 55, ##ctx) \ 5496 + FN(perf_prog_read_value, 56, ##ctx) \ 5497 + FN(getsockopt, 57, ##ctx) \ 5498 + FN(override_return, 58, ##ctx) \ 5499 + FN(sock_ops_cb_flags_set, 59, ##ctx) \ 5500 + FN(msg_redirect_map, 60, ##ctx) \ 5501 + FN(msg_apply_bytes, 61, ##ctx) \ 5502 + FN(msg_cork_bytes, 62, ##ctx) \ 5503 + FN(msg_pull_data, 63, ##ctx) \ 5504 + FN(bind, 64, ##ctx) \ 5505 + FN(xdp_adjust_tail, 65, ##ctx) \ 5506 + FN(skb_get_xfrm_state, 66, ##ctx) \ 5507 + FN(get_stack, 67, ##ctx) \ 5508 + FN(skb_load_bytes_relative, 68, ##ctx) \ 5509 + FN(fib_lookup, 69, ##ctx) \ 5510 + FN(sock_hash_update, 70, ##ctx) \ 5511 + FN(msg_redirect_hash, 71, ##ctx) \ 5512 + FN(sk_redirect_hash, 72, ##ctx) \ 5513 + FN(lwt_push_encap, 73, ##ctx) \ 5514 + FN(lwt_seg6_store_bytes, 74, ##ctx) \ 5515 + FN(lwt_seg6_adjust_srh, 75, ##ctx) \ 5516 + FN(lwt_seg6_action, 76, ##ctx) \ 5517 + FN(rc_repeat, 77, ##ctx) \ 5518 + FN(rc_keydown, 78, ##ctx) \ 5519 + FN(skb_cgroup_id, 79, ##ctx) \ 5520 + FN(get_current_cgroup_id, 80, ##ctx) \ 5521 + FN(get_local_storage, 81, ##ctx) \ 5522 + FN(sk_select_reuseport, 82, ##ctx) \ 5523 + FN(skb_ancestor_cgroup_id, 83, ##ctx) \ 5524 + FN(sk_lookup_tcp, 84, ##ctx) \ 5525 + FN(sk_lookup_udp, 85, ##ctx) \ 5526 + FN(sk_release, 86, ##ctx) \ 5527 + FN(map_push_elem, 87, ##ctx) \ 5528 + FN(map_pop_elem, 88, ##ctx) \ 5529 + FN(map_peek_elem, 89, ##ctx) \ 5530 + FN(msg_push_data, 90, ##ctx) \ 5531 + FN(msg_pop_data, 91, ##ctx) \ 5532 + FN(rc_pointer_rel, 92, ##ctx) \ 5533 + FN(spin_lock, 93, ##ctx) \ 5534 + FN(spin_unlock, 94, ##ctx) \ 5535 + FN(sk_fullsock, 95, ##ctx) \ 5536 + FN(tcp_sock, 96, ##ctx) \ 5537 + FN(skb_ecn_set_ce, 97, ##ctx) \ 5538 + FN(get_listener_sock, 98, ##ctx) \ 5539 + FN(skc_lookup_tcp, 99, ##ctx) \ 5540 + FN(tcp_check_syncookie, 100, ##ctx) \ 5541 + FN(sysctl_get_name, 101, ##ctx) \ 5542 + FN(sysctl_get_current_value, 102, ##ctx) \ 5543 + FN(sysctl_get_new_value, 103, ##ctx) \ 5544 + FN(sysctl_set_new_value, 104, ##ctx) \ 5545 + FN(strtol, 105, ##ctx) \ 5546 + FN(strtoul, 106, ##ctx) \ 5547 + FN(sk_storage_get, 107, ##ctx) \ 5548 + FN(sk_storage_delete, 108, ##ctx) \ 5549 + FN(send_signal, 109, ##ctx) \ 5550 + FN(tcp_gen_syncookie, 110, ##ctx) \ 5551 + FN(skb_output, 111, ##ctx) \ 5552 + FN(probe_read_user, 112, ##ctx) \ 5553 + FN(probe_read_kernel, 113, ##ctx) \ 5554 + FN(probe_read_user_str, 114, ##ctx) \ 5555 + FN(probe_read_kernel_str, 115, ##ctx) \ 5556 + FN(tcp_send_ack, 116, ##ctx) \ 5557 + FN(send_signal_thread, 117, ##ctx) \ 5558 + FN(jiffies64, 118, ##ctx) \ 5559 + FN(read_branch_records, 119, ##ctx) \ 5560 + FN(get_ns_current_pid_tgid, 120, ##ctx) \ 5561 + FN(xdp_output, 121, ##ctx) \ 5562 + FN(get_netns_cookie, 122, ##ctx) \ 5563 + FN(get_current_ancestor_cgroup_id, 123, ##ctx) \ 5564 + FN(sk_assign, 124, ##ctx) \ 5565 + FN(ktime_get_boot_ns, 125, ##ctx) \ 5566 + FN(seq_printf, 126, ##ctx) \ 5567 + FN(seq_write, 127, ##ctx) \ 5568 + FN(sk_cgroup_id, 128, ##ctx) \ 5569 + FN(sk_ancestor_cgroup_id, 129, ##ctx) \ 5570 + FN(ringbuf_output, 130, ##ctx) \ 5571 + FN(ringbuf_reserve, 131, ##ctx) \ 5572 + FN(ringbuf_submit, 132, ##ctx) \ 5573 + FN(ringbuf_discard, 133, ##ctx) \ 5574 + FN(ringbuf_query, 134, ##ctx) \ 5575 + FN(csum_level, 135, ##ctx) \ 5576 + FN(skc_to_tcp6_sock, 136, ##ctx) \ 5577 + FN(skc_to_tcp_sock, 137, ##ctx) \ 5578 + FN(skc_to_tcp_timewait_sock, 138, ##ctx) \ 5579 + FN(skc_to_tcp_request_sock, 139, ##ctx) \ 5580 + FN(skc_to_udp6_sock, 140, ##ctx) \ 5581 + FN(get_task_stack, 141, ##ctx) \ 5582 + FN(load_hdr_opt, 142, ##ctx) \ 5583 + FN(store_hdr_opt, 143, ##ctx) \ 5584 + FN(reserve_hdr_opt, 144, ##ctx) \ 5585 + FN(inode_storage_get, 145, ##ctx) \ 5586 + FN(inode_storage_delete, 146, ##ctx) \ 5587 + FN(d_path, 147, ##ctx) \ 5588 + FN(copy_from_user, 148, ##ctx) \ 5589 + FN(snprintf_btf, 149, ##ctx) \ 5590 + FN(seq_printf_btf, 150, ##ctx) \ 5591 + FN(skb_cgroup_classid, 151, ##ctx) \ 5592 + FN(redirect_neigh, 152, ##ctx) \ 5593 + FN(per_cpu_ptr, 153, ##ctx) \ 5594 + FN(this_cpu_ptr, 154, ##ctx) \ 5595 + FN(redirect_peer, 155, ##ctx) \ 5596 + FN(task_storage_get, 156, ##ctx) \ 5597 + FN(task_storage_delete, 157, ##ctx) \ 5598 + FN(get_current_task_btf, 158, ##ctx) \ 5599 + FN(bprm_opts_set, 159, ##ctx) \ 5600 + FN(ktime_get_coarse_ns, 160, ##ctx) \ 5601 + FN(ima_inode_hash, 161, ##ctx) \ 5602 + FN(sock_from_file, 162, ##ctx) \ 5603 + FN(check_mtu, 163, ##ctx) \ 5604 + FN(for_each_map_elem, 164, ##ctx) \ 5605 + FN(snprintf, 165, ##ctx) \ 5606 + FN(sys_bpf, 166, ##ctx) \ 5607 + FN(btf_find_by_name_kind, 167, ##ctx) \ 5608 + FN(sys_close, 168, ##ctx) \ 5609 + FN(timer_init, 169, ##ctx) \ 5610 + FN(timer_set_callback, 170, ##ctx) \ 5611 + FN(timer_start, 171, ##ctx) \ 5612 + FN(timer_cancel, 172, ##ctx) \ 5613 + FN(get_func_ip, 173, ##ctx) \ 5614 + FN(get_attach_cookie, 174, ##ctx) \ 5615 + FN(task_pt_regs, 175, ##ctx) \ 5616 + FN(get_branch_snapshot, 176, ##ctx) \ 5617 + FN(trace_vprintk, 177, ##ctx) \ 5618 + FN(skc_to_unix_sock, 178, ##ctx) \ 5619 + FN(kallsyms_lookup_name, 179, ##ctx) \ 5620 + FN(find_vma, 180, ##ctx) \ 5621 + FN(loop, 181, ##ctx) \ 5622 + FN(strncmp, 182, ##ctx) \ 5623 + FN(get_func_arg, 183, ##ctx) \ 5624 + FN(get_func_ret, 184, ##ctx) \ 5625 + FN(get_func_arg_cnt, 185, ##ctx) \ 5626 + FN(get_retval, 186, ##ctx) \ 5627 + FN(set_retval, 187, ##ctx) \ 5628 + FN(xdp_get_buff_len, 188, ##ctx) \ 5629 + FN(xdp_load_bytes, 189, ##ctx) \ 5630 + FN(xdp_store_bytes, 190, ##ctx) \ 5631 + FN(copy_from_user_task, 191, ##ctx) \ 5632 + FN(skb_set_tstamp, 192, ##ctx) \ 5633 + FN(ima_file_hash, 193, ##ctx) \ 5634 + FN(kptr_xchg, 194, ##ctx) \ 5635 + FN(map_lookup_percpu_elem, 195, ##ctx) \ 5636 + FN(skc_to_mptcp_sock, 196, ##ctx) \ 5637 + FN(dynptr_from_mem, 197, ##ctx) \ 5638 + FN(ringbuf_reserve_dynptr, 198, ##ctx) \ 5639 + FN(ringbuf_submit_dynptr, 199, ##ctx) \ 5640 + FN(ringbuf_discard_dynptr, 200, ##ctx) \ 5641 + FN(dynptr_read, 201, ##ctx) \ 5642 + FN(dynptr_write, 202, ##ctx) \ 5643 + FN(dynptr_data, 203, ##ctx) \ 5644 + FN(tcp_raw_gen_syncookie_ipv4, 204, ##ctx) \ 5645 + FN(tcp_raw_gen_syncookie_ipv6, 205, ##ctx) \ 5646 + FN(tcp_raw_check_syncookie_ipv4, 206, ##ctx) \ 5647 + FN(tcp_raw_check_syncookie_ipv6, 207, ##ctx) \ 5648 + FN(ktime_get_tai_ns, 208, ##ctx) \ 5649 + FN(user_ringbuf_drain, 209, ##ctx) \ 5650 5650 /* */ 5651 + 5652 + /* backwards-compatibility macros for users of __BPF_FUNC_MAPPER that don't 5653 + * know or care about integer value that is now passed as second argument 5654 + */ 5655 + #define __BPF_FUNC_MAPPER_APPLY(name, value, FN) FN(name), 5656 + #define __BPF_FUNC_MAPPER(FN) ___BPF_FUNC_MAPPER(__BPF_FUNC_MAPPER_APPLY, FN) 5651 5657 5652 5658 /* integer value in 'imm' field of BPF_CALL instruction selects which helper 5653 5659 * function eBPF program intends to call 5654 5660 */ 5655 - #define __BPF_ENUM_FN(x) BPF_FUNC_ ## x 5661 + #define __BPF_ENUM_FN(x, y) BPF_FUNC_ ## x = y, 5656 5662 enum bpf_func_id { 5657 - __BPF_FUNC_MAPPER(__BPF_ENUM_FN) 5663 + ___BPF_FUNC_MAPPER(__BPF_ENUM_FN) 5658 5664 __BPF_FUNC_MAX_ID, 5659 5665 }; 5660 5666 #undef __BPF_ENUM_FN
+44 -4
tools/lib/bpf/bpf.c
··· 935 935 return bpf_obj_get_next_id(start_id, next_id, BPF_LINK_GET_NEXT_ID); 936 936 } 937 937 938 - int bpf_prog_get_fd_by_id(__u32 id) 938 + int bpf_prog_get_fd_by_id_opts(__u32 id, 939 + const struct bpf_get_fd_by_id_opts *opts) 939 940 { 940 941 const size_t attr_sz = offsetofend(union bpf_attr, open_flags); 941 942 union bpf_attr attr; 942 943 int fd; 943 944 945 + if (!OPTS_VALID(opts, bpf_get_fd_by_id_opts)) 946 + return libbpf_err(-EINVAL); 947 + 944 948 memset(&attr, 0, attr_sz); 945 949 attr.prog_id = id; 950 + attr.open_flags = OPTS_GET(opts, open_flags, 0); 946 951 947 952 fd = sys_bpf_fd(BPF_PROG_GET_FD_BY_ID, &attr, attr_sz); 948 953 return libbpf_err_errno(fd); 949 954 } 950 955 951 - int bpf_map_get_fd_by_id(__u32 id) 956 + int bpf_prog_get_fd_by_id(__u32 id) 957 + { 958 + return bpf_prog_get_fd_by_id_opts(id, NULL); 959 + } 960 + 961 + int bpf_map_get_fd_by_id_opts(__u32 id, 962 + const struct bpf_get_fd_by_id_opts *opts) 952 963 { 953 964 const size_t attr_sz = offsetofend(union bpf_attr, open_flags); 954 965 union bpf_attr attr; 955 966 int fd; 956 967 968 + if (!OPTS_VALID(opts, bpf_get_fd_by_id_opts)) 969 + return libbpf_err(-EINVAL); 970 + 957 971 memset(&attr, 0, attr_sz); 958 972 attr.map_id = id; 973 + attr.open_flags = OPTS_GET(opts, open_flags, 0); 959 974 960 975 fd = sys_bpf_fd(BPF_MAP_GET_FD_BY_ID, &attr, attr_sz); 961 976 return libbpf_err_errno(fd); 962 977 } 963 978 964 - int bpf_btf_get_fd_by_id(__u32 id) 979 + int bpf_map_get_fd_by_id(__u32 id) 980 + { 981 + return bpf_map_get_fd_by_id_opts(id, NULL); 982 + } 983 + 984 + int bpf_btf_get_fd_by_id_opts(__u32 id, 985 + const struct bpf_get_fd_by_id_opts *opts) 965 986 { 966 987 const size_t attr_sz = offsetofend(union bpf_attr, open_flags); 967 988 union bpf_attr attr; 968 989 int fd; 969 990 991 + if (!OPTS_VALID(opts, bpf_get_fd_by_id_opts)) 992 + return libbpf_err(-EINVAL); 993 + 970 994 memset(&attr, 0, attr_sz); 971 995 attr.btf_id = id; 996 + attr.open_flags = OPTS_GET(opts, open_flags, 0); 972 997 973 998 fd = sys_bpf_fd(BPF_BTF_GET_FD_BY_ID, &attr, attr_sz); 974 999 return libbpf_err_errno(fd); 975 1000 } 976 1001 977 - int bpf_link_get_fd_by_id(__u32 id) 1002 + int bpf_btf_get_fd_by_id(__u32 id) 1003 + { 1004 + return bpf_btf_get_fd_by_id_opts(id, NULL); 1005 + } 1006 + 1007 + int bpf_link_get_fd_by_id_opts(__u32 id, 1008 + const struct bpf_get_fd_by_id_opts *opts) 978 1009 { 979 1010 const size_t attr_sz = offsetofend(union bpf_attr, open_flags); 980 1011 union bpf_attr attr; 981 1012 int fd; 982 1013 1014 + if (!OPTS_VALID(opts, bpf_get_fd_by_id_opts)) 1015 + return libbpf_err(-EINVAL); 1016 + 983 1017 memset(&attr, 0, attr_sz); 984 1018 attr.link_id = id; 1019 + attr.open_flags = OPTS_GET(opts, open_flags, 0); 985 1020 986 1021 fd = sys_bpf_fd(BPF_LINK_GET_FD_BY_ID, &attr, attr_sz); 987 1022 return libbpf_err_errno(fd); 1023 + } 1024 + 1025 + int bpf_link_get_fd_by_id(__u32 id) 1026 + { 1027 + return bpf_link_get_fd_by_id_opts(id, NULL); 988 1028 } 989 1029 990 1030 int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len)
+16
tools/lib/bpf/bpf.h
··· 365 365 LIBBPF_API int bpf_map_get_next_id(__u32 start_id, __u32 *next_id); 366 366 LIBBPF_API int bpf_btf_get_next_id(__u32 start_id, __u32 *next_id); 367 367 LIBBPF_API int bpf_link_get_next_id(__u32 start_id, __u32 *next_id); 368 + 369 + struct bpf_get_fd_by_id_opts { 370 + size_t sz; /* size of this struct for forward/backward compatibility */ 371 + __u32 open_flags; /* permissions requested for the operation on fd */ 372 + size_t :0; 373 + }; 374 + #define bpf_get_fd_by_id_opts__last_field open_flags 375 + 368 376 LIBBPF_API int bpf_prog_get_fd_by_id(__u32 id); 377 + LIBBPF_API int bpf_prog_get_fd_by_id_opts(__u32 id, 378 + const struct bpf_get_fd_by_id_opts *opts); 369 379 LIBBPF_API int bpf_map_get_fd_by_id(__u32 id); 380 + LIBBPF_API int bpf_map_get_fd_by_id_opts(__u32 id, 381 + const struct bpf_get_fd_by_id_opts *opts); 370 382 LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id); 383 + LIBBPF_API int bpf_btf_get_fd_by_id_opts(__u32 id, 384 + const struct bpf_get_fd_by_id_opts *opts); 371 385 LIBBPF_API int bpf_link_get_fd_by_id(__u32 id); 386 + LIBBPF_API int bpf_link_get_fd_by_id_opts(__u32 id, 387 + const struct bpf_get_fd_by_id_opts *opts); 372 388 LIBBPF_API int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len); 373 389 374 390 struct bpf_prog_query_opts {
+31 -4
tools/lib/bpf/btf_dump.c
··· 219 219 return 0; 220 220 } 221 221 222 + static void btf_dump_free_names(struct hashmap *map) 223 + { 224 + size_t bkt; 225 + struct hashmap_entry *cur; 226 + 227 + hashmap__for_each_entry(map, cur, bkt) 228 + free((void *)cur->key); 229 + 230 + hashmap__free(map); 231 + } 232 + 222 233 void btf_dump__free(struct btf_dump *d) 223 234 { 224 235 int i; ··· 248 237 free(d->cached_names); 249 238 free(d->emit_queue); 250 239 free(d->decl_stack); 251 - hashmap__free(d->type_names); 252 - hashmap__free(d->ident_names); 240 + btf_dump_free_names(d->type_names); 241 + btf_dump_free_names(d->ident_names); 253 242 254 243 free(d); 255 244 } ··· 955 944 lvl + 1); 956 945 } 957 946 958 - if (vlen) 947 + /* 948 + * Keep `struct empty {}` on a single line, 949 + * only print newline when there are regular or padding fields. 950 + */ 951 + if (vlen || t->size) 959 952 btf_dump_printf(d, "\n"); 960 953 btf_dump_printf(d, "%s}", pfx(lvl)); 961 954 if (packed) ··· 1535 1520 static size_t btf_dump_name_dups(struct btf_dump *d, struct hashmap *name_map, 1536 1521 const char *orig_name) 1537 1522 { 1523 + char *old_name, *new_name; 1538 1524 size_t dup_cnt = 0; 1525 + int err; 1526 + 1527 + new_name = strdup(orig_name); 1528 + if (!new_name) 1529 + return 1; 1539 1530 1540 1531 hashmap__find(name_map, orig_name, (void **)&dup_cnt); 1541 1532 dup_cnt++; 1542 - hashmap__set(name_map, orig_name, (void *)dup_cnt, NULL, NULL); 1533 + 1534 + err = hashmap__set(name_map, new_name, (void *)dup_cnt, 1535 + (const void **)&old_name, NULL); 1536 + if (err) 1537 + free(new_name); 1538 + 1539 + free(old_name); 1543 1540 1544 1541 return dup_cnt; 1545 1542 }
+17 -5
tools/lib/bpf/libbpf.c
··· 597 597 size_t shstrndx; /* section index for section name strings */ 598 598 size_t strtabidx; 599 599 struct elf_sec_desc *secs; 600 - int sec_cnt; 600 + size_t sec_cnt; 601 601 int btf_maps_shndx; 602 602 __u32 btf_maps_sec_btf_id; 603 603 int text_shndx; ··· 1408 1408 static int 1409 1409 bpf_object__init_license(struct bpf_object *obj, void *data, size_t size) 1410 1410 { 1411 + if (!data) { 1412 + pr_warn("invalid license section in %s\n", obj->path); 1413 + return -LIBBPF_ERRNO__FORMAT; 1414 + } 1411 1415 /* libbpf_strlcpy() only copies first N - 1 bytes, so size + 1 won't 1412 1416 * go over allowed ELF data section buffer 1413 1417 */ ··· 1425 1421 { 1426 1422 __u32 kver; 1427 1423 1428 - if (size != sizeof(kver)) { 1424 + if (!data || size != sizeof(kver)) { 1429 1425 pr_warn("invalid kver section in %s\n", obj->path); 1430 1426 return -LIBBPF_ERRNO__FORMAT; 1431 1427 } ··· 3316 3312 Elf64_Shdr *sh; 3317 3313 3318 3314 /* ELF section indices are 0-based, but sec #0 is special "invalid" 3319 - * section. e_shnum does include sec #0, so e_shnum is the necessary 3320 - * size of an array to keep all the sections. 3315 + * section. Since section count retrieved by elf_getshdrnum() does 3316 + * include sec #0, it is already the necessary size of an array to keep 3317 + * all the sections. 3321 3318 */ 3322 - obj->efile.sec_cnt = obj->efile.ehdr->e_shnum; 3319 + if (elf_getshdrnum(obj->efile.elf, &obj->efile.sec_cnt)) { 3320 + pr_warn("elf: failed to get the number of sections for %s: %s\n", 3321 + obj->path, elf_errmsg(-1)); 3322 + return -LIBBPF_ERRNO__FORMAT; 3323 + } 3323 3324 obj->efile.secs = calloc(obj->efile.sec_cnt, sizeof(*obj->efile.secs)); 3324 3325 if (!obj->efile.secs) 3325 3326 return -ENOMEM; ··· 4114 4105 { 4115 4106 int l = 0, r = obj->nr_programs - 1, m; 4116 4107 struct bpf_program *prog; 4108 + 4109 + if (!obj->nr_programs) 4110 + return NULL; 4117 4111 4118 4112 while (l < r) { 4119 4113 m = l + (r - l + 1) / 2;
+5 -1
tools/lib/bpf/libbpf.map
··· 367 367 libbpf_bpf_map_type_str; 368 368 libbpf_bpf_prog_type_str; 369 369 perf_buffer__buffer; 370 - }; 370 + } LIBBPF_0.8.0; 371 371 372 372 LIBBPF_1.1.0 { 373 373 global: 374 + bpf_btf_get_fd_by_id_opts; 375 + bpf_link_get_fd_by_id_opts; 376 + bpf_map_get_fd_by_id_opts; 377 + bpf_prog_get_fd_by_id_opts; 374 378 user_ring_buffer__discard; 375 379 user_ring_buffer__free; 376 380 user_ring_buffer__new;
+4 -7
tools/lib/bpf/usdt.c
··· 1348 1348 1349 1349 static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec *arg) 1350 1350 { 1351 - char *reg_name = NULL; 1351 + char reg_name[16]; 1352 1352 int arg_sz, len, reg_off; 1353 1353 long off; 1354 1354 1355 - if (sscanf(arg_str, " %d @ \[ %m[a-z0-9], %ld ] %n", &arg_sz, &reg_name, &off, &len) == 3) { 1355 + if (sscanf(arg_str, " %d @ \[ %15[a-z0-9], %ld ] %n", &arg_sz, reg_name, &off, &len) == 3) { 1356 1356 /* Memory dereference case, e.g., -4@[sp, 96] */ 1357 1357 arg->arg_type = USDT_ARG_REG_DEREF; 1358 1358 arg->val_off = off; 1359 1359 reg_off = calc_pt_regs_off(reg_name); 1360 - free(reg_name); 1361 1360 if (reg_off < 0) 1362 1361 return reg_off; 1363 1362 arg->reg_off = reg_off; 1364 - } else if (sscanf(arg_str, " %d @ \[ %m[a-z0-9] ] %n", &arg_sz, &reg_name, &len) == 2) { 1363 + } else if (sscanf(arg_str, " %d @ \[ %15[a-z0-9] ] %n", &arg_sz, reg_name, &len) == 2) { 1365 1364 /* Memory dereference case, e.g., -4@[sp] */ 1366 1365 arg->arg_type = USDT_ARG_REG_DEREF; 1367 1366 arg->val_off = 0; 1368 1367 reg_off = calc_pt_regs_off(reg_name); 1369 - free(reg_name); 1370 1368 if (reg_off < 0) 1371 1369 return reg_off; 1372 1370 arg->reg_off = reg_off; ··· 1373 1375 arg->arg_type = USDT_ARG_CONST; 1374 1376 arg->val_off = off; 1375 1377 arg->reg_off = 0; 1376 - } else if (sscanf(arg_str, " %d @ %m[a-z0-9] %n", &arg_sz, &reg_name, &len) == 2) { 1378 + } else if (sscanf(arg_str, " %d @ %15[a-z0-9] %n", &arg_sz, reg_name, &len) == 2) { 1377 1379 /* Register read case, e.g., -8@x4 */ 1378 1380 arg->arg_type = USDT_ARG_REG; 1379 1381 arg->val_off = 0; 1380 1382 reg_off = calc_pt_regs_off(reg_name); 1381 - free(reg_name); 1382 1383 if (reg_off < 0) 1383 1384 return reg_off; 1384 1385 arg->reg_off = reg_off;
+2 -1
tools/testing/selftests/bpf/DENYLIST
··· 1 1 # TEMPORARY 2 + # Alphabetical order 2 3 get_stack_raw_tp # spams with kernel warnings until next bpf -> bpf-next merge 3 - stacktrace_build_id_nmi 4 4 stacktrace_build_id 5 + stacktrace_build_id_nmi 5 6 task_fd_query_rawtp 6 7 varlen
+21 -18
tools/testing/selftests/bpf/DENYLIST.s390x
··· 1 1 # TEMPORARY 2 + # Alphabetical order 2 3 atomics # attach(add): actual -524 <= expected 0 (trampoline) 3 - bpf_iter_setsockopt # JIT does not support calling kernel function (kfunc) 4 4 bloom_filter_map # failed to find kernel BTF type ID of '__x64_sys_getpgid': -3 (?) 5 - bpf_tcp_ca # JIT does not support calling kernel function (kfunc) 5 + bpf_cookie # failed to open_and_load program: -524 (trampoline) 6 + bpf_iter_setsockopt # JIT does not support calling kernel function (kfunc) 6 7 bpf_loop # attaches to __x64_sys_nanosleep 7 8 bpf_mod_race # BPF trampoline 8 9 bpf_nf # JIT does not support calling kernel function 10 + bpf_tcp_ca # JIT does not support calling kernel function (kfunc) 11 + cb_refs # expected error message unexpected error: -524 (trampoline) 12 + cgroup_hierarchical_stats # JIT does not support calling kernel function (kfunc) 9 13 core_read_macros # unknown func bpf_probe_read#4 (overlapping) 10 14 d_path # failed to auto-attach program 'prog_stat': -524 (trampoline) 15 + deny_namespace # failed to attach: ERROR: strerror_r(-524)=22 (trampoline) 11 16 dummy_st_ops # test_run unexpected error: -524 (errno 524) (trampoline) 12 17 fentry_fexit # fentry attach failed: -524 (trampoline) 13 18 fentry_test # fentry_first_attach unexpected error: -524 (trampoline) ··· 23 18 get_func_args_test # trampoline 24 19 get_func_ip_test # get_func_ip_test__attach unexpected error: -524 (trampoline) 25 20 get_stack_raw_tp # user_stack corrupted user stack (no backchain userspace) 21 + htab_update # failed to attach: ERROR: strerror_r(-524)=22 (trampoline) 26 22 kfree_skb # attach fentry unexpected error: -524 (trampoline) 27 23 kfunc_call # 'bpf_prog_active': not found in kernel BTF (?) 24 + kfunc_dynptr_param # JIT does not support calling kernel function (kfunc) 25 + kprobe_multi_test # relies on fentry 28 26 ksyms_module # test_ksyms_module__open_and_load unexpected error: -9 (?) 29 27 ksyms_module_libbpf # JIT does not support calling kernel function (kfunc) 30 28 ksyms_module_lskel # test_ksyms_module_lskel__open_and_load unexpected error: -9 (?) 29 + libbpf_get_fd_by_id_opts # failed to attach: ERROR: strerror_r(-524)=22 (trampoline) 30 + lookup_key # JIT does not support calling kernel function (kfunc) 31 + lru_bug # prog 'printk': failed to auto-attach: -524 32 + map_kptr # failed to open_and_load program: -524 (trampoline) 31 33 modify_return # modify_return attach failed: -524 (trampoline) 32 34 module_attach # skel_attach skeleton attach failed: -524 (trampoline) 33 35 mptcp 34 - kprobe_multi_test # relies on fentry 35 36 netcnt # failed to load BPF skeleton 'netcnt_prog': -7 (?) 36 37 probe_user # check_kprobe_res wrong kprobe res from probe read (?) 37 38 recursion # skel_attach unexpected error: -524 (trampoline) 38 39 ringbuf # skel_load skeleton load failed (?) 40 + select_reuseport # intermittently fails on new s390x setup 41 + send_signal # intermittently fails to receive signal 42 + setget_sockopt # attach unexpected error: -524 (trampoline) 39 43 sk_assign # Can't read on server: Invalid argument (?) 40 44 sk_lookup # endianness problem 41 45 sk_storage_tracing # test_sk_storage_tracing__attach unexpected error: -524 (trampoline) ··· 66 52 trace_ext # failed to auto-attach program 'test_pkt_md_access_new': -524 (trampoline) 67 53 trace_printk # trace_printk__load unexpected error: -2 (errno 2) (?) 68 54 trace_vprintk # trace_vprintk__open_and_load unexpected error: -9 (?) 55 + tracing_struct # failed to auto-attach: -524 (trampoline) 69 56 trampoline_count # prog 'prog1': failed to attach: ERROR: strerror_r(-524)=22 (trampoline) 57 + unpriv_bpf_disabled # fentry 58 + user_ringbuf # failed to find kernel BTF type ID of '__s390x_sys_prctl': -3 (?) 70 59 verif_stats # trace_vprintk__open_and_load unexpected error: -9 (?) 60 + verify_pkcs7_sig # JIT does not support calling kernel function (kfunc) 71 61 vmlinux # failed to auto-attach program 'handle__fentry': -524 (trampoline) 72 62 xdp_adjust_tail # case-128 err 0 errno 28 retval 1 size 128 expect-size 3520 (?) 73 63 xdp_bonding # failed to auto-attach program 'trace_on_entry': -524 (trampoline) 74 64 xdp_bpf2bpf # failed to auto-attach program 'trace_on_entry': -524 (trampoline) 75 - map_kptr # failed to open_and_load program: -524 (trampoline) 76 - bpf_cookie # failed to open_and_load program: -524 (trampoline) 77 65 xdp_do_redirect # prog_run_max_size unexpected error: -22 (errno 22) 78 - send_signal # intermittently fails to receive signal 79 - select_reuseport # intermittently fails on new s390x setup 80 66 xdp_synproxy # JIT does not support calling kernel function (kfunc) 81 - unpriv_bpf_disabled # fentry 82 - lru_bug # prog 'printk': failed to auto-attach: -524 83 - setget_sockopt # attach unexpected error: -524 (trampoline) 84 - cb_refs # expected error message unexpected error: -524 (trampoline) 85 - cgroup_hierarchical_stats # JIT does not support calling kernel function (kfunc) 86 - htab_update # failed to attach: ERROR: strerror_r(-524)=22 (trampoline) 87 - tracing_struct # failed to auto-attach: -524 (trampoline) 88 - user_ringbuf # failed to find kernel BTF type ID of '__s390x_sys_prctl': -3 (?) 89 - lookup_key # JIT does not support calling kernel function (kfunc) 90 - verify_pkcs7_sig # JIT does not support calling kernel function (kfunc) 91 - kfunc_dynptr_param # JIT does not support calling kernel function (kfunc)
+6 -5
tools/testing/selftests/bpf/README.rst
··· 14 14 The script tries to ensure that the tests are run with the same environment as they 15 15 would be run post-submit in the CI used by the Maintainers. 16 16 17 - This script downloads a suitable Kconfig and VM userspace image from the system used by 18 - the CI. It builds the kernel (without overwriting your existing Kconfig), recompiles the 19 - bpf selftests, runs them (by default ``tools/testing/selftests/bpf/test_progs``) and 20 - saves the resulting output (by default in ``~/.bpf_selftests``). 17 + This script uses the in-tree kernel configuration and downloads a VM userspace 18 + image from the system used by the CI. It builds the kernel (without overwriting 19 + your existing Kconfig), recompiles the bpf selftests, runs them (by default 20 + ``tools/testing/selftests/bpf/test_progs``) and saves the resulting output (by 21 + default in ``~/.bpf_selftests``). 21 22 22 23 Script dependencies: 23 24 - clang (preferably built from sources, https://github.com/llvm/llvm-project); ··· 27 26 - docutils (for ``rst2man``); 28 27 - libcap-devel. 29 28 30 - For more information on about using the script, run: 29 + For more information about using the script, run: 31 30 32 31 .. code-block:: console 33 32
+8 -13
tools/testing/selftests/bpf/prog_tests/bpf_iter.c
··· 3 3 #include <test_progs.h> 4 4 #include <unistd.h> 5 5 #include <sys/syscall.h> 6 + #include <task_local_storage_helpers.h> 6 7 #include "bpf_iter_ipv6_route.skel.h" 7 8 #include "bpf_iter_netlink.skel.h" 8 9 #include "bpf_iter_bpf_map.skel.h" ··· 176 175 bpf_iter_bpf_map__destroy(skel); 177 176 } 178 177 179 - static int pidfd_open(pid_t pid, unsigned int flags) 180 - { 181 - return syscall(SYS_pidfd_open, pid, flags); 182 - } 183 - 184 178 static void check_bpf_link_info(const struct bpf_program *prog) 185 179 { 186 180 LIBBPF_OPTS(bpf_iter_attach_opts, opts); ··· 291 295 union bpf_iter_link_info linfo; 292 296 int pidfd; 293 297 294 - pidfd = pidfd_open(getpid(), 0); 295 - if (!ASSERT_GT(pidfd, 0, "pidfd_open")) 298 + pidfd = sys_pidfd_open(getpid(), 0); 299 + if (!ASSERT_GT(pidfd, 0, "sys_pidfd_open")) 296 300 return; 297 301 298 302 memset(&linfo, 0, sizeof(linfo)); ··· 1494 1498 static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool one_proc) 1495 1499 { 1496 1500 struct bpf_iter_vma_offset *skel; 1497 - struct bpf_link *link; 1498 1501 char buf[16] = {}; 1499 1502 int iter_fd, len; 1500 1503 int pgsz, shift; ··· 1508 1513 ; 1509 1514 skel->bss->page_shift = shift; 1510 1515 1511 - link = bpf_program__attach_iter(skel->progs.get_vma_offset, opts); 1512 - if (!ASSERT_OK_PTR(link, "attach_iter")) 1513 - return; 1516 + skel->links.get_vma_offset = bpf_program__attach_iter(skel->progs.get_vma_offset, opts); 1517 + if (!ASSERT_OK_PTR(skel->links.get_vma_offset, "attach_iter")) 1518 + goto exit; 1514 1519 1515 - iter_fd = bpf_iter_create(bpf_link__fd(link)); 1520 + iter_fd = bpf_iter_create(bpf_link__fd(skel->links.get_vma_offset)); 1516 1521 if (!ASSERT_GT(iter_fd, 0, "create_iter")) 1517 1522 goto exit; 1518 1523 ··· 1530 1535 close(iter_fd); 1531 1536 1532 1537 exit: 1533 - bpf_link__destroy(link); 1538 + bpf_iter_vma_offset__destroy(skel); 1534 1539 } 1535 1540 1536 1541 static void test_task_vma_offset(void)
+3 -3
tools/testing/selftests/bpf/prog_tests/bpf_nf.c
··· 49 49 50 50 static void test_bpf_nf_ct(int mode) 51 51 { 52 - const char *iptables = "iptables -t raw %s PREROUTING -j CONNMARK --set-mark 42/0"; 52 + const char *iptables = "iptables-legacy -t raw %s PREROUTING -j CONNMARK --set-mark 42/0"; 53 53 int srv_fd = -1, client_fd = -1, srv_client_fd = -1; 54 54 struct sockaddr_in peer_addr = {}; 55 55 struct test_bpf_nf *skel; 56 56 int prog_fd, err; 57 57 socklen_t len; 58 58 u16 srv_port; 59 - char cmd[64]; 59 + char cmd[128]; 60 60 LIBBPF_OPTS(bpf_test_run_opts, topts, 61 61 .data_in = &pkt_v4, 62 62 .data_size_in = sizeof(pkt_v4), ··· 69 69 70 70 /* Enable connection tracking */ 71 71 snprintf(cmd, sizeof(cmd), iptables, "-A"); 72 - if (!ASSERT_OK(system(cmd), "iptables")) 72 + if (!ASSERT_OK(system(cmd), cmd)) 73 73 goto end; 74 74 75 75 srv_port = (mode == TEST_XDP) ? 5005 : 5006;
+14 -12
tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
··· 325 325 static int get_syms(char ***symsp, size_t *cntp) 326 326 { 327 327 size_t cap = 0, cnt = 0, i; 328 - char *name, **syms = NULL; 328 + char *name = NULL, **syms = NULL; 329 329 struct hashmap *map; 330 330 char buf[256]; 331 331 FILE *f; ··· 352 352 /* skip modules */ 353 353 if (strchr(buf, '[')) 354 354 continue; 355 + 356 + free(name); 355 357 if (sscanf(buf, "%ms$*[^\n]\n", &name) != 1) 356 358 continue; 357 359 /* ··· 371 369 if (!strncmp(name, "__ftrace_invalid_address__", 372 370 sizeof("__ftrace_invalid_address__") - 1)) 373 371 continue; 372 + 374 373 err = hashmap__add(map, name, NULL); 375 - if (err) { 376 - free(name); 377 - if (err == -EEXIST) 378 - continue; 374 + if (err == -EEXIST) 375 + continue; 376 + if (err) 379 377 goto error; 380 - } 378 + 381 379 err = libbpf_ensure_mem((void **) &syms, &cap, 382 380 sizeof(*syms), cnt + 1); 383 - if (err) { 384 - free(name); 381 + if (err) 385 382 goto error; 386 - } 387 - syms[cnt] = name; 388 - cnt++; 383 + 384 + syms[cnt++] = name; 385 + name = NULL; 389 386 } 390 387 391 388 *symsp = syms; 392 389 *cntp = cnt; 393 390 394 391 error: 392 + free(name); 395 393 fclose(f); 396 394 hashmap__free(map); 397 395 if (err) { 398 396 for (i = 0; i < cnt; i++) 399 - free(syms[cnt]); 397 + free(syms[i]); 400 398 free(syms); 401 399 } 402 400 return err;
+87
tools/testing/selftests/bpf/prog_tests/libbpf_get_fd_by_id_opts.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + /* 4 + * Copyright (C) 2022 Huawei Technologies Duesseldorf GmbH 5 + * 6 + * Author: Roberto Sassu <roberto.sassu@huawei.com> 7 + */ 8 + 9 + #include <test_progs.h> 10 + 11 + #include "test_libbpf_get_fd_by_id_opts.skel.h" 12 + 13 + void test_libbpf_get_fd_by_id_opts(void) 14 + { 15 + struct test_libbpf_get_fd_by_id_opts *skel; 16 + struct bpf_map_info info_m = {}; 17 + __u32 len = sizeof(info_m), value; 18 + int ret, zero = 0, fd = -1; 19 + LIBBPF_OPTS(bpf_get_fd_by_id_opts, fd_opts_rdonly, 20 + .open_flags = BPF_F_RDONLY, 21 + ); 22 + 23 + skel = test_libbpf_get_fd_by_id_opts__open_and_load(); 24 + if (!ASSERT_OK_PTR(skel, 25 + "test_libbpf_get_fd_by_id_opts__open_and_load")) 26 + return; 27 + 28 + ret = test_libbpf_get_fd_by_id_opts__attach(skel); 29 + if (!ASSERT_OK(ret, "test_libbpf_get_fd_by_id_opts__attach")) 30 + goto close_prog; 31 + 32 + ret = bpf_obj_get_info_by_fd(bpf_map__fd(skel->maps.data_input), 33 + &info_m, &len); 34 + if (!ASSERT_OK(ret, "bpf_obj_get_info_by_fd")) 35 + goto close_prog; 36 + 37 + fd = bpf_map_get_fd_by_id(info_m.id); 38 + if (!ASSERT_LT(fd, 0, "bpf_map_get_fd_by_id")) 39 + goto close_prog; 40 + 41 + fd = bpf_map_get_fd_by_id_opts(info_m.id, NULL); 42 + if (!ASSERT_LT(fd, 0, "bpf_map_get_fd_by_id_opts")) 43 + goto close_prog; 44 + 45 + fd = bpf_map_get_fd_by_id_opts(info_m.id, &fd_opts_rdonly); 46 + if (!ASSERT_GE(fd, 0, "bpf_map_get_fd_by_id_opts")) 47 + goto close_prog; 48 + 49 + /* Map lookup should work with read-only fd. */ 50 + ret = bpf_map_lookup_elem(fd, &zero, &value); 51 + if (!ASSERT_OK(ret, "bpf_map_lookup_elem")) 52 + goto close_prog; 53 + 54 + if (!ASSERT_EQ(value, 0, "map value mismatch")) 55 + goto close_prog; 56 + 57 + /* Map update should not work with read-only fd. */ 58 + ret = bpf_map_update_elem(fd, &zero, &len, BPF_ANY); 59 + if (!ASSERT_LT(ret, 0, "bpf_map_update_elem")) 60 + goto close_prog; 61 + 62 + /* Map update should work with read-write fd. */ 63 + ret = bpf_map_update_elem(bpf_map__fd(skel->maps.data_input), &zero, 64 + &len, BPF_ANY); 65 + if (!ASSERT_OK(ret, "bpf_map_update_elem")) 66 + goto close_prog; 67 + 68 + /* Prog get fd with opts set should not work (no kernel support). */ 69 + ret = bpf_prog_get_fd_by_id_opts(0, &fd_opts_rdonly); 70 + if (!ASSERT_EQ(ret, -EINVAL, "bpf_prog_get_fd_by_id_opts")) 71 + goto close_prog; 72 + 73 + /* Link get fd with opts set should not work (no kernel support). */ 74 + ret = bpf_link_get_fd_by_id_opts(0, &fd_opts_rdonly); 75 + if (!ASSERT_EQ(ret, -EINVAL, "bpf_link_get_fd_by_id_opts")) 76 + goto close_prog; 77 + 78 + /* BTF get fd with opts set should not work (no kernel support). */ 79 + ret = bpf_btf_get_fd_by_id_opts(0, &fd_opts_rdonly); 80 + ASSERT_EQ(ret, -EINVAL, "bpf_btf_get_fd_by_id_opts"); 81 + 82 + close_prog: 83 + if (fd >= 0) 84 + close(fd); 85 + 86 + test_libbpf_get_fd_by_id_opts__destroy(skel); 87 + }
+2 -1
tools/testing/selftests/bpf/prog_tests/map_kptr.c
··· 105 105 ASSERT_OK(opts.retval, "test_map_kptr_ref2 retval"); 106 106 107 107 if (test_run) 108 - return; 108 + goto exit; 109 109 110 110 ret = bpf_map__update_elem(skel->maps.array_map, 111 111 &key, sizeof(key), buf, sizeof(buf), 0); ··· 132 132 ret = bpf_map__delete_elem(skel->maps.lru_hash_map, &key, sizeof(key), 0); 133 133 ASSERT_OK(ret, "lru_hash_map delete"); 134 134 135 + exit: 135 136 map_kptr__destroy(skel); 136 137 } 137 138
+2 -1
tools/testing/selftests/bpf/prog_tests/tracing_struct.c
··· 15 15 16 16 err = tracing_struct__attach(skel); 17 17 if (!ASSERT_OK(err, "tracing_struct__attach")) 18 - return; 18 + goto destroy_skel; 19 19 20 20 ASSERT_OK(trigger_module_test_read(256), "trigger_read"); 21 21 ··· 54 54 ASSERT_EQ(skel->bss->t5_ret, 1, "t5 ret"); 55 55 56 56 tracing_struct__detach(skel); 57 + destroy_skel: 57 58 tracing_struct__destroy(skel); 58 59 } 59 60
+4 -3
tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
··· 18 18 ); 19 19 20 20 err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd); 21 - if (ASSERT_OK(err, "test_xdp_adjust_tail_shrink")) 21 + if (!ASSERT_OK(err, "test_xdp_adjust_tail_shrink")) 22 22 return; 23 23 24 24 err = bpf_prog_test_run_opts(prog_fd, &topts); ··· 53 53 ); 54 54 55 55 err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd); 56 - if (ASSERT_OK(err, "test_xdp_adjust_tail_grow")) 56 + if (!ASSERT_OK(err, "test_xdp_adjust_tail_grow")) 57 57 return; 58 58 59 59 err = bpf_prog_test_run_opts(prog_fd, &topts); ··· 63 63 expect_sz = sizeof(pkt_v6) + 40; /* Test grow with 40 bytes */ 64 64 topts.data_in = &pkt_v6; 65 65 topts.data_size_in = sizeof(pkt_v6); 66 + topts.data_size_out = sizeof(buf); 66 67 err = bpf_prog_test_run_opts(prog_fd, &topts); 67 68 ASSERT_OK(err, "ipv6"); 68 69 ASSERT_EQ(topts.retval, XDP_TX, "ipv6 retval"); ··· 90 89 ); 91 90 92 91 err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd); 93 - if (ASSERT_OK(err, "test_xdp_adjust_tail_grow")) 92 + if (!ASSERT_OK(err, "test_xdp_adjust_tail_grow")) 94 93 return; 95 94 96 95 /* Test case-64 */
+3 -3
tools/testing/selftests/bpf/prog_tests/xdp_synproxy.c
··· 94 94 SYS("sysctl -w net.ipv4.tcp_syncookies=2"); 95 95 SYS("sysctl -w net.ipv4.tcp_timestamps=1"); 96 96 SYS("sysctl -w net.netfilter.nf_conntrack_tcp_loose=0"); 97 - SYS("iptables -t raw -I PREROUTING \ 97 + SYS("iptables-legacy -t raw -I PREROUTING \ 98 98 -i tmp1 -p tcp -m tcp --syn --dport 8080 -j CT --notrack"); 99 - SYS("iptables -t filter -A INPUT \ 99 + SYS("iptables-legacy -t filter -A INPUT \ 100 100 -i tmp1 -p tcp -m tcp --dport 8080 -m state --state INVALID,UNTRACKED \ 101 101 -j SYNPROXY --sack-perm --timestamp --wscale 7 --mss 1460"); 102 - SYS("iptables -t filter -A INPUT \ 102 + SYS("iptables-legacy -t filter -A INPUT \ 103 103 -i tmp1 -m state --state INVALID -j DROP"); 104 104 105 105 ctrl_file = SYS_OUT("./xdp_synproxy --iface tmp1 --ports 8080 \
+9
tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c
··· 102 102 struct zone_padding __pad__; 103 103 }; 104 104 105 + /* ----- START-EXPECTED-OUTPUT ----- */ 106 + struct padding_wo_named_members { 107 + long: 64; 108 + long: 64; 109 + }; 110 + 111 + /* ------ END-EXPECTED-OUTPUT ------ */ 112 + 105 113 int f(struct { 106 114 struct padded_implicitly _1; 107 115 struct padded_explicitly _2; 108 116 struct padded_a_lot _3; 109 117 struct padded_cache_line _4; 110 118 struct zone _5; 119 + struct padding_wo_named_members _6; 111 120 } *_) 112 121 { 113 122 return 0;
+36
tools/testing/selftests/bpf/progs/test_libbpf_get_fd_by_id_opts.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + /* 4 + * Copyright (C) 2022 Huawei Technologies Duesseldorf GmbH 5 + * 6 + * Author: Roberto Sassu <roberto.sassu@huawei.com> 7 + */ 8 + 9 + #include "vmlinux.h" 10 + #include <errno.h> 11 + #include <bpf/bpf_helpers.h> 12 + #include <bpf/bpf_tracing.h> 13 + 14 + /* From include/linux/mm.h. */ 15 + #define FMODE_WRITE 0x2 16 + 17 + struct { 18 + __uint(type, BPF_MAP_TYPE_ARRAY); 19 + __uint(max_entries, 1); 20 + __type(key, __u32); 21 + __type(value, __u32); 22 + } data_input SEC(".maps"); 23 + 24 + char _license[] SEC("license") = "GPL"; 25 + 26 + SEC("lsm/bpf_map") 27 + int BPF_PROG(check_access, struct bpf_map *map, fmode_t fmode) 28 + { 29 + if (map != (struct bpf_map *)&data_input) 30 + return 0; 31 + 32 + if (fmode & FMODE_WRITE) 33 + return -EACCES; 34 + 35 + return 0; 36 + }
+4
tools/testing/selftests/bpf/task_local_storage_helpers.h
··· 7 7 #include <sys/types.h> 8 8 9 9 #ifndef __NR_pidfd_open 10 + #ifdef __alpha__ 11 + #define __NR_pidfd_open 544 12 + #else 10 13 #define __NR_pidfd_open 434 14 + #endif 11 15 #endif 12 16 13 17 static inline int sys_pidfd_open(pid_t pid, unsigned int flags)
+10 -3
tools/testing/selftests/bpf/test_verifier.c
··· 68 68 #define SKIP_INSNS() BPF_RAW_INSN(0xde, 0xa, 0xd, 0xbeef, 0xdeadbeef) 69 69 70 70 #define DEFAULT_LIBBPF_LOG_LEVEL 4 71 - #define VERBOSE_LIBBPF_LOG_LEVEL 1 72 71 73 72 #define F_NEEDS_EFFICIENT_UNALIGNED_ACCESS (1 << 0) 74 73 #define F_LOAD_WITH_STRICT_ALIGNMENT (1 << 1) ··· 80 81 static bool unpriv_disabled = false; 81 82 static int skips; 82 83 static bool verbose = false; 84 + static int verif_log_level = 0; 83 85 84 86 struct kfunc_btf_id_pair { 85 87 const char *kfunc; ··· 759 759 .log_buf = bpf_vlog, 760 760 .log_size = sizeof(bpf_vlog), 761 761 .log_level = (verbose 762 - ? VERBOSE_LIBBPF_LOG_LEVEL 762 + ? verif_log_level 763 763 : DEFAULT_LIBBPF_LOG_LEVEL), 764 764 ); 765 765 ··· 1491 1491 1492 1492 opts.expected_attach_type = test->expected_attach_type; 1493 1493 if (verbose) 1494 - opts.log_level = VERBOSE_LIBBPF_LOG_LEVEL; 1494 + opts.log_level = verif_log_level | 4; /* force stats */ 1495 1495 else if (expected_ret == VERBOSE_ACCEPT) 1496 1496 opts.log_level = 2; 1497 1497 else ··· 1746 1746 if (argc > 1 && strcmp(argv[1], "-v") == 0) { 1747 1747 arg++; 1748 1748 verbose = true; 1749 + verif_log_level = 1; 1750 + argc--; 1751 + } 1752 + if (argc > 1 && strcmp(argv[1], "-vv") == 0) { 1753 + arg++; 1754 + verbose = true; 1755 + verif_log_level = 2; 1749 1756 argc--; 1750 1757 } 1751 1758
+33 -4
tools/testing/selftests/bpf/veristat.c
··· 509 509 return 0; 510 510 } 511 511 512 + static void fixup_obj(struct bpf_object *obj) 513 + { 514 + struct bpf_map *map; 515 + 516 + bpf_object__for_each_map(map, obj) { 517 + /* disable pinning */ 518 + bpf_map__set_pin_path(map, NULL); 519 + 520 + /* fix up map size, if necessary */ 521 + switch (bpf_map__type(map)) { 522 + case BPF_MAP_TYPE_SK_STORAGE: 523 + case BPF_MAP_TYPE_TASK_STORAGE: 524 + case BPF_MAP_TYPE_INODE_STORAGE: 525 + case BPF_MAP_TYPE_CGROUP_STORAGE: 526 + break; 527 + default: 528 + if (bpf_map__max_entries(map) == 0) 529 + bpf_map__set_max_entries(map, 1); 530 + } 531 + } 532 + } 533 + 512 534 static int process_prog(const char *filename, struct bpf_object *obj, struct bpf_program *prog) 513 535 { 514 536 const char *prog_name = bpf_program__name(prog); ··· 564 542 bpf_program__set_log_level(prog, 4); /* only verifier stats */ 565 543 } 566 544 verif_log_buf[0] = '\0'; 545 + 546 + /* increase chances of successful BPF object loading */ 547 + fixup_obj(obj); 567 548 568 549 err = bpf_object__load(obj); 569 550 env.progs_processed++; ··· 1129 1104 else 1130 1105 snprintf(diff_buf, sizeof(diff_buf), "%s", "MISMATCH"); 1131 1106 } else { 1107 + double p = 0.0; 1108 + 1132 1109 snprintf(base_buf, sizeof(base_buf), "%ld", base_val); 1133 1110 snprintf(comp_buf, sizeof(comp_buf), "%ld", comp_val); 1134 1111 1135 1112 diff_val = comp_val - base_val; 1136 1113 if (base == &fallback_stats || comp == &fallback_stats || base_val == 0) { 1137 - snprintf(diff_buf, sizeof(diff_buf), "%+ld (%+.2lf%%)", 1138 - diff_val, comp_val < base_val ? -100.0 : 100.0); 1114 + if (comp_val == base_val) 1115 + p = 0.0; /* avoid +0 (+100%) case */ 1116 + else 1117 + p = comp_val < base_val ? -100.0 : 100.0; 1139 1118 } else { 1140 - snprintf(diff_buf, sizeof(diff_buf), "%+ld (%+.2lf%%)", 1141 - diff_val, diff_val * 100.0 / base_val); 1119 + p = diff_val * 100.0 / base_val; 1142 1120 } 1121 + snprintf(diff_buf, sizeof(diff_buf), "%+ld (%+.2lf%%)", diff_val, p); 1143 1122 } 1144 1123 1145 1124 switch (fmt) {