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