From patchwork Thu Sep 10 14:04:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neal Cardwell X-Patchwork-Id: 1361607 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=ZA30eiw2; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BnLM85DJjz9sR4 for ; Fri, 11 Sep 2020 00:08:04 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731066AbgIJOHs (ORCPT ); Thu, 10 Sep 2020 10:07:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728971AbgIJOEq (ORCPT ); Thu, 10 Sep 2020 10:04:46 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EABD9C061345 for ; Thu, 10 Sep 2020 07:04:42 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id o14so4253325qtq.0 for ; Thu, 10 Sep 2020 07:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=wZb+bYOBCFyLXSATRBr9zjdlrGh9pUT/rzRHEgOsJSQ=; b=ZA30eiw2EqodgjOkBTLdZpJZcv8nDCXfV/j35v6bFXfhwKpVt/eOLgdRg50bB8owQP bP7mXWsdrXng1cOi4gOAYiKVYqWw4aDeYA7GqCQ9pGRt2U79slTkm/9oPpdHOHJetV7x W3Ko40S9v5oHvTWqMRUTQN3ubB9uupPowEhs8+8zb0XpRaW4ED19PbdlMH7Jf5gf8B9W zFuJYR1RoDo7yXVtFNVr/NmwyHmY5xOQStgMYD5gi1ZK1KlXaLM45yoamA8hL4X91Qin fy0gb4HabaA27lRux/YOVj1dOkM8pg0fh6heuo4INUhhggz1ptr0DXAfDXloBYB7M/rw PBtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=wZb+bYOBCFyLXSATRBr9zjdlrGh9pUT/rzRHEgOsJSQ=; b=eHxCgkuVL7GIfwdj6R7c/8nq4dBLoz0W65U8v0p+Pe4G7AliLBNn84yameqEtnTgkF vsgKDTCRR9UlZfFxaspPeD4aRZqH3Gdllq+L0XB1UxYUE6NLxK/k/LYi9EoTBa4Do9d6 1HWbzPRFEy2bFeSSTikyAvVEJzIvYcm0R0+ws4smD4/LQtxaug7z8AhwKxtCiQzLRwkn zU6gyGKLDTRp7Tad8MvhbvkIWRado2r7mHyECpvpicwpeZ28IYy47BzR08RxBssNpzkx e1ut7BF6sesIJ5v7a8Y+sgyS08l8QZ60zMeCK+j/655muTGBQ8k5YTfFYdAqBswEpTMa mDrQ== X-Gm-Message-State: AOAM5321V/FneKQmN5LewzkMyJfO0CDVWVesPIEOJYG6DUqbvCKHaybZ 6wIIsyoLJCLEIqw/5fkUbtbocqxxJyVT3Ew= X-Google-Smtp-Source: ABdhPJwstIQ+ToMb2krrdnUUZuhBvvKyjAYX6JCmXbRjV+aCMnn6RfXtLPry0J2KPHbvL+WQ2Fwgxlo2juKvffE= X-Received: from soy.nyc.corp.google.com ([2620:0:1003:312:7220:84ff:fe09:3008]) (user=ncardwell job=sendgmr) by 2002:a0c:a063:: with SMTP id b90mr6224285qva.25.1599746682043; Thu, 10 Sep 2020 07:04:42 -0700 (PDT) Date: Thu, 10 Sep 2020 10:04:24 -0400 In-Reply-To: <20200910140428.751193-1-ncardwell@google.com> Message-Id: <20200910140428.751193-2-ncardwell@google.com> Mime-Version: 1.0 References: <20200910140428.751193-1-ncardwell@google.com> X-Mailer: git-send-email 2.28.0.526.ge36021eeef-goog Subject: [PATCH bpf-next v2 1/5] tcp: only init congestion control if not initialized already From: Neal Cardwell To: Alexei Starovoitov Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Eric Dumazet , Lawrence Brakmo Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Change tcp_init_transfer() to only initialize congestion control if it has not been initialized already. With this new approach, we can arrange things so that if the EBPF code sets the congestion control by calling setsockopt(TCP_CONGESTION) then tcp_init_transfer() will not re-initialize the CC module. This is an approach that has the following beneficial properties: (1) This allows CC module customizations made by the EBPF called in tcp_init_transfer() to persist, and not be wiped out by a later call to tcp_init_congestion_control() in tcp_init_transfer(). (2) Does not flip the order of EBPF and CC init, to avoid causing bugs for existing code upstream that depends on the current order. (3) Does not cause 2 initializations for for CC in the case where the EBPF called in tcp_init_transfer() wants to set the CC to a new CC algorithm. (4) Allows follow-on simplifications to the code in net/core/filter.c and net/ipv4/tcp_cong.c, which currently both have some complexity to special-case CC initialization to avoid double CC initialization if EBPF sets the CC. Signed-off-by: Neal Cardwell Acked-by: Yuchung Cheng Acked-by: Kevin Yang Signed-off-by: Eric Dumazet Cc: Lawrence Brakmo --- include/net/inet_connection_sock.h | 3 ++- net/ipv4/tcp.c | 1 + net/ipv4/tcp_cong.c | 3 ++- net/ipv4/tcp_input.c | 4 +++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h index c738abeb3265..dc763ca9413c 100644 --- a/include/net/inet_connection_sock.h +++ b/include/net/inet_connection_sock.h @@ -96,7 +96,8 @@ struct inet_connection_sock { void (*icsk_clean_acked)(struct sock *sk, u32 acked_seq); struct hlist_node icsk_listen_portaddr_node; unsigned int (*icsk_sync_mss)(struct sock *sk, u32 pmtu); - __u8 icsk_ca_state:6, + __u8 icsk_ca_state:5, + icsk_ca_initialized:1, icsk_ca_setsockopt:1, icsk_ca_dst_locked:1; __u8 icsk_retransmits; diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 57a568875539..7360d3db2b61 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2698,6 +2698,7 @@ int tcp_disconnect(struct sock *sk, int flags) if (icsk->icsk_ca_ops->release) icsk->icsk_ca_ops->release(sk); memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv)); + icsk->icsk_ca_initialized = 0; tcp_set_ca_state(sk, TCP_CA_Open); tp->is_sack_reneg = 0; tcp_clear_retrans(tp); diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c index 62878cf26d9c..d18d7a1ce4ce 100644 --- a/net/ipv4/tcp_cong.c +++ b/net/ipv4/tcp_cong.c @@ -176,7 +176,7 @@ void tcp_assign_congestion_control(struct sock *sk) void tcp_init_congestion_control(struct sock *sk) { - const struct inet_connection_sock *icsk = inet_csk(sk); + struct inet_connection_sock *icsk = inet_csk(sk); tcp_sk(sk)->prior_ssthresh = 0; if (icsk->icsk_ca_ops->init) @@ -185,6 +185,7 @@ void tcp_init_congestion_control(struct sock *sk) INET_ECN_xmit(sk); else INET_ECN_dontxmit(sk); + icsk->icsk_ca_initialized = 1; } static void tcp_reinit_congestion_control(struct sock *sk, diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 4337841faeff..0e5ac0d33fd3 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -5894,8 +5894,10 @@ void tcp_init_transfer(struct sock *sk, int bpf_op, struct sk_buff *skb) tp->snd_cwnd = tcp_init_cwnd(tp, __sk_dst_get(sk)); tp->snd_cwnd_stamp = tcp_jiffies32; + icsk->icsk_ca_initialized = 0; bpf_skops_established(sk, bpf_op, skb); - tcp_init_congestion_control(sk); + if (!icsk->icsk_ca_initialized) + tcp_init_congestion_control(sk); tcp_init_buffer_space(sk); } From patchwork Thu Sep 10 14:04:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neal Cardwell X-Patchwork-Id: 1361609 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=LRp6/ky4; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BnLQN3lDcz9sVg for ; Fri, 11 Sep 2020 00:10:52 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731091AbgIJOIs (ORCPT ); Thu, 10 Sep 2020 10:08:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731054AbgIJOEq (ORCPT ); Thu, 10 Sep 2020 10:04:46 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 687EEC061348 for ; Thu, 10 Sep 2020 07:04:44 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id 205so3663843qkd.2 for ; Thu, 10 Sep 2020 07:04:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=vizF2ErHY9g5QaQv8JTl5z8oP+vX2Em3be2Hcn5/dQc=; b=LRp6/ky4mbVOwpcB81abrxn0NSnll+XZSW+NVCkhmf23JDTDlqb0ReZzzMKoQ8anEV LVYtkluf3wQySy/nL3qv+5j6nbUKh2AcwinETW5T6mx0XhGsZUX0J6uM/LA89aMgsPyj nbHCkaq/ButfqcIBfgxEel2GtPgiszBLNGBGtatNZVBeu4n7yrgJ3gXyN5mZkPXMsZF7 SF/lcZZ7ojsiY08DM1VM9i9lNByaJwNOehK2e/UDwKC3nwhRLTqZ6KGnNl5x2oZ27XhW i24UzYIIKwJYsGz0UnYTOhRVKQzhFWZC3MR7jUtXFH1H6bS06NLMh1trQjWWxNCC4Hxt kIwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=vizF2ErHY9g5QaQv8JTl5z8oP+vX2Em3be2Hcn5/dQc=; b=GLoInRr2ZVMQ6qOcNETcjBaDxh7m32wYYPtdoxf0JQXCigzYTy/aTuyVd8O1Evxk4h vRb52RDXclyRRsgDw0fL5Y/QYvOJG9rOb8TmAe31GgVcoJzYJAtUVaoFpZ6vQ4VIXYLi K7CpxG0BXoUccmxZf/n/k0iRZbZE8J7wwNy4zK/oTa5Ml4h1kw1CcK3VZOI3LzxVF2Yh t0yVsmuGKOQfUMGyXbTvH9ArHmovUWdRGa0LubIluozr3uHs06okCZHqC1xLcc/OOKaJ KEORxMw5aXRiT6fzbz49iOLcU/C23EnOiwqOKxHLPfrjhVqmkZBgkzJKg9q8FpZOUrw5 Q29w== X-Gm-Message-State: AOAM530UCD9BU9MoNXN8fkz7mG3xjBI4vyoZxpbMgXAf6AD9YOVGQB2O NdJCe4TiaHJ+opnCZe/JaGvo//AJSe7od8g= X-Google-Smtp-Source: ABdhPJxEn1aInpaHAmEFjlmhAEXZXDzYJ9Tzc32ZglsWUKKyZJpdUc9bC64fxf2B1PxD/7dnkQPNqSC3fW3JaBA= X-Received: from soy.nyc.corp.google.com ([2620:0:1003:312:7220:84ff:fe09:3008]) (user=ncardwell job=sendgmr) by 2002:a0c:e904:: with SMTP id a4mr8610458qvo.21.1599746683572; Thu, 10 Sep 2020 07:04:43 -0700 (PDT) Date: Thu, 10 Sep 2020 10:04:25 -0400 In-Reply-To: <20200910140428.751193-1-ncardwell@google.com> Message-Id: <20200910140428.751193-3-ncardwell@google.com> Mime-Version: 1.0 References: <20200910140428.751193-1-ncardwell@google.com> X-Mailer: git-send-email 2.28.0.526.ge36021eeef-goog Subject: [PATCH bpf-next v2 2/5] tcp: simplify EBPF TCP_CONGESTION to always init CC From: Neal Cardwell To: Alexei Starovoitov Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Eric Dumazet , Lawrence Brakmo Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Now that the previous patch ensures we don't initialize the congestion control twice, when EBPF sets the congestion control algorithm at connection establishment we can simplify the code by simply initializing the congestion control module at that time. Signed-off-by: Neal Cardwell Acked-by: Yuchung Cheng Acked-by: Kevin Yang Signed-off-by: Eric Dumazet Cc: Lawrence Brakmo --- net/core/filter.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 47eef9a0be6a..067f6759a68f 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4313,8 +4313,6 @@ static const struct bpf_func_proto bpf_get_socket_uid_proto = { .arg1_type = ARG_PTR_TO_CTX, }; -#define SOCKOPT_CC_REINIT (1 << 0) - static int _bpf_setsockopt(struct sock *sk, int level, int optname, char *optval, int optlen, u32 flags) { @@ -4449,13 +4447,12 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname, sk->sk_prot->setsockopt == tcp_setsockopt) { if (optname == TCP_CONGESTION) { char name[TCP_CA_NAME_MAX]; - bool reinit = flags & SOCKOPT_CC_REINIT; strncpy(name, optval, min_t(long, optlen, TCP_CA_NAME_MAX-1)); name[TCP_CA_NAME_MAX-1] = 0; ret = tcp_set_congestion_control(sk, name, false, - reinit, true); + true, true); } else { struct inet_connection_sock *icsk = inet_csk(sk); struct tcp_sock *tp = tcp_sk(sk); @@ -4652,8 +4649,6 @@ BPF_CALL_5(bpf_sock_ops_setsockopt, struct bpf_sock_ops_kern *, bpf_sock, int, level, int, optname, char *, optval, int, optlen) { u32 flags = 0; - if (bpf_sock->op > BPF_SOCK_OPS_NEEDS_ECN) - flags |= SOCKOPT_CC_REINIT; return _bpf_setsockopt(bpf_sock->sk, level, optname, optval, optlen, flags); } From patchwork Thu Sep 10 14:04:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neal Cardwell X-Patchwork-Id: 1362027 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=QajuAUGO; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BnX5b0fJbz9sVj for ; Fri, 11 Sep 2020 07:26:59 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728165AbgIJV06 (ORCPT ); Thu, 10 Sep 2020 17:26:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731075AbgIJOXG (ORCPT ); Thu, 10 Sep 2020 10:23:06 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01BF1C061342 for ; Thu, 10 Sep 2020 07:04:48 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id q21so3340000qvf.22 for ; Thu, 10 Sep 2020 07:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=S6AuheHIRwyrJQTuUfR58Qd8kmBi7CvFbpaQ8Qcutxg=; b=QajuAUGO1z6mtgnQGYddMRp5WNEAhc/5TFjcpoB6Kfe/uJAnkiTb6SsIFmrnNX5Vdg XW+Xea4sGfl/jcPaopuRaPepnB4FyO5M3JsFqSuRVa7Pu4AsYjV52I8qoHV3uLwlk5I9 mTYcADwr/hQn+EH2KC5u/zGEQtLUVSiH5ngkwa3e4Fv9CZgHJxE5XL5okk2IgID4qa+K tgboxIenP1jBg2vfziLRQryzfs7XoRkcgidORhQOjgcCGuSIOEovCGB2+gZRMcQ8fjRY h0nd2ZLti+xQQjhdGX14I9kEkDnDqreXfI5PHcY0DTjqWsVtk4tIUocg4tneZu3CdIK2 Xxbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=S6AuheHIRwyrJQTuUfR58Qd8kmBi7CvFbpaQ8Qcutxg=; b=r0pu7h1KzIUzaQGTA8RMxugZrbGXWg8rdI/Rpe2xL10+CFKMgJQzlXQX1KagUANXqM fMy4E2NUy5WJXBNfunHgU8fVfVCWan5UbN37AAoMTAzDDsQepNwvHvYhiZhM1qjaFVlg ElSiJOY679gPA7eVNrUkuNhYdIyeRx2Bp0v1gD0So5NhQnQTVTIAOdods341EgRfdwmQ sQP2ew03EmMqMKalow5vz+FxML/a4J47KwyojHP9vv9eDfVgraJ+FDikoErYfx+b9Z2/ Fl2DfHUxkY14vde1+rB2InW9o1cMla8A+1bFlBuJ//Hm1WI5yV+qBPI8B7/hfITN3CaC gg3w== X-Gm-Message-State: AOAM533V3HGfZMlGyUjf8E7KjciANu9i/W4VGIMrhTZEIlxr2ZoiLxsV 6uPtQ6++oiyBAKn3UfNLpRY348EgTSfUKtE= X-Google-Smtp-Source: ABdhPJyvKsca7qmqMrHh776VXUO5/DVTrT6CEpS1MdyCdKTMaSfUCFblhgbEXRS/W3g43KycstUXaVAJqIQzMPE= X-Received: from soy.nyc.corp.google.com ([2620:0:1003:312:7220:84ff:fe09:3008]) (user=ncardwell job=sendgmr) by 2002:a0c:f493:: with SMTP id i19mr9160193qvm.84.1599746685002; Thu, 10 Sep 2020 07:04:45 -0700 (PDT) Date: Thu, 10 Sep 2020 10:04:26 -0400 In-Reply-To: <20200910140428.751193-1-ncardwell@google.com> Message-Id: <20200910140428.751193-4-ncardwell@google.com> Mime-Version: 1.0 References: <20200910140428.751193-1-ncardwell@google.com> X-Mailer: git-send-email 2.28.0.526.ge36021eeef-goog Subject: [PATCH bpf-next v2 3/5] tcp: simplify tcp_set_congestion_control(): always reinitialize From: Neal Cardwell To: Alexei Starovoitov Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Eric Dumazet , Lawrence Brakmo Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Now that the previous patches ensure that all call sites for tcp_set_congestion_control() want to initialize congestion control, we can simplify tcp_set_congestion_control() by removing the reinit argument and the code to support it. Signed-off-by: Neal Cardwell Acked-by: Yuchung Cheng Acked-by: Kevin Yang Signed-off-by: Eric Dumazet Cc: Lawrence Brakmo --- include/net/tcp.h | 2 +- net/core/filter.c | 3 +-- net/ipv4/tcp.c | 2 +- net/ipv4/tcp_cong.c | 11 ++--------- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index e85d564446c6..f857146c17a5 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1104,7 +1104,7 @@ void tcp_get_available_congestion_control(char *buf, size_t len); void tcp_get_allowed_congestion_control(char *buf, size_t len); int tcp_set_allowed_congestion_control(char *allowed); int tcp_set_congestion_control(struct sock *sk, const char *name, bool load, - bool reinit, bool cap_net_admin); + bool cap_net_admin); u32 tcp_slow_start(struct tcp_sock *tp, u32 acked); void tcp_cong_avoid_ai(struct tcp_sock *tp, u32 w, u32 acked); diff --git a/net/core/filter.c b/net/core/filter.c index 067f6759a68f..e89d6d7da03c 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4451,8 +4451,7 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname, strncpy(name, optval, min_t(long, optlen, TCP_CA_NAME_MAX-1)); name[TCP_CA_NAME_MAX-1] = 0; - ret = tcp_set_congestion_control(sk, name, false, - true, true); + ret = tcp_set_congestion_control(sk, name, false, true); } else { struct inet_connection_sock *icsk = inet_csk(sk); struct tcp_sock *tp = tcp_sk(sk); diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 7360d3db2b61..e58ab9db73ff 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3050,7 +3050,7 @@ static int do_tcp_setsockopt(struct sock *sk, int level, int optname, name[val] = 0; lock_sock(sk); - err = tcp_set_congestion_control(sk, name, true, true, + err = tcp_set_congestion_control(sk, name, true, ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)); release_sock(sk); diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c index d18d7a1ce4ce..a9b0fb52a1ec 100644 --- a/net/ipv4/tcp_cong.c +++ b/net/ipv4/tcp_cong.c @@ -341,7 +341,7 @@ int tcp_set_allowed_congestion_control(char *val) * already initialized. */ int tcp_set_congestion_control(struct sock *sk, const char *name, bool load, - bool reinit, bool cap_net_admin) + bool cap_net_admin) { struct inet_connection_sock *icsk = inet_csk(sk); const struct tcp_congestion_ops *ca; @@ -365,15 +365,8 @@ int tcp_set_congestion_control(struct sock *sk, const char *name, bool load, if (!ca) { err = -ENOENT; } else if (!load) { - const struct tcp_congestion_ops *old_ca = icsk->icsk_ca_ops; - if (bpf_try_module_get(ca, ca->owner)) { - if (reinit) { - tcp_reinit_congestion_control(sk, ca); - } else { - icsk->icsk_ca_ops = ca; - bpf_module_put(old_ca, old_ca->owner); - } + tcp_reinit_congestion_control(sk, ca); } else { err = -EBUSY; } From patchwork Thu Sep 10 14:04:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neal Cardwell X-Patchwork-Id: 1362017 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=FiyJnDW2; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BnWqL1XgYz9sVK for ; Fri, 11 Sep 2020 07:14:38 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727887AbgIJVO0 (ORCPT ); Thu, 10 Sep 2020 17:14:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731014AbgIJO2b (ORCPT ); Thu, 10 Sep 2020 10:28:31 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45674C061757 for ; Thu, 10 Sep 2020 07:04:47 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id 125so3660695qkh.4 for ; Thu, 10 Sep 2020 07:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=2TlvW+gem47oqaiPgHzk63tIxcSfaHdErY8i/BUbrtQ=; b=FiyJnDW25tS4GsOYsE8fh7PH8XlSDXnLRLpoCzOwoVPB+WfOOQdhNo3FNUixcDKLli OI70gHY1emuyc7ikwb5r5Wdz6sgx4iqccIUHkzj/DJ6SucZBUJ/qFnhFPaJqqsrfn+Z6 94k4e1HqkdDHFi/2v4fAmVFxG5sgQgz+mfCkv0/7hifqfQWPq3wBKYR/vBazRXVe8pDq geR6uJXnxn54TnUTDx4gVyZsAWuU0eFdjNZVE8LgSAj8Mtws1D2FR+D0ilDhxGh1Dx2V coML/5PbGTLZ9Ay4TE31Rh8QCctHiCHJNeqapUE1buKrdS+MQr+yF/2b6qvMcYPIrICU 49Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=2TlvW+gem47oqaiPgHzk63tIxcSfaHdErY8i/BUbrtQ=; b=L32tcbW68oa+i6SUBpa0w7I7Ns0Wf5PDgTodvq554Hrmp6asjDwfIrpvPy4R7FuJgb q+ggQ8BQG2UEy5oe7YMTCKDWsbhS2XUbMWrpBOqsrFJF3BFkEAX0m4hAKjhEMPTZ3Oca J9NlApPMd6lkhUzUo+xCxQV3QwULtMGV6hroGpWWvBxClEn0Y38X9mJg7l2is9HeqEgL /VYXkH8mEdbrfHRu0tGBjpkHnGm/uCNnK9HiSnvorCw8r0RcLqGwDQesHE6PjKQ3SfBa Ech3baaDsl+k9v6Inx4vJgqEBQ2qHglMHSdnonC19f4vDIt+2EP4xDfJXmawmNwunS0+ 7+AQ== X-Gm-Message-State: AOAM530w1UvygGF0wqcgpY0sp7jGTRhwsrKm0fPnr3PJ5tSlpQKbw8pR Elc/elctoGLK9oNT1Pkry2OAnWq+qDB5Br4= X-Google-Smtp-Source: ABdhPJz0Tr2O2Uzx3/IO7MvKwuvstSzyeN3XwXkJO0PvecWUqV+6qSs4NleAc0dMP0AdbTzjD9W2ob0h0WpeeOw= X-Received: from soy.nyc.corp.google.com ([2620:0:1003:312:7220:84ff:fe09:3008]) (user=ncardwell job=sendgmr) by 2002:a0c:eeca:: with SMTP id h10mr8952892qvs.13.1599746686356; Thu, 10 Sep 2020 07:04:46 -0700 (PDT) Date: Thu, 10 Sep 2020 10:04:27 -0400 In-Reply-To: <20200910140428.751193-1-ncardwell@google.com> Message-Id: <20200910140428.751193-5-ncardwell@google.com> Mime-Version: 1.0 References: <20200910140428.751193-1-ncardwell@google.com> X-Mailer: git-send-email 2.28.0.526.ge36021eeef-goog Subject: [PATCH bpf-next v2 4/5] tcp: simplify _bpf_setsockopt(): remove flags argument From: Neal Cardwell To: Alexei Starovoitov Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Eric Dumazet , Lawrence Brakmo Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Now that the previous patches have removed the code that uses the flags argument to _bpf_setsockopt(), we can remove that argument. Signed-off-by: Neal Cardwell Acked-by: Yuchung Cheng Acked-by: Kevin Yang Signed-off-by: Eric Dumazet Cc: Lawrence Brakmo --- net/core/filter.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index e89d6d7da03c..d266c6941967 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4314,7 +4314,7 @@ static const struct bpf_func_proto bpf_get_socket_uid_proto = { }; static int _bpf_setsockopt(struct sock *sk, int level, int optname, - char *optval, int optlen, u32 flags) + char *optval, int optlen) { char devname[IFNAMSIZ]; int val, valbool; @@ -4611,9 +4611,7 @@ static int _bpf_getsockopt(struct sock *sk, int level, int optname, BPF_CALL_5(bpf_sock_addr_setsockopt, struct bpf_sock_addr_kern *, ctx, int, level, int, optname, char *, optval, int, optlen) { - u32 flags = 0; - return _bpf_setsockopt(ctx->sk, level, optname, optval, optlen, - flags); + return _bpf_setsockopt(ctx->sk, level, optname, optval, optlen); } static const struct bpf_func_proto bpf_sock_addr_setsockopt_proto = { @@ -4647,9 +4645,7 @@ static const struct bpf_func_proto bpf_sock_addr_getsockopt_proto = { BPF_CALL_5(bpf_sock_ops_setsockopt, struct bpf_sock_ops_kern *, bpf_sock, int, level, int, optname, char *, optval, int, optlen) { - u32 flags = 0; - return _bpf_setsockopt(bpf_sock->sk, level, optname, optval, optlen, - flags); + return _bpf_setsockopt(bpf_sock->sk, level, optname, optval, optlen); } static const struct bpf_func_proto bpf_sock_ops_setsockopt_proto = { From patchwork Thu Sep 10 14:04:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neal Cardwell X-Patchwork-Id: 1362020 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=YQG35bnD; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BnWx05XwPz9sSP for ; Fri, 11 Sep 2020 07:19:32 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727965AbgIJVOJ (ORCPT ); Thu, 10 Sep 2020 17:14:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731144AbgIJO2b (ORCPT ); Thu, 10 Sep 2020 10:28:31 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8A1EC061346 for ; Thu, 10 Sep 2020 07:04:48 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id l1so3396108qvr.0 for ; Thu, 10 Sep 2020 07:04:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=xA7IbJ3yaVDET7+RE99G6nvD4sMERSruE+q/sYEPOkY=; b=YQG35bnDpcnnwuZjnW/nNyuqSr7tOnkchO8w13j8BCWRuyorpS3LNqsE1HzyTpXtne cVnXZgKp/Io8YK9Nsh/HTmMP2cvTB7EsmRWD7915Y68vgnybPk+FaSvXVmJZrv7lI1/s 4n160ykKZMfKQ5qmcsVrFPvBJ9zCqbzPrsjk5c2W312BdmXbI0MUJpyvZ+OdVZd4LiFb YRfQI8J89JXN/ATXwQTUygxLk+pcpK5ITJc/5gsosgZTeWkAbUFzXT1gFKe+ETNv++tm bbEQccOFfARXaDCY6I5AIYOi/j8oJZwNnTY9Ltny0LjCAR5RRCmW87YgSVIxXHmQeO4W uVPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=xA7IbJ3yaVDET7+RE99G6nvD4sMERSruE+q/sYEPOkY=; b=gfZE/++0g33FacvudgmwmJjmhlM1F6chlsxCWnDEowf10WLLQ2IeVE624Owyxkt9nw fGFvZOykFfa/xv1hzrXKij97fqW2zujatUGJChD35Uif9aHG6CXA9SX43M/1O6hIvjpI eXsGby/5H9wB/1IpxJLMkX5s5lnT953y2rCos8y6padlxhRJ1RO1/XR42jHWk81+64e2 1S9PLJuxQnaf0vx/v470DBfa5uijz80pLA0rULaM4SzYlREBW/2WCtxcY10MIvifpvI3 Z7PqY6jjB6idCS6auHPvzcqgL4K7pKvwR0gecmzeI4eUL398EA8S9uivWbrOXmazBJWJ FXPw== X-Gm-Message-State: AOAM533MelLX+UGFWPf30RRGOXfxi55NN7d00Uv5O2jZT70ofHoCToD9 gOrZynWfp6EjR3eEp2tze8PrrmheBSxHOBc= X-Google-Smtp-Source: ABdhPJzikJ/z/Ool8o6FS01OSPjXiNwxoGQkyIbTt86xNyu9dl0ZhDkYNdah/gvC4hNfHKpPIZzZVTC8ANkYKEc= X-Received: from soy.nyc.corp.google.com ([2620:0:1003:312:7220:84ff:fe09:3008]) (user=ncardwell job=sendgmr) by 2002:a0c:b6d7:: with SMTP id h23mr8664387qve.17.1599746687832; Thu, 10 Sep 2020 07:04:47 -0700 (PDT) Date: Thu, 10 Sep 2020 10:04:28 -0400 In-Reply-To: <20200910140428.751193-1-ncardwell@google.com> Message-Id: <20200910140428.751193-6-ncardwell@google.com> Mime-Version: 1.0 References: <20200910140428.751193-1-ncardwell@google.com> X-Mailer: git-send-email 2.28.0.526.ge36021eeef-goog Subject: [PATCH bpf-next v2 5/5] tcp: simplify tcp_set_congestion_control() load=false case From: Neal Cardwell To: Alexei Starovoitov Cc: netdev@vger.kernel.org, Neal Cardwell , Martin KaFai Lau , Lawrence Brakmo , Eric Dumazet , Yuchung Cheng , Kevin Yang Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Simplify tcp_set_congestion_control() by removing the initialization code path for the !load case. There are only two call sites for tcp_set_congestion_control(). The EBPF call site is the only one that passes load=false; it also passes cap_net_admin=true. Because of that, the exact same behavior can be achieved by removing the special if (!load) branch of the logic. Both before and after this commit, the EBPF case will call bpf_try_module_get(), and if that succeeds then call tcp_reinit_congestion_control() or if that fails then return EBUSY. Note that this returns the logic to a structure very similar to the structure before: commit 91b5b21c7c16 ("bpf: Add support for changing congestion control") except that the CAP_NET_ADMIN status is passed in as a function argument. This clean-up was suggested by Martin KaFai Lau. Signed-off-by: Neal Cardwell Suggested-by: Martin KaFai Lau Cc: Lawrence Brakmo Cc: Eric Dumazet Cc: Yuchung Cheng Cc: Kevin Yang --- net/ipv4/tcp_cong.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c index a9b0fb52a1ec..db47ac24d057 100644 --- a/net/ipv4/tcp_cong.c +++ b/net/ipv4/tcp_cong.c @@ -362,21 +362,14 @@ int tcp_set_congestion_control(struct sock *sk, const char *name, bool load, goto out; } - if (!ca) { + if (!ca) err = -ENOENT; - } else if (!load) { - if (bpf_try_module_get(ca, ca->owner)) { - tcp_reinit_congestion_control(sk, ca); - } else { - err = -EBUSY; - } - } else if (!((ca->flags & TCP_CONG_NON_RESTRICTED) || cap_net_admin)) { + else if (!((ca->flags & TCP_CONG_NON_RESTRICTED) || cap_net_admin)) err = -EPERM; - } else if (!bpf_try_module_get(ca, ca->owner)) { + else if (!bpf_try_module_get(ca, ca->owner)) err = -EBUSY; - } else { + else tcp_reinit_congestion_control(sk, ca); - } out: rcu_read_unlock(); return err;