net/smc: avoid overwriting when adjusting sock bufsizes
Wen Gu
reviewerPATCH 1/1 net/smc: avoid overwriting when adjusting sock bufsizes
When copying smc settings to clcsock, avoid setting clcsock's sk_sndbuf to sysctl_tcp_wmem[1], since this may overwrite the value set by tcp_sndbuf_expand() in TCP connection establishment.
And the other setting sk_{snd|rcv}buf to sysctl value in smc_adjust_sock_bufsizes() can also be omitted since the initialization of smc sock and clcsock has set sk_{snd|rcv}buf to smc.sysctl_{w|r}mem or ipv4_sysctl_tcp_{w|r}mem[1].
---
FYI,
The detailed motivation and testing can be found in the link above.
--- net/smc/af_smc.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-)
net/smc/af_smc.c +2 -20
@@ -459,29 +459,11 @@ static int smc_bind(struct socket *sock, struct sockaddr *uaddr,static void smc_adjust_sock_bufsizes (struct sock *nsk,struct sock *osk,unsigned long mask) { -struct net *nnet =sock_net (nsk); - nsk->sk_userlocks = osk->sk_userlocks; -if (osk->sk_userlocks &SOCK_SNDBUF_LOCK ) { +if (osk->sk_userlocks &SOCK_SNDBUF_LOCK ) nsk->sk_sndbuf = osk->sk_sndbuf; - }else { -if (mask ==SK_FLAGS_SMC_TO_CLC ) -WRITE_ONCE (nsk->sk_sndbuf, -READ_ONCE (nnet->ipv4.sysctl_tcp_wmem[1 ])); -else -WRITE_ONCE (nsk->sk_sndbuf, -2 *READ_ONCE (nnet->smc.sysctl_wmem)); - } -if (osk->sk_userlocks &SOCK_RCVBUF_LOCK ) { +if (osk->sk_userlocks &SOCK_RCVBUF_LOCK ) nsk->sk_rcvbuf = osk->sk_rcvbuf; - }else { -if (mask ==SK_FLAGS_SMC_TO_CLC ) -WRITE_ONCE (nsk->sk_rcvbuf, -READ_ONCE (nnet->ipv4.sysctl_tcp_rmem[1 ])); -else -WRITE_ONCE (nsk->sk_rcvbuf, -2 *READ_ONCE (nnet->smc.sysctl_rmem)); - } } static void smc_copy_sock_settings(struct sock *nsk, struct sock *osk,
Signature · 1 line
2.32.0.3.g01195cf9f
Paolo Abeni
maintainerQuoted 9 lines · Wen Gu
When copying smc settings to clcsock, avoid setting clcsock's
sk_sndbufto sysctl_tcp_wmem[1], since this may overwrite the value set bytcp_sndbuf_expand()in TCP connection establishment.And the other setting sk_{snd|rcv}buf to sysctl value in
smc_adjust_sock_bufsizes()can also be omitted since the initialization of smc sock and clcsock has set sk_{snd|rcv}buf to smc.sysctl_{w|r}mem or ipv4_sysctl_tcp_{w|r}mem[1].
Quoted 6 lines
Fixes 30c3c4a4497c ("net/smc: Use correct buffer sizes when switching between TCP and SMC")Signed-off-by Wen Gu <[email protected]>---
FYI,
The detailed motivation and testing can be found in the link above.
My understanding is that there is an open question here if this is the expected and desired behavior.
@Wenjia, @Jan: could you please have a look?
Thanks!
Paolo
Wenjia Zhang
Reviewed-byQuoted 20 lines · Paolo Abeni
Quoted 9 lines · Wen Gu
When copying smc settings to clcsock, avoid setting clcsock's
sk_sndbufto sysctl_tcp_wmem[1], since this may overwrite the value set bytcp_sndbuf_expand()in TCP connection establishment.And the other setting sk_{snd|rcv}buf to sysctl value in
smc_adjust_sock_bufsizes()can also be omitted since the initialization of smc sock and clcsock has set sk_{snd|rcv}buf to smc.sysctl_{w|r}mem or ipv4_sysctl_tcp_{w|r}mem[1].Quoted 6 lines
Fixes 30c3c4a4497c ("net/smc: Use correct buffer sizes when switching between TCP and SMC")Signed-off-by Wen Gu <[email protected]>---
FYI,
The detailed motivation and testing can be found in the link above.My understanding is that there is an open question here if this is the expected and desired behavior.
Quoted 7 lines
@Wenjia, @Jan: could you please have a look?
Thanks!
Paolo
@Paolo, thank you for reminding us!
@Wen, Gerd and I have looked into your patch and discussed on it. Gerd would send the concrete answer to your question soon.
Regarding to this patch, it looks good to me. Here you are:
Thanks,
Wenjia
Hi Wen Gu,
sorry for the late reply, I'm just catching up after a bit of a vacation.
Quoted 60 lines · Wen Gu
When copying smc settings to clcsock, avoid setting clcsock's
sk_sndbufto sysctl_tcp_wmem[1], since this may overwrite the value set bytcp_sndbuf_expand()in TCP connection establishment.And the other setting sk_{snd|rcv}buf to sysctl value in
smc_adjust_sock_bufsizes()can also be omitted since the initialization of smc sock and clcsock has set sk_{snd|rcv}buf to smc.sysctl_{w|r}mem or ipv4_sysctl_tcp_{w|r}mem[1].Fixes 30c3c4a4497c ("net/smc: Use correct buffer sizes whenswitching between TCP and SMC")
Link:
https://lore.kernel.org/r/[email protected]Signed-off-by Wen Gu <[email protected]>---
FYI,
The detailed motivation and testing can be found in the link above.
---
net/smc/af_smc.c | 22 ++--------------------1 file changed, 2 insertions(+), 20 deletions(-)net/smc/af_smc.c +0
-0@@ -459,29 +459,11 @@ static int smc_bind(struct socket *sock, struct sockaddr *uaddr,static void smc_adjust_sock_bufsizes(struct sock *nsk, struct sock *osk,
unsigned long mask) {net/smc/af_smc.c +0
-2-struct net *nnet =sock_net (nsk); -
nsk->sk_userlocks=osk->sk_userlocks;net/smc/af_smc.c +1
-1-if (osk->sk_userlocks &SOCK_SNDBUF_LOCK ) { +if (osk->sk_userlocks &SOCK_SNDBUF_LOCK )
nsk->sk_sndbuf=osk->sk_sndbuf;net/smc/af_smc.c +0
-4- }else { -if (mask ==SK_FLAGS_SMC_TO_CLC ) - WRITE_ONCE(nsk->sk_sndbuf, - READ_ONCE(nnet-Quoted 1 line
ipv4.sysctl_tcp_wmem[1]));
net/smc/af_smc.c +0
-3- else - WRITE_ONCE(nsk->sk_sndbuf, - 2 * READ_ONCE(nnet-Quoted 1 line
smc.sysctl_wmem));
net/smc/af_smc.c +1
-2- } -if (osk->sk_userlocks &SOCK_RCVBUF_LOCK ) { +if (osk->sk_userlocks &SOCK_RCVBUF_LOCK )
nsk->sk_rcvbuf=osk->sk_rcvbuf;net/smc/af_smc.c +0
-4- }else { -if (mask ==SK_FLAGS_SMC_TO_CLC ) - WRITE_ONCE(nsk->sk_rcvbuf, - READ_ONCE(nnet-Quoted 1 line
ipv4.sysctl_tcp_rmem[1]));
net/smc/af_smc.c +0
-3- else - WRITE_ONCE(nsk->sk_rcvbuf, - 2 * READ_ONCE(nnet-Quoted 1 line
smc.sysctl_rmem));
net/smc/af_smc.c +0
-1- }
Quoted 4 lines
}
static void smc_copy_sock_settings(struct sock *nsk, struct sock *osk,
As Wenjia already said, we've discussed this a bit.
As I remember, I've added the sections to copy over the sysctl values as a "safety measure" when moving between smc/clc sockets - but had the wrong assumption in mind that e.g. in a fall-back a new TCP handshake would be done. Apparently, we didn't test the buffer size behavior in these scenarios enough to notice the "weird" behavior.
So we reviewed your initial report of the oddity per your message in the link above, too.
We fully agree that if no connection at the SMC level could be established, you should expect the socket buffersizes be used that had been established for the TCP connection - regardless if the fallback is due to the server or the client.
So feel free to add my
Thanks,
Gerd
Wen Gu
reviewerQuoted 4 lines · Gerd Bayer
Hi Wen Gu,
sorry for the late reply, I'm just catching up after a bit of a vacation.
No worries at all, I hope you had a great vacation!
Quoted 20 lines · Wen Gu
Quoted 18 lines
When copying smc settings to clcsock, avoid setting clcsock's
sk_sndbufto sysctl_tcp_wmem[1], since this may overwrite the value set bytcp_sndbuf_expand()in TCP connection establishment.And the other setting sk_{snd|rcv}buf to sysctl value in
smc_adjust_sock_bufsizes()can also be omitted since the initialization of smc sock and clcsock has set sk_{snd|rcv}buf to smc.sysctl_{w|r}mem or ipv4_sysctl_tcp_{w|r}mem[1].Fixes 30c3c4a4497c ("net/smc: Use correct buffer sizes whenswitching between TCP and SMC")
Link:
https://lore.kernel.org/r/[email protected]Signed-off-by Wen Gu <[email protected]>---
FYI,
The detailed motivation and testing can be found in the link above.
---
<...>
Quoted 11 lines
As Wenjia already said, we've discussed this a bit.
As I remember, I've added the sections to copy over the sysctl values as a "safety measure" when moving between smc/clc sockets - but had the wrong assumption in mind that e.g. in a fall-back a new TCP handshake would be done. Apparently, we didn't test the buffer size behavior in these scenarios enough to notice the "weird" behavior.So we reviewed your initial report of the oddity per your message in the link above, too.
Quoted 8 lines
We fully agree that if no connection at the SMC level could be established, you should expect the socket buffersizes be used that had been established for the TCP connection - regardless if the fallback is due to the server or the client.
So feel free to add my
Reviewed-by Gerd Bayer <[email protected]>, too.
Hi, Gerd and Wenjia. Thanks a lot for your confirmation.
And as for the last question in the initial report (link above), that why the server does not call smc_copy_sock_settings_to_clc() like the client when fallback happens, I guess it is because at the time that server fallback, the new_smc sock has not been accepted, so there will be no user's sock settings that needs to be copied to clcsock.
Thanks!
Quoted 2 lines
Thanks,
Gerd
This patch was applied to netdev/net.git (main) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:
Quoted 10 lines · On Fri, 31 May 2024 16:54:17 +0800 you wrote:
When copying smc settings to clcsock, avoid setting clcsock's
sk_sndbufto sysctl_tcp_wmem[1], since this may overwrite the value set bytcp_sndbuf_expand()in TCP connection establishment.And the other setting sk_{snd|rcv}buf to sysctl value in
smc_adjust_sock_bufsizes()can also be omitted since the initialization of smc sock and clcsock has set sk_{snd|rcv}buf to smc.sysctl_{w|r}mem or ipv4_sysctl_tcp_{w|r}mem[1].[...]
Here is the summary with links:
- [net] net/smc: avoid overwriting when adjusting sock bufsizes
https://git.kernel.org/netdev/net/c/fb0aa0781a5f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html