As it was shown in the report by Alexander Azimov, hash rethink at the client-side may lead to connection timeout toward stateful anycast services. Tom Herbert created a patchset to address this issue by applying hash rethink only after a negative routing event (3RTOs) [1]. This change also affects server-side behavior, which we found undesirable. This patchset changes defaults in a way to make them safe: hash rethink at the client-side is disabled and enabled at the server-side upon each RTO event or in case of duplicate acknowledgments.
This patchset provides two options to change default behaviour. The hash rethink may be disabled at the server-side by the new sysctl option. Changes in the sysctl option don't affect default behavior at the client-side.
Hash rethink can also be enabled/disabled with socket option or bpf syscalls which ovewrite both default and sysctl settings. This socket option is available on both client and server-side. This should provide mechanics to enable hash rethink inside administrative domain, such as DC, where hash rethink at the client-side can be desirable.
[1] https://lore.kernel.org/netdev/20210809185314.38187-1-tom@herbertland.com/
Akhmat Karakotov (4):
txhash: Make rethinking txhash behavior configurable via sysctl
txhash: Add socket option to control TX hash rethink behavior
bpf: Add SO_TXREHASH setsockopt
tcp: change SYN ACK retransmit behaviour to account for rehash
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 | 2 ++
include/net/netns/core.h | 2 ++
include/net/sock.h | 28 ++++++++++++++-------------
include/uapi/asm-generic/socket.h | 2 ++
include/uapi/linux/socket.h | 4 ++++
net/core/filter.c | 10 ++++++++++
net/core/net_namespace.c | 3 +++
net/core/sock.c | 13 +++++++++++++
net/core/sysctl_net_core.c | 7 +++++++
net/ipv4/inet_connection_sock.c | 3 +++
net/ipv4/tcp_output.c | 3 ++-
14 files changed, 69 insertions(+), 14 deletions(-)
--
2.17.1
@@ -360,7 +360,7 @@ static int __net_init net_defaults_init_net(struct net *net){net->core.sysctl_somaxconn=SOMAXCONN;-net->core.sysctl_txrehash=SOCK_TXREHASH_DISABLED;+net->core.sysctl_txrehash=SOCK_TXREHASH_ENABLED;return0;}
@@ -1367,6 +1367,14 @@ int sock_setsockopt(struct socket *sock, int level, int optname,~SOCK_BUF_LOCK_MASK);break;+caseSO_TXREHASH:+if(val<-1||val>1){+ret=-EINVAL;+break;+}+sk->sk_txrehash=val;+break;+default:ret=-ENOPROTOOPT;break;
@@ -1733,6 +1741,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,v.val=sk->sk_userlocks&SOCK_BUF_LOCK_MASK;break;+caseSO_TXREHASH:+v.val=sk->sk_txrehash;+break;+default:/* We implement the SO_SNDLOWAT etc to not be settable*(1003.1g7).
@@ -1046,6 +1046,9 @@ int inet_csk_listen_start(struct sock *sk, int backlog)sk->sk_ack_backlog=0;inet_csk_delack_init(sk);+if(sk->sk_txrehash==SOCK_TXREHASH_DEFAULT)+sk->sk_txrehash=READ_ONCE(sock_net(sk)->core.sysctl_txrehash);+/* There is race window here: we announce ourselves listening,*butthistransitionisstillnotvalidatedbyget_port().*ItisOK,becausethissocketenterstohashtableonly
@@ -4808,6 +4808,13 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,caseSO_REUSEPORT:sk->sk_reuseport=valbool;break;+caseSO_TXREHASH:+if(val<-1||val>1){+ret=-EINVAL;+break;+}+sk->sk_txrehash=val;+break;default:ret=-EINVAL;}
@@ -4980,6 +4987,9 @@ static int _bpf_getsockopt(struct sock *sk, int level, int optname,caseSO_REUSEPORT:*((int*)optval)=sk->sk_reuseport;break;+caseSO_TXREHASH:+*((int*)optval)=sk->sk_txrehash;+break;default:gotoerr_clear;}
Disabling rehash behavior did not affect SYN ACK retransmits because hash
was forcefully changed bypassing the sk_rethink_hash function. This patch
adds a condition which checks for rehash mode before resetting hash.
Signed-off-by: Akhmat Karakotov <redacted>
---
net/ipv4/tcp_output.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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 disabled by default.
Signed-off-by: Akhmat Karakotov <redacted>
---
include/net/netns/core.h | 2 ++
include/net/sock.h | 34 +++++++++++++++++++++-------------
include/uapi/linux/socket.h | 3 +++
net/core/net_namespace.c | 3 +++
net/core/sysctl_net_core.c | 7 +++++++
5 files changed, 36 insertions(+), 13 deletions(-)
From: Eric Dumazet <hidden> Date: 2021-10-25 20:55:19
On 10/25/21 1:35 PM, Akhmat Karakotov wrote:
quoted hunk
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 disabled by default.
Signed-off-by: Akhmat Karakotov <redacted>
---
include/net/netns/core.h | 2 ++
include/net/sock.h | 34 +++++++++++++++++++++-------------
include/uapi/linux/socket.h | 3 +++
net/core/net_namespace.c | 3 +++
net/core/sysctl_net_core.c | 7 +++++++
5 files changed, 36 insertions(+), 13 deletions(-)
From: Eric Dumazet <hidden> Date: 2021-10-25 21:05:44
On 10/25/21 1:35 PM, Akhmat Karakotov wrote:
Add the SO_TXREHASH socket option to control hash rethink behavior per socket.
When default mode is set, sockets disable rehash at initialization and use
sysctl option when entering listen state. setsockopt() overrides default
behavior.
What values are accepted, and what are their meaning ?
It seems weird to do anything in inet_csk_listen_start()
For sockets that have not used SO_TXREHASH
(this includes passive sockets where their parent did not use SO_TXREHASH),
the sysctl _current_ value should be used every time we consider a rehash.
@@ -360,7 +360,7 @@ static int __net_init net_defaults_init_net(struct net *net){net->core.sysctl_somaxconn=SOMAXCONN;-net->core.sysctl_txrehash=SOCK_TXREHASH_DISABLED;+net->core.sysctl_txrehash=SOCK_TXREHASH_ENABLED;
@@ -1367,6 +1367,14 @@ int sock_setsockopt(struct socket *sock, int level, int optname,~SOCK_BUF_LOCK_MASK);break;+caseSO_TXREHASH:+if(val<-1||val>1){+ret=-EINVAL;+break;+}+sk->sk_txrehash=val;+break;+default:ret=-ENOPROTOOPT;break;
@@ -1733,6 +1741,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,v.val=sk->sk_userlocks&SOCK_BUF_LOCK_MASK;break;+caseSO_TXREHASH:+v.val=sk->sk_txrehash;+break;+default:/* We implement the SO_SNDLOWAT etc to not be settable*(1003.1g7).
@@ -1046,6 +1046,9 @@ int inet_csk_listen_start(struct sock *sk, int backlog)sk->sk_ack_backlog=0;inet_csk_delack_init(sk);+if(sk->sk_txrehash==SOCK_TXREHASH_DEFAULT)+sk->sk_txrehash=READ_ONCE(sock_net(sk)->core.sysctl_txrehash);+/* There is race window here: we announce ourselves listening,*butthistransitionisstillnotvalidatedbyget_port().*ItisOK,becausethissocketenterstohashtableonly
On Oct 26, 2021, at 00:05, Eric Dumazet [off-list ref] wrote:
On 10/25/21 1:35 PM, Akhmat Karakotov wrote:
quoted
Add the SO_TXREHASH socket option to control hash rethink behavior per socket.
When default mode is set, sockets disable rehash at initialization and use
sysctl option when entering listen state. setsockopt() overrides default
behavior.
What values are accepted, and what are their meaning ?
It seems weird to do anything in inet_csk_listen_start()
For sockets that have not used SO_TXREHASH
(this includes passive sockets where their parent did not use SO_TXREHASH),
the sysctl _current_ value should be used every time we consider a rehash.
SO_TXREHASH_DEFAULT value means default behavior: for listening sockets
the sysctl value is taken, while for others rehash is disabled. The motivation
was to disallow hash rethink at the client-side to avoid connection timeout to
anycast services (as was stated in cover letter).
ENABLED and DISABLED values are for enforcing rehash option values.
To be honest I didn't quite understand how you propose to change patch behaviour.
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 <redacted>
---
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 | 15 +++++++++++++--
5 files changed, 40 insertions(+), 15 deletions(-)
@@ -618,7 +627,9 @@ static __net_init int sysctl_core_net_init(struct net *net)if(tbl==NULL)gotoerr_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){
As it was shown in the report by Alexander Azimov, hash rethink at the
client-side may lead to connection timeout toward stateful anycast
services. Tom Herbert created a patchset to address this issue by applying
hash rethink only after a negative routing event (3RTOs) [1]. This change
also affects server-side behavior, which we found undesirable. This
patchset changes defaults in a way to make them safe: hash rethink at the
client-side is disabled and enabled at the server-side upon each RTO
event or in case of duplicate acknowledgments.
This patchset provides two options to change default behaviour. The hash
rethink may be disabled at the server-side by the new sysctl option.
Changes in the sysctl option don't affect default behavior at the
client-side.
Hash rethink can also be enabled/disabled with socket option or bpf
syscalls which ovewrite both default and sysctl settings. This socket
option is available on both client and server-side. This should provide
mechanics to enable hash rethink inside administrative domain, such as DC,
where hash rethink at the client-side can be desirable.
[1] https://lore.kernel.org/netdev/20210809185314.38187-1-tom@herbertland.com/
v2:
- Changed sysctl default to ENABLED in all patches. Reduced sysctl
and socket option size to u8. Fixed netns bug reported by kernel
test robot.
Akhmat Karakotov (4):
txhash: Make rethinking txhash behavior configurable via sysctl
txhash: Add socket option to control TX hash rethink behavior
bpf: Add SO_TXREHASH setsockopt
tcp: change SYN ACK retransmit behaviour to account for rehash
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 | 2 ++
include/net/netns/core.h | 1 +
include/net/sock.h | 28 ++++++++++++++-------------
include/uapi/asm-generic/socket.h | 2 ++
include/uapi/linux/socket.h | 4 ++++
net/core/filter.c | 10 ++++++++++
net/core/net_namespace.c | 2 ++
net/core/sock.c | 13 +++++++++++++
net/core/sysctl_net_core.c | 15 ++++++++++++--
net/ipv4/inet_connection_sock.c | 3 +++
net/ipv4/tcp_output.c | 3 ++-
14 files changed, 73 insertions(+), 16 deletions(-)
--
2.17.1
@@ -4808,6 +4808,13 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,caseSO_REUSEPORT:sk->sk_reuseport=valbool;break;+caseSO_TXREHASH:+if(val<-1||val>1){+ret=-EINVAL;+break;+}+sk->sk_txrehash=val;+break;default:ret=-EINVAL;}
@@ -4980,6 +4987,9 @@ static int _bpf_getsockopt(struct sock *sk, int level, int optname,caseSO_REUSEPORT:*((int*)optval)=sk->sk_reuseport;break;+caseSO_TXREHASH:+*((int*)optval)=sk->sk_txrehash;+break;default:gotoerr_clear;}
@@ -1367,6 +1367,14 @@ int sock_setsockopt(struct socket *sock, int level, int optname,~SOCK_BUF_LOCK_MASK);break;+caseSO_TXREHASH:+if(val<-1||val>1){+ret=-EINVAL;+break;+}+sk->sk_txrehash=val;+break;+default:ret=-ENOPROTOOPT;break;
@@ -1733,6 +1741,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,v.val=sk->sk_userlocks&SOCK_BUF_LOCK_MASK;break;+caseSO_TXREHASH:+v.val=sk->sk_txrehash;+break;+default:/* We implement the SO_SNDLOWAT etc to not be settable*(1003.1g7).
@@ -1046,6 +1046,9 @@ int inet_csk_listen_start(struct sock *sk, int backlog)sk->sk_ack_backlog=0;inet_csk_delack_init(sk);+if(sk->sk_txrehash==SOCK_TXREHASH_DEFAULT)+sk->sk_txrehash=READ_ONCE(sock_net(sk)->core.sysctl_txrehash);+/* There is race window here: we announce ourselves listening,*butthistransitionisstillnotvalidatedbyget_port().*ItisOK,becausethissocketenterstohashtableonly
Disabling rehash behavior did not affect SYN ACK retransmits because hash
was forcefully changed bypassing the sk_rethink_hash function. This patch
adds a condition which checks for rehash mode before resetting hash.
Signed-off-by: Akhmat Karakotov <redacted>
---
net/ipv4/tcp_output.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Hi Eric,
I've sent v2 of the patch. I've removed confusing part with sysctl default values
and made other changes according to your comments. I look forward for your
review.
On Nov 12, 2021, at 21:19, Akhmat Karakotov [off-list ref] wrote:
As it was shown in the report by Alexander Azimov, hash rethink at the
client-side may lead to connection timeout toward stateful anycast
services. Tom Herbert created a patchset to address this issue by applying
hash rethink only after a negative routing event (3RTOs) [1]. This change
also affects server-side behavior, which we found undesirable. This
patchset changes defaults in a way to make them safe: hash rethink at the
client-side is disabled and enabled at the server-side upon each RTO
event or in case of duplicate acknowledgments.
This patchset provides two options to change default behaviour. The hash
rethink may be disabled at the server-side by the new sysctl option.
Changes in the sysctl option don't affect default behavior at the
client-side.
Hash rethink can also be enabled/disabled with socket option or bpf
syscalls which ovewrite both default and sysctl settings. This socket
option is available on both client and server-side. This should provide
mechanics to enable hash rethink inside administrative domain, such as DC,
where hash rethink at the client-side can be desirable.
[1] https://lore.kernel.org/netdev/20210809185314.38187-1-tom@herbertland.com/
v2:
- Changed sysctl default to ENABLED in all patches. Reduced sysctl
and socket option size to u8. Fixed netns bug reported by kernel
test robot.
Akhmat Karakotov (4):
txhash: Make rethinking txhash behavior configurable via sysctl
txhash: Add socket option to control TX hash rethink behavior
bpf: Add SO_TXREHASH setsockopt
tcp: change SYN ACK retransmit behaviour to account for rehash
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 | 2 ++
include/net/netns/core.h | 1 +
include/net/sock.h | 28 ++++++++++++++-------------
include/uapi/asm-generic/socket.h | 2 ++
include/uapi/linux/socket.h | 4 ++++
net/core/filter.c | 10 ++++++++++
net/core/net_namespace.c | 2 ++
net/core/sock.c | 13 +++++++++++++
net/core/sysctl_net_core.c | 15 ++++++++++++--
net/ipv4/inet_connection_sock.c | 3 +++
net/ipv4/tcp_output.c | 3 ++-
14 files changed, 73 insertions(+), 16 deletions(-)
--
2.17.1
Hi Eric,
I wonder if you have time to provide review regarding my last update to the patch.
On Nov 23, 2021, at 16:20, Akhmat Karakotov [off-list ref] wrote:
Hi Eric,
I've sent v2 of the patch. I've removed confusing part with sysctl default values
and made other changes according to your comments. I look forward for your
review.
quoted
On Nov 12, 2021, at 21:19, Akhmat Karakotov [off-list ref] wrote:
As it was shown in the report by Alexander Azimov, hash rethink at the
client-side may lead to connection timeout toward stateful anycast
services. Tom Herbert created a patchset to address this issue by applying
hash rethink only after a negative routing event (3RTOs) [1]. This change
also affects server-side behavior, which we found undesirable. This
patchset changes defaults in a way to make them safe: hash rethink at the
client-side is disabled and enabled at the server-side upon each RTO
event or in case of duplicate acknowledgments.
This patchset provides two options to change default behaviour. The hash
rethink may be disabled at the server-side by the new sysctl option.
Changes in the sysctl option don't affect default behavior at the
client-side.
Hash rethink can also be enabled/disabled with socket option or bpf
syscalls which ovewrite both default and sysctl settings. This socket
option is available on both client and server-side. This should provide
mechanics to enable hash rethink inside administrative domain, such as DC,
where hash rethink at the client-side can be desirable.
[1] https://lore.kernel.org/netdev/20210809185314.38187-1-tom@herbertland.com/
v2:
- Changed sysctl default to ENABLED in all patches. Reduced sysctl
and socket option size to u8. Fixed netns bug reported by kernel
test robot.
Akhmat Karakotov (4):
txhash: Make rethinking txhash behavior configurable via sysctl
txhash: Add socket option to control TX hash rethink behavior
bpf: Add SO_TXREHASH setsockopt
tcp: change SYN ACK retransmit behaviour to account for rehash
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 | 2 ++
include/net/netns/core.h | 1 +
include/net/sock.h | 28 ++++++++++++++-------------
include/uapi/asm-generic/socket.h | 2 ++
include/uapi/linux/socket.h | 4 ++++
net/core/filter.c | 10 ++++++++++
net/core/net_namespace.c | 2 ++
net/core/sock.c | 13 +++++++++++++
net/core/sysctl_net_core.c | 15 ++++++++++++--
net/ipv4/inet_connection_sock.c | 3 +++
net/ipv4/tcp_output.c | 3 ++-
14 files changed, 73 insertions(+), 16 deletions(-)
--
2.17.1
From: Eric Dumazet <hidden> Date: 2021-12-01 16:49:48
On 11/30/21 1:58 AM, Akhmat Karakotov wrote:
Hi Eric,
I wonder if you have time to provide review regarding my last update to the patch.
Sorry, your patches did not reach me. Can you resend them, adding
"Eric Dumazet [off-list ref]" address to make sure I can catch
them ?
Thanks !
quoted
On Nov 23, 2021, at 16:20, Akhmat Karakotov [off-list ref] wrote:
Hi Eric,
I've sent v2 of the patch. I've removed confusing part with sysctl default values
and made other changes according to your comments. I look forward for your
review.
quoted
On Nov 12, 2021, at 21:19, Akhmat Karakotov [off-list ref] wrote:
As it was shown in the report by Alexander Azimov, hash rethink at the
client-side may lead to connection timeout toward stateful anycast
services. Tom Herbert created a patchset to address this issue by applying
hash rethink only after a negative routing event (3RTOs) [1]. This change
also affects server-side behavior, which we found undesirable. This
patchset changes defaults in a way to make them safe: hash rethink at the
client-side is disabled and enabled at the server-side upon each RTO
event or in case of duplicate acknowledgments.
This patchset provides two options to change default behaviour. The hash
rethink may be disabled at the server-side by the new sysctl option.
Changes in the sysctl option don't affect default behavior at the
client-side.
Hash rethink can also be enabled/disabled with socket option or bpf
syscalls which ovewrite both default and sysctl settings. This socket
option is available on both client and server-side. This should provide
mechanics to enable hash rethink inside administrative domain, such as DC,
where hash rethink at the client-side can be desirable.
[1] https://lore.kernel.org/netdev/20210809185314.38187-1-tom@herbertland.com/
v2:
- Changed sysctl default to ENABLED in all patches. Reduced sysctl
and socket option size to u8. Fixed netns bug reported by kernel
test robot.
Akhmat Karakotov (4):
txhash: Make rethinking txhash behavior configurable via sysctl
txhash: Add socket option to control TX hash rethink behavior
bpf: Add SO_TXREHASH setsockopt
tcp: change SYN ACK retransmit behaviour to account for rehash
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 | 2 ++
include/net/netns/core.h | 1 +
include/net/sock.h | 28 ++++++++++++++-------------
include/uapi/asm-generic/socket.h | 2 ++
include/uapi/linux/socket.h | 4 ++++
net/core/filter.c | 10 ++++++++++
net/core/net_namespace.c | 2 ++
net/core/sock.c | 13 +++++++++++++
net/core/sysctl_net_core.c | 15 ++++++++++++--
net/ipv4/inet_connection_sock.c | 3 +++
net/ipv4/tcp_output.c | 3 ++-
14 files changed, 73 insertions(+), 16 deletions(-)
--
2.17.1
Sorry, your patches did not reach me. Can you resend them, adding
"Eric Dumazet [off-list ref]" address to make sure I can catch
them ?
Thanks !
Hi Eric,
Resending patch, as you asked. Hope it reaches you well.
---
As it was shown in the report by Alexander Azimov, hash rethink at the
client-side may lead to connection timeout toward stateful anycast
services. Tom Herbert created a patchset to address this issue by applying
hash rethink only after a negative routing event (3RTOs) [1]. This change
also affects server-side behavior, which we found undesirable. This
patchset changes defaults in a way to make them safe: hash rethink at the
client-side is disabled and enabled at the server-side upon each RTO
event or in case of duplicate acknowledgments.
This patchset provides two options to change default behaviour. The hash
rethink may be disabled at the server-side by the new sysctl option.
Changes in the sysctl option don't affect default behavior at the
client-side.
Hash rethink can also be enabled/disabled with socket option or bpf
syscalls which ovewrite both default and sysctl settings. This socket
option is available on both client and server-side. This should provide
mechanics to enable hash rethink inside administrative domain, such as DC,
where hash rethink at the client-side can be desirable.
[1] https://lore.kernel.org/netdev/20210809185314.38187-1-tom@herbertland.com/
v2:
- Changed sysctl default to ENABLED in all patches. Reduced sysctl
and socket option size to u8. Fixed netns bug reported by kernel
test robot.
Akhmat Karakotov (4):
txhash: Make rethinking txhash behavior configurable via sysctl
txhash: Add socket option to control TX hash rethink behavior
bpf: Add SO_TXREHASH setsockopt
tcp: change SYN ACK retransmit behaviour to account for rehash
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 | 2 ++
include/net/netns/core.h | 1 +
include/net/sock.h | 28 ++++++++++++++-------------
include/uapi/asm-generic/socket.h | 2 ++
include/uapi/linux/socket.h | 4 ++++
net/core/filter.c | 10 ++++++++++
net/core/net_namespace.c | 2 ++
net/core/sock.c | 13 +++++++++++++
net/core/sysctl_net_core.c | 15 ++++++++++++--
net/ipv4/inet_connection_sock.c | 3 +++
net/ipv4/tcp_output.c | 3 ++-
14 files changed, 73 insertions(+), 16 deletions(-)
--
2.17.1
@@ -1367,6 +1367,14 @@ int sock_setsockopt(struct socket *sock, int level, int optname,~SOCK_BUF_LOCK_MASK);break;+caseSO_TXREHASH:+if(val<-1||val>1){+ret=-EINVAL;+break;+}+sk->sk_txrehash=val;+break;+default:ret=-ENOPROTOOPT;break;
@@ -1733,6 +1741,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,v.val=sk->sk_userlocks&SOCK_BUF_LOCK_MASK;break;+caseSO_TXREHASH:+v.val=sk->sk_txrehash;+break;+default:/* We implement the SO_SNDLOWAT etc to not be settable*(1003.1g7).
@@ -1046,6 +1046,9 @@ int inet_csk_listen_start(struct sock *sk, int backlog)sk->sk_ack_backlog=0;inet_csk_delack_init(sk);+if(sk->sk_txrehash==SOCK_TXREHASH_DEFAULT)+sk->sk_txrehash=READ_ONCE(sock_net(sk)->core.sysctl_txrehash);+/* There is race window here: we announce ourselves listening,*butthistransitionisstillnotvalidatedbyget_port().*ItisOK,becausethissocketenterstohashtableonly
@@ -4808,6 +4808,13 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,caseSO_REUSEPORT:sk->sk_reuseport=valbool;break;+caseSO_TXREHASH:+if(val<-1||val>1){+ret=-EINVAL;+break;+}+sk->sk_txrehash=val;+break;default:ret=-EINVAL;}
@@ -4980,6 +4987,9 @@ static int _bpf_getsockopt(struct sock *sk, int level, int optname,caseSO_REUSEPORT:*((int*)optval)=sk->sk_reuseport;break;+caseSO_TXREHASH:+*((int*)optval)=sk->sk_txrehash;+break;default:gotoerr_clear;}
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 <redacted>
---
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 | 15 +++++++++++++--
5 files changed, 40 insertions(+), 15 deletions(-)
@@ -618,7 +627,9 @@ static __net_init int sysctl_core_net_init(struct net *net)if(tbl==NULL)gotoerr_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){
Disabling rehash behavior did not affect SYN ACK retransmits because hash
was forcefully changed bypassing the sk_rethink_hash function. This patch
adds a condition which checks for rehash mode before resetting hash.
Signed-off-by: Akhmat Karakotov <redacted>
---
net/ipv4/tcp_output.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
@@ -1367,6 +1367,14 @@ int sock_setsockopt(struct socket *sock, int level, int optname,~SOCK_BUF_LOCK_MASK);break;+caseSO_TXREHASH:+if(val<-1||val>1){+ret=-EINVAL;+break;+}+sk->sk_txrehash=val;+break;+default:ret=-ENOPROTOOPT;break;
@@ -1733,6 +1741,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,v.val=sk->sk_userlocks&SOCK_BUF_LOCK_MASK;break;+caseSO_TXREHASH:+v.val=sk->sk_txrehash;+break;+default:/* We implement the SO_SNDLOWAT etc to not be settable*(1003.1g7).
@@ -1046,6 +1046,9 @@ int inet_csk_listen_start(struct sock *sk, int backlog)sk->sk_ack_backlog=0;inet_csk_delack_init(sk);+if(sk->sk_txrehash==SOCK_TXREHASH_DEFAULT)+sk->sk_txrehash=READ_ONCE(sock_net(sk)->core.sysctl_txrehash);+/* There is race window here: we announce ourselves listening,*butthistransitionisstillnotvalidatedbyget_port().*ItisOK,becausethissocketenterstohashtableonly--
From: Eric Dumazet <edumazet@google.com> Date: 2021-12-02 17:24:24
On Thu, Dec 2, 2021 at 8:41 AM Akhmat Karakotov [off-list ref] wrote:
quoted hunk
Disabling rehash behavior did not affect SYN ACK retransmits because hash
was forcefully changed bypassing the sk_rethink_hash function. This patch
adds a condition which checks for rehash mode before resetting hash.
Signed-off-by: Akhmat Karakotov <redacted>
---
net/ipv4/tcp_output.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Since you add a new sk->sk_txrehash, you probably want to add
READ_ONCE()/WRITE_ONCE() over the reads/writes,
because at this point the listener socket lock is not held.
/* Paired with WRITE_ONCE() in sock_setsockopt() */
if (READ_ONCE(sk->sk_txrehash) == SOCK_TXREHASH_ENABLED)
sock_setsockopt() would need a similar comment
/* Paired with READ_ONCE() in tcp_rtx_synack() */
WRITE_ONCE(sk->sk_txrehash, val);
+ tcp_rsk(req)->txhash = net_tx_rndhash();
res = af_ops->send_synack(sk, NULL, &fl, req, NULL, TCP_SYNACK_NORMAL,
NULL);
if (!res) {
--
2.17.1
@@ -4808,6 +4808,13 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,caseSO_REUSEPORT:sk->sk_reuseport=valbool;break;+caseSO_TXREHASH:+if(val<-1||val>1){+ret=-EINVAL;+break;+}+sk->sk_txrehash=(u8)val;+break;default:ret=-EINVAL;}
@@ -4980,6 +4987,9 @@ static int _bpf_getsockopt(struct sock *sk, int level, int optname,caseSO_REUSEPORT:*((int*)optval)=sk->sk_reuseport;break;+caseSO_TXREHASH:+*((int*)optval)=sk->sk_txrehash;+break;default:gotoerr_clear;}
@@ -1367,6 +1367,14 @@ int sock_setsockopt(struct socket *sock, int level, int optname,~SOCK_BUF_LOCK_MASK);break;+caseSO_TXREHASH:+if(val<-1||val>1){+ret=-EINVAL;+break;+}+sk->sk_txrehash=(u8)val;+break;+default:ret=-ENOPROTOOPT;break;
@@ -1733,6 +1741,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,v.val=sk->sk_userlocks&SOCK_BUF_LOCK_MASK;break;+caseSO_TXREHASH:+v.val=sk->sk_txrehash;+break;+default:/* We implement the SO_SNDLOWAT etc to not be settable*(1003.1g7).
@@ -1046,6 +1046,9 @@ int inet_csk_listen_start(struct sock *sk, int backlog)sk->sk_ack_backlog=0;inet_csk_delack_init(sk);+if(sk->sk_txrehash==SOCK_TXREHASH_DEFAULT)+sk->sk_txrehash=READ_ONCE(sock_net(sk)->core.sysctl_txrehash);+/* There is race window here: we announce ourselves listening,*butthistransitionisstillnotvalidatedbyget_port().*ItisOK,becausethissocketenterstohashtableonly
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 <redacted>
---
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(-)
@@ -618,7 +627,8 @@ static __net_init int sysctl_core_net_init(struct net *net)if(tbl==NULL)gotoerr_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){
As it was shown in the report by Alexander Azimov, hash rethink at the
client-side may lead to connection timeout toward stateful anycast
services. Tom Herbert created a patchset to address this issue by applying
hash rethink only after a negative routing event (3RTOs) [1]. This change
also affects server-side behavior, which we found undesirable. This
patchset changes defaults in a way to make them safe: hash rethink at the
client-side is disabled and enabled at the server-side upon each RTO
event or in case of duplicate acknowledgments.
This patchset provides two options to change default behaviour. The hash
rethink may be disabled at the server-side by the new sysctl option.
Changes in the sysctl option don't affect default behavior at the
client-side.
Hash rethink can also be enabled/disabled with socket option or bpf
syscalls which ovewrite both default and sysctl settings. This socket
option is available on both client and server-side. This should provide
mechanics to enable hash rethink inside administrative domain, such as DC,
where hash rethink at the client-side can be desirable.
[1] https://lore.kernel.org/netdev/20210809185314.38187-1-tom@herbertland.com/
v2:
- Changed sysctl default to ENABLED in all patches. Reduced sysctl
and socket option size to u8. Fixed netns bug reported by kernel
test robot.
v3:
- Fixed bug with bad u8 comparison. Moved sk->txrehash to use less
bytes in struct. Added WRITE_ONCE() in setsockopt in and
READ_ONCE() in tcp_rtx_synack.
Akhmat Karakotov (4):
txhash: Make rethinking txhash behavior configurable via sysctl
txhash: Add socket option to control TX hash rethink behavior
bpf: Add SO_TXREHASH setsockopt
tcp: change SYN ACK retransmit behaviour to account for rehash
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 | 2 ++
include/net/netns/core.h | 1 +
include/net/sock.h | 28 ++++++++++++++-------------
include/uapi/asm-generic/socket.h | 2 ++
include/uapi/linux/socket.h | 4 ++++
net/core/filter.c | 10 ++++++++++
net/core/net_namespace.c | 2 ++
net/core/sock.c | 14 ++++++++++++++
net/core/sysctl_net_core.c | 14 ++++++++++++--
net/ipv4/inet_connection_sock.c | 3 +++
net/ipv4/tcp_output.c | 4 +++-
14 files changed, 74 insertions(+), 16 deletions(-)
--
2.17.1
Disabling rehash behavior did not affect SYN ACK retransmits because hash
was forcefully changed bypassing the sk_rethink_hash function. This patch
adds a condition which checks for rehash mode before resetting hash.
Signed-off-by: Akhmat Karakotov <redacted>
---
net/core/sock.c | 3 ++-
net/ipv4/tcp_output.c | 4 +++-
2 files changed, 5 insertions(+), 2 deletions(-)
@@ -1372,7 +1372,8 @@ int sock_setsockopt(struct socket *sock, int level, int optname,ret=-EINVAL;break;}-sk->sk_txrehash=(u8)val;+/* Paired with READ_ONCE() in tcp_rtx_synack() */+WRITE_ONCE(sk->sk_txrehash,(u8)val);break;default:
From: Eric Dumazet <edumazet@google.com> Date: 2021-12-06 19:47:28
On Mon, Dec 6, 2021 at 11:11 AM Akhmat Karakotov [off-list ref] wrote:
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 <redacted>
---
From: Eric Dumazet <edumazet@google.com> Date: 2021-12-06 19:48:20
On Mon, Dec 6, 2021 at 11:11 AM Akhmat Karakotov [off-list ref] wrote:
Add the SO_TXREHASH socket option to control hash rethink behavior per socket.
When default mode is set, sockets disable rehash at initialization and use
sysctl option when entering listen state. setsockopt() overrides default
behavior.
Signed-off-by: Akhmat Karakotov <redacted>
---
From: Eric Dumazet <edumazet@google.com> Date: 2021-12-06 19:49:52
On Mon, Dec 6, 2021 at 11:11 AM Akhmat Karakotov [off-list ref] wrote:
Disabling rehash behavior did not affect SYN ACK retransmits because hash
was forcefully changed bypassing the sk_rethink_hash function. This patch
adds a condition which checks for rehash mode before resetting hash.
Signed-off-by: Akhmat Karakotov <redacted>
---
Dear David, We got the patch reviewed couple of weeks ago, please let us know what further steps are required before merge. Thanks, Akhmat.
quoted hunk
On Dec 6, 2021, at 22:11, Akhmat Karakotov [off-list ref] wrote:
Disabling rehash behavior did not affect SYN ACK retransmits because hash
was forcefully changed bypassing the sk_rethink_hash function. This patch
adds a condition which checks for rehash mode before resetting hash.
Signed-off-by: Akhmat Karakotov <redacted>
---
net/core/sock.c | 3 ++-
net/ipv4/tcp_output.c | 4 +++-
2 files changed, 5 insertions(+), 2 deletions(-)
From: Jakub Kicinski <kuba@kernel.org> Date: 2022-01-18 16:03:55
On Mon, 17 Jan 2022 18:31:37 +0300 Akhmat Karakotov wrote:
We got the patch reviewed couple of weeks ago, please let us know what
further steps are required before merge. Thanks, Akhmat.
We rarely merge RFC patchsets these days, you need to repost without
the RFC marking. Obviously keeping Eric's Acks. You should also CC
the bpf list & maintainers on patch 3. Please repost next week, the
merge window is still ongoing and net-next is closed for another few
days:
http://vger.kernel.org/~davem/net-next.html
On Jan 18, 2022, at 19:03, Jakub Kicinski [off-list ref] wrote:
On Mon, 17 Jan 2022 18:31:37 +0300 Akhmat Karakotov wrote:
quoted
We got the patch reviewed couple of weeks ago, please let us know what
further steps are required before merge. Thanks, Akhmat.
We rarely merge RFC patchsets these days, you need to repost without
the RFC marking. Obviously keeping Eric's Acks. You should also CC
the bpf list & maintainers on patch 3. Please repost next week, the
merge window is still ongoing and net-next is closed for another few
days:
http://vger.kernel.org/~davem/net-next.html
Thanks for answer, Jakub! I'll resend it next week.