Re: [PATCH bpf-next v11 1/5] bpf: Parameterize task iterators.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Sep 26, 2022 at 11:50 AM Kui-Feng Lee <kuifeng@xxxxxx> wrote:
>
> Allow creating an iterator that loops through resources of one
> thread/process.
>
> People could only create iterators to loop through all resources of
> files, vma, and tasks in the system, even though they were interested
> in only the resources of a specific task or process.  Passing the
> additional parameters, people can now create an iterator to go
> through all resources or only the resources of a task.
>
> Signed-off-by: Kui-Feng Lee <kuifeng@xxxxxx>
> Acked-by: Yonghong Song <yhs@xxxxxx>
> ---
>  include/linux/bpf.h            |  25 +++++
>  include/uapi/linux/bpf.h       |   6 ++
>  kernel/bpf/task_iter.c         | 192 +++++++++++++++++++++++++++++----
>  tools/include/uapi/linux/bpf.h |   6 ++
>  4 files changed, 207 insertions(+), 22 deletions(-)
>

[...]

> +static int bpf_iter_attach_task(struct bpf_prog *prog,
> +                               union bpf_iter_link_info *linfo,
> +                               struct bpf_iter_aux_info *aux)
> +{
> +       unsigned int flags;
> +       struct pid_namespace *ns;
> +       struct pid *pid;
> +       pid_t tgid;
> +
> +       if ((!!linfo->task.tid + !!linfo->task.pid + !!linfo->task.pid_fd) > 1)
> +               return -EINVAL;
> +
> +       aux->task.type = BPF_TASK_ITER_ALL;
> +       if (linfo->task.tid != 0) {
> +               aux->task.type = BPF_TASK_ITER_TID;
> +               aux->task.pid = linfo->task.tid;
> +       }
> +       if (linfo->task.pid != 0) {
> +               aux->task.type = BPF_TASK_ITER_TGID;
> +               aux->task.pid = linfo->task.pid;
> +       }
> +       if (linfo->task.pid_fd != 0) {
> +               aux->task.type = BPF_TASK_ITER_TGID;
> +               ns = task_active_pid_ns(current);
> +               if (IS_ERR(ns))
> +                       return PTR_ERR(ns);

doesn't seem like task_active_pid_ns() can fail (other places in
kernel never handle NULL or IS_ERR for this), so I dropped this IS_ERR
check

> +
> +               pid = pidfd_get_pid(linfo->task.pid_fd, &flags);
> +               if (IS_ERR(pid))
> +                       return PTR_ERR(pid);
> +
> +               tgid = pid_nr_ns(pid, ns);
> +               aux->task.pid = tgid;
> +               put_pid(pid);
> +       }
> +
> +       return 0;
> +}
> +

[...]



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux