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=1796381918; b=OARLUuvJIu2A4KCVDwvtxmZWJzm0cWjhufkgbnbIFI9aqa8CLAvgyWpfU4MkHDpLI/5P EJrFeEsQR8k2brdvDN8McwcmOB1SsJRT2sLtZ3Rg40C75AjguRzuXybpEzYNStGuSSMMA rluQSQg/EUR9dN2K+umczwxfe2oF8iXPy34FcqQ3J+e+oXAc06W05DuCnL0ztv3fL8iF+ GCtFgW7Pk/RFgP7o2ig0zHCPXIB2F/dlGUCyP0PtIwrZsDrhAWKz+kd7T6dCRbDRIb61U azH6sIDOXEpBm5df8oB7e0rgOkIEYsz43VtST34eSEbm3n6Q4sJUsh34ROYJIhI28nQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381918; 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=Sp4SiRr1CyVriaYOqeqFgiTKbXhO43bXIla2zg3GamM=; b=ecr3Ii+6rwoRpC7XXQZm4f3MP1jViLoXjXCLKy6mLNjk5HB+tfpYvtZOcuoXGmEnE8F4 ctuV9Lz/hFrqeA7hNr9qrfi9LPtoYAE7n+haY/wSQ5qY3qrQX4DyTJZozqaOjZ8WYgkoT 7soFxPf7zeLbojaJqrCbl6euX10ezpLdyOlkQKA9y5lWcM9tQTM1kIiSfxFujcG9f5tGW BmfSh4QdkYGbCq3pAk4GDm7RbOddGJoJwQZFrDgptZMZpKuWNU7KT1Xi+T49bAj0V6Wbb EFulz1uXQFo4R4gR7IjXKV1Qv3oSk49nY18nDOUEw55CWox9ELauoGPo9q/XTupPITQ== 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=gsee8jdu; 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 462C0606A32D; Fri, 4 Dec 2026 10:58:38 +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=gsee8jdu Received: by smtp.kernel.org (Postfix) with ESMTPSA id B18011F000C2; Fri, 4 Dec 2026 10:58:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381918; bh=Sp4SiRr1CyVriaYOqeqFgiTKbXhO43bXIla2zg3GamM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gsee8jduQzjMlSMHiabHfJP6cCfebTZuwcFwG7DaoBQSAM4kLvY2LEYRPddae2amj LMOZM3bG1zdfU3g9WJ1hZA9iux/8UJhvaA7jdn3QKrLaYN0xDY/yElfFdxaK4I3KQd OgV6FMIfCT9PmnxvBgk9h7/ZRTNVmrm+ys5/+d8o= 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.18 227/703] net: do not run out of frags in alloc_skb_with_frags() Date: Fri, 4 Dec 2026 19:02:06 +0900 Message-ID: <20261204100633.866249030@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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 27eb14c2b330f..7d05b11c9880f 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6769,17 +6769,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