From: Matthieu Baerts <matttbe@kernel.org>
To: Mat Martineau <martineau@kernel.org>
Cc: MPTCP Linux <mptcp@lists.linux.dev>, Chris Mason <mason@kernel.org>
Subject: Re: [PATCH mptcp-net v3 33/50] mptcp: don't charge a shared page twice at accept()
Date: Thu, 26 Nov 2026 15:32:06 +0100 [thread overview]
Message-ID: <527e1d5d-29cf-4fa4-9d0d-067f5ebed443@kernel.org> (raw)
In-Reply-To: <6e1bc879-784e-5115-fa6c-0365182929a1@kernel.org>
Hi Mat,
Thank you for the reviews!
On 26/11/2026 03:20, Mat Martineau wrote:
> On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:
>
>> From: Chris Mason <mason@kernel.org>
>>
>> accept() of an MPTCP connection that has already received data can leak
>> one page of memory cgroup charge, and the leaked charges can get the
>> server OOM killed.
>>
>> At accept(), __inet_accept() charges the MPTCP socket (msk) for the
>> memory that it holds, rounded up to whole pages, and
>> mptcp_graft_subflows() does the same for each subflow. A page is
>> uncharged only once, when the socket that holds it releases it, so
>> rounding up each socket on its own is only correct while each page
>> belongs to one socket. But for each skb that the msk takes over from a
>> subflow, it borrows skb->truesize bytes from the pages that the subflow
>> reserved, so the two can share a page:
>>
>> reserved by the subflow 4096 bytes 1 page
>> now held by the msk 896 bytes charged for 1 page
>> still held by the subflow 3200 bytes charged for 1 page
>>
>> The fix used here is to keep a running sum of what the msk and its
>> subflows hold, and to let the new mptcp_charge_subflow() charge each
>> subflow only for the pages that it adds to the rounded-up sum.
>>
>> 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:
>> an MPTCP server in a memory cgroup, the first byte of the client
>> arriving before accept(). Without this patch, 4096 bytes stayed charged
>> to the memory cgroup for each connection, after its end:
>>
>> SNAP label=after-1000 rounds=1000 sockets_left_in_srv=0 [...]
>> c_sock=4096000 [...]
>> SNAP label=after-5000 rounds=5000 sockets_left_in_srv=0 [...]
>> c_sock=20480000 [...]
>>
>> With a memory limit, the original version of this patch reported that
>> the server was killed by the OOM killer after about 14,400 connections.
>>
>> Fixes: 9db5b3cec4ec ("mptcp: borrow forward memory from subflow")
>> Signed-off-by: Chris Mason <mason@kernel.org>
>> [ Shorter comment. Commit message: how the issue was found, and its
>> symptoms. ]
>> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
>> ---
>> Note (Clashiko on v2): the backlog can still be charged twice here: this
>> is fixed by the next patch.
>> ---
>> net/mptcp/protocol.c | 21 ++++++++++++++++++++-
>> 1 file changed, 20 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
>> index f8cb585da0b3..504fe4a9954f 100644
>> --- a/net/mptcp/protocol.c
>> +++ b/net/mptcp/protocol.c
>> @@ -4664,10 +4664,26 @@ static int mptcp_listen(struct socket *sock,
>> int backlog)
>> return err;
>> }
>>
>> +/* The msk and its subflows share pages: charge their rounded-up sum */
>
> I suggest adding a note that this is similar to __sk_charge() (to make
> it easier keep the two functions consistent if either has future
> changes). But otherwise the patch looks good.
Good idea! The v4 will contain:
/* Similar to __sk_charge(), but the msk and its subflows share pages */
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
next prev parent reply other threads:[~2026-11-26 14:32 UTC|newest]
Thread overview: 77+ 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-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-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-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-24 21:59 ` [PATCH mptcp-net v3 11/50] mptcp: no sf left: process pending MP_FASTCLOSE Matthieu Baerts (NGI0)
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-24 21:59 ` [PATCH mptcp-net v3 13/50] mptcp: process pending close events at accept() Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 14/50] mptcp: report errors received before accept() Matthieu Baerts (NGI0)
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-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-24 21:59 ` [PATCH mptcp-net v3 22/50] mptcp: close a subflow reset for a bad mapping Matthieu Baerts (NGI0)
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-24 21:59 ` [PATCH mptcp-net v3 26/50] mptcp: keep room for infinite map after fallback Matthieu Baerts (NGI0)
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-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 [this message]
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-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-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-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-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-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-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-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-25 0:39 ` [PATCH mptcp-net v3 00/50] mptcp: misc fixes 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=527e1d5d-29cf-4fa4-9d0d-067f5ebed443@kernel.org \
--to=matttbe@kernel.org \
--cc=martineau@kernel.org \
--cc=mason@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox