History

bpf: Create anonymous bpf iterator

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.

Yonghong Song committed 6 years ago

Commit ac51d991 parent fd4f12b5 files · +168 −0Browse files

Showing the changes to include/uapi/linux (1 of 5 files). Show all

Unified · Split

include/uapi/linux/bpf.h+6−0
@@ -116,6 +116,7 @@ enum bpf_cmd { · 115 unmodified lines
116116 BPF_LINK_GET_FD_BY_ID,
117117 BPF_LINK_GET_NEXT_ID,
118118 BPF_ENABLE_STATS,
119+ BPF_ITER_CREATE,
119120 };
120121
121122 enum bpf_map_type {
@@ -614,6 +615,11 @@ union bpf_attr { · 492 unmodified lines
614615 __u32 type;
615616 } enable_stats;
616617
618+ struct { /* struct used by BPF_ITER_CREATE command */
619+ __u32 link_fd;
620+ __u32 flags;
621+ } iter_create;
622+
617623 } __attribute__((aligned(8)));
618624
619625 /* The description below is an attempt at providing documentation to eBPF