TencentOS-kernel/kernel/bpf
Yonghong Song bc0d87eda9 bpf: Change uapi for bpf iterator map elements
[upstream commit 5e7b30205cef80f6bb922e61834437ca7bff5837]

Commit a5cbe05a6673 ("bpf: Implement bpf iterator for
map elements") added bpf iterator support for
map elements. The map element bpf iterator requires
info to identify a particular map. In the above
commit, the attr->link_create.target_fd is used
to carry map_fd and an enum bpf_iter_link_info
is added to uapi to specify the target_fd actually
representing a map_fd:
    enum bpf_iter_link_info {
	BPF_ITER_LINK_UNSPEC = 0,
	BPF_ITER_LINK_MAP_FD = 1,

	MAX_BPF_ITER_LINK_INFO,
    };

This is an extensible approach as we can grow
enumerator for pid, cgroup_id, etc. and we can
unionize target_fd for pid, cgroup_id, etc.
But in the future, there are chances that
more complex customization may happen, e.g.,
for tasks, it could be filtered based on
both cgroup_id and user_id.

This patch changed the uapi to have fields
	__aligned_u64	iter_info;
	__u32		iter_info_len;
for additional iter_info for link_create.
The iter_info is defined as
	union bpf_iter_link_info {
		struct {
			__u32   map_fd;
		} map;
	};

So future extension for additional customization
will be easier. The bpf_iter_link_info will be
passed to target callback to validate and generic
bpf_iter framework does not need to deal it any
more.

Note that map_fd = 0 will be considered invalid
and -EBADF will be returned to user space.

Fixes: a5cbe05a6673 ("bpf: Implement bpf iterator for map elements")
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20200805055056.1457463-1-yhs@fb.com
2022-06-21 10:27:15 +08:00
..
Makefile bpf: Add bpf_prog iterator 2022-06-21 10:27:14 +08:00
arraymap.c bpf: Implement bpf iterator for array maps 2022-06-21 10:27:15 +08:00
bpf_iter.c bpf: Change uapi for bpf iterator map elements 2022-06-21 10:27:15 +08:00
bpf_lru_list.c bpf_lru_list: Read double-checked variable once without lock 2021-04-12 12:52:15 +08:00
bpf_lru_list.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
bpf_lsm.c bpf: lsm: Implement attach, detach and execution 2022-06-21 10:27:08 +08:00
bpf_struct_ops.c bpf: Set map_btf_{name, id} for all map types 2022-06-21 10:27:13 +08:00
bpf_struct_ops_types.h bpf: tcp: Support tcp_congestion_ops in bpf 2022-06-21 10:27:05 +08:00
btf.c bpf: Support readonly/readwrite buffers in verifier 2022-06-21 10:27:14 +08:00
cgroup.c bpf, cgroup: Return ENOLINK for auto-detached links on update 2022-06-21 10:27:09 +08:00
core.c bpf: Implement CAP_BPF 2022-06-21 10:27:12 +08:00
cpumap.c bpf: Set map_btf_{name, id} for all map types 2022-06-21 10:27:13 +08:00
devmap.c bpf: Set map_btf_{name, id} for all map types 2022-06-21 10:27:13 +08:00
disasm.c bpf: Introduce BPF nospec instruction for mitigating Spectre v4 2022-06-21 10:27:02 +08:00
disasm.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
dispatcher.c bpf: Introduce BPF dispatcher 2022-06-21 10:27:06 +08:00
hashtab.c bpf: Implement bpf iterator for hash maps 2022-06-21 10:27:14 +08:00
helpers.c bpf: Fix helper bpf_map_peek_elem_proto pointing to wrong callback 2021-03-16 16:44:00 +08:00
inode.c bpf: Create file bpf iterator 2022-06-21 10:27:11 +08:00
local_storage.c bpf: Set map_btf_{name, id} for all map types 2022-06-21 10:27:13 +08:00
lpm_trie.c bpf: Set map_btf_{name, id} for all map types 2022-06-21 10:27:13 +08:00
map_in_map.c bpf: Implement CAP_BPF 2022-06-21 10:27:12 +08:00
map_in_map.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
map_iter.c bpf: Change uapi for bpf iterator map elements 2022-06-21 10:27:15 +08:00
net_namespace.c inet: Run SK_LOOKUP BPF program on socket lookup 2022-06-21 10:27:10 +08:00
offload.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
percpu_freelist.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
percpu_freelist.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
prog_iter.c bpf: Refactor bpf_iter_reg to have separate seq_info member 2022-06-21 10:27:14 +08:00
queue_stack_maps.c bpf: Set map_btf_{name, id} for all map types 2022-06-21 10:27:13 +08:00
reuseport_array.c bpf: Set map_btf_{name, id} for all map types 2022-06-21 10:27:13 +08:00
stackmap.c bpf: Resolve BTF IDs in vmlinux image 2022-06-21 10:27:14 +08:00
syscall.c bpf: Change uapi for bpf iterator map elements 2022-06-21 10:27:15 +08:00
sysfs_btf.c bpf: Fix sysfs export of empty BTF section 2021-03-16 16:37:55 +08:00
task_iter.c bpf: Refactor to provide aux info to bpf_iter_init_seq_priv_t 2022-06-21 10:27:14 +08:00
tnum.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
trampoline.c bpf: lsm: Implement attach, detach and execution 2022-06-21 10:27:08 +08:00
verifier.c bpf: Support readonly/readwrite buffers in verifier 2022-06-21 10:27:14 +08:00
xskmap.c bpf: Set map_btf_{name, id} for all map types 2022-06-21 10:27:13 +08:00