diff options
author | Roman Gushchin <guro@fb.com> | 2018-09-28 10:45:40 -0400 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-10-01 10:18:32 -0400 |
commit | f294b37ec7b24a574884cd157497a3748081c0f0 (patch) | |
tree | fb5bdf6cf4a5ff61b7a5f84274ae82c123aac7a9 | |
parent | 8bad74f9840f87661f20ced3dc80c84ab4fd55a1 (diff) |
bpf: rework cgroup storage pointer passing
To simplify the following introduction of per-cpu cgroup storage,
let's rework a bit a mechanism of passing a pointer to a cgroup
storage into the bpf_get_local_storage(). Let's save a pointer
to the corresponding bpf_cgroup_storage structure, instead of
a pointer to the actual buffer.
It will help us to handle per-cpu storage later, which has
a different way of accessing to the actual data.
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>
-rw-r--r-- | include/linux/bpf-cgroup.h | 13 | ||||
-rw-r--r-- | kernel/bpf/helpers.c | 8 | ||||
-rw-r--r-- | kernel/bpf/local_storage.c | 3 |
3 files changed, 12 insertions, 12 deletions
diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h index e9871b012dac..7e0c9a1d48b7 100644 --- a/include/linux/bpf-cgroup.h +++ b/include/linux/bpf-cgroup.h | |||
@@ -23,7 +23,8 @@ struct bpf_cgroup_storage; | |||
23 | extern struct static_key_false cgroup_bpf_enabled_key; | 23 | extern struct static_key_false cgroup_bpf_enabled_key; |
24 | #define cgroup_bpf_enabled static_branch_unlikely(&cgroup_bpf_enabled_key) | 24 | #define cgroup_bpf_enabled static_branch_unlikely(&cgroup_bpf_enabled_key) |
25 | 25 | ||
26 | DECLARE_PER_CPU(void*, bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]); | 26 | DECLARE_PER_CPU(struct bpf_cgroup_storage*, |
27 | bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]); | ||
27 | 28 | ||
28 | #define for_each_cgroup_storage_type(stype) \ | 29 | #define for_each_cgroup_storage_type(stype) \ |
29 | for (stype = 0; stype < MAX_BPF_CGROUP_STORAGE_TYPE; stype++) | 30 | for (stype = 0; stype < MAX_BPF_CGROUP_STORAGE_TYPE; stype++) |
@@ -115,15 +116,9 @@ static inline void bpf_cgroup_storage_set(struct bpf_cgroup_storage | |||
115 | *storage[MAX_BPF_CGROUP_STORAGE_TYPE]) | 116 | *storage[MAX_BPF_CGROUP_STORAGE_TYPE]) |
116 | { | 117 | { |
117 | enum bpf_cgroup_storage_type stype; | 118 | enum bpf_cgroup_storage_type stype; |
118 | struct bpf_storage_buffer *buf; | ||
119 | |||
120 | for_each_cgroup_storage_type(stype) { | ||
121 | if (!storage[stype]) | ||
122 | continue; | ||
123 | 119 | ||
124 | buf = READ_ONCE(storage[stype]->buf); | 120 | for_each_cgroup_storage_type(stype) |
125 | this_cpu_write(bpf_cgroup_storage[stype], &buf->data[0]); | 121 | this_cpu_write(bpf_cgroup_storage[stype], storage[stype]); |
126 | } | ||
127 | } | 122 | } |
128 | 123 | ||
129 | struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog, | 124 | struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog, |
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index 9070b2ace6aa..e42f8789b7ea 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c | |||
@@ -195,7 +195,8 @@ const struct bpf_func_proto bpf_get_current_cgroup_id_proto = { | |||
195 | }; | 195 | }; |
196 | 196 | ||
197 | #ifdef CONFIG_CGROUP_BPF | 197 | #ifdef CONFIG_CGROUP_BPF |
198 | DECLARE_PER_CPU(void*, bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]); | 198 | DECLARE_PER_CPU(struct bpf_cgroup_storage*, |
199 | bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]); | ||
199 | 200 | ||
200 | BPF_CALL_2(bpf_get_local_storage, struct bpf_map *, map, u64, flags) | 201 | BPF_CALL_2(bpf_get_local_storage, struct bpf_map *, map, u64, flags) |
201 | { | 202 | { |
@@ -204,8 +205,11 @@ BPF_CALL_2(bpf_get_local_storage, struct bpf_map *, map, u64, flags) | |||
204 | * verifier checks that its value is correct. | 205 | * verifier checks that its value is correct. |
205 | */ | 206 | */ |
206 | enum bpf_cgroup_storage_type stype = cgroup_storage_type(map); | 207 | enum bpf_cgroup_storage_type stype = cgroup_storage_type(map); |
208 | struct bpf_cgroup_storage *storage; | ||
207 | 209 | ||
208 | return (unsigned long) this_cpu_read(bpf_cgroup_storage[stype]); | 210 | storage = this_cpu_read(bpf_cgroup_storage[stype]); |
211 | |||
212 | return (unsigned long)&READ_ONCE(storage->buf)->data[0]; | ||
209 | } | 213 | } |
210 | 214 | ||
211 | const struct bpf_func_proto bpf_get_local_storage_proto = { | 215 | const struct bpf_func_proto bpf_get_local_storage_proto = { |
diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c index 0bd9f19fc557..6742292fb39e 100644 --- a/kernel/bpf/local_storage.c +++ b/kernel/bpf/local_storage.c | |||
@@ -7,7 +7,8 @@ | |||
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[MAX_BPF_CGROUP_STORAGE_TYPE]); | 10 | DEFINE_PER_CPU(struct bpf_cgroup_storage*, |
11 | bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]); | ||
11 | 12 | ||
12 | #ifdef CONFIG_CGROUP_BPF | 13 | #ifdef CONFIG_CGROUP_BPF |
13 | 14 | ||