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=1796386356; b=2zZorCjGjFbnoruMDT+ZWc2JrTbtpxEJkiyS0IokNSmHNVYLH2IRw+1CjbMVOOP/91tx vv1chNAPy3R6M03kFT8b8Ax34jjZhie0kL7Y5tRh0+b1dpc+KmkgMq3AYE7BDNuGODoMT Q+Zp1wLwwNvykZ9j6BV6vVEb0YMNmPzQkVvfwhMFxX00IqCG49AM1AVIA9E0lsinrCr3o mUhyRCMITSO33VP3m+OpaU2gMxlMhwWepgVmvQmvA/dom2yV/pdngfCS4wLydaJL2Q9V9 WcJeDiYe/B+nEd4mjHtzXVk6IJubYzzErXYNWKeTQyfG/t/qKRjAoYOhMXDLw7TNXiw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386356; 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=GBpS5SmBJzVH/SoFrkuowUkKwkcE0jer9vgg/cYLVnA=; b=XDcHxg4SLp8eUOfoqZyZWbrNdMD4wtIODqxrBY6efOB6fkRK93dfzMbOFxnt8lLnjUj6 juLrJOSKv+xe4ZaCokAcMsu9DFYxEA7l7M7mdbMMzWJk1AAWRVxsYtVYQkl8/l6YEp714 FcdmqB84r9qSydPsaHHpQ4lKyrjLZq6z/zeuMHmLAHLESYFWg3c6mdiAHXui5A0CiAp4r M7+U4HZweBwZDEczDYxz6a6FdMObpPPF0ijQtMKvOjNnxjm9B9FRp3lswyJKmbq5i2EzU Ipcfpp1fCKpVtz7zwO083avdp2w+Y+GC0GAGSulwyB8DKfQm53xUjoCoj3BVabHRHuQ== 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="itqhWG/g"; 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 0F93B606A336; Fri, 4 Dec 2026 12:12:36 +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=itqhWG/g Received: by smtp.kernel.org (Postfix) with ESMTPSA id 318AE1F0092C; Fri, 4 Dec 2026 12:12:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386355; bh=GBpS5SmBJzVH/SoFrkuowUkKwkcE0jer9vgg/cYLVnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=itqhWG/gAsJd/RzWbP5HkICy4MDBjcRn8J2uYqUuRtAtZm6lvDzRioyH5uUREI5bA s11tvjuxr/V9ewnq3mLbqFTIUU+s1sbEW1GueSA3iQXY+aYXnP1odJOI4CQI4VwMVe RUumd8mYTDgXPNkpwCTYr8t3zsSl5BlaUmIY01CQ= 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.6 0927/1167] net: do not run out of frags in alloc_skb_with_frags() Date: Fri, 4 Dec 2026 19:05:54 +0900 Message-ID: <20261204100726.339765663@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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 6.6-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 ba3ed28fea478..ef8e2c8fa028f 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6385,17 +6385,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