From: Geliang Tang <geliang@kernel.org>
To: Mat Martineau <martineau@kernel.org>,
"Matthieu Baerts (NGI0)" <matttbe@kernel.org>
Cc: MPTCP Linux <mptcp@lists.linux.dev>
Subject: Re: [PATCH mptcp-net v3 04/50] mptcp: return EOF after a DATA_FIN, as TCP does
Date: Thu, 26 Nov 2026 10:59:47 +0800 [thread overview]
Message-ID: <229f98a10259d919820fd8ef31fbf21f9e0dbfeb.camel@kernel.org> (raw)
In-Reply-To: <39c8abe7-1af4-7e26-a394-f7cf0b5d86d8@kernel.org>
Hi Matt, Mat,
On Wed, 2026-11-25 at 17:57 -0800, Mat Martineau wrote:
> On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:
>
> > Once an MPTCP socket has received a DATA_FIN, recv() returns the
> > remaining data, then EOF. But if the connection was then reset, e.g. by
> > an MP_FASTCLOSE, recv() returned an error after the data, e.g. EPIPE,
> > instead of EOF as TCP does. A proxy resetting the other connection on
> > read errors then dropped the data it still had to forward.
> >
> > As TCP does with a FIN, set SOCK_DONE when processing the DATA_FIN, and
> > check it before the socket error in recvmsg(). With an MP_FASTCLOSE, the
> > data still in the backlog is moved first, not to miss the DATA_FIN.
> > After a fallback, a DATA_FIN is also emulated after a reset: only set
> > SOCK_DONE after a FIN, not to hide a reset behind an EOF. This FIN is
> > cleared when the first subflow is disconnected: process this DATA_FIN
> > before.
> >
> > This was reported on GitHub, and is validated with new Packetdrill
> > tests: data and a DATA_FIN are received, then an MP_FASTCLOSE; and
> > after a fallback, data, a FIN and a reset. Without this patch, the
> > second read() returned EPIPE in both cases:
> >
> > receive_fastclose_after_data_fin.pkt:27: runtime error in read call: Expected result 0 but got -1 with errno 32 (Broken pipe)
> > v1_connect_tcpfallback_fin_reset.pkt:19: runtime error in read call: Expected result 0 but got -1 with errno 32 (Broken pipe)
> >
> > Note for the backports: the issue with an MP_FASTCLOSE comes from commit
> > 69800e516e96 ("mptcp: propagate fastclose error"), in v6.1. Before that,
> > the modifications in mptcp_check_fastclose() and mptcp_disconnect() are
> > not needed.
> >
> > Fixes: 15cc10453398 ("mptcp: deliver ssk errors to msk")
> > Link: https://github.com/multipath-tcp/mptcp_net-next/issues/647
> > Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
>
> Reviewed-by: Mat Martineau <martineau@kernel.org>
Thanks for adding this SOCK_DONE patch; it is very helpful for my work on
modifying mptcp_inq_hint(). mptcp_inq_hint() should check SOCK_DONE, just like
tcp_inq_hint() does.
Acked-by: Geliang Tang <geliang@kernel.org>
I'm wondering whether this patch should come before patch 1, because patch 1
checks SOCK_DONE, but SOCK_DONE isn't set at that point.
Thanks,
-Geliang
>
> > ---
> > v2: new, for issue #647 reported on GitHub
> > v3: process the DATA_FIN before disconnecting the first subflow, which
> > clears its FIN (Clashiko)
> >
> > Note (Clashiko on v2): with a DATA_FIN, then an MP_FASTCLOSE in
> > FIN_WAIT2, the reset subflows are only released at close(): not a leak.
> > A DATA_FIN mapped on another CPU while an MP_FASTCLOSE is processed can
> > still lead to ECONNRESET: two subflows racing, and the connection reset
> > by the peer anyway.
> > ---
> > net/mptcp/protocol.c | 31 +++++++++++++++++++++++++++++--
> > 1 file changed, 29 insertions(+), 2 deletions(-)
> >
> > diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> > index 9e297fa08bfe..de6da0b6c4ca 100644
> > --- a/net/mptcp/protocol.c
> > +++ b/net/mptcp/protocol.c
> > @@ -714,6 +714,10 @@ static void mptcp_check_data_fin(struct sock *sk)
> > WRITE_ONCE(msk->rcv_data_fin, 0);
> >
> > WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | RCV_SHUTDOWN);
> > + /* on fallback, also emulated after a reset: check for a FIN */
> > + if (!__mptcp_check_fallback(msk) ||
> > + (msk->first && sock_flag(msk->first, SOCK_DONE)))
> > + sock_set_flag(sk, SOCK_DONE);
> > smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
> >
> > switch (sk->sk_state) {
> > @@ -972,6 +976,9 @@ static bool __mptcp_subflow_error_report(struct sock *sk, struct sock *ssk)
> > * destroy the msk as needed.
> > */
> > ssk_state = inet_sk_state_load(ssk);
> > + /* a FIN received before still leads to EOF, as with TCP */
> > + if (sock_flag(ssk, SOCK_DONE) && mptcp_pending_data_fin(sk, NULL))
> > + sock_set_flag(sk, SOCK_DONE);
> > if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD))
> > mptcp_set_state(sk, ssk_state);
> > WRITE_ONCE(sk->sk_err, -err);
> > @@ -2494,6 +2501,9 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
> > !timeo)
> > break;
> > } else {
> > + if (sock_flag(sk, SOCK_DONE))
> > + break;
> > +
> > copied = sock_error(sk);
> > if (copied)
> > break;
> > @@ -2813,6 +2823,8 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
> > void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
> > struct mptcp_subflow_context *subflow)
> > {
> > + struct mptcp_sock *msk = mptcp_sk(sk);
> > +
> > /* The first subflow can already be closed or disconnected */
> > if (subflow->close_event_done || READ_ONCE(subflow->local_id) < 0)
> > return;
> > @@ -2820,12 +2832,21 @@ void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
> > subflow->close_event_done = true;
> >
> > if (sk->sk_state == TCP_ESTABLISHED)
> > - mptcp_event(MPTCP_EVENT_SUB_CLOSED, mptcp_sk(sk), ssk, GFP_KERNEL);
> > + mptcp_event(MPTCP_EVENT_SUB_CLOSED, msk, ssk, GFP_KERNEL);
> >
> > /* subflow aborted before reaching the fully_established status
> > * attempt the creation of the next subflow
> > */
> > - mptcp_pm_subflow_check_next(mptcp_sk(sk), subflow);
> > + mptcp_pm_subflow_check_next(msk, subflow);
> > +
> > + /* On fallback, the FIN of the first subflow is cleared when it is
> > + * disconnected: process the DATA_FIN emulated from it before.
> > + */
> > + if (ssk == msk->first && __mptcp_check_fallback(msk) &&
> > + READ_ONCE(msk->rcv_data_fin) && !sock_flag(sk, SOCK_DEAD)) {
> > + mptcp_move_skbs(sk);
> > + mptcp_check_data_fin(sk);
> > + }
> >
> > __mptcp_close_ssk(sk, ssk, subflow, MPTCP_CF_PUSH);
> > }
> > @@ -2938,6 +2959,11 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)
> > if (likely(!READ_ONCE(msk->rcv_fastclose)))
> > return;
> >
> > + /* a DATA_FIN received before still leads to EOF, as with TCP */
> > + if (READ_ONCE(msk->rcv_data_fin))
> > + mptcp_move_skbs(sk);
> > + mptcp_check_data_fin(sk);
> > +
> > mptcp_token_destroy(msk);
> >
> > mptcp_for_each_subflow_safe(msk, subflow, tmp) {
> > @@ -3797,6 +3823,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)
> > atomic64_set(&msk->rcv_wnd_sent, 0);
> >
> > WRITE_ONCE(sk->sk_shutdown, 0);
> > + sock_reset_flag(sk, SOCK_DONE);
> > sk_error_report(sk);
> > return 0;
> > }
> >
> > --
> > 2.55.0
> >
> >
> >
next prev parent reply other threads:[~2026-11-26 2:59 UTC|newest]
Thread overview: 105+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 01/50] mptcp: keep an orphan while it can send its data Matthieu Baerts (NGI0)
2026-11-25 1:16 ` Mat Martineau
2026-11-25 1:17 ` Mat Martineau
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-24 21:59 ` [PATCH mptcp-net v3 02/50] mptcp: limit an orphan probing a zero window Matthieu Baerts (NGI0)
2026-11-25 1:19 ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 03/50] mptcp: count orphans as TCP does Matthieu Baerts (NGI0)
2026-11-25 1:21 ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 04/50] mptcp: return EOF after a DATA_FIN, " Matthieu Baerts (NGI0)
2026-11-26 1:57 ` Mat Martineau
2026-11-26 2:59 ` Geliang Tang [this message]
2026-11-26 8:06 ` Matthieu Baerts
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-24 21:59 ` [PATCH mptcp-net v3 05/50] mptcp: let TCP send orphan data after fallback Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 06/50] mptcp: reset the subflow on abort " Matthieu Baerts (NGI0)
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-24 21:59 ` [PATCH mptcp-net v3 07/50] mptcp: wake up blocked senders when no sf left Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 08/50] mptcp: set SEND_SHUTDOWN on close by an sf error Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 09/50] mptcp: start close timeout on initial sf shutdown Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 10/50] mptcp: process a DATA_FIN received with old data Matthieu Baerts (NGI0)
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-24 21:59 ` [PATCH mptcp-net v3 11/50] mptcp: no sf left: process pending MP_FASTCLOSE Matthieu Baerts (NGI0)
2026-11-27 1:12 ` Geliang Tang
2026-11-27 18:57 ` Matthieu Baerts
2026-12-01 8:59 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 12/50] mptcp: no sf left: process pending DATA_FIN Matthieu Baerts (NGI0)
2026-11-24 22:33 ` sashiko-bot
2026-11-26 16:50 ` Matthieu Baerts
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-24 21:59 ` [PATCH mptcp-net v3 13/50] mptcp: process pending close events at accept() Matthieu Baerts (NGI0)
2026-11-27 1:06 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 14/50] mptcp: report errors received before accept() Matthieu Baerts (NGI0)
2026-11-27 1:02 ` Geliang Tang
2026-11-27 1:04 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 15/50] mptcp: clear sk_err on connect(), as TCP does Matthieu Baerts (NGI0)
2026-11-26 6:40 ` Geliang Tang
2026-11-26 8:15 ` Matthieu Baerts
2026-11-24 21:59 ` [PATCH mptcp-net v3 16/50] mptcp: clear DEFER_CONNECT on disconnect Matthieu Baerts (NGI0)
2026-11-26 6:41 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 17/50] mptcp: report sf aborts during deferred connect Matthieu Baerts (NGI0)
2026-11-27 1:00 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 18/50] mptcp: no fastclose reset from SYN_SENT subflows Matthieu Baerts (NGI0)
2026-11-26 7:04 ` Geliang Tang
2026-11-26 7:35 ` Matthieu Baerts
2026-11-26 8:02 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 19/50] mptcp: fastopen: keep listeners and connections Matthieu Baerts (NGI0)
2026-11-26 8:20 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 20/50] mptcp: don't inherit fastopening from a listener Matthieu Baerts (NGI0)
2026-11-26 7:07 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 21/50] mptcp: drop non-MP_JOIN cookie ACKs on PM listeners Matthieu Baerts (NGI0)
2026-11-27 1:17 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 22/50] mptcp: close a subflow reset for a bad mapping Matthieu Baerts (NGI0)
2026-11-27 1:17 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 23/50] mptcp: pm: kernel: count endpoint listeners as sockets in use Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 24/50] mptcp: count a listener once when listen() is called again Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 25/50] mptcp: send the infinite map in a single segment Matthieu Baerts (NGI0)
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-24 21:59 ` [PATCH mptcp-net v3 26/50] mptcp: keep room for infinite map after fallback Matthieu Baerts (NGI0)
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-24 21:59 ` [PATCH mptcp-net v3 27/50] mptcp: do not fallback while old data is in flight Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 28/50] mptcp: stop resending data to a peer that fell back Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 29/50] mptcp: don't resend data acked without MPTCP opts Matthieu Baerts (NGI0)
2026-11-24 22:36 ` sashiko-bot
2026-11-26 16:53 ` Matthieu Baerts
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-24 21:59 ` [PATCH mptcp-net v3 30/50] mptcp: pm: kernel: don't count signal+subflow ID 0 endp Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 31/50] selftests: mptcp: join: check re-adding " Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 32/50] mptcp: reclaim forward memory after coalescing skbs Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 33/50] mptcp: don't charge a shared page twice at accept() Matthieu Baerts (NGI0)
2026-11-26 2:20 ` Mat Martineau
2026-11-26 14:32 ` Matthieu Baerts
2026-11-24 21:59 ` [PATCH mptcp-net v3 34/50] mptcp: don't charge the backlog " Matthieu Baerts (NGI0)
2026-11-26 2:43 ` Mat Martineau
2026-11-26 14:41 ` Matthieu Baerts
2026-11-24 21:59 ` [PATCH mptcp-net v3 35/50] mptcp: don't charge a subflow twice when it joins during accept() Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 36/50] mptcp: continue the last mapping after a fallback Matthieu Baerts (NGI0)
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-24 21:59 ` [PATCH mptcp-net v3 37/50] mptcp: keep the first byte after a simult connect Matthieu Baerts (NGI0)
2026-11-24 22:45 ` sashiko-bot
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-24 21:59 ` [PATCH mptcp-net v3 38/50] mptcp: move to ESTABLISHED " Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 39/50] mptcp: fix MSG_PEEK after a partly peeked skb Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 40/50] mptcp: send the DATA_ACK after moving the backlog Matthieu Baerts (NGI0)
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-24 21:59 ` [PATCH mptcp-net v3 41/50] selftests: mptcp: join: infinite map: no spurious rtx Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 42/50] selftests: mptcp: connect: trunc: wait for acks Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-net v3 43/50] mptcp: order write_seq and DATA_FIN flag Matthieu Baerts (NGI0)
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-24 22:00 ` [PATCH mptcp-net v3 44/50] mptcp: order write_seq and DATA_FIN flag for fallback Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-net v3 45/50] Squash to "bpf: Add mptcp packet scheduler struct_ops" Matthieu Baerts (NGI0)
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-24 22:00 ` [PATCH mptcp-net v3 46/50] Squash to "bpf: Export mptcp packet scheduler helpers" Matthieu Baerts (NGI0)
2026-11-24 22:45 ` sashiko-bot
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 47/50] mptcp: push pending data after a fallback on reception Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 48/50] mptcp: report errors as TCP does when closing Matthieu Baerts (NGI0)
2026-11-24 22:52 ` sashiko-bot
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 49/50] mptcp: trace: name all the mapping statuses Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH RFC mptcp-next mptcp-net v3 50/50] mptcp: reset when the DSS disappears after a DATA_ACK Matthieu Baerts (NGI0)
2026-11-24 22:36 ` sashiko-bot
2026-11-26 23:29 ` netdev-bot+sashiko
2026-11-25 0:39 ` [PATCH mptcp-net v3 00/50] mptcp: misc fixes MPTCP CI
2026-11-26 16:54 ` Matthieu Baerts
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=229f98a10259d919820fd8ef31fbf21f9e0dbfeb.camel@kernel.org \
--to=geliang@kernel.org \
--cc=martineau@kernel.org \
--cc=matttbe@kernel.org \
--cc=mptcp@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.