Skip to content

Commit

Permalink
Merge branch 'bpf-task_group_seq_get_next-misc-cleanups'
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Alexei Starovoitov committed Sep 8, 2023
2 parents 35897c3 + 780aa8d commit 9bc8692
Showing 1 changed file with 10 additions and 30 deletions.
40 changes: 10 additions & 30 deletions kernel/bpf/task_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 9bc8692

Please sign in to comment.