diff options
Diffstat (limited to 'kernel/bpf/arraymap.c')
-rw-r--r-- | kernel/bpf/arraymap.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index c72e0d8e1e65..1a6e9861d554 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c | |||
@@ -160,6 +160,36 @@ static void *array_map_lookup_elem(struct bpf_map *map, void *key) | |||
160 | return array->value + array->elem_size * (index & array->index_mask); | 160 | return array->value + array->elem_size * (index & array->index_mask); |
161 | } | 161 | } |
162 | 162 | ||
163 | static int array_map_direct_value_addr(const struct bpf_map *map, u64 *imm, | ||
164 | u32 off) | ||
165 | { | ||
166 | struct bpf_array *array = container_of(map, struct bpf_array, map); | ||
167 | |||
168 | if (map->max_entries != 1) | ||
169 | return -ENOTSUPP; | ||
170 | if (off >= map->value_size) | ||
171 | return -EINVAL; | ||
172 | |||
173 | *imm = (unsigned long)array->value; | ||
174 | return 0; | ||
175 | } | ||
176 | |||
177 | static int array_map_direct_value_meta(const struct bpf_map *map, u64 imm, | ||
178 | u32 *off) | ||
179 | { | ||
180 | struct bpf_array *array = container_of(map, struct bpf_array, map); | ||
181 | u64 base = (unsigned long)array->value; | ||
182 | u64 range = array->elem_size; | ||
183 | |||
184 | if (map->max_entries != 1) | ||
185 | return -ENOTSUPP; | ||
186 | if (imm < base || imm >= base + range) | ||
187 | return -ENOENT; | ||
188 | |||
189 | *off = imm - base; | ||
190 | return 0; | ||
191 | } | ||
192 | |||
163 | /* emit BPF instructions equivalent to C code of array_map_lookup_elem() */ | 193 | /* emit BPF instructions equivalent to C code of array_map_lookup_elem() */ |
164 | static u32 array_map_gen_lookup(struct bpf_map *map, struct bpf_insn *insn_buf) | 194 | static u32 array_map_gen_lookup(struct bpf_map *map, struct bpf_insn *insn_buf) |
165 | { | 195 | { |
@@ -419,6 +449,8 @@ const struct bpf_map_ops array_map_ops = { | |||
419 | .map_update_elem = array_map_update_elem, | 449 | .map_update_elem = array_map_update_elem, |
420 | .map_delete_elem = array_map_delete_elem, | 450 | .map_delete_elem = array_map_delete_elem, |
421 | .map_gen_lookup = array_map_gen_lookup, | 451 | .map_gen_lookup = array_map_gen_lookup, |
452 | .map_direct_value_addr = array_map_direct_value_addr, | ||
453 | .map_direct_value_meta = array_map_direct_value_meta, | ||
422 | .map_seq_show_elem = array_map_seq_show_elem, | 454 | .map_seq_show_elem = array_map_seq_show_elem, |
423 | .map_check_btf = array_map_check_btf, | 455 | .map_check_btf = array_map_check_btf, |
424 | }; | 456 | }; |