From patchwork Thu Sep 10 19:35:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neal Cardwell X-Patchwork-Id: 261121 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83372C43461 for ; Thu, 10 Sep 2020 19:37:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A58221D81 for ; Thu, 10 Sep 2020 19:37:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nUdv6TKl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727901AbgIJTgu (ORCPT ); Thu, 10 Sep 2020 15:36:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725803AbgIJTfl (ORCPT ); Thu, 10 Sep 2020 15:35:41 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AAF4C061757 for ; Thu, 10 Sep 2020 12:35:41 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id g72so7287773qke.8 for ; Thu, 10 Sep 2020 12:35:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y1Qjy3REE/DvqVeuoDCxwy818dXeknrvZhb2GWvtIBA=; b=nUdv6TKlDUP0FhNeZ4heaPj1d4St+l3qKYYO3tXTjo6UAF/3Rtfu6mMV0bie+iT/qu /sJUmVZAuPnTEhwc4KZsPL9vvo+2J2NWzqkHLRHmNlJ8Myvh7Mdd+JKEBf4OhzDI732g 6nwziRl1edDb/q1o21gy/TWMSNc0ckM37RrIhdFgjSdSbpxC0uZHNvzTIhnENPZyuC++ vhpwEB5hmJc48sf/uUeEGvPUqcY8Vs7zMWAIryq5uYIPhw637aKE/+otQaaa8XepApid 0GAR55WjhtCetUO6NKBrRAkZVMEtb+LtUEgEYgdkejnX59MicR15XI6pNxHusyGB1KzQ PscQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y1Qjy3REE/DvqVeuoDCxwy818dXeknrvZhb2GWvtIBA=; b=BxOq5t1PLTOHG48tAMUsOuM6ZcFT53GA/q5LWfSdmW/5USg21lUEO0nFz7C4/Q3Mvc N9Af4kMknUcsriqHeerGWWIUX9ftBjdIV57N0pGU33s+PbMUYXQWMtcRtztxP3ZfL8Ad kFGy/IrjGkXiz75JHtaDaeenB7QDbKElGhYntrh6DbtfY7N1QnZZx8rLZiWlhgVWmV42 zHASmUt4vDFuw5b7rbOPUI4fJ5RmwB+ilOrxJN0sadr6OECNzSRTSUfEXehsmOKOl4fw rs/K3EbDlRLvPZd073EHJl9pt67Lqbtju5oLQbrrmNwd7NeB9r984SB+JHVngC/LgtJI 34QA== X-Gm-Message-State: AOAM532EemwqUYwS4v+3DpiZXBDdwyLPADYnkPcPiBLMgbqEgUu8AK7w nBvfvXb00kzFANsruWYr7Jk= X-Google-Smtp-Source: ABdhPJzL5h0rqe0d1/fQ3dAU1WYaa+mSsB35kHaairqhv6PTiDwbK9mcBZBZeYxWE8Caj5AbYgK7Xw== X-Received: by 2002:ae9:e70c:: with SMTP id m12mr9493095qka.91.1599766540338; Thu, 10 Sep 2020 12:35:40 -0700 (PDT) Received: from soy.nyc.corp.google.com ([2620:0:1003:312:7220:84ff:fe09:3008]) by smtp.gmail.com with ESMTPSA id f13sm7735484qko.122.2020.09.10.12.35.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 12:35:39 -0700 (PDT) From: Neal Cardwell To: Alexei Starovoitov Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Eric Dumazet , Lawrence Brakmo Subject: [PATCH bpf-next v3 2/5] tcp: simplify EBPF TCP_CONGESTION to always init CC Date: Thu, 10 Sep 2020 15:35:33 -0400 Message-Id: <20200910193536.2980613-3-ncardwell.kernel@gmail.com> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog In-Reply-To: <20200910193536.2980613-1-ncardwell.kernel@gmail.com> References: <20200910193536.2980613-1-ncardwell.kernel@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Neal Cardwell 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 19:35:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neal Cardwell X-Patchwork-Id: 261122 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F331EC433E2 for ; Thu, 10 Sep 2020 19:36:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B144F21D81 for ; Thu, 10 Sep 2020 19:36:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="O9Sz5hNW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727870AbgIJTgX (ORCPT ); Thu, 10 Sep 2020 15:36:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726755AbgIJTfm (ORCPT ); Thu, 10 Sep 2020 15:35:42 -0400 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BEF4C0613ED for ; Thu, 10 Sep 2020 12:35:42 -0700 (PDT) Received: by mail-qt1-x844.google.com with SMTP id n18so5852869qtw.0 for ; Thu, 10 Sep 2020 12:35:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4NVvlx0Y06jzusDaZ6IoBQMLf9wBMnk5hk4bhYfrbF8=; b=O9Sz5hNWhATnTUNiYf3UGLUufvuzzLSxfcu0boUs38EcmxBqpYnGydHu2ebKnMHEKk Rv5iNW6coIzPPkjq2sudtMqrg7Hx/wiDo7mTXfiBp4dfEjxN3NZ0BBMv4ycKmWTg128L eXmWDa9i7uicUhp44J1ma00dD/FPnVQ18efb5Sjyvm2/rjrm65q96TQgA43Lwsqtt5O6 I2eTuaUrjJe8Obru4oPQY9hbpu+BbEVN5ckiIlsOkr5X7CLXU8aQVKUik7TfGou4qpH3 xnHOXh2P49n+wee6/9kn0LYCgnhOXHb9NIQ3dD9Gza3z6K75myiJH7bvtwRlRtjGbvXO pVhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4NVvlx0Y06jzusDaZ6IoBQMLf9wBMnk5hk4bhYfrbF8=; b=hPy3UTUs9UZjVsBEnOIl3ZmU96VkItMzlnuaXPpLc8Il4anJb5Su//5Fpuw41b00bN iyQF5dtwZWJTbgYVGYEPUWUJ0dBvvzsZ2HOMFJlaoEpRyANxtBbCnh0cE6RI1pTKD0se fDGokfvSb216BpkqxFfgAHFwtap1rNbr3QL6n31NqaimGZX+80+arizthTwN3UE0JmXC WRY0Pj3+08YTJKjGS3k5jhAr5tEuizcL+gS9Y2vX60ZdXqDxDAWxm8MntH0FpMMc0LaI vfsbI2SlhzkY1TRTo0NeTjdAwJOh1iEyUDHFJGC7Ne7NBeZcgpFAggCZ7aEM5jtaWe1a tryA== X-Gm-Message-State: AOAM530xW4LTYAC0iUsxuhj0eY1nbUE63hsrO5urRWS4Y5D4l6Gu9XAs E1cwQJoEXc4rXIVHBq054/k= X-Google-Smtp-Source: ABdhPJz4Iex0y5KVVdZqsnJVgaBMBTll5NGl/3hUklsTJRTDBUGNjrq/1ONxdQUeYwJj7+b41Gf+Zg== X-Received: by 2002:ac8:4757:: with SMTP id k23mr9377376qtp.105.1599766541328; Thu, 10 Sep 2020 12:35:41 -0700 (PDT) Received: from soy.nyc.corp.google.com ([2620:0:1003:312:7220:84ff:fe09:3008]) by smtp.gmail.com with ESMTPSA id f13sm7735484qko.122.2020.09.10.12.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 12:35:40 -0700 (PDT) From: Neal Cardwell To: Alexei Starovoitov Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Eric Dumazet , Lawrence Brakmo Subject: [PATCH bpf-next v3 3/5] tcp: simplify tcp_set_congestion_control(): always reinitialize Date: Thu, 10 Sep 2020 15:35:34 -0400 Message-Id: <20200910193536.2980613-4-ncardwell.kernel@gmail.com> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog In-Reply-To: <20200910193536.2980613-1-ncardwell.kernel@gmail.com> References: <20200910193536.2980613-1-ncardwell.kernel@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Neal Cardwell 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 19:35:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neal Cardwell X-Patchwork-Id: 261120 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B303C43461 for ; Thu, 10 Sep 2020 19:37:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E8F8A21D81 for ; Thu, 10 Sep 2020 19:37:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KoJqjh90" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727058AbgIJTgu (ORCPT ); Thu, 10 Sep 2020 15:36:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726675AbgIJTgB (ORCPT ); Thu, 10 Sep 2020 15:36:01 -0400 Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBA3AC061795 for ; Thu, 10 Sep 2020 12:35:43 -0700 (PDT) Received: by mail-qv1-xf41.google.com with SMTP id db4so3951365qvb.4 for ; Thu, 10 Sep 2020 12:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sbLrAjHEicejYQwCS7LtXSjDNtzl79GZWNsQFcCLCUc=; b=KoJqjh90741y0xJ6Orny3csrEmvi3uFlCBat90ZGtWvfMc/gcHOsPLbTfxJRFkSVZ4 Z/kS9vlLBKW3P0ffGxfwl64xiBv0zv1pmwjraq1tByjGzRSnM1hdvS5YyTisCGyJ3IR5 LMVlC/4IjI1QQk7GIso9YVnpAHok0l32YD9hGUaaP5hGkQVPOl0AzeAWHT30oP0sIA3Q GYQ7F386PIFnmrCk3A2Q7NhsMaeCY9hepyodAAHwBsft0qxgJ/7YdUr17dktlipIMz8O HsUDXkEDGex9sTIXh0+mmMKhMqVGPgfcu7qWS31EBMLlV4Gg91MpvYnJko1Vj4FUo/+6 KETw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sbLrAjHEicejYQwCS7LtXSjDNtzl79GZWNsQFcCLCUc=; b=A+izVfv/Tw38+5C+5m7vIeGKVrsTZWm8qZ0XUZQUlh2pnr7Ek3Rvex9DDqy0eS0iwu hilqyaBSQZGGyrxJzL8tzsciaOcvIdcrGkFJacdF3Z5FcF6uTF1tl2BCtbNmlSGw7GN/ QIvVJA6RNa5ltt+Tg8jJbP2WUR/DHxF9IesUeXfa0d0+0lg5e7Hm57OWz1lUm1q4BZgQ je6C7fQiYT+C4OB+NQK6GHOs6LoSWEJhCR1M2S15nxD7PWjVpV92TfoKnqGkhbfB4YOd 4xjpUxrXOeeh9GQbNF37j93DO+vTSrrgDsv6AKqCKsyYSlMMhSjnp/epR3sQn5pyScFM Mo9A== X-Gm-Message-State: AOAM53161lCvm+6PmfaikdNZCqNh40K4mYZBjHfyX3xE0+y4659wxd6/ 2wk1XpV/NNlKAj/gmwlYkFM= X-Google-Smtp-Source: ABdhPJwslwe1CWWUgBDfRofmYx6ztM259qUlz7amMNyGU08b8BKwriKqcK3DuyE78avTM3YOBpnBIg== X-Received: by 2002:a0c:c492:: with SMTP id u18mr9916090qvi.18.1599766543234; Thu, 10 Sep 2020 12:35:43 -0700 (PDT) Received: from soy.nyc.corp.google.com ([2620:0:1003:312:7220:84ff:fe09:3008]) by smtp.gmail.com with ESMTPSA id f13sm7735484qko.122.2020.09.10.12.35.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 12:35:42 -0700 (PDT) From: Neal Cardwell To: Alexei Starovoitov Cc: netdev@vger.kernel.org, Neal Cardwell , Martin KaFai Lau , Lawrence Brakmo , Eric Dumazet , Yuchung Cheng , Kevin Yang Subject: [PATCH bpf-next v3 5/5] tcp: simplify tcp_set_congestion_control() load=false case Date: Thu, 10 Sep 2020 15:35:36 -0400 Message-Id: <20200910193536.2980613-6-ncardwell.kernel@gmail.com> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog In-Reply-To: <20200910193536.2980613-1-ncardwell.kernel@gmail.com> References: <20200910193536.2980613-1-ncardwell.kernel@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Neal Cardwell 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;