diff options
author | Martin KaFai Lau <martin.lau@kernel.org> | 2022-09-02 03:28:09 +0300 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2022-09-03 06:34:30 +0300 |
commit | 2c5b6bf5cda048af896bb0e12a956783f7d6c835 (patch) | |
tree | 05af9be23331d2fa012f52fb52be75c7a639cde2 /net/core | |
parent | 4ff09db1b79b98b4a2a7511571c640b76cab3beb (diff) | |
download | linux-2c5b6bf5cda048af896bb0e12a956783f7d6c835.tar.xz |
bpf: net: Avoid sk_getsockopt() taking sk lock when called from bpf
Similar to the earlier commit that changed sk_setsockopt() to
use sockopt_{lock,release}_sock() such that it can avoid taking
lock when called from bpf. This patch also changes sk_getsockopt()
to use sockopt_{lock,release}_sock() such that a latter patch can
make bpf_getsockopt(SOL_SOCKET) to reuse sk_getsockopt().
Only sk_get_filter() requires this change and it is used by
the optname SO_GET_FILTER.
The '.getname' implementations in sock->ops->getname() is not
changed also since bpf does not always have the sk->sk_socket
pointer and cannot support SO_PEERNAME.
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20220902002809.2888981-1-kafai@fb.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/filter.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/net/core/filter.c b/net/core/filter.c index 962014f7f64b..f57f78feb380 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -10722,7 +10722,7 @@ int sk_get_filter(struct sock *sk, sockptr_t optval, unsigned int len) struct sk_filter *filter; int ret = 0; - lock_sock(sk); + sockopt_lock_sock(sk); filter = rcu_dereference_protected(sk->sk_filter, lockdep_sock_is_held(sk)); if (!filter) @@ -10755,7 +10755,7 @@ int sk_get_filter(struct sock *sk, sockptr_t optval, unsigned int len) */ ret = fprog->len; out: - release_sock(sk); + sockopt_release_sock(sk); return ret; } |