bpf: Add kfuncs for storing struct task_struct * as a kptr
authorDavid Vernet <void@manifault.com>
Sun, 20 Nov 2022 05:10:03 +0000 (23:10 -0600)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 20 Nov 2022 17:16:21 +0000 (09:16 -0800)
commit90660309b0c76c564a31a21f3a81d6641a9acaa0
treedac6bcbbda3253e99b4a41e9c5c33b62d6adae00
parent3f00c52393445ed49aadc1a567aa502c6333b1a1
bpf: Add kfuncs for storing struct task_struct * as a kptr

Now that BPF supports adding new kernel functions with kfuncs, and
storing kernel objects in maps with kptrs, we can add a set of kfuncs
which allow struct task_struct objects to be stored in maps as
referenced kptrs. The possible use cases for doing this are plentiful.
During tracing, for example, it would be useful to be able to collect
some tasks that performed a certain operation, and then periodically
summarize who they are, which cgroup they're in, how much CPU time
they've utilized, etc.

In order to enable this, this patch adds three new kfuncs:

struct task_struct *bpf_task_acquire(struct task_struct *p);
struct task_struct *bpf_task_kptr_get(struct task_struct **pp);
void bpf_task_release(struct task_struct *p);

A follow-on patch will add selftests validating these kfuncs.

Signed-off-by: David Vernet <void@manifault.com>
Link: https://lore.kernel.org/r/20221120051004.3605026-4-void@manifault.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/helpers.c