History

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.

Lorenz Bauer committed 6 years ago

Commit 1a2e2011 parent 7b709732 files · +17 −19Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/skmsg.h+16−4
@@ -347,11 +347,23 @@ static inline void sk_psock_update_proto(struct sock *sk, · 346 unmodified lines
347347 struct sk_psock *psock,
348348 struct proto *ops)
349349 {
350− psock->saved_unhash = sk->sk_prot->unhash;
351− psock->saved_close = sk->sk_prot->close;
352− psock->saved_write_space = sk->sk_write_space;
350+ /* Initialize saved callbacks and original proto only once, since this
351+ * function may be called multiple times for a psock, e.g. when
352+ * psock->progs.msg_parser is updated.
353+ *
354+ * Since we've not installed the new proto, psock is not yet in use and
355+ * we can initialize it without synchronization.
356+ */
357+ if (!psock->sk_proto) {
358+ struct proto *orig = READ_ONCE(sk->sk_prot);
359+
360+ psock->saved_unhash = orig->unhash;
361+ psock->saved_close = orig->close;
362+ psock->saved_write_space = sk->sk_write_space;
363+
364+ psock->sk_proto = orig;
365+ }
353366
354− psock->sk_proto = sk->sk_prot;
355367 /* Pairs with lockless read in sk_clone_lock() */
356368 WRITE_ONCE(sk->sk_prot, ops);
357369 }