Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-4.13-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup

Pull cgroup fixes from Tejun Heo:
"Several cgroup bug fixes.

- cgroup core was calling a migration callback on empty migrations,
which could make cpuset crash.

- There was a very subtle bug where the controller interface files
aren't created directly when cgroup2 is mounted. Because later
operations create them, this bug didn't get noticed earlier.

- Failed writes to cgroup.subtree_control were incorrectly returning
zero"

* 'for-4.13-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup:
cgroup: fix error return value from cgroup_subtree_control()
cgroup: create dfl_root files on subsys registration
cgroup: don't call migration methods if there are no tasks to migrate

+40 -29
+3
kernel/cgroup/cgroup-internal.h
··· 33 33 struct list_head src_csets; 34 34 struct list_head dst_csets; 35 35 36 + /* the number of tasks in the set */ 37 + int nr_tasks; 38 + 36 39 /* the subsys currently being processed */ 37 40 int ssid; 38 41
+37 -29
kernel/cgroup/cgroup.c
··· 2006 2006 if (!cset->mg_src_cgrp) 2007 2007 return; 2008 2008 2009 + mgctx->tset.nr_tasks++; 2010 + 2009 2011 list_move_tail(&task->cg_list, &cset->mg_tasks); 2010 2012 if (list_empty(&cset->mg_node)) 2011 2013 list_add_tail(&cset->mg_node, ··· 2096 2094 struct css_set *cset, *tmp_cset; 2097 2095 int ssid, failed_ssid, ret; 2098 2096 2099 - /* methods shouldn't be called if no task is actually migrating */ 2100 - if (list_empty(&tset->src_csets)) 2101 - return 0; 2102 - 2103 2097 /* check that we can legitimately attach to the cgroup */ 2104 - do_each_subsys_mask(ss, ssid, mgctx->ss_mask) { 2105 - if (ss->can_attach) { 2106 - tset->ssid = ssid; 2107 - ret = ss->can_attach(tset); 2108 - if (ret) { 2109 - failed_ssid = ssid; 2110 - goto out_cancel_attach; 2098 + if (tset->nr_tasks) { 2099 + do_each_subsys_mask(ss, ssid, mgctx->ss_mask) { 2100 + if (ss->can_attach) { 2101 + tset->ssid = ssid; 2102 + ret = ss->can_attach(tset); 2103 + if (ret) { 2104 + failed_ssid = ssid; 2105 + goto out_cancel_attach; 2106 + } 2111 2107 } 2112 - } 2113 - } while_each_subsys_mask(); 2108 + } while_each_subsys_mask(); 2109 + } 2114 2110 2115 2111 /* 2116 2112 * Now that we're guaranteed success, proceed to move all tasks to ··· 2137 2137 */ 2138 2138 tset->csets = &tset->dst_csets; 2139 2139 2140 - do_each_subsys_mask(ss, ssid, mgctx->ss_mask) { 2141 - if (ss->attach) { 2142 - tset->ssid = ssid; 2143 - ss->attach(tset); 2144 - } 2145 - } while_each_subsys_mask(); 2140 + if (tset->nr_tasks) { 2141 + do_each_subsys_mask(ss, ssid, mgctx->ss_mask) { 2142 + if (ss->attach) { 2143 + tset->ssid = ssid; 2144 + ss->attach(tset); 2145 + } 2146 + } while_each_subsys_mask(); 2147 + } 2146 2148 2147 2149 ret = 0; 2148 2150 goto out_release_tset; 2149 2151 2150 2152 out_cancel_attach: 2151 - do_each_subsys_mask(ss, ssid, mgctx->ss_mask) { 2152 - if (ssid == failed_ssid) 2153 - break; 2154 - if (ss->cancel_attach) { 2155 - tset->ssid = ssid; 2156 - ss->cancel_attach(tset); 2157 - } 2158 - } while_each_subsys_mask(); 2153 + if (tset->nr_tasks) { 2154 + do_each_subsys_mask(ss, ssid, mgctx->ss_mask) { 2155 + if (ssid == failed_ssid) 2156 + break; 2157 + if (ss->cancel_attach) { 2158 + tset->ssid = ssid; 2159 + ss->cancel_attach(tset); 2160 + } 2161 + } while_each_subsys_mask(); 2162 + } 2159 2163 out_release_tset: 2160 2164 spin_lock_irq(&css_set_lock); 2161 2165 list_splice_init(&tset->dst_csets, &tset->src_csets); ··· 3001 2997 cgrp->subtree_control &= ~disable; 3002 2998 3003 2999 ret = cgroup_apply_control(cgrp); 3004 - 3005 3000 cgroup_finalize_control(cgrp, ret); 3001 + if (ret) 3002 + goto out_unlock; 3006 3003 3007 3004 kernfs_activate(cgrp->kn); 3008 - ret = 0; 3009 3005 out_unlock: 3010 3006 cgroup_kn_unlock(of->kn); 3011 3007 return ret ?: nbytes; ··· 4673 4669 4674 4670 if (ss->bind) 4675 4671 ss->bind(init_css_set.subsys[ssid]); 4672 + 4673 + mutex_lock(&cgroup_mutex); 4674 + css_populate_dir(init_css_set.subsys[ssid]); 4675 + mutex_unlock(&cgroup_mutex); 4676 4676 } 4677 4677 4678 4678 /* init_css_set.subsys[] has been updated, re-hash */