public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Jiayuan Chen" <jiayuan.chen@linux.dev>
To: "Christian Brauner" <brauner@kernel.org>,
	"Oleg Nesterov" <oleg@redhat.com>
Cc: linux-kernel@vger.kernel.org, mrpre@163.com, mkoutny@suse.com,
	syzbot+adcaa842b762a1762e7d@syzkaller.appspotmail.com,
	syzbot+fab52e3459fa2f95df57@syzkaller.appspotmail.com,
	syzbot+0718f65353d72efaac1e@syzkaller.appspotmail.com,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Lorenzo Stoakes" <lorenzo.stoakes@oracle.com>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Wei Yang" <richard.weiyang@gmail.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Al Viro" <viro@zeniv.linux.org.uk>,
	"Mateusz Guzik" <mjguzik@gmail.com>,
	"Joel Granados" <joel.granados@kernel.org>,
	"Jens Axboe" <axboe@kernel.dk>, "Wei Liu" <wei.liu@kernel.org>,
	"Frederic Weisbecker" <frederic@kernel.org>
Subject: Re: [PATCH v1] pid: annotate data-races around pid_ns->pid_allocated
Date: Fri, 25 Apr 2025 05:37:54 +0000	[thread overview]
Message-ID: <ad4137be8f8b14f932e6590355d59618c3fbfc9c@linux.dev> (raw)
In-Reply-To: <20250424-marsch-radio-fb7bf6484c05@brauner>

April 24, 2025 at 17:38, "Christian Brauner" <brauner@kernel.org> wrote:

> 
> On Wed, Apr 23, 2025 at 06:38:18PM +0200, Oleg Nesterov wrote:
> 
> > 
> > On 04/23, Jiayuan Chen wrote:
> > 
> >  April 23, 2025 at 21:51, "Oleg Nesterov" <oleg@redhat.com> wrote:
> > 
> >  >
> > 
> >  > On 04/23, Jiayuan Chen wrote:
> > 
> >  >
> > 
> >  > >
> > 
> >  > > Suppress syzbot reports by annotating these accesses using
> > 
> >  > >
> > 
> >  > > READ_ONCE() / WRITE_ONCE().
> > 
> >  > >
> > 
> >  >
> > 
> >  > ...
> > 
> >  >
> > 
> >  > >
> > 
> >  > > --- a/kernel/pid.c
> > 
> >  > >
> > 
> >  > > +++ b/kernel/pid.c
> > 
> >  > >
> > 
> >  > > @@ -122,7 +122,8 @@ 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) {
> > 
> >  > >
> > 
> >  > > + WRITE_ONCE(ns->pid_allocated, READ_ONCE(ns->pid_allocated) - 1);
> > 
> >  > >
> > 
> >  > > + switch (READ_ONCE(ns->pid_allocated)) {
> > 
> >  > >
> > 
> >  >
> > 
> >  > I keep forgetting how kcsan works, but we don't need
> > 
> >  >
> > 
> >  > READ_ONCE(ns->pid_allocated) under pidmap_lock?
> > 
> >  >
> > 
> >  > Same for other functions which read/modify ->pid_allocated with
> > 
> >  >
> > 
> >  > this lock held.
> > 
> >  >
> > 
> >  > Oleg.
> > 
> >  >
> > 
> >  However, not all places that read/write pid_allocated are locked,
> > 
> >  for example:
> > 
> >  https://web.git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/kernel/pid_namespace.c#n271
> > 
> >  https://web.git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/kernel/fork.c#n2602
> > 
> >  So, in fact, the pidmap_lock is not effective. And if we were to add locks
> > 
> >  to all these places, it would be too heavy.
> > 
> >  
> > 
> >  It seems you misunderstood me. I didn't argue with the lockless READ_ONCE()s
> > 
> >  outside of pidmap_lock.
> > 
> 
> Agreed. We should only add those annotations where they're really
> 
> needed (someone once taught me ;).
>

Thank you for your suggestion, it make sense to me.

      reply	other threads:[~2025-04-25  5:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-23 11:55 [PATCH v1] pid: annotate data-races around pid_ns->pid_allocated Jiayuan Chen
2025-04-23 13:51 ` Oleg Nesterov
2025-04-23 14:33   ` Jiayuan Chen
2025-04-23 16:24     ` Michal Koutný
2025-04-23 16:38     ` Oleg Nesterov
2025-04-24  9:38       ` Christian Brauner
2025-04-25  5:37         ` Jiayuan Chen [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=ad4137be8f8b14f932e6590355d59618c3fbfc9c@linux.dev \
    --to=jiayuan.chen@linux.dev \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=david@redhat.com \
    --cc=frederic@kernel.org \
    --cc=joel.granados@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mjguzik@gmail.com \
    --cc=mkoutny@suse.com \
    --cc=mrpre@163.com \
    --cc=oleg@redhat.com \
    --cc=richard.weiyang@gmail.com \
    --cc=surenb@google.com \
    --cc=syzbot+0718f65353d72efaac1e@syzkaller.appspotmail.com \
    --cc=syzbot+adcaa842b762a1762e7d@syzkaller.appspotmail.com \
    --cc=syzbot+fab52e3459fa2f95df57@syzkaller.appspotmail.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=wei.liu@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