From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F7142FF659 for ; Wed, 12 Nov 2025 09:52:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762941168; cv=none; b=K4wcq8PnbnOXCTJCFMJyEbREdocn4lNYEJPa/VrNQEq48oORCgKz+4tV0rQFm37axA41wv/2YRIU6t5IUbNo732KfSWIVc2g5l/PCPMQCFuvyQk4prPSBgSRXY1SJIn/KUDiYujPIqJyrSUas58kv15G3mzZj1Pde/qa4Mx56P8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762941168; c=relaxed/simple; bh=DzcsxOdzD7+jvtJCe6BeAks9RA5b/hTbRLJopHaRYbU=; h=Message-ID:Date:MIME-Version:Subject:To:References:From:Cc: In-Reply-To:Content-Type; b=sPd2zSEvF8ftV+X85SaruNWw5QwWh6EYVc1eMYQjlcuUSL0yLVTcXbykSYi3HqZlOkKBzW7Gk4vb3V203JHLZ3umps4g9qQccwmQfjrIpreyKwJuzLtE1WFdghFQXTW33+KZMEikztpay21EpvAqDbhlgqaa8NUpww5UFFq0k+0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WZDXqQMo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WZDXqQMo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A9C6C19423; Wed, 12 Nov 2025 09:52:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1762941168; bh=DzcsxOdzD7+jvtJCe6BeAks9RA5b/hTbRLJopHaRYbU=; h=Date:Subject:To:References:From:Cc:In-Reply-To:From; b=WZDXqQMol5S9HgGuhpt8cLJOdUt2NJZKsAmRDvHDTXhbOnR/qzL+1DMpUxHhQ385y sSRAMwgbcDt1yWdpXFSPKzpUvNEKYTcO/s6di1mrjOhgprP/7LpSgOr3zjx0abJqpO 9goOhZklrbDQIkJpHVJBmVsjZ9sJnebfJW49LqoYd6OpArHJwfdOy8lJyPUQQXNMwr FDN1ZAUGIfa/swlOvawyI6b83CcLaEIM75i1DnSsk7kIv9NKTQxe8zEWSMxeY99yD3 YQ7rO34Xe7X2GfvxPBKZPhoLUx4yOD04EhPX/pZBoz43JIefCy2WIFmcIVsoR4j/Ak EL11ykKCkXxAg== Message-ID: <301e47c3-3c4a-4e8f-8c4f-a359356cc7a3@kernel.org> Date: Wed, 12 Nov 2025 10:52:44 +0100 Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Subject: Re: [PATCH v2 mptcp-next] Squash-to: "mptcp: leverage the backlog for RX packet processing" Content-Language: en-GB, fr-BE To: Paolo Abeni References: <704b4358-30b2-4065-abbb-752f4f9a3c79@kernel.org> <27e7304b-d485-4e01-bd47-a169c5b25849@redhat.com> From: Matthieu Baerts Cc: mptcp@lists.linux.dev, Geliang Tang Autocrypt: addr=matttbe@kernel.org; keydata= xsFNBFXj+ekBEADxVr99p2guPcqHFeI/JcFxls6KibzyZD5TQTyfuYlzEp7C7A9swoK5iCvf YBNdx5Xl74NLSgx6y/1NiMQGuKeu+2BmtnkiGxBNanfXcnl4L4Lzz+iXBvvbtCbynnnqDDqU c7SPFMpMesgpcu1xFt0F6bcxE+0ojRtSCZ5HDElKlHJNYtD1uwY4UYVGWUGCF/+cY1YLmtfb WdNb/SFo+Mp0HIt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ObzHNgAp3zy/L4lXwc6WW5vnpWAzqXFHP8D9PTpqvBALbXqL06smP47JqbyQxj Xf7D2rrPeIqbYmVY9da1KzMOVf3gReazYa89zZSdVkMojfWsbq05zwYU+SCWS3NiyF6QghbW voxbFwX1i/0xRwJiX9NNbRj1huVKQuS4W7rbWA87TrVQPXUAdkyd7FRYICNW+0gddysIwPoa KrLfx3Ba6Rpx0JznbrVOtXlihjl4KV8mtOPjYDY9u+8x412xXnlGl6AC4HLu2F3ECkamY4G6 UxejX+E6vW6Xe4n7H+rEX5UFgPRdYkS1TA/X3nMen9bouxNsvIJv7C6adZmMHqu/2azX7S7I vrxxySzOw9GxjoVTuzWMKWpDGP8n71IFeOot8JuPZtJ8omz+DZel+WCNZMVdVNLPOd5frqOv mpz0VhFAlNTjU1Vy0CnuxX3AM51J8dpdNyG0S8rADh6C8AKCDOfUstpq28/6oTaQv7QZdge0 JY6dglzGKnCi/zsmp2+1w559frz4+IC7j/igvJGX4KDDKUs0mlld8J2u2sBXv7CGxdzQoHaz lzVbFe7fduHbABmYz9cefQpO7wDE/Q== Organization: NGI0 Core In-Reply-To: <27e7304b-d485-4e01-bd47-a169c5b25849@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Paolo, Thank you for your reply! On 12/11/2025 10:24, Paolo Abeni wrote: > On 11/11/25 5:21 PM, Matthieu Baerts wrote: >> On 09/11/2025 14:53, Paolo Abeni wrote: >>> If a subflow receives data before gaining the memcg while the msk >>> socket lock is held at accept time, or the PM locks the msk socket >>> while still unaccepted and subflows push data to it at the same time, >>> the mptcp_graph_subflows() can complete with a non empty backlog. >>> >>> The msk will try to borrow such memory, but (some) of the skbs there >>> where not memcg charged. When the msk finally will return such accounted >>> memory, we should hit the same splat of #597. >>> [even if so far I was unable to replicate this scenario] >>> >>> This patch tries to address such potential issue by: >>> - preventing the subflow from queuing data into the backlog after >>> gaining the memcg. This ensure that at the end of the look all the >>> skbs in the backlog (if any) are _not_ memory accounted. >>> - mem charge the backlog to msk >>> - 'restart' the subflow and spool any data waiting there. >>> >>> Signed-off-by: Paolo Abeni >>> --- >>> net/mptcp/protocol.c | 46 ++++++++++++++++++++++++++++++++++++++++++-- >>> 1 file changed, 44 insertions(+), 2 deletions(-) >>> >>> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c >>> index 5e9325c7ea9c..d6b08e1de358 100644 >>> --- a/net/mptcp/protocol.c >>> +++ b/net/mptcp/protocol.c >>> @@ -4082,10 +4082,12 @@ static void mptcp_graph_subflows(struct sock *sk) >>> { >>> struct mptcp_subflow_context *subflow; >>> struct mptcp_sock *msk = mptcp_sk(sk); >>> + struct sock *ssk; >>> + int old_amt, amt; >>> + bool slow; >>> >>> mptcp_for_each_subflow(msk, subflow) { >>> - struct sock *ssk = mptcp_subflow_tcp_sock(subflow); >>> - bool slow; >>> + ssk = mptcp_subflow_tcp_sock(subflow); >>> >>> slow = lock_sock_fast(ssk); >>> >>> @@ -4095,8 +4097,48 @@ static void mptcp_graph_subflows(struct sock *sk) >>> if (!ssk->sk_socket) >>> mptcp_sock_graft(ssk, sk->sk_socket); >>> >>> + if (!mem_cgroup_from_sk(sk)) >> >> Should we not call mem_cgroup_sk_enabled() instead? It does this: >> >> return mem_cgroup_sockets_enabled && mem_cgroup_from_sk(sk); >> >> That's what is done in net/core/sock.c and net/ipv4/tcp_output.c. Not in >> __inet_accept(), because mem_cgroup_sockets_enabled() is checked before. >> Maybe we should do the same here? >> >> (Note that it is not clear to me if mem_cgroup can be enabled later on, >> and if yes, what should be done with existing connections.) > > It's just an additional optimization, to leverage static branch, but > it's not strictly needed. Can be added, thus. I see, thank you! While at it, should we call mem_cgroup_*() only once by using local variables? >>> + goto unlock; >>> + >>> __mptcp_inherit_cgrp_data(sk, ssk); >>> __mptcp_inherit_memcg(sk, ssk, GFP_KERNEL); >>> + >>> + /* Prevent subflows from queueing data into the backlog >>> + * as soon as cg is set; note that we can't race >>> + * with __mptcp_close_ssk setting this bit for a really >>> + * closing socket, because we hold the msk socket lock here. >>> + */ >>> + subflow->closing = 1; >>> + >>> +unlock: >>> + unlock_sock_fast(ssk, slow); >>> + } >>> + >>> + if (!mem_cgroup_from_sk(sk)) >> >> Same here? >> >>> + return; >>> + >>> + /* Charge the bl memory, note that __sk_charge accounted for >>> + * fwd memory and rmem only >>> + */ >>> + mptcp_data_lock(sk); >>> + old_amt = sk_mem_pages(sk->sk_forward_alloc + >>> + atomic_read(&sk->sk_rmem_alloc)); >>> + amt = sk_mem_pages(msk->backlog_len + sk->sk_forward_alloc + >>> + atomic_read(&sk->sk_rmem_alloc)); >> >> (Same as Geliang for the alignment here, and eventually calling >> kmem_cache_charge() like in __inet_accept()) > > This and the next are the more obscure point. I chose to not call > kmem_cache_charge() because I'm (was) a bit doubtful about such call > being legit in __inet_accept(): active (plain TCP) sockets are not > accounted, just passive ones. Re-thinking about it I guess it's better > to be consistent with TCP than trying to be smarted (history has proved > it does not work so well :-P) > > TL;DR: I'll add the missing kmem_cache_charge(); :) Indeed, safer. If it is changed in TCP, hopefully the same will be done in MPTCP side. >>> + amt -= old_amt; >>> + if (amt) >>> + mem_cgroup_sk_charge(sk, amt, GFP_ATOMIC | __GFP_NOFAIL); >> >> Just to be sure: no need to check if there was an error? It is not done >> in __inet_accept() either, so I guess no? > > The __GFP_NOFAIL flag ensures that the call can not fail. Of course, I missed that! > Adding it with > GFP_ATOMIC is at least "original" (this is the only call site with this > flags combo). In the next version I'll move the call outside the > spinlock (we are still under the msk socket lock) to replace GFP_ATOMIC > with GFP_KERNEL. Good idea! Also better to align with what is done with TCP. > Many thanks for all the review effort! That's the least I can do with all the new fixes and optimisations :) Cheers, Matt -- Sponsored by the NGI0 Core fund.