1
2
3
4
5
6
7
8#ifndef _MISC_CGROUP_H_
9#define _MISC_CGROUP_H_
10
11
12
13
14enum misc_res_type {
15#ifdef CONFIG_KVM_AMD_SEV
16
17 MISC_CG_RES_SEV,
18
19 MISC_CG_RES_SEV_ES,
20#endif
21 MISC_CG_RES_TYPES
22};
23
24struct misc_cg;
25
26#ifdef CONFIG_CGROUP_MISC
27
28#include <linux/cgroup.h>
29
30
31
32
33
34
35
36struct misc_res {
37 unsigned long max;
38 atomic_long_t usage;
39 bool failed;
40};
41
42
43
44
45
46
47struct misc_cg {
48 struct cgroup_subsys_state css;
49 struct misc_res res[MISC_CG_RES_TYPES];
50};
51
52unsigned long misc_cg_res_total_usage(enum misc_res_type type);
53int misc_cg_set_capacity(enum misc_res_type type, unsigned long capacity);
54int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
55 unsigned long amount);
56void misc_cg_uncharge(enum misc_res_type type, struct misc_cg *cg,
57 unsigned long amount);
58
59
60
61
62
63
64
65
66
67
68static inline struct misc_cg *css_misc(struct cgroup_subsys_state *css)
69{
70 return css ? container_of(css, struct misc_cg, css) : NULL;
71}
72
73
74
75
76
77
78
79
80
81static inline struct misc_cg *get_current_misc_cg(void)
82{
83 return css_misc(task_get_css(current, misc_cgrp_id));
84}
85
86
87
88
89
90static inline void put_misc_cg(struct misc_cg *cg)
91{
92 if (cg)
93 css_put(&cg->css);
94}
95
96#else
97
98static inline unsigned long misc_cg_res_total_usage(enum misc_res_type type)
99{
100 return 0;
101}
102
103static inline int misc_cg_set_capacity(enum misc_res_type type,
104 unsigned long capacity)
105{
106 return 0;
107}
108
109static inline int misc_cg_try_charge(enum misc_res_type type,
110 struct misc_cg *cg,
111 unsigned long amount)
112{
113 return 0;
114}
115
116static inline void misc_cg_uncharge(enum misc_res_type type,
117 struct misc_cg *cg,
118 unsigned long amount)
119{
120}
121
122static inline struct misc_cg *get_current_misc_cg(void)
123{
124 return NULL;
125}
126
127static inline void put_misc_cg(struct misc_cg *cg)
128{
129}
130
131#endif
132#endif
133