aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/local_storage.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/bpf/local_storage.c')
-rw-r--r--kernel/bpf/local_storage.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c
index 22ad967d1e5f..0bd9f19fc557 100644
--- a/kernel/bpf/local_storage.c
+++ b/kernel/bpf/local_storage.c
@@ -7,7 +7,7 @@
7#include <linux/rbtree.h> 7#include <linux/rbtree.h>
8#include <linux/slab.h> 8#include <linux/slab.h>
9 9
10DEFINE_PER_CPU(void*, bpf_cgroup_storage); 10DEFINE_PER_CPU(void*, bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]);
11 11
12#ifdef CONFIG_CGROUP_BPF 12#ifdef CONFIG_CGROUP_BPF
13 13
@@ -251,6 +251,7 @@ const struct bpf_map_ops cgroup_storage_map_ops = {
251 251
252int bpf_cgroup_storage_assign(struct bpf_prog *prog, struct bpf_map *_map) 252int bpf_cgroup_storage_assign(struct bpf_prog *prog, struct bpf_map *_map)
253{ 253{
254 enum bpf_cgroup_storage_type stype = cgroup_storage_type(_map);
254 struct bpf_cgroup_storage_map *map = map_to_storage(_map); 255 struct bpf_cgroup_storage_map *map = map_to_storage(_map);
255 int ret = -EBUSY; 256 int ret = -EBUSY;
256 257
@@ -258,11 +259,12 @@ int bpf_cgroup_storage_assign(struct bpf_prog *prog, struct bpf_map *_map)
258 259
259 if (map->prog && map->prog != prog) 260 if (map->prog && map->prog != prog)
260 goto unlock; 261 goto unlock;
261 if (prog->aux->cgroup_storage && prog->aux->cgroup_storage != _map) 262 if (prog->aux->cgroup_storage[stype] &&
263 prog->aux->cgroup_storage[stype] != _map)
262 goto unlock; 264 goto unlock;
263 265
264 map->prog = prog; 266 map->prog = prog;
265 prog->aux->cgroup_storage = _map; 267 prog->aux->cgroup_storage[stype] = _map;
266 ret = 0; 268 ret = 0;
267unlock: 269unlock:
268 spin_unlock_bh(&map->lock); 270 spin_unlock_bh(&map->lock);
@@ -272,24 +274,26 @@ unlock:
272 274
273void bpf_cgroup_storage_release(struct bpf_prog *prog, struct bpf_map *_map) 275void bpf_cgroup_storage_release(struct bpf_prog *prog, struct bpf_map *_map)
274{ 276{
277 enum bpf_cgroup_storage_type stype = cgroup_storage_type(_map);
275 struct bpf_cgroup_storage_map *map = map_to_storage(_map); 278 struct bpf_cgroup_storage_map *map = map_to_storage(_map);
276 279
277 spin_lock_bh(&map->lock); 280 spin_lock_bh(&map->lock);
278 if (map->prog == prog) { 281 if (map->prog == prog) {
279 WARN_ON(prog->aux->cgroup_storage != _map); 282 WARN_ON(prog->aux->cgroup_storage[stype] != _map);
280 map->prog = NULL; 283 map->prog = NULL;
281 prog->aux->cgroup_storage = NULL; 284 prog->aux->cgroup_storage[stype] = NULL;
282 } 285 }
283 spin_unlock_bh(&map->lock); 286 spin_unlock_bh(&map->lock);
284} 287}
285 288
286struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog) 289struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog,
290 enum bpf_cgroup_storage_type stype)
287{ 291{
288 struct bpf_cgroup_storage *storage; 292 struct bpf_cgroup_storage *storage;
289 struct bpf_map *map; 293 struct bpf_map *map;
290 u32 pages; 294 u32 pages;
291 295
292 map = prog->aux->cgroup_storage; 296 map = prog->aux->cgroup_storage[stype];
293 if (!map) 297 if (!map)
294 return NULL; 298 return NULL;
295 299