bpf: Recognize '__map' suffix in kfunc arguments
authorAlexei Starovoitov <ast@kernel.org>
Thu, 7 Mar 2024 03:12:24 +0000 (19:12 -0800)
committerMartin KaFai Lau <martin.lau@kernel.org>
Thu, 7 Mar 2024 22:58:48 +0000 (14:58 -0800)
commit8d94f1357c00d7706c1f3d0bb568e054cef6aea1
tree862e04056270e16af686d28debe629be4daeba1b
parent88d1d4a7eebea2836859246d91fe9d141789dfc3
bpf: Recognize '__map' suffix in kfunc arguments

Recognize 'void *p__map' kfunc argument as 'struct bpf_map *p__map'.
It allows kfunc to have 'void *' argument for maps, since bpf progs
will call them as:
struct {
        __uint(type, BPF_MAP_TYPE_ARENA);
...
} arena SEC(".maps");

bpf_kfunc_with_map(... &arena ...);

Underneath libbpf will load CONST_PTR_TO_MAP into the register via ld_imm64
insn. If kfunc was defined with 'struct bpf_map *' it would pass the
verifier as well, but bpf prog would need to type cast the argument
(void *)&arena, which is not clean.

Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/r/20240307031228.42896-3-alexei.starovoitov@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
kernel/bpf/verifier.c