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, pabeni@redhat.com, geliang@kernel.org,
	kuba@kernel.org
Subject: Re: [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN in mptcp_inq_hint
Date: Sat, 05 Dec 2026 06:21:51 +0000	[thread overview]
Message-ID: <179645171175.3143.10537289200338346238@kernel.org> (raw)
In-Reply-To: <20261203-mptcp-fixes-for-siocinq-v7-6-e6d589de9cf8@kernel.org>

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

Critical: 0 · High: 0 · Medium: 1 · 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] In fallback mode, mptcp_inq_hint() counts the FIN only through
  the msk SOCK_DONE flag.
- [Low] mptcp_inq_hint() reads the MPTCP_FALLBACK_DONE bit
  (__mptcp_check_fallback()) before it reads msk->rcv_data_fin,…

--

mptcp: count the DATA_FIN in mptcp_inq_hint

This commit changes mptcp_inq_hint() to always start from
mptcp_data_avail(). It then adds one byte for the DATA_FIN when SOCK_DONE
is set, or when not in fallback and mptcp_rcv_data_fin_in_seq() reports
the DATA_FIN in sequence. The aim is to match TCP, where the FIN is
counted in TCP_CM_INQ until it is read.

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 1d330c5d09f42..e0e6266e11c85 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2487,22 +2487,17 @@ static bool mptcp_move_skbs(struct sock *sk)
>  static unsigned int mptcp_inq_hint(const struct sock *sk)
>  {
>  	const struct mptcp_sock *msk = mptcp_sk(sk);
> -	const struct sk_buff *skb;
> +	u64 hint_val = mptcp_data_avail(msk);

[ ... ]

> -	if (sock_flag(sk, SOCK_DONE))
> -		return 1;
> +	if (sock_flag(sk, SOCK_DONE) ||
> +	    (!__mptcp_check_fallback(msk) &&
> +	     mptcp_rcv_data_fin_in_seq(sk, NULL)))
> +		hint_val += 1;

[Severity: Medium]
In fallback mode, can this still miss the FIN in the case the
fallback_fin.pkt reproducer covers?

With fallback, the FIN is counted only through the msk SOCK_DONE flag.
For a fallback FIN, that flag is set only by mptcp_check_data_fin(),
which runs from the worker:

net/mptcp/subflow.c:subflow_sched_work_if_closed() {
    ...
	if (__mptcp_check_fallback(msk) && subflow_is_done(ssk) &&
	    msk->first == ssk &&
	    mptcp_update_rcv_data_fin(msk, subflow->map_seq +
				      subflow->map_data_len, true))
		mptcp_schedule_work(sk);
}

If the reader is blocked in sk_wait_data(), the msk is not owned, so
__mptcp_data_ready() moves the data straight into the msk queue:

net/mptcp/protocol.c:__mptcp_data_ready() {
    ...
	if (!sock_owned_by_user(sk)) {
		/* Wake-up the reader only for in-sequence data */
		if (move_skbs_to_msk(msk, ssk) && mptcp_epollin_ready(sk))
			sk->sk_data_ready(sk);
    ...
}

The woken reader then takes the msk lock and copies the data. The
backlog is empty, so mptcp_move_skbs() and mptcp_check_data_fin() never
run in the recvmsg path. The worker can't run in time either, because
the reader holds the msk lock.

At that point mptcp_inq_hint() sees SOCK_DONE clear. The second term is
skipped because __mptcp_check_fallback(msk) is true.

Wouldn't TCP_CM_INQ then report N (or 0 once everything is read), where
TCP would report N+1 (or 1)? It looks like the reproducer passes only
when the worker runs before recvmsg().

mptcp_check_data_fin() already tells a FIN apart from an RST in
fallback:

net/mptcp/protocol.c:mptcp_check_data_fin() {
    ...
		if (!__mptcp_check_fallback(msk) ||
		    (msk->first && sock_flag(msk->first, SOCK_DONE)))
			sock_set_flag(sk, SOCK_DONE);
    ...
}

Could the hint combine that msk->first SOCK_DONE test with
mptcp_rcv_data_fin_in_seq(), instead of excluding every fallback case?
mptcp_inq_hint() always runs under the msk socket lock, so msk->first
can be read there.

[Severity: Low]
Is there an ordering issue between the fallback check and the loads in
mptcp_rcv_data_fin_in_seq()?

The MPTCP_FALLBACK_DONE bit is tested before rcv_data_fin,
rcv_data_fin_seq and ack_seq are read. No lock or barrier ties the two
checks together, and the reader holds only the msk socket lock.

Both values are written from softirq:

- __mptcp_try_fallback() sets the fallback bit under msk->fallback_lock,
  for example from check_fully_established() or
  subflow_check_data_avail().
- subflow_sched_work_if_closed()->mptcp_update_rcv_data_fin() publishes
  the dummy DATA_FIN.

A possible interleaving:

CPU0 (msk lock owner)         CPU1 (softirq)
mptcp_inq_hint()
  __mptcp_check_fallback()
    returns false
                              __mptcp_try_fallback()
                                set MPTCP_FALLBACK_DONE
                              subflow RST
                              subflow_sched_work_if_closed()
                                mptcp_update_rcv_data_fin()
                                  rcv_data_fin_seq = map_seq + map_data_len
                                  rcv_data_fin = 1
  mptcp_rcv_data_fin_in_seq()
    rcv_data_fin == 1
    ack_seq == rcv_data_fin_seq
  hint_val += 1

Take an active-side msk that has received no data since the fallback.
There, map_seq + map_data_len equals ack_seq, because
mptcp_finish_connect() initialises subflow->map_seq to ack_seq.

Wouldn't this count the spurious FIN byte on RST that the commit message
says excluding fallback avoids? On weakly ordered CPUs the two loads
could also be reordered.

Would reading rcv_data_fin first (with smp_rmb()) and checking the
fallback bit afterwards close most of this window?

>  
> -	return 0;
> +	return (unsigned int)hint_val;
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-mptcp-fixes-for-siocinq-v7-0-e6d589de9cf8%40kernel.org

  parent reply	other threads:[~2026-12-05  6:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 16:48 [PATCH mptcp-net v7 0/6] mptcp: fixes for SIOCINQ Matthieu Baerts (NGI0)
2026-12-03 16:48 ` [PATCH mptcp-net v7 1/6] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint Matthieu Baerts (NGI0)
2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 2/6] mptcp: add missing memory barriers for rcv_data_fin_seq Matthieu Baerts (NGI0)
2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 3/6] mptcp: extract mptcp_rcv_data_fin_in_seq helper Matthieu Baerts (NGI0)
2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 4/6] mptcp: add mptcp_inq() for SIOCINQ Matthieu Baerts (NGI0)
2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 5/6] mptcp: use SOCK_DONE in mptcp_inq_hint Matthieu Baerts (NGI0)
2026-12-03 16:48 ` [PATCH mptcp-next mptcp-net v7 6/6] mptcp: count the DATA_FIN " Matthieu Baerts (NGI0)
2026-12-03 18:50   ` sashiko-bot
2026-12-04 10:55     ` Geliang Tang
2026-12-04 12:12       ` Matthieu Baerts
2026-12-04 12:14         ` Matthieu Baerts
2026-12-04 23:06         ` Geliang Tang
2026-12-05 14:28           ` Matthieu Baerts
2026-12-05  6:21   ` netdev-bot+sashiko [this message]
2026-12-03 18:33 ` [PATCH mptcp-net v7 0/6] mptcp: fixes for SIOCINQ MPTCP CI

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=179645171175.3143.10537289200338346238@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=geliang@kernel.org \
    --cc=kuba@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=pabeni@redhat.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 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.