cgroup-defs.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /*
  2. * linux/cgroup-defs.h - basic definitions for cgroup
  3. *
  4. * This file provides basic type and interface. Include this file directly
  5. * only if necessary to avoid cyclic dependencies.
  6. */
  7. #ifndef _LINUX_CGROUP_DEFS_H
  8. #define _LINUX_CGROUP_DEFS_H
  9. #include <linux/limits.h>
  10. #include <linux/list.h>
  11. #include <linux/idr.h>
  12. #include <linux/wait.h>
  13. #include <linux/mutex.h>
  14. #include <linux/rcupdate.h>
  15. #include <linux/percpu-refcount.h>
  16. #include <linux/percpu-rwsem.h>
  17. #include <linux/workqueue.h>
  18. #ifdef CONFIG_CGROUPS
  19. struct cgroup;
  20. struct cgroup_root;
  21. struct cgroup_subsys;
  22. struct cgroup_taskset;
  23. struct kernfs_node;
  24. struct kernfs_ops;
  25. struct kernfs_open_file;
  26. struct seq_file;
  27. #define MAX_CGROUP_TYPE_NAMELEN 32
  28. #define MAX_CGROUP_ROOT_NAMELEN 64
  29. #define MAX_CFTYPE_NAME 64
  30. /* define the enumeration of all cgroup subsystems */
  31. #define SUBSYS(_x) _x ## _cgrp_id,
  32. enum cgroup_subsys_id {
  33. #include <linux/cgroup_subsys.h>
  34. CGROUP_SUBSYS_COUNT,
  35. };
  36. #undef SUBSYS
  37. /* bits in struct cgroup_subsys_state flags field */
  38. enum {
  39. CSS_NO_REF = (1 << 0), /* no reference counting for this css */
  40. CSS_ONLINE = (1 << 1), /* between ->css_online() and ->css_offline() */
  41. CSS_RELEASED = (1 << 2), /* refcnt reached zero, released */
  42. CSS_VISIBLE = (1 << 3), /* css is visible to userland */
  43. CSS_DYING = (1 << 4), /* css is dying */
  44. };
  45. /* bits in struct cgroup flags field */
  46. enum {
  47. /* Control Group requires release notifications to userspace */
  48. CGRP_NOTIFY_ON_RELEASE,
  49. /*
  50. * Clone the parent's configuration when creating a new child
  51. * cpuset cgroup. For historical reasons, this option can be
  52. * specified at mount time and thus is implemented here.
  53. */
  54. CGRP_CPUSET_CLONE_CHILDREN,
  55. };
  56. /* cgroup_root->flags */
  57. enum {
  58. CGRP_ROOT_NOPREFIX = (1 << 1), /* mounted subsystems have no named prefix */
  59. CGRP_ROOT_XATTR = (1 << 2), /* supports extended attributes */
  60. };
  61. /* cftype->flags */
  62. enum {
  63. CFTYPE_ONLY_ON_ROOT = (1 << 0), /* only create on root cgrp */
  64. CFTYPE_NOT_ON_ROOT = (1 << 1), /* don't create on root cgrp */
  65. CFTYPE_NO_PREFIX = (1 << 3), /* (DON'T USE FOR NEW FILES) no subsys prefix */
  66. CFTYPE_WORLD_WRITABLE = (1 << 4), /* (DON'T USE FOR NEW FILES) S_IWUGO */
  67. /* internal flags, do not use outside cgroup core proper */
  68. __CFTYPE_ONLY_ON_DFL = (1 << 16), /* only on default hierarchy */
  69. __CFTYPE_NOT_ON_DFL = (1 << 17), /* not on default hierarchy */
  70. };
  71. /*
  72. * cgroup_file is the handle for a file instance created in a cgroup which
  73. * is used, for example, to generate file changed notifications. This can
  74. * be obtained by setting cftype->file_offset.
  75. */
  76. struct cgroup_file {
  77. /* do not access any fields from outside cgroup core */
  78. struct kernfs_node *kn;
  79. };
  80. /*
  81. * Per-subsystem/per-cgroup state maintained by the system. This is the
  82. * fundamental structural building block that controllers deal with.
  83. *
  84. * Fields marked with "PI:" are public and immutable and may be accessed
  85. * directly without synchronization.
  86. */
  87. struct cgroup_subsys_state {
  88. /* PI: the cgroup that this css is attached to */
  89. struct cgroup *cgroup;
  90. /* PI: the cgroup subsystem that this css is attached to */
  91. struct cgroup_subsys *ss;
  92. /* reference count - access via css_[try]get() and css_put() */
  93. struct percpu_ref refcnt;
  94. /* PI: the parent css */
  95. struct cgroup_subsys_state *parent;
  96. /* siblings list anchored at the parent's ->children */
  97. struct list_head sibling;
  98. struct list_head children;
  99. /*
  100. * PI: Subsys-unique ID. 0 is unused and root is always 1. The
  101. * matching css can be looked up using css_from_id().
  102. */
  103. int id;
  104. unsigned int flags;
  105. /*
  106. * Monotonically increasing unique serial number which defines a
  107. * uniform order among all csses. It's guaranteed that all
  108. * ->children lists are in the ascending order of ->serial_nr and
  109. * used to allow interrupting and resuming iterations.
  110. */
  111. u64 serial_nr;
  112. /*
  113. * Incremented by online self and children. Used to guarantee that
  114. * parents are not offlined before their children.
  115. */
  116. atomic_t online_cnt;
  117. /* percpu_ref killing and RCU release */
  118. struct rcu_head rcu_head;
  119. struct work_struct destroy_work;
  120. };
  121. /*
  122. * A css_set is a structure holding pointers to a set of
  123. * cgroup_subsys_state objects. This saves space in the task struct
  124. * object and speeds up fork()/exit(), since a single inc/dec and a
  125. * list_add()/del() can bump the reference count on the entire cgroup
  126. * set for a task.
  127. */
  128. struct css_set {
  129. /* Reference count */
  130. atomic_t refcount;
  131. /*
  132. * List running through all cgroup groups in the same hash
  133. * slot. Protected by css_set_lock
  134. */
  135. struct hlist_node hlist;
  136. /*
  137. * Lists running through all tasks using this cgroup group.
  138. * mg_tasks lists tasks which belong to this cset but are in the
  139. * process of being migrated out or in. Protected by
  140. * css_set_rwsem, but, during migration, once tasks are moved to
  141. * mg_tasks, it can be read safely while holding cgroup_mutex.
  142. */
  143. struct list_head tasks;
  144. struct list_head mg_tasks;
  145. /*
  146. * List of cgrp_cset_links pointing at cgroups referenced from this
  147. * css_set. Protected by css_set_lock.
  148. */
  149. struct list_head cgrp_links;
  150. /* the default cgroup associated with this css_set */
  151. struct cgroup *dfl_cgrp;
  152. /*
  153. * Set of subsystem states, one for each subsystem. This array is
  154. * immutable after creation apart from the init_css_set during
  155. * subsystem registration (at boot time).
  156. */
  157. struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT];
  158. /*
  159. * List of csets participating in the on-going migration either as
  160. * source or destination. Protected by cgroup_mutex.
  161. */
  162. struct list_head mg_preload_node;
  163. struct list_head mg_node;
  164. /*
  165. * If this cset is acting as the source of migration the following
  166. * two fields are set. mg_src_cgrp and mg_dst_cgrp are
  167. * respectively the source and destination cgroups of the on-going
  168. * migration. mg_dst_cset is the destination cset the target tasks
  169. * on this cset should be migrated to. Protected by cgroup_mutex.
  170. */
  171. struct cgroup *mg_src_cgrp;
  172. struct cgroup *mg_dst_cgrp;
  173. struct css_set *mg_dst_cset;
  174. /*
  175. * On the default hierarhcy, ->subsys[ssid] may point to a css
  176. * attached to an ancestor instead of the cgroup this css_set is
  177. * associated with. The following node is anchored at
  178. * ->subsys[ssid]->cgroup->e_csets[ssid] and provides a way to
  179. * iterate through all css's attached to a given cgroup.
  180. */
  181. struct list_head e_cset_node[CGROUP_SUBSYS_COUNT];
  182. /* all css_task_iters currently walking this cset */
  183. struct list_head task_iters;
  184. /* dead and being drained, ignore for migration */
  185. bool dead;
  186. /* For RCU-protected deletion */
  187. struct rcu_head rcu_head;
  188. };
  189. struct cgroup {
  190. /* self css with NULL ->ss, points back to this cgroup */
  191. struct cgroup_subsys_state self;
  192. unsigned long flags; /* "unsigned long" so bitops work */
  193. /*
  194. * idr allocated in-hierarchy ID.
  195. *
  196. * ID 0 is not used, the ID of the root cgroup is always 1, and a
  197. * new cgroup will be assigned with a smallest available ID.
  198. *
  199. * Allocating/Removing ID must be protected by cgroup_mutex.
  200. */
  201. int id;
  202. /*
  203. * The depth this cgroup is at. The root is at depth zero and each
  204. * step down the hierarchy increments the level. This along with
  205. * ancestor_ids[] can determine whether a given cgroup is a
  206. * descendant of another without traversing the hierarchy.
  207. */
  208. int level;
  209. /*
  210. * Each non-empty css_set associated with this cgroup contributes
  211. * one to populated_cnt. All children with non-zero popuplated_cnt
  212. * of their own contribute one. The count is zero iff there's no
  213. * task in this cgroup or its subtree.
  214. */
  215. int populated_cnt;
  216. struct kernfs_node *kn; /* cgroup kernfs entry */
  217. struct cgroup_file procs_file; /* handle for "cgroup.procs" */
  218. struct cgroup_file events_file; /* handle for "cgroup.events" */
  219. /*
  220. * The bitmask of subsystems enabled on the child cgroups.
  221. * ->subtree_control is the one configured through
  222. * "cgroup.subtree_control" while ->child_ss_mask is the effective
  223. * one which may have more subsystems enabled. Controller knobs
  224. * are made available iff it's enabled in ->subtree_control.
  225. */
  226. u16 subtree_control;
  227. u16 subtree_ss_mask;
  228. u16 old_subtree_control;
  229. u16 old_subtree_ss_mask;
  230. /* Private pointers for each registered subsystem */
  231. struct cgroup_subsys_state __rcu *subsys[CGROUP_SUBSYS_COUNT];
  232. struct cgroup_root *root;
  233. /*
  234. * List of cgrp_cset_links pointing at css_sets with tasks in this
  235. * cgroup. Protected by css_set_lock.
  236. */
  237. struct list_head cset_links;
  238. /*
  239. * On the default hierarchy, a css_set for a cgroup with some
  240. * susbsys disabled will point to css's which are associated with
  241. * the closest ancestor which has the subsys enabled. The
  242. * following lists all css_sets which point to this cgroup's css
  243. * for the given subsystem.
  244. */
  245. struct list_head e_csets[CGROUP_SUBSYS_COUNT];
  246. /*
  247. * list of pidlists, up to two for each namespace (one for procs, one
  248. * for tasks); created on demand.
  249. */
  250. struct list_head pidlists;
  251. struct mutex pidlist_mutex;
  252. /* used to wait for offlining of csses */
  253. wait_queue_head_t offline_waitq;
  254. /* used to schedule release agent */
  255. struct work_struct release_agent_work;
  256. /* ids of the ancestors at each level including self */
  257. int ancestor_ids[];
  258. };
  259. /*
  260. * A cgroup_root represents the root of a cgroup hierarchy, and may be
  261. * associated with a kernfs_root to form an active hierarchy. This is
  262. * internal to cgroup core. Don't access directly from controllers.
  263. */
  264. struct cgroup_root {
  265. struct kernfs_root *kf_root;
  266. /* The bitmask of subsystems attached to this hierarchy */
  267. unsigned int subsys_mask;
  268. /* Unique id for this hierarchy. */
  269. int hierarchy_id;
  270. /* The root cgroup. Root is destroyed on its release. */
  271. struct cgroup cgrp;
  272. /* for cgrp->ancestor_ids[0] */
  273. int cgrp_ancestor_id_storage;
  274. /* Number of cgroups in the hierarchy, used only for /proc/cgroups */
  275. atomic_t nr_cgrps;
  276. /* A list running through the active hierarchies */
  277. struct list_head root_list;
  278. /* Hierarchy-specific flags */
  279. unsigned int flags;
  280. /* IDs for cgroups in this hierarchy */
  281. struct idr cgroup_idr;
  282. /* The path to use for release notifications. */
  283. char release_agent_path[PATH_MAX];
  284. /* The name for this hierarchy - may be empty */
  285. char name[MAX_CGROUP_ROOT_NAMELEN];
  286. };
  287. /*
  288. * struct cftype: handler definitions for cgroup control files
  289. *
  290. * When reading/writing to a file:
  291. * - the cgroup to use is file->f_path.dentry->d_parent->d_fsdata
  292. * - the 'cftype' of the file is file->f_path.dentry->d_fsdata
  293. */
  294. struct cftype {
  295. /*
  296. * By convention, the name should begin with the name of the
  297. * subsystem, followed by a period. Zero length string indicates
  298. * end of cftype array.
  299. */
  300. char name[MAX_CFTYPE_NAME];
  301. unsigned long private;
  302. /*
  303. * The maximum length of string, excluding trailing nul, that can
  304. * be passed to write. If < PAGE_SIZE-1, PAGE_SIZE-1 is assumed.
  305. */
  306. size_t max_write_len;
  307. /* CFTYPE_* flags */
  308. unsigned int flags;
  309. /*
  310. * If non-zero, should contain the offset from the start of css to
  311. * a struct cgroup_file field. cgroup will record the handle of
  312. * the created file into it. The recorded handle can be used as
  313. * long as the containing css remains accessible.
  314. */
  315. unsigned int file_offset;
  316. /*
  317. * Fields used for internal bookkeeping. Initialized automatically
  318. * during registration.
  319. */
  320. struct cgroup_subsys *ss; /* NULL for cgroup core files */
  321. struct list_head node; /* anchored at ss->cfts */
  322. struct kernfs_ops *kf_ops;
  323. /*
  324. * read_u64() is a shortcut for the common case of returning a
  325. * single integer. Use it in place of read()
  326. */
  327. u64 (*read_u64)(struct cgroup_subsys_state *css, struct cftype *cft);
  328. /*
  329. * read_s64() is a signed version of read_u64()
  330. */
  331. s64 (*read_s64)(struct cgroup_subsys_state *css, struct cftype *cft);
  332. /* generic seq_file read interface */
  333. int (*seq_show)(struct seq_file *sf, void *v);
  334. /* optional ops, implement all or none */
  335. void *(*seq_start)(struct seq_file *sf, loff_t *ppos);
  336. void *(*seq_next)(struct seq_file *sf, void *v, loff_t *ppos);
  337. void (*seq_stop)(struct seq_file *sf, void *v);
  338. /*
  339. * write_u64() is a shortcut for the common case of accepting
  340. * a single integer (as parsed by simple_strtoull) from
  341. * userspace. Use in place of write(); return 0 or error.
  342. */
  343. int (*write_u64)(struct cgroup_subsys_state *css, struct cftype *cft,
  344. u64 val);
  345. /*
  346. * write_s64() is a signed version of write_u64()
  347. */
  348. int (*write_s64)(struct cgroup_subsys_state *css, struct cftype *cft,
  349. s64 val);
  350. /*
  351. * write() is the generic write callback which maps directly to
  352. * kernfs write operation and overrides all other operations.
  353. * Maximum write size is determined by ->max_write_len. Use
  354. * of_css/cft() to access the associated css and cft.
  355. */
  356. ssize_t (*write)(struct kernfs_open_file *of,
  357. char *buf, size_t nbytes, loff_t off);
  358. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  359. struct lock_class_key lockdep_key;
  360. #endif
  361. };
  362. /*
  363. * Control Group subsystem type.
  364. * See Documentation/cgroups/cgroups.txt for details
  365. */
  366. struct cgroup_subsys {
  367. struct cgroup_subsys_state *(*css_alloc)(struct cgroup_subsys_state *parent_css);
  368. int (*css_online)(struct cgroup_subsys_state *css);
  369. void (*css_offline)(struct cgroup_subsys_state *css);
  370. void (*css_released)(struct cgroup_subsys_state *css);
  371. void (*css_free)(struct cgroup_subsys_state *css);
  372. void (*css_reset)(struct cgroup_subsys_state *css);
  373. int (*can_attach)(struct cgroup_taskset *tset);
  374. void (*cancel_attach)(struct cgroup_taskset *tset);
  375. void (*attach)(struct cgroup_taskset *tset);
  376. void (*post_attach)(void);
  377. int (*can_fork)(struct task_struct *task);
  378. void (*cancel_fork)(struct task_struct *task);
  379. void (*fork)(struct task_struct *task);
  380. void (*exit)(struct task_struct *task);
  381. void (*free)(struct task_struct *task);
  382. void (*bind)(struct cgroup_subsys_state *root_css);
  383. bool early_init:1;
  384. /*
  385. * If %true, the controller, on the default hierarchy, doesn't show
  386. * up in "cgroup.controllers" or "cgroup.subtree_control", is
  387. * implicitly enabled on all cgroups on the default hierarchy, and
  388. * bypasses the "no internal process" constraint. This is for
  389. * utility type controllers which is transparent to userland.
  390. *
  391. * An implicit controller can be stolen from the default hierarchy
  392. * anytime and thus must be okay with offline csses from previous
  393. * hierarchies coexisting with csses for the current one.
  394. */
  395. bool implicit_on_dfl:1;
  396. /*
  397. * If %false, this subsystem is properly hierarchical -
  398. * configuration, resource accounting and restriction on a parent
  399. * cgroup cover those of its children. If %true, hierarchy support
  400. * is broken in some ways - some subsystems ignore hierarchy
  401. * completely while others are only implemented half-way.
  402. *
  403. * It's now disallowed to create nested cgroups if the subsystem is
  404. * broken and cgroup core will emit a warning message on such
  405. * cases. Eventually, all subsystems will be made properly
  406. * hierarchical and this will go away.
  407. */
  408. bool broken_hierarchy:1;
  409. bool warned_broken_hierarchy:1;
  410. /* the following two fields are initialized automtically during boot */
  411. int id;
  412. const char *name;
  413. /* optional, initialized automatically during boot if not set */
  414. const char *legacy_name;
  415. /* link to parent, protected by cgroup_lock() */
  416. struct cgroup_root *root;
  417. /* idr for css->id */
  418. struct idr css_idr;
  419. /*
  420. * List of cftypes. Each entry is the first entry of an array
  421. * terminated by zero length name.
  422. */
  423. struct list_head cfts;
  424. /*
  425. * Base cftypes which are automatically registered. The two can
  426. * point to the same array.
  427. */
  428. struct cftype *dfl_cftypes; /* for the default hierarchy */
  429. struct cftype *legacy_cftypes; /* for the legacy hierarchies */
  430. /*
  431. * A subsystem may depend on other subsystems. When such subsystem
  432. * is enabled on a cgroup, the depended-upon subsystems are enabled
  433. * together if available. Subsystems enabled due to dependency are
  434. * not visible to userland until explicitly enabled. The following
  435. * specifies the mask of subsystems that this one depends on.
  436. */
  437. unsigned int depends_on;
  438. };
  439. extern struct percpu_rw_semaphore cgroup_threadgroup_rwsem;
  440. /**
  441. * cgroup_threadgroup_change_begin - threadgroup exclusion for cgroups
  442. * @tsk: target task
  443. *
  444. * Called from threadgroup_change_begin() and allows cgroup operations to
  445. * synchronize against threadgroup changes using a percpu_rw_semaphore.
  446. */
  447. static inline void cgroup_threadgroup_change_begin(struct task_struct *tsk)
  448. {
  449. percpu_down_read(&cgroup_threadgroup_rwsem);
  450. }
  451. /**
  452. * cgroup_threadgroup_change_end - threadgroup exclusion for cgroups
  453. * @tsk: target task
  454. *
  455. * Called from threadgroup_change_end(). Counterpart of
  456. * cgroup_threadcgroup_change_begin().
  457. */
  458. static inline void cgroup_threadgroup_change_end(struct task_struct *tsk)
  459. {
  460. percpu_up_read(&cgroup_threadgroup_rwsem);
  461. }
  462. #else /* CONFIG_CGROUPS */
  463. #define CGROUP_SUBSYS_COUNT 0
  464. static inline void cgroup_threadgroup_change_begin(struct task_struct *tsk) {}
  465. static inline void cgroup_threadgroup_change_end(struct task_struct *tsk) {}
  466. #endif /* CONFIG_CGROUPS */
  467. #ifdef CONFIG_SOCK_CGROUP_DATA
  468. /*
  469. * sock_cgroup_data is embedded at sock->sk_cgrp_data and contains
  470. * per-socket cgroup information except for memcg association.
  471. *
  472. * On legacy hierarchies, net_prio and net_cls controllers directly set
  473. * attributes on each sock which can then be tested by the network layer.
  474. * On the default hierarchy, each sock is associated with the cgroup it was
  475. * created in and the networking layer can match the cgroup directly.
  476. *
  477. * To avoid carrying all three cgroup related fields separately in sock,
  478. * sock_cgroup_data overloads (prioidx, classid) and the cgroup pointer.
  479. * On boot, sock_cgroup_data records the cgroup that the sock was created
  480. * in so that cgroup2 matches can be made; however, once either net_prio or
  481. * net_cls starts being used, the area is overriden to carry prioidx and/or
  482. * classid. The two modes are distinguished by whether the lowest bit is
  483. * set. Clear bit indicates cgroup pointer while set bit prioidx and
  484. * classid.
  485. *
  486. * While userland may start using net_prio or net_cls at any time, once
  487. * either is used, cgroup2 matching no longer works. There is no reason to
  488. * mix the two and this is in line with how legacy and v2 compatibility is
  489. * handled. On mode switch, cgroup references which are already being
  490. * pointed to by socks may be leaked. While this can be remedied by adding
  491. * synchronization around sock_cgroup_data, given that the number of leaked
  492. * cgroups is bound and highly unlikely to be high, this seems to be the
  493. * better trade-off.
  494. */
  495. struct sock_cgroup_data {
  496. union {
  497. #ifdef __LITTLE_ENDIAN
  498. struct {
  499. u8 is_data;
  500. u8 padding;
  501. u16 prioidx;
  502. u32 classid;
  503. } __packed;
  504. #else
  505. struct {
  506. u32 classid;
  507. u16 prioidx;
  508. u8 padding;
  509. u8 is_data;
  510. } __packed;
  511. #endif
  512. u64 val;
  513. };
  514. };
  515. /*
  516. * There's a theoretical window where the following accessors race with
  517. * updaters and return part of the previous pointer as the prioidx or
  518. * classid. Such races are short-lived and the result isn't critical.
  519. */
  520. static inline u16 sock_cgroup_prioidx(struct sock_cgroup_data *skcd)
  521. {
  522. /* fallback to 1 which is always the ID of the root cgroup */
  523. return (skcd->is_data & 1) ? skcd->prioidx : 1;
  524. }
  525. static inline u32 sock_cgroup_classid(struct sock_cgroup_data *skcd)
  526. {
  527. /* fallback to 0 which is the unconfigured default classid */
  528. return (skcd->is_data & 1) ? skcd->classid : 0;
  529. }
  530. /*
  531. * If invoked concurrently, the updaters may clobber each other. The
  532. * caller is responsible for synchronization.
  533. */
  534. static inline void sock_cgroup_set_prioidx(struct sock_cgroup_data *skcd,
  535. u16 prioidx)
  536. {
  537. struct sock_cgroup_data skcd_buf = {{ .val = READ_ONCE(skcd->val) }};
  538. if (sock_cgroup_prioidx(&skcd_buf) == prioidx)
  539. return;
  540. if (!(skcd_buf.is_data & 1)) {
  541. skcd_buf.val = 0;
  542. skcd_buf.is_data = 1;
  543. }
  544. skcd_buf.prioidx = prioidx;
  545. WRITE_ONCE(skcd->val, skcd_buf.val); /* see sock_cgroup_ptr() */
  546. }
  547. static inline void sock_cgroup_set_classid(struct sock_cgroup_data *skcd,
  548. u32 classid)
  549. {
  550. struct sock_cgroup_data skcd_buf = {{ .val = READ_ONCE(skcd->val) }};
  551. if (sock_cgroup_classid(&skcd_buf) == classid)
  552. return;
  553. if (!(skcd_buf.is_data & 1)) {
  554. skcd_buf.val = 0;
  555. skcd_buf.is_data = 1;
  556. }
  557. skcd_buf.classid = classid;
  558. WRITE_ONCE(skcd->val, skcd_buf.val); /* see sock_cgroup_ptr() */
  559. }
  560. #else /* CONFIG_SOCK_CGROUP_DATA */
  561. struct sock_cgroup_data {
  562. };
  563. #endif /* CONFIG_SOCK_CGROUP_DATA */
  564. #endif /* _LINUX_CGROUP_DEFS_H */