All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mat Martineau <martineau@kernel.org>
To: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
Cc: MPTCP Linux <mptcp@lists.linux.dev>, Chris Mason <mason@kernel.org>
Subject: Re: [PATCH mptcp-net v3 34/50] mptcp: don't charge the backlog twice at accept()
Date: Wed, 25 Nov 2026 18:43:09 -0800 (PST)	[thread overview]
Message-ID: <089c2aae-6368-14d4-ef3f-77021a35408e@kernel.org> (raw)
In-Reply-To: <20261124-mptcp-cmason-fixes-v3-34-416c0920c73f@kernel.org>

On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:

> From: Chris Mason <mason@kernel.org>
>
> accept() can permanently overcharge the memory cgroup of an MPTCP
> server, so the server can be OOM killed, if the new connection received
> data while its MPTCP socket was locked.
>
> The sockets of an MPTCP connection have no memory cgroup before
> accept(), which then charges the sk_forward_alloc and the sk_rmem_alloc
> of the MPTCP socket (msk) and of each subflow. mptcp_graft_subflows()
> also charges msk->backlog_unaccounted: the truesize of the skbs that
> __mptcp_add_backlog() queued while the socket lock of the msk was held
> and their subflow had no memory cgroup. But the first charge already
> covers each of these skbs that has not been freed, in the sk_rmem_alloc
> of its subflow or of the msk, so no later uncharge matches the extra
> charge.
>
> The fix used here is to remove msk->backlog_unaccounted, its charge in
> mptcp_graft_subflows() and the warning that tests it in
> mptcp_can_spool_backlog(). An RFC patch [1] removes the same lines, as
> part of another approach.
>
> This issue has been found with the help of an LLM, and reproduced in a
> VM, with the reproducer shared with the original version of this patch,
> on a kernel with the previous patch: 100,000 connections to an MPTCP
> server in a memory cgroup. Without this patch, about 63 MB stayed
> charged to this memory cgroup once all the connections were closed, and
> to its parent after its removal:
>
>  SNAP label=after-100000 rounds=100000 sockets_left_in_srv=0 tcp_mem_pages=0 [...] c_sock=63295488 [...]
>  [...]
>  SNAP label=c-removed rounds=100000 sockets_left_in_srv=0 tcp_mem_pages=0 c=removed [...] p_sock=63295488 [...]
>
> And about 12 MB with only 50 connections, each getting 20,000 duplicates
> of a byte before accept(), beside bare ACKs with RM_ADDR, which make the
> MPTCP worker take the socket lock:

What does "20,000 duplicates of a byte" mean? Just that each connection 
received 20kbytes before accept? If the test case happens to use the same 
byte value for every data byte in the payload, that's superfluous 
information.

Other than that, the patch LGTM.

Reviewed-by: Mat Martineau <martineau@kernel.org>

>
>  SNAP label=after-50 rounds=50 sockets_left_in_srv=0 tcp_mem_pages=256 [...] c_sock=12881920 [...]
>
> Fixes: 6228efe0cc01 ("mptcp: leverage the backlog for RX packet processing")
> Link: https://lore.kernel.org/all/20260924080219.1036588-4-caixinchen1@huawei.com/ [1]
> Signed-off-by: Chris Mason <mason@kernel.org>
> [ No comment change: the commit message explains why the backlog is
>  covered. Commit message: refer to the RFC [1] removing the same lines
>  + how the issue was found, and its symptoms. ]
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> ---
> net/mptcp/protocol.c | 35 +----------------------------------
> net/mptcp/protocol.h |  1 -
> 2 files changed, 1 insertion(+), 35 deletions(-)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 504fe4a9954f..c9ef23276399 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -802,12 +802,6 @@ static void __mptcp_add_backlog(struct sock *sk,
>
> account:
> 	WRITE_ONCE(msk->backlog_len, msk->backlog_len + delta);
> -
> -	/* Possibly not accept()ed yet, keep track of memory not CG
> -	 * accounted, mptcp_graft_subflows() will handle it.
> -	 */
> -	if (!mem_cgroup_from_sk(ssk))
> -		msk->backlog_unaccounted += delta;
> }
>
> static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
> @@ -2456,12 +2450,6 @@ static bool mptcp_can_spool_backlog(struct sock *sk, struct list_head *skbs)
> {
> 	struct mptcp_sock *msk = mptcp_sk(sk);
>
> -	/* After CG initialization, subflows should never add skb before
> -	 * gaining the CG themself.
> -	 */
> -	DEBUG_NET_WARN_ON_ONCE(msk->backlog_unaccounted && sk->sk_socket &&
> -			       mem_cgroup_from_sk(sk));
> -
> 	if (list_empty(&msk->backlog_list))
> 		return false;
>
> @@ -4691,8 +4679,7 @@ static void mptcp_graft_subflows(struct sock *sk)
> 		/* Subflows joining after __inet_accept() will get the
> 		 * mem CG properly initialized at mptcp_finish_join() time,
> 		 * but subflows pending in join_list need explicit
> -		 * initialization before flushing `backlog_unaccounted`
> -		 * or MPTCP can later unexpectedly observe unaccounted memory.
> +		 * initialization by the loop below.
> 		 */
> 		mptcp_data_lock(sk);
> 		list_splice_init(&msk->join_list, &join_list);
> @@ -4724,26 +4711,6 @@ static void mptcp_graft_subflows(struct sock *sk)
> unlock:
> 		release_sock(ssk);
> 	}
> -
> -	if (mem_cgroup_sk_enabled(sk)) {
> -		gfp_t gfp = GFP_KERNEL | __GFP_NOFAIL;
> -		int amt;
> -
> -		/* Account the backlog memory; prior accept() is aware of
> -		 * fwd and rmem only.
> -		 */
> -		mptcp_data_lock(sk);
> -		amt = sk_mem_pages(sk->sk_forward_alloc +
> -				   msk->backlog_unaccounted +
> -				   atomic_read(&sk->sk_rmem_alloc)) -
> -		      sk_mem_pages(sk->sk_forward_alloc +
> -				   atomic_read(&sk->sk_rmem_alloc));
> -		msk->backlog_unaccounted = 0;
> -		mptcp_data_unlock(sk);
> -
> -		if (amt)
> -			mem_cgroup_sk_charge(sk, amt, gfp);
> -	}
> }
>
> static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index d0ae782c9ade..9a9dbab672af 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
> @@ -394,7 +394,6 @@ struct mptcp_sock {
>
> 	struct list_head backlog_list;	/* protected by the data lock */
> 	u32		backlog_len;
> -	u32		backlog_unaccounted;
> };
>
> #define mptcp_data_lock(sk) spin_lock_bh(&(sk)->sk_lock.slock)
>
> -- 
> 2.55.0
>
>
>

  reply	other threads:[~2026-11-26  2:43 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 [this message]
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=089c2aae-6368-14d4-ef3f-77021a35408e@kernel.org \
    --to=martineau@kernel.org \
    --cc=mason@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.