A new bpf command BPF_ITER_CREATE is added. The anonymous bpf iterator is seq_file based. The seq_file private data are referenced by targets. The bpf_iter infrastructure allocated additional space at seq_file->private before the space used by targets to store some meta data, e.g., prog: prog to run session_id: an unique id for each opened seq_file seq_num: how many times bpf programs are queried in this session done_stop: an internal state to decide whether bpf program should be called in seq_ops->stop() or not The seq_num will start from 0 for valid objects. The bpf program may see the same seq_num more than once if - seq_file buffer overflow happens and the same object is retried by bpf_seq_read(), or - the bpf program explicitly requests a retry of the same object Since module is not supported for bpf_iter, all target registeration happens at __init time, so there is no need to change bpf_iter_unreg_target() as it is used mostly in error path of the init function at which time no bpf iterators have been created yet.
Showing the changes to include/uapi/linux (1 of 5 files). Show all
Unified · Split
| @@ -116,6 +116,7 @@ enum bpf_cmd { · 115 unmodified lines | ||
| 116 | 116 | BPF_LINK_GET_FD_BY_ID, |
| 117 | 117 | BPF_LINK_GET_NEXT_ID, |
| 118 | 118 | BPF_ENABLE_STATS, |
| 119 | + BPF_ITER_CREATE, | |
| 119 | 120 | }; |
| 120 | 121 | |
| 121 | 122 | enum bpf_map_type { |
| @@ -614,6 +615,11 @@ union bpf_attr { · 492 unmodified lines | ||
| 614 | 615 | __u32 type; |
| 615 | 616 | } enable_stats; |
| 616 | 617 | |
| 618 | + struct { /* struct used by BPF_ITER_CREATE command */ | |
| 619 | + __u32 link_fd; | |
| 620 | + __u32 flags; | |
| 621 | + } iter_create; | |
| 622 | + | |
| 617 | 623 | } __attribute__((aligned(8))); |
| 618 | 624 | |
| 619 | 625 | /* The description below is an attempt at providing documentation to eBPF |