lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 23 Jun 2023 16:03:46 +0100
From: Pavel Begunkov <asml.silence@...il.com>
To: Eric Dumazet <edumazet@...gle.com>
Cc: netdev@...r.kernel.org, davem@...emloft.net, dsahern@...nel.org,
 pabeni@...hat.com, kuba@...nel.org
Subject: Re: [PATCH net-next v2] net/tcp: optimise locking for blocking splice

On 6/23/23 15:17, Eric Dumazet wrote:
> On Fri, Jun 23, 2023 at 2:40 PM Pavel Begunkov <asml.silence@...il.com> wrote:
>>
>> Even when tcp_splice_read() reads all it was asked for, for blocking
>> sockets it'll release and immediately regrab the socket lock, loop
>> around and break on the while check.
>>
>> Check tss.len right after we adjust it, and return if we're done.
>> That saves us one release_sock(); lock_sock(); pair per successful
>> blocking splice read.
>>
>> Signed-off-by: Pavel Begunkov <asml.silence@...il.com>
>> ---
>>
>> v2: go with Paolo's suggestion
>>      aggressively shrink the patch
>>
>>   net/ipv4/tcp.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
>> index 71b42eef9dbf..d56edc2c885f 100644
>> --- a/net/ipv4/tcp.c
>> +++ b/net/ipv4/tcp.c
>> @@ -839,7 +839,7 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
>>                  tss.len -= ret;
>>                  spliced += ret;
>>
>> -               if (!timeo)
>> +               if (!tss.len || !timeo)
>>                          break;
>>                  release_sock(sk);
>>                  lock_sock(sk);
> 
> SGTM, thanks.
> 
> Reviewed-by: Eric Dumazet <edumazet@...gle.com>
> 
> I wonder if the "release_sock();sock_lock();"  could be replaced by
> sk_flush_backlog() anyway ?
> Or is there any other reason for this dance ?

Now as you mentioned, it definitely sounds like that. And the code
is 15 years old, perhaps nobody was paying attention.


> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 71b42eef9dbf527098963bc03deecf55042e2021..d03d38060944d63d2728a7bf90a5c117b7852d8b
> 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -841,8 +841,7 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
> 
>                  if (!timeo)
>                          break;
> -               release_sock(sk);
> -               lock_sock(sk);
> +               sk_flush_backlog();
> 
>                  if (sk->sk_err || sk->sk_state == TCP_CLOSE ||
>                      (sk->sk_shutdown & RCV_SHUTDOWN) ||

-- 
Pavel Begunkov

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ