Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bpf: Add bpf_task_from_vpid() kfunc

bpf_task_from_pid() that currently exists looks up the
struct task_struct corresponding to the pid in the root pid
namespace (init_pid_ns).

This patch adds bpf_task_from_vpid() which looks up the
struct task_struct corresponding to vpid in the pid namespace
of the current process.

This is useful for getting information about other processes
in the same pid namespace.

Signed-off-by: Juntong Deng <juntong.deng@outlook.com>
Link: https://lore.kernel.org/r/AM6PR03MB5848E50DA58F79CDE65433C399442@AM6PR03MB5848.eurprd03.prod.outlook.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Juntong Deng and committed by
Alexei Starovoitov
675c3596 1477d31b

+20
+20
kernel/bpf/helpers.c
··· 2522 2522 } 2523 2523 2524 2524 /** 2525 + * bpf_task_from_vpid - Find a struct task_struct from its vpid by looking it up 2526 + * in the pid namespace of the current task. If a task is returned, it must 2527 + * either be stored in a map, or released with bpf_task_release(). 2528 + * @vpid: The vpid of the task being looked up. 2529 + */ 2530 + __bpf_kfunc struct task_struct *bpf_task_from_vpid(s32 vpid) 2531 + { 2532 + struct task_struct *p; 2533 + 2534 + rcu_read_lock(); 2535 + p = find_task_by_vpid(vpid); 2536 + if (p) 2537 + p = bpf_task_acquire(p); 2538 + rcu_read_unlock(); 2539 + 2540 + return p; 2541 + } 2542 + 2543 + /** 2525 2544 * bpf_dynptr_slice() - Obtain a read-only pointer to the dynptr data. 2526 2545 * @p: The dynptr whose data slice to retrieve 2527 2546 * @offset: Offset into the dynptr ··· 3053 3034 BTF_ID_FLAGS(func, bpf_task_get_cgroup1, KF_ACQUIRE | KF_RCU | KF_RET_NULL) 3054 3035 #endif 3055 3036 BTF_ID_FLAGS(func, bpf_task_from_pid, KF_ACQUIRE | KF_RET_NULL) 3037 + BTF_ID_FLAGS(func, bpf_task_from_vpid, KF_ACQUIRE | KF_RET_NULL) 3056 3038 BTF_ID_FLAGS(func, bpf_throw) 3057 3039 BTF_KFUNCS_END(generic_btf_ids) 3058 3040