Re: [PATCH] pid: use READ_ONCE() in pid_alive()
From: Oleg Nesterov
Date: Fri Oct 02 2026 - 08:02:21 EST
On 10/02, Babanpreet Singh wrote:
>
> --- a/include/linux/pid.h
> +++ b/include/linux/pid.h
> @@ -264,7 +264,7 @@ static inline pid_t task_tgid_nr(struct task_struct *tsk)
> */
> static inline int pid_alive(const struct task_struct *p)
> {
> - return p->thread_pid != NULL;
> + return READ_ONCE(p->thread_pid) != NULL;
> }
>
> static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
> diff --git a/kernel/pid.c b/kernel/pid.c
> index 95b8ccfa82690..adf7216067684 100644
> --- a/kernel/pid.c
> +++ b/kernel/pid.c
> @@ -411,7 +411,7 @@ static void __change_pid(struct pid **pids, struct task_struct *task,
> pid = *pid_ptr;
>
> hlist_del_rcu(&task->pid_links[type]);
> - *pid_ptr = new;
> + WRITE_ONCE(*pid_ptr, new);
Acked-by: Oleg Nesterov <oleg@xxxxxxxxxx>