From: Christian Brauner <brauner@kernel.org>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Mateusz Guzik <mjguzik@gmail.com>,
"Eric W. Biederman" <ebiederm@xmission.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] release_task: kill the no longer needed get/put_pid(thread_pid)
Date: Mon, 14 Apr 2025 21:39:47 +0200 [thread overview]
Message-ID: <20250414-lappalie-abhilfe-eb7810af39bb@brauner> (raw)
In-Reply-To: <20250411121857.GA10550@redhat.com>
On Fri, Apr 11, 2025 at 02:18:57PM +0200, Oleg Nesterov wrote:
> After the commit 7903f907a2260 ("pid: perform free_pid() calls outside
> of tasklist_lock") __unhash_process() -> detach_pid() no longer calls
> free_pid(), proc_flush_pid() can just use p->thread_pid without the
> now pointless get_pid() + put_pid().
>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> ---
> kernel/exit.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/exit.c b/kernel/exit.c
> index 1b51dc099f1e..96d639383f86 100644
> --- a/kernel/exit.c
> +++ b/kernel/exit.c
> @@ -239,7 +239,6 @@ void release_task(struct task_struct *p)
> {
> struct release_task_post post;
> struct task_struct *leader;
> - struct pid *thread_pid;
> int zap_leader;
> repeat:
> memset(&post, 0, sizeof(post));
> @@ -253,8 +252,6 @@ void release_task(struct task_struct *p)
> pidfs_exit(p);
> cgroup_release(p);
>
> - thread_pid = get_pid(p->thread_pid);
> -
> write_lock_irq(&tasklist_lock);
> ptrace_release_task(p);
> __exit_signal(&post, p);
> @@ -282,8 +279,8 @@ void release_task(struct task_struct *p)
> }
>
> write_unlock_irq(&tasklist_lock);
> - proc_flush_pid(thread_pid);
> - put_pid(thread_pid);
> + /* p->thread_pid can't go away until free_pids() below */
> + proc_flush_pid(p->thread_pid);
This cannot work though, right?
Because after __unhash_process() p->thread_pid may be NULL:
__unhash_process()
-> detach_pid()
-> __change_pid()
{
struct pid **pid_ptr, *pid;
pid_ptr = task_pid_ptr(task, type);
*pid_ptr = NULL;
for (tmp = PIDTYPE_MAX; --tmp >= 0; )
if (pid_has_task(pid, tmp)) /* will be false if @group_dead is true
return;
WARN_ON(pids[type]);
pids[type] = pid;
}
so this needs:
diff --git a/kernel/exit.c b/kernel/exit.c
index e6132ebdaed4..9232c4c684e9 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -244,6 +244,7 @@ void release_task(struct task_struct *p)
{
struct release_task_post post;
struct task_struct *leader;
+ struct pid *thread_pid = task_pid(p);
int zap_leader;
repeat:
memset(&post, 0, sizeof(post));
@@ -285,7 +286,7 @@ void release_task(struct task_struct *p)
write_unlock_irq(&tasklist_lock);
/* p->thread_pid can't go away until free_pids() below */
- proc_flush_pid(p->thread_pid);
+ proc_flush_pid(thread_pid);
add_device_randomness(&p->se.sum_exec_runtime,
sizeof(p->se.sum_exec_runtime));
free_pids(post.pids);
I've folded this diff into your patch, Oleg. Let me know if you see any
additional issues with this.
next prev parent reply other threads:[~2025-04-14 19:39 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-11 12:18 Oleg Nesterov
2025-04-11 12:33 ` Mateusz Guzik
2025-04-14 11:42 ` Christian Brauner
2025-04-14 19:39 ` Christian Brauner [this message]
2025-04-14 19:45 ` Christian Brauner
2025-04-14 19:54 ` Mateusz Guzik
2025-04-14 20:45 ` Oleg Nesterov
2025-04-14 21:26 ` Mateusz Guzik
2025-04-15 7:35 ` Christian Brauner
2025-04-15 8:29 ` Mateusz Guzik
2025-04-14 20:39 ` Oleg Nesterov
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=20250414-lappalie-abhilfe-eb7810af39bb@brauner \
--to=brauner@kernel.org \
--cc=Liam.Howlett@oracle.com \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mjguzik@gmail.com \
--cc=oleg@redhat.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
all inboxes | Powered by JetHome®