diff mbox series

[net] net/smc: avoid overwriting when adjusting sock bufsizes

Message ID 20240531085417.43104-1-guwen@linux.alibaba.com (mailing list archive)
State Accepted
Commit fb0aa0781a5f457e3864da68af52c3b1f4f7fd8f
Delegated to: Netdev Maintainers
Headers show
Series [net] net/smc: avoid overwriting when adjusting sock bufsizes | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 902 this patch: 902
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 11 of 11 maintainers
netdev/build_clang success Errors and warnings before: 906 this patch: 906
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 906 this patch: 906
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 31 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-06-04--18-00 (tests: 1045)

Commit Message

Wen Gu May 31, 2024, 8:54 a.m. UTC
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].

Fixes: 30c3c4a4497c ("net/smc: Use correct buffer sizes when switching between TCP and SMC")
Link: https://lore.kernel.org/r/5eaf3858-e7fd-4db8-83e8-3d7a3e0e9ae2@linux.alibaba.com
Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
---
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(-)

Comments

Paolo Abeni June 4, 2024, 2:04 p.m. UTC | #1
On Fri, 2024-05-31 at 16:54 +0800, Wen Gu wrote:
> 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].
> 
> Fixes: 30c3c4a4497c ("net/smc: Use correct buffer sizes when switching between TCP and SMC")
> Link: https://lore.kernel.org/r/5eaf3858-e7fd-4db8-83e8-3d7a3e0e9ae2@linux.alibaba.com
> Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
> ---
> 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 June 4, 2024, 3:10 p.m. UTC | #2
On 04.06.24 16:04, Paolo Abeni wrote:
> On Fri, 2024-05-31 at 16:54 +0800, Wen Gu wrote:
>> 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].
>>
>> Fixes: 30c3c4a4497c ("net/smc: Use correct buffer sizes when switching between TCP and SMC")
>> Link: https://lore.kernel.org/r/5eaf3858-e7fd-4db8-83e8-3d7a3e0e9ae2@linux.alibaba.com
>> Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
>> ---
>> 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
> 
> @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:

Reviewed-by: Wenjia Zhang <wenjia@linux.ibm.com>

Thanks,
Wenjia
Gerd Bayer June 4, 2024, 4:16 p.m. UTC | #3
Hi Wen Gu,

sorry for the late reply, I'm just catching up after a bit of a
vacation.

On Fri, 2024-05-31 at 16:54 +0800, Wen Gu wrote:
> 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].
> 
> Fixes: 30c3c4a4497c ("net/smc: Use correct buffer sizes when
> switching between TCP and SMC")
> Link:
> https://lore.kernel.org/r/5eaf3858-e7fd-4db8-83e8-3d7a3e0e9ae2@linux.alibaba.com
> Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
> ---
> 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(-)
> 
> diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
> index 9389f0cfa374..a35281153067 100644
> --- a/net/smc/af_smc.c
> +++ b/net/smc/af_smc.c
> @@ -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,

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
Reviewed-by: Gerd Bayer <gbayer@linux.ibm.com>, too.

Thanks,
Gerd
Wen Gu June 5, 2024, 6:01 a.m. UTC | #4
On 2024/6/5 00:16, Gerd Bayer wrote:
> 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!

> 
> On Fri, 2024-05-31 at 16:54 +0800, Wen Gu wrote:
>> 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].
>>
>> Fixes: 30c3c4a4497c ("net/smc: Use correct buffer sizes when
>> switching between TCP and SMC")
>> Link:
>> https://lore.kernel.org/r/5eaf3858-e7fd-4db8-83e8-3d7a3e0e9ae2@linux.alibaba.com
>> Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
>> ---
>> FYI,
>> The detailed motivation and testing can be found in the link above.
>> ---

<...>

> 
> 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
> Reviewed-by: Gerd Bayer <gbayer@linux.ibm.com>, 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!

> Thanks,
> Gerd
patchwork-bot+netdevbpf@kernel.org June 5, 2024, 8:50 a.m. UTC | #5
Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

On Fri, 31 May 2024 16:54:17 +0800 you wrote:
> 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].
> 
> [...]

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!
diff mbox series

Patch

diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 9389f0cfa374..a35281153067 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -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,