]>
Commit | Line | Data |
---|---|---|
b8704eb5 GKH |
1 | From c6110222c6f49ea68169f353565eb865488a8619 Mon Sep 17 00:00:00 2001 |
2 | From: Daniel Borkmann <daniel@iogearbox.net> | |
3 | Date: Tue, 14 May 2019 01:18:55 +0200 | |
4 | Subject: bpf: add map_lookup_elem_sys_only for lookups from syscall side | |
5 | ||
6 | From: Daniel Borkmann <daniel@iogearbox.net> | |
7 | ||
8 | commit c6110222c6f49ea68169f353565eb865488a8619 upstream. | |
9 | ||
10 | Add a callback map_lookup_elem_sys_only() that map implementations | |
11 | could use over map_lookup_elem() from system call side in case the | |
12 | map implementation needs to handle the latter differently than from | |
13 | the BPF data path. If map_lookup_elem_sys_only() is set, this will | |
14 | be preferred pick for map lookups out of user space. This hook is | |
15 | used in a follow-up fix for LRU map, but once development window | |
16 | opens, we can convert other map types from map_lookup_elem() (here, | |
17 | the one called upon BPF_MAP_LOOKUP_ELEM cmd is meant) over to use | |
18 | the callback to simplify and clean up the latter. | |
19 | ||
20 | Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> | |
21 | Acked-by: Martin KaFai Lau <kafai@fb.com> | |
22 | Signed-off-by: Alexei Starovoitov <ast@kernel.org> | |
23 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
24 | ||
25 | --- | |
26 | include/linux/bpf.h | 1 + | |
27 | kernel/bpf/syscall.c | 5 ++++- | |
28 | 2 files changed, 5 insertions(+), 1 deletion(-) | |
29 | ||
30 | --- a/include/linux/bpf.h | |
31 | +++ b/include/linux/bpf.h | |
32 | @@ -35,6 +35,7 @@ struct bpf_map_ops { | |
33 | void (*map_free)(struct bpf_map *map); | |
34 | int (*map_get_next_key)(struct bpf_map *map, void *key, void *next_key); | |
35 | void (*map_release_uref)(struct bpf_map *map); | |
36 | + void *(*map_lookup_elem_sys_only)(struct bpf_map *map, void *key); | |
37 | ||
38 | /* funcs callable from userspace and from eBPF programs */ | |
39 | void *(*map_lookup_elem)(struct bpf_map *map, void *key); | |
40 | --- a/kernel/bpf/syscall.c | |
41 | +++ b/kernel/bpf/syscall.c | |
42 | @@ -738,7 +738,10 @@ static int map_lookup_elem(union bpf_att | |
43 | err = map->ops->map_peek_elem(map, value); | |
44 | } else { | |
45 | rcu_read_lock(); | |
46 | - ptr = map->ops->map_lookup_elem(map, key); | |
47 | + if (map->ops->map_lookup_elem_sys_only) | |
48 | + ptr = map->ops->map_lookup_elem_sys_only(map, key); | |
49 | + else | |
50 | + ptr = map->ops->map_lookup_elem(map, key); | |
51 | if (IS_ERR(ptr)) { | |
52 | err = PTR_ERR(ptr); | |
53 | } else if (!ptr) { |