1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Miscellaneous cgroup controller.
5 * Copyright 2020 Google LLC
6 * Author: Vipin Sharma <vipinsh@google.com>
8 #ifndef _MISC_CGROUP_H_
9 #define _MISC_CGROUP_H_
12 * enum misc_res_type - Types of misc cgroup entries supported by the host.
15 #ifdef CONFIG_KVM_AMD_SEV
16 /** @MISC_CG_RES_SEV: AMD SEV ASIDs resource */
18 /** @MISC_CG_RES_SEV_ES: AMD SEV-ES ASIDs resource */
21 #ifdef CONFIG_INTEL_TDX_HOST
22 /* Intel TDX HKIDs resource */
25 /** @MISC_CG_RES_TYPES: count of enum misc_res_type constants */
31 #ifdef CONFIG_CGROUP_MISC
33 #include <linux/cgroup.h>
36 * struct misc_res: Per cgroup per misc type resource
37 * @max: Maximum limit on the resource.
38 * @watermark: Historical maximum usage of the resource.
39 * @usage: Current usage of the resource.
40 * @events: Number of times, the resource limit exceeded.
47 atomic64_t events_local;
51 * struct misc_cg - Miscellaneous controller's cgroup structure.
52 * @css: cgroup subsys state object.
53 * @events_file: Handle for the misc resources events file.
54 * @res: Array of misc resources usage in the cgroup.
57 struct cgroup_subsys_state css;
60 struct cgroup_file events_file;
61 /* misc.events.local */
62 struct cgroup_file events_local_file;
64 struct misc_res res[MISC_CG_RES_TYPES];
67 int misc_cg_set_capacity(enum misc_res_type type, u64 capacity);
68 int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg, u64 amount);
69 void misc_cg_uncharge(enum misc_res_type type, struct misc_cg *cg, u64 amount);
72 * css_misc() - Get misc cgroup from the css.
73 * @css: cgroup subsys state object.
75 * Context: Any context.
77 * * %NULL - If @css is null.
78 * * struct misc_cg* - misc cgroup pointer of the passed css.
80 static inline struct misc_cg *css_misc(struct cgroup_subsys_state *css)
82 return css ? container_of(css, struct misc_cg, css) : NULL;
86 * get_current_misc_cg() - Find and get the misc cgroup of the current task.
88 * Returned cgroup has its ref count increased by 1. Caller must call
89 * put_misc_cg() to return the reference.
91 * Return: Misc cgroup to which the current task belongs to.
93 static inline struct misc_cg *get_current_misc_cg(void)
95 return css_misc(task_get_css(current, misc_cgrp_id));
99 * put_misc_cg() - Put the misc cgroup and reduce its ref count.
100 * @cg - cgroup to put.
102 static inline void put_misc_cg(struct misc_cg *cg)
108 #else /* !CONFIG_CGROUP_MISC */
110 static inline int misc_cg_set_capacity(enum misc_res_type type, u64 capacity)
115 static inline int misc_cg_try_charge(enum misc_res_type type,
122 static inline void misc_cg_uncharge(enum misc_res_type type,
128 static inline struct misc_cg *get_current_misc_cg(void)
133 static inline void put_misc_cg(struct misc_cg *cg)
137 #endif /* CONFIG_CGROUP_MISC */
138 #endif /* _MISC_CGROUP_H_ */