All of lore.kernel.org
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: matttbe@kernel.org
Cc: mptcp@lists.linux.dev, kuba@kernel.org
Subject: Re: [PATCH mptcp-next mptcp-net v3 48/50] mptcp: report errors as TCP does when closing
Date: Thu, 26 Nov 2026 23:29:58 +0000	[thread overview]
Message-ID: <179573579872.3133.12332671479932565054@kernel.org> (raw)
In-Reply-To: <20261124-mptcp-cmason-fixes-v3-48-416c0920c73f@kernel.org>

Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 3 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] Spurious ECONNRESET after a clean MPTCP-level close, in
  __mptcp_close_ssk() (net/mptcp/protocol.c:2962-2968).
- [Medium] mptcp: skipped mptcp_check_rcv_close() in __mptcp_close_ssk()
  when ESTABLISHED
- [Medium] mptcp: premature TCP_CLOSE and wakeup before mptcp_close_err()
  on timeout
- [Low] The barrier-pairing comments disagree.

--

mptcp: report errors as TCP does when closing

This patch makes the MPTCP socket set SHUTDOWN_MASK and an error when it
moves to TCP_CLOSE. This covers the close timeout (ETIMEDOUT), the last
subflow closing outside ESTABLISHED, and the late cleanup in accept(). In
those cases the error is the last subflow's error, or one picked from the
MPTCP-level state, matching tcp_done_with_error().

Link: https://github.com/multipath-tcp/mptcp_net-next/issues/648

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 016b16b3cc925..0a7600aea181e 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -518,6 +518,56 @@ static void mptcp_close_wake_up(struct sock *sk)
>  		sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
>  }
>  
> +/* Mirror the tcp_reset() error propagation */
> +static int mptcp_reset_err(const struct sock *sk)
> +{
> +	int err;
> +
> +	switch (sk->sk_state) {
> +	case TCP_SYN_SENT:
> +		err = ECONNREFUSED;
> +		break;
> +	case TCP_CLOSE_WAIT:
> +		err = EPIPE;
> +		break;
> +	default:
> +		err = ECONNRESET;
> +	}
> +
> +	return err;
> +}
> +
> +/* No more data can be exchanged: report it, as tcp_done_with_error() does */
> +static void mptcp_close_err(struct sock *sk, int err)
> +{
> +	WRITE_ONCE(sk->sk_err, err);
> +	/* This barrier is coupled with smp_rmb() in mptcp_poll() */
> +	smp_wmb();

[Severity: Low]

This isn't a bug, but the comment on the reader side in mptcp_poll() still
names only __mptcp_error_report() as the matching writer:

	/* This barrier is coupled with smp_wmb() in __mptcp_error_report() */
	smp_rmb();

__mptcp_error_report() has no smp_wmb() of its own. The writers are
__mptcp_subflow_error_report() and now mptcp_close_err().

The ordering itself looks correct. Could the mptcp_poll() comment be updated
to name the new writer too?

> +	WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
> +	mptcp_set_state(sk, TCP_CLOSE);
> +	if (sock_flag(sk, SOCK_DEAD))
> +		return;
> +
> +	mptcp_close_wake_up(sk);
> +	sk_error_report(sk);
> +}
> +
> +/* As TCP: the error of the last subflow, e.g. ETIMEDOUT, but after a reset
> + * (EBADMSG: by MPTCP) or without error, it depends on the msk state
> + */
> +static void mptcp_close_last_err(struct sock *sk, int err)
> +{
> +	switch (err) {
> +	case 0:
> +	case ECONNREFUSED:
> +	case ECONNRESET:
> +	case EPIPE:
> +	case EBADMSG:
> +		err = mptcp_reset_err(sk);
> +	}
> +	mptcp_close_err(sk, err);
> +}
> +

[ ... ]

> @@ -2905,13 +2957,15 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
>  			mptcp_set_close_tout(sk, tcp_jiffies32 -
>  					     (mptcp_close_timeout(sk) + 1));
>  			mptcp_schedule_work(sk);
> +		} else if (sk->sk_state == TCP_CLOSE) {
> +			mptcp_close_wake_up(sk);
>  		} else if (sk->sk_state != TCP_ESTABLISHED ||
>  			   msk->in_accept_queue) {
>  			mptcp_check_rcv_close(sk);
> -			mptcp_set_state(sk, TCP_CLOSE);
> -			WRITE_ONCE(sk->sk_shutdown,
> -				   sk->sk_shutdown | SEND_SHUTDOWN);
> -			mptcp_close_wake_up(sk);
> +			if (sk->sk_state == TCP_CLOSE)
> +				mptcp_close_wake_up(sk);
> +			else
> +				mptcp_close_last_err(sk, ssk_err);

[Severity: Medium]
Can waiters be woken here before the error is set, on the close
timeout path?

When mptcp_close_tout_expired() is true in mptcp_worker(),
mptcp_do_fastclose() moves the msk to TCP_CLOSE first, while sk_err is
still 0 and sk_shutdown is not SHUTDOWN_MASK. The loop then calls
__mptcp_close_ssk() on each subflow. Once only msk->first is left, in
TCP_CLOSE, this new branch calls mptcp_close_wake_up() on a socket
that is not SOCK_DEAD. That runs sk_state_change() before
mptcp_close_err(sk, ETIMEDOUT) has written sk_err and sk_shutdown.

mptcp_poll() and getsockopt(SO_ERROR) do not take the msk socket lock.
A waiter woken on another CPU can therefore see TCP_CLOSE with
sk_shutdown at 0 and sk_err at 0. It gets EPOLLHUP without EPOLLERR,
EPOLLIN or EPOLLOUT, and SO_ERROR returns 0 instead of ETIMEDOUT. An
application acting on that first wakeup would miss the timeout this
patch is meant to report. mptcp_close_err() then wakes everybody a
second time.

The ordering mptcp_close_err() sets up (sk_err, smp_wmb(),
SHUTDOWN_MASK, then TCP_CLOSE) does not help here, as the state was
already published by mptcp_do_fastclose(). mptcp_check_fastclose() has
a similar, older inversion: TCP_CLOSE is set before SHUTDOWN_MASK, and
there is no smp_wmb() after sk_err.

Should the wake up in __mptcp_close_ssk() be left to mptcp_close_err()
on the close timeout path? Or should sk_err and sk_shutdown be set
before mptcp_do_fastclose() changes the state?

[Severity: Medium]
Can a DATA_FIN still sitting in msk->backlog_list be missed here?

Suppose the peer sends its last data with a DATA_FIN, then closes or
resets the only subflow, while mptcp_worker() owns the msk socket lock.
The skb is queued in msk->backlog_list and msk->rcv_data_fin is set,
but msk->ack_seq has not reached msk->rcv_data_fin_seq yet. The
mptcp_check_data_fin() call in mptcp_worker() does not spool the
backlog, so sk_state is still TCP_ESTABLISHED when
__mptcp_close_subflow() reaches __mptcp_close_ssk().

mptcp_close_ssk() only spools the backlog for the first subflow after
a fallback. The TCP_ESTABLISHED test above also runs before
mptcp_check_rcv_close() gets a chance to, so this ends up in the
mptcp_start_tout_timer() branch. The backlog is only moved later, from
mptcp_release_cb(), which then processes the DATA_FIN and moves the msk
to TCP_CLOSE_WAIT with no subflow left.

The msk then sits in TCP_CLOSE_WAIT until the close timeout expires.
With this patch, mptcp_worker() then reports ETIMEDOUT through
mptcp_close_err(), on a connection the peer closed cleanly. Had the
DATA_FIN been processed first, mptcp_close_last_err() would have
closed it at once with EPIPE. An MP_FASTCLOSE received in the same
window looks to be skipped the same way.

The TCP_ESTABLISHED gating predates this patch, but the new error
reporting makes the difference visible to applications. Should
mptcp_check_rcv_close() be called before sk_state is tested here, or
is the pending DATA_FIN expected to be handled somewhere else?

[Severity: Medium]

Can this report ECONNRESET after a clean MPTCP-level close?

mptcp_check_rcv_close() only handles the receive side, through
mptcp_check_data_fin() and mptcp_check_fastclose(). When our own DATA_FIN is
acked, the move to TCP_CLOSE is done only by mptcp_check_data_fin_ack(),
which is called only from mptcp_worker():

net/mptcp/protocol.c:mptcp_check_data_fin_ack() {
    ...
	if (mptcp_pending_data_fin_ack(sk)) {
		...
		case TCP_CLOSING:
		case TCP_LAST_ACK:
			mptcp_shutdown_subflows(msk);
			mptcp_set_state(sk, TCP_CLOSE);
    ...
}

When the DATA_ACK arrives, __mptcp_clean_una() only schedules the worker:

	if (mptcp_pending_data_fin_ack(sk))
		mptcp_schedule_work(sk);

So until the worker runs, the msk can still be in TCP_LAST_ACK or
TCP_CLOSING with our DATA_FIN already acked.

Suppose msk->first is already in TCP_CLOSE and the one other subflow is
removed in that window. One way is a peer RM_ADDR, handled earlier in the
same worker run:

mptcp_worker()
  mptcp_pm_worker()
    mptcp_pm_rm_addr_recv()
      mptcp_pm_rm_addr_or_subflow()
        mptcp_close_ssk()
          __mptcp_close_ssk()
  ...
  mptcp_check_data_fin_ack()   <- runs only after this

mptcp_pm_rm_addr_or_subflow() skips only subflows in FIN_WAIT1, FIN_WAIT2,
CLOSING or CLOSE, so an ESTABLISHED or CLOSE_WAIT subflow is still removed.
A netlink endpoint delete or flush, or a userspace PM subflow destroy, can
also reach mptcp_close_ssk() directly under the msk lock.

In that case ssk_err is 0, and for a socket that is not SOCK_DEAD (for
example after shutdown(SHUT_WR)) the result is:

mptcp_close_last_err(sk, 0)
  mptcp_reset_err(sk)            -> ECONNRESET for LAST_ACK / CLOSING
  mptcp_close_err(sk, ECONNRESET)

When mptcp_check_data_fin_ack() runs later, the msk is already in
TCP_CLOSE, mptcp_pending_data_fin_ack() returns false, and sk_err stays at
ECONNRESET. mptcp_poll() then reports EPOLLERR and SO_ERROR returns
ECONNRESET on a connection that finished its DATA_FIN exchange cleanly.

Before this patch, this path moved to TCP_CLOSE without setting sk_err.
TCP also sets no error when the final ACK arrives in LAST_ACK or CLOSING.

Should the pending DATA_FIN ack be processed first, either through
mptcp_check_data_fin_ack() or a mptcp_pending_data_fin_ack() test, before
the error is picked? This doesn't seem to be addressed by the later patches
in the series.

>  		} else {
>  			mptcp_start_tout_timer(sk);
>  		}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org

  parent reply	other threads:[~2026-11-26 23:29 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
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 [this message]
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=179573579872.3133.12332671479932565054@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=kuba@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.