Skip to contentSkip to conversation

pidfd: don't do_notify_pidfd() if !thread_group_empty()

PATCH Applied Oleg Nesterov 3 participants 6 messages Jan 27, 2024 – Jan 29, 2024

lore
Share & tools
lore
#0 lore raw

cover pidfd: don't do_notify_pidfd() if !thread_group_empty()

To me this patch makes sense regardless, but also this is another preparation for PIDFD_THREAD change we discuss.

Oleg.

#1 lore raw

do_notify_pidfd() makes no sense until the whole thread group exits, change do_notify_parent() to check thread_group_empty().

This avoids the unnecessary do_notify_pidfd() when tsk is not a leader, or it exits before other threads, or it has a ptraced EXIT_ZOMBIE sub-thread.

---
 kernel/signal.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/signal.c +5 -3
index c9c57d053ce4..9561a3962ca6 100644
@@ -2050,9 +2050,11 @@ bool do_notify_parent(struct task_struct *tsk, int sig)
 
 	WARN_ON_ONCE(!tsk->ptrace &&
 	       (tsk->group_leader != tsk || !thread_group_empty(tsk)));
-
-	/* Wake up all pidfd waiters */
-	do_notify_pidfd(tsk);
+	/*
+	 * tsk is a group leader and has no threads, wake up the pidfd waiters.
+	 */
+	if (thread_group_empty(tsk))
+		do_notify_pidfd(tsk);
 
 	if (sig != SIGCHLD) {
 		/*
Signature · 1 line
2.25.1.362.g51ebf55
Reviewed-by
#2 lore raw
Quoted 7 lines · Oleg Nesterov

do_notify_pidfd() makes no sense until the whole thread group exits, change do_notify_parent() to check thread_group_empty().

This avoids the unnecessary do_notify_pidfd() when tsk is not a leader, or it exits before other threads, or it has a ptraced EXIT_ZOMBIE sub-thread.

Looks good to me, thanks.

Tycho

#3 lore raw
Quoted 5 lines · Tycho Andersen
Quoted 3 lines · Oleg Nesterov

do_notify_pidfd() makes no sense until the whole thread group exits, change do_notify_parent() to check thread_group_empty().

Quoted 8 lines
Quoted 4 lines

This avoids the unnecessary do_notify_pidfd() when tsk is not a leader, or it exits before other threads, or it has a ptraced EXIT_ZOMBIE sub-thread.

Looks good to me, thanks.

Thanks Tycho,

Oleg.

#4 lore raw

PATCH 1/1 pidfd: don't do_notify_pidfd() if !thread_group_empty()

In reply to Oleg Nesterov

do_notify_pidfd() makes no sense until the whole thread group exits, change do_notify_parent() to check thread_group_empty().

This avoids the unnecessary do_notify_pidfd() when tsk is not a leader, or it exits before other threads, or it has a ptraced EXIT_ZOMBIE sub-thread.

---
 kernel/signal.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/signal.c +5 -3
index c9c57d053ce4..9561a3962ca6 100644
@@ -2050,9 +2050,11 @@ bool do_notify_parent(struct task_struct *tsk, int sig)
 
 	WARN_ON_ONCE(!tsk->ptrace &&
 	       (tsk->group_leader != tsk || !thread_group_empty(tsk)));
-
-	/* Wake up all pidfd waiters */
-	do_notify_pidfd(tsk);
+	/*
+	 * tsk is a group leader and has no threads, wake up the pidfd waiters.
+	 */
+	if (thread_group_empty(tsk))
+		do_notify_pidfd(tsk);
 
 	if (sig != SIGCHLD) {
 		/*
Signature · 1 line
2.25.1.362.g51ebf55
#5 lore raw
In reply to Oleg Nesterov
Quoted 5 lines · Oleg Nesterov

To me this patch makes sense regardless, but also this is another preparation for PIDFD_THREAD change we discuss.

Oleg.

Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.misc

[1/1] pidfd: don't do_notify_pidfd() if !thread_group_empty()

      https://git.kernel.org/vfs/vfs/c/e191619dcdca