]> www.infradead.org Git - users/jedix/linux-maple.git/commit
bpf: Support getting referenced kptr from struct_ops argument
authorAmery Hung <amery.hung@bytedance.com>
Mon, 17 Feb 2025 19:06:37 +0000 (11:06 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 18 Feb 2025 02:47:27 +0000 (18:47 -0800)
commita687df2008f66669deec27f74d1793c8a537a4bd
treee9f39a9635fe5166a01ee1b6b825514f294f353b
parent432051806f614ca512da401b80257b95b2a2241e
bpf: Support getting referenced kptr from struct_ops argument

Allows struct_ops programs to acqurie referenced kptrs from arguments
by directly reading the argument.

The verifier will acquire a reference for struct_ops a argument tagged
with "__ref" in the stub function in the beginning of the main program.
The user will be able to access the referenced kptr directly by reading
the context as long as it has not been released by the program.

This new mechanism to acquire referenced kptr (compared to the existing
"kfunc with KF_ACQUIRE") is introduced for ergonomic and semantic reasons.
In the first use case, Qdisc_ops, an skb is passed to .enqueue in the
first argument. This mechanism provides a natural way for users to get a
referenced kptr in the .enqueue struct_ops programs and makes sure that a
qdisc will always enqueue or drop the skb.

Signed-off-by: Amery Hung <amery.hung@bytedance.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Acked-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20250217190640.1748177-3-ameryhung@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf.h
kernel/bpf/bpf_struct_ops.c
kernel/bpf/btf.c
kernel/bpf/verifier.c