All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Jiayi Zhang <zhangjiayi1014@gmail.com>
Cc: "Christian Brauner" <brauner@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Pavel Tikhomirov" <ptikhomirov@virtuozzo.com>,
	"Jiayuan Chen" <jiayuan.chen@linux.dev>,
	"Michal Koutný" <mkoutny@suse.com>,
	linux-kernel@vger.kernel.org,
	syzbot+0718f65353d72efaac1e@syzkaller.appspotmail.com,
	syzbot+fab52e3459fa2f95df57@syzkaller.appspotmail.com,
	syzkaller-bugs@googlegroups.com
Subject: Re: [PATCH] pid: use READ_ONCE() and WRITE_ONCE() for pid_namespace::pid_allocated
Date: Thu, 3 Dec 2026 13:00:08 +0100	[thread overview]
Message-ID: <axFZyNmJlxd_sZMM@redhat.com> (raw)
In-Reply-To: <20261202175542.4130656-1-zhangjiayi1014@gmail.com>

On 12/02, Jiayi Zhang wrote:
>
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -2507,7 +2507,7 @@ __latent_entropy struct task_struct *copy_process(
>  	 * child missed SIGKILL.  If current is not in the same namespace,
>  	 * we can't rely on fatal_signal_pending() below.
>  	 */
> -	if (unlikely(!(ns_of_pid(pid)->pid_allocated & PIDNS_ADDING))) {
> +	if (unlikely(!(READ_ONCE(ns_of_pid(pid)->pid_allocated) & PIDNS_ADDING))) {
>  		retval = -ENOMEM;
>  		goto bad_fork_core_free;
>  	}
> diff --git a/kernel/pid.c b/kernel/pid.c
> index adf7216..7b31ec7 100644
> --- a/kernel/pid.c
> +++ b/kernel/pid.c
> @@ -121,7 +121,10 @@ void free_pid(struct pid *pid)
>  	for (i = 0; i <= pid->level; i++) {
>  		struct upid *upid = pid->numbers + i;
>  		struct pid_namespace *ns = upid->ns;
> -		switch (--ns->pid_allocated) {
> +		unsigned int nr_allocated = ns->pid_allocated - 1;
> +
> +		WRITE_ONCE(ns->pid_allocated, nr_allocated);
> +		switch (nr_allocated) {
>  		case 2:
>  		case 1:
>  			/* When all that is left in the pid namespace
> @@ -331,7 +334,8 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *arg_set_tid,
>  	for (upid = pid->numbers + ns->level; upid >= pid->numbers; --upid) {
>  		/* Make the PID visible to find_pid_ns. */
>  		idr_replace(&upid->ns->idr, pid, upid->nr);
> -		upid->ns->pid_allocated++;
> +		WRITE_ONCE(upid->ns->pid_allocated,
> +			   upid->ns->pid_allocated + 1);
>  	}
>  	spin_unlock(&pidmap_lock);
>  	idr_preload_end();
> @@ -363,7 +367,7 @@ out_abort:
>  void disable_pid_allocation(struct pid_namespace *ns)
>  {
>  	spin_lock(&pidmap_lock);
> -	ns->pid_allocated &= ~PIDNS_ADDING;
> +	WRITE_ONCE(ns->pid_allocated, ns->pid_allocated & ~PIDNS_ADDING);
>  	spin_unlock(&pidmap_lock);
>  }
>  
> diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
> index 127a5fd..53b0793 100644
> --- a/kernel/pid_namespace.c
> +++ b/kernel/pid_namespace.c
> @@ -270,7 +270,7 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
>  	 */
>  	for (;;) {
>  		set_current_state(TASK_IDLE | TASK_FREEZABLE);
> -		if (pid_ns->pid_allocated == init_pids)
> +		if (READ_ONCE(pid_ns->pid_allocated) == init_pids)
>  			break;
>  		schedule();
>  	}

Reviewed-by: Oleg Nesterov <oleg@redhat.com>


      parent reply	other threads:[~2026-12-03 12:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 17:55 [PATCH] pid: use READ_ONCE() and WRITE_ONCE() for pid_namespace::pid_allocated Jiayi Zhang
2026-12-03  9:44 ` Pavel Tikhomirov
2026-12-03 12:00 ` Oleg Nesterov [this message]

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=axFZyNmJlxd_sZMM@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=jiayuan.chen@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkoutny@suse.com \
    --cc=ptikhomirov@virtuozzo.com \
    --cc=syzbot+0718f65353d72efaac1e@syzkaller.appspotmail.com \
    --cc=syzbot+fab52e3459fa2f95df57@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=zhangjiayi1014@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.