summaryrefslogtreecommitdiffstats
path: root/kernel/bpf/syscall.c
diff options
context:
space:
mode:
authorStanislav Fomichev <sdf@google.com>2019-08-14 13:37:48 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2019-08-17 17:18:54 -0400
commitb0e4701ce15d0381cdea0643c7f0a35dc529cec2 (patch)
tree35f71eca49d4baa3ce31be4c830db41f60f2cb32 /kernel/bpf/syscall.c
parentfae55527ac1164b66bee983a4d82ade2bfedb332 (diff)
bpf: export bpf_map_inc_not_zero
Rename existing bpf_map_inc_not_zero to __bpf_map_inc_not_zero to indicate that it's caller's responsibility to do proper locking. Create and export bpf_map_inc_not_zero wrapper that properly locks map_idr_lock. Will be used in the next commit to hold a map while cloning a socket. Cc: Martin KaFai Lau <kafai@fb.com> Cc: Yonghong Song <yhs@fb.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Acked-by: Yonghong Song <yhs@fb.com> Signed-off-by: Stanislav Fomichev <sdf@google.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r--kernel/bpf/syscall.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 5d141f16f6fa..cf8052b016e7 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -683,8 +683,8 @@ struct bpf_map *bpf_map_get_with_uref(u32 ufd)
683} 683}
684 684
685/* map_idr_lock should have been held */ 685/* map_idr_lock should have been held */
686static struct bpf_map *bpf_map_inc_not_zero(struct bpf_map *map, 686static struct bpf_map *__bpf_map_inc_not_zero(struct bpf_map *map,
687 bool uref) 687 bool uref)
688{ 688{
689 int refold; 689 int refold;
690 690
@@ -704,6 +704,16 @@ static struct bpf_map *bpf_map_inc_not_zero(struct bpf_map *map,
704 return map; 704 return map;
705} 705}
706 706
707struct bpf_map *bpf_map_inc_not_zero(struct bpf_map *map, bool uref)
708{
709 spin_lock_bh(&map_idr_lock);
710 map = __bpf_map_inc_not_zero(map, uref);
711 spin_unlock_bh(&map_idr_lock);
712
713 return map;
714}
715EXPORT_SYMBOL_GPL(bpf_map_inc_not_zero);
716
707int __weak bpf_stackmap_copy(struct bpf_map *map, void *key, void *value) 717int __weak bpf_stackmap_copy(struct bpf_map *map, void *key, void *value)
708{ 718{
709 return -ENOTSUPP; 719 return -ENOTSUPP;
@@ -2177,7 +2187,7 @@ static int bpf_map_get_fd_by_id(const union bpf_attr *attr)
2177 spin_lock_bh(&map_idr_lock); 2187 spin_lock_bh(&map_idr_lock);
2178 map = idr_find(&map_idr, id); 2188 map = idr_find(&map_idr, id);
2179 if (map) 2189 if (map)
2180 map = bpf_map_inc_not_zero(map, true); 2190 map = __bpf_map_inc_not_zero(map, true);
2181 else 2191 else
2182 map = ERR_PTR(-ENOENT); 2192 map = ERR_PTR(-ENOENT);
2183 spin_unlock_bh(&map_idr_lock); 2193 spin_unlock_bh(&map_idr_lock);