From: Leon Hwang <leon.hwang@linux.dev>
To: Eric Dumazet <edumazet@google.com>
Cc: netdev@vger.kernel.org, "David S . Miller" <davem@davemloft.net>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Neal Cardwell" <ncardwell@google.com>,
"Kuniyuki Iwashima" <kuniyu@google.com>,
"Ido Schimmel" <idosch@nvidia.com>,
"Ilpo Järvinen" <ij@kernel.org>,
"Chia-Yu Chang" <chia-yu.chang@nokia-bell-labs.com>,
"Yung Chih Su" <yuuchihsu@gmail.com>,
"Wyatt Feng" <bronzed_45_vested@icloud.com>,
"Jason Xing" <kerneljasonxing@gmail.com>,
"Lance Yang" <lance.yang@linux.dev>,
"Jiayuan Chen" <jiayuan.chen@linux.dev>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [RFC PATCH net-next v2 1/2] tcp: Add net.ipv4.tcp_purge_receive_queue sysctl
Date: Wed, 15 Jul 2026 23:25:51 +0800 [thread overview]
Message-ID: <2dc3d52b-ce4a-411d-9c30-934318ee98b0@linux.dev> (raw)
In-Reply-To: <CANn89iLyeAPNV2VHTM3w0-zpzjZNFy3aJDsVUERYyniLN4ub7A@mail.gmail.com>
On 2026/7/15 23:15, Eric Dumazet wrote:
> On Wed, Jul 15, 2026 at 4:54 PM Leon Hwang <leon.hwang@linux.dev> wrote:
[...]
>> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
>> index 61045a8886e4..4f1027173e95 100644
>> --- a/net/ipv4/tcp_input.c
>> +++ b/net/ipv4/tcp_input.c
>> @@ -4853,6 +4853,7 @@ void tcp_done_with_error(struct sock *sk, int err)
>> /* When we get a reset we do this. */
>> void tcp_reset(struct sock *sk, struct sk_buff *skb)
>> {
>> + const struct net *net = sock_net(sk);
>> int err;
>>
>> trace_tcp_receive_reset(sk);
>> @@ -4869,6 +4870,27 @@ void tcp_reset(struct sock *sk, struct sk_buff *skb)
>> err = ECONNREFUSED;
>> break;
>> case TCP_CLOSE_WAIT:
>> + /* RFC9293 3.10.7.4. Other States
>> + * Second, check the RST bit:
>> + * CLOSE-WAIT STATE
>> + *
>> + * If the RST bit is set, then any outstanding RECEIVEs and
>> + * SEND should receive "reset" responses. All segment queues
>> + * should be flushed. Users should also receive an unsolicited
>> + * general "connection reset" signal. Enter the CLOSED state,
>> + * delete the TCB, and return.
>> + *
>> + * If net.ipv4.tcp_purge_receive_queue is enabled,
>> + * sk_receive_queue will be flushed too.
>> + */
>> + if (unlikely(READ_ONCE(net->ipv4.sysctl_tcp_purge_receive_queue))) {
>> + struct tcp_sock *tp = tcp_sk(sk);
>> +
>> + skb_queue_purge(&sk->sk_receive_queue);
>> + WRITE_ONCE(tp->copied_seq, tp->rcv_nxt);
>> + WRITE_ONCE(tp->urg_data, 0);
>> + sk_set_peek_off(sk, -1);
>> + }
>> err = EPIPE;
>> break;
>> case TCP_CLOSE:
>> --
>> 2.55.0
>>
>
> My thoughts are:
>
> out_of_order_queue has been forgotten. skbs could be there and still
> 'block devmem'
>
> WRITE_ONCE(tp->copied_seq, tp->rcv_nxt) is certainly wrong, because
> read() will return 0, instead of -1 (errno = EPIPE or ECONNRESET)
> So the application will not know a RST was received :/
>
> I think that BSD and linux implementations have historically retained
> acknowledged,
> buffered receive data upon RST to allow applications to drain data
> already ACKed prior to the reset.
>
> Adding a narrow sysctl specifically for CLOSE_WAIT creates
> inconsistent behavior across TCP states.
Got it. I won't pursue this sysctl approach in the future. Thanks for
the review.
Leon
next prev parent reply other threads:[~2026-07-15 15:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 14:53 [RFC PATCH net-next v2 0/2] tcp: Add net.ipv4.tcp_purge_receive_queue sysctl Leon Hwang
2026-07-15 14:53 ` [RFC PATCH net-next v2 1/2] " Leon Hwang
2026-07-15 15:15 ` Eric Dumazet
2026-07-15 15:25 ` Leon Hwang [this message]
2026-07-15 15:30 ` Eric Dumazet
2026-07-15 15:48 ` Leon Hwang
2026-07-15 14:53 ` [RFC PATCH net-next v2 2/2] selftests/net: packetdrill: Add two tcp_purge_receive_queue tests Leon Hwang
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=2dc3d52b-ce4a-411d-9c30-934318ee98b0@linux.dev \
--to=leon.hwang@linux.dev \
--cc=bronzed_45_vested@icloud.com \
--cc=chia-yu.chang@nokia-bell-labs.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=ij@kernel.org \
--cc=jiayuan.chen@linux.dev \
--cc=kerneljasonxing@gmail.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=lance.yang@linux.dev \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=skhan@linuxfoundation.org \
--cc=yuuchihsu@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