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=1796383585; b=LFPEPv7qvSkQgz8cR2hMcYG6MYXok8CBpyMAKmxm4cfT7pILnALuJf7XTyjB118Nmp16 4CxFOACSbehyN3+lYriWhahW38qN7ww8AJoLSYU91alv/5UR23oDuVYOhKLq5yNOCtaVx /I9/K6tSLWiWdG6Gzvwi/hJ7MSsoZ91LLuDS4dWlpVTgnoEDc8k3bd/BEHkoO3e3h8HdW JGpP71Z2XQzNWH/tS15R4CODh0tU+e7+BslilbtHwq3TIomlDm7KaHseZrB1P03RpSCOv GCTO0j5OwElhnt0zroiK9WaE4V+wCeTydLQw5PSqDVcIIl47BAdR6Ow6olnFPZ53V1Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383585; 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=GL2fWkJ99ftQzPNZ1p5us2nWM7aBmH5HayYBp89UagM=; b=FtDDysn33Z9XOhXVEcDT6FTG4e7mKjO0TJyQ8NV7TDuCU5hAaR2b71cvC9Ob+eflM7nS 1zvgloker9cWbGF4DeTROwhPOGS6KHGX13oCbHMESoAXIrQ5OAz6/IabgQJnNod7Rj1+L 6IKlagv1JK00z/g+jT/y8hPLgXirM+1qGkLkZjSWzLGAz1eCOu+u9EaETiUkLG9/Marj9 BnM0panKiE2iP6sLxkJxh/yQvH1gMR+J1THlRCIVQqslJ5CpDf6tkLW/KHf+1RsLsvI/q lltFHKulbAkjsg1xkLjMFPQdCgv/JymcoJChHcc7v+c9s7kRBkLv9xG4a+wx+sDryYA== 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=EI7kkP+o; 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 5D4E8606A33C; Fri, 4 Dec 2026 11:26:25 +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=EI7kkP+o Received: by smtp.kernel.org (Postfix) with ESMTPSA id 937E01F00934; Fri, 4 Dec 2026 11:26:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383585; bh=GL2fWkJ99ftQzPNZ1p5us2nWM7aBmH5HayYBp89UagM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EI7kkP+oYQOijK3c2vOrt2ldv2Ad2lNPlyWZRYBnBUCoXaaveQufszW62tv9MZdR0 5AkaYmc8jmwCrNZ68uwKp3zXGkvTqCDWvbGRSa+yT8PkgMjWlD6Y0WY1Eb00iNkeEq dqgKwORhpYf2xz/fKnnqTb0p1RSH5P73HlleItfQ= 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 6.12 234/555] net: do not run out of frags in alloc_skb_with_frags() Date: Fri, 4 Dec 2026 19:04:37 +0900 Message-ID: <20261204100618.130877112@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-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 b772dd4c041f4..a218157a06a03 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6699,17 +6699,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