bpf: Add bpf_task_from_pid() kfunc
authorDavid Vernet <void@manifault.com>
Tue, 22 Nov 2022 14:52:59 +0000 (08:52 -0600)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 24 Nov 2022 01:45:23 +0000 (17:45 -0800)
commit3f0e6f2b41d35d4446160c745e8f09037447dd8f
treeb175c6182c6108a34cfe5d9eda1218fd17cd0151
parent5bad3587b7a292148cea10185cd8770baaeb7445
bpf: Add bpf_task_from_pid() kfunc

Callers can currently store tasks as kptrs using bpf_task_acquire(),
bpf_task_kptr_get(), and bpf_task_release(). These are useful if a
caller already has a struct task_struct *, but there may be some callers
who only have a pid, and want to look up the associated struct
task_struct * from that to e.g. find task->comm.

This patch therefore adds a new bpf_task_from_pid() kfunc which allows
BPF programs to get a struct task_struct * kptr from a pid.

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