linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Brauner <christian.brauner@ubuntu.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Adrian Reber <areber@redhat.com>,
	Eric Biederman <ebiederm@xmission.com>,
	Pavel Emelianov <xemul@virtuozzo.com>,
	Jann Horn <jannh@google.com>,
	Dmitry Safonov <0x7f454c46@gmail.com>,
	linux-kernel@vger.kernel.org, Andrei Vagin <avagin@gmail.com>,
	Mike Rapoport <rppt@linux.ibm.com>,
	Radostin Stoyanov <rstoyanov1@gmail.com>
Subject: Re: [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID
Date: Wed, 7 Aug 2019 20:00:34 +0200	[thread overview]
Message-ID: <20190807180033.lucbhob6wfunp5xf@wittgenstein> (raw)
In-Reply-To: <20190807142609.GC24112@redhat.com>

On Wed, Aug 07, 2019 at 04:26:10PM +0200, Oleg Nesterov wrote:
> On 08/06, Adrian Reber wrote:
> >
> > +struct pid *alloc_pid(struct pid_namespace *ns, int set_tid)
> >  {
> >  	struct pid *pid;
> >  	enum pid_type type;
> > @@ -186,12 +186,35 @@ struct pid *alloc_pid(struct pid_namespace *ns)
> >  		if (idr_get_cursor(&tmp->idr) > RESERVED_PIDS)
> >  			pid_min = RESERVED_PIDS;
> >  
> > -		/*
> > -		 * Store a null pointer so find_pid_ns does not find
> > -		 * a partially initialized PID (see below).
> > -		 */
> > -		nr = idr_alloc_cyclic(&tmp->idr, NULL, pid_min,
> > -				      pid_max, GFP_ATOMIC);
> > +		if (set_tid) {
> > +			/*
> > +			 * Also fail if a PID != 1 is requested
> > +			 * and no PID 1 exists.
> > +			 */
> > +			if ((set_tid >= pid_max) || ((set_tid != 1) &&
> > +				(idr_is_empty(&tmp->idr)))) {
> 
> too many parentheses ;) this is purely cosmetic, up to you, but to me
> 
> 			if (set_tid >= pid_max ||
> 			   (set_tid != 1 && idr_is_empty(&tmp->idr))) {
> 
> looks a bit more readable.
> 
> 
> > +				spin_unlock_irq(&pidmap_lock);
> > +				retval = -EINVAL;
> > +				goto out_free;
> 
> This doesn't look right, you need idr_preload_end() before goto out_free.
> 
> But I'd suggest to simply do
> 
> 			nr = -EINVAL;
> 			if (set_tid < pid_max &&
> 			   (set_tid != 1 || idr_is_empty(&tmp->idr)))
> 				nr = idr_alloc(&tmp->idr, NULL, set_tid,
> 						set_tid + 1, GFP_ATOMIC);
> 
> 			...
> 
> this is more robust.

That all sounds reasonable to me.

  reply	other threads:[~2019-08-07 18:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-06 19:15 [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID Adrian Reber
2019-08-06 19:15 ` [PATCH v3 2/2] selftests: add tests for clone3() Adrian Reber
2019-08-07 14:26 ` [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID Oleg Nesterov
2019-08-07 18:00   ` Christian Brauner [this message]
2019-08-07 15:48 ` Oleg Nesterov
2019-08-07 15:57   ` Dmitry Safonov
2019-08-07 16:21     ` Oleg Nesterov
2019-08-07 16:33       ` Dmitry Safonov
2019-08-07 16:47         ` Dmitry Safonov
2019-08-07 18:20   ` Christian Brauner
2019-08-07 16:08 ` Oleg Nesterov
2019-08-07 18:05   ` Christian Brauner
2019-08-07 17:55 ` Christian Brauner

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=20190807180033.lucbhob6wfunp5xf@wittgenstein \
    --to=christian.brauner@ubuntu.com \
    --cc=0x7f454c46@gmail.com \
    --cc=areber@redhat.com \
    --cc=avagin@gmail.com \
    --cc=ebiederm@xmission.com \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=rppt@linux.ibm.com \
    --cc=rstoyanov1@gmail.com \
    --cc=xemul@virtuozzo.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;
as well as URLs for NNTP newsgroup(s).