diff options
Diffstat (limited to 'include/linux/bpf-cgroup.h')
-rw-r--r-- | include/linux/bpf-cgroup.h | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h index f91b0f8ff3a9..e9871b012dac 100644 --- a/include/linux/bpf-cgroup.h +++ b/include/linux/bpf-cgroup.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #ifndef _BPF_CGROUP_H | 2 | #ifndef _BPF_CGROUP_H |
3 | #define _BPF_CGROUP_H | 3 | #define _BPF_CGROUP_H |
4 | 4 | ||
5 | #include <linux/bpf.h> | ||
5 | #include <linux/errno.h> | 6 | #include <linux/errno.h> |
6 | #include <linux/jump_label.h> | 7 | #include <linux/jump_label.h> |
7 | #include <linux/percpu.h> | 8 | #include <linux/percpu.h> |
@@ -22,7 +23,10 @@ struct bpf_cgroup_storage; | |||
22 | extern struct static_key_false cgroup_bpf_enabled_key; | 23 | extern struct static_key_false cgroup_bpf_enabled_key; |
23 | #define cgroup_bpf_enabled static_branch_unlikely(&cgroup_bpf_enabled_key) | 24 | #define cgroup_bpf_enabled static_branch_unlikely(&cgroup_bpf_enabled_key) |
24 | 25 | ||
25 | DECLARE_PER_CPU(void*, bpf_cgroup_storage); | 26 | DECLARE_PER_CPU(void*, bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]); |
27 | |||
28 | #define for_each_cgroup_storage_type(stype) \ | ||
29 | for (stype = 0; stype < MAX_BPF_CGROUP_STORAGE_TYPE; stype++) | ||
26 | 30 | ||
27 | struct bpf_cgroup_storage_map; | 31 | struct bpf_cgroup_storage_map; |
28 | 32 | ||
@@ -43,7 +47,7 @@ struct bpf_cgroup_storage { | |||
43 | struct bpf_prog_list { | 47 | struct bpf_prog_list { |
44 | struct list_head node; | 48 | struct list_head node; |
45 | struct bpf_prog *prog; | 49 | struct bpf_prog *prog; |
46 | struct bpf_cgroup_storage *storage; | 50 | struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE]; |
47 | }; | 51 | }; |
48 | 52 | ||
49 | struct bpf_prog_array; | 53 | struct bpf_prog_array; |
@@ -101,18 +105,29 @@ int __cgroup_bpf_run_filter_sock_ops(struct sock *sk, | |||
101 | int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor, | 105 | int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor, |
102 | short access, enum bpf_attach_type type); | 106 | short access, enum bpf_attach_type type); |
103 | 107 | ||
104 | static inline void bpf_cgroup_storage_set(struct bpf_cgroup_storage *storage) | 108 | static inline enum bpf_cgroup_storage_type cgroup_storage_type( |
109 | struct bpf_map *map) | ||
105 | { | 110 | { |
111 | return BPF_CGROUP_STORAGE_SHARED; | ||
112 | } | ||
113 | |||
114 | static inline void bpf_cgroup_storage_set(struct bpf_cgroup_storage | ||
115 | *storage[MAX_BPF_CGROUP_STORAGE_TYPE]) | ||
116 | { | ||
117 | enum bpf_cgroup_storage_type stype; | ||
106 | struct bpf_storage_buffer *buf; | 118 | struct bpf_storage_buffer *buf; |
107 | 119 | ||
108 | if (!storage) | 120 | for_each_cgroup_storage_type(stype) { |
109 | return; | 121 | if (!storage[stype]) |
122 | continue; | ||
110 | 123 | ||
111 | buf = READ_ONCE(storage->buf); | 124 | buf = READ_ONCE(storage[stype]->buf); |
112 | this_cpu_write(bpf_cgroup_storage, &buf->data[0]); | 125 | this_cpu_write(bpf_cgroup_storage[stype], &buf->data[0]); |
126 | } | ||
113 | } | 127 | } |
114 | 128 | ||
115 | struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog); | 129 | struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog, |
130 | enum bpf_cgroup_storage_type stype); | ||
116 | void bpf_cgroup_storage_free(struct bpf_cgroup_storage *storage); | 131 | void bpf_cgroup_storage_free(struct bpf_cgroup_storage *storage); |
117 | void bpf_cgroup_storage_link(struct bpf_cgroup_storage *storage, | 132 | void bpf_cgroup_storage_link(struct bpf_cgroup_storage *storage, |
118 | struct cgroup *cgroup, | 133 | struct cgroup *cgroup, |
@@ -265,13 +280,14 @@ static inline int cgroup_bpf_prog_query(const union bpf_attr *attr, | |||
265 | return -EINVAL; | 280 | return -EINVAL; |
266 | } | 281 | } |
267 | 282 | ||
268 | static inline void bpf_cgroup_storage_set(struct bpf_cgroup_storage *storage) {} | 283 | static inline void bpf_cgroup_storage_set( |
284 | struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE]) {} | ||
269 | static inline int bpf_cgroup_storage_assign(struct bpf_prog *prog, | 285 | static inline int bpf_cgroup_storage_assign(struct bpf_prog *prog, |
270 | struct bpf_map *map) { return 0; } | 286 | struct bpf_map *map) { return 0; } |
271 | static inline void bpf_cgroup_storage_release(struct bpf_prog *prog, | 287 | static inline void bpf_cgroup_storage_release(struct bpf_prog *prog, |
272 | struct bpf_map *map) {} | 288 | struct bpf_map *map) {} |
273 | static inline struct bpf_cgroup_storage *bpf_cgroup_storage_alloc( | 289 | static inline struct bpf_cgroup_storage *bpf_cgroup_storage_alloc( |
274 | struct bpf_prog *prog) { return 0; } | 290 | struct bpf_prog *prog, enum bpf_cgroup_storage_type stype) { return 0; } |
275 | static inline void bpf_cgroup_storage_free( | 291 | static inline void bpf_cgroup_storage_free( |
276 | struct bpf_cgroup_storage *storage) {} | 292 | struct bpf_cgroup_storage *storage) {} |
277 | 293 | ||
@@ -293,6 +309,8 @@ static inline void bpf_cgroup_storage_free( | |||
293 | #define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) ({ 0; }) | 309 | #define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) ({ 0; }) |
294 | #define BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(type,major,minor,access) ({ 0; }) | 310 | #define BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(type,major,minor,access) ({ 0; }) |
295 | 311 | ||
312 | #define for_each_cgroup_storage_type(stype) for (; false; ) | ||
313 | |||
296 | #endif /* CONFIG_CGROUP_BPF */ | 314 | #endif /* CONFIG_CGROUP_BPF */ |
297 | 315 | ||
298 | #endif /* _BPF_CGROUP_H */ | 316 | #endif /* _BPF_CGROUP_H */ |