]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/5.0.19/bpf-add-map_lookup_elem_sys_only-for-lookups-from-syscall-side.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 5.0.19 / bpf-add-map_lookup_elem_sys_only-for-lookups-from-syscall-side.patch
CommitLineData
b8704eb5
GKH
1From c6110222c6f49ea68169f353565eb865488a8619 Mon Sep 17 00:00:00 2001
2From: Daniel Borkmann <daniel@iogearbox.net>
3Date: Tue, 14 May 2019 01:18:55 +0200
4Subject: bpf: add map_lookup_elem_sys_only for lookups from syscall side
5
6From: Daniel Borkmann <daniel@iogearbox.net>
7
8commit c6110222c6f49ea68169f353565eb865488a8619 upstream.
9
10Add a callback map_lookup_elem_sys_only() that map implementations
11could use over map_lookup_elem() from system call side in case the
12map implementation needs to handle the latter differently than from
13the BPF data path. If map_lookup_elem_sys_only() is set, this will
14be preferred pick for map lookups out of user space. This hook is
15used in a follow-up fix for LRU map, but once development window
16opens, we can convert other map types from map_lookup_elem() (here,
17the one called upon BPF_MAP_LOOKUP_ELEM cmd is meant) over to use
18the callback to simplify and clean up the latter.
19
20Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
21Acked-by: Martin KaFai Lau <kafai@fb.com>
22Signed-off-by: Alexei Starovoitov <ast@kernel.org>
23Signed-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) {