Re: [PATCH v3 1/2] pid: Replace pid bitmap implementation with IDR API

From: Rik van Riel
Date: Fri Oct 06 2017 - 15:09:16 EST


On Fri, 2017-10-06 at 07:53 -0400, Gargi Sharma wrote:

> @@ -308,8 +165,28 @@ struct pid *alloc_pid(struct pid_namespace *ns)

The code looks like it addresses all of Oleg's comments now, but the
comments could be a little clearer, IMHO.
Â
> Â tmp = ns;
> Â pid->level = ns->level;
> +
> Â for (i = ns->level; i >= 0; i--) {
> - nr = alloc_pidmap(tmp);
> + int pid_min = 1;
> + idr_preload(GFP_KERNEL);
> + spin_lock_irq(&pidmap_lock);
> +
> + /*
> + Â* init really needs pid 1, but after reaching the
> maximum
> + Â* wrap back to RESERVED_PIDS
> + Â*/
> + if (idr_get_cursor(&tmp->idr) > RESERVED_PIDS)
> + pid_min = RESERVED_PIDS;
> +
> + /*
> + Â* allocate a NULL pointer so that find_pid_ns can't
> + Â* find pid that is not fully initialized
> + Â*/

/*
* 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);
> + spin_unlock_irq(&pidmap_lock);
> + idr_preload_end();
> +
> Â if (nr < 0) {
> Â retval = nr;
> Â goto out_free;
> @@ -339,6 +216,7 @@ struct pid *alloc_pid(struct pid_namespace *ns)
> Â for ( ; upid >= pid->numbers; --upid) {
> Â hlist_add_head_rcu(&upid->pid_chain,
> Â &pid_hash[pid_hashfn(upid->nr, upid-
> >ns)]);

/* Make the PID visible to find_pid_ns. */

> + idr_replace(&upid->ns->idr, pid, upid->nr);
> Â upid->ns->nr_hashed++;
> Â }
> Â spin_unlock_irq(&pidmap_lock);
>

Everything else looks great to me.

Reviewed-by: Rik van Riel <riel@xxxxxxxxxx>

--
All Rights Reversed.

Attachment: signature.asc
Description: This is a digitally signed message part