Re: [PATCH v2 1/2] bpf: Add kfuncs for storing struct task_struct * as a kptr

Martin KaFai Lau
2022-10-03T19:21:09Z

On 10/1/22 7:47 AM, David Vernet wrote:
> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> index b069517a3da0..36cbe1b8f8b1 100644
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
> @@ -1700,20 +1700,93 @@ bpf_base_func_proto(enum bpf_func_id func_id)
> }
> }
>
> -BTF_SET8_START(tracing_btf_ids)
> +__diag_push();
> +__diag_ignore_all("-Wmissing-prototypes",
> + "Global functions as their definitions will be in vmlinux BTF");
> +
> +/**
> + * bpf_task_acquire - Acquire a reference to a task. A task acquired by this
> + * kfunc which is not stored in a map as a kptr, must be released by calling
> + * bpf_task_release().
> + * @p: The task on which a reference is being acquired.
> + */
> +__used noinline
> +struct task_struct *bpf_task_acquire(struct task_struct *p)
> +{
> + refcount_inc(&p->rcu_users);

This probably needs to be refcount_inc_not_zero() also for the cases like during
the task free tracepoint ?