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 * Types of misc cgroup entries supported by the host.
15 #ifdef CONFIG_KVM_AMD_SEV
16 /* AMD SEV ASIDs resource */
18 /* AMD SEV-ES ASIDs resource */
26 #ifdef CONFIG_CGROUP_MISC
28 #include <linux/cgroup.h>
31 * struct misc_res: Per cgroup per misc type resource
32 * @max: Maximum limit on the resource.
33 * @usage: Current usage of the resource.
34 * @failed: True if charged failed for the resource in a cgroup.
43 * struct misc_cg - Miscellaneous controller's cgroup structure.
44 * @css: cgroup subsys state object.
45 * @res: Array of misc resources usage in the cgroup.
48 struct cgroup_subsys_state css;
49 struct misc_res res[MISC_CG_RES_TYPES];
52 unsigned long misc_cg_res_total_usage(enum misc_res_type type);
53 int misc_cg_set_capacity(enum misc_res_type type, unsigned long capacity);
54 int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
55 unsigned long amount);
56 void misc_cg_uncharge(enum misc_res_type type, struct misc_cg *cg,
57 unsigned long amount);
60 * css_misc() - Get misc cgroup from the css.
61 * @css: cgroup subsys state object.
63 * Context: Any context.
65 * * %NULL - If @css is null.
66 * * struct misc_cg* - misc cgroup pointer of the passed css.
68 static inline struct misc_cg *css_misc(struct cgroup_subsys_state *css)
70 return css ? container_of(css, struct misc_cg, css) : NULL;
74 * get_current_misc_cg() - Find and get the misc cgroup of the current task.
76 * Returned cgroup has its ref count increased by 1. Caller must call
77 * put_misc_cg() to return the reference.
79 * Return: Misc cgroup to which the current task belongs to.
81 static inline struct misc_cg *get_current_misc_cg(void)
83 return css_misc(task_get_css(current, misc_cgrp_id));
87 * put_misc_cg() - Put the misc cgroup and reduce its ref count.
88 * @cg - cgroup to put.
90 static inline void put_misc_cg(struct misc_cg *cg)
96 #else /* !CONFIG_CGROUP_MISC */
98 static inline unsigned long misc_cg_res_total_usage(enum misc_res_type type)
103 static inline int misc_cg_set_capacity(enum misc_res_type type,
104 unsigned long capacity)
109 static inline int misc_cg_try_charge(enum misc_res_type type,
111 unsigned long amount)
116 static inline void misc_cg_uncharge(enum misc_res_type type,
118 unsigned long amount)
122 static inline struct misc_cg *get_current_misc_cg(void)
127 static inline void put_misc_cg(struct misc_cg *cg)
131 #endif /* CONFIG_CGROUP_MISC */
132 #endif /* _MISC_CGROUP_H_ */