All of lore.kernel.org
 help / color / mirror / Atom feed
From: Craig Gallek <kraigatgoog@gmail.com>
To: netdev@vger.kernel.org, David Miller <davem@davemloft.net>
Subject: [PATCH net-next 5/7] soreuseport: Prep for fast reuseport TCP socket selection
Date: Thu,  4 Feb 2016 10:35:16 -0500	[thread overview]
Message-ID: <1454600118-30152-6-git-send-email-kraigatgoog@gmail.com> (raw)
In-Reply-To: <1454600118-30152-1-git-send-email-kraigatgoog@gmail.com>

From: Craig Gallek <kraig@google.com>

Both of the lines in this patch probably should have been included
in the initial implementation of this code for generic socket
support, but weren't technically necessary since only UDP sockets
were supported.

First, the sk_reuseport_cb points to a structure which assumes
each socket in the group has this pointer assigned at the same
time it's added to the array in the structure.  The sk_clone_lock
function breaks this assumption.  Since a child socket shouldn't
implicitly be in a reuseport group, the simple fix is to clear
the field in the clone.

Second, the SO_ATTACH_REUSEPORT_xBPF socket options require that
SO_REUSEPORT also be set first.  For UDP sockets, this is easily
enforced at bind-time since that process both puts the socket in
the appropriate receive hlist and updates the reuseport structures.
Since these operations can happen at two different times for TCP
sockets (bind and listen) it must be explicitly checked to enforce
the use of SO_REUSEPORT with SO_ATTACH_REUSEPORT_xBPF in the
setsockopt call.

Signed-off-by: Craig Gallek <kraig@google.com>
---
 net/core/filter.c | 2 +-
 net/core/sock.c   | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/core/filter.c b/net/core/filter.c
index 94d26201080d..2a6e9562f1ab 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -1181,7 +1181,7 @@ static int __reuseport_attach_prog(struct bpf_prog *prog, struct sock *sk)
 	if (bpf_prog_size(prog->len) > sysctl_optmem_max)
 		return -ENOMEM;
 
-	if (sk_unhashed(sk)) {
+	if (sk_unhashed(sk) && sk->sk_reuseport) {
 		err = reuseport_alloc(sk);
 		if (err)
 			return err;
diff --git a/net/core/sock.c b/net/core/sock.c
index 6c1c8bc93412..46dc8ad7d050 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1531,6 +1531,7 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
 			newsk = NULL;
 			goto out;
 		}
+		RCU_INIT_POINTER(newsk->sk_reuseport_cb, NULL);
 
 		newsk->sk_err	   = 0;
 		newsk->sk_priority = 0;
-- 
2.7.0.rc3.207.g0ac5344

  parent reply	other threads:[~2016-02-04 15:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-04 15:35 [PATCH net-next 0/7] Faster SO_REUSEPORT for TCP Craig Gallek
2016-02-04 15:35 ` [PATCH net-next 1/7] sock: struct proto hash function may error Craig Gallek
2016-02-05  5:34   ` Eric Dumazet
2016-02-09 23:44   ` Craig Gallek
2016-02-04 15:35 ` [PATCH net-next 2/7] inet: create IPv6-equivalent inet_hash function Craig Gallek
2016-02-05  5:34   ` Eric Dumazet
2016-02-04 15:35 ` [PATCH net-next 3/7] tcp: __tcp_hdrlen() helper Craig Gallek
2016-02-05  5:35   ` Eric Dumazet
2016-02-04 15:35 ` [PATCH net-next 4/7] inet: refactor inet[6]_lookup functions to take skb Craig Gallek
2016-02-05  5:36   ` Eric Dumazet
2016-02-04 15:35 ` Craig Gallek [this message]
2016-02-05  5:37   ` [PATCH net-next 5/7] soreuseport: Prep for fast reuseport TCP socket selection Eric Dumazet
2016-02-04 15:35 ` [PATCH net-next 6/7] soreuseport: " Craig Gallek
2016-02-05  5:38   ` Eric Dumazet
2016-02-04 15:35 ` [PATCH net-next 7/7] soreuseport: BPF selection functional test for TCP Craig Gallek
2016-02-05  5:40   ` Eric Dumazet
2016-02-06  2:59   ` Alexei Starovoitov
2016-02-09 23:39 [PATCH net-next 0/7] Faster SO_REUSEPORT " Craig Gallek
2016-02-09 23:39 ` [PATCH net-next 5/7] soreuseport: Prep for fast reuseport TCP socket selection Craig Gallek

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=1454600118-30152-6-git-send-email-kraigatgoog@gmail.com \
    --to=kraigatgoog@gmail.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.