cgroup: allow ->post_create() to fail
Subsystems (13)
Tejun Heo
maintainerPATCH 1/1 cgroup: allow ->post_create() to fail
Hello,
This became a rather large patchset mostly because there are a lot of weirdities and subtle breakages in create/destroy/load/unload paths. The goal of the patchset is allowing ->post_create() to fail and renaming ->create/post_create/pre_destroy/destroy() to ->css_alloc/css_online/css_offline/css_free().
This patchset contains the following seventeen patches.
0001-cgroup-remove-incorrect-dget-dput-pair-in-cgroup_cre.patch 0002-cgroup-initialize-cgrp-allcg_node-in-init_cgroup_hou.patch 0003-cgroup-open-code-cgroup_create_dir.patch 0004-cgroup-create-directory-before-linking-while-creatin.patch 0005-cgroup-cgroup-dentry-isn-t-a-RCU-pointer.patch 0006-cgroup-remove-duplicate-RCU-free-on-struct-cgroup.patch 0007-cgroup-make-CSS_-flags-bit-masks-instead-of-bit-posi.patch 0008-cgroup-trivial-cleanup-for-cgroup_init-load_subsys.patch 0009-cgroup-lock-cgroup_mutex-in-cgroup_init_subsys.patch 0010-cgroup-fix-harmless-bugs-in-cgroup_load_subsys-fail-.patch 0011-cgroup-separate-out-cgroup_destroy_locked.patch 0012-cgroup-introduce-CSS_ONLINE-flag-and-on-offline_css-.patch 0013-cgroup-simplify-cgroup_load_subsys-failure-path.patch 0014-cgroup-use-mutex_trylock-when-grabbing-i_mutex-of-a-.patch 0015-cgroup-update-cgroup_create-failure-path.patch 0016-cgroup-allow-post_create-to-fail.patch 0017-cgroup-rename-create-post_create-pre_destroy-destroy.patch
0001 is a bugfix. Tagged for -stable. I don't I'll push it through for-3.7-fixes tho. This has been broken forever and nobody reported anything yet.
0002-0011 are various fixes and cleanups to prepare for the following changes. Each should be self-explanatory.
0012-0015 are preparation patches more directly related to allowing failure of ->post_create().
0016 allows ->post_create() to fail.
0017 renames ops and updates documentation.
This patchst is on top of cgroup/for-3.8 and available on the following git branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git review-cgroup-online-may-fail
and contains the following changes.
Documentation/cgroups/cgroups.txt | 49 +++--- block/blk-cgroup.c | 14 - include/linux/cgroup.h | 47 +++--- kernel/cgroup.c | 288 +++++++++++++++++++++----------------- kernel/cgroup_freezer.c | 22 +- kernel/cpuset.c | 10 - kernel/events/core.c | 8 - kernel/sched/core.c | 16 +- mm/hugetlb_cgroup.c | 14 - mm/memcontrol.c | 12 - net/core/netprio_cgroup.c | 8 - net/sched/cls_cgroup.c | 8 - security/device_cgroup.c | 8 - 13 files changed, 278 insertions(+), 226 deletions(-)
Thanks.
--
tejun
Tejun Heo
maintainerPATCH 1/17 cgroup: remove incorrect dget/dput() pair in cgroup_create_dir()
cgroup_create_dir() does weird dancing with dentry refcnt. On success, it gets and then puts it achieving nothing. On failure, it puts but there isn't no matching get anywhere leading to the following oops if cgroup_create_file() fails for whatever reason.
------------[ cut here ]------------ kernel BUG at /work/os/work/fs/dcache.c:552! invalid opcode: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC Modules linked in: CPU 2 Pid: 697, comm: mkdir Not tainted 3.7.0-rc4-work+ #3 Bochs Bochs RIP: 0010:[<ffffffff811d9c0c>] [<ffffffff811d9c0c>] dput+0x1dc/0x1e0 RSP: 0018:ffff88001a3ebef8 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffff88000e5b1ef8 RCX: 0000000000000403 RDX: 0000000000000303 RSI: 2000000000000000 RDI: ffff88000e5b1f58 RBP: ffff88001a3ebf18 R08: ffffffff82c76960 R09: 0000000000000001 R10: ffff880015022080 R11: ffd9bed70f48a041 R12: 00000000ffffffea R13: 0000000000000001 R14: ffff88000e5b1f58 R15: 00007fff57656d60 FS: 00007ff05fcb3800(0000) GS:ffff88001fd00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000004046f0 CR3: 000000001315f000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Process mkdir (pid: 697, threadinfo ffff88001a3ea000, task ffff880015022080) Stack: ffff88001a3ebf48 00000000ffffffea 0000000000000001 0000000000000000 ffff88001a3ebf38 ffffffff811cc889 0000000000000001 ffff88000e5b1ef8 ffff88001a3ebf68 ffffffff811d1fc9 ffff8800198d7f18 ffff880019106ef8 Call Trace: [<ffffffff811cc889>] done_path_create+0x19/0x50 [<ffffffff811d1fc9>] sys_mkdirat+0x59/0x80 [<ffffffff811d2009>] sys_mkdir+0x19/0x20 [<ffffffff81be1e02>] system_call_fastpath+0x16/0x1b Code: 00 48 8d 90 18 01 00 00 48 89 93 c0 00 00 00 4c 89 a0 18 01 00 00 48 8b 83 a0 00 00 00 83 80 28 01 00 00 01 e8 e6 6f a0 00 eb 92 <0f> 0b 66 90 0f 1f 44 00 00 55 48 89 e5 41 57 41 56 49 89 fe 41 RIP [<ffffffff811d9c0c>] dput+0x1dc/0x1e0 RSP <ffff88001a3ebef8> ---[ end trace 1277bcfd9561ddb0 ]---
Fix it by dropping the unnecessary dget/dput() pair.
--- kernel/cgroup.c | 2 -- 1 file changed, 2 deletions(-)
kernel/cgroup.c +0 -2
@@ -2684,9 +2684,7 @@ static int cgroup_create_dir(struct cgroup *cgrp, struct dentry *dentry, dentry->d_fsdata = cgrp;inc_nlink (parent->d_inode);rcu_assign_pointer (cgrp->dentry, dentry); -dget (dentry); } -dput (dentry);return error; }
Signature · 1 line
1.7.11.7
Re: [PATCH 01/17] cgroup: remove incorrect dget/dput() pair in cgroup_create_dir()
Quoted 51 lines · Tejun Heo
cgroup_create_dir()does weird dancing with dentry refcnt. On success, it gets and then puts it achieving nothing. On failure, it puts but there isn't no matching get anywhere leading to the following oops ifcgroup_create_file()fails for whatever reason.------------[ cut here ]------------ kernel BUG at /work/os/work/fs/dcache.c:552! invalid opcode: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC Modules linked in: CPU 2 Pid: 697, comm: mkdir Not tainted 3.7.0-rc4-work+ #3 Bochs Bochs RIP: 0010:[<ffffffff811d9c0c>] [<ffffffff811d9c0c>] dput+0x1dc/0x1e0 RSP: 0018:ffff88001a3ebef8 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffff88000e5b1ef8 RCX: 0000000000000403 RDX: 0000000000000303 RSI: 2000000000000000 RDI: ffff88000e5b1f58 RBP: ffff88001a3ebf18 R08: ffffffff82c76960 R09: 0000000000000001 R10: ffff880015022080 R11: ffd9bed70f48a041 R12: 00000000ffffffea R13: 0000000000000001 R14: ffff88000e5b1f58 R15: 00007fff57656d60 FS: 00007ff05fcb3800(0000) GS:ffff88001fd00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000004046f0 CR3: 000000001315f000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Process mkdir (pid: 697, threadinfo ffff88001a3ea000, task ffff880015022080) Stack: ffff88001a3ebf48 00000000ffffffea 0000000000000001 0000000000000000 ffff88001a3ebf38 ffffffff811cc889 0000000000000001 ffff88000e5b1ef8 ffff88001a3ebf68 ffffffff811d1fc9 ffff8800198d7f18 ffff880019106ef8 Call Trace: [<ffffffff811cc889>] done_path_create+0x19/0x50 [<ffffffff811d1fc9>] sys_mkdirat+0x59/0x80 [<ffffffff811d2009>] sys_mkdir+0x19/0x20 [<ffffffff81be1e02>] system_call_fastpath+0x16/0x1b Code: 00 48 8d 90 18 01 00 00 48 89 93 c0 00 00 00 4c 89 a0 18 01 00 00 48 8b 83 a0 00 00 00 83 80 28 01 00 00 01 e8 e6 6f a0 00 eb 92 <0f> 0b 66 90 0f 1f 44 00 00 55 48 89 e5 41 57 41 56 49 89 fe 41 RIP [<ffffffff811d9c0c>] dput+0x1dc/0x1e0 RSP <ffff88001a3ebef8> ---[ end trace 1277bcfd9561ddb0 ]---Fix it by dropping the unnecessary dget/dput() pair.
Signed-off-by Tejun Heo <[email protected]>--- kernel/cgroup.c | 2 -- 1 file changed, 2 deletions(-)kernel/cgroup.c +0
-0
kernel/cgroup.c static int cgroup_create_dir(struct cgroup *cgrp, struct dentry *dentry, · line 2688
Quoted 7 lines
kernel/cgroup.c +0
-2@@ -2684,9 +2684,7 @@ static int cgroup_create_dir(struct cgroup *cgrp, struct dentry *dentry, dentry->d_fsdata = cgrp;inc_nlink (parent->d_inode);rcu_assign_pointer (cgrp->dentry, dentry); -dget (dentry); } -dput (dentry);
The code has been there since cgroup was merged into mainline!
Quoted 3 lines
kernel/cgroup.c +0
-0return error; }
Tejun Heo
maintainerRe: [PATCH 01/17] cgroup: remove incorrect dget/dput() pair in cgroup_create_dir()
Quoted 6 lines · Li Zefan
Quoted 6 lines
kernel/cgroup.c +0
-0@@ -2684,9 +2684,7 @@ static int cgroup_create_dir(struct cgroup *cgrp, struct dentry *dentry, dentry->d_fsdata = cgrp;
Quoted 8 lines
kernel/cgroup.c static int cgroup_create_dir(struct cgroup *cgrp, struct dentry *dentry, · line 2688
Quoted 6 lines
kernel/cgroup.c +0
-2inc_nlink (parent->d_inode);rcu_assign_pointer (cgrp->dentry, dentry); -dget (dentry); } -dput (dentry);The code has been there since cgroup was merged into mainline!
I know. Sometimes it's scary how many latent bugs we have in the kernel and how long many of them have been around. At other times, it's comforting. I mean, there's a pretty good chance that other people don't notice my screw ups, right? :P
Signature · 1 line
tejun
A message that is not in the archive (sent off-list or not yet received): 1352775704-9023-2-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
Re: [PATCH 01/17] cgroup: remove incorrect dget/dput() pair in cgroup_create_dir()
Quoted 51 lines · Tejun Heo
cgroup_create_dir()does weird dancing with dentry refcnt. On success, it gets and then puts it achieving nothing. On failure, it puts but there isn't no matching get anywhere leading to the following oops ifcgroup_create_file()fails for whatever reason.------------[ cut here ]------------ kernel BUG at /work/os/work/fs/dcache.c:552! invalid opcode: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC Modules linked in: CPU 2 Pid: 697, comm: mkdir Not tainted 3.7.0-rc4-work+ #3 Bochs Bochs RIP: 0010:[<ffffffff811d9c0c>] [<ffffffff811d9c0c>] dput+0x1dc/0x1e0 RSP: 0018:ffff88001a3ebef8 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffff88000e5b1ef8 RCX: 0000000000000403 RDX: 0000000000000303 RSI: 2000000000000000 RDI: ffff88000e5b1f58 RBP: ffff88001a3ebf18 R08: ffffffff82c76960 R09: 0000000000000001 R10: ffff880015022080 R11: ffd9bed70f48a041 R12: 00000000ffffffea R13: 0000000000000001 R14: ffff88000e5b1f58 R15: 00007fff57656d60 FS: 00007ff05fcb3800(0000) GS:ffff88001fd00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000004046f0 CR3: 000000001315f000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Process mkdir (pid: 697, threadinfo ffff88001a3ea000, task ffff880015022080) Stack: ffff88001a3ebf48 00000000ffffffea 0000000000000001 0000000000000000 ffff88001a3ebf38 ffffffff811cc889 0000000000000001 ffff88000e5b1ef8 ffff88001a3ebf68 ffffffff811d1fc9 ffff8800198d7f18 ffff880019106ef8 Call Trace: [<ffffffff811cc889>] done_path_create+0x19/0x50 [<ffffffff811d1fc9>] sys_mkdirat+0x59/0x80 [<ffffffff811d2009>] sys_mkdir+0x19/0x20 [<ffffffff81be1e02>] system_call_fastpath+0x16/0x1b Code: 00 48 8d 90 18 01 00 00 48 89 93 c0 00 00 00 4c 89 a0 18 01 00 00 48 8b 83 a0 00 00 00 83 80 28 01 00 00 01 e8 e6 6f a0 00 eb 92 <0f> 0b 66 90 0f 1f 44 00 00 55 48 89 e5 41 57 41 56 49 89 fe 41 RIP [<ffffffff811d9c0c>] dput+0x1dc/0x1e0 RSP <ffff88001a3ebef8> ---[ end trace 1277bcfd9561ddb0 ]---Fix it by dropping the unnecessary dget/dput() pair.
Signed-off-by Tejun Heo <[email protected]>--- kernel/cgroup.c | 2 -- 1 file changed, 2 deletions(-)kernel/cgroup.c +0
-0
kernel/cgroup.c static int cgroup_create_dir(struct cgroup *cgrp, struct dentry *dentry, · line 2688
Quoted 7 lines
kernel/cgroup.c +0
-2@@ -2684,9 +2684,7 @@ static int cgroup_create_dir(struct cgroup *cgrp, struct dentry *dentry, dentry->d_fsdata = cgrp;inc_nlink (parent->d_inode);rcu_assign_pointer (cgrp->dentry, dentry); -dget (dentry); } -dput (dentry);
The code has been there since cgroup was merged into mainline!
Quoted 3 lines
kernel/cgroup.c +0
-0return error; }
Tejun Heo
maintainerPATCH 2/17 cgroup: initialize cgrp->allcg_node in init_cgroup_housekeeping()
In reply to Tejun HeoNot strictly necessary but it's annoying to have uninitialized list_head around.
--- kernel/cgroup.c | 1 + 1 file changed, 1 insertion(+)
kernel/cgroup.c +1 -0
@@ -1381,6 +1381,7 @@ static void init_cgroup_housekeeping(struct cgroup *cgrp)INIT_LIST_HEAD (&cgrp->children);INIT_LIST_HEAD (&cgrp->files);INIT_LIST_HEAD (&cgrp->css_sets); +INIT_LIST_HEAD (&cgrp->allcg_node);INIT_LIST_HEAD (&cgrp->release_list);INIT_LIST_HEAD (&cgrp->pidlists);mutex_init (&cgrp->pidlist_mutex);
Signature · 1 line
1.7.11.7
Tejun Heo
maintainerPATCH 3/17 cgroup: open-code cgroup_create_dir()
In reply to Tejun HeoThe operation order of cgroup creation is about to change and cgroup_create_dir() is more of a hindrance than a proper abstraction. Open-code it by moving the parent nlink adjustment next to self nlink adjustment in cgroup_create_file() and the rest to cgroup_create().
This patch doesn't introduce any behavior change.
--- kernel/cgroup.c | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-)
kernel/cgroup.c +5 -25
@@ -2652,6 +2652,7 @@ static int cgroup_create_file(struct dentry *dentry, umode_t mode,/* start off with i_nlink == 2 (for "." entry) */ inc_nlink (inode); +inc_nlink (dentry->d_parent->d_inode);/* start with the directory inode held, so that we can * populate it without racing with another mkdir */
@@ -2666,30 +2667,6 @@ static int cgroup_create_file(struct dentry *dentry, umode_t mode,return 0 ; } -/* -* cgroup_create_dir - create a directory for an object. -* @cgrp: the cgroup we create the directory for. It must have a valid -* ->parent field. And we are going to fill its ->dentry field. -* @dentry: dentry of the new cgroup -* @mode: mode to set on new directory. -*/ -static int cgroup_create_dir (struct cgroup *cgrp,struct dentry *dentry, -umode_t mode) -{ -struct dentry *parent; -int error =0 ; - - parent = cgrp->parent->dentry; - error =cgroup_create_file (dentry,S_IFDIR | mode, cgrp->root->sb); -if (!error) { - dentry->d_fsdata = cgrp; -inc_nlink (parent->d_inode); -rcu_assign_pointer (cgrp->dentry, dentry); - } - -return error; -} -/** * cgroup_file_mode - deduce file mode of a control file * @cft: the control file in question
@@ -4138,10 +4115,13 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,list_add_tail_rcu (&cgrp->sibling, &cgrp->parent->children); root->number_of_cgroups++; - err =cgroup_create_dir (cgrp, dentry, mode); + err =cgroup_create_file (dentry,S_IFDIR | mode, sb);if (err <0 ) goto err_remove; + dentry->d_fsdata = cgrp; +rcu_assign_pointer (cgrp->dentry, dentry); +for_each_subsys (root, ss) {/* each css holds a ref to the cgroup's dentry */ dget (dentry);
Signature · 1 line
1.7.11.7
Tejun Heo
maintainerPATCH 4/17 cgroup: create directory before linking while creating a new cgroup
In reply to Tejun HeoWhile creating a new cgroup, cgroup_create() links the newly allocated cgroup into various places before trying to create its directory. Because cgroup life-cycle is tied to the vfs objects, this makes it impossible to use cgroup_rmdir() for rolling back creation - the removal logic depends on having full vfs objects.
This patch moves directory creation above linking and collect linking operations to one place. This allows directory creation failure to share error exit path with css allocation failures and any failure sites afterwards (to be added later) can use cgroup_rmdir() logic to undo creation.
It also removes the need to check whether cgroup->dentry is %NULL in cgroup_path. If a cgroup is visible, its dentry is guaranteed to be visible too.
Note that this also makes the memory barriers around cgroup->dentry, which currently is misleadingly using RCU operations, unnecessary. This will be handled in the next patch.
While at it, locking BUG_ON() on i_mutex is converted to lockdep_assert_held().
--- kernel/cgroup.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-)
kernel/cgroup.c +13 -19
@@ -1760,7 +1760,7 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)struct dentry *dentry =rcu_dereference_check (cgrp->dentry,cgroup_lock_is_held ()); -if (!dentry || cgrp == dummytop) { +if (cgrp == dummytop) {/* * Inactive subsystems have no dentry for their root * cgroup
@@ -4112,15 +4112,22 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, } } -list_add_tail_rcu (&cgrp->sibling, &cgrp->parent->children); - root->number_of_cgroups++; - +/* +* Create directory. cgroup_create_file() returns with the new +* directory locked on success so that it can be populated without +* dropping cgroup_mutex. +*/ err =cgroup_create_file (dentry,S_IFDIR | mode, sb);if (err <0 ) - goto err_remove; + goto err_destroy; +lockdep_assert_held (&dentry->d_inode->i_mutex); +/* allocation complete, commit to creation */ dentry->d_fsdata = cgrp;rcu_assign_pointer (cgrp->dentry, dentry); +list_add_tail (&cgrp->allcg_node, &root->allcg_list); +list_add_tail_rcu (&cgrp->sibling, &cgrp->parent->children); + root->number_of_cgroups++;for_each_subsys (root, ss) {/* each css holds a ref to the cgroup's dentry */
@@ -4131,11 +4138,6 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, ss->post_create (cgrp); } -/* The cgroup directory was pre-locked for us */ -BUG_ON (!mutex_is_locked (&cgrp->dentry->d_inode->i_mutex)); - -list_add_tail (&cgrp->allcg_node, &root->allcg_list); - err =cgroup_populate_dir (cgrp, true, root->subsys_mask);/* If err < 0, we have a half-filled directory - oh well ;) */
@@ -4144,20 +4146,12 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,return 0 ; - err_remove: - -list_del_rcu (&cgrp->sibling); - root->number_of_cgroups--; - - err_destroy: - +err_destroy:for_each_subsys (root, ss) {if (cgrp->subsys[ss->subsys_id]) ss->destroy (cgrp); } -mutex_unlock (&cgroup_mutex); -/* Release the reference count that we took on the superblock */ deactivate_super (sb); err_free:
Signature · 1 line
1.7.11.7
Re: [PATCH 04/17] cgroup: create directory before linking while creating a new cgroup
Quoted 13 lines · Tejun Heo
While creating a new cgroup,
cgroup_create()links the newly allocated cgroup into various places before trying to create its directory. Because cgroup life-cycle is tied to the vfs objects, this makes it impossible to usecgroup_rmdir()for rolling back creation - the removal logic depends on having full vfs objects.This patch moves directory creation above linking and collect linking operations to one place. This allows directory creation failure to share error exit path with css allocation failures and any failure sites afterwards (to be added later) can use
cgroup_rmdir()logic to undo creation.
Quoted 4 lines
It also removes the need to check whether
cgroup->dentryis %NULL incgroup_path. If a cgroup is visible, its dentry is guaranteed to be visible too.
I'm afraid this isn't safe.
The cgroup is visible to a controller soon after ss->create(), and then the controller might call cgroup_path() while cgrp->dentry is still NULL.
This can happen for cpu cgroup I think, and in fact the NULL check was added for this reason IIRC.
Quoted 11 lines
Note that this also makes the memory barriers around
cgroup->dentry, which currently is misleadingly using RCU operations, unnecessary. This will be handled in the next patch.While at it, locking
BUG_ON()oni_mutexis converted tolockdep_assert_held().Signed-off-by Tejun Heo <[email protected]>--- kernel/cgroup.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-)
Tejun Heo
maintainerRe: [PATCH 04/17] cgroup: create directory before linking while creating a new cgroup
Hello, Li.
Quoted 8 lines · Li Zefan
Quoted 3 lines
It also removes the need to check whether
cgroup->dentryis %NULL incgroup_path. If a cgroup is visible, its dentry is guaranteed to be visible too.I'm afraid this isn't safe.
The cgroup is visible to a controller soon after
ss->create(), and then the controller might callcgroup_path()whilecgrp->dentryis still NULL.
Hmmm... I can't find any case where ss->create() is calling cgroup_path(). Do you remember which one that was?
Quoted 2 lines
This can happen for cpu cgroup I think, and in fact the NULL check was added for this reason IIRC.
Then, I think we better move the dentry assignment further up. It's really silly to be unable to answer "what's this new cgroup's name?" for any callback really. Will update accordingly.
Thanks.
Signature · 1 line
tejun
Re: [PATCH 04/17] cgroup: create directory before linking while creating a new cgroup
Quoted 7 lines · Tejun Heo
Hello, Li.
Quoted 4 lines · Li Zefan
Quoted 3 lines
It also removes the need to check whether
cgroup->dentryis %NULL incgroup_path. If a cgroup is visible, its dentry is guaranteed to be visible too.
Quoted 8 lines
Quoted 4 lines
I'm afraid this isn't safe.
The cgroup is visible to a controller soon after
ss->create(), and then the controller might callcgroup_path()whilecgrp->dentryis still NULL.Hmmm... I can't find any case where
ss->create()is callingcgroup_path(). Do you remember which one that was?
I meant cgroup_create() may race with cgroup_path(). We used to have this race:
(cpu0) (cpu1)
mkdir cat /proc/sched_debug
cgroup_create()
cpu_cgroup_create()
register_fair_sched_group()
list_add_rcu(...)
print_cfs_stats()
for_each_leaf_cfs_rq()
print_cfs_rq()
cgroup_path() css->cgroup = cgroup;
cgroup->dentry = dentry;
In this case, cgroup_path() might access NULL cgroup or NULL dentry.
But I've looked the current scheduler code, no race anymore, because now the cfs_rq won't be added to the gloal list until there's task in the cgroup. (in the old time it was added to the list when creating a cgroup)
A message that is not in the archive (sent off-list or not yet received): 20121114190407.GI21185-9pTldWuhBndy/[email protected]
Re: [PATCH 04/17] cgroup: create directory before linking while creating a new cgroup
Quoted 7 lines · Tejun Heo
Hello, Li.
Quoted 4 lines · Li Zefan
Quoted 3 lines
It also removes the need to check whether
cgroup->dentryis %NULL incgroup_path. If a cgroup is visible, its dentry is guaranteed to be visible too.
Quoted 8 lines
Quoted 4 lines
I'm afraid this isn't safe.
The cgroup is visible to a controller soon after
ss->create(), and then the controller might callcgroup_path()whilecgrp->dentryis still NULL.Hmmm... I can't find any case where
ss->create()is callingcgroup_path(). Do you remember which one that was?
I meant cgroup_create() may race with cgroup_path(). We used to have this race:
(cpu0) (cpu1)
mkdir cat /proc/sched_debug
cgroup_create()
cpu_cgroup_create()
register_fair_sched_group()
list_add_rcu(...)
print_cfs_stats()
for_each_leaf_cfs_rq()
print_cfs_rq()
cgroup_path() css->cgroup = cgroup;
cgroup->dentry = dentry;
In this case, cgroup_path() might access NULL cgroup or NULL dentry.
But I've looked the current scheduler code, no race anymore, because now the cfs_rq won't be added to the gloal list until there's task in the cgroup. (in the old time it was added to the list when creating a cgroup)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 04/17] cgroup: create directory before linking while creating a new cgroup
Hello, Li.
Quoted 8 lines · Li Zefan
Quoted 3 lines
It also removes the need to check whether
cgroup->dentryis %NULL incgroup_path. If a cgroup is visible, its dentry is guaranteed to be visible too.I'm afraid this isn't safe.
The cgroup is visible to a controller soon after
ss->create(), and then the controller might callcgroup_path()whilecgrp->dentryis still NULL.
Hmmm... I can't find any case where ss->create() is calling cgroup_path(). Do you remember which one that was?
Quoted 2 lines
This can happen for cpu cgroup I think, and in fact the NULL check was added for this reason IIRC.
Then, I think we better move the dentry assignment further up. It's really silly to be unable to answer "what's this new cgroup's name?" for any callback really. Will update accordingly.
Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerPATCH v2 4/17 cgroup: create directory before linking while creating a new cgroup
In reply to Tejun HeoWhile creating a new cgroup, cgroup_create() links the newly allocated cgroup into various places before trying to create its directory. Because cgroup life-cycle is tied to the vfs objects, this makes it impossible to use cgroup_rmdir() for rolling back creation - the removal logic depends on having full vfs objects.
This patch moves directory creation above linking and collect linking operations to one place. This allows directory creation failure to share error exit path with css allocation failures and any failure sites afterwards (to be added later) can use cgroup_rmdir() logic to undo creation.
Note that this also makes the memory barriers around cgroup->dentry, which currently is misleadingly using RCU operations, unnecessary. This will be handled in the next patch.
While at it, locking BUG_ON() on i_mutex is converted to lockdep_assert_held().
v2: Patch originally removed %NULL dentry check in cgroup_path();
however, Li pointed out that this patch doesn't make it unnecessary as ->create() may call cgroup_path(). Drop the change for now.
--- kernel/cgroup.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-)
kernel/cgroup.c +12 -18
@@ -4112,15 +4112,22 @@ static long cgroup_create(struct cgroup } } -list_add_tail_rcu (&cgrp->sibling, &cgrp->parent->children); - root->number_of_cgroups++; - +/* +* Create directory. cgroup_create_file() returns with the new +* directory locked on success so that it can be populated without +* dropping cgroup_mutex. +*/ err =cgroup_create_file (dentry,S_IFDIR | mode, sb);if (err <0 ) - goto err_remove; + goto err_destroy; +lockdep_assert_held (&dentry->d_inode->i_mutex); +/* allocation complete, commit to creation */ dentry->d_fsdata = cgrp;rcu_assign_pointer (cgrp->dentry, dentry); +list_add_tail (&cgrp->allcg_node, &root->allcg_list); +list_add_tail_rcu (&cgrp->sibling, &cgrp->parent->children); + root->number_of_cgroups++;for_each_subsys (root, ss) {/* each css holds a ref to the cgroup's dentry */
@@ -4131,11 +4138,6 @@ static long cgroup_create(struct cgroup ss->post_create (cgrp); } -/* The cgroup directory was pre-locked for us */ -BUG_ON (!mutex_is_locked (&cgrp->dentry->d_inode->i_mutex)); - -list_add_tail (&cgrp->allcg_node, &root->allcg_list); - err =cgroup_populate_dir (cgrp, true, root->subsys_mask);/* If err < 0, we have a half-filled directory - oh well ;) */
@@ -4144,20 +4146,12 @@ static long cgroup_create(struct cgroupreturn 0 ; - err_remove: - -list_del_rcu (&cgrp->sibling); - root->number_of_cgroups--; - - err_destroy: - +err_destroy:for_each_subsys (root, ss) {if (cgrp->subsys[ss->subsys_id]) ss->destroy (cgrp); } -mutex_unlock (&cgroup_mutex); -/* Release the reference count that we took on the superblock */ deactivate_super (sb); err_free:
A message that is not in the archive (sent off-list or not yet received): 1352775704-9023-5-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
PATCH v2 4/17 cgroup: create directory before linking while creating a new cgroup
While creating a new cgroup, cgroup_create() links the newly allocated cgroup into various places before trying to create its directory. Because cgroup life-cycle is tied to the vfs objects, this makes it impossible to use cgroup_rmdir() for rolling back creation - the removal logic depends on having full vfs objects.
This patch moves directory creation above linking and collect linking operations to one place. This allows directory creation failure to share error exit path with css allocation failures and any failure sites afterwards (to be added later) can use cgroup_rmdir() logic to undo creation.
Note that this also makes the memory barriers around cgroup->dentry, which currently is misleadingly using RCU operations, unnecessary. This will be handled in the next patch.
While at it, locking BUG_ON() on i_mutex is converted to lockdep_assert_held().
v2: Patch originally removed %NULL dentry check in cgroup_path();
however, Li pointed out that this patch doesn't make it unnecessary as ->create() may call cgroup_path(). Drop the change for now.
--- kernel/cgroup.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-)
kernel/cgroup.c +12 -18
@@ -4112,15 +4112,22 @@ static long cgroup_create(struct cgroup } } -list_add_tail_rcu (&cgrp->sibling, &cgrp->parent->children); - root->number_of_cgroups++; - +/* +* Create directory. cgroup_create_file() returns with the new +* directory locked on success so that it can be populated without +* dropping cgroup_mutex. +*/ err =cgroup_create_file (dentry,S_IFDIR | mode, sb);if (err <0 ) - goto err_remove; + goto err_destroy; +lockdep_assert_held (&dentry->d_inode->i_mutex); +/* allocation complete, commit to creation */ dentry->d_fsdata = cgrp;rcu_assign_pointer (cgrp->dentry, dentry); +list_add_tail (&cgrp->allcg_node, &root->allcg_list); +list_add_tail_rcu (&cgrp->sibling, &cgrp->parent->children); + root->number_of_cgroups++;for_each_subsys (root, ss) {/* each css holds a ref to the cgroup's dentry */
@@ -4131,11 +4138,6 @@ static long cgroup_create(struct cgroup ss->post_create (cgrp); } -/* The cgroup directory was pre-locked for us */ -BUG_ON (!mutex_is_locked (&cgrp->dentry->d_inode->i_mutex)); - -list_add_tail (&cgrp->allcg_node, &root->allcg_list); - err =cgroup_populate_dir (cgrp, true, root->subsys_mask);/* If err < 0, we have a half-filled directory - oh well ;) */
@@ -4144,20 +4146,12 @@ static long cgroup_create(struct cgroupreturn 0 ; - err_remove: - -list_del_rcu (&cgrp->sibling); - root->number_of_cgroups--; - - err_destroy: - +err_destroy:for_each_subsys (root, ss) {if (cgrp->subsys[ss->subsys_id]) ss->destroy (cgrp); } -mutex_unlock (&cgroup_mutex); -/* Release the reference count that we took on the superblock */ deactivate_super (sb); err_free:
Tejun Heo
maintainerPATCH 5/17 cgroup: cgroup->dentry isn't a RCU pointer
In reply to Tejun Heocgroup->dentry is marked and used as a RCU pointer; however, it isn't one - the final dentry put doesn't go through call_rcu(). cgroup and dentry share the same RCU freeing rule via synchronize_rcu() in cgroup_diput() (kfree_rcu() used on cgrp is unnecessary). If cgrp is accessible under RCU read lock, so is its dentry and dereferencing cgrp->dentry doesn't need any further RCU protection or annotation.
While not being accurate, before the previous patch, the RCU accessors served a purpose as memory barriers - cgroup->dentry used to be assigned after the cgroup was made visible to cgroup_path(), so the assignment and dereferencing in cgroup_path() needed the memory barrier pair. Now that list_add_tail_rcu() happens after cgroup->dentry is assigned, this no longer is necessary.
Remove the now unnecessary and misleading RCU annotations from cgroup->dentry. To make up for the removal of rcu_dereference_check() in cgroup_path(), add an explicit rcu_lockdep_assert(), which asserts the dereference rule of @cgrp, not cgrp->dentry.
--- include/linux/cgroup.h | 2 +- kernel/cgroup.c | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-)
include/linux/cgroup.h +1 -1
@@ -165,7 +165,7 @@ struct cgroup {struct list_head files;/* my files */ struct cgroup *parent;/* my parent */ -struct dentry __rcu *dentry;/* cgroup fs entry, RCU protected */ +struct dentry *dentry;/* cgroup fs entry, RCU protected */ /* Private pointers for each registered subsystem */ struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT ];
kernel/cgroup.c +6 -5
@@ -1756,9 +1756,11 @@ static struct kobject *cgroup_kobj;*/ int cgroup_path (const struct cgroup *cgrp,char *buf,int buflen) { +struct dentry *dentry = cgrp->dentry;char *start; -struct dentry *dentry =rcu_dereference_check (cgrp->dentry, -cgroup_lock_is_held ()); + +rcu_lockdep_assert (rcu_read_lock_held () ||cgroup_lock_is_held (), +"cgroup_path() called without proper locking" );if (cgrp == dummytop) {/*
@@ -1782,8 +1784,7 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)if (!cgrp)break ; - dentry =rcu_dereference_check (cgrp->dentry, -cgroup_lock_is_held ()); + dentry = cgrp->dentry;if (!cgrp->parent)continue ;if (--start < buf)
@@ -4124,7 +4125,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,/* allocation complete, commit to creation */ dentry->d_fsdata = cgrp; -rcu_assign_pointer (cgrp->dentry, dentry); + cgrp->dentry = dentry;list_add_tail (&cgrp->allcg_node, &root->allcg_list);list_add_tail_rcu (&cgrp->sibling, &cgrp->parent->children); root->number_of_cgroups++;
Signature · 1 line
1.7.11.7
Re: [PATCH 05/17] cgroup: cgroup->dentry isn't a RCU pointer
Quoted 14 lines · Tejun Heo
cgroup->dentryis marked and used as a RCU pointer; however, it isn't one - the final dentry put doesn't go throughcall_rcu(). cgroup and dentry share the same RCU freeing rule viasynchronize_rcu()incgroup_diput()(kfree_rcu()used on cgrp is unnecessary). If cgrp is accessible under RCU read lock, so is its dentry and dereferencingcgrp->dentrydoesn't need any further RCU protection or annotation.While not being accurate, before the previous patch, the RCU accessors served a purpose as memory barriers -
cgroup->dentryused to be assigned after the cgroup was made visible tocgroup_path(), so the assignment and dereferencing incgroup_path()needed the memory barrier pair. Now thatlist_add_tail_rcu()happens aftercgroup->dentryis assigned, this no longer is necessary.
Quoted 5 lines
Remove the now unnecessary and misleading RCU annotations from
cgroup->dentry. To make up for the removal ofrcu_dereference_check()incgroup_path(), add an explicitrcu_lockdep_assert(), which asserts the dereference rule of @cgrp, notcgrp->dentry.
Will memcontrol.c need similar amendments?
The code that lives in -mm and includes kmemcg includes the following excerpt:
rcu_read_lock();
dentry = rcu_dereference(memcg->css.cgroup->dentry);
rcu_read_unlock();Tejun Heo
maintainerRe: [PATCH 05/17] cgroup: cgroup->dentry isn't a RCU pointer
Hello, Glauber.
Quoted 8 lines · Glauber Costa
Will
memcontrol.cneed similar amendments?The code that lives in -mm and includes kmemcg includes the following excerpt:
rcu_read_lock(); dentry = rcu_dereference(memcg->css.cgroup->dentry); rcu_read_unlock();
Ooh, yeah, hmmm... that should happen after this series gets merged. I'll mark it as pending.
Thanks.
Signature · 1 line
tejun
Re: [PATCH 05/17] cgroup: cgroup->dentry isn't a RCU pointer
Quoted 8 lines · Tejun Heo
Hello, Glauber.
Quoted 5 lines · Glauber Costa
Will
memcontrol.cneed similar amendments?The code that lives in -mm and includes kmemcg includes the following excerpt:
Quoted 9 lines
Quoted 3 lines
rcu_read_lock(); dentry = rcu_dereference(memcg->css.cgroup->dentry); rcu_read_unlock();Ooh, yeah, hmmm... that should happen after this series gets merged. I'll mark it as pending.
Thanks.
Btw: I did this because there is no other facility to figure out a memcg's "name".
I wonder if there is anyone else using this, so we could just abstract that in cgroup.c?
Tejun Heo
maintainerRe: [PATCH 05/17] cgroup: cgroup->dentry isn't a RCU pointer
Hello, Glauber.
Quoted 8 lines · Glauber Costa
Quoted 3 lines
Ooh, yeah, hmmm... that should happen after this series gets merged. I'll mark it as pending.
Btw: I did this because there is no other facility to figure out a memcg's "name".
I wonder if there is anyone else using this, so we could just abstract that in
cgroup.c?
We have cgroup_path() after all, so I don't think it's crazy to have cgroup_name(). Please feel free to add.
Thanks.
Signature · 1 line
tejun
A message that is not in the archive (sent off-list or not yet received): 20121114185504.GG21185-9pTldWuhBndy/[email protected]
Re: [PATCH 05/17] cgroup: cgroup->dentry isn't a RCU pointer
Quoted 8 lines · Tejun Heo
Hello, Glauber.
Quoted 5 lines · Glauber Costa
Will
memcontrol.cneed similar amendments?The code that lives in -mm and includes kmemcg includes the following excerpt:
Quoted 9 lines
Quoted 3 lines
rcu_read_lock(); dentry = rcu_dereference(memcg->css.cgroup->dentry); rcu_read_unlock();Ooh, yeah, hmmm... that should happen after this series gets merged. I'll mark it as pending.
Thanks.
Btw: I did this because there is no other facility to figure out a memcg's "name".
I wonder if there is anyone else using this, so we could just abstract that in cgroup.c?
A message that is not in the archive (sent off-list or not yet received): 1352775704-9023-6-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
Re: [PATCH 05/17] cgroup: cgroup->dentry isn't a RCU pointer
Quoted 14 lines · Tejun Heo
cgroup->dentryis marked and used as a RCU pointer; however, it isn't one - the final dentry put doesn't go throughcall_rcu(). cgroup and dentry share the same RCU freeing rule viasynchronize_rcu()incgroup_diput()(kfree_rcu()used on cgrp is unnecessary). If cgrp is accessible under RCU read lock, so is its dentry and dereferencingcgrp->dentrydoesn't need any further RCU protection or annotation.While not being accurate, before the previous patch, the RCU accessors served a purpose as memory barriers -
cgroup->dentryused to be assigned after the cgroup was made visible tocgroup_path(), so the assignment and dereferencing incgroup_path()needed the memory barrier pair. Now thatlist_add_tail_rcu()happens aftercgroup->dentryis assigned, this no longer is necessary.
Quoted 5 lines
Remove the now unnecessary and misleading RCU annotations from
cgroup->dentry. To make up for the removal ofrcu_dereference_check()incgroup_path(), add an explicitrcu_lockdep_assert(), which asserts the dereference rule of @cgrp, notcgrp->dentry.
Will memcontrol.c need similar amendments?
The code that lives in -mm and includes kmemcg includes the following excerpt:
rcu_read_lock();
dentry = rcu_dereference(memcg->css.cgroup->dentry);
rcu_read_unlock();Tejun Heo
maintainerPATCH 6/17 cgroup: remove duplicate RCU free on struct cgroup
In reply to Tejun Heostruct cgroup is made RCU-safe by synchronize_rcu() in cgroup_diput(). There is no reason to use RCU safe kfree on it after it. Remove cgroup->rcu_head and use kfree() instead of kfree_rcu() in cgroup_diput().
--- include/linux/cgroup.h | 3 --- kernel/cgroup.c | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-)
include/linux/cgroup.h +0 -3
@@ -196,9 +196,6 @@ struct cgroup {struct list_head pidlists;struct mutex pidlist_mutex; -/* For RCU-protected deletion */ -struct rcu_head rcu_head; -/* List of events which userspace want to receive */ struct list_head event_list;spinlock_t event_list_lock;
kernel/cgroup.c +1 -1
@@ -893,7 +893,7 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode)simple_xattrs_free (&cgrp->xattrs); -kfree_rcu (cgrp, rcu_head); +kfree (cgrp); }else {struct cfent *cfe =__d_cfe (dentry);struct cgroup *cgrp = dentry->d_parent->d_fsdata;
Signature · 1 line
1.7.11.7
Re: [PATCH 06/17] cgroup: remove duplicate RCU free on struct cgroup
Quoted 1 line · Tejun Heo
struct cgroup is made RCU-safe by
synchronize_rcu()incgroup_diput().
but synchronize_rcu() is called before ss->destroy().
rcu_read_lock();for_each_leaf_cfs_rq(cpu_rq(cpu), cfs_rq)
print_cfs_rq(m, cpu, cfs_rq); -> call cgroup_path(task_group->css.cgroup);
rcu_read_unlock();
With this patch, if the above code race with cgroup_diput(), we might end up accessing a cgroup which has been freed.
Quoted 29 lines
There is no reason to use RCU safe kfree on it after it. Remove
cgroup->rcu_headand usekfree()instead ofkfree_rcu()incgroup_diput().Signed-off-by Tejun Heo <[email protected]>--- include/linux/cgroup.h | 3 --- kernel/cgroup.c | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-)include/linux/cgroup.h +0
-3@@ -196,9 +196,6 @@ struct cgroup {struct list_head pidlists;struct mutex pidlist_mutex; -/* For RCU-protected deletion */ -struct rcu_head rcu_head; -/* List of events which userspace want to receive */ struct list_head event_list;spinlock_t event_list_lock;kernel/cgroup.c +0
-0
kernel/cgroup.c static void cgroup_diput(struct dentry *dentry, struct inode *inode) · line 896
Quoted 5 lines
kernel/cgroup.c +1
-1@@ -893,7 +893,7 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode)simple_xattrs_free (&cgrp->xattrs); -kfree_rcu (cgrp, rcu_head); +kfree (cgrp);
This was also added to prevent a race in group scheduling code, and I think the race still exists.
Quoted 4 lines
kernel/cgroup.c +0
-0}else {struct cfent *cfe =__d_cfe (dentry);struct cgroup *cgrp = dentry->d_parent->d_fsdata;
Tejun Heo
maintainerRe: [PATCH 06/17] cgroup: remove duplicate RCU free on struct cgroup
Hello, Li.
Quoted 5 lines · Li Zefan
Quoted 1 line · Tejun Heo
struct cgroup is made RCU-safe by
synchronize_rcu()incgroup_diput().but
synchronize_rcu()is called beforess->destroy().
Quoted 8 lines
rcu_read_lock();for_each_leaf_cfs_rq(cpu_rq(cpu), cfs_rq)print_cfs_rq(m, cpu, cfs_rq); -> call cgroup_path(task_group->css.cgroup);
rcu_read_unlock();With this patch, if the above code race with
cgroup_diput(), we might end up accessing a cgroup which has been freed.
Ah, okay. So, the problem here is that sched is using ->css_free() as a de-registration point rather than freeing and may end up walking it after ->css_free() is complete inside RCU period.
I think the correct solution is using ->css_offline() for that. It's ugly to require double RCU grace periods.
Quoted 6 lines
Quoted 6 lines
kernel/cgroup.c +0
-0@@ -893,7 +893,7 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode)
Quoted 7 lines
kernel/cgroup.c static void cgroup_diput(struct dentry *dentry, struct inode *inode) · line 896
Quoted 4 lines
kernel/cgroup.c +1
-1simple_xattrs_free (&cgrp->xattrs); -kfree_rcu (cgrp, rcu_head); +kfree (cgrp);This was also added to prevent a race in group scheduling code, and I think the race still exists.
Care to point out which one? I don't think the double-RCU workaround is a good idea. We really should sort it out by following object lifecycle rules consistently.
Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerPATCH 7/17 cgroup: make CSS_* flags bit masks instead of bit positions
In reply to Tejun HeoCurrently, CSS_* flags are defined as bit positions and manipulated using atomic bitops. There's no reason to use atomic bitops for them and bit positions are clunkier to deal with than bit masks. Make CSS_* bit masks instead and use the usual C bitwise operators to access them.
--- include/linux/cgroup.h | 8 ++++---- kernel/cgroup.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
include/linux/cgroup.h +4 -4
@@ -81,7 +81,7 @@ struct cgroup_subsys_state {/* bits in struct cgroup_subsys_state flags field */ enum { -CSS_ROOT ,/* This CSS is the root of the subsystem */ +CSS_ROOT = (1 <<0 ),/* this CSS is the root of the subsystem */ };/* Caller must verify that the css is not for root cgroup */
@@ -100,7 +100,7 @@ static inline void __css_get(struct cgroup_subsys_state *css, int count)static inline void css_get (struct cgroup_subsys_state *css) {/* We don't need to reference count the root state */ -if (!test_bit (CSS_ROOT , &css->flags)) +if (!(css->flags &CSS_ROOT ))__css_get (css,1 ); }
@@ -113,7 +113,7 @@ static inline void css_get(struct cgroup_subsys_state *css)extern bool __css_tryget (struct cgroup_subsys_state *css);static inline bool css_tryget (struct cgroup_subsys_state *css) { -if (test_bit (CSS_ROOT , &css->flags)) +if (css->flags &CSS_ROOT )return true;return __css_tryget (css); }
@@ -126,7 +126,7 @@ static inline bool css_tryget(struct cgroup_subsys_state *css)extern void __css_put (struct cgroup_subsys_state *css);static inline void css_put (struct cgroup_subsys_state *css) { -if (!test_bit (CSS_ROOT , &css->flags)) +if (!(css->flags &CSS_ROOT ))__css_put (css); }
kernel/cgroup.c +1 -1
@@ -4020,7 +4020,7 @@ static void init_cgroup_css(struct cgroup_subsys_state *css, css->flags =0 ; css->id =NULL ;if (cgrp == dummytop) -set_bit (CSS_ROOT , &css->flags); + css->flags |=CSS_ROOT ;BUG_ON (cgrp->subsys[ss->subsys_id]); cgrp->subsys[ss->subsys_id] = css;
Signature · 1 line
1.7.11.7
Tejun Heo
maintainerPATCH 8/17 cgroup: trivial cleanup for cgroup_init/load_subsys()
In reply to Tejun HeoConsistently use @css and @dummytop in these two functions instead of referring to them indirectly.
--- kernel/cgroup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/cgroup.c +3 -3
@@ -4332,7 +4332,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)* pointer to this state - since the subsystem is * newly registered, all tasks and hence the * init_css_set is in the subsystem's top cgroup. */ - init_css_set.subsys[ss->subsys_id] = dummytop->subsys[ss->subsys_id]; + init_css_set.subsys[ss->subsys_id] = css; need_forkexit_callback |= ss->fork || ss->exit;
@@ -4344,7 +4344,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss) ss->active =1 ;if (ss->post_create) - ss->post_create (&ss->root->top_cgroup); + ss->post_create (dummytop);/* this function shouldn't be used with modular subsystems, since they * need to register a subsys_id, among other things */
@@ -4456,7 +4456,7 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss) ss->active =1 ;if (ss->post_create) - ss->post_create (&ss->root->top_cgroup); + ss->post_create (dummytop);/* success! */ mutex_unlock (&cgroup_mutex);
Signature · 1 line
1.7.11.7
Tejun Heo
maintainerPATCH 9/17 cgroup: lock cgroup_mutex in cgroup_init_subsys()
In reply to Tejun HeoMake cgroup_init_subsys() grab cgroup_mutex while initializing a subsystem so that all helpers and callbacks are called under the context they expect. This isn't strictly necessary as cgroup_init_subsys() doesn't race with anybody but will allow adding lockdep assertions.
--- kernel/cgroup.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/cgroup.c +4 -0
@@ -4317,6 +4317,8 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)printk (KERN_INFO "Initializing cgroup subsys %s\n" , ss->name); +mutex_lock (&cgroup_mutex); +/* init base cftset */ cgroup_init_cftsets (ss);
@@ -4346,6 +4348,8 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)if (ss->post_create) ss->post_create (dummytop); +mutex_unlock (&cgroup_mutex); +/* this function shouldn't be used with modular subsystems, since they * need to register a subsys_id, among other things */ BUG_ON (ss->module);
Signature · 1 line
1.7.11.7
Tejun Heo
maintainerPATCH 10/17 cgroup: fix harmless bugs in cgroup_load_subsys() fail path and cgroup_unload_subsys()
In reply to Tejun Heo* If idr init fails, cgroup_load_subsys() cleared dummytop->subsys[] before calilng ->destroy() making CSS inaccessible to the callback, and didn't unlink ss->sibling. As no modular controller uses ->use_id, this doesn't cause any actual problems.
* cgroup_unload_subsys() was forgetting to free idr, call ->pre_destroy() and clear ->active. As there currently is no modular controller which uses ->use_id, ->pre_destroy() or ->active, this doesn't cause any actual problems.
--- kernel/cgroup.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
kernel/cgroup.c +14 -1
@@ -4420,9 +4420,10 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)if (ss->use_id) {int ret =cgroup_init_idr (ss, css);if (ret) { - dummytop->subsys[ss->subsys_id] =NULL ; ss->destroy (dummytop); + dummytop->subsys[ss->subsys_id] =NULL ; subsys[ss->subsys_id] =NULL ; +list_del_init (&ss->sibling);mutex_unlock (&cgroup_mutex);return ret; }
@@ -4490,7 +4491,19 @@ void cgroup_unload_subsys(struct cgroup_subsys *ss)*/ BUG_ON (ss->root != &rootnode); +/* ->pre_destroy() should be called outside cgroup_mutex for now */ +if (ss->pre_destroy) + ss->pre_destroy (dummytop); +mutex_lock (&cgroup_mutex); + + ss->active =0 ; + +if (ss->use_id) { +idr_remove_all (&ss->idr); +idr_destroy (&ss->idr); + } +/* deassign the subsys_id */ subsys[ss->subsys_id] =NULL ;
Signature · 1 line
1.7.11.7
Tejun Heo
maintainerPATCH 11/17 cgroup: separate out cgroup_destroy_locked()
In reply to Tejun HeoSeparate out cgroup_destroy_locked() from cgroup_destroy(). This will be later used in cgroup_create() failure path.
While at it, add lockdep asserts on i_mutex and cgroup_mutex, and move @d and @parent assignments to their declarations.
This patch doesn't introduce any functional difference.
--- kernel/cgroup.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-)
kernel/cgroup.c +25 -15
@@ -242,6 +242,8 @@ static DEFINE_SPINLOCK(hierarchy_id_lock);*/ static int need_forkexit_callback__read_mostly ; +static int cgroup_destroy_locked (struct cgroup *cgrp); +#ifdef CONFIG_PROVE_LOCKING int cgroup_lock_is_held (void ) {
@@ -4209,22 +4211,20 @@ static int cgroup_has_css_refs(struct cgroup *cgrp)return 0 ; } -static int cgroup_rmdir (struct inode *unused_dir,struct dentry *dentry) +static int cgroup_destroy_locked (struct cgroup *cgrp) + __releases(&cgroup_mutex) __acquires(&cgroup_mutex) { -struct cgroup *cgrp = dentry->d_fsdata; -struct dentry *d; -struct cgroup *parent; +struct dentry *d = cgrp->dentry; +struct cgroup *parent = cgrp->parent;DEFINE_WAIT (wait);struct cgroup_event *event, *tmp;struct cgroup_subsys *ss; -/* the vfs holds both inode->i_mutex already */ -mutex_lock (&cgroup_mutex); - parent = cgrp->parent; -if (atomic_read (&cgrp->count) || !list_empty (&cgrp->children)) { -mutex_unlock (&cgroup_mutex); +lockdep_assert_held (&d->d_inode->i_mutex); +lockdep_assert_held (&cgroup_mutex); + +if (atomic_read (&cgrp->count) || !list_empty (&cgrp->children))return -EBUSY ; - }/* * Block new css_tryget() by deactivating refcnt and mark @cgrp
@@ -4243,7 +4243,9 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry)/* * Tell subsystems to initate destruction. pre_destroy() should be * called with cgroup_mutex unlocked. See 3fa59dfbc3 ("cgroup: fix -* potential deadlock in pre_destroy") for details. +* potential deadlock in pre_destroy") for details. This temporary +* unlocking should go away once cgroup_mutex is unexported from +* controllers. */ mutex_unlock (&cgroup_mutex);for_each_subsys (cgrp->root, ss)
@@ -4268,11 +4270,9 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry)/* delete this cgroup from parent->children */ list_del_rcu (&cgrp->sibling); -list_del_init (&cgrp->allcg_node); - d =dget (cgrp->dentry); - +dget (d);cgroup_d_remove_dir (d);dput (d);
@@ -4293,10 +4293,20 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry) }spin_unlock (&cgrp->event_list_lock); -mutex_unlock (&cgroup_mutex);return 0 ; } +static int cgroup_rmdir (struct inode *unused_dir,struct dentry *dentry) +{ +int ret; + +mutex_lock (&cgroup_mutex); + ret =cgroup_destroy_locked (dentry->d_fsdata); +mutex_unlock (&cgroup_mutex); + +return ret; +} + static void __init_or_module cgroup_init_cftsets(struct cgroup_subsys *ss) {INIT_LIST_HEAD (&ss->cftsets);
Signature · 1 line
1.7.11.7
Tejun Heo
maintainerPATCH 12/17 cgroup: introduce CSS_ONLINE flag and on/offline_css() helpers
In reply to Tejun HeoNew helpers on/offline_css() respectively wrap ->post_create() and ->pre_destroy() invocations. online_css() sets CSS_ONLINE after ->post_create() is complete and offline_css() invokes ->pre_destroy() iff CSS_ONLINE is set and clears it while also handling the temporary dropping of cgroup_mutex.
This patch doesn't introduce any behavior change at the moment but will be used to improve cgroup_create() failure path and allow ->post_create() to fail.
--- include/linux/cgroup.h | 1 + kernel/cgroup.c | 65 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 43 insertions(+), 23 deletions(-)
include/linux/cgroup.h +1 -0
@@ -82,6 +82,7 @@ struct cgroup_subsys_state {/* bits in struct cgroup_subsys_state flags field */ enum {CSS_ROOT = (1 <<0 ),/* this CSS is the root of the subsystem */ +CSS_ONLINE = (1 <<1 ),/* between ->post_create() and ->pre_destroy() */ };/* Caller must verify that the css is not for root cgroup */
kernel/cgroup.c +42 -23
104 lines not on this page · raw message
Signature · 1 line
1.7.11.7
A message that is not in the archive (sent off-list or not yet received): 1352775704-9023-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
PATCH 12/17 cgroup: introduce CSS_ONLINE flag and on/offline_css() helpers
New helpers on/offline_css() respectively wrap ->post_create() and ->pre_destroy() invocations. online_css() sets CSS_ONLINE after ->post_create() is complete and offline_css() invokes ->pre_destroy() iff CSS_ONLINE is set and clears it while also handling the temporary dropping of cgroup_mutex.
This patch doesn't introduce any behavior change at the moment but will be used to improve cgroup_create() failure path and allow ->post_create() to fail.
--- include/linux/cgroup.h | 1 + kernel/cgroup.c | 65 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 43 insertions(+), 23 deletions(-)
include/linux/cgroup.h +1 -0
@@ -82,6 +82,7 @@ struct cgroup_subsys_state {/* bits in struct cgroup_subsys_state flags field */ enum {CSS_ROOT = (1 <<0 ),/* this CSS is the root of the subsystem */ +CSS_ONLINE = (1 <<1 ),/* between ->post_create() and ->pre_destroy() */ };/* Caller must verify that the css is not for root cgroup */
kernel/cgroup.c +42 -23
104 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 13/17 cgroup: simplify cgroup_load_subsys() failure path
In reply to a message not in the archiveNow that cgroup_unload_subsys() can tell whether the root css is online or not, we can safely call cgroup_unload_subsys() after idr init failure in cgroup_load_subsys().
Replace the manual unrolling and invoke cgroup_unload_subsys() on failure. This drops cgroup_mutex inbetween but should be safe as the subsystem will fail try_module_get() and thus can't be mounted inbetween. As this means that cgroup_unload_subsys() can be called before css_sets are rehashed, remove BUG_ON() on %NULL css_set->subsys[] from cgroup_unload_subsys().
--- kernel/cgroup.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
kernel/cgroup.c +10 -11
@@ -4400,8 +4400,8 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)*/ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss) { -int i;struct cgroup_subsys_state *css; +int i, ret;/* check name and function validity */ if (ss->name == NULL || strlen(ss->name) > MAX_CGROUP_TYPE_NAMELEN ||
@@ -4452,15 +4452,9 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)init_cgroup_css (css, ss, dummytop);/* init_idr must be after init_cgroup_css because it sets css->id. */ if (ss->use_id) { -int ret =cgroup_init_idr (ss, css); -if (ret) { - ss->destroy (dummytop); - dummytop->subsys[ss->subsys_id] =NULL ; - subsys[ss->subsys_id] =NULL ; -list_del_init (&ss->sibling); -mutex_unlock (&cgroup_mutex); -return ret; - } + ret =cgroup_init_idr (ss, css); +if (ret) + goto err_unload; }/*
@@ -4498,6 +4492,12 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)/* success! */ mutex_unlock (&cgroup_mutex);return 0 ; + +err_unload: +mutex_unlock (&cgroup_mutex); +/* @ss can't be mounted here as try_module_get() would fail */ +cgroup_unload_subsys (ss); +return ret; }EXPORT_SYMBOL_GPL (cgroup_load_subsys);
@@ -4548,7 +4548,6 @@ void cgroup_unload_subsys(struct cgroup_subsys *ss)struct css_set *cg = link->cg;hlist_del (&cg->hlist); -BUG_ON (!cg->subsys[ss->subsys_id]); cg->subsys[ss->subsys_id] =NULL ; hhead =css_set_hash (cg->subsys);hlist_add_head (&cg->hlist, hhead);
Signature · 1 line
1.7.11.7
PATCH 14/17 cgroup: use mutex_trylock() when grabbing i_mutex of a new cgroup directory
In reply to a message not in the archiveAll cgroup directory i_mutexes nest outside cgroup_mutex; however, new directory creation is a special case. A new cgroup directory is created while holding cgroup_mutex. Populating the new directory requires both the new directory's i_mutex and cgroup_mutex. Because all directory i_mutexes nest outside cgroup_mutex, grabbing both requires releasing cgroup_mutex first, which isn't a good idea as the new cgroup isn't yet ready to be manipulated by other cgroup opreations.
This is worked around by grabbing the new directory's i_mutex while holding cgroup_mutex before making it visible. As there's no other user at that point, grabbing the i_mutex under cgroup_mutex can't lead to deadlock.
cgroup_create_file() was using I_MUTEX_CHILD to tell lockdep not to worry about the reverse locking order; however, this creates pseudo locking dependency cgroup_mutex -> I_MUTEX_CHILD, which isn't true - all directory i_mutexes are still nested outside cgroup_mutex. This pseudo locking dependency can lead to spurious lockdep warnings.
Use mutex_trylock() instead. This will always succeed and lockdep doesn't create any locking dependency for it.
--- kernel/cgroup.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
kernel/cgroup.c +9 -3
@@ -2657,9 +2657,15 @@ static int cgroup_create_file(struct dentry *dentry, umode_t mode,inc_nlink (inode);inc_nlink (dentry->d_parent->d_inode); -/* start with the directory inode held, so that we can -* populate it without racing with another mkdir */ -mutex_lock_nested (&inode->i_mutex,I_MUTEX_CHILD ); +/* +* Control reaches here with cgroup_mutex held. +* @inode->i_mutex should nest outside cgroup_mutex but we +* want to populate it immediately without releasing +* cgroup_mutex. As @inode isn't visible to anyone else +* yet, trylock will always succeed without affecting +* lockdep checks. +*/ +WARN_ON_ONCE (!mutex_trylock (&inode->i_mutex)); }else if (S_ISREG (mode)) { inode->i_size =0 ; inode->i_fop = &cgroup_file_operations;
Signature · 1 line
1.7.11.7
PATCH 16/17 cgroup: allow ->post_create() to fail
In reply to a message not in the archiveThere could be cases where controllers want to do initialization operations which may fail from ->post_create(). This patch makes ->post_create() return -errno to indicate failure and online_css() relay such failures.
--- include/linux/cgroup.h | 2 +- kernel/cgroup.c | 29 +++++++++++++++++++---------- kernel/cgroup_freezer.c | 4 +++- 3 files changed, 23 insertions(+), 12 deletions(-)
include/linux/cgroup.h +1 -1
@@ -437,7 +437,7 @@ int cgroup_taskset_size(struct cgroup_taskset *tset);struct cgroup_subsys {struct cgroup_subsys_state *(*create)(struct cgroup *cgrp); -void (*post_create)(struct cgroup *cgrp); +int (*post_create)(struct cgroup *cgrp);void (*pre_destroy)(struct cgroup *cgrp);void (*destroy)(struct cgroup *cgrp);int (*can_attach)(struct cgroup *cgrp,struct cgroup_taskset *tset);
kernel/cgroup.c +19 -10
@@ -4041,14 +4041,18 @@ static void init_cgroup_css(struct cgroup_subsys_state *css,INIT_WORK (&css->dput_work, css_dput_fn); } -/* invoke ->post_create() on a new CSS and mark it online */ -static void online_css (struct cgroup_subsys *ss,struct cgroup *cgrp) +/* invoke ->post_create() on a new CSS and mark it online if successful */ +static int online_css (struct cgroup_subsys *ss,struct cgroup *cgrp) { +int ret =0 ; +lockdep_assert_held (&cgroup_mutex);if (ss->post_create) - ss->post_create (cgrp); - cgrp->subsys[ss->subsys_id]->flags |=CSS_ONLINE ; + ret = ss->post_create (cgrp); +if (!ret) + cgrp->subsys[ss->subsys_id]->flags |=CSS_ONLINE ; +return ret; }/* if the CSS is online, invoke ->pre_destory() on it and mark it offline */
@@ -4174,12 +4178,15 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,list_add_tail_rcu (&cgrp->sibling, &cgrp->parent->children); root->number_of_cgroups++; -for_each_subsys (root, ss) { -/* each css holds a ref to the cgroup's dentry */ +/* each css holds a ref to the cgroup's dentry */ +for_each_subsys (root, ss)dget (dentry); -/* creation succeeded, notify subsystems */ -online_css (ss, cgrp); +/* creation succeeded, notify subsystems */ +for_each_subsys (root, ss) { + err =online_css (ss, cgrp); +if (err) + goto err_destroy; } err =cgroup_populate_dir (cgrp, true, root->subsys_mask);
@@ -4393,7 +4400,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)BUG_ON (!list_empty (&init_task.tasks)); ss->active =1 ; -online_css (ss, dummytop); +BUG_ON (online_css (ss, dummytop));mutex_unlock (&cgroup_mutex);
@@ -4500,7 +4507,9 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)write_unlock (&css_set_lock); ss->active =1 ; -online_css (ss, dummytop); + ret =online_css (ss, dummytop); +if (ret) + goto err_unload;/* success! */ mutex_unlock (&cgroup_mutex);
kernel/cgroup_freezer.c +3 -1
@@ -112,7 +112,7 @@ static struct cgroup_subsys_state *freezer_create(struct cgroup *cgroup)* parent's freezing state while holding both parent's and our * freezer->lock. */ -static void freezer_post_create (struct cgroup *cgroup) +static int freezer_post_create (struct cgroup *cgroup) {struct freezer *freezer =cgroup_freezer (cgroup);struct freezer *parent =parent_freezer (freezer);
@@ -136,6 +136,8 @@ static void freezer_post_create(struct cgroup *cgroup)spin_unlock (&freezer->lock);if (parent)spin_unlock_irq (&parent->lock); + +return 0 ; }/**
Signature · 1 line
1.7.11.7
PATCH 17/17 cgroup: rename ->create/post_create/pre_destroy/destroy() to ->css_alloc/online/offline/free()
In reply to a message not in the archiveRename cgroup_subsys css lifetime related callbacks to better describe what their roles are. Also, update documentation.
--- Documentation/cgroups/cgroups.txt | 49 ++++++++++++++++++++++--------------- block/blk-cgroup.c | 14 +++++------ include/linux/cgroup.h | 35 ++++++++++++++------------- kernel/cgroup.c | 51 ++++++++++++++++++++------------------- kernel/cgroup_freezer.c | 20 +++++++-------- kernel/cpuset.c | 10 ++++---- kernel/events/core.c | 8 +++--- kernel/sched/core.c | 16 ++++++------ mm/hugetlb_cgroup.c | 14 +++++------ mm/memcontrol.c | 12 ++++----- net/core/netprio_cgroup.c | 8 +++--- net/sched/cls_cgroup.c | 8 +++--- security/device_cgroup.c | 8 +++--- 13 files changed, 132 insertions(+), 121 deletions(-)
Documentation/cgroups/cgroups.txt +29 -20
@@ -553,16 +553,16 @@ call to cgroup_unload_subsys(). It should also set its_subsys.module = THIS_MODULE in its .c file. Each subsystem may export the following methods. The only mandatory -methods are create/destroy. Any others that are null are presumed to +methods are css_alloc/free. Any others that are null are presumed to be successful no-ops. -struct cgroup_subsys_state *create(struct cgroup *cgrp) +struct cgroup_subsys_state *css_alloc(struct cgroup *cgrp) (cgroup_mutex held by caller) -Called to create a subsystem state object for a cgroup. The +Called to allocate a subsystem state object for a cgroup. The subsystem should allocate its subsystem state object for the passed cgroup, returning a pointer to the new object on success or a -negative error code. On success, the subsystem pointer should point to +ERR_PTR() value. On success, the subsystem pointer should point to a structure of type cgroup_subsys_state (typically embedded in a larger subsystem-specific object), which will be initialized by the cgroup system. Note that this will be called at initialization to
@@ -571,24 +571,33 @@ identified by the passed cgroup object having a NULL parent (since it's the root of the hierarchy) and may be an appropriate place for initialization code. -void destroy(struct cgroup *cgrp) +int css_online(struct cgroup *cgrp) (cgroup_mutex held by caller) -The cgroup system is about to destroy the passed cgroup; the subsystem -should do any necessary cleanup and free its subsystem state -object. By the time this method is called, the cgroup has already been -unlinked from the file system and from the child list of its parent; -cgroup->parent is still valid. (Note - can also be called for a -newly-created cgroup if an error occurs after this subsystem's -create() method has been called for the new cgroup). - -int pre_destroy(struct cgroup *cgrp); - -Called before checking the reference count on each subsystem. This may -be useful for subsystems which have some extra references even if -there are not tasks in the cgroup. If pre_destroy() returns error code, -rmdir() will fail with it. From this behavior, pre_destroy() can be -called multiple times against a cgroup. +Called after @cgrp successfully completed all allocations and made +visible to cgroup_for_each_child/descendant_*() iterators. The +subsystem may choose to fail creation by returning -errno. This +callback can be used to implement reliable state sharing and +propagation along the hierarchy. See the comment on +cgroup_for_each_descendant_pre() for details. + +void css_offline(struct cgroup *cgrp); + +This is the counterpart of css_online() and called iff css_online() +has succeeded on @cgrp. This signifies the beginning of the end of +@cgrp. @cgrp is being removed and the subsystem should start dropping +all references it's holding on @cgrp. When all references are dropped, +cgroup removal will proceed to the next step - css_free(). After this +callback, @cgrp should be considered dead to the subsystem. + +void css_free(struct cgroup *cgrp) +(cgroup_mutex held by caller) + +The cgroup system is about to free @cgrp; the subsystem should free +its subsystem state object. By the time this method is called, @cgrp +is completely unused; @cgrp->parent is still valid. (Note - can also +be called for a newly-created cgroup if an error occurs after this +subsystem's create() method has been called for the new cgroup). int can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset) (cgroup_mutex held by caller)
block/blk-cgroup.c +7 -7
@@ -600,7 +600,7 @@ struct cftype blkcg_files[] = { };/** -* blkcg_pre_destroy - cgroup pre_destroy callback +* blkcg_css_offline - cgroup css_offline callback * @cgroup: cgroup of interest * * This function is called when @cgroup is about to go away and responsible
@@ -610,7 +610,7 @@ struct cftype blkcg_files[] = {* * This is the blkcg counterpart of ioc_release_fn(). */ -static void blkcg_pre_destroy (struct cgroup *cgroup) +static void blkcg_css_offline (struct cgroup *cgroup) {struct blkcg *blkcg =cgroup_to_blkcg (cgroup);
@@ -634,7 +634,7 @@ static void blkcg_pre_destroy(struct cgroup *cgroup)spin_unlock_irq (&blkcg->lock); } -static void blkcg_destroy (struct cgroup *cgroup) +static void blkcg_css_free (struct cgroup *cgroup) {struct blkcg *blkcg =cgroup_to_blkcg (cgroup);
@@ -642,7 +642,7 @@ static void blkcg_destroy(struct cgroup *cgroup)kfree (blkcg); } -static struct cgroup_subsys_state *blkcg_create (struct cgroup *cgroup) +static struct cgroup_subsys_state *blkcg_css_alloc (struct cgroup *cgroup) {static atomic64_t id_seq =ATOMIC64_INIT (0 );struct blkcg *blkcg;
@@ -739,10 +739,10 @@ static int blkcg_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)struct cgroup_subsys blkio_subsys = { .name ="blkio" , - .create = blkcg_create, + .css_alloc = blkcg_css_alloc, + .css_offline = blkcg_css_offline, + .css_free = blkcg_css_free, .can_attach = blkcg_can_attach, - .pre_destroy = blkcg_pre_destroy, - .destroy = blkcg_destroy, .subsys_id = blkio_subsys_id, .base_cftypes = blkcg_files, .module =THIS_MODULE ,
include/linux/cgroup.h +18 -17
@@ -82,7 +82,7 @@ struct cgroup_subsys_state {/* bits in struct cgroup_subsys_state flags field */ enum {CSS_ROOT = (1 <<0 ),/* this CSS is the root of the subsystem */ -CSS_ONLINE = (1 <<1 ),/* between ->post_create() and ->pre_destroy() */ +CSS_ONLINE = (1 <<1 ),/* between ->css_online() and ->css_offline() */ };/* Caller must verify that the css is not for root cgroup */
@@ -436,10 +436,11 @@ int cgroup_taskset_size(struct cgroup_taskset *tset);*/ struct cgroup_subsys { -struct cgroup_subsys_state *(*create)(struct cgroup *cgrp); -int (*post_create)(struct cgroup *cgrp); -void (*pre_destroy)(struct cgroup *cgrp); -void (*destroy)(struct cgroup *cgrp); +struct cgroup_subsys_state *(*css_alloc)(struct cgroup *cgrp); +int (*css_online)(struct cgroup *cgrp); +void (*css_offline)(struct cgroup *cgrp); +void (*css_free)(struct cgroup *cgrp); +int (*can_attach)(struct cgroup *cgrp,struct cgroup_taskset *tset);void (*cancel_attach)(struct cgroup *cgrp,struct cgroup_taskset *tset);void (*attach)(struct cgroup *cgrp,struct cgroup_taskset *tset);
@@ -538,13 +539,13 @@ static inline struct cgroup* task_cgroup(struct task_struct *task,* @cgroup: cgroup whose children to walk * * Walk @cgroup's children. Must be called under rcu_read_lock(). A child -* cgroup which hasn't finished ->post_create() or already has finished -* ->pre_destroy() may show up during traversal and it's each subsystem's +* cgroup which hasn't finished ->css_online() or already has finished +* ->css_offline() may show up during traversal and it's each subsystem's * responsibility to verify that each @pos is alive. * -* If a subsystem synchronizes against the parent in its ->post_create() -* and before starting iterating, a cgroup which finished ->post_create() -* is guaranteed to be visible in the future iterations. +* If a subsystem synchronizes against the parent in its ->css_online() and +* before starting iterating, a cgroup which finished ->css_online() is +* guaranteed to be visible in the future iterations. */ #define cgroup_for_each_child (pos, cgroup) \ list_for_each_entry_rcu(pos, &(cgroup)->children, sibling)
@@ -558,19 +559,19 @@ struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos,* @cgroup: cgroup whose descendants to walk * * Walk @cgroup's descendants. Must be called under rcu_read_lock(). A -* descendant cgroup which hasn't finished ->post_create() or already has -* finished ->pre_destroy() may show up during traversal and it's each +* descendant cgroup which hasn't finished ->css_online() or already has +* finished ->css_offline() may show up during traversal and it's each * subsystem's responsibility to verify that each @pos is alive. * -* If a subsystem synchronizes against the parent in its ->post_create() -* and before starting iterating, and synchronizes against @pos on each -* iteration, any descendant cgroup which finished ->post_create() is +* If a subsystem synchronizes against the parent in its ->css_online() and +* before starting iterating, and synchronizes against @pos on each +* iteration, any descendant cgroup which finished ->css_offline() is * guaranteed to be visible in the future iterations. * * In other words, the following guarantees that a descendant can't escape * state updates of its ancestors. * -* my_post_create(@cgrp) +* my_online(@cgrp) * { * Lock @cgrp->parent and @cgrp; * Inherit state from @cgrp->parent;
@@ -603,7 +604,7 @@ struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos,* iteration should lock and unlock both @pos->parent and @pos. * * Alternatively, a subsystem may choose to use a single global lock to -* synchronize ->post_create() and ->pre_destroy() against tree-walking +* synchronize ->css_online() and ->css_offline() against tree-walking * operations. */ #define cgroup_for_each_descendant_pre (pos, cgroup) \
kernel/cgroup.c +26 -25
142 lines not on this page · raw message
kernel/cgroup_freezer.c +10 -10
@@ -92,7 +92,7 @@ static const char *freezer_state_strs(unsigned int state)struct cgroup_subsys freezer_subsys; -static struct cgroup_subsys_state *freezer_create (struct cgroup *cgroup) +static struct cgroup_subsys_state *freezer_css_alloc (struct cgroup *cgroup) {struct freezer *freezer;
@@ -105,14 +105,14 @@ static struct cgroup_subsys_state *freezer_create(struct cgroup *cgroup) }/** -* freezer_post_create - commit creation of a freezer cgroup +* freezer_css_online - commit creation of a freezer cgroup * @cgroup: cgroup being created * * We're committing to creation of @cgroup. Mark it online and inherit * parent's freezing state while holding both parent's and our * freezer->lock. */ -static int freezer_post_create (struct cgroup *cgroup) +static int freezer_css_online (struct cgroup *cgroup) {struct freezer *freezer =cgroup_freezer (cgroup);struct freezer *parent =parent_freezer (freezer);
@@ -141,13 +141,13 @@ static int freezer_post_create(struct cgroup *cgroup) }/** -* freezer_pre_destroy - initiate destruction of @cgroup +* freezer_css_offline - initiate destruction of @cgroup * @cgroup: cgroup being destroyed * * @cgroup is going away. Mark it dead and decrement system_freezing_count * if it was holding one. */ -static void freezer_pre_destroy (struct cgroup *cgroup) +static void freezer_css_offline (struct cgroup *cgroup) {struct freezer *freezer =cgroup_freezer (cgroup);
@@ -161,7 +161,7 @@ static void freezer_pre_destroy(struct cgroup *cgroup)spin_unlock_irq (&freezer->lock); } -static void freezer_destroy (struct cgroup *cgroup) +static void freezer_css_free (struct cgroup *cgroup) {kfree (cgroup_freezer (cgroup)); }
@@ -477,10 +477,10 @@ static struct cftype files[] = {struct cgroup_subsys freezer_subsys = { .name ="freezer" , - .create = freezer_create, - .post_create = freezer_post_create, - .pre_destroy = freezer_pre_destroy, - .destroy = freezer_destroy, + .css_alloc = freezer_css_alloc, + .css_online = freezer_css_online, + .css_offline = freezer_css_offline, + .css_free = freezer_css_free, .subsys_id = freezer_subsys_id, .attach = freezer_attach, .fork = freezer_fork,
kernel/cpuset.c +5 -5
@@ -1821,11 +1821,11 @@ static void cpuset_post_clone(struct cgroup *cgroup) }/* -* cpuset_create - create a cpuset +* cpuset_css_alloc - allocate a cpuset css * cont: control group that the new cpuset will be part of */ -static struct cgroup_subsys_state *cpuset_create (struct cgroup *cont) +static struct cgroup_subsys_state *cpuset_css_alloc (struct cgroup *cont) {struct cpuset *cs;struct cpuset *parent;
@@ -1864,7 +1864,7 @@ static struct cgroup_subsys_state *cpuset_create(struct cgroup *cont)* will call async_rebuild_sched_domains(). */ -static void cpuset_destroy (struct cgroup *cont) +static void cpuset_css_free (struct cgroup *cont) {struct cpuset *cs =cgroup_cs (cont);
@@ -1878,8 +1878,8 @@ static void cpuset_destroy(struct cgroup *cont)struct cgroup_subsys cpuset_subsys = { .name ="cpuset" , - .create = cpuset_create, - .destroy = cpuset_destroy, + .css_alloc = cpuset_css_alloc, + .css_free = cpuset_css_free, .can_attach = cpuset_can_attach, .attach = cpuset_attach, .post_clone = cpuset_post_clone,
kernel/events/core.c +4 -4
@@ -7434,7 +7434,7 @@ unlock:device_initcall (perf_event_sysfs_init);#ifdef CONFIG_CGROUP_PERF -static struct cgroup_subsys_state *perf_cgroup_create (struct cgroup *cont) +static struct cgroup_subsys_state *perf_cgroup_css_alloc (struct cgroup *cont) {struct perf_cgroup *jc;
@@ -7451,7 +7451,7 @@ static struct cgroup_subsys_state *perf_cgroup_create(struct cgroup *cont)return &jc->css; } -static void perf_cgroup_destroy (struct cgroup *cont) +static void perf_cgroup_css_free (struct cgroup *cont) {struct perf_cgroup *jc; jc = container_of(cgroup_subsys_state(cont, perf_subsys_id),
@@ -7492,8 +7492,8 @@ static void perf_cgroup_exit(struct cgroup *cgrp, struct cgroup *old_cgrp,struct cgroup_subsys perf_subsys = { .name ="perf_event" , .subsys_id = perf_subsys_id, - .create = perf_cgroup_create, - .destroy = perf_cgroup_destroy, + .css_alloc = perf_cgroup_css_alloc, + .css_free = perf_cgroup_css_free, .exit = perf_cgroup_exit, .attach = perf_cgroup_attach,
kernel/sched/core.c +8 -8
@@ -7468,7 +7468,7 @@ static inline struct task_group *cgroup_tg(struct cgroup *cgrp) struct task_group, css); } -static struct cgroup_subsys_state *cpu_cgroup_create (struct cgroup *cgrp) +static struct cgroup_subsys_state *cpu_cgroup_css_alloc (struct cgroup *cgrp) {struct task_group *tg, *parent;
@@ -7485,7 +7485,7 @@ static struct cgroup_subsys_state *cpu_cgroup_create(struct cgroup *cgrp)return &tg->css; } -static void cpu_cgroup_destroy (struct cgroup *cgrp) +static void cpu_cgroup_css_free (struct cgroup *cgrp) {struct task_group *tg =cgroup_tg (cgrp);
@@ -7845,8 +7845,8 @@ static struct cftype cpu_files[] = {struct cgroup_subsys cpu_cgroup_subsys = { .name ="cpu" , - .create = cpu_cgroup_create, - .destroy = cpu_cgroup_destroy, + .css_alloc = cpu_cgroup_css_alloc, + .css_free = cpu_cgroup_css_free, .can_attach = cpu_cgroup_can_attach, .attach = cpu_cgroup_attach, .exit = cpu_cgroup_exit,
@@ -7869,7 +7869,7 @@ struct cgroup_subsys cpu_cgroup_subsys = {struct cpuacct root_cpuacct;/* create a new cpu accounting group */ -static struct cgroup_subsys_state *cpuacct_create (struct cgroup *cgrp) +static struct cgroup_subsys_state *cpuacct_css_alloc (struct cgroup *cgrp) {struct cpuacct *ca;
@@ -7899,7 +7899,7 @@ out: }/* destroy an existing cpu accounting group */ -static void cpuacct_destroy (struct cgroup *cgrp) +static void cpuacct_css_free (struct cgroup *cgrp) {struct cpuacct *ca =cgroup_ca (cgrp);
@@ -8070,8 +8070,8 @@ void cpuacct_charge(struct task_struct *tsk, u64 cputime)struct cgroup_subsys cpuacct_subsys = { .name ="cpuacct" , - .create = cpuacct_create, - .destroy = cpuacct_destroy, + .css_alloc = cpuacct_css_alloc, + .css_free = cpuacct_css_free, .subsys_id = cpuacct_subsys_id, .base_cftypes = files, };
mm/hugetlb_cgroup.c +7 -7
@@ -77,7 +77,7 @@ static inline bool hugetlb_cgroup_have_usage(struct cgroup *cg)return false; } -static struct cgroup_subsys_state *hugetlb_cgroup_create (struct cgroup *cgroup) +static struct cgroup_subsys_state *hugetlb_cgroup_css_alloc (struct cgroup *cgroup) {int idx;struct cgroup *parent_cgroup;
@@ -101,7 +101,7 @@ static struct cgroup_subsys_state *hugetlb_cgroup_create(struct cgroup *cgroup)return &h_cgroup->css; } -static void hugetlb_cgroup_destroy (struct cgroup *cgroup) +static void hugetlb_cgroup_css_free (struct cgroup *cgroup) {struct hugetlb_cgroup *h_cgroup;
@@ -155,7 +155,7 @@ out:* Force the hugetlb cgroup to empty the hugetlb resources by moving them to * the parent cgroup. */ -static void hugetlb_cgroup_pre_destroy (struct cgroup *cgroup) +static void hugetlb_cgroup_css_offline (struct cgroup *cgroup) {struct hstate *h;struct page *page;
@@ -404,8 +404,8 @@ void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage)struct cgroup_subsys hugetlb_subsys = { .name ="hugetlb" , - .create = hugetlb_cgroup_create, - .pre_destroy = hugetlb_cgroup_pre_destroy, - .destroy = hugetlb_cgroup_destroy, - .subsys_id = hugetlb_subsys_id, + .css_alloc = hugetlb_cgroup_css_alloc, + .css_offline = hugetlb_cgroup_css_offline, + .css_free = hugetlb_cgroup_css_free, + .subsys_id = hugetlb_subsys_id, };
mm/memcontrol.c +6 -6
@@ -4922,7 +4922,7 @@ err_cleanup: }static struct cgroup_subsys_state *__ref -mem_cgroup_create (struct cgroup *cont) +mem_cgroup_css_alloc (struct cgroup *cont) {struct mem_cgroup *memcg, *parent;long error = -ENOMEM ;
@@ -5003,14 +5003,14 @@ free_out:return ERR_PTR (error); } -static void mem_cgroup_pre_destroy (struct cgroup *cont) +static void mem_cgroup_css_offline (struct cgroup *cont) {struct mem_cgroup *memcg =mem_cgroup_from_cont (cont);mem_cgroup_reparent_charges (memcg); } -static void mem_cgroup_destroy (struct cgroup *cont) +static void mem_cgroup_css_free (struct cgroup *cont) {struct mem_cgroup *memcg =mem_cgroup_from_cont (cont);
@@ -5600,9 +5600,9 @@ static void mem_cgroup_move_task(struct cgroup *cont,struct cgroup_subsys mem_cgroup_subsys = { .name ="memory" , .subsys_id = mem_cgroup_subsys_id, - .create = mem_cgroup_create, - .pre_destroy = mem_cgroup_pre_destroy, - .destroy = mem_cgroup_destroy, + .css_alloc = mem_cgroup_css_alloc, + .css_offline = mem_cgroup_css_offline, + .css_free = mem_cgroup_css_free, .can_attach = mem_cgroup_can_attach, .cancel_attach = mem_cgroup_cancel_attach, .attach = mem_cgroup_move_task,
net/core/netprio_cgroup.c +4 -4
@@ -108,7 +108,7 @@ static int write_update_netdev_table(struct net_device *dev)return ret; } -static struct cgroup_subsys_state *cgrp_create (struct cgroup *cgrp) +static struct cgroup_subsys_state *cgrp_css_alloc (struct cgroup *cgrp) {struct cgroup_netprio_state *cs;int ret = -EINVAL ;
@@ -132,7 +132,7 @@ out:return ERR_PTR (ret); } -static void cgrp_destroy (struct cgroup *cgrp) +static void cgrp_css_free (struct cgroup *cgrp) {struct cgroup_netprio_state *cs;struct net_device *dev;
@@ -276,8 +276,8 @@ static struct cftype ss_files[] = {struct cgroup_subsys net_prio_subsys = { .name ="net_prio" , - .create = cgrp_create, - .destroy = cgrp_destroy, + .css_alloc = cgrp_css_alloc, + .css_free = cgrp_css_free, .attach = net_prio_attach, .subsys_id = net_prio_subsys_id, .base_cftypes = ss_files,
net/sched/cls_cgroup.c +4 -4
@@ -34,7 +34,7 @@ static inline struct cgroup_cls_state *task_cls_state(struct task_struct *p) struct cgroup_cls_state, css); } -static struct cgroup_subsys_state *cgrp_create (struct cgroup *cgrp) +static struct cgroup_subsys_state *cgrp_css_alloc (struct cgroup *cgrp) {struct cgroup_cls_state *cs;
@@ -48,7 +48,7 @@ static struct cgroup_subsys_state *cgrp_create(struct cgroup *cgrp)return &cs->css; } -static void cgrp_destroy (struct cgroup *cgrp) +static void cgrp_css_free (struct cgroup *cgrp) {kfree (cgrp_cls_state (cgrp)); }
@@ -75,8 +75,8 @@ static struct cftype ss_files[] = {struct cgroup_subsys net_cls_subsys = { .name ="net_cls" , - .create = cgrp_create, - .destroy = cgrp_destroy, + .css_alloc = cgrp_css_alloc, + .css_free = cgrp_css_free, .subsys_id = net_cls_subsys_id, .base_cftypes = ss_files, .module =THIS_MODULE ,
security/device_cgroup.c +4 -4
@@ -180,7 +180,7 @@ static void dev_exception_clean(struct dev_cgroup *dev_cgroup)/* * called from kernel/cgroup.c with cgroup_lock() held. */ -static struct cgroup_subsys_state *devcgroup_create (struct cgroup *cgroup) +static struct cgroup_subsys_state *devcgroup_css_alloc (struct cgroup *cgroup) {struct dev_cgroup *dev_cgroup, *parent_dev_cgroup;struct cgroup *parent_cgroup;
@@ -210,7 +210,7 @@ static struct cgroup_subsys_state *devcgroup_create(struct cgroup *cgroup)return &dev_cgroup->css; } -static void devcgroup_destroy (struct cgroup *cgroup) +static void devcgroup_css_free (struct cgroup *cgroup) {struct dev_cgroup *dev_cgroup;
@@ -564,8 +564,8 @@ static struct cftype dev_cgroup_files[] = {struct cgroup_subsys devices_subsys = { .name ="devices" , .can_attach = devcgroup_can_attach, - .create = devcgroup_create, - .destroy = devcgroup_destroy, + .css_alloc = devcgroup_css_alloc, + .css_free = devcgroup_css_free, .subsys_id = devices_subsys_id, .base_cftypes = dev_cgroup_files,
Signature · 1 line
1.7.11.7
Li Zefan
Acked-byQuoted 19 lines · Tejun Heo
Hello,
This became a rather large patchset mostly because there are a lot of weirdities and subtle breakages in create/destroy/load/unload paths. The goal of the patchset is allowing ->post_create() to fail and renaming ->create/post_create/pre_destroy/destroy() to ->css_alloc/css_online/css_offline/css_free().
This patchset contains the following seventeen patches.
0001-cgroup-remove-incorrect-dget-dput-pair-in-cgroup_cre.patch 0002-cgroup-initialize-cgrp-allcg_node-in-init_cgroup_hou.patch 0003-cgroup-open-code-cgroup_create_dir.patch 0004-cgroup-create-directory-before-linking-while-creatin.patch 0005-cgroup-cgroup-dentry-isn-t-a-RCU-pointer.patch 0006-cgroup-remove-duplicate-RCU-free-on-struct-cgroup.patch 0007-cgroup-make-CSS_-flags-bit-masks-instead-of-bit-posi.patch 0008-cgroup-trivial-cleanup-for-cgroup_init-load_subsys.patch 0009-cgroup-lock-cgroup_mutex-in-cgroup_init_subsys.patch
Quoted 9 lines
0010-cgroup-fix-harmless-bugs-in-cgroup_load_subsys-fail-.patch 0011-cgroup-separate-out-cgroup_destroy_locked.patch 0012-cgroup-introduce-CSS_ONLINE-flag-and-on-offline_css-.patch 0013-cgroup-simplify-cgroup_load_subsys-failure-path.patch 0014-cgroup-use-mutex_trylock-when-grabbing-i_mutex-of-a-.patch 0015-cgroup-update-cgroup_create-failure-path.patch 0016-cgroup-allow-post_create-to-fail.patch 0017-cgroup-rename-create-post_create-pre_destroy-destroy.patch
except 0006-cgroup-remove-duplicate-RCU-free-on-struct-cgroup.patch
Quoted 18 lines
0001 is a bugfix. Tagged for -stable. I don't I'll push it through for-3.7-fixes tho. This has been broken forever and nobody reported anything yet.
0002-0011 are various fixes and cleanups to prepare for the following changes. Each should be self-explanatory.
0012-0015 are preparation patches more directly related to allowing failure of ->post_create().
0016 allows ->post_create() to fail.
0017 renames ops and updates documentation.
This patchst is on top of cgroup/for-3.8 and available on the following git branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.gitreview-cgroup-online-may-fail
Tejun Heo
maintainerPATCH 13/17 cgroup: simplify cgroup_load_subsys() failure path
In reply to Tejun HeoNow that cgroup_unload_subsys() can tell whether the root css is online or not, we can safely call cgroup_unload_subsys() after idr init failure in cgroup_load_subsys().
Replace the manual unrolling and invoke cgroup_unload_subsys() on failure. This drops cgroup_mutex inbetween but should be safe as the subsystem will fail try_module_get() and thus can't be mounted inbetween. As this means that cgroup_unload_subsys() can be called before css_sets are rehashed, remove BUG_ON() on %NULL css_set->subsys[] from cgroup_unload_subsys().
--- kernel/cgroup.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
kernel/cgroup.c +10 -11
@@ -4400,8 +4400,8 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)*/ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss) { -int i;struct cgroup_subsys_state *css; +int i, ret;/* check name and function validity */ if (ss->name == NULL || strlen(ss->name) > MAX_CGROUP_TYPE_NAMELEN ||
@@ -4452,15 +4452,9 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)init_cgroup_css (css, ss, dummytop);/* init_idr must be after init_cgroup_css because it sets css->id. */ if (ss->use_id) { -int ret =cgroup_init_idr (ss, css); -if (ret) { - ss->destroy (dummytop); - dummytop->subsys[ss->subsys_id] =NULL ; - subsys[ss->subsys_id] =NULL ; -list_del_init (&ss->sibling); -mutex_unlock (&cgroup_mutex); -return ret; - } + ret =cgroup_init_idr (ss, css); +if (ret) + goto err_unload; }/*
@@ -4498,6 +4492,12 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)/* success! */ mutex_unlock (&cgroup_mutex);return 0 ; + +err_unload: +mutex_unlock (&cgroup_mutex); +/* @ss can't be mounted here as try_module_get() would fail */ +cgroup_unload_subsys (ss); +return ret; }EXPORT_SYMBOL_GPL (cgroup_load_subsys);
@@ -4548,7 +4548,6 @@ void cgroup_unload_subsys(struct cgroup_subsys *ss)struct css_set *cg = link->cg;hlist_del (&cg->hlist); -BUG_ON (!cg->subsys[ss->subsys_id]); cg->subsys[ss->subsys_id] =NULL ; hhead =css_set_hash (cg->subsys);hlist_add_head (&cg->hlist, hhead);
Signature · 1 line
1.7.11.7
Tejun Heo
maintainerPATCH 14/17 cgroup: use mutex_trylock() when grabbing i_mutex of a new cgroup directory
In reply to Tejun HeoAll cgroup directory i_mutexes nest outside cgroup_mutex; however, new directory creation is a special case. A new cgroup directory is created while holding cgroup_mutex. Populating the new directory requires both the new directory's i_mutex and cgroup_mutex. Because all directory i_mutexes nest outside cgroup_mutex, grabbing both requires releasing cgroup_mutex first, which isn't a good idea as the new cgroup isn't yet ready to be manipulated by other cgroup opreations.
This is worked around by grabbing the new directory's i_mutex while holding cgroup_mutex before making it visible. As there's no other user at that point, grabbing the i_mutex under cgroup_mutex can't lead to deadlock.
cgroup_create_file() was using I_MUTEX_CHILD to tell lockdep not to worry about the reverse locking order; however, this creates pseudo locking dependency cgroup_mutex -> I_MUTEX_CHILD, which isn't true - all directory i_mutexes are still nested outside cgroup_mutex. This pseudo locking dependency can lead to spurious lockdep warnings.
Use mutex_trylock() instead. This will always succeed and lockdep doesn't create any locking dependency for it.
--- kernel/cgroup.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
kernel/cgroup.c +9 -3
@@ -2657,9 +2657,15 @@ static int cgroup_create_file(struct dentry *dentry, umode_t mode,inc_nlink (inode);inc_nlink (dentry->d_parent->d_inode); -/* start with the directory inode held, so that we can -* populate it without racing with another mkdir */ -mutex_lock_nested (&inode->i_mutex,I_MUTEX_CHILD ); +/* +* Control reaches here with cgroup_mutex held. +* @inode->i_mutex should nest outside cgroup_mutex but we +* want to populate it immediately without releasing +* cgroup_mutex. As @inode isn't visible to anyone else +* yet, trylock will always succeed without affecting +* lockdep checks. +*/ +WARN_ON_ONCE (!mutex_trylock (&inode->i_mutex)); }else if (S_ISREG (mode)) { inode->i_size =0 ; inode->i_fop = &cgroup_file_operations;
Signature · 1 line
1.7.11.7
Tejun Heo
maintainerPATCH 15/17 cgroup: update cgroup_create() failure path
In reply to Tejun Heocgroup_create() was ignoring failure of cgroupfs files. Update it such that, if file creation fails, it rolls back by calling cgroup_destroy_locked() and returns failure.
Note that error out goto labels are renamed. The labels are a bit confusing but will become better w/ later cgroup operation renames.
--- kernel/cgroup.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
kernel/cgroup.c +14 -7
@@ -4107,7 +4107,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,*/ if (!cgroup_lock_live_group (parent)) { err = -ENODEV ; - goto err_free; + goto err_free_cgrp; }/* Grab a reference on the superblock so the hierarchy doesn't
@@ -4135,13 +4135,13 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, css = ss->create (cgrp);if (IS_ERR (css)) { err =PTR_ERR (css); - goto err_destroy; + goto err_free_all; }init_cgroup_css (css, ss, cgrp);if (ss->use_id) { err =alloc_css_id (ss, parent, cgrp);if (err) - goto err_destroy; + goto err_free_all; }/* At error, ->destroy() callback has to free assigned ID. */ if (clone_children (parent) && ss->post_clone)
@@ -4164,7 +4164,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,*/ err =cgroup_create_file (dentry,S_IFDIR | mode, sb);if (err <0 ) - goto err_destroy; + goto err_free_all;lockdep_assert_held (&dentry->d_inode->i_mutex);/* allocation complete, commit to creation */
@@ -4183,14 +4183,15 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, } err =cgroup_populate_dir (cgrp, true, root->subsys_mask); -/* If err < 0, we have a half-filled directory - oh well ;) */ +if (err) + goto err_destroy;mutex_unlock (&cgroup_mutex);mutex_unlock (&cgrp->dentry->d_inode->i_mutex);return 0 ; -err_destroy: +err_free_all:for_each_subsys (root, ss) {if (cgrp->subsys[ss->subsys_id]) ss->destroy (cgrp);
@@ -4198,9 +4199,15 @@ err_destroy:mutex_unlock (&cgroup_mutex);/* Release the reference count that we took on the superblock */ deactivate_super (sb); -err_free: +err_free_cgrp:kfree (cgrp);return err; + +err_destroy: +cgroup_destroy_locked (cgrp); +mutex_unlock (&cgroup_mutex); +mutex_unlock (&dentry->d_inode->i_mutex); +return err; }static int cgroup_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode)
Signature · 1 line
1.7.11.7
Tejun Heo
maintainerPATCH 16/17 cgroup: allow ->post_create() to fail
In reply to Tejun HeoThere could be cases where controllers want to do initialization operations which may fail from ->post_create(). This patch makes ->post_create() return -errno to indicate failure and online_css() relay such failures.
--- include/linux/cgroup.h | 2 +- kernel/cgroup.c | 29 +++++++++++++++++++---------- kernel/cgroup_freezer.c | 4 +++- 3 files changed, 23 insertions(+), 12 deletions(-)
include/linux/cgroup.h +1 -1
@@ -437,7 +437,7 @@ int cgroup_taskset_size(struct cgroup_taskset *tset);struct cgroup_subsys {struct cgroup_subsys_state *(*create)(struct cgroup *cgrp); -void (*post_create)(struct cgroup *cgrp); +int (*post_create)(struct cgroup *cgrp);void (*pre_destroy)(struct cgroup *cgrp);void (*destroy)(struct cgroup *cgrp);int (*can_attach)(struct cgroup *cgrp,struct cgroup_taskset *tset);
kernel/cgroup.c +19 -10
@@ -4041,14 +4041,18 @@ static void init_cgroup_css(struct cgroup_subsys_state *css,INIT_WORK (&css->dput_work, css_dput_fn); } -/* invoke ->post_create() on a new CSS and mark it online */ -static void online_css (struct cgroup_subsys *ss,struct cgroup *cgrp) +/* invoke ->post_create() on a new CSS and mark it online if successful */ +static int online_css (struct cgroup_subsys *ss,struct cgroup *cgrp) { +int ret =0 ; +lockdep_assert_held (&cgroup_mutex);if (ss->post_create) - ss->post_create (cgrp); - cgrp->subsys[ss->subsys_id]->flags |=CSS_ONLINE ; + ret = ss->post_create (cgrp); +if (!ret) + cgrp->subsys[ss->subsys_id]->flags |=CSS_ONLINE ; +return ret; }/* if the CSS is online, invoke ->pre_destory() on it and mark it offline */
@@ -4174,12 +4178,15 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,list_add_tail_rcu (&cgrp->sibling, &cgrp->parent->children); root->number_of_cgroups++; -for_each_subsys (root, ss) { -/* each css holds a ref to the cgroup's dentry */ +/* each css holds a ref to the cgroup's dentry */ +for_each_subsys (root, ss)dget (dentry); -/* creation succeeded, notify subsystems */ -online_css (ss, cgrp); +/* creation succeeded, notify subsystems */ +for_each_subsys (root, ss) { + err =online_css (ss, cgrp); +if (err) + goto err_destroy; } err =cgroup_populate_dir (cgrp, true, root->subsys_mask);
@@ -4393,7 +4400,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)BUG_ON (!list_empty (&init_task.tasks)); ss->active =1 ; -online_css (ss, dummytop); +BUG_ON (online_css (ss, dummytop));mutex_unlock (&cgroup_mutex);
@@ -4500,7 +4507,9 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)write_unlock (&css_set_lock); ss->active =1 ; -online_css (ss, dummytop); + ret =online_css (ss, dummytop); +if (ret) + goto err_unload;/* success! */ mutex_unlock (&cgroup_mutex);
kernel/cgroup_freezer.c +3 -1
@@ -112,7 +112,7 @@ static struct cgroup_subsys_state *freezer_create(struct cgroup *cgroup)* parent's freezing state while holding both parent's and our * freezer->lock. */ -static void freezer_post_create (struct cgroup *cgroup) +static int freezer_post_create (struct cgroup *cgroup) {struct freezer *freezer =cgroup_freezer (cgroup);struct freezer *parent =parent_freezer (freezer);
@@ -136,6 +136,8 @@ static void freezer_post_create(struct cgroup *cgroup)spin_unlock (&freezer->lock);if (parent)spin_unlock_irq (&parent->lock); + +return 0 ; }/**
Signature · 1 line
1.7.11.7
Tejun Heo
maintainerPATCH 17/17 cgroup: rename ->create/post_create/pre_destroy/destroy() to ->css_alloc/online/offline/free()
In reply to Tejun HeoRename cgroup_subsys css lifetime related callbacks to better describe what their roles are. Also, update documentation.
--- Documentation/cgroups/cgroups.txt | 49 ++++++++++++++++++++++--------------- block/blk-cgroup.c | 14 +++++------ include/linux/cgroup.h | 35 ++++++++++++++------------- kernel/cgroup.c | 51 ++++++++++++++++++++------------------- kernel/cgroup_freezer.c | 20 +++++++-------- kernel/cpuset.c | 10 ++++---- kernel/events/core.c | 8 +++--- kernel/sched/core.c | 16 ++++++------ mm/hugetlb_cgroup.c | 14 +++++------ mm/memcontrol.c | 12 ++++----- net/core/netprio_cgroup.c | 8 +++--- net/sched/cls_cgroup.c | 8 +++--- security/device_cgroup.c | 8 +++--- 13 files changed, 132 insertions(+), 121 deletions(-)
Documentation/cgroups/cgroups.txt +29 -20
@@ -553,16 +553,16 @@ call to cgroup_unload_subsys(). It should also set its_subsys.module = THIS_MODULE in its .c file. Each subsystem may export the following methods. The only mandatory -methods are create/destroy. Any others that are null are presumed to +methods are css_alloc/free. Any others that are null are presumed to be successful no-ops. -struct cgroup_subsys_state *create(struct cgroup *cgrp) +struct cgroup_subsys_state *css_alloc(struct cgroup *cgrp) (cgroup_mutex held by caller) -Called to create a subsystem state object for a cgroup. The +Called to allocate a subsystem state object for a cgroup. The subsystem should allocate its subsystem state object for the passed cgroup, returning a pointer to the new object on success or a -negative error code. On success, the subsystem pointer should point to +ERR_PTR() value. On success, the subsystem pointer should point to a structure of type cgroup_subsys_state (typically embedded in a larger subsystem-specific object), which will be initialized by the cgroup system. Note that this will be called at initialization to
@@ -571,24 +571,33 @@ identified by the passed cgroup object having a NULL parent (since it's the root of the hierarchy) and may be an appropriate place for initialization code. -void destroy(struct cgroup *cgrp) +int css_online(struct cgroup *cgrp) (cgroup_mutex held by caller) -The cgroup system is about to destroy the passed cgroup; the subsystem -should do any necessary cleanup and free its subsystem state -object. By the time this method is called, the cgroup has already been -unlinked from the file system and from the child list of its parent; -cgroup->parent is still valid. (Note - can also be called for a -newly-created cgroup if an error occurs after this subsystem's -create() method has been called for the new cgroup). - -int pre_destroy(struct cgroup *cgrp); - -Called before checking the reference count on each subsystem. This may -be useful for subsystems which have some extra references even if -there are not tasks in the cgroup. If pre_destroy() returns error code, -rmdir() will fail with it. From this behavior, pre_destroy() can be -called multiple times against a cgroup. +Called after @cgrp successfully completed all allocations and made +visible to cgroup_for_each_child/descendant_*() iterators. The +subsystem may choose to fail creation by returning -errno. This +callback can be used to implement reliable state sharing and +propagation along the hierarchy. See the comment on +cgroup_for_each_descendant_pre() for details. + +void css_offline(struct cgroup *cgrp); + +This is the counterpart of css_online() and called iff css_online() +has succeeded on @cgrp. This signifies the beginning of the end of +@cgrp. @cgrp is being removed and the subsystem should start dropping +all references it's holding on @cgrp. When all references are dropped, +cgroup removal will proceed to the next step - css_free(). After this +callback, @cgrp should be considered dead to the subsystem. + +void css_free(struct cgroup *cgrp) +(cgroup_mutex held by caller) + +The cgroup system is about to free @cgrp; the subsystem should free +its subsystem state object. By the time this method is called, @cgrp +is completely unused; @cgrp->parent is still valid. (Note - can also +be called for a newly-created cgroup if an error occurs after this +subsystem's create() method has been called for the new cgroup). int can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset) (cgroup_mutex held by caller)
block/blk-cgroup.c +7 -7
@@ -600,7 +600,7 @@ struct cftype blkcg_files[] = { };/** -* blkcg_pre_destroy - cgroup pre_destroy callback +* blkcg_css_offline - cgroup css_offline callback * @cgroup: cgroup of interest * * This function is called when @cgroup is about to go away and responsible
@@ -610,7 +610,7 @@ struct cftype blkcg_files[] = {* * This is the blkcg counterpart of ioc_release_fn(). */ -static void blkcg_pre_destroy (struct cgroup *cgroup) +static void blkcg_css_offline (struct cgroup *cgroup) {struct blkcg *blkcg =cgroup_to_blkcg (cgroup);
@@ -634,7 +634,7 @@ static void blkcg_pre_destroy(struct cgroup *cgroup)spin_unlock_irq (&blkcg->lock); } -static void blkcg_destroy (struct cgroup *cgroup) +static void blkcg_css_free (struct cgroup *cgroup) {struct blkcg *blkcg =cgroup_to_blkcg (cgroup);
@@ -642,7 +642,7 @@ static void blkcg_destroy(struct cgroup *cgroup)kfree (blkcg); } -static struct cgroup_subsys_state *blkcg_create (struct cgroup *cgroup) +static struct cgroup_subsys_state *blkcg_css_alloc (struct cgroup *cgroup) {static atomic64_t id_seq =ATOMIC64_INIT (0 );struct blkcg *blkcg;
@@ -739,10 +739,10 @@ static int blkcg_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)struct cgroup_subsys blkio_subsys = { .name ="blkio" , - .create = blkcg_create, + .css_alloc = blkcg_css_alloc, + .css_offline = blkcg_css_offline, + .css_free = blkcg_css_free, .can_attach = blkcg_can_attach, - .pre_destroy = blkcg_pre_destroy, - .destroy = blkcg_destroy, .subsys_id = blkio_subsys_id, .base_cftypes = blkcg_files, .module =THIS_MODULE ,
include/linux/cgroup.h +18 -17
@@ -82,7 +82,7 @@ struct cgroup_subsys_state {/* bits in struct cgroup_subsys_state flags field */ enum {CSS_ROOT = (1 <<0 ),/* this CSS is the root of the subsystem */ -CSS_ONLINE = (1 <<1 ),/* between ->post_create() and ->pre_destroy() */ +CSS_ONLINE = (1 <<1 ),/* between ->css_online() and ->css_offline() */ };/* Caller must verify that the css is not for root cgroup */
@@ -436,10 +436,11 @@ int cgroup_taskset_size(struct cgroup_taskset *tset);*/ struct cgroup_subsys { -struct cgroup_subsys_state *(*create)(struct cgroup *cgrp); -int (*post_create)(struct cgroup *cgrp); -void (*pre_destroy)(struct cgroup *cgrp); -void (*destroy)(struct cgroup *cgrp); +struct cgroup_subsys_state *(*css_alloc)(struct cgroup *cgrp); +int (*css_online)(struct cgroup *cgrp); +void (*css_offline)(struct cgroup *cgrp); +void (*css_free)(struct cgroup *cgrp); +int (*can_attach)(struct cgroup *cgrp,struct cgroup_taskset *tset);void (*cancel_attach)(struct cgroup *cgrp,struct cgroup_taskset *tset);void (*attach)(struct cgroup *cgrp,struct cgroup_taskset *tset);
@@ -538,13 +539,13 @@ static inline struct cgroup* task_cgroup(struct task_struct *task,* @cgroup: cgroup whose children to walk * * Walk @cgroup's children. Must be called under rcu_read_lock(). A child -* cgroup which hasn't finished ->post_create() or already has finished -* ->pre_destroy() may show up during traversal and it's each subsystem's +* cgroup which hasn't finished ->css_online() or already has finished +* ->css_offline() may show up during traversal and it's each subsystem's * responsibility to verify that each @pos is alive. * -* If a subsystem synchronizes against the parent in its ->post_create() -* and before starting iterating, a cgroup which finished ->post_create() -* is guaranteed to be visible in the future iterations. +* If a subsystem synchronizes against the parent in its ->css_online() and +* before starting iterating, a cgroup which finished ->css_online() is +* guaranteed to be visible in the future iterations. */ #define cgroup_for_each_child (pos, cgroup) \ list_for_each_entry_rcu(pos, &(cgroup)->children, sibling)
@@ -558,19 +559,19 @@ struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos,* @cgroup: cgroup whose descendants to walk * * Walk @cgroup's descendants. Must be called under rcu_read_lock(). A -* descendant cgroup which hasn't finished ->post_create() or already has -* finished ->pre_destroy() may show up during traversal and it's each +* descendant cgroup which hasn't finished ->css_online() or already has +* finished ->css_offline() may show up during traversal and it's each * subsystem's responsibility to verify that each @pos is alive. * -* If a subsystem synchronizes against the parent in its ->post_create() -* and before starting iterating, and synchronizes against @pos on each -* iteration, any descendant cgroup which finished ->post_create() is +* If a subsystem synchronizes against the parent in its ->css_online() and +* before starting iterating, and synchronizes against @pos on each +* iteration, any descendant cgroup which finished ->css_offline() is * guaranteed to be visible in the future iterations. * * In other words, the following guarantees that a descendant can't escape * state updates of its ancestors. * -* my_post_create(@cgrp) +* my_online(@cgrp) * { * Lock @cgrp->parent and @cgrp; * Inherit state from @cgrp->parent;
@@ -603,7 +604,7 @@ struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos,* iteration should lock and unlock both @pos->parent and @pos. * * Alternatively, a subsystem may choose to use a single global lock to -* synchronize ->post_create() and ->pre_destroy() against tree-walking +* synchronize ->css_online() and ->css_offline() against tree-walking * operations. */ #define cgroup_for_each_descendant_pre (pos, cgroup) \
kernel/cgroup.c +26 -25
142 lines not on this page · raw message
kernel/cgroup_freezer.c +10 -10
@@ -92,7 +92,7 @@ static const char *freezer_state_strs(unsigned int state)struct cgroup_subsys freezer_subsys; -static struct cgroup_subsys_state *freezer_create (struct cgroup *cgroup) +static struct cgroup_subsys_state *freezer_css_alloc (struct cgroup *cgroup) {struct freezer *freezer;
@@ -105,14 +105,14 @@ static struct cgroup_subsys_state *freezer_create(struct cgroup *cgroup) }/** -* freezer_post_create - commit creation of a freezer cgroup +* freezer_css_online - commit creation of a freezer cgroup * @cgroup: cgroup being created * * We're committing to creation of @cgroup. Mark it online and inherit * parent's freezing state while holding both parent's and our * freezer->lock. */ -static int freezer_post_create (struct cgroup *cgroup) +static int freezer_css_online (struct cgroup *cgroup) {struct freezer *freezer =cgroup_freezer (cgroup);struct freezer *parent =parent_freezer (freezer);
@@ -141,13 +141,13 @@ static int freezer_post_create(struct cgroup *cgroup) }/** -* freezer_pre_destroy - initiate destruction of @cgroup +* freezer_css_offline - initiate destruction of @cgroup * @cgroup: cgroup being destroyed * * @cgroup is going away. Mark it dead and decrement system_freezing_count * if it was holding one. */ -static void freezer_pre_destroy (struct cgroup *cgroup) +static void freezer_css_offline (struct cgroup *cgroup) {struct freezer *freezer =cgroup_freezer (cgroup);
@@ -161,7 +161,7 @@ static void freezer_pre_destroy(struct cgroup *cgroup)spin_unlock_irq (&freezer->lock); } -static void freezer_destroy (struct cgroup *cgroup) +static void freezer_css_free (struct cgroup *cgroup) {kfree (cgroup_freezer (cgroup)); }
@@ -477,10 +477,10 @@ static struct cftype files[] = {struct cgroup_subsys freezer_subsys = { .name ="freezer" , - .create = freezer_create, - .post_create = freezer_post_create, - .pre_destroy = freezer_pre_destroy, - .destroy = freezer_destroy, + .css_alloc = freezer_css_alloc, + .css_online = freezer_css_online, + .css_offline = freezer_css_offline, + .css_free = freezer_css_free, .subsys_id = freezer_subsys_id, .attach = freezer_attach, .fork = freezer_fork,
kernel/cpuset.c +5 -5
@@ -1821,11 +1821,11 @@ static void cpuset_post_clone(struct cgroup *cgroup) }/* -* cpuset_create - create a cpuset +* cpuset_css_alloc - allocate a cpuset css * cont: control group that the new cpuset will be part of */ -static struct cgroup_subsys_state *cpuset_create (struct cgroup *cont) +static struct cgroup_subsys_state *cpuset_css_alloc (struct cgroup *cont) {struct cpuset *cs;struct cpuset *parent;
@@ -1864,7 +1864,7 @@ static struct cgroup_subsys_state *cpuset_create(struct cgroup *cont)* will call async_rebuild_sched_domains(). */ -static void cpuset_destroy (struct cgroup *cont) +static void cpuset_css_free (struct cgroup *cont) {struct cpuset *cs =cgroup_cs (cont);
@@ -1878,8 +1878,8 @@ static void cpuset_destroy(struct cgroup *cont)struct cgroup_subsys cpuset_subsys = { .name ="cpuset" , - .create = cpuset_create, - .destroy = cpuset_destroy, + .css_alloc = cpuset_css_alloc, + .css_free = cpuset_css_free, .can_attach = cpuset_can_attach, .attach = cpuset_attach, .post_clone = cpuset_post_clone,
kernel/events/core.c +4 -4
@@ -7434,7 +7434,7 @@ unlock:device_initcall (perf_event_sysfs_init);#ifdef CONFIG_CGROUP_PERF -static struct cgroup_subsys_state *perf_cgroup_create (struct cgroup *cont) +static struct cgroup_subsys_state *perf_cgroup_css_alloc (struct cgroup *cont) {struct perf_cgroup *jc;
@@ -7451,7 +7451,7 @@ static struct cgroup_subsys_state *perf_cgroup_create(struct cgroup *cont)return &jc->css; } -static void perf_cgroup_destroy (struct cgroup *cont) +static void perf_cgroup_css_free (struct cgroup *cont) {struct perf_cgroup *jc; jc = container_of(cgroup_subsys_state(cont, perf_subsys_id),
@@ -7492,8 +7492,8 @@ static void perf_cgroup_exit(struct cgroup *cgrp, struct cgroup *old_cgrp,struct cgroup_subsys perf_subsys = { .name ="perf_event" , .subsys_id = perf_subsys_id, - .create = perf_cgroup_create, - .destroy = perf_cgroup_destroy, + .css_alloc = perf_cgroup_css_alloc, + .css_free = perf_cgroup_css_free, .exit = perf_cgroup_exit, .attach = perf_cgroup_attach,
kernel/sched/core.c +8 -8
@@ -7468,7 +7468,7 @@ static inline struct task_group *cgroup_tg(struct cgroup *cgrp) struct task_group, css); } -static struct cgroup_subsys_state *cpu_cgroup_create (struct cgroup *cgrp) +static struct cgroup_subsys_state *cpu_cgroup_css_alloc (struct cgroup *cgrp) {struct task_group *tg, *parent;
@@ -7485,7 +7485,7 @@ static struct cgroup_subsys_state *cpu_cgroup_create(struct cgroup *cgrp)return &tg->css; } -static void cpu_cgroup_destroy (struct cgroup *cgrp) +static void cpu_cgroup_css_free (struct cgroup *cgrp) {struct task_group *tg =cgroup_tg (cgrp);
@@ -7845,8 +7845,8 @@ static struct cftype cpu_files[] = {struct cgroup_subsys cpu_cgroup_subsys = { .name ="cpu" , - .create = cpu_cgroup_create, - .destroy = cpu_cgroup_destroy, + .css_alloc = cpu_cgroup_css_alloc, + .css_free = cpu_cgroup_css_free, .can_attach = cpu_cgroup_can_attach, .attach = cpu_cgroup_attach, .exit = cpu_cgroup_exit,
@@ -7869,7 +7869,7 @@ struct cgroup_subsys cpu_cgroup_subsys = {struct cpuacct root_cpuacct;/* create a new cpu accounting group */ -static struct cgroup_subsys_state *cpuacct_create (struct cgroup *cgrp) +static struct cgroup_subsys_state *cpuacct_css_alloc (struct cgroup *cgrp) {struct cpuacct *ca;
@@ -7899,7 +7899,7 @@ out: }/* destroy an existing cpu accounting group */ -static void cpuacct_destroy (struct cgroup *cgrp) +static void cpuacct_css_free (struct cgroup *cgrp) {struct cpuacct *ca =cgroup_ca (cgrp);
@@ -8070,8 +8070,8 @@ void cpuacct_charge(struct task_struct *tsk, u64 cputime)struct cgroup_subsys cpuacct_subsys = { .name ="cpuacct" , - .create = cpuacct_create, - .destroy = cpuacct_destroy, + .css_alloc = cpuacct_css_alloc, + .css_free = cpuacct_css_free, .subsys_id = cpuacct_subsys_id, .base_cftypes = files, };
mm/hugetlb_cgroup.c +7 -7
@@ -77,7 +77,7 @@ static inline bool hugetlb_cgroup_have_usage(struct cgroup *cg)return false; } -static struct cgroup_subsys_state *hugetlb_cgroup_create (struct cgroup *cgroup) +static struct cgroup_subsys_state *hugetlb_cgroup_css_alloc (struct cgroup *cgroup) {int idx;struct cgroup *parent_cgroup;
@@ -101,7 +101,7 @@ static struct cgroup_subsys_state *hugetlb_cgroup_create(struct cgroup *cgroup)return &h_cgroup->css; } -static void hugetlb_cgroup_destroy (struct cgroup *cgroup) +static void hugetlb_cgroup_css_free (struct cgroup *cgroup) {struct hugetlb_cgroup *h_cgroup;
@@ -155,7 +155,7 @@ out:* Force the hugetlb cgroup to empty the hugetlb resources by moving them to * the parent cgroup. */ -static void hugetlb_cgroup_pre_destroy (struct cgroup *cgroup) +static void hugetlb_cgroup_css_offline (struct cgroup *cgroup) {struct hstate *h;struct page *page;
@@ -404,8 +404,8 @@ void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage)struct cgroup_subsys hugetlb_subsys = { .name ="hugetlb" , - .create = hugetlb_cgroup_create, - .pre_destroy = hugetlb_cgroup_pre_destroy, - .destroy = hugetlb_cgroup_destroy, - .subsys_id = hugetlb_subsys_id, + .css_alloc = hugetlb_cgroup_css_alloc, + .css_offline = hugetlb_cgroup_css_offline, + .css_free = hugetlb_cgroup_css_free, + .subsys_id = hugetlb_subsys_id, };
mm/memcontrol.c +6 -6
@@ -4922,7 +4922,7 @@ err_cleanup: }static struct cgroup_subsys_state *__ref -mem_cgroup_create (struct cgroup *cont) +mem_cgroup_css_alloc (struct cgroup *cont) {struct mem_cgroup *memcg, *parent;long error = -ENOMEM ;
@@ -5003,14 +5003,14 @@ free_out:return ERR_PTR (error); } -static void mem_cgroup_pre_destroy (struct cgroup *cont) +static void mem_cgroup_css_offline (struct cgroup *cont) {struct mem_cgroup *memcg =mem_cgroup_from_cont (cont);mem_cgroup_reparent_charges (memcg); } -static void mem_cgroup_destroy (struct cgroup *cont) +static void mem_cgroup_css_free (struct cgroup *cont) {struct mem_cgroup *memcg =mem_cgroup_from_cont (cont);
@@ -5600,9 +5600,9 @@ static void mem_cgroup_move_task(struct cgroup *cont,struct cgroup_subsys mem_cgroup_subsys = { .name ="memory" , .subsys_id = mem_cgroup_subsys_id, - .create = mem_cgroup_create, - .pre_destroy = mem_cgroup_pre_destroy, - .destroy = mem_cgroup_destroy, + .css_alloc = mem_cgroup_css_alloc, + .css_offline = mem_cgroup_css_offline, + .css_free = mem_cgroup_css_free, .can_attach = mem_cgroup_can_attach, .cancel_attach = mem_cgroup_cancel_attach, .attach = mem_cgroup_move_task,
net/core/netprio_cgroup.c +4 -4
@@ -108,7 +108,7 @@ static int write_update_netdev_table(struct net_device *dev)return ret; } -static struct cgroup_subsys_state *cgrp_create (struct cgroup *cgrp) +static struct cgroup_subsys_state *cgrp_css_alloc (struct cgroup *cgrp) {struct cgroup_netprio_state *cs;int ret = -EINVAL ;
@@ -132,7 +132,7 @@ out:return ERR_PTR (ret); } -static void cgrp_destroy (struct cgroup *cgrp) +static void cgrp_css_free (struct cgroup *cgrp) {struct cgroup_netprio_state *cs;struct net_device *dev;
@@ -276,8 +276,8 @@ static struct cftype ss_files[] = {struct cgroup_subsys net_prio_subsys = { .name ="net_prio" , - .create = cgrp_create, - .destroy = cgrp_destroy, + .css_alloc = cgrp_css_alloc, + .css_free = cgrp_css_free, .attach = net_prio_attach, .subsys_id = net_prio_subsys_id, .base_cftypes = ss_files,
net/sched/cls_cgroup.c +4 -4
@@ -34,7 +34,7 @@ static inline struct cgroup_cls_state *task_cls_state(struct task_struct *p) struct cgroup_cls_state, css); } -static struct cgroup_subsys_state *cgrp_create (struct cgroup *cgrp) +static struct cgroup_subsys_state *cgrp_css_alloc (struct cgroup *cgrp) {struct cgroup_cls_state *cs;
@@ -48,7 +48,7 @@ static struct cgroup_subsys_state *cgrp_create(struct cgroup *cgrp)return &cs->css; } -static void cgrp_destroy (struct cgroup *cgrp) +static void cgrp_css_free (struct cgroup *cgrp) {kfree (cgrp_cls_state (cgrp)); }
@@ -75,8 +75,8 @@ static struct cftype ss_files[] = {struct cgroup_subsys net_cls_subsys = { .name ="net_cls" , - .create = cgrp_create, - .destroy = cgrp_destroy, + .css_alloc = cgrp_css_alloc, + .css_free = cgrp_css_free, .subsys_id = net_cls_subsys_id, .base_cftypes = ss_files, .module =THIS_MODULE ,
security/device_cgroup.c +4 -4
@@ -180,7 +180,7 @@ static void dev_exception_clean(struct dev_cgroup *dev_cgroup)/* * called from kernel/cgroup.c with cgroup_lock() held. */ -static struct cgroup_subsys_state *devcgroup_create (struct cgroup *cgroup) +static struct cgroup_subsys_state *devcgroup_css_alloc (struct cgroup *cgroup) {struct dev_cgroup *dev_cgroup, *parent_dev_cgroup;struct cgroup *parent_cgroup;
@@ -210,7 +210,7 @@ static struct cgroup_subsys_state *devcgroup_create(struct cgroup *cgroup)return &dev_cgroup->css; } -static void devcgroup_destroy (struct cgroup *cgroup) +static void devcgroup_css_free (struct cgroup *cgroup) {struct dev_cgroup *dev_cgroup;
@@ -564,8 +564,8 @@ static struct cftype dev_cgroup_files[] = {struct cgroup_subsys devices_subsys = { .name ="devices" , .can_attach = devcgroup_can_attach, - .create = devcgroup_create, - .destroy = devcgroup_destroy, + .css_alloc = devcgroup_css_alloc, + .css_free = devcgroup_css_free, .subsys_id = devices_subsys_id, .base_cftypes = dev_cgroup_files,
Signature · 1 line
1.7.11.7
Quoted 19 lines · Tejun Heo
Hello,
This became a rather large patchset mostly because there are a lot of weirdities and subtle breakages in create/destroy/load/unload paths. The goal of the patchset is allowing ->post_create() to fail and renaming ->create/post_create/pre_destroy/destroy() to ->css_alloc/css_online/css_offline/css_free().
This patchset contains the following seventeen patches.
0001-cgroup-remove-incorrect-dget-dput-pair-in-cgroup_cre.patch 0002-cgroup-initialize-cgrp-allcg_node-in-init_cgroup_hou.patch 0003-cgroup-open-code-cgroup_create_dir.patch 0004-cgroup-create-directory-before-linking-while-creatin.patch 0005-cgroup-cgroup-dentry-isn-t-a-RCU-pointer.patch 0006-cgroup-remove-duplicate-RCU-free-on-struct-cgroup.patch 0007-cgroup-make-CSS_-flags-bit-masks-instead-of-bit-posi.patch 0008-cgroup-trivial-cleanup-for-cgroup_init-load_subsys.patch 0009-cgroup-lock-cgroup_mutex-in-cgroup_init_subsys.patch
Quoted 9 lines
0010-cgroup-fix-harmless-bugs-in-cgroup_load_subsys-fail-.patch 0011-cgroup-separate-out-cgroup_destroy_locked.patch 0012-cgroup-introduce-CSS_ONLINE-flag-and-on-offline_css-.patch 0013-cgroup-simplify-cgroup_load_subsys-failure-path.patch 0014-cgroup-use-mutex_trylock-when-grabbing-i_mutex-of-a-.patch 0015-cgroup-update-cgroup_create-failure-path.patch 0016-cgroup-allow-post_create-to-fail.patch 0017-cgroup-rename-create-post_create-pre_destroy-destroy.patch
except 0006-cgroup-remove-duplicate-RCU-free-on-struct-cgroup.patch
Quoted 18 lines
0001 is a bugfix. Tagged for -stable. I don't I'll push it through for-3.7-fixes tho. This has been broken forever and nobody reported anything yet.
0002-0011 are various fixes and cleanups to prepare for the following changes. Each should be self-explanatory.
0012-0015 are preparation patches more directly related to allowing failure of ->post_create().
0016 allows ->post_create() to fail.
0017 renames ops and updates documentation.
This patchst is on top of cgroup/for-3.8 and available on the following git branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.gitreview-cgroup-online-may-fail
Tejun Heo
maintainerQuoted 3 lines · Li Zefan
Acked-by Li Zefan <[email protected]>except 0006-cgroup-remove-duplicate-RCU-free-on-struct-cgroup.patch
Patchset applied to cgroup/for-3.8 sans 0006.
Thanks.
Signature · 1 line
tejun
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 3 lines · Li Zefan
Acked-by Li Zefan <[email protected]>except 0006-cgroup-remove-duplicate-RCU-free-on-struct-cgroup.patch
Patchset applied to cgroup/for-3.8 sans 0006.
Thanks.
Signature · 1 line
tejun