From: Jonathan Lemon <jonathan.lemon@gmail.com>
To: <netdev@vger.kernel.org>, <ast@kernel.org>,
<daniel@iogearbox.net>, <yhs@fb.com>
Cc: <kernel-team@fb.com>
Subject: [PATCH v2 bpf-next] bpf: increment and use correct thread iterator
Date: Thu, 3 Dec 2020 19:43:02 -0800 [thread overview]
Message-ID: <20201204034302.2123841-1-jonathan.lemon@gmail.com> (raw)
From: Jonathan Lemon <bsd@fb.com>
If unable to obtain the file structure for the current task,
proceed to the next task number after the one returned from
task_seq_get_next(), instead of the next task number from the
original iterator.
Use thread_group_leader() instead of comparing tgid vs pid, which
might may be racy.
Only obtain the task reference count at the end of the RCU section
instead of repeatedly obtaining/releasing it when iterathing though
a thread group.
Fixes: eaaacd23910f ("bpf: Add task and task/file iterator targets")
Fixes: 203d7b054fc7 ("bpf: Avoid iterating duplicated files for task_file iterator")
Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com>
---
kernel/bpf/task_iter.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c
index 0458a40edf10..66a52fcf589a 100644
--- a/kernel/bpf/task_iter.c
+++ b/kernel/bpf/task_iter.c
@@ -33,17 +33,17 @@ static struct task_struct *task_seq_get_next(struct pid_namespace *ns,
pid = find_ge_pid(*tid, ns);
if (pid) {
*tid = pid_nr_ns(pid, ns);
- task = get_pid_task(pid, PIDTYPE_PID);
+ task = pid_task(pid, PIDTYPE_PID);
if (!task) {
++*tid;
goto retry;
- } else if (skip_if_dup_files && task->tgid != task->pid &&
+ } else if (skip_if_dup_files && !thread_group_leader(task) &&
task->files == task->group_leader->files) {
- put_task_struct(task);
task = NULL;
++*tid;
goto retry;
}
+ get_task_struct(task);
}
rcu_read_unlock();
@@ -164,7 +164,7 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info)
curr_files = get_files_struct(curr_task);
if (!curr_files) {
put_task_struct(curr_task);
- curr_tid = ++(info->tid);
+ curr_tid = curr_tid + 1;
info->fd = 0;
goto again;
}
--
2.24.1
next reply other threads:[~2020-12-04 3:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-04 3:43 Jonathan Lemon [this message]
2020-12-04 8:01 ` [PATCH v2 bpf-next] bpf: increment and use correct thread iterator Yonghong Song
2020-12-04 17:14 ` Jonathan Lemon
2020-12-04 18:54 ` Yonghong Song
2020-12-09 19:02 ` Yonghong Song
2020-12-11 16:30 ` Jonathan Lemon
2020-12-14 7:01 ` Yonghong Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201204034302.2123841-1-jonathan.lemon@gmail.com \
--to=jonathan.lemon@gmail.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).