public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue@us.ibm.com>
To: Ben Blum <bblum@google.com>
Cc: linux-kernel@vger.kernel.org,
	containers@lists.linux-foundation.org, akpm@linux-foundation.org,
	lizf@cn.fujitsu.com, menage@google.com
Subject: Re: [PATCH 2/3] Ensures correct concurrent opening/reading of pidlists across pid namespaces
Date: Sat, 11 Jul 2009 16:59:33 -0500	[thread overview]
Message-ID: <20090711215933.GB29503@us.ibm.com> (raw)
In-Reply-To: <20090710230200.16778.89212.stgit@hastromil.mtv.corp.google.com>

Quoting Ben Blum (bblum@google.com):
...
> +static struct cgroup_pidlist *cgroup_pidlist_find(struct cgroup *cgrp,
> +						  enum cgroup_filetype type)
> +{
> +	struct cgroup_pidlist *l;
> +	/* don't need task_nsproxy() if we're looking at ourself */
> +	struct pid_namespace *ns = get_pid_ns(current->nsproxy->pid_ns);
> +	/*
> +	 * We can't drop the pidlist_mutex before taking the l->mutex in case
> +	 * the last ref-holder is trying to remove l from the list at the same
> +	 * time. Holding the pidlist_mutex precludes somebody taking whichever
> +	 * list we find out from under us - compare release_pid_array().
> +	 */
> +	mutex_lock(&cgrp->pidlist_mutex);
> +	list_for_each_entry(l, &cgrp->pidlists, links) {
> +		if (l->key.type == type && l->key.ns == ns) {
> +			/* found a matching list - drop the extra refcount */
> +			put_pid_ns(ns);
> +			/* make sure l doesn't vanish out from under us */
> +			down_write(&l->mutex);
> +			mutex_unlock(&cgrp->pidlist_mutex);
> +			l->use_count++;
> +			return l;
> +		}
> +	}
> +	/* entry not found; create a new one */
> +	l = kmalloc(sizeof(struct cgroup_pidlist), GFP_KERNEL);
> +	if (!l) {
> +		mutex_unlock(&cgrp->pidlist_mutex);

Again, you need to put_pid_ns(ns) here.

> +		return l;
> +	}
> +	init_rwsem(&l->mutex);
> +	down_write(&l->mutex);
> +	l->key.type = type;
> +	l->key.ns = ns;
> +	l->use_count = 0; /* don't increment here */
> +	l->list = NULL;
> +	l->owner = cgrp;
> +	list_add(&l->links, &cgrp->pidlists);
> +	mutex_unlock(&cgrp->pidlist_mutex);
> +	return l;
> +}

  reply	other threads:[~2009-07-11 21:59 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-10 23:01 [PATCH v2 0/3] CGroups: cgroup member list enhancement/fix Ben Blum
2009-07-10 23:01 ` [PATCH 1/3] Adds a read-only "procs" file similar to "tasks" that shows only unique tgids Ben Blum
2009-07-13  3:46   ` Li Zefan
2009-07-13 15:25     ` Benjamin Blum
2009-07-14 18:34   ` Dave Hansen
2009-07-14 21:26     ` Benjamin Blum
2009-07-14 21:49       ` Dave Hansen
2009-07-14 22:55         ` Benjamin Blum
2009-07-15  1:31         ` Li Zefan
2009-07-10 23:02 ` [PATCH 2/3] Ensures correct concurrent opening/reading of pidlists across pid namespaces Ben Blum
2009-07-11 21:59   ` Serge E. Hallyn [this message]
2009-07-10 23:02 ` [PATCH 3/3] Quick vmalloc vs kmalloc fix to the case where array size is too large Ben Blum
2009-07-13  3:03   ` Li Zefan
2009-07-13  6:03     ` KAMEZAWA Hiroyuki
2009-07-13 15:27       ` Benjamin Blum
2009-07-13 23:49         ` KAMEZAWA Hiroyuki
2009-07-14  3:50           ` Paul Menage
2009-07-14  3:53             ` KAMEZAWA Hiroyuki
2009-07-14  4:04               ` Paul Menage
2009-07-14  4:25                 ` KAMEZAWA Hiroyuki
2009-07-14 17:26                   ` Benjamin Blum
2009-07-14 17:28                   ` Paul Menage
2009-07-14 17:47                     ` Dave Hansen
2009-07-14 17:50                       ` Paul Menage
2009-07-14 21:30                         ` Benjamin Blum

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=20090711215933.GB29503@us.ibm.com \
    --to=serue@us.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=bblum@google.com \
    --cc=containers@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=menage@google.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