cgroup-v1.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  1. #include "cgroup-internal.h"
  2. #include <linux/ctype.h>
  3. #include <linux/kmod.h>
  4. #include <linux/sort.h>
  5. #include <linux/delay.h>
  6. #include <linux/mm.h>
  7. #include <linux/sched/signal.h>
  8. #include <linux/sched/task.h>
  9. #include <linux/magic.h>
  10. #include <linux/slab.h>
  11. #include <linux/vmalloc.h>
  12. #include <linux/delayacct.h>
  13. #include <linux/pid_namespace.h>
  14. #include <linux/cgroupstats.h>
  15. #include <trace/events/cgroup.h>
  16. /*
  17. * pidlists linger the following amount before being destroyed. The goal
  18. * is avoiding frequent destruction in the middle of consecutive read calls
  19. * Expiring in the middle is a performance problem not a correctness one.
  20. * 1 sec should be enough.
  21. */
  22. #define CGROUP_PIDLIST_DESTROY_DELAY HZ
  23. /* Controllers blocked by the commandline in v1 */
  24. static u16 cgroup_no_v1_mask;
  25. /*
  26. * pidlist destructions need to be flushed on cgroup destruction. Use a
  27. * separate workqueue as flush domain.
  28. */
  29. static struct workqueue_struct *cgroup_pidlist_destroy_wq;
  30. /*
  31. * Protects cgroup_subsys->release_agent_path. Modifying it also requires
  32. * cgroup_mutex. Reading requires either cgroup_mutex or this spinlock.
  33. */
  34. static DEFINE_SPINLOCK(release_agent_path_lock);
  35. bool cgroup1_ssid_disabled(int ssid)
  36. {
  37. return cgroup_no_v1_mask & (1 << ssid);
  38. }
  39. /**
  40. * cgroup_attach_task_all - attach task 'tsk' to all cgroups of task 'from'
  41. * @from: attach to all cgroups of a given task
  42. * @tsk: the task to be attached
  43. */
  44. int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk)
  45. {
  46. struct cgroup_root *root;
  47. int retval = 0;
  48. mutex_lock(&cgroup_mutex);
  49. percpu_down_write(&cgroup_threadgroup_rwsem);
  50. for_each_root(root) {
  51. struct cgroup *from_cgrp;
  52. if (root == &cgrp_dfl_root)
  53. continue;
  54. spin_lock_irq(&css_set_lock);
  55. from_cgrp = task_cgroup_from_root(from, root);
  56. spin_unlock_irq(&css_set_lock);
  57. retval = cgroup_attach_task(from_cgrp, tsk, false);
  58. if (retval)
  59. break;
  60. }
  61. percpu_up_write(&cgroup_threadgroup_rwsem);
  62. mutex_unlock(&cgroup_mutex);
  63. return retval;
  64. }
  65. EXPORT_SYMBOL_GPL(cgroup_attach_task_all);
  66. /**
  67. * cgroup_trasnsfer_tasks - move tasks from one cgroup to another
  68. * @to: cgroup to which the tasks will be moved
  69. * @from: cgroup in which the tasks currently reside
  70. *
  71. * Locking rules between cgroup_post_fork() and the migration path
  72. * guarantee that, if a task is forking while being migrated, the new child
  73. * is guaranteed to be either visible in the source cgroup after the
  74. * parent's migration is complete or put into the target cgroup. No task
  75. * can slip out of migration through forking.
  76. */
  77. int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from)
  78. {
  79. DEFINE_CGROUP_MGCTX(mgctx);
  80. struct cgrp_cset_link *link;
  81. struct css_task_iter it;
  82. struct task_struct *task;
  83. int ret;
  84. if (cgroup_on_dfl(to))
  85. return -EINVAL;
  86. ret = cgroup_migrate_vet_dst(to);
  87. if (ret)
  88. return ret;
  89. mutex_lock(&cgroup_mutex);
  90. percpu_down_write(&cgroup_threadgroup_rwsem);
  91. /* all tasks in @from are being moved, all csets are source */
  92. spin_lock_irq(&css_set_lock);
  93. list_for_each_entry(link, &from->cset_links, cset_link)
  94. cgroup_migrate_add_src(link->cset, to, &mgctx);
  95. spin_unlock_irq(&css_set_lock);
  96. ret = cgroup_migrate_prepare_dst(&mgctx);
  97. if (ret)
  98. goto out_err;
  99. /*
  100. * Migrate tasks one-by-one until @from is empty. This fails iff
  101. * ->can_attach() fails.
  102. */
  103. do {
  104. css_task_iter_start(&from->self, 0, &it);
  105. do {
  106. task = css_task_iter_next(&it);
  107. } while (task && (task->flags & PF_EXITING));
  108. if (task)
  109. get_task_struct(task);
  110. css_task_iter_end(&it);
  111. if (task) {
  112. ret = cgroup_migrate(task, false, &mgctx);
  113. if (!ret)
  114. TRACE_CGROUP_PATH(transfer_tasks, to, task, false);
  115. put_task_struct(task);
  116. }
  117. } while (task && !ret);
  118. out_err:
  119. cgroup_migrate_finish(&mgctx);
  120. percpu_up_write(&cgroup_threadgroup_rwsem);
  121. mutex_unlock(&cgroup_mutex);
  122. return ret;
  123. }
  124. /*
  125. * Stuff for reading the 'tasks'/'procs' files.
  126. *
  127. * Reading this file can return large amounts of data if a cgroup has
  128. * *lots* of attached tasks. So it may need several calls to read(),
  129. * but we cannot guarantee that the information we produce is correct
  130. * unless we produce it entirely atomically.
  131. *
  132. */
  133. /* which pidlist file are we talking about? */
  134. enum cgroup_filetype {
  135. CGROUP_FILE_PROCS,
  136. CGROUP_FILE_TASKS,
  137. };
  138. /*
  139. * A pidlist is a list of pids that virtually represents the contents of one
  140. * of the cgroup files ("procs" or "tasks"). We keep a list of such pidlists,
  141. * a pair (one each for procs, tasks) for each pid namespace that's relevant
  142. * to the cgroup.
  143. */
  144. struct cgroup_pidlist {
  145. /*
  146. * used to find which pidlist is wanted. doesn't change as long as
  147. * this particular list stays in the list.
  148. */
  149. struct { enum cgroup_filetype type; struct pid_namespace *ns; } key;
  150. /* array of xids */
  151. pid_t *list;
  152. /* how many elements the above list has */
  153. int length;
  154. /* each of these stored in a list by its cgroup */
  155. struct list_head links;
  156. /* pointer to the cgroup we belong to, for list removal purposes */
  157. struct cgroup *owner;
  158. /* for delayed destruction */
  159. struct delayed_work destroy_dwork;
  160. };
  161. /*
  162. * The following two functions "fix" the issue where there are more pids
  163. * than kmalloc will give memory for; in such cases, we use vmalloc/vfree.
  164. * TODO: replace with a kernel-wide solution to this problem
  165. */
  166. #define PIDLIST_TOO_LARGE(c) ((c) * sizeof(pid_t) > (PAGE_SIZE * 2))
  167. static void *pidlist_allocate(int count)
  168. {
  169. if (PIDLIST_TOO_LARGE(count))
  170. return vmalloc(array_size(count, sizeof(pid_t)));
  171. else
  172. return kmalloc_array(count, sizeof(pid_t), GFP_KERNEL);
  173. }
  174. static void pidlist_free(void *p)
  175. {
  176. kvfree(p);
  177. }
  178. /*
  179. * Used to destroy all pidlists lingering waiting for destroy timer. None
  180. * should be left afterwards.
  181. */
  182. void cgroup1_pidlist_destroy_all(struct cgroup *cgrp)
  183. {
  184. struct cgroup_pidlist *l, *tmp_l;
  185. mutex_lock(&cgrp->pidlist_mutex);
  186. list_for_each_entry_safe(l, tmp_l, &cgrp->pidlists, links)
  187. mod_delayed_work(cgroup_pidlist_destroy_wq, &l->destroy_dwork, 0);
  188. mutex_unlock(&cgrp->pidlist_mutex);
  189. flush_workqueue(cgroup_pidlist_destroy_wq);
  190. BUG_ON(!list_empty(&cgrp->pidlists));
  191. }
  192. static void cgroup_pidlist_destroy_work_fn(struct work_struct *work)
  193. {
  194. struct delayed_work *dwork = to_delayed_work(work);
  195. struct cgroup_pidlist *l = container_of(dwork, struct cgroup_pidlist,
  196. destroy_dwork);
  197. struct cgroup_pidlist *tofree = NULL;
  198. mutex_lock(&l->owner->pidlist_mutex);
  199. /*
  200. * Destroy iff we didn't get queued again. The state won't change
  201. * as destroy_dwork can only be queued while locked.
  202. */
  203. if (!delayed_work_pending(dwork)) {
  204. list_del(&l->links);
  205. pidlist_free(l->list);
  206. put_pid_ns(l->key.ns);
  207. tofree = l;
  208. }
  209. mutex_unlock(&l->owner->pidlist_mutex);
  210. kfree(tofree);
  211. }
  212. /*
  213. * pidlist_uniq - given a kmalloc()ed list, strip out all duplicate entries
  214. * Returns the number of unique elements.
  215. */
  216. static int pidlist_uniq(pid_t *list, int length)
  217. {
  218. int src, dest = 1;
  219. /*
  220. * we presume the 0th element is unique, so i starts at 1. trivial
  221. * edge cases first; no work needs to be done for either
  222. */
  223. if (length == 0 || length == 1)
  224. return length;
  225. /* src and dest walk down the list; dest counts unique elements */
  226. for (src = 1; src < length; src++) {
  227. /* find next unique element */
  228. while (list[src] == list[src-1]) {
  229. src++;
  230. if (src == length)
  231. goto after;
  232. }
  233. /* dest always points to where the next unique element goes */
  234. list[dest] = list[src];
  235. dest++;
  236. }
  237. after:
  238. return dest;
  239. }
  240. /*
  241. * The two pid files - task and cgroup.procs - guaranteed that the result
  242. * is sorted, which forced this whole pidlist fiasco. As pid order is
  243. * different per namespace, each namespace needs differently sorted list,
  244. * making it impossible to use, for example, single rbtree of member tasks
  245. * sorted by task pointer. As pidlists can be fairly large, allocating one
  246. * per open file is dangerous, so cgroup had to implement shared pool of
  247. * pidlists keyed by cgroup and namespace.
  248. */
  249. static int cmppid(const void *a, const void *b)
  250. {
  251. return *(pid_t *)a - *(pid_t *)b;
  252. }
  253. static struct cgroup_pidlist *cgroup_pidlist_find(struct cgroup *cgrp,
  254. enum cgroup_filetype type)
  255. {
  256. struct cgroup_pidlist *l;
  257. /* don't need task_nsproxy() if we're looking at ourself */
  258. struct pid_namespace *ns = task_active_pid_ns(current);
  259. lockdep_assert_held(&cgrp->pidlist_mutex);
  260. list_for_each_entry(l, &cgrp->pidlists, links)
  261. if (l->key.type == type && l->key.ns == ns)
  262. return l;
  263. return NULL;
  264. }
  265. /*
  266. * find the appropriate pidlist for our purpose (given procs vs tasks)
  267. * returns with the lock on that pidlist already held, and takes care
  268. * of the use count, or returns NULL with no locks held if we're out of
  269. * memory.
  270. */
  271. static struct cgroup_pidlist *cgroup_pidlist_find_create(struct cgroup *cgrp,
  272. enum cgroup_filetype type)
  273. {
  274. struct cgroup_pidlist *l;
  275. lockdep_assert_held(&cgrp->pidlist_mutex);
  276. l = cgroup_pidlist_find(cgrp, type);
  277. if (l)
  278. return l;
  279. /* entry not found; create a new one */
  280. l = kzalloc(sizeof(struct cgroup_pidlist), GFP_KERNEL);
  281. if (!l)
  282. return l;
  283. INIT_DELAYED_WORK(&l->destroy_dwork, cgroup_pidlist_destroy_work_fn);
  284. l->key.type = type;
  285. /* don't need task_nsproxy() if we're looking at ourself */
  286. l->key.ns = get_pid_ns(task_active_pid_ns(current));
  287. l->owner = cgrp;
  288. list_add(&l->links, &cgrp->pidlists);
  289. return l;
  290. }
  291. /**
  292. * cgroup_task_count - count the number of tasks in a cgroup.
  293. * @cgrp: the cgroup in question
  294. */
  295. int cgroup_task_count(const struct cgroup *cgrp)
  296. {
  297. int count = 0;
  298. struct cgrp_cset_link *link;
  299. spin_lock_irq(&css_set_lock);
  300. list_for_each_entry(link, &cgrp->cset_links, cset_link)
  301. count += link->cset->nr_tasks;
  302. spin_unlock_irq(&css_set_lock);
  303. return count;
  304. }
  305. /*
  306. * Load a cgroup's pidarray with either procs' tgids or tasks' pids
  307. */
  308. static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type,
  309. struct cgroup_pidlist **lp)
  310. {
  311. pid_t *array;
  312. int length;
  313. int pid, n = 0; /* used for populating the array */
  314. struct css_task_iter it;
  315. struct task_struct *tsk;
  316. struct cgroup_pidlist *l;
  317. lockdep_assert_held(&cgrp->pidlist_mutex);
  318. /*
  319. * If cgroup gets more users after we read count, we won't have
  320. * enough space - tough. This race is indistinguishable to the
  321. * caller from the case that the additional cgroup users didn't
  322. * show up until sometime later on.
  323. */
  324. length = cgroup_task_count(cgrp);
  325. array = pidlist_allocate(length);
  326. if (!array)
  327. return -ENOMEM;
  328. /* now, populate the array */
  329. css_task_iter_start(&cgrp->self, 0, &it);
  330. while ((tsk = css_task_iter_next(&it))) {
  331. if (unlikely(n == length))
  332. break;
  333. /* get tgid or pid for procs or tasks file respectively */
  334. if (type == CGROUP_FILE_PROCS)
  335. pid = task_tgid_vnr(tsk);
  336. else
  337. pid = task_pid_vnr(tsk);
  338. if (pid > 0) /* make sure to only use valid results */
  339. array[n++] = pid;
  340. }
  341. css_task_iter_end(&it);
  342. length = n;
  343. /* now sort & (if procs) strip out duplicates */
  344. sort(array, length, sizeof(pid_t), cmppid, NULL);
  345. if (type == CGROUP_FILE_PROCS)
  346. length = pidlist_uniq(array, length);
  347. l = cgroup_pidlist_find_create(cgrp, type);
  348. if (!l) {
  349. pidlist_free(array);
  350. return -ENOMEM;
  351. }
  352. /* store array, freeing old if necessary */
  353. pidlist_free(l->list);
  354. l->list = array;
  355. l->length = length;
  356. *lp = l;
  357. return 0;
  358. }
  359. /*
  360. * seq_file methods for the tasks/procs files. The seq_file position is the
  361. * next pid to display; the seq_file iterator is a pointer to the pid
  362. * in the cgroup->l->list array.
  363. */
  364. static void *cgroup_pidlist_start(struct seq_file *s, loff_t *pos)
  365. {
  366. /*
  367. * Initially we receive a position value that corresponds to
  368. * one more than the last pid shown (or 0 on the first call or
  369. * after a seek to the start). Use a binary-search to find the
  370. * next pid to display, if any
  371. */
  372. struct kernfs_open_file *of = s->private;
  373. struct cgroup *cgrp = seq_css(s)->cgroup;
  374. struct cgroup_pidlist *l;
  375. enum cgroup_filetype type = seq_cft(s)->private;
  376. int index = 0, pid = *pos;
  377. int *iter, ret;
  378. mutex_lock(&cgrp->pidlist_mutex);
  379. /*
  380. * !NULL @of->priv indicates that this isn't the first start()
  381. * after open. If the matching pidlist is around, we can use that.
  382. * Look for it. Note that @of->priv can't be used directly. It
  383. * could already have been destroyed.
  384. */
  385. if (of->priv)
  386. of->priv = cgroup_pidlist_find(cgrp, type);
  387. /*
  388. * Either this is the first start() after open or the matching
  389. * pidlist has been destroyed inbetween. Create a new one.
  390. */
  391. if (!of->priv) {
  392. ret = pidlist_array_load(cgrp, type,
  393. (struct cgroup_pidlist **)&of->priv);
  394. if (ret)
  395. return ERR_PTR(ret);
  396. }
  397. l = of->priv;
  398. if (pid) {
  399. int end = l->length;
  400. while (index < end) {
  401. int mid = (index + end) / 2;
  402. if (l->list[mid] == pid) {
  403. index = mid;
  404. break;
  405. } else if (l->list[mid] <= pid)
  406. index = mid + 1;
  407. else
  408. end = mid;
  409. }
  410. }
  411. /* If we're off the end of the array, we're done */
  412. if (index >= l->length)
  413. return NULL;
  414. /* Update the abstract position to be the actual pid that we found */
  415. iter = l->list + index;
  416. *pos = *iter;
  417. return iter;
  418. }
  419. static void cgroup_pidlist_stop(struct seq_file *s, void *v)
  420. {
  421. struct kernfs_open_file *of = s->private;
  422. struct cgroup_pidlist *l = of->priv;
  423. if (l)
  424. mod_delayed_work(cgroup_pidlist_destroy_wq, &l->destroy_dwork,
  425. CGROUP_PIDLIST_DESTROY_DELAY);
  426. mutex_unlock(&seq_css(s)->cgroup->pidlist_mutex);
  427. }
  428. static void *cgroup_pidlist_next(struct seq_file *s, void *v, loff_t *pos)
  429. {
  430. struct kernfs_open_file *of = s->private;
  431. struct cgroup_pidlist *l = of->priv;
  432. pid_t *p = v;
  433. pid_t *end = l->list + l->length;
  434. /*
  435. * Advance to the next pid in the array. If this goes off the
  436. * end, we're done
  437. */
  438. p++;
  439. if (p >= end) {
  440. (*pos)++;
  441. return NULL;
  442. } else {
  443. *pos = *p;
  444. return p;
  445. }
  446. }
  447. static int cgroup_pidlist_show(struct seq_file *s, void *v)
  448. {
  449. seq_printf(s, "%d\n", *(int *)v);
  450. return 0;
  451. }
  452. static ssize_t __cgroup1_procs_write(struct kernfs_open_file *of,
  453. char *buf, size_t nbytes, loff_t off,
  454. bool threadgroup)
  455. {
  456. struct cgroup *cgrp;
  457. struct task_struct *task;
  458. const struct cred *cred, *tcred;
  459. ssize_t ret;
  460. cgrp = cgroup_kn_lock_live(of->kn, false);
  461. if (!cgrp)
  462. return -ENODEV;
  463. task = cgroup_procs_write_start(buf, threadgroup);
  464. ret = PTR_ERR_OR_ZERO(task);
  465. if (ret)
  466. goto out_unlock;
  467. /*
  468. * Even if we're attaching all tasks in the thread group, we only
  469. * need to check permissions on one of them.
  470. */
  471. cred = current_cred();
  472. tcred = get_task_cred(task);
  473. if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) &&
  474. !uid_eq(cred->euid, tcred->uid) &&
  475. !uid_eq(cred->euid, tcred->suid))
  476. ret = -EACCES;
  477. put_cred(tcred);
  478. if (ret)
  479. goto out_finish;
  480. ret = cgroup_attach_task(cgrp, task, threadgroup);
  481. out_finish:
  482. cgroup_procs_write_finish(task);
  483. out_unlock:
  484. cgroup_kn_unlock(of->kn);
  485. return ret ?: nbytes;
  486. }
  487. static ssize_t cgroup1_procs_write(struct kernfs_open_file *of,
  488. char *buf, size_t nbytes, loff_t off)
  489. {
  490. return __cgroup1_procs_write(of, buf, nbytes, off, true);
  491. }
  492. static ssize_t cgroup1_tasks_write(struct kernfs_open_file *of,
  493. char *buf, size_t nbytes, loff_t off)
  494. {
  495. return __cgroup1_procs_write(of, buf, nbytes, off, false);
  496. }
  497. static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
  498. char *buf, size_t nbytes, loff_t off)
  499. {
  500. struct cgroup *cgrp;
  501. BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);
  502. cgrp = cgroup_kn_lock_live(of->kn, false);
  503. if (!cgrp)
  504. return -ENODEV;
  505. spin_lock(&release_agent_path_lock);
  506. strlcpy(cgrp->root->release_agent_path, strstrip(buf),
  507. sizeof(cgrp->root->release_agent_path));
  508. spin_unlock(&release_agent_path_lock);
  509. cgroup_kn_unlock(of->kn);
  510. return nbytes;
  511. }
  512. static int cgroup_release_agent_show(struct seq_file *seq, void *v)
  513. {
  514. struct cgroup *cgrp = seq_css(seq)->cgroup;
  515. spin_lock(&release_agent_path_lock);
  516. seq_puts(seq, cgrp->root->release_agent_path);
  517. spin_unlock(&release_agent_path_lock);
  518. seq_putc(seq, '\n');
  519. return 0;
  520. }
  521. static int cgroup_sane_behavior_show(struct seq_file *seq, void *v)
  522. {
  523. seq_puts(seq, "0\n");
  524. return 0;
  525. }
  526. static u64 cgroup_read_notify_on_release(struct cgroup_subsys_state *css,
  527. struct cftype *cft)
  528. {
  529. return notify_on_release(css->cgroup);
  530. }
  531. static int cgroup_write_notify_on_release(struct cgroup_subsys_state *css,
  532. struct cftype *cft, u64 val)
  533. {
  534. if (val)
  535. set_bit(CGRP_NOTIFY_ON_RELEASE, &css->cgroup->flags);
  536. else
  537. clear_bit(CGRP_NOTIFY_ON_RELEASE, &css->cgroup->flags);
  538. return 0;
  539. }
  540. static u64 cgroup_clone_children_read(struct cgroup_subsys_state *css,
  541. struct cftype *cft)
  542. {
  543. return test_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags);
  544. }
  545. static int cgroup_clone_children_write(struct cgroup_subsys_state *css,
  546. struct cftype *cft, u64 val)
  547. {
  548. if (val)
  549. set_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags);
  550. else
  551. clear_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags);
  552. return 0;
  553. }
  554. /* cgroup core interface files for the legacy hierarchies */
  555. struct cftype cgroup1_base_files[] = {
  556. {
  557. .name = "cgroup.procs",
  558. .seq_start = cgroup_pidlist_start,
  559. .seq_next = cgroup_pidlist_next,
  560. .seq_stop = cgroup_pidlist_stop,
  561. .seq_show = cgroup_pidlist_show,
  562. .private = CGROUP_FILE_PROCS,
  563. .write = cgroup1_procs_write,
  564. },
  565. {
  566. .name = "cgroup.clone_children",
  567. .read_u64 = cgroup_clone_children_read,
  568. .write_u64 = cgroup_clone_children_write,
  569. },
  570. {
  571. .name = "cgroup.sane_behavior",
  572. .flags = CFTYPE_ONLY_ON_ROOT,
  573. .seq_show = cgroup_sane_behavior_show,
  574. },
  575. {
  576. .name = "tasks",
  577. .seq_start = cgroup_pidlist_start,
  578. .seq_next = cgroup_pidlist_next,
  579. .seq_stop = cgroup_pidlist_stop,
  580. .seq_show = cgroup_pidlist_show,
  581. .private = CGROUP_FILE_TASKS,
  582. .write = cgroup1_tasks_write,
  583. },
  584. {
  585. .name = "notify_on_release",
  586. .read_u64 = cgroup_read_notify_on_release,
  587. .write_u64 = cgroup_write_notify_on_release,
  588. },
  589. {
  590. .name = "release_agent",
  591. .flags = CFTYPE_ONLY_ON_ROOT,
  592. .seq_show = cgroup_release_agent_show,
  593. .write = cgroup_release_agent_write,
  594. .max_write_len = PATH_MAX - 1,
  595. },
  596. { } /* terminate */
  597. };
  598. /* Display information about each subsystem and each hierarchy */
  599. int proc_cgroupstats_show(struct seq_file *m, void *v)
  600. {
  601. struct cgroup_subsys *ss;
  602. int i;
  603. seq_puts(m, "#subsys_name\thierarchy\tnum_cgroups\tenabled\n");
  604. /*
  605. * ideally we don't want subsystems moving around while we do this.
  606. * cgroup_mutex is also necessary to guarantee an atomic snapshot of
  607. * subsys/hierarchy state.
  608. */
  609. mutex_lock(&cgroup_mutex);
  610. for_each_subsys(ss, i)
  611. seq_printf(m, "%s\t%d\t%d\t%d\n",
  612. ss->legacy_name, ss->root->hierarchy_id,
  613. atomic_read(&ss->root->nr_cgrps),
  614. cgroup_ssid_enabled(i));
  615. mutex_unlock(&cgroup_mutex);
  616. return 0;
  617. }
  618. /**
  619. * cgroupstats_build - build and fill cgroupstats
  620. * @stats: cgroupstats to fill information into
  621. * @dentry: A dentry entry belonging to the cgroup for which stats have
  622. * been requested.
  623. *
  624. * Build and fill cgroupstats so that taskstats can export it to user
  625. * space.
  626. */
  627. int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry)
  628. {
  629. struct kernfs_node *kn = kernfs_node_from_dentry(dentry);
  630. struct cgroup *cgrp;
  631. struct css_task_iter it;
  632. struct task_struct *tsk;
  633. /* it should be kernfs_node belonging to cgroupfs and is a directory */
  634. if (dentry->d_sb->s_type != &cgroup_fs_type || !kn ||
  635. kernfs_type(kn) != KERNFS_DIR)
  636. return -EINVAL;
  637. mutex_lock(&cgroup_mutex);
  638. /*
  639. * We aren't being called from kernfs and there's no guarantee on
  640. * @kn->priv's validity. For this and css_tryget_online_from_dir(),
  641. * @kn->priv is RCU safe. Let's do the RCU dancing.
  642. */
  643. rcu_read_lock();
  644. cgrp = rcu_dereference(*(void __rcu __force **)&kn->priv);
  645. if (!cgrp || cgroup_is_dead(cgrp)) {
  646. rcu_read_unlock();
  647. mutex_unlock(&cgroup_mutex);
  648. return -ENOENT;
  649. }
  650. rcu_read_unlock();
  651. css_task_iter_start(&cgrp->self, 0, &it);
  652. while ((tsk = css_task_iter_next(&it))) {
  653. switch (tsk->state) {
  654. case TASK_RUNNING:
  655. stats->nr_running++;
  656. break;
  657. case TASK_INTERRUPTIBLE:
  658. stats->nr_sleeping++;
  659. break;
  660. case TASK_UNINTERRUPTIBLE:
  661. stats->nr_uninterruptible++;
  662. break;
  663. case TASK_STOPPED:
  664. stats->nr_stopped++;
  665. break;
  666. default:
  667. if (delayacct_is_task_waiting_on_io(tsk))
  668. stats->nr_io_wait++;
  669. break;
  670. }
  671. }
  672. css_task_iter_end(&it);
  673. mutex_unlock(&cgroup_mutex);
  674. return 0;
  675. }
  676. void cgroup1_check_for_release(struct cgroup *cgrp)
  677. {
  678. if (notify_on_release(cgrp) && !cgroup_is_populated(cgrp) &&
  679. !css_has_online_children(&cgrp->self) && !cgroup_is_dead(cgrp))
  680. schedule_work(&cgrp->release_agent_work);
  681. }
  682. /*
  683. * Notify userspace when a cgroup is released, by running the
  684. * configured release agent with the name of the cgroup (path
  685. * relative to the root of cgroup file system) as the argument.
  686. *
  687. * Most likely, this user command will try to rmdir this cgroup.
  688. *
  689. * This races with the possibility that some other task will be
  690. * attached to this cgroup before it is removed, or that some other
  691. * user task will 'mkdir' a child cgroup of this cgroup. That's ok.
  692. * The presumed 'rmdir' will fail quietly if this cgroup is no longer
  693. * unused, and this cgroup will be reprieved from its death sentence,
  694. * to continue to serve a useful existence. Next time it's released,
  695. * we will get notified again, if it still has 'notify_on_release' set.
  696. *
  697. * The final arg to call_usermodehelper() is UMH_WAIT_EXEC, which
  698. * means only wait until the task is successfully execve()'d. The
  699. * separate release agent task is forked by call_usermodehelper(),
  700. * then control in this thread returns here, without waiting for the
  701. * release agent task. We don't bother to wait because the caller of
  702. * this routine has no use for the exit status of the release agent
  703. * task, so no sense holding our caller up for that.
  704. */
  705. void cgroup1_release_agent(struct work_struct *work)
  706. {
  707. struct cgroup *cgrp =
  708. container_of(work, struct cgroup, release_agent_work);
  709. char *pathbuf = NULL, *agentbuf = NULL;
  710. char *argv[3], *envp[3];
  711. int ret;
  712. mutex_lock(&cgroup_mutex);
  713. pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
  714. agentbuf = kstrdup(cgrp->root->release_agent_path, GFP_KERNEL);
  715. if (!pathbuf || !agentbuf || !strlen(agentbuf))
  716. goto out;
  717. spin_lock_irq(&css_set_lock);
  718. ret = cgroup_path_ns_locked(cgrp, pathbuf, PATH_MAX, &init_cgroup_ns);
  719. spin_unlock_irq(&css_set_lock);
  720. if (ret < 0 || ret >= PATH_MAX)
  721. goto out;
  722. argv[0] = agentbuf;
  723. argv[1] = pathbuf;
  724. argv[2] = NULL;
  725. /* minimal command environment */
  726. envp[0] = "HOME=/";
  727. envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
  728. envp[2] = NULL;
  729. mutex_unlock(&cgroup_mutex);
  730. call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
  731. goto out_free;
  732. out:
  733. mutex_unlock(&cgroup_mutex);
  734. out_free:
  735. kfree(agentbuf);
  736. kfree(pathbuf);
  737. }
  738. /*
  739. * cgroup_rename - Only allow simple rename of directories in place.
  740. */
  741. static int cgroup1_rename(struct kernfs_node *kn, struct kernfs_node *new_parent,
  742. const char *new_name_str)
  743. {
  744. struct cgroup *cgrp = kn->priv;
  745. int ret;
  746. if (kernfs_type(kn) != KERNFS_DIR)
  747. return -ENOTDIR;
  748. if (kn->parent != new_parent)
  749. return -EIO;
  750. /*
  751. * We're gonna grab cgroup_mutex which nests outside kernfs
  752. * active_ref. kernfs_rename() doesn't require active_ref
  753. * protection. Break them before grabbing cgroup_mutex.
  754. */
  755. kernfs_break_active_protection(new_parent);
  756. kernfs_break_active_protection(kn);
  757. mutex_lock(&cgroup_mutex);
  758. ret = kernfs_rename(kn, new_parent, new_name_str);
  759. if (!ret)
  760. TRACE_CGROUP_PATH(rename, cgrp);
  761. mutex_unlock(&cgroup_mutex);
  762. kernfs_unbreak_active_protection(kn);
  763. kernfs_unbreak_active_protection(new_parent);
  764. return ret;
  765. }
  766. static int cgroup1_show_options(struct seq_file *seq, struct kernfs_root *kf_root)
  767. {
  768. struct cgroup_root *root = cgroup_root_from_kf(kf_root);
  769. struct cgroup_subsys *ss;
  770. int ssid;
  771. for_each_subsys(ss, ssid)
  772. if (root->subsys_mask & (1 << ssid))
  773. seq_show_option(seq, ss->legacy_name, NULL);
  774. if (root->flags & CGRP_ROOT_NOPREFIX)
  775. seq_puts(seq, ",noprefix");
  776. if (root->flags & CGRP_ROOT_XATTR)
  777. seq_puts(seq, ",xattr");
  778. if (root->flags & CGRP_ROOT_CPUSET_V2_MODE)
  779. seq_puts(seq, ",cpuset_v2_mode");
  780. spin_lock(&release_agent_path_lock);
  781. if (strlen(root->release_agent_path))
  782. seq_show_option(seq, "release_agent",
  783. root->release_agent_path);
  784. spin_unlock(&release_agent_path_lock);
  785. if (test_bit(CGRP_CPUSET_CLONE_CHILDREN, &root->cgrp.flags))
  786. seq_puts(seq, ",clone_children");
  787. if (strlen(root->name))
  788. seq_show_option(seq, "name", root->name);
  789. return 0;
  790. }
  791. static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
  792. {
  793. char *token, *o = data;
  794. bool all_ss = false, one_ss = false;
  795. u16 mask = U16_MAX;
  796. struct cgroup_subsys *ss;
  797. int nr_opts = 0;
  798. int i;
  799. #ifdef CONFIG_CPUSETS
  800. mask = ~((u16)1 << cpuset_cgrp_id);
  801. #endif
  802. memset(opts, 0, sizeof(*opts));
  803. while ((token = strsep(&o, ",")) != NULL) {
  804. nr_opts++;
  805. if (!*token)
  806. return -EINVAL;
  807. if (!strcmp(token, "none")) {
  808. /* Explicitly have no subsystems */
  809. opts->none = true;
  810. continue;
  811. }
  812. if (!strcmp(token, "all")) {
  813. /* Mutually exclusive option 'all' + subsystem name */
  814. if (one_ss)
  815. return -EINVAL;
  816. all_ss = true;
  817. continue;
  818. }
  819. if (!strcmp(token, "noprefix")) {
  820. opts->flags |= CGRP_ROOT_NOPREFIX;
  821. continue;
  822. }
  823. if (!strcmp(token, "clone_children")) {
  824. opts->cpuset_clone_children = true;
  825. continue;
  826. }
  827. if (!strcmp(token, "cpuset_v2_mode")) {
  828. opts->flags |= CGRP_ROOT_CPUSET_V2_MODE;
  829. continue;
  830. }
  831. if (!strcmp(token, "xattr")) {
  832. opts->flags |= CGRP_ROOT_XATTR;
  833. continue;
  834. }
  835. if (!strncmp(token, "release_agent=", 14)) {
  836. /* Specifying two release agents is forbidden */
  837. if (opts->release_agent)
  838. return -EINVAL;
  839. opts->release_agent =
  840. kstrndup(token + 14, PATH_MAX - 1, GFP_KERNEL);
  841. if (!opts->release_agent)
  842. return -ENOMEM;
  843. continue;
  844. }
  845. if (!strncmp(token, "name=", 5)) {
  846. const char *name = token + 5;
  847. /* Can't specify an empty name */
  848. if (!strlen(name))
  849. return -EINVAL;
  850. /* Must match [\w.-]+ */
  851. for (i = 0; i < strlen(name); i++) {
  852. char c = name[i];
  853. if (isalnum(c))
  854. continue;
  855. if ((c == '.') || (c == '-') || (c == '_'))
  856. continue;
  857. return -EINVAL;
  858. }
  859. /* Specifying two names is forbidden */
  860. if (opts->name)
  861. return -EINVAL;
  862. opts->name = kstrndup(name,
  863. MAX_CGROUP_ROOT_NAMELEN - 1,
  864. GFP_KERNEL);
  865. if (!opts->name)
  866. return -ENOMEM;
  867. continue;
  868. }
  869. for_each_subsys(ss, i) {
  870. if (strcmp(token, ss->legacy_name))
  871. continue;
  872. if (!cgroup_ssid_enabled(i))
  873. continue;
  874. if (cgroup1_ssid_disabled(i))
  875. continue;
  876. /* Mutually exclusive option 'all' + subsystem name */
  877. if (all_ss)
  878. return -EINVAL;
  879. opts->subsys_mask |= (1 << i);
  880. one_ss = true;
  881. break;
  882. }
  883. if (i == CGROUP_SUBSYS_COUNT)
  884. return -ENOENT;
  885. }
  886. /*
  887. * If the 'all' option was specified select all the subsystems,
  888. * otherwise if 'none', 'name=' and a subsystem name options were
  889. * not specified, let's default to 'all'
  890. */
  891. if (all_ss || (!one_ss && !opts->none && !opts->name))
  892. for_each_subsys(ss, i)
  893. if (cgroup_ssid_enabled(i) && !cgroup1_ssid_disabled(i))
  894. opts->subsys_mask |= (1 << i);
  895. /*
  896. * We either have to specify by name or by subsystems. (So all
  897. * empty hierarchies must have a name).
  898. */
  899. if (!opts->subsys_mask && !opts->name)
  900. return -EINVAL;
  901. /*
  902. * Option noprefix was introduced just for backward compatibility
  903. * with the old cpuset, so we allow noprefix only if mounting just
  904. * the cpuset subsystem.
  905. */
  906. if ((opts->flags & CGRP_ROOT_NOPREFIX) && (opts->subsys_mask & mask))
  907. return -EINVAL;
  908. /* Can't specify "none" and some subsystems */
  909. if (opts->subsys_mask && opts->none)
  910. return -EINVAL;
  911. return 0;
  912. }
  913. static int cgroup1_remount(struct kernfs_root *kf_root, int *flags, char *data)
  914. {
  915. int ret = 0;
  916. struct cgroup_root *root = cgroup_root_from_kf(kf_root);
  917. struct cgroup_sb_opts opts;
  918. u16 added_mask, removed_mask;
  919. cgroup_lock_and_drain_offline(&cgrp_dfl_root.cgrp);
  920. /* See what subsystems are wanted */
  921. ret = parse_cgroupfs_options(data, &opts);
  922. if (ret)
  923. goto out_unlock;
  924. if (opts.subsys_mask != root->subsys_mask || opts.release_agent)
  925. pr_warn("option changes via remount are deprecated (pid=%d comm=%s)\n",
  926. task_tgid_nr(current), current->comm);
  927. added_mask = opts.subsys_mask & ~root->subsys_mask;
  928. removed_mask = root->subsys_mask & ~opts.subsys_mask;
  929. /* Don't allow flags or name to change at remount */
  930. if ((opts.flags ^ root->flags) ||
  931. (opts.name && strcmp(opts.name, root->name))) {
  932. pr_err("option or name mismatch, new: 0x%x \"%s\", old: 0x%x \"%s\"\n",
  933. opts.flags, opts.name ?: "", root->flags, root->name);
  934. ret = -EINVAL;
  935. goto out_unlock;
  936. }
  937. /* remounting is not allowed for populated hierarchies */
  938. if (!list_empty(&root->cgrp.self.children)) {
  939. ret = -EBUSY;
  940. goto out_unlock;
  941. }
  942. ret = rebind_subsystems(root, added_mask);
  943. if (ret)
  944. goto out_unlock;
  945. WARN_ON(rebind_subsystems(&cgrp_dfl_root, removed_mask));
  946. if (opts.release_agent) {
  947. spin_lock(&release_agent_path_lock);
  948. strcpy(root->release_agent_path, opts.release_agent);
  949. spin_unlock(&release_agent_path_lock);
  950. }
  951. trace_cgroup_remount(root);
  952. out_unlock:
  953. kfree(opts.release_agent);
  954. kfree(opts.name);
  955. mutex_unlock(&cgroup_mutex);
  956. return ret;
  957. }
  958. struct kernfs_syscall_ops cgroup1_kf_syscall_ops = {
  959. .rename = cgroup1_rename,
  960. .show_options = cgroup1_show_options,
  961. .remount_fs = cgroup1_remount,
  962. .mkdir = cgroup_mkdir,
  963. .rmdir = cgroup_rmdir,
  964. .show_path = cgroup_show_path,
  965. };
  966. struct dentry *cgroup1_mount(struct file_system_type *fs_type, int flags,
  967. void *data, unsigned long magic,
  968. struct cgroup_namespace *ns)
  969. {
  970. struct super_block *pinned_sb = NULL;
  971. struct cgroup_sb_opts opts;
  972. struct cgroup_root *root;
  973. struct cgroup_subsys *ss;
  974. struct dentry *dentry;
  975. int i, ret;
  976. bool new_root = false;
  977. cgroup_lock_and_drain_offline(&cgrp_dfl_root.cgrp);
  978. /* First find the desired set of subsystems */
  979. ret = parse_cgroupfs_options(data, &opts);
  980. if (ret)
  981. goto out_unlock;
  982. /*
  983. * Destruction of cgroup root is asynchronous, so subsystems may
  984. * still be dying after the previous unmount. Let's drain the
  985. * dying subsystems. We just need to ensure that the ones
  986. * unmounted previously finish dying and don't care about new ones
  987. * starting. Testing ref liveliness is good enough.
  988. */
  989. for_each_subsys(ss, i) {
  990. if (!(opts.subsys_mask & (1 << i)) ||
  991. ss->root == &cgrp_dfl_root)
  992. continue;
  993. if (!percpu_ref_tryget_live(&ss->root->cgrp.self.refcnt)) {
  994. mutex_unlock(&cgroup_mutex);
  995. msleep(10);
  996. ret = restart_syscall();
  997. goto out_free;
  998. }
  999. cgroup_put(&ss->root->cgrp);
  1000. }
  1001. for_each_root(root) {
  1002. bool name_match = false;
  1003. if (root == &cgrp_dfl_root)
  1004. continue;
  1005. /*
  1006. * If we asked for a name then it must match. Also, if
  1007. * name matches but sybsys_mask doesn't, we should fail.
  1008. * Remember whether name matched.
  1009. */
  1010. if (opts.name) {
  1011. if (strcmp(opts.name, root->name))
  1012. continue;
  1013. name_match = true;
  1014. }
  1015. /*
  1016. * If we asked for subsystems (or explicitly for no
  1017. * subsystems) then they must match.
  1018. */
  1019. if ((opts.subsys_mask || opts.none) &&
  1020. (opts.subsys_mask != root->subsys_mask)) {
  1021. if (!name_match)
  1022. continue;
  1023. ret = -EBUSY;
  1024. goto out_unlock;
  1025. }
  1026. if (root->flags ^ opts.flags)
  1027. pr_warn("new mount options do not match the existing superblock, will be ignored\n");
  1028. /*
  1029. * We want to reuse @root whose lifetime is governed by its
  1030. * ->cgrp. Let's check whether @root is alive and keep it
  1031. * that way. As cgroup_kill_sb() can happen anytime, we
  1032. * want to block it by pinning the sb so that @root doesn't
  1033. * get killed before mount is complete.
  1034. *
  1035. * With the sb pinned, tryget_live can reliably indicate
  1036. * whether @root can be reused. If it's being killed,
  1037. * drain it. We can use wait_queue for the wait but this
  1038. * path is super cold. Let's just sleep a bit and retry.
  1039. */
  1040. pinned_sb = kernfs_pin_sb(root->kf_root, NULL);
  1041. if (IS_ERR(pinned_sb) ||
  1042. !percpu_ref_tryget_live(&root->cgrp.self.refcnt)) {
  1043. mutex_unlock(&cgroup_mutex);
  1044. if (!IS_ERR_OR_NULL(pinned_sb))
  1045. deactivate_super(pinned_sb);
  1046. msleep(10);
  1047. ret = restart_syscall();
  1048. goto out_free;
  1049. }
  1050. ret = 0;
  1051. goto out_unlock;
  1052. }
  1053. /*
  1054. * No such thing, create a new one. name= matching without subsys
  1055. * specification is allowed for already existing hierarchies but we
  1056. * can't create new one without subsys specification.
  1057. */
  1058. if (!opts.subsys_mask && !opts.none) {
  1059. ret = -EINVAL;
  1060. goto out_unlock;
  1061. }
  1062. /* Hierarchies may only be created in the initial cgroup namespace. */
  1063. if (ns != &init_cgroup_ns) {
  1064. ret = -EPERM;
  1065. goto out_unlock;
  1066. }
  1067. root = kzalloc(sizeof(*root), GFP_KERNEL);
  1068. if (!root) {
  1069. ret = -ENOMEM;
  1070. goto out_unlock;
  1071. }
  1072. new_root = true;
  1073. init_cgroup_root(root, &opts);
  1074. ret = cgroup_setup_root(root, opts.subsys_mask, PERCPU_REF_INIT_DEAD);
  1075. if (ret)
  1076. cgroup_free_root(root);
  1077. out_unlock:
  1078. mutex_unlock(&cgroup_mutex);
  1079. out_free:
  1080. kfree(opts.release_agent);
  1081. kfree(opts.name);
  1082. if (ret)
  1083. return ERR_PTR(ret);
  1084. dentry = cgroup_do_mount(&cgroup_fs_type, flags, root,
  1085. CGROUP_SUPER_MAGIC, ns);
  1086. /*
  1087. * There's a race window after we release cgroup_mutex and before
  1088. * allocating a superblock. Make sure a concurrent process won't
  1089. * be able to re-use the root during this window by delaying the
  1090. * initialization of root refcnt.
  1091. */
  1092. if (new_root) {
  1093. mutex_lock(&cgroup_mutex);
  1094. percpu_ref_reinit(&root->cgrp.self.refcnt);
  1095. mutex_unlock(&cgroup_mutex);
  1096. }
  1097. /*
  1098. * If @pinned_sb, we're reusing an existing root and holding an
  1099. * extra ref on its sb. Mount is complete. Put the extra ref.
  1100. */
  1101. if (pinned_sb)
  1102. deactivate_super(pinned_sb);
  1103. return dentry;
  1104. }
  1105. static int __init cgroup1_wq_init(void)
  1106. {
  1107. /*
  1108. * Used to destroy pidlists and separate to serve as flush domain.
  1109. * Cap @max_active to 1 too.
  1110. */
  1111. cgroup_pidlist_destroy_wq = alloc_workqueue("cgroup_pidlist_destroy",
  1112. 0, 1);
  1113. BUG_ON(!cgroup_pidlist_destroy_wq);
  1114. return 0;
  1115. }
  1116. core_initcall(cgroup1_wq_init);
  1117. static int __init cgroup_no_v1(char *str)
  1118. {
  1119. struct cgroup_subsys *ss;
  1120. char *token;
  1121. int i;
  1122. while ((token = strsep(&str, ",")) != NULL) {
  1123. if (!*token)
  1124. continue;
  1125. if (!strcmp(token, "all")) {
  1126. cgroup_no_v1_mask = U16_MAX;
  1127. break;
  1128. }
  1129. for_each_subsys(ss, i) {
  1130. if (strcmp(token, ss->name) &&
  1131. strcmp(token, ss->legacy_name))
  1132. continue;
  1133. cgroup_no_v1_mask |= 1 << i;
  1134. }
  1135. }
  1136. return 1;
  1137. }
  1138. __setup("cgroup_no_v1=", cgroup_no_v1);