From patchwork Wed Feb 10 16:50:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Craig Gallek X-Patchwork-Id: 581494 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id A76B714031D for ; Thu, 11 Feb 2016 03:51:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753125AbcBJQvD (ORCPT ); Wed, 10 Feb 2016 11:51:03 -0500 Received: from mail-qk0-f178.google.com ([209.85.220.178]:33113 "EHLO mail-qk0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752701AbcBJQuz (ORCPT ); Wed, 10 Feb 2016 11:50:55 -0500 Received: by mail-qk0-f178.google.com with SMTP id s5so9021824qkd.0 for ; Wed, 10 Feb 2016 08:50:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=IYE808NjpwiHm7RzW3u9fzHXfbBSrRhfnVUWntg8dAQ=; b=CYSKiGqGNCuOCUGJReWZDed+IPLomyJTZtw10f2MEEBU6h4Xyno7ec8vjoCTUkyLuy 4Z3wsv8e+GoYHs6xGEJuCyod90mRBnboamW0hvbiiOT43r9sjS/+xNYiq3JEaiPlih8P q6zzVxI39uXCeFN1n7NgOp06rCOWaKQN0Mdn3ydcuoU59HMfwZRL8YSBvcqXXDE3Av70 t1lvAbv+9zlrVbtOMam9znkIX/MLP3gkS9aPj9bTSmOPqFGNcmNiKC3X8q+3qyxxo6hy mgc38YKdn49wvqLT9Aqb8wtO7i2PgV7LoTEziQQ4Lf7cw8j+DbFluW74ngvMtB2kVaaB a12Q== X-Gm-Message-State: AG10YOQuGB119VW1BApkfNeZtjU47av3YPdXsPm5lU9afp1bwk1Golklim/V9nl02863CXB/ X-Received: by 10.55.82.70 with SMTP id g67mr34949220qkb.57.1455123054179; Wed, 10 Feb 2016 08:50:54 -0800 (PST) Received: from cgallek-warp18.nyc.corp.google.com ([172.29.18.56]) by smtp.gmail.com with ESMTPSA id 2sm358088qgi.33.2016.02.10.08.50.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Feb 2016 08:50:52 -0800 (PST) From: Craig Gallek To: netdev@vger.kernel.org, David Miller Subject: [PATCH net-next v4 5/7] soreuseport: Prep for fast reuseport TCP socket selection Date: Wed, 10 Feb 2016 11:50:39 -0500 Message-Id: <1455123041-22638-6-git-send-email-kraigatgoog@gmail.com> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: <1455123041-22638-1-git-send-email-kraigatgoog@gmail.com> References: <1455123041-22638-1-git-send-email-kraigatgoog@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Craig Gallek 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 --- 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;