netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Neal Cardwell <ncardwell.kernel@gmail.com>
To: Alexei Starovoitov <ast@kernel.org>
Cc: netdev@vger.kernel.org, Neal Cardwell <ncardwell@google.com>,
	Martin KaFai Lau <kafai@fb.com>, Lawrence Brakmo <brakmo@fb.com>,
	Eric Dumazet <edumazet@google.com>,
	Yuchung Cheng <ycheng@google.com>, Kevin Yang <yyd@google.com>
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	[thread overview]
Message-ID: <20200910193536.2980613-6-ncardwell.kernel@gmail.com> (raw)
In-Reply-To: <20200910193536.2980613-1-ncardwell.kernel@gmail.com>

From: Neal Cardwell <ncardwell@google.com>

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 <ncardwell@google.com>
Suggested-by: Martin KaFai Lau <kafai@fb.com>
Cc: Lawrence Brakmo <brakmo@fb.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Yuchung Cheng <ycheng@google.com>
Cc: Kevin Yang <yyd@google.com>
---
 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;
-- 
2.28.0.618.gf4bc123cb7-goog


  parent reply	other threads:[~2020-09-10 19:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-10 19:35 [PATCH bpf-next v3 0/5] tcp: increase flexibility of EBPF congestion control initialization Neal Cardwell
2020-09-10 19:35 ` [PATCH bpf-next v3 1/5] tcp: only init congestion control if not initialized already Neal Cardwell
2020-09-10 19:35 ` [PATCH bpf-next v3 2/5] tcp: simplify EBPF TCP_CONGESTION to always init CC Neal Cardwell
2020-09-10 19:35 ` [PATCH bpf-next v3 3/5] tcp: simplify tcp_set_congestion_control(): always reinitialize Neal Cardwell
2020-09-10 19:35 ` [PATCH bpf-next v3 4/5] tcp: simplify _bpf_setsockopt(): remove flags argument Neal Cardwell
2020-09-10 19:35 ` Neal Cardwell [this message]
2020-09-11  3:28 ` [PATCH bpf-next v3 0/5] tcp: increase flexibility of EBPF congestion control initialization Martin KaFai Lau
2020-09-11  4:20   ` Alexei Starovoitov

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=20200910193536.2980613-6-ncardwell.kernel@gmail.com \
    --to=ncardwell.kernel@gmail.com \
    --cc=ast@kernel.org \
    --cc=brakmo@fb.com \
    --cc=edumazet@google.com \
    --cc=kafai@fb.com \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=ycheng@google.com \
    --cc=yyd@google.com \
    /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).