From: Jason Xing <kerneljasonxing@gmail.com>
To: sunyiqi <sunyiqixm@gmail.com>
Cc: edumazet@google.com, davem@davemloft.net, dsahern@kernel.org,
kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: remove release/lock_sock in tcp_splice_read
Date: Thu, 15 Aug 2024 18:48:16 +0800 [thread overview]
Message-ID: <CAL+tcoBoe+YA12ZEn+-R2r4YYR3by1VsnN6GGmQoAtOPiej+BA@mail.gmail.com> (raw)
In-Reply-To: <20240815084330.166987-1-sunyiqixm@gmail.com>
On Thu, Aug 15, 2024 at 5:46 PM sunyiqi <sunyiqixm@gmail.com> wrote:
>
> When enters tcp_splice_read, tcp_splice_read will call lock_sock
> for sk in order to prevent other threads acquiring sk and release it
> before return.
>
> But in while(tss.len) loop, it releases and re-locks sk, give the other
> thread a small window to lock the sk.
>
> As a result, release/lock_sock in the while loop in tcp_splice_read may
> cause race condition.
>
> Fixes: 9c55e01c0cc8 ("[TCP]: Splice receive support.")
> Signed-off-by: sunyiqi <sunyiqixm@gmail.com>
It's more of an optimization instead of a BUG, no?
I don't consider it as a bug, unless you can prove it... Let me ask
what kind of race issues could re-lock cause?
I think holding the socket lock too long is not a good idea because
releasing the lock can give others breathing (having the chance to
finish their own stuff). Please see release_sock().
Thanks,
Jason
> ---
> net/ipv4/tcp.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index e03a342c9162..7a2ce0e2e5be 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -856,8 +856,6 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
>
> if (!tss.len || !timeo)
> break;
> - release_sock(sk);
> - lock_sock(sk);
>
> if (sk->sk_err || sk->sk_state == TCP_CLOSE ||
> (sk->sk_shutdown & RCV_SHUTDOWN) ||
> --
> 2.34.1
>
>
prev parent reply other threads:[~2024-08-15 10:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-15 8:43 sunyiqi
2024-08-15 10:00 ` Paolo Abeni
2024-08-15 10:55 ` Jason Xing
2024-08-15 11:22 ` Paolo Abeni
2024-08-15 11:34 ` Jason Xing
2024-08-15 10:48 ` Jason Xing [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAL+tcoBoe+YA12ZEn+-R2r4YYR3by1VsnN6GGmQoAtOPiej+BA@mail.gmail.com \
--to=kerneljasonxing@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sunyiqixm@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®