All of lore.kernel.org
 help / color / mirror / Atom feed
From: Akhmat Karakotov <hmukos@yandex-team.ru>
To: netdev@vger.kernel.org
Cc: hmukos@yandex-team.ru, edumazet@google.com,
	eric.dumazet@gmail.com, mitradir@yandex-team.ru,
	tom@herbertland.com, zeil@yandex-team.ru
Subject: [RFC PATCH v3 net-next 1/4] txhash: Make rethinking txhash behavior configurable via sysctl
Date: Mon,  6 Dec 2021 22:11:08 +0300	[thread overview]
Message-ID: <20211206191111.14376-2-hmukos@yandex-team.ru> (raw)
In-Reply-To: <20211206191111.14376-1-hmukos@yandex-team.ru>

Add a per ns sysctl that controls the txhash rethink behavior,
sk_rethink_txhash. When enabled, the same behavior is retained, when
disabled, rethink is not performed. Sysctl is enabled by default.

Signed-off-by: Akhmat Karakotov <hmukos@yandex-team.ru>
---
 include/net/netns/core.h    |  1 +
 include/net/sock.h          | 34 +++++++++++++++++++++-------------
 include/uapi/linux/socket.h |  3 +++
 net/core/net_namespace.c    |  2 ++
 net/core/sysctl_net_core.c  | 14 ++++++++++++--
 5 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/include/net/netns/core.h b/include/net/netns/core.h
index 36c2d998a43c..00760e4efed7 100644
--- a/include/net/netns/core.h
+++ b/include/net/netns/core.h
@@ -10,6 +10,7 @@ struct netns_core {
 	struct ctl_table_header	*sysctl_hdr;
 
 	int	sysctl_somaxconn;
+	u8	sysctl_txrehash;
 
 #ifdef CONFIG_PROC_FS
 	int __percpu *sock_inuse;
diff --git a/include/net/sock.h b/include/net/sock.h
index 66a9a90f9558..cc83140d6502 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -577,6 +577,18 @@ static inline bool sk_user_data_is_nocopy(const struct sock *sk)
 			   __tmp | SK_USER_DATA_NOCOPY);		\
 })
 
+static inline
+struct net *sock_net(const struct sock *sk)
+{
+	return read_pnet(&sk->sk_net);
+}
+
+static inline
+void sock_net_set(struct sock *sk, struct net *net)
+{
+	write_pnet(&sk->sk_net, net);
+}
+
 /*
  * SK_CAN_REUSE and SK_NO_REUSE on a socket mean that the socket is OK
  * or not whether his port will be reused by someone else. SK_FORCE_REUSE
@@ -1942,10 +1954,18 @@ static inline void sk_set_txhash(struct sock *sk)
 
 static inline bool sk_rethink_txhash(struct sock *sk)
 {
-	if (sk->sk_txhash) {
+	u8 rehash;
+
+	if (!sk->sk_txhash)
+		return false;
+
+	rehash = READ_ONCE(sock_net(sk)->core.sysctl_txrehash);
+
+	if (rehash) {
 		sk_set_txhash(sk);
 		return true;
 	}
+
 	return false;
 }
 
@@ -2596,18 +2616,6 @@ static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb)
 	__kfree_skb(skb);
 }
 
-static inline
-struct net *sock_net(const struct sock *sk)
-{
-	return read_pnet(&sk->sk_net);
-}
-
-static inline
-void sock_net_set(struct sock *sk, struct net *net)
-{
-	write_pnet(&sk->sk_net, net);
-}
-
 static inline bool
 skb_sk_is_prefetched(struct sk_buff *skb)
 {
diff --git a/include/uapi/linux/socket.h b/include/uapi/linux/socket.h
index eb0a9a5b6e71..0accd6102ece 100644
--- a/include/uapi/linux/socket.h
+++ b/include/uapi/linux/socket.h
@@ -31,4 +31,7 @@ struct __kernel_sockaddr_storage {
 
 #define SOCK_BUF_LOCK_MASK (SOCK_SNDBUF_LOCK | SOCK_RCVBUF_LOCK)
 
+#define SOCK_TXREHASH_DISABLED	0
+#define SOCK_TXREHASH_ENABLED	1
+
 #endif /* _UAPI_LINUX_SOCKET_H */
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index a448a9b5bb2d..de7bf682092c 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -359,6 +359,8 @@ static __net_init int setup_net(struct net *net, struct user_namespace *user_ns)
 static int __net_init net_defaults_init_net(struct net *net)
 {
 	net->core.sysctl_somaxconn = SOMAXCONN;
+	net->core.sysctl_txrehash = SOCK_TXREHASH_ENABLED;
+
 	return 0;
 }
 
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index c8496c1142c9..01491631b20e 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -592,6 +592,15 @@ static struct ctl_table netns_core_table[] = {
 		.extra1		= SYSCTL_ZERO,
 		.proc_handler	= proc_dointvec_minmax
 	},
+	{
+		.procname	= "txrehash",
+		.data		= &init_net.core.sysctl_txrehash,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
 	{ }
 };
 
@@ -610,7 +619,7 @@ __setup("fb_tunnels=", fb_tunnels_only_for_init_net_sysctl_setup);
 
 static __net_init int sysctl_core_net_init(struct net *net)
 {
-	struct ctl_table *tbl;
+	struct ctl_table *tbl, *tmp;
 
 	tbl = netns_core_table;
 	if (!net_eq(net, &init_net)) {
@@ -618,7 +627,8 @@ static __net_init int sysctl_core_net_init(struct net *net)
 		if (tbl == NULL)
 			goto err_dup;
 
-		tbl[0].data = &net->core.sysctl_somaxconn;
+		for (tmp = tbl; tmp->procname; tmp++)
+			tmp->data += (char *)net - (char *)&init_net;
 
 		/* Don't export any sysctls to unprivileged users */
 		if (net->user_ns != &init_user_ns) {
-- 
2.17.1


  reply	other threads:[~2021-12-06 19:11 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-25 20:35 [RFC PATCH net-next 0/4] txhash: Make hash rethink configurable Akhmat Karakotov
2021-10-25 20:35 ` [RFC PATCH net-next 1/4] txhash: Make rethinking txhash behavior configurable via sysctl Akhmat Karakotov
2021-10-25 20:54   ` Eric Dumazet
2021-11-05  6:13   ` [txhash] d7fa06e1ae: WARNING:at_net/sysctl_net.c:#register_net_sysctl kernel test robot
2021-11-05  6:13     ` kernel test robot
2021-11-05  6:13     ` [LTP] " kernel test robot
2021-10-25 20:35 ` [RFC PATCH net-next 2/4] txhash: Add socket option to control TX hash rethink behavior Akhmat Karakotov
2021-10-25 21:05   ` Eric Dumazet
2021-10-29 10:01     ` Akhmat Karakotov
     [not found]       ` <D7FFC160-1DC3-42A5-BE0E-15FD81BEB1F3@yandex-team.ru>
2021-11-08 12:48         ` Akhmat Karakotov
2021-11-08 19:39           ` Eric Dumazet
2021-10-25 20:35 ` [RFC PATCH net-next 3/4] bpf: Add SO_TXREHASH setsockopt Akhmat Karakotov
2021-10-25 20:35 ` [RFC PATCH net-next 4/4] tcp: change SYN ACK retransmit behaviour to account for rehash Akhmat Karakotov
2021-11-12 18:19 ` [RFC PATCH v2 net-next 0/4] txhash: Make hash rethink configurable Akhmat Karakotov
2021-11-12 18:19   ` [RFC PATCH v2 net-next 1/4] txhash: Make rethinking txhash behavior configurable via sysctl Akhmat Karakotov
2021-11-12 18:19   ` [RFC PATCH v2 net-next 2/4] txhash: Add socket option to control TX hash rethink behavior Akhmat Karakotov
2021-11-12 18:19   ` [RFC PATCH v2 net-next 3/4] bpf: Add SO_TXREHASH setsockopt Akhmat Karakotov
2021-11-12 18:19   ` [RFC PATCH v2 net-next 4/4] tcp: change SYN ACK retransmit behaviour to account for rehash Akhmat Karakotov
2021-11-23 13:20   ` [RFC PATCH v2 net-next 0/4] txhash: Make hash rethink configurable Akhmat Karakotov
2021-11-30  9:58     ` Akhmat Karakotov
2021-12-01 16:49       ` Eric Dumazet
2021-12-02 16:40         ` Akhmat Karakotov
2021-12-02 16:40           ` [RFC PATCH v2 net-next 1/4] txhash: Make rethinking txhash behavior configurable via sysctl Akhmat Karakotov
2021-12-02 16:40           ` [RFC PATCH v2 net-next 2/4] txhash: Add socket option to control TX hash rethink behavior Akhmat Karakotov
2021-12-02 17:18             ` Eric Dumazet
2021-12-02 21:59             ` kernel test robot
2021-12-02 21:59               ` kernel test robot
2021-12-02 16:40           ` [RFC PATCH v2 net-next 3/4] bpf: Add SO_TXREHASH setsockopt Akhmat Karakotov
2021-12-02 16:40           ` [RFC PATCH v2 net-next 4/4] tcp: change SYN ACK retransmit behaviour to account for rehash Akhmat Karakotov
2021-12-02 17:24             ` Eric Dumazet
2021-12-06 19:11 ` [RFC PATCH v3 net-next 0/4] txhash: Make hash rethink configurable Akhmat Karakotov
2021-12-06 19:11   ` Akhmat Karakotov [this message]
2021-12-06 19:47     ` [RFC PATCH v3 net-next 1/4] txhash: Make rethinking txhash behavior configurable via sysctl Eric Dumazet
2021-12-06 19:11   ` [RFC PATCH v3 net-next 2/4] txhash: Add socket option to control TX hash rethink behavior Akhmat Karakotov
2021-12-06 19:48     ` Eric Dumazet
2021-12-06 19:11   ` [RFC PATCH v3 net-next 3/4] bpf: Add SO_TXREHASH setsockopt Akhmat Karakotov
2021-12-06 19:48     ` Eric Dumazet
2021-12-06 19:11   ` [RFC PATCH v3 net-next 4/4] tcp: change SYN ACK retransmit behaviour to account for rehash Akhmat Karakotov
2021-12-06 19:49     ` Eric Dumazet
2022-01-17 15:31     ` Akhmat Karakotov
2022-01-18 16:03       ` Jakub Kicinski
2022-01-18 16:52         ` Akhmat Karakotov
2021-12-04 10:51 [RFC PATCH v2 net-next 2/4] txhash: Add socket option to control TX hash rethink behavior kernel test robot
2021-12-06 13:33 ` Dan Carpenter

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=20211206191111.14376-2-hmukos@yandex-team.ru \
    --to=hmukos@yandex-team.ru \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=mitradir@yandex-team.ru \
    --cc=netdev@vger.kernel.org \
    --cc=tom@herbertland.com \
    --cc=zeil@yandex-team.ru \
    /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.