From: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
To: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Subject: Re: [PATCH cgroup 1/2] cgroup: move module ref handling into rebind_subsystems()
Date: Fri, 12 Jul 2013 17:08:23 +0800 [thread overview]
Message-ID: <51DFC787.7080703@huawei.com> (raw)
In-Reply-To: <51DFC650.9010801-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
>> Subject: [PATCH 1/2] cgroup: move module ref handling into rebind_subsystems()
>>
>> Module ref handling in cgroup is rather weird.
>> parse_cgroupfs_options() grabs all the modules for the specified
>> subsystems. A module ref is kept if the specified subsystem is newly
>> bound to the hierarchy. If not, or the operation fails, the refs are
>> dropped. This scatters module ref handling across multiple functions
>> making it difficult to track. It also make the function nasty to use
>> for dynamic subsystem binding which is necessary for the planned
>> unified hierarchy.
>>
>> There's nothing which requires the subsystem modules to be pinned
>> between parse_cgroupfs_options() and rebind_subsystems() in both mount
>> and remount paths. parse_cgroupfs_options() can just parse and
>> rebind_subsystems() can handle pinning the subsystems that it wants to
>> bind, which is a natural part of its task - binding - anyway.
>>
>> Move module ref handling into rebind_subsystems() which makes the code
>> a lot simpler - modules are gotten iff it's gonna be bound and put iff
>> unbound or binding fails.
>>
>> Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
>> ---
>> kernel/cgroup.c | 87 +++++++++++++++------------------------------------------
>> 1 file changed, 22 insertions(+), 65 deletions(-)
>>
>> diff --git a/kernel/cgroup.c b/kernel/cgroup.c
>> index 3bc7a1a..a65aff1 100644
>> --- a/kernel/cgroup.c
>> +++ b/kernel/cgroup.c
>> @@ -1003,6 +1003,7 @@ static int rebind_subsystems(struct cgroupfs_root *root,
>> {
>> struct cgroup *cgrp = &root->top_cgroup;
>> struct cgroup_subsys *ss;
>> + unsigned long pinned = 0;
>> int i, ret;
>>
>> BUG_ON(!mutex_is_locked(&cgroup_mutex));
>> @@ -1010,20 +1011,26 @@ static int rebind_subsystems(struct cgroupfs_root *root,
>>
>> /* Check that any added subsystems are currently free */
>> for_each_subsys(ss, i) {
>> - unsigned long bit = 1UL << i;
>> -
>> - if (!(bit & added_mask))
>> + if (!(added_mask & (1 << i)))
>> continue;
>>
>> + /* is the subsystem mounted elsewhere? */
>> if (ss->root != &cgroup_dummy_root) {
>> - /* Subsystem isn't free */
>> - return -EBUSY;
>> + ret = -EBUSY;
>> + goto out_put;
>> }
>> +
>> + /* pin the module */
>> + if (!try_module_get(ss->module)) {
>> + ret = -ENOENT;
>> + goto out_put;
>> + }
>> + pinned |= 1 << i;
>> }
>
> This looks wrong to me.
>
> cgroup_mount()
> {
> mutex_lock(cgroup_mutex);
> parse_cgroupfs_options();
> mutex_unlock(cgroup_mutex);
> ...
>
> mutex_lock(cgroup_mutex);
> ...
> rebind_subsystems();
> ...
> mutex_unlock(cgroup_mutex);
> }
>
> so a modular cgroup subsystem can be unloaded inbetween, say it's net_cls, and
> then it's possible that:
>
> # mount -t cgroup -o net_cls xxx /cgroup
>
> The above operation succeeds but it's not binded to cgroupfs as it just got
> unloaded.
>
for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) {
...
if (!subsys[i] && (added_mask & (1 << i))
return -EINVAL;
...
}
This should work.
next prev parent reply other threads:[~2013-07-12 9:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20130629041231.GA31353@htj.dyndns.org>
[not found] ` <20130629041231.GA31353-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-06-29 4:13 ` [PATCH 2/2] cgroup: remove gratuituous BUG_ON()s from rebind_subsystems() Tejun Heo
2013-07-12 9:03 ` [PATCH cgroup 1/2] cgroup: move module ref handling into rebind_subsystems() Li Zefan
[not found] ` <51DFC650.9010801-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-07-12 9:08 ` Li Zefan [this message]
[not found] ` <51DFC787.7080703-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-07-12 20:10 ` Tejun Heo
2013-07-12 20:38 ` [PATCH v2 " Tejun Heo
[not found] ` <20130712203817.GI23680-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2013-07-15 2:54 ` Li Zefan
[not found] ` <51E3645A.6080404-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-07-16 11:29 ` Tejun Heo
[not found] ` <20130629041305.GB31353@htj.dyndns.org>
[not found] ` <20130629041305.GB31353-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-07-15 2:54 ` [PATCH 2/2] cgroup: remove gratuituous BUG_ON()s from rebind_subsystems() Li Zefan
2013-06-29 4:12 [PATCH cgroup 1/2] cgroup: move module ref handling into rebind_subsystems() Tejun Heo
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=51DFC787.7080703@huawei.com \
--to=lizefan-hv44wf8li93qt0dzr+alfa@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=tj-DgEjT+Ai2ygdnm+yROfE0A@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