diff options
author | Daniel Borkmann <daniel@iogearbox.net> | 2019-05-13 19:18:55 -0400 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2019-05-14 13:47:29 -0400 |
commit | c6110222c6f49ea68169f353565eb865488a8619 (patch) | |
tree | 181de3f33b1e298789b1827b0103d6304f532a86 /kernel/bpf | |
parent | 2474c62898c63f8bb122ffda2cd93fdaad55603a (diff) |
bpf: add map_lookup_elem_sys_only for lookups from syscall side
Add a callback map_lookup_elem_sys_only() that map implementations
could use over map_lookup_elem() from system call side in case the
map implementation needs to handle the latter differently than from
the BPF data path. If map_lookup_elem_sys_only() is set, this will
be preferred pick for map lookups out of user space. This hook is
used in a follow-up fix for LRU map, but once development window
opens, we can convert other map types from map_lookup_elem() (here,
the one called upon BPF_MAP_LOOKUP_ELEM cmd is meant) over to use
the callback to simplify and clean up the latter.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel/bpf')
-rw-r--r-- | kernel/bpf/syscall.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index ad3ccf82f31d..cb5440b02e82 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c | |||
@@ -808,7 +808,10 @@ static int map_lookup_elem(union bpf_attr *attr) | |||
808 | err = map->ops->map_peek_elem(map, value); | 808 | err = map->ops->map_peek_elem(map, value); |
809 | } else { | 809 | } else { |
810 | rcu_read_lock(); | 810 | rcu_read_lock(); |
811 | ptr = map->ops->map_lookup_elem(map, key); | 811 | if (map->ops->map_lookup_elem_sys_only) |
812 | ptr = map->ops->map_lookup_elem_sys_only(map, key); | ||
813 | else | ||
814 | ptr = map->ops->map_lookup_elem(map, key); | ||
812 | if (IS_ERR(ptr)) { | 815 | if (IS_ERR(ptr)) { |
813 | err = PTR_ERR(ptr); | 816 | err = PTR_ERR(ptr); |
814 | } else if (!ptr) { | 817 | } else if (!ptr) { |