diff options
author | Roman Gushchin <guro@fb.com> | 2018-09-28 10:45:36 -0400 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-10-01 10:18:32 -0400 |
commit | 8bad74f9840f87661f20ced3dc80c84ab4fd55a1 (patch) | |
tree | 1ac3ef2547d12f0fd6a232fbc1daac2672537907 /kernel/bpf/local_storage.c | |
parent | 5bf7a60b8e70969f65c961d7e2c4eb40eb2c664d (diff) |
bpf: extend cgroup bpf core to allow multiple cgroup storage types
In order to introduce per-cpu cgroup storage, let's generalize
bpf cgroup core to support multiple cgroup storage types.
Potentially, per-node cgroup storage can be added later.
This commit is mostly a formal change that replaces
cgroup_storage pointer with a array of cgroup_storage pointers.
It doesn't actually introduce a new storage type,
it will be done later.
Each bpf program is now able to have one cgroup storage of each type.
Signed-off-by: Roman Gushchin <guro@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'kernel/bpf/local_storage.c')
-rw-r--r-- | kernel/bpf/local_storage.c | 18 |
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 | ||
10 | DEFINE_PER_CPU(void*, bpf_cgroup_storage); | 10 | DEFINE_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 | ||
252 | int bpf_cgroup_storage_assign(struct bpf_prog *prog, struct bpf_map *_map) | 252 | int 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; |
267 | unlock: | 269 | unlock: |
268 | spin_unlock_bh(&map->lock); | 270 | spin_unlock_bh(&map->lock); |
@@ -272,24 +274,26 @@ unlock: | |||
272 | 274 | ||
273 | void bpf_cgroup_storage_release(struct bpf_prog *prog, struct bpf_map *_map) | 275 | void 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 | ||
286 | struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog) | 289 | struct 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 | ||