UPSTREAM: skmsg: Update saved hooks only once

Only update psock->saved_* if psock->sk_proto has not been initialized
yet. This allows us to get rid of tcp_bpf_reinit_sk_prot.

Change-Id: Idda8683c7abf3106adeca0cde9c94161f78c4a79
Signed-off-by: Lorenz Bauer <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Reviewed-by: Jakub Sitnicki <[email protected]>
Acked-by: John Fastabend <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
This commit is contained in:
Lorenz Bauer 2020-03-09 11:12:33 +00:00 • committed by basamaryan
commit 6aa78c8885
No known key found for this signature in database
GPG key ID: 210D5384FB2A5885
2 changed files with 17 additions and 19 deletions

View file

@ -666,20 +666,6 @@ static void tcp_bpf_update_sk_prot(struct sock *sk, struct sk_psock *psock)
sk_psock_update_proto(sk, psock, &tcp_bpf_prots[family][config]);
}
static void tcp_bpf_reinit_sk_prot(struct sock *sk, struct sk_psock *psock)
{
int family = sk->sk_family == AF_INET6 ? TCP_BPF_IPV6 : TCP_BPF_IPV4;
int config = psock->progs.msg_parser ? TCP_BPF_TX : TCP_BPF_BASE;
/* Reinit occurs when program types change e.g. TCP_BPF_TX is removed
* or added requiring sk_prot hook updates. We keep original saved
* hooks in this case.
*
* Pairs with lockless read in sk_clone_lock().
*/
WRITE_ONCE(sk->sk_prot, &tcp_bpf_prots[family][config]);
}
static int tcp_bpf_assert_proto_ops(struct proto *ops)
{
/* In order to avoid retpoline, we make assumptions when we call
@ -699,7 +685,7 @@ void tcp_bpf_reinit(struct sock *sk)
rcu_read_lock();
psock = sk_psock(sk);
tcp_bpf_reinit_sk_prot(sk, psock);
tcp_bpf_update_sk_prot(sk, psock);
rcu_read_unlock();
}