diff options
author | Alexei Starovoitov <ast@kernel.org> | 2023-09-07 18:46:29 +0300 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2023-09-08 18:42:19 +0300 |
commit | 9bc869253d4de75fed388caaeb7626b3ee8ec56c (patch) | |
tree | cd1914df315c0b10386433d457cb011e354b9522 | |
parent | 35897c3c5264469cbd45e44d23c165a08cfb6b3c (diff) | |
parent | 780aa8dfcb73f4703b1c4be11c21c8dca36502ad (diff) | |
download | linux-9bc869253d4de75fed388caaeb7626b3ee8ec56c.tar.xz |
Merge branch 'bpf-task_group_seq_get_next-misc-cleanups'
Oleg Nesterov says:
====================
bpf: task_group_seq_get_next: misc cleanups
Yonghong,
I am resending 1-5 of 6 as you suggested with your acks included.
The next (final) patch will change this code to use __next_thread when
https://lore.kernel.org/all/20230824143142.GA31222@redhat.com/
is merged.
Oleg.
====================
Link: https://lore.kernel.org/r/20230905154612.GA24872@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r-- | kernel/bpf/task_iter.c | 40 |
1 files changed, 10 insertions, 30 deletions
diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c index c4ab9d6cdbe9..7473068ed313 100644 --- a/kernel/bpf/task_iter.c +++ b/kernel/bpf/task_iter.c @@ -35,16 +35,13 @@ static struct task_struct *task_group_seq_get_next(struct bpf_iter_seq_task_comm u32 *tid, bool skip_if_dup_files) { - struct task_struct *task, *next_task; + struct task_struct *task; struct pid *pid; - u32 saved_tid; + u32 next_tid; if (!*tid) { /* The first time, the iterator calls this function. */ pid = find_pid_ns(common->pid, common->ns); - if (!pid) - return NULL; - task = get_pid_task(pid, PIDTYPE_TGID); if (!task) return NULL; @@ -66,44 +63,27 @@ static struct task_struct *task_group_seq_get_next(struct bpf_iter_seq_task_comm return task; } - pid = find_pid_ns(common->pid_visiting, common->ns); - if (!pid) - return NULL; - - task = get_pid_task(pid, PIDTYPE_PID); + task = find_task_by_pid_ns(common->pid_visiting, common->ns); if (!task) return NULL; retry: - if (!pid_alive(task)) { - put_task_struct(task); - return NULL; - } - - next_task = next_thread(task); - put_task_struct(task); - if (!next_task) - return NULL; + task = next_thread(task); - saved_tid = *tid; - *tid = __task_pid_nr_ns(next_task, PIDTYPE_PID, common->ns); - if (!*tid || *tid == common->pid) { + next_tid = __task_pid_nr_ns(task, PIDTYPE_PID, common->ns); + if (!next_tid || next_tid == common->pid) { /* Run out of tasks of a process. The tasks of a * thread_group are linked as circular linked list. */ - *tid = saved_tid; return NULL; } - get_task_struct(next_task); - common->pid_visiting = *tid; - - if (skip_if_dup_files && task->files == task->group_leader->files) { - task = next_task; + if (skip_if_dup_files && task->files == task->group_leader->files) goto retry; - } - return next_task; + *tid = common->pid_visiting = next_tid; + get_task_struct(task); + return task; } static struct task_struct *task_seq_get_next(struct bpf_iter_seq_task_common *common, |