From: Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
To: Paul Menage <menage-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
bblum-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
lizf-BthXqXjhjHXBeW8qKU6YJg@public.gmane.org
Subject: Re: [PATCH 2/2] Ensures correct concurrent opening/reading of pidlists across pid namespaces
Date: Thu, 2 Jul 2009 16:54:13 -0700 [thread overview]
Message-ID: <20090702165413.f4a21471.akpm@linux-foundation.org> (raw)
In-Reply-To: <20090702232625.3969.54444.stgit-u3IScbYxn0zHt/MElyovVYaSKrA+ACpX0E9HWUfgJXw@public.gmane.org>
On Thu, 02 Jul 2009 16:26:25 -0700
Paul Menage <menage-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> wrote:
> Ensures correct concurrent opening/reading of pidlists across pid namespaces
>
> Previously there was the problem in which two processes from different pid
> namespaces reading the tasks or procs file could result in one process seeing
> results from the other's namespace. Rather than one pidlist for each file in a
> cgroup, we now keep a list of pidlists keyed by namespace and file type (tasks
> versus procs) in which entries are placed on demand. Each pidlist has its own
> lock, and that the pidlists themselves are passed around in the seq_file's
> private pointer means we don't have to touch the cgroup or its master list
> except when creating and destroying entries.
>
> Signed-off-by: Ben Blum <bblum-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
> Reviewed-by: Paul Menage <menage-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
> Signed-off-by: Paul Menage <menage-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
The way these patches were sent states that you were their primary
author. Is that accurate? If not, they should have had
From: Ben Blum <bblum-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
at the very top of the changelog.
>
> ...
>
> /**
> + * find the appropriate pidlist for our purpose (given procs vs tasks)
> + * returns with the lock on that pidlist already held, and takes care
> + * of the use count, or returns NULL with no locks held if we're out of
> + * memory.
> + */
Comment purports to be kerneldoc, but isn't.
> +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);
> + 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 */
This looks fishy.
> + down_write(&l->mutex);
> + mutex_unlock(&cgrp->pidlist_mutex);
> + l->use_count++;
> + return l;
The caller of cgroup_pidlist_find() must ensure that l->use_count > 0,
otherwise cgroup_pidlist_find() cannot safely use `l' - it could be
freed at any time. But if l->use_count > 0, there is no risk of `l'
"vanishing out from under us".
I'm probably wrong there, but that's the usual pattern and this code
looks like it's doing something different. Please check?
> + }
> + }
> + /* entry not found; create a new one */
> + l = kmalloc(sizeof(struct cgroup_pidlist), GFP_KERNEL);
> + if (!l) {
> + mutex_unlock(&cgrp->pidlist_mutex);
> + 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;
> +}
> +
>
> ...
>
next prev parent reply other threads:[~2009-07-02 23:54 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20090702231814.3969.44308.stgit@menage.mtv.corp.google.com>
[not found] ` <20090702231814.3969.44308.stgit-u3IScbYxn0zHt/MElyovVYaSKrA+ACpX0E9HWUfgJXw@public.gmane.org>
2009-07-02 23:26 ` [PATCH 1/2] Adds a read-only "procs" file similar to "tasks" that shows only unique tgids Paul Menage
[not found] ` <20090702232620.3969.16680.stgit-u3IScbYxn0zHt/MElyovVYaSKrA+ACpX0E9HWUfgJXw@public.gmane.org>
2009-07-02 23:46 ` Andrew Morton
[not found] ` <20090702164649.303c4952.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2009-07-03 0:31 ` Benjamin Blum
[not found] ` <2f86c2480907021731h13e0bb95q94f06829eded9aa6@mail.gmail.com>
[not found] ` <2f86c2480907021731h13e0bb95q94f06829eded9aa6-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-03 0:53 ` Andrew Morton
[not found] ` <20090702175341.fd2e26d5.akpm@linux-foundation.org>
[not found] ` <20090702175341.fd2e26d5.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2009-07-03 1:08 ` Paul Menage
[not found] ` <6599ad830907021808o6f3bb51eh324e4bf13544d83e@mail.gmail.com>
[not found] ` <6599ad830907021808o6f3bb51eh324e4bf13544d83e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-03 1:17 ` Benjamin Blum
2009-07-03 1:30 ` Andrew Morton
[not found] ` <2f86c2480907021817o79fce75yd9785aab682f7bb4@mail.gmail.com>
[not found] ` <2f86c2480907021817o79fce75yd9785aab682f7bb4-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-03 2:08 ` Andrew Morton
2009-07-03 2:25 ` Matt Helsley
[not found] ` <20090703022553.GJ19135@count0.beaverton.ibm.com>
[not found] ` <20090703022553.GJ19135-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2009-07-03 3:49 ` Paul Menage
2009-07-03 7:08 ` Benjamin Blum
[not found] ` <20090702190845.0cafc46a.akpm@linux-foundation.org>
[not found] ` <20090702190845.0cafc46a.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2009-07-03 4:16 ` Paul Menage
[not found] ` <6599ad830907022116n7a711c7fs52ff9b400ec8797f-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-03 6:55 ` Andrew Morton
[not found] ` <20090702235527.7ddc873c.akpm@linux-foundation.org>
[not found] ` <20090702235527.7ddc873c.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2009-07-03 7:54 ` KAMEZAWA Hiroyuki
2009-07-03 16:11 ` Paul Menage
[not found] ` <6599ad830907030911m6176dc59id3a7d897b03d2bd@mail.gmail.com>
[not found] ` <6599ad830907030911m6176dc59id3a7d897b03d2bd-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-03 16:50 ` Andrew Morton
[not found] ` <20090703095000.cf46ad19.akpm@linux-foundation.org>
[not found] ` <20090703095000.cf46ad19.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2009-07-03 17:54 ` Paul Menage
[not found] ` <6599ad830907031054x74d90149y38aae60afa403d58@mail.gmail.com>
[not found] ` <6599ad830907031054x74d90149y38aae60afa403d58-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-03 18:10 ` Andrew Morton
[not found] ` <20090703111016.ceb28541.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2009-07-15 8:33 ` Eric W. Biederman
[not found] ` <m1ocrm73cu.fsf@fess.ebiederm.org>
[not found] ` <m1ocrm73cu.fsf-+imSwln9KH6u2/kzUuoCbdi2O/JbrIOy@public.gmane.org>
2009-07-15 16:18 ` Paul Menage
[not found] ` <20090702183004.1e3f4315.akpm@linux-foundation.org>
[not found] ` <20090702183004.1e3f4315.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2009-07-03 5:54 ` KAMEZAWA Hiroyuki
[not found] ` <20090703145441.f526793f.kamezawa.hiroyu@jp.fujitsu.com>
[not found] ` <20090703145441.f526793f.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2009-07-03 15:52 ` Paul Menage
[not found] ` <6599ad830907030852p2cd667e3m353d68448e0cdc6a@mail.gmail.com>
[not found] ` <6599ad830907030852p2cd667e3m353d68448e0cdc6a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-04 2:07 ` KAMEZAWA Hiroyuki
[not found] ` <3f9558558c68d9e2fe00f7c7681c3764.squirrel-n3SY6/QrmYVJe+uFzlzAcYO9/linGGC/AL8bYrjMMd8@public.gmane.org>
2009-07-04 16:10 ` Paul Menage
[not found] ` <6599ad830907040910k5c9d720bqafdf596bbc005783@mail.gmail.com>
[not found] ` <6599ad830907040910k5c9d720bqafdf596bbc005783-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-05 23:53 ` KAMEZAWA Hiroyuki
2009-07-02 23:26 ` [PATCH 2/2] Ensures correct concurrent opening/reading of pidlists across pid namespaces Paul Menage
[not found] ` <20090702232625.3969.54444.stgit-u3IScbYxn0zHt/MElyovVYaSKrA+ACpX0E9HWUfgJXw@public.gmane.org>
2009-07-02 23:54 ` Andrew Morton [this message]
[not found] ` <20090702165413.f4a21471.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2009-07-03 0:22 ` Paul Menage
[not found] ` <6599ad830907021722x7b012991i1eca056bc72c010c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-03 0:26 ` Paul Menage
2009-07-03 0:43 ` Benjamin Blum
2009-07-03 1:15 ` [PATCH 0/2] CGroups: cgroup member list enhancement/fix Li Zefan
2009-07-05 6:38 ` Balbir Singh
[not found] ` <20090705063850.GX11273@balbir.in.ibm.com>
[not found] ` <20090705063850.GX11273-SINUvgVNF2CyUtPGxGje5AC/G2K4zDHf@public.gmane.org>
2009-07-10 23:58 ` Paul Menage
[not found] ` <6599ad830907101658i13e4046br70377a487dd6b49b@mail.gmail.com>
[not found] ` <6599ad830907101658i13e4046br70377a487dd6b49b-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-13 12:11 ` Balbir Singh
[not found] ` <20090713121138.GC5051@balbir.in.ibm.com>
[not found] ` <20090713121138.GC5051-SINUvgVNF2CyUtPGxGje5AC/G2K4zDHf@public.gmane.org>
2009-07-13 16:26 ` Paul Menage
[not found] ` <6599ad830907130926v7788af12hdcd76e4ccb3ab6de@mail.gmail.com>
[not found] ` <6599ad830907130926v7788af12hdcd76e4ccb3ab6de-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-14 5:56 ` Balbir Singh
[not found] ` <20090714055638.GI5051@balbir.in.ibm.com>
[not found] ` <20090714055638.GI5051-SINUvgVNF2CyUtPGxGje5AC/G2K4zDHf@public.gmane.org>
2009-07-14 6:49 ` Paul Menage
[not found] ` <6599ad830907132349u6cf52060t4fafb6637cbe4ed1@mail.gmail.com>
[not found] ` <6599ad830907132349u6cf52060t4fafb6637cbe4ed1-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-14 7:16 ` Balbir Singh
[not found] ` <20090714071617.GK5051@balbir.in.ibm.com>
[not found] ` <20090714071617.GK5051-SINUvgVNF2CyUtPGxGje5AC/G2K4zDHf@public.gmane.org>
2009-07-14 17:34 ` Benjamin Blum
[not found] ` <2f86c2480907141034r5a985cfue9e8fdf64ad28465@mail.gmail.com>
[not found] ` <2f86c2480907141034r5a985cfue9e8fdf64ad28465-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-14 17:43 ` Paul Menage
[not found] ` <6599ad830907141043s1c16d5c9saad9118c210ecef4@mail.gmail.com>
[not found] ` <6599ad830907141043s1c16d5c9saad9118c210ecef4-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-14 20:38 ` Paul Menage
[not found] ` <6599ad830907141338t794e60admf81807b381c46e41@mail.gmail.com>
[not found] ` <6599ad830907141338t794e60admf81807b381c46e41-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-14 23:08 ` Matt Helsley
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=20090702165413.f4a21471.akpm@linux-foundation.org \
--to=akpm-de/tnxtf+jlsfhdxvbkv3wd2fqjk+8+b@public.gmane.org \
--cc=bblum-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=lizf-BthXqXjhjHXBeW8qKU6YJg@public.gmane.org \
--cc=menage-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.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