diff mbox series

[RFC,net-next,2/3] txhash: Add socket option to control TX hash rethink behavior

Message ID 20210809185314.38187-3-tom@herbertland.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series txhash: Make hash rethink configurable and change the default | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 24 maintainers not CCed: xiangxia.m.yue@gmail.com yangbo.lu@nxp.com linux-mips@vger.kernel.org edumazet@google.com linux-alpha@vger.kernel.org linux-parisc@vger.kernel.org linmiaohe@huawei.com sparclinux@vger.kernel.org m@lambda.lt rth@twiddle.net arnd@arndb.de deller@gmx.de pabeni@redhat.com tsbogend@alpha.franken.de kuba@kernel.org daniel@iogearbox.net aahringo@redhat.com ink@jurassic.park.msu.ru mattst88@gmail.com James.Bottomley@HansenPartnership.com ptikhomirov@virtuozzo.com linux-arch@vger.kernel.org bjorn@kernel.org fw@strlen.de
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff fail Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit fail Errors and warnings before: 616 this patch: 651
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 102 lines checked
netdev/build_allmodconfig_warn fail Errors and warnings before: 1103 this patch: 1274
netdev/header_inline success Link

Commit Message

Tom Herbert Aug. 9, 2021, 6:53 p.m. UTC
Add the SO_TXREHASH_MODE socket option to control hash rethink behavior
per socket. The setsockopt argument is a mask of rethink modes
(SOCK_TXREHASH_MODE_NEG_ADVICE, SOCK_TXREHASH_MODE_SYN_RTO,
and SOCK_TXREHASH_MODE_RTO). The argument may also be -1U
(SOCK_TXREHASH_MODE_DEFAULT) which indicates that the default system
value should be used (see txrehash_mode sysctl)
---
 arch/alpha/include/uapi/asm/socket.h  |  2 ++
 arch/mips/include/uapi/asm/socket.h   |  2 ++
 arch/parisc/include/uapi/asm/socket.h |  2 ++
 arch/sparc/include/uapi/asm/socket.h  |  3 ++-
 include/net/sock.h                    |  8 +++++++-
 include/uapi/asm-generic/socket.h     |  2 ++
 net/core/sock.c                       | 16 ++++++++++++++++
 7 files changed, 33 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/arch/alpha/include/uapi/asm/socket.h b/arch/alpha/include/uapi/asm/socket.h
index 1dd9baf4a6c2..1165cdab5277 100644
--- a/arch/alpha/include/uapi/asm/socket.h
+++ b/arch/alpha/include/uapi/asm/socket.h
@@ -131,6 +131,8 @@ 
 
 #define SO_BUF_LOCK		72
 
+#define SO_TXREHASH_MODE	73
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
diff --git a/arch/mips/include/uapi/asm/socket.h b/arch/mips/include/uapi/asm/socket.h
index 1eaf6a1ca561..91412f7725bd 100644
--- a/arch/mips/include/uapi/asm/socket.h
+++ b/arch/mips/include/uapi/asm/socket.h
@@ -142,6 +142,8 @@ 
 
 #define SO_BUF_LOCK		72
 
+#define SO_TXREHASH_MODE	73
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
diff --git a/arch/parisc/include/uapi/asm/socket.h b/arch/parisc/include/uapi/asm/socket.h
index 8baaad52d799..80e0eddc6730 100644
--- a/arch/parisc/include/uapi/asm/socket.h
+++ b/arch/parisc/include/uapi/asm/socket.h
@@ -123,6 +123,8 @@ 
 
 #define SO_BUF_LOCK		0x4046
 
+#define SO_TXREHASH_MODE	0x4047
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
diff --git a/arch/sparc/include/uapi/asm/socket.h b/arch/sparc/include/uapi/asm/socket.h
index e80ee8641ac3..2fd5679e4116 100644
--- a/arch/sparc/include/uapi/asm/socket.h
+++ b/arch/sparc/include/uapi/asm/socket.h
@@ -124,8 +124,9 @@ 
 
 #define SO_BUF_LOCK              0x0051
 
-#if !defined(__KERNEL__)
+#define SO_TXREHASH_MODE	 0x0052
 
+#if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
 #define SO_TIMESTAMP		SO_TIMESTAMP_OLD
diff --git a/include/net/sock.h b/include/net/sock.h
index 6ef5314e8eed..b6ddb5278b8c 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -313,6 +313,7 @@  struct bpf_local_storage;
   *	@sk_rcvtimeo: %SO_RCVTIMEO setting
   *	@sk_sndtimeo: %SO_SNDTIMEO setting
   *	@sk_txhash: computed flow hash for use on transmit
+  *	@sk_txrehash_mode: configuration bits for controlling TX hash rethink
   *	@sk_filter: socket filtering instructions
   *	@sk_timer: sock cleanup timer
   *	@sk_stamp: time stamp of last packet received
@@ -462,6 +463,7 @@  struct sock {
 	unsigned int		sk_gso_max_size;
 	gfp_t			sk_allocation;
 	__u32			sk_txhash;
+	unsigned int		sk_txrehash_mode;
 
 	/*
 	 * Because of non atomicity rules, all
@@ -1953,7 +1955,11 @@  static inline bool sk_rethink_txhash(struct sock *sk, unsigned int level)
 	if (!sk->sk_txhash)
 		return false;
 
-	rehash_mode = READ_ONCE(sock_net(sk)->core.sysctl_txrehash_mode);
+	if (sk->sk_txrehash_mode == SOCK_TXREHASH_MODE_DEFAULT)
+		rehash_mode =
+			READ_ONCE(sock_net(sk)->core.sysctl_txrehash_mode);
+	else
+		rehash_mode = sk->sk_txrehash_mode;
 
 	if (level & rehash_mode) {
 		sk_set_txhash(sk);
diff --git a/include/uapi/asm-generic/socket.h b/include/uapi/asm-generic/socket.h
index 1f0a2b4864e4..daa775cc4108 100644
--- a/include/uapi/asm-generic/socket.h
+++ b/include/uapi/asm-generic/socket.h
@@ -126,6 +126,8 @@ 
 
 #define SO_BUF_LOCK		72
 
+#define SO_TXREHASH_MODE	73
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
diff --git a/net/core/sock.c b/net/core/sock.c
index aada649e07e8..946d9e9242c8 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1367,6 +1367,17 @@  int sock_setsockopt(struct socket *sock, int level, int optname,
 					  ~SOCK_BUF_LOCK_MASK);
 		break;
 
+	case SO_TXREHASH_MODE:
+		if (val == SOCK_TXREHASH_MODE_DEFAULT ||
+		    (val & ~SOCK_TXREHASH_MODE_MASK)) {
+			ret = -EINVAL;
+			break;
+		}
+
+		sk->sk_txrehash_mode =  val;
+
+		break;
+
 	default:
 		ret = -ENOPROTOOPT;
 		break;
@@ -1733,6 +1744,10 @@  int sock_getsockopt(struct socket *sock, int level, int optname,
 		v.val = sk->sk_userlocks & SOCK_BUF_LOCK_MASK;
 		break;
 
+	case SO_TXREHASH_MODE:
+		v.val = sk->sk_txrehash_mode;
+		break;
+
 	default:
 		/* We implement the SO_SNDLOWAT etc to not be settable
 		 * (1003.1g 7).
@@ -3158,6 +3173,7 @@  void sock_init_data(struct socket *sock, struct sock *sk)
 	sk->sk_pacing_rate = ~0UL;
 	WRITE_ONCE(sk->sk_pacing_shift, 10);
 	sk->sk_incoming_cpu = -1;
+	sk->sk_txrehash_mode = SOCK_TXREHASH_MODE_DEFAULT;
 
 	sk_rx_queue_clear(sk);
 	/*