From: Lorenz Bauer <lmb@cloudflare.com>
To: john.fastabend@gmail.com, Daniel Borkmann <daniel@iogearbox.net>,
Jakub Sitnicki <jakub@cloudflare.com>,
Lorenz Bauer <lmb@cloudflare.com>,
Eric Dumazet <edumazet@google.com>,
"David S. Miller" <davem@davemloft.net>,
Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>,
Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
Jakub Kicinski <kuba@kernel.org>,
Alexei Starovoitov <ast@kernel.org>
Cc: kernel-team@cloudflare.com, netdev@vger.kernel.org,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH bpf-next v3 02/12] skmsg: update saved hooks only once
Date: Wed, 4 Mar 2020 11:13:07 +0100 [thread overview]
Message-ID: <20200304101318.5225-3-lmb@cloudflare.com> (raw)
In-Reply-To: <20200304101318.5225-1-lmb@cloudflare.com>
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.
Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
---
include/linux/skmsg.h | 20 ++++++++++++++++----
net/ipv4/tcp_bpf.c | 16 +---------------
2 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/include/linux/skmsg.h b/include/linux/skmsg.h
index 4d3d75d63066..2be51b7a5800 100644
--- a/include/linux/skmsg.h
+++ b/include/linux/skmsg.h
@@ -347,11 +347,23 @@ static inline void sk_psock_update_proto(struct sock *sk,
struct sk_psock *psock,
struct proto *ops)
{
- psock->saved_unhash = sk->sk_prot->unhash;
- psock->saved_close = sk->sk_prot->close;
- psock->saved_write_space = sk->sk_write_space;
+ /* Initialize saved callbacks and original proto only once, since this
+ * function may be called multiple times for a psock, e.g. when
+ * psock->progs.msg_parser is updated.
+ *
+ * Since we've not installed the new proto, psock is not yet in use and
+ * we can initialize it without synchronization.
+ */
+ if (!psock->sk_proto) {
+ struct proto *orig = READ_ONCE(sk->sk_prot);
+
+ psock->saved_unhash = orig->unhash;
+ psock->saved_close = orig->close;
+ psock->saved_write_space = sk->sk_write_space;
+
+ psock->sk_proto = orig;
+ }
- psock->sk_proto = sk->sk_prot;
/* Pairs with lockless read in sk_clone_lock() */
WRITE_ONCE(sk->sk_prot, ops);
}
diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
index 7d6e1b75d4d4..3327afa05c3d 100644
--- a/net/ipv4/tcp_bpf.c
+++ b/net/ipv4/tcp_bpf.c
@@ -637,20 +637,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
@@ -670,7 +656,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();
}
--
2.20.1
next prev parent reply other threads:[~2020-03-04 10:14 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-04 10:13 [PATCH bpf-next v3 00/12] bpf: sockmap, sockhash: support storing UDP sockets Lorenz Bauer
2020-03-04 10:13 ` [PATCH bpf-next v3 01/12] bpf: sockmap: only check ULP for TCP sockets Lorenz Bauer
2020-03-05 12:00 ` Jakub Sitnicki
2020-03-06 14:56 ` John Fastabend
2020-03-04 10:13 ` Lorenz Bauer [this message]
2020-03-05 12:03 ` [PATCH bpf-next v3 02/12] skmsg: update saved hooks only once Jakub Sitnicki
2020-03-06 15:00 ` John Fastabend
2020-03-04 10:13 ` [PATCH bpf-next v3 03/12] bpf: tcp: move assertions into tcp_bpf_get_proto Lorenz Bauer
2020-03-05 12:10 ` Jakub Sitnicki
2020-03-06 15:25 ` John Fastabend
2020-03-04 10:13 ` [PATCH bpf-next v3 04/12] bpf: tcp: guard declarations with CONFIG_NET_SOCK_MSG Lorenz Bauer
2020-03-05 12:14 ` Jakub Sitnicki
2020-03-04 10:13 ` [PATCH bpf-next v3 05/12] bpf: sockmap: move generic sockmap hooks from BPF TCP Lorenz Bauer
2020-03-05 12:32 ` Jakub Sitnicki
2020-03-06 15:28 ` John Fastabend
2020-03-04 10:13 ` [PATCH bpf-next v3 06/12] bpf: sockmap: simplify sock_map_init_proto Lorenz Bauer
2020-03-05 12:39 ` Jakub Sitnicki
2020-03-06 15:29 ` John Fastabend
2020-03-04 10:13 ` [PATCH bpf-next v3 07/12] bpf: add sockmap hooks for UDP sockets Lorenz Bauer
2020-03-06 15:44 ` John Fastabend
2020-03-04 10:13 ` [PATCH bpf-next v3 08/12] bpf: sockmap: add UDP support Lorenz Bauer
2020-03-06 15:31 ` John Fastabend
2020-03-04 10:13 ` [PATCH bpf-next v3 09/12] selftests: bpf: don't listen() on UDP sockets Lorenz Bauer
2020-03-05 12:53 ` Jakub Sitnicki
2020-03-06 15:36 ` John Fastabend
2020-03-04 10:13 ` [PATCH bpf-next v3 10/12] selftests: bpf: add tests for UDP sockets in sockmap Lorenz Bauer
2020-03-06 15:38 ` John Fastabend
2020-03-04 10:13 ` [PATCH bpf-next v3 11/12] selftests: bpf: enable UDP sockmap reuseport tests Lorenz Bauer
2020-03-05 12:56 ` Jakub Sitnicki
2020-03-06 15:39 ` John Fastabend
2020-03-04 10:13 ` [PATCH bpf-next v3 12/12] bpf, doc: update maintainers for L7 BPF Lorenz Bauer
2020-03-05 12:58 ` Jakub Sitnicki
2020-03-05 12:59 ` [PATCH bpf-next v3 00/12] bpf: sockmap, sockhash: support storing UDP sockets Jakub Sitnicki
2020-03-06 15:45 ` John Fastabend
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200304101318.5225-3-lmb@cloudflare.com \
--to=lmb@cloudflare.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jakub@cloudflare.com \
--cc=john.fastabend@gmail.com \
--cc=kernel-team@cloudflare.com \
--cc=kuba@kernel.org \
--cc=kuznet@ms2.inr.ac.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=yoshfuji@linux-ipv6.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).