Merge tag 'perf-core-2022-08-01' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / include / linux / cgroup-defs.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * linux/cgroup-defs.h - basic definitions for cgroup
4  *
5  * This file provides basic type and interface.  Include this file directly
6  * only if necessary to avoid cyclic dependencies.
7  */
8 #ifndef _LINUX_CGROUP_DEFS_H
9 #define _LINUX_CGROUP_DEFS_H
10
11 #include <linux/limits.h>
12 #include <linux/list.h>
13 #include <linux/idr.h>
14 #include <linux/wait.h>
15 #include <linux/mutex.h>
16 #include <linux/rcupdate.h>
17 #include <linux/refcount.h>
18 #include <linux/percpu-refcount.h>
19 #include <linux/percpu-rwsem.h>
20 #include <linux/u64_stats_sync.h>
21 #include <linux/workqueue.h>
22 #include <linux/bpf-cgroup-defs.h>
23 #include <linux/psi_types.h>
24
25 #ifdef CONFIG_CGROUPS
26
27 struct cgroup;
28 struct cgroup_root;
29 struct cgroup_subsys;
30 struct cgroup_taskset;
31 struct kernfs_node;
32 struct kernfs_ops;
33 struct kernfs_open_file;
34 struct seq_file;
35 struct poll_table_struct;
36
37 #define MAX_CGROUP_TYPE_NAMELEN 32
38 #define MAX_CGROUP_ROOT_NAMELEN 64
39 #define MAX_CFTYPE_NAME         64
40
41 /* define the enumeration of all cgroup subsystems */
42 #define SUBSYS(_x) _x ## _cgrp_id,
43 enum cgroup_subsys_id {
44 #include <linux/cgroup_subsys.h>
45         CGROUP_SUBSYS_COUNT,
46 };
47 #undef SUBSYS
48
49 /* bits in struct cgroup_subsys_state flags field */
50 enum {
51         CSS_NO_REF      = (1 << 0), /* no reference counting for this css */
52         CSS_ONLINE      = (1 << 1), /* between ->css_online() and ->css_offline() */
53         CSS_RELEASED    = (1 << 2), /* refcnt reached zero, released */
54         CSS_VISIBLE     = (1 << 3), /* css is visible to userland */
55         CSS_DYING       = (1 << 4), /* css is dying */
56 };
57
58 /* bits in struct cgroup flags field */
59 enum {
60         /* Control Group requires release notifications to userspace */
61         CGRP_NOTIFY_ON_RELEASE,
62         /*
63          * Clone the parent's configuration when creating a new child
64          * cpuset cgroup.  For historical reasons, this option can be
65          * specified at mount time and thus is implemented here.
66          */
67         CGRP_CPUSET_CLONE_CHILDREN,
68
69         /* Control group has to be frozen. */
70         CGRP_FREEZE,
71
72         /* Cgroup is frozen. */
73         CGRP_FROZEN,
74
75         /* Control group has to be killed. */
76         CGRP_KILL,
77 };
78
79 /* cgroup_root->flags */
80 enum {
81         CGRP_ROOT_NOPREFIX      = (1 << 1), /* mounted subsystems have no named prefix */
82         CGRP_ROOT_XATTR         = (1 << 2), /* supports extended attributes */
83
84         /*
85          * Consider namespaces as delegation boundaries.  If this flag is
86          * set, controller specific interface files in a namespace root
87          * aren't writeable from inside the namespace.
88          */
89         CGRP_ROOT_NS_DELEGATE   = (1 << 3),
90
91         /*
92          * Enable cpuset controller in v1 cgroup to use v2 behavior.
93          */
94         CGRP_ROOT_CPUSET_V2_MODE = (1 << 4),
95
96         /*
97          * Enable legacy local memory.events.
98          */
99         CGRP_ROOT_MEMORY_LOCAL_EVENTS = (1 << 5),
100
101         /*
102          * Enable recursive subtree protection
103          */
104         CGRP_ROOT_MEMORY_RECURSIVE_PROT = (1 << 6),
105 };
106
107 /* cftype->flags */
108 enum {
109         CFTYPE_ONLY_ON_ROOT     = (1 << 0),     /* only create on root cgrp */
110         CFTYPE_NOT_ON_ROOT      = (1 << 1),     /* don't create on root cgrp */
111         CFTYPE_NS_DELEGATABLE   = (1 << 2),     /* writeable beyond delegation boundaries */
112
113         CFTYPE_NO_PREFIX        = (1 << 3),     /* (DON'T USE FOR NEW FILES) no subsys prefix */
114         CFTYPE_WORLD_WRITABLE   = (1 << 4),     /* (DON'T USE FOR NEW FILES) S_IWUGO */
115         CFTYPE_DEBUG            = (1 << 5),     /* create when cgroup_debug */
116         CFTYPE_PRESSURE         = (1 << 6),     /* only if pressure feature is enabled */
117
118         /* internal flags, do not use outside cgroup core proper */
119         __CFTYPE_ONLY_ON_DFL    = (1 << 16),    /* only on default hierarchy */
120         __CFTYPE_NOT_ON_DFL     = (1 << 17),    /* not on default hierarchy */
121 };
122
123 /*
124  * cgroup_file is the handle for a file instance created in a cgroup which
125  * is used, for example, to generate file changed notifications.  This can
126  * be obtained by setting cftype->file_offset.
127  */
128 struct cgroup_file {
129         /* do not access any fields from outside cgroup core */
130         struct kernfs_node *kn;
131         unsigned long notified_at;
132         struct timer_list notify_timer;
133 };
134
135 /*
136  * Per-subsystem/per-cgroup state maintained by the system.  This is the
137  * fundamental structural building block that controllers deal with.
138  *
139  * Fields marked with "PI:" are public and immutable and may be accessed
140  * directly without synchronization.
141  */
142 struct cgroup_subsys_state {
143         /* PI: the cgroup that this css is attached to */
144         struct cgroup *cgroup;
145
146         /* PI: the cgroup subsystem that this css is attached to */
147         struct cgroup_subsys *ss;
148
149         /* reference count - access via css_[try]get() and css_put() */
150         struct percpu_ref refcnt;
151
152         /* siblings list anchored at the parent's ->children */
153         struct list_head sibling;
154         struct list_head children;
155
156         /* flush target list anchored at cgrp->rstat_css_list */
157         struct list_head rstat_css_node;
158
159         /*
160          * PI: Subsys-unique ID.  0 is unused and root is always 1.  The
161          * matching css can be looked up using css_from_id().
162          */
163         int id;
164
165         unsigned int flags;
166
167         /*
168          * Monotonically increasing unique serial number which defines a
169          * uniform order among all csses.  It's guaranteed that all
170          * ->children lists are in the ascending order of ->serial_nr and
171          * used to allow interrupting and resuming iterations.
172          */
173         u64 serial_nr;
174
175         /*
176          * Incremented by online self and children.  Used to guarantee that
177          * parents are not offlined before their children.
178          */
179         atomic_t online_cnt;
180
181         /* percpu_ref killing and RCU release */
182         struct work_struct destroy_work;
183         struct rcu_work destroy_rwork;
184
185         /*
186          * PI: the parent css.  Placed here for cache proximity to following
187          * fields of the containing structure.
188          */
189         struct cgroup_subsys_state *parent;
190 };
191
192 /*
193  * A css_set is a structure holding pointers to a set of
194  * cgroup_subsys_state objects. This saves space in the task struct
195  * object and speeds up fork()/exit(), since a single inc/dec and a
196  * list_add()/del() can bump the reference count on the entire cgroup
197  * set for a task.
198  */
199 struct css_set {
200         /*
201          * Set of subsystem states, one for each subsystem. This array is
202          * immutable after creation apart from the init_css_set during
203          * subsystem registration (at boot time).
204          */
205         struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT];
206
207         /* reference count */
208         refcount_t refcount;
209
210         /*
211          * For a domain cgroup, the following points to self.  If threaded,
212          * to the matching cset of the nearest domain ancestor.  The
213          * dom_cset provides access to the domain cgroup and its csses to
214          * which domain level resource consumptions should be charged.
215          */
216         struct css_set *dom_cset;
217
218         /* the default cgroup associated with this css_set */
219         struct cgroup *dfl_cgrp;
220
221         /* internal task count, protected by css_set_lock */
222         int nr_tasks;
223
224         /*
225          * Lists running through all tasks using this cgroup group.
226          * mg_tasks lists tasks which belong to this cset but are in the
227          * process of being migrated out or in.  Protected by
228          * css_set_rwsem, but, during migration, once tasks are moved to
229          * mg_tasks, it can be read safely while holding cgroup_mutex.
230          */
231         struct list_head tasks;
232         struct list_head mg_tasks;
233         struct list_head dying_tasks;
234
235         /* all css_task_iters currently walking this cset */
236         struct list_head task_iters;
237
238         /*
239          * On the default hierarchy, ->subsys[ssid] may point to a css
240          * attached to an ancestor instead of the cgroup this css_set is
241          * associated with.  The following node is anchored at
242          * ->subsys[ssid]->cgroup->e_csets[ssid] and provides a way to
243          * iterate through all css's attached to a given cgroup.
244          */
245         struct list_head e_cset_node[CGROUP_SUBSYS_COUNT];
246
247         /* all threaded csets whose ->dom_cset points to this cset */
248         struct list_head threaded_csets;
249         struct list_head threaded_csets_node;
250
251         /*
252          * List running through all cgroup groups in the same hash
253          * slot. Protected by css_set_lock
254          */
255         struct hlist_node hlist;
256
257         /*
258          * List of cgrp_cset_links pointing at cgroups referenced from this
259          * css_set.  Protected by css_set_lock.
260          */
261         struct list_head cgrp_links;
262
263         /*
264          * List of csets participating in the on-going migration either as
265          * source or destination.  Protected by cgroup_mutex.
266          */
267         struct list_head mg_src_preload_node;
268         struct list_head mg_dst_preload_node;
269         struct list_head mg_node;
270
271         /*
272          * If this cset is acting as the source of migration the following
273          * two fields are set.  mg_src_cgrp and mg_dst_cgrp are
274          * respectively the source and destination cgroups of the on-going
275          * migration.  mg_dst_cset is the destination cset the target tasks
276          * on this cset should be migrated to.  Protected by cgroup_mutex.
277          */
278         struct cgroup *mg_src_cgrp;
279         struct cgroup *mg_dst_cgrp;
280         struct css_set *mg_dst_cset;
281
282         /* dead and being drained, ignore for migration */
283         bool dead;
284
285         /* For RCU-protected deletion */
286         struct rcu_head rcu_head;
287 };
288
289 struct cgroup_base_stat {
290         struct task_cputime cputime;
291
292 #ifdef CONFIG_SCHED_CORE
293         u64 forceidle_sum;
294 #endif
295 };
296
297 /*
298  * rstat - cgroup scalable recursive statistics.  Accounting is done
299  * per-cpu in cgroup_rstat_cpu which is then lazily propagated up the
300  * hierarchy on reads.
301  *
302  * When a stat gets updated, the cgroup_rstat_cpu and its ancestors are
303  * linked into the updated tree.  On the following read, propagation only
304  * considers and consumes the updated tree.  This makes reading O(the
305  * number of descendants which have been active since last read) instead of
306  * O(the total number of descendants).
307  *
308  * This is important because there can be a lot of (draining) cgroups which
309  * aren't active and stat may be read frequently.  The combination can
310  * become very expensive.  By propagating selectively, increasing reading
311  * frequency decreases the cost of each read.
312  *
313  * This struct hosts both the fields which implement the above -
314  * updated_children and updated_next - and the fields which track basic
315  * resource statistics on top of it - bsync, bstat and last_bstat.
316  */
317 struct cgroup_rstat_cpu {
318         /*
319          * ->bsync protects ->bstat.  These are the only fields which get
320          * updated in the hot path.
321          */
322         struct u64_stats_sync bsync;
323         struct cgroup_base_stat bstat;
324
325         /*
326          * Snapshots at the last reading.  These are used to calculate the
327          * deltas to propagate to the global counters.
328          */
329         struct cgroup_base_stat last_bstat;
330
331         /*
332          * Child cgroups with stat updates on this cpu since the last read
333          * are linked on the parent's ->updated_children through
334          * ->updated_next.
335          *
336          * In addition to being more compact, singly-linked list pointing
337          * to the cgroup makes it unnecessary for each per-cpu struct to
338          * point back to the associated cgroup.
339          *
340          * Protected by per-cpu cgroup_rstat_cpu_lock.
341          */
342         struct cgroup *updated_children;        /* terminated by self cgroup */
343         struct cgroup *updated_next;            /* NULL iff not on the list */
344 };
345
346 struct cgroup_freezer_state {
347         /* Should the cgroup and its descendants be frozen. */
348         bool freeze;
349
350         /* Should the cgroup actually be frozen? */
351         int e_freeze;
352
353         /* Fields below are protected by css_set_lock */
354
355         /* Number of frozen descendant cgroups */
356         int nr_frozen_descendants;
357
358         /*
359          * Number of tasks, which are counted as frozen:
360          * frozen, SIGSTOPped, and PTRACEd.
361          */
362         int nr_frozen_tasks;
363 };
364
365 struct cgroup {
366         /* self css with NULL ->ss, points back to this cgroup */
367         struct cgroup_subsys_state self;
368
369         unsigned long flags;            /* "unsigned long" so bitops work */
370
371         /*
372          * The depth this cgroup is at.  The root is at depth zero and each
373          * step down the hierarchy increments the level.  This along with
374          * ancestor_ids[] can determine whether a given cgroup is a
375          * descendant of another without traversing the hierarchy.
376          */
377         int level;
378
379         /* Maximum allowed descent tree depth */
380         int max_depth;
381
382         /*
383          * Keep track of total numbers of visible and dying descent cgroups.
384          * Dying cgroups are cgroups which were deleted by a user,
385          * but are still existing because someone else is holding a reference.
386          * max_descendants is a maximum allowed number of descent cgroups.
387          *
388          * nr_descendants and nr_dying_descendants are protected
389          * by cgroup_mutex and css_set_lock. It's fine to read them holding
390          * any of cgroup_mutex and css_set_lock; for writing both locks
391          * should be held.
392          */
393         int nr_descendants;
394         int nr_dying_descendants;
395         int max_descendants;
396
397         /*
398          * Each non-empty css_set associated with this cgroup contributes
399          * one to nr_populated_csets.  The counter is zero iff this cgroup
400          * doesn't have any tasks.
401          *
402          * All children which have non-zero nr_populated_csets and/or
403          * nr_populated_children of their own contribute one to either
404          * nr_populated_domain_children or nr_populated_threaded_children
405          * depending on their type.  Each counter is zero iff all cgroups
406          * of the type in the subtree proper don't have any tasks.
407          */
408         int nr_populated_csets;
409         int nr_populated_domain_children;
410         int nr_populated_threaded_children;
411
412         int nr_threaded_children;       /* # of live threaded child cgroups */
413
414         struct kernfs_node *kn;         /* cgroup kernfs entry */
415         struct cgroup_file procs_file;  /* handle for "cgroup.procs" */
416         struct cgroup_file events_file; /* handle for "cgroup.events" */
417
418         /*
419          * The bitmask of subsystems enabled on the child cgroups.
420          * ->subtree_control is the one configured through
421          * "cgroup.subtree_control" while ->subtree_ss_mask is the effective
422          * one which may have more subsystems enabled.  Controller knobs
423          * are made available iff it's enabled in ->subtree_control.
424          */
425         u16 subtree_control;
426         u16 subtree_ss_mask;
427         u16 old_subtree_control;
428         u16 old_subtree_ss_mask;
429
430         /* Private pointers for each registered subsystem */
431         struct cgroup_subsys_state __rcu *subsys[CGROUP_SUBSYS_COUNT];
432
433         struct cgroup_root *root;
434
435         /*
436          * List of cgrp_cset_links pointing at css_sets with tasks in this
437          * cgroup.  Protected by css_set_lock.
438          */
439         struct list_head cset_links;
440
441         /*
442          * On the default hierarchy, a css_set for a cgroup with some
443          * susbsys disabled will point to css's which are associated with
444          * the closest ancestor which has the subsys enabled.  The
445          * following lists all css_sets which point to this cgroup's css
446          * for the given subsystem.
447          */
448         struct list_head e_csets[CGROUP_SUBSYS_COUNT];
449
450         /*
451          * If !threaded, self.  If threaded, it points to the nearest
452          * domain ancestor.  Inside a threaded subtree, cgroups are exempt
453          * from process granularity and no-internal-task constraint.
454          * Domain level resource consumptions which aren't tied to a
455          * specific task are charged to the dom_cgrp.
456          */
457         struct cgroup *dom_cgrp;
458         struct cgroup *old_dom_cgrp;            /* used while enabling threaded */
459
460         /* per-cpu recursive resource statistics */
461         struct cgroup_rstat_cpu __percpu *rstat_cpu;
462         struct list_head rstat_css_list;
463
464         /* cgroup basic resource statistics */
465         struct cgroup_base_stat last_bstat;
466         struct cgroup_base_stat bstat;
467         struct prev_cputime prev_cputime;       /* for printing out cputime */
468
469         /*
470          * list of pidlists, up to two for each namespace (one for procs, one
471          * for tasks); created on demand.
472          */
473         struct list_head pidlists;
474         struct mutex pidlist_mutex;
475
476         /* used to wait for offlining of csses */
477         wait_queue_head_t offline_waitq;
478
479         /* used to schedule release agent */
480         struct work_struct release_agent_work;
481
482         /* used to track pressure stalls */
483         struct psi_group psi;
484
485         /* used to store eBPF programs */
486         struct cgroup_bpf bpf;
487
488         /* If there is block congestion on this cgroup. */
489         atomic_t congestion_count;
490
491         /* Used to store internal freezer state */
492         struct cgroup_freezer_state freezer;
493
494         /* ids of the ancestors at each level including self */
495         u64 ancestor_ids[];
496 };
497
498 /*
499  * A cgroup_root represents the root of a cgroup hierarchy, and may be
500  * associated with a kernfs_root to form an active hierarchy.  This is
501  * internal to cgroup core.  Don't access directly from controllers.
502  */
503 struct cgroup_root {
504         struct kernfs_root *kf_root;
505
506         /* The bitmask of subsystems attached to this hierarchy */
507         unsigned int subsys_mask;
508
509         /* Unique id for this hierarchy. */
510         int hierarchy_id;
511
512         /* The root cgroup.  Root is destroyed on its release. */
513         struct cgroup cgrp;
514
515         /* for cgrp->ancestor_ids[0] */
516         u64 cgrp_ancestor_id_storage;
517
518         /* Number of cgroups in the hierarchy, used only for /proc/cgroups */
519         atomic_t nr_cgrps;
520
521         /* A list running through the active hierarchies */
522         struct list_head root_list;
523
524         /* Hierarchy-specific flags */
525         unsigned int flags;
526
527         /* The path to use for release notifications. */
528         char release_agent_path[PATH_MAX];
529
530         /* The name for this hierarchy - may be empty */
531         char name[MAX_CGROUP_ROOT_NAMELEN];
532 };
533
534 /*
535  * struct cftype: handler definitions for cgroup control files
536  *
537  * When reading/writing to a file:
538  *      - the cgroup to use is file->f_path.dentry->d_parent->d_fsdata
539  *      - the 'cftype' of the file is file->f_path.dentry->d_fsdata
540  */
541 struct cftype {
542         /*
543          * By convention, the name should begin with the name of the
544          * subsystem, followed by a period.  Zero length string indicates
545          * end of cftype array.
546          */
547         char name[MAX_CFTYPE_NAME];
548         unsigned long private;
549
550         /*
551          * The maximum length of string, excluding trailing nul, that can
552          * be passed to write.  If < PAGE_SIZE-1, PAGE_SIZE-1 is assumed.
553          */
554         size_t max_write_len;
555
556         /* CFTYPE_* flags */
557         unsigned int flags;
558
559         /*
560          * If non-zero, should contain the offset from the start of css to
561          * a struct cgroup_file field.  cgroup will record the handle of
562          * the created file into it.  The recorded handle can be used as
563          * long as the containing css remains accessible.
564          */
565         unsigned int file_offset;
566
567         /*
568          * Fields used for internal bookkeeping.  Initialized automatically
569          * during registration.
570          */
571         struct cgroup_subsys *ss;       /* NULL for cgroup core files */
572         struct list_head node;          /* anchored at ss->cfts */
573         struct kernfs_ops *kf_ops;
574
575         int (*open)(struct kernfs_open_file *of);
576         void (*release)(struct kernfs_open_file *of);
577
578         /*
579          * read_u64() is a shortcut for the common case of returning a
580          * single integer. Use it in place of read()
581          */
582         u64 (*read_u64)(struct cgroup_subsys_state *css, struct cftype *cft);
583         /*
584          * read_s64() is a signed version of read_u64()
585          */
586         s64 (*read_s64)(struct cgroup_subsys_state *css, struct cftype *cft);
587
588         /* generic seq_file read interface */
589         int (*seq_show)(struct seq_file *sf, void *v);
590
591         /* optional ops, implement all or none */
592         void *(*seq_start)(struct seq_file *sf, loff_t *ppos);
593         void *(*seq_next)(struct seq_file *sf, void *v, loff_t *ppos);
594         void (*seq_stop)(struct seq_file *sf, void *v);
595
596         /*
597          * write_u64() is a shortcut for the common case of accepting
598          * a single integer (as parsed by simple_strtoull) from
599          * userspace. Use in place of write(); return 0 or error.
600          */
601         int (*write_u64)(struct cgroup_subsys_state *css, struct cftype *cft,
602                          u64 val);
603         /*
604          * write_s64() is a signed version of write_u64()
605          */
606         int (*write_s64)(struct cgroup_subsys_state *css, struct cftype *cft,
607                          s64 val);
608
609         /*
610          * write() is the generic write callback which maps directly to
611          * kernfs write operation and overrides all other operations.
612          * Maximum write size is determined by ->max_write_len.  Use
613          * of_css/cft() to access the associated css and cft.
614          */
615         ssize_t (*write)(struct kernfs_open_file *of,
616                          char *buf, size_t nbytes, loff_t off);
617
618         __poll_t (*poll)(struct kernfs_open_file *of,
619                          struct poll_table_struct *pt);
620
621 #ifdef CONFIG_DEBUG_LOCK_ALLOC
622         struct lock_class_key   lockdep_key;
623 #endif
624 };
625
626 /*
627  * Control Group subsystem type.
628  * See Documentation/admin-guide/cgroup-v1/cgroups.rst for details
629  */
630 struct cgroup_subsys {
631         struct cgroup_subsys_state *(*css_alloc)(struct cgroup_subsys_state *parent_css);
632         int (*css_online)(struct cgroup_subsys_state *css);
633         void (*css_offline)(struct cgroup_subsys_state *css);
634         void (*css_released)(struct cgroup_subsys_state *css);
635         void (*css_free)(struct cgroup_subsys_state *css);
636         void (*css_reset)(struct cgroup_subsys_state *css);
637         void (*css_rstat_flush)(struct cgroup_subsys_state *css, int cpu);
638         int (*css_extra_stat_show)(struct seq_file *seq,
639                                    struct cgroup_subsys_state *css);
640
641         int (*can_attach)(struct cgroup_taskset *tset);
642         void (*cancel_attach)(struct cgroup_taskset *tset);
643         void (*attach)(struct cgroup_taskset *tset);
644         void (*post_attach)(void);
645         int (*can_fork)(struct task_struct *task,
646                         struct css_set *cset);
647         void (*cancel_fork)(struct task_struct *task, struct css_set *cset);
648         void (*fork)(struct task_struct *task);
649         void (*exit)(struct task_struct *task);
650         void (*release)(struct task_struct *task);
651         void (*bind)(struct cgroup_subsys_state *root_css);
652
653         bool early_init:1;
654
655         /*
656          * If %true, the controller, on the default hierarchy, doesn't show
657          * up in "cgroup.controllers" or "cgroup.subtree_control", is
658          * implicitly enabled on all cgroups on the default hierarchy, and
659          * bypasses the "no internal process" constraint.  This is for
660          * utility type controllers which is transparent to userland.
661          *
662          * An implicit controller can be stolen from the default hierarchy
663          * anytime and thus must be okay with offline csses from previous
664          * hierarchies coexisting with csses for the current one.
665          */
666         bool implicit_on_dfl:1;
667
668         /*
669          * If %true, the controller, supports threaded mode on the default
670          * hierarchy.  In a threaded subtree, both process granularity and
671          * no-internal-process constraint are ignored and a threaded
672          * controllers should be able to handle that.
673          *
674          * Note that as an implicit controller is automatically enabled on
675          * all cgroups on the default hierarchy, it should also be
676          * threaded.  implicit && !threaded is not supported.
677          */
678         bool threaded:1;
679
680         /* the following two fields are initialized automatically during boot */
681         int id;
682         const char *name;
683
684         /* optional, initialized automatically during boot if not set */
685         const char *legacy_name;
686
687         /* link to parent, protected by cgroup_lock() */
688         struct cgroup_root *root;
689
690         /* idr for css->id */
691         struct idr css_idr;
692
693         /*
694          * List of cftypes.  Each entry is the first entry of an array
695          * terminated by zero length name.
696          */
697         struct list_head cfts;
698
699         /*
700          * Base cftypes which are automatically registered.  The two can
701          * point to the same array.
702          */
703         struct cftype *dfl_cftypes;     /* for the default hierarchy */
704         struct cftype *legacy_cftypes;  /* for the legacy hierarchies */
705
706         /*
707          * A subsystem may depend on other subsystems.  When such subsystem
708          * is enabled on a cgroup, the depended-upon subsystems are enabled
709          * together if available.  Subsystems enabled due to dependency are
710          * not visible to userland until explicitly enabled.  The following
711          * specifies the mask of subsystems that this one depends on.
712          */
713         unsigned int depends_on;
714 };
715
716 extern struct percpu_rw_semaphore cgroup_threadgroup_rwsem;
717
718 /**
719  * cgroup_threadgroup_change_begin - threadgroup exclusion for cgroups
720  * @tsk: target task
721  *
722  * Allows cgroup operations to synchronize against threadgroup changes
723  * using a percpu_rw_semaphore.
724  */
725 static inline void cgroup_threadgroup_change_begin(struct task_struct *tsk)
726 {
727         percpu_down_read(&cgroup_threadgroup_rwsem);
728 }
729
730 /**
731  * cgroup_threadgroup_change_end - threadgroup exclusion for cgroups
732  * @tsk: target task
733  *
734  * Counterpart of cgroup_threadcgroup_change_begin().
735  */
736 static inline void cgroup_threadgroup_change_end(struct task_struct *tsk)
737 {
738         percpu_up_read(&cgroup_threadgroup_rwsem);
739 }
740
741 #else   /* CONFIG_CGROUPS */
742
743 #define CGROUP_SUBSYS_COUNT 0
744
745 static inline void cgroup_threadgroup_change_begin(struct task_struct *tsk)
746 {
747         might_sleep();
748 }
749
750 static inline void cgroup_threadgroup_change_end(struct task_struct *tsk) {}
751
752 #endif  /* CONFIG_CGROUPS */
753
754 #ifdef CONFIG_SOCK_CGROUP_DATA
755
756 /*
757  * sock_cgroup_data is embedded at sock->sk_cgrp_data and contains
758  * per-socket cgroup information except for memcg association.
759  *
760  * On legacy hierarchies, net_prio and net_cls controllers directly
761  * set attributes on each sock which can then be tested by the network
762  * layer. On the default hierarchy, each sock is associated with the
763  * cgroup it was created in and the networking layer can match the
764  * cgroup directly.
765  */
766 struct sock_cgroup_data {
767         struct cgroup   *cgroup; /* v2 */
768 #ifdef CONFIG_CGROUP_NET_CLASSID
769         u32             classid; /* v1 */
770 #endif
771 #ifdef CONFIG_CGROUP_NET_PRIO
772         u16             prioidx; /* v1 */
773 #endif
774 };
775
776 static inline u16 sock_cgroup_prioidx(const struct sock_cgroup_data *skcd)
777 {
778 #ifdef CONFIG_CGROUP_NET_PRIO
779         return READ_ONCE(skcd->prioidx);
780 #else
781         return 1;
782 #endif
783 }
784
785 static inline u32 sock_cgroup_classid(const struct sock_cgroup_data *skcd)
786 {
787 #ifdef CONFIG_CGROUP_NET_CLASSID
788         return READ_ONCE(skcd->classid);
789 #else
790         return 0;
791 #endif
792 }
793
794 static inline void sock_cgroup_set_prioidx(struct sock_cgroup_data *skcd,
795                                            u16 prioidx)
796 {
797 #ifdef CONFIG_CGROUP_NET_PRIO
798         WRITE_ONCE(skcd->prioidx, prioidx);
799 #endif
800 }
801
802 static inline void sock_cgroup_set_classid(struct sock_cgroup_data *skcd,
803                                            u32 classid)
804 {
805 #ifdef CONFIG_CGROUP_NET_CLASSID
806         WRITE_ONCE(skcd->classid, classid);
807 #endif
808 }
809
810 #else   /* CONFIG_SOCK_CGROUP_DATA */
811
812 struct sock_cgroup_data {
813 };
814
815 #endif  /* CONFIG_SOCK_CGROUP_DATA */
816
817 #endif  /* _LINUX_CGROUP_DEFS_H */