All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Gargi Sharma <gs051095@gmail.com>
Cc: linux-kernel@vger.kernel.org, Rik van Riel <riel@surriel.com>,
	Julia Lawall <julia.lawall@lip6.fr>,
	akpm@linux-foundation.org, mingo@kernel.org,
	pasha.tatashin@oracle.com, ktkhai@virtuozzo.com,
	Eric Biederman <ebiederm@xmission.com>
Subject: Re: [PATCH v2 2/2] pid: Remove pidhash
Date: Mon, 2 Oct 2017 17:03:46 +0200	[thread overview]
Message-ID: <20171002150346.GA9481@redhat.com> (raw)
In-Reply-To: <CAOCi2DEyxPcFGRmNMsCSogSV4PLWKukkaVm8G6+9jsy5HwKxFA@mail.gmail.com>

On 09/30, Gargi Sharma wrote:
>
> On Wed, Sep 27, 2017 at 9:58 PM, Oleg Nesterov <oleg@redhat.com> wrote:
> > If I was not clear...
> >
> > in short, after this patch the very first idr_alloc_cyclic() is already
> > wrong. Because, once again, the new not-fully-initialized pid can be found
> > by find_pid_ns().
>
>  If the PIDNS_ADDING check fails, I jump to the flag that performs
>  this
>  while (++i <= ns->level)
>                  idr_remove(&ns->idr, (pid->numbers + i)->nr);
>  So when find_pid_ns() is called, it will not find this pid.

You misunderstood.

OK, to simplify lets forget about namespaces, locking, everything. So after
this patch alloc_pid() roughly does:

	pid = kmem_cache_alloc();

	nr = idr_alloc_cyclic(idr, pid); // lets suppose it returns 1234

	/* WINDOW */

	for (type = 0; type < PIDTYPE_MAX; ++type)
		INIT_HLIST_HEAD(&pid->tasks[type]);


now suppose that in that WINDOW above another CPU does, just for example,
sys_tkill(1234, SIG) which implies find_task_by_vpid(1234) which does
pid_task(find_pid_ns(1234)).

find_pid_ns() returns the non-initialized pid above, because with this
patch it is idr_find() and this pid was already added by idr_alloc_cyclic().

Then pid_task(pid) returns garbage because pid->tasks[] was not initialised yet.

And of course we have the same problems with pid->count/numbers/etc.

See?

> > perhaps you should chane the previous patch to do
> > idr_alloc_cyclic(ptr = NULL) and use idr_replace() in this patch after
> > the PIDNS_HASH_ADDING check.
>
> I'm not sure if I understand this. Do we want to do this to make sure
> the pid namespace is
> initialized before the first process enters into
> the namespace? If yes,

No,

> how does idr_alloc_cyclic(ptr = NULL) help?

In this case find_pid_ns/idr_find will return NULL until we do
idr_replace(idr, pid) when this pid is fully initialized.

Oleg.

  reply	other threads:[~2017-10-02 15:03 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-27  5:06 [PATCH v2 0/2] Replace PID bitmap allocation with IDR API Gargi Sharma
2017-09-27  5:06 ` [PATCH v2 1/2] pid: Replace pid bitmap implementation " Gargi Sharma
2017-09-27 13:09   ` Rik van Riel
2017-09-27 14:06     ` Oleg Nesterov
2017-09-27 15:06       ` Gargi Sharma
2017-09-27 15:15         ` Oleg Nesterov
2017-09-27 15:05     ` Gargi Sharma
2017-09-27 15:05   ` Oleg Nesterov
2017-10-01  9:15   ` Christoph Hellwig
2017-10-01 10:35     ` Gargi Sharma
2017-10-02 13:14       ` Rik van Riel
2017-10-02 13:05     ` Rik van Riel
2017-09-27  5:06 ` [PATCH v2 2/2] pid: Remove pidhash Gargi Sharma
2017-09-27 15:45   ` Oleg Nesterov
2017-09-27 16:28     ` Oleg Nesterov
2017-09-30 15:41       ` Gargi Sharma
2017-10-02 15:03         ` Oleg Nesterov [this message]
2017-10-02 13:35     ` Rik van Riel
2017-10-02 13:45       ` Rik van Riel
2017-10-02 15:21       ` Oleg Nesterov
2017-10-02 15:22         ` Rik van Riel
2017-10-02 16:27           ` Gargi Sharma
2017-09-27 17:18 ` [PATCH v2 0/2] Replace PID bitmap allocation with IDR API Eric W. Biederman
     [not found]   ` <CAOCi2DESqWV2YPcRTe6NYjx6m6N19ewXbAyfLfeBa23kJiEO9Q@mail.gmail.com>
2017-09-28 19:46     ` Rik van Riel
2017-09-28 20:05       ` Gargi Sharma
2017-09-29  0:35         ` Rik van Riel

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=20171002150346.GA9481@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=gs051095@gmail.com \
    --cc=julia.lawall@lip6.fr \
    --cc=ktkhai@virtuozzo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=pasha.tatashin@oracle.com \
    --cc=riel@surriel.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.