From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 70E758002A for ; Thu, 19 Nov 2026 04:49:47 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AJ4lZ2V001239; Thu, 19 Nov 2026 07:47:36 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AJ4lZ2V001239 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="v+/+9fky" Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AJ4lDXw001160 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 19 Nov 2026 07:47:13 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AJ4lDXw001160 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4903fc8537aso1333013f8f.0 for ; Wed, 18 Nov 2026 20:47:13 -0800 (PST) X-Gm-Message-State: APuU4Z8yGywey0XQuzGFXZcFjaEFRl+WDg2JCBghGIkBzdV+81Rp9e39 4WB6uYY9NXmGBE1tkNOGgt4I+UeNpa5fbOcplAc5WH8NdLAIlqpeesgC3XCvnJXSqf//mLk9I08 TcqHrqfttaD3Db+YOMV62D9lL3f4e/K5ttSl8IhE/eXaD/2xjtZLiZQ== X-Gm-Gg: AZFdTZfaNab2XHKSj0nd2qQzfqBJGTF4Bi8aoGuIpu/1CaKSHwhpBjt5QJcD//jk+KW y/QVdHvtaeIFi1T9KQCF6/JuRDBsR3kKdQ9kaeqOdvQcS089XeopgOzZEYBw3/pWql1/Oe/2y+f 1Vf/EiKZjVMPmH5SGFI3hVbt5doaRppA1JaioCHgDsTvYZwPliZ5/qQ9CAqO99LCVOGdu3iX+K1 pvbv7AIBHcOu+BRfqCaBi/GJEQKy6KSf0fNkq8CBfSyvIwBSfxSLaVTooVuWdrTNkpzo5L45eZ3 gq07fxAfdpqHE4r44o4Llzjun39Sc6cK76vlxPXJsvjTJBC7E6p6Vv+VgXwHNoYPPTykt/fLGgJ DGlIHdM6Yu/gsKf17c9Af4lFJXw== X-Received: by 2002:a5d:64cf:0:b0:4a6:4862:28f5 with SMTP id ffacd0b85a97d-4a6486229b8mr9835722f8f.3.1795063633015; Wed, 18 Nov 2026 20:47:13 -0800 (PST) X-Received: by 2002:a5d:64cf:0:b0:4a6:4862:28f5 with SMTP id ffacd0b85a97d-4a6486229b8mr9835704f8f.3.1795063632528; Wed, 18 Nov 2026 20:47:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795063632; cv=none; d=google.com; s=arc-20260327; b=hLV2gtxN+P+lJ7yWbzGXEugQ0ff/mqaM5W0zEE/hYOfA5B4RTWd7EEkq1F0pZ+uTL8 VV6RbHOpczFAMJ8su/rlNe2ckW8BUGKxpEYqpYJ344fTfdwqO4209Idd6Y8lvssCpCCm A4v8UbLDM+mOc99kL5b2t18IVL1Eopcs52BUQ6paHTnxSLtJv3u5eBcSYhLTHLg0Mjto 9rhsRgoJl9m9kzHDakBr3MWJX8pJfggh129fXJP4VkqGjuhhOM5nzUl5t/bw6wd5I5LX OnnE20aBSjD/i6P2yih7u9DD/GTM9mmvOT9dgKCmVJN01S7yqpMcD7yRl0daPmjrsdzL i2Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=A1+yhzQMaIkfgIXT/GdQRNqkFgPgJhmxssSxr+FuMno=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=YE3lEDdeQLt26Na4aF9aPAjbieo5NqGKovFZsSQSROYyG0GtgSxC5HDqpJjo5jq4eh VLoyM6a+r6TVPIu6kVQ5B266duhqNSarfYZoa50YvkDnm+S49+0k9xtx9+0J9jfSzbrr qKhefXHrVHbutixXB1EsA90bHLH5PfONvukfuO20aX1tFhLexuudv/gWsJ+9TtxDuf2P d24DxcCDRDoyamW89sZfL482sspaCcPgjEKZPvc90tDw3qopqoVFwED4IcGq9DCBgwFc x7zxEDez9w+ZDkvOA3qIm9Ikk47vB89r30jfXZsIu+Ak7FsRCbSKvIjdp5Lmc5il+8Jf e4QA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b="v+/+9fky"; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-4a650d2f5a1si9704160f8f.23.2026.11.18.20.47.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 20:47:12 -0800 (PST) Received-SPF: pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b="v+/+9fky"; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=A1+yhzQMaIkfgIXT/GdQRNqkFgPgJhmxssSxr+FuMno=; b=v+/+9fky4cMy b0T15TCF8orOyjE/5d0nK8BdxrbF04adWZl38GHSMh5RSkb0SevVNgQz6Mw2nry5sAUvPTuv9sj9g kWdKWzj8TOPAJpDgW5N/lwlCYOA4yKLeENECQD1NpT+Sv8FEuKi2bNhLQyB4y2ikYp7kTBiKQOEqa YKC5YViEc+K8y53AYdWeRvYeMnhLh725TvkN9hQpKlKsnmdkLTBc99HRSPqhayq2oy6jvdhbwP+N3 ESQMCwt14GbIKIzLobIrHce/w5NuDgkCrJTNcypzDv5JNN3yms1pRZ2PAWs9v1C8OxYZ2nO/MgkQ7 WxN0mY2/5ZGDMIpgyPR+XQ==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xTtyv-004znD-0o; Thu, 19 Nov 2026 05:47:10 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Thu, 19 Nov 2026 06:35:33 +0200 Message-ID: <20261119044702.1218722-9-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261119044702.1218722-1-eva.kurchatova@virtuozzo.com> References: <20261119044702.1218722-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 8/9] ms/mptcp: borrow forward memory from subflow X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Paolo Abeni In the MPTCP receive path, we release the subflow allocated fwd memory just to allocate it again shortly after for the msk. That could increases the failures chances, especially when we will add backlog processing, with other actions could consume the just released memory before the msk socket has a chance to do the rcv allocation. Replace the skb_orphan() call with an open-coded variant that explicitly borrows, the fwd memory from the subflow socket instead of releasing it. The borrowed memory does not have PAGE_SIZE granularity; rounding to the page size will make the fwd allocated memory higher than what is strictly required and could make the incoming subflow fwd mem consistently negative. Instead, keep track of the accumulated frag and borrow the full page at subflow close time. This allow removing the last drop in the TCP to MPTCP transition and the associated, now unused, MIB. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20251121-net-next-mptcp-memcg-backlog-imp-v1-12-1f34b6c1e0b1@kernel.org Signed-off-by: Jakub Kicinski (cherry picked from commit 9db5b3cec4ec1c0cd3239689f5c8653d691a1754) Rebase note: mptcp_init_skb() is not split out of __mptcp_move_skb() in this tree, so the subflow lends and the msk borrows the forward memory there, in place of skb_orphan() and the sk_rmem_schedule() check. lent_mem_frag goes after the close_event_done bool. Here the patch comes after "ms/mptcp: implemented OoO queue pruning", which it precedes in mainline, so RcvPruned and the drop label stay for the in-sequence check of that patch. Mainline removed the counter here and brought it back with e0e4d56b0505 ("mptcp: explicitly drop over memory limits"). https://virtuozzo.atlassian.net/browse/VSTOR-155321 Feature: fix ms/net Signed-off-by: Eva Kurchatova --- net/mptcp/fastopen.c | 4 +++- net/mptcp/protocol.c | 21 ++++++++++++++------- net/mptcp/protocol.h | 28 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/net/mptcp/fastopen.c b/net/mptcp/fastopen.c index b9e451197902..82ec15bcfd7f 100644 --- a/net/mptcp/fastopen.c +++ b/net/mptcp/fastopen.c @@ -32,7 +32,8 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf /* dequeue the skb from sk receive queue */ __skb_unlink(skb, &ssk->sk_receive_queue); skb_ext_reset(skb); - skb_orphan(skb); + + mptcp_subflow_lend_fwdmem(subflow, skb); /* We copy the fastopen data, but that don't belong to the mptcp sequence * space, need to offset it in the subflow sequence, see mptcp_subflow_get_map_offset() @@ -50,6 +51,7 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf mptcp_data_lock(sk); DEBUG_NET_WARN_ON_ONCE(sock_owned_by_user_nocheck(sk)); + mptcp_borrow_fwdmem(sk, skb); skb_set_owner_r(skb, sk); __skb_queue_tail(&sk->sk_receive_queue, skb); mptcp_sk(sk)->bytes_received += skb->len; diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index e278f199a200..ff0a56db0876 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -349,13 +349,8 @@ static bool __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk, __skb_unlink(skb, &ssk->sk_receive_queue); skb_ext_reset(skb); - skb_orphan(skb); - - /* try to fetch required memory from subflow */ - if (!sk_rmem_schedule(sk, skb, skb->truesize)) { - MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RCVPRUNED); - goto drop; - } + mptcp_subflow_lend_fwdmem(subflow, skb); + mptcp_borrow_fwdmem(sk, skb); has_rxtstamp = TCP_SKB_CB(skb)->has_rxtstamp; @@ -2448,6 +2443,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, { struct mptcp_sock *msk = mptcp_sk(sk); bool dispose_it, need_push = false; + int fwd_remaining; /* Do not pass RX data to the msk, even if the subflow socket is not * going to be freed (i.e. even for the first subflow on graceful @@ -2456,6 +2452,17 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, lock_sock_nested(ssk, SINGLE_DEPTH_NESTING); subflow->closing = 1; + /* Borrow the fwd allocated page left-over; fwd memory for the subflow + * could be negative at this point, but will be reach zero soon - when + * the data allocated using such fragment will be freed. + */ + if (subflow->lent_mem_frag) { + fwd_remaining = PAGE_SIZE - subflow->lent_mem_frag; + sk_forward_alloc_add(sk, fwd_remaining); + sk_forward_alloc_add(ssk, -fwd_remaining); + subflow->lent_mem_frag = 0; + } + /* If the first subflow moved to a close state before accept, e.g. due * to an incoming reset or listener shutdown, the subflow socket is * already deleted by inet_child_forget() and the mptcp socket can't diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 282176fe111d..51a8a3357e2d 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -543,6 +543,7 @@ struct mptcp_subflow_context { bool close_event_done; /* has done the post-closed part, * protected by msk socket lock */ + u32 lent_mem_frag; u32 remote_nonce; u64 thmac; u32 local_nonce; @@ -646,6 +647,33 @@ mptcp_send_active_reset_reason(struct sock *sk) tcp_send_active_reset(sk, GFP_ATOMIC, reason); } +/* Made the fwd mem carried by the given skb available to the msk, + * To be paired with a previous mptcp_subflow_lend_fwdmem() before freeing + * the skb or setting the skb ownership. + */ +static inline void mptcp_borrow_fwdmem(struct sock *sk, struct sk_buff *skb) +{ + struct sock *ssk = skb->sk; + + /* The subflow just lend the skb fwd memory, and we know that the skb + * is only accounted on the incoming subflow rcvbuf. + */ + DEBUG_NET_WARN_ON_ONCE(skb->destructor); + skb->sk = NULL; + sk_forward_alloc_add(sk, skb->truesize); + atomic_sub(skb->truesize, &ssk->sk_rmem_alloc); +} + +static inline void +mptcp_subflow_lend_fwdmem(struct mptcp_subflow_context *subflow, + struct sk_buff *skb) +{ + int frag = (subflow->lent_mem_frag + skb->truesize) & (PAGE_SIZE - 1); + + skb->destructor = NULL; + subflow->lent_mem_frag = frag; +} + static inline u64 mptcp_subflow_get_map_offset(const struct mptcp_subflow_context *subflow) { -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel