From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Christian Brauner <brauner@kernel.org>,
David Laight <david.laight.linux@gmail.com>,
Mingyu Wang <25181214217@stu.xidian.edu.cn>,
linux-kernel@vger.kernel.org
Subject: [PATCH] pid: document that do_each_pid_task() needs tasklist_lock
Date: Sun, 11 Oct 2026 16:16:51 +0200 [thread overview]
Message-ID: <asuaU8H_5MbO3-cW@redhat.com> (raw)
do_each_pid_task() looks "obviously rcu-safe". This confuses people
and we already have 2 buggy users: send_sigio() and send_sigurg().
The reasons why it is not are not obvious at all, add the comment.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
include/linux/pid.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/include/linux/pid.h b/include/linux/pid.h
index ddaef0bbc8ba..f5476d7140a3 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -187,6 +187,15 @@ static inline pid_t pid_nr(struct pid *pid)
pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
pid_t pid_vnr(struct pid *pid);
+/*
+ * Needs tasklist_lock if type > PIDTYPE_TGID. A lockless reader can:
+ *
+ * - race with a change_pid() that moves the task to another hlist,
+ * and continue to scan the wrong list.
+ *
+ * - race with a copy_process() that adds a new task to the start of hlist,
+ * and miss the new child.
+ */
#define do_each_pid_task(pid, type, task) \
do { \
if ((pid) != NULL) \
--
2.55.0
next reply other threads:[~2026-10-11 14:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-11 14:16 Oleg Nesterov [this message]
2026-10-12 8:40 ` Christian Brauner
2026-10-12 12:54 ` David Laight
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=asuaU8H_5MbO3-cW@redhat.com \
--to=oleg@redhat.com \
--cc=25181214217@stu.xidian.edu.cn \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=david.laight.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®