From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380328; b=txhf98qZUOi1kYp6Go+VuUrLvHYUdRafX5fLWWG+CU8OWopTbwkmmtXwqxZDX2leNv1B hHF1cyjsnZHSLQ9QpiYkajw4oCRnJjOMyzo8p7P3RFw2jzGDsPLT7YDfLnjLG6jMO240B /mRWphdsm+p4h+2mJF/h8EhA0p3MuPiHCpKIPF6wfkU0QyFPsfIXtijbrCv4aGbsbfs/g DBoG/dj4ahcRWv8mVBpL/SWGP4vRo5jFOD0BhwSTTxBUKRW7ldOhyLvfoAIb0FFnY8fp3 RHsOwnhFarQhCsRGMdyW85UhyhBUvSvd3DZmNX89h9LxR6xDwxSJWM/Y/18o5limO8Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380328; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=CN860ikuuNs1q5/YnGi5I+Q1IUs1yGmbFKYuSKG8fZo=; b=4b21RdAa5lbuC1OrnBAtj+cCwoCZkVWhL0IzgE3OZ7RyJ96sgbBU7gzTcy7h4Fpx3umz 5y0QZXpjLgJtdSvo/cdjR4EuOgdOxowprARe+T0MXm803L0DnvNDXFMZdUYRCm8OITcyp ODm+2gyL224swJb1HJznpDaIXmkXRGKO7SWglSZT4wps7xzOWQuRBgvrUinnCYkfkpWa2 K2ftrl8y3Th3pmSAfBHKFxiqeGdBJxW2AfzqfPtCa49LOp1k66TFqENWlmosKP5f/yprU YDwUxcffgtKKRGZ2j/aHxMsGw3CCO1NIDddjvsZAT+NOWBeygGZ4ASPTB64F4nj37Kw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ctwB1Gjw; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A66B5606A322; Fri, 4 Dec 2026 10:32:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ctwB1Gjw Received: by smtp.kernel.org (Postfix) with ESMTPSA id 223ED1F00897; Fri, 4 Dec 2026 10:32:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380328; bh=CN860ikuuNs1q5/YnGi5I+Q1IUs1yGmbFKYuSKG8fZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ctwB1Gjw0P1KpedbVBX/N/vIK+TLyVlL6Pc0je9us6Az+I/vIrzsRfdFjHM9vdQ/j CaZO5KcBLg4/p9k08PtCz7C0DlNTZQwhmnZLph6HSnyi0xKCiHnyTgg6M04dyfeDvB zNONFX4hi2giEuSHzE8gtan9hBNfGaVtoAlI4vd0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Haishuang Yan , Jakub Kicinski , Sasha Levin Subject: [PATCH 7.3 185/742] net: do not run out of frags in alloc_skb_with_frags() Date: Fri, 4 Dec 2026 19:00:49 +0900 Message-ID: <20261204100639.995355736@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Haishuang Yan [ Upstream commit 5924465bb4e986eae6809c899ddaf38d3897f55d ] alloc_skb_with_frags() can need more than MAX_SKB_FRAGS frags for a data_len that passed its size check, and then fails with -ENOBUFS: - the tail is split into one frag per bit set in its page count; - after a failed high-order allocation, the order is lowered without checking that the frags left can hold the rest. tun hits this with large GSO packets from a vhost-net guest. Use one larger page for the tail when splitting it would not fit. Only lower the order if the rest still fits, else retry the same order with direct reclaim. If that retry fails too, the allocation still fails. Found while prototyping >64K TSO in a virtio-net guest. Tested with that guest, page allocation fault injection and the KUnit test in patch 2. Fixes: 09c2c90705bb ("net: allow alloc_skb_with_frags() to allocate bigger packets") Signed-off-by: Haishuang Yan Link: https://patch.msgid.link/20261116115620.18151-2-yanhaishuang@cmss.chinamobile.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/core/skbuff.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 1856aecd5558c..d87fe0ad9c103 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6861,17 +6861,40 @@ struct sk_buff *alloc_skb_with_frags(unsigned long header_len, while (data_len) { if (nr_frags == MAX_SKB_FRAGS) goto failure; - while (order && PAGE_ALIGN(data_len) < (PAGE_SIZE << order)) - order--; + if (order && PAGE_ALIGN(data_len) < (PAGE_SIZE << order)) { + unsigned long pages = DIV_ROUND_UP(data_len, PAGE_SIZE); + + /* If splitting the rest into smaller pages would need + * more frags than we have left, use one larger page. + */ + if (hweight_long(pages) > MAX_SKB_FRAGS - nr_frags) + order = order_base_2(pages); + else + order = ilog2(pages); + } if (order) { page = alloc_pages((gfp_mask & ~__GFP_DIRECT_RECLAIM) | __GFP_COMP | __GFP_NOWARN, order); - if (!page) { - order--; - continue; + if (unlikely(!page)) { + unsigned int shift = PAGE_SHIFT + order - 1; + + /* Can smaller pages hold the rest? */ + if (((data_len - 1) >> shift) + 1 <= + MAX_SKB_FRAGS - nr_frags) { + order--; + continue; + } + /* No, retry this order with direct reclaim. */ + if (!gfpflags_allow_blocking(gfp_mask)) + goto failure; + page = alloc_pages(gfp_mask | __GFP_COMP | + __GFP_NOWARN | __GFP_NORETRY, + order); + if (!page) + goto failure; } } else { page = alloc_page(gfp_mask); -- 2.53.0