Article View: linux.kernel.netdev
Article #12668Re: [PATCH net 1/2] net: do not run out of frags in alloc_skb_with_frags()
From: Narcisa Vasile
Date: Sun, 08 Nov 2026 08:20
Date: Sun, 08 Nov 2026 08:20
116 lines
16195 bytes
16195 bytes
On Sun, Nov 08, 2026 at 07:06:16PM +0900, Haishuang Yan wrote:
> alloc_skb_with_frags() rejects data_len above
> MAX_SKB_FRAGS * (PAGE_SIZE << order) up front, but then rounds the order
> down for the tail, so a tail of N pages is split into one frag per bit
> set in N. A data_len that passed the check can then need more than
> MAX_SKB_FRAGS frags, and the allocation fails with -ENOBUFS although
> every page allocation succeeded.
>
> With order 3 and 4K pages, a 516536 byte packet is 15 * 32K plus a 25016
> byte tail, which becomes 16K + 8K + 4K, so 18 frags are needed. Sizes
> between about 480K and 540K can be affected.
>
> tun hits this when vhost-net hands it a GSO packet of such a size from a
> guest. Nothing on the host limits the size of a guest's GSO packet to
> 64K: virtio_net_hdr has no total length, and tun_get_user() sizes the
> skb from the descriptor chain. Today's virtio-net drivers stay at 64K,
> but a guest can send bigger packets by raising its own TSO limit, and
> the host must not depend on the guest for that. Worse, vhost-net treats
> -ENOBUFS from sendmsg() as transient: handle_tx_copy() puts the
> descriptor back and retries it, so the vhost worker spins at 100% on
> the same packet and the device stops passing traffic in both
> directions. On an unmodified host, tun_get_user() returned -ENOBUFS
> about 620,000 times per second, the tap's rx_dropped counter climbed at
> the same rate, and this went on with no traffic until the VM was
> destroyed.
>
> Keep rounding the tail down when the remaining frags allow it, so no
> allocation that works today changes, and use one page rounded up for
> the whole tail otherwise. This is never larger than the full-size
> chunks already used.
>
> This was triggered while prototyping >64K TSO for virtio-net, with a
> one-line guest virtio_net change raising its TSO limit; the host was
> unmodified. The fix was tested with that reproducer and with the KUnit
> test in the next patch.
>
> Fixes: 09c2c90705bb ("net: allow alloc_skb_with_frags() to allocate bigger packets")
> Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>
> ---
> Base: net 30c71476d842 ("ipv6: Check the Home Address option again before its
> address is used"). The reproducer below was run on net-next 303d91a15925,
> where alloc_skb_with_frags() is identical. On net: KUnit net_core 20/20
> (kunit.py, UML x86_64), and allmodconfig W=1 build of net/core/ (arm64)
> with no warnings.
>
> Reproducer: x86_64 KVM host (i7-14700) running net-next 303d91a15925 with no
> local changes; vhost-net, a tap NIC with mrg_rxbuf=on and rx_queue_size=1024.
> The guest (net-next too) has a local one-line virtio_net change setting
> netif_set_tso_max_size(dev, GSO_MAX_SIZE), plus
> `ip link set dev ethX gso_max_size 524280 gso_ipv4_max_size 524280`; then
> iperf3 guest -> host.
>
> Without this patch: iperf3 fails, one vhost worker stays at 99.9% CPU,
> tun_get_user() returns -105 (31014 times in 50 ms, kretprobe), the tap's
> rx_dropped goes up by 34M during the run and keeps climbing at ~690k/s with
> no traffic, and the guest can no longer ping the host until the VM is
> destroyed. With this patch (same setup plus this patch on the host): 81
> Gbit/s, no drops, and the vhost worker is idle afterwards.
>
> net/core/skbuff.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
I think we should decouple the two parts you've pointed out:
1. For valid packets that pass the initial data_len size check,
this patch avoids running out of frags by putting the tail into one
larger block of pages instead of splitting it into several smaller blocks.
2. The vhost cpu spin: this patch fixes it for the sizes in (1), but a
modified guest can still trigger it by sending a larger frame (above
~4.75 MB on x86).
In that case, tun_alloc_skb() asks for a linear part above the
kmalloc limit. The alloc_skb() allocation in this function can never
succeed and returns -ENOBUFS, and vhost-net retries the same frame
indefinitely.
Should we also return -EMSGSIZE when header_len
is above the kmalloc limit, like it already does for an oversized
data_len? I'm not sure whether the errno change is acceptable?.
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index 8da53d5b76fc..93e7b04ddfe6 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -6902,8 +6902,18 @@ 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 = PAGE_ALIGN(data_len) >> PAGE_SHIFT;
> +
> + /* Rounding the tail down to smaller pages takes one
> + * frag per bit set in its page count. If not enough
> + * frags are left for that, use one bigger page.
> + */
nit, feel free to ignore, this might read more simply as:
/* 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) |
Technical Details
Message-ID:
<avAwu/1w6+2TJoE6@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358653-linux-kernel-netdev=dewy.ruReferences:
<20261108100617.23840-1-yanhaishuang@cmss.chinamobile.com> <20261108100617.23840-2-yanhaishuang@cmss.chinamobile.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358653-linux-kernel-netdev=dewy.ru
From: narcisav.kernel@gmail.com (Narcisa Vasile)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 1/2] net: do not run out of frags in
alloc_skb_with_frags()
Date: Sun, 8 Nov 2026 00:20:11 -0800
Organization: Usenet Network
Message-ID: <avAwu/1w6+2TJoE6@gmail.com>
References: <20261108100617.23840-1-yanhaishuang@cmss.chinamobile.com>
<20261108100617.23840-2-yanhaishuang@cmss.chinamobile.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
logging-data="90866"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:i58lj/YulBNPyh78Yd0leOzRR/c= sha256:kbGfGFQQSHF+yK3ClIOnIweiCZHRSUG/JHcwhhsWNlM=
sha1:fRaIAcyO3tucIL13uddsnHKGasM= sha256:ced7odX7WU3BT9rsZOQD2BlB6ji1BEvxYVqLcBI/h6U=
Content-Disposition: inline
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id CDA66113533; Sun, 8 Nov 2026 11:21:30 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.149
X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id xoNEwHn69-43;
Sun, 8 Nov 2026 11:21:20 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-358653-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id A918711203E; Sun, 8 Nov 2026 11:21:10 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id B3A8161583E; Sun, 8 Nov 2026 08:21:07 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1794126064;
b=XhGnh3bZfBkTHi5S6Z8KY8ip7Pm/UF1RVis+x9OIrPME5fpsgI6VQdNkKJGzu2Bg4E+3
fDhXvVqw9FLzhPGiKHPc1y/lSBiM8i+pRBa2GjG/GWK9wwhot7bz08zWRT+zH1VpJwulU
kYFaZWQ0s77wPcAg5EOJ9foGvVpQbD6K3S6EQPq467T9kjZS0e5KLzEVOSyJ3PjMrtxNq
+BGLDupXPMocKcL5aJb5yJ7ASi+39MsHPSMoJtb7+/a9897RlD+OP+NofHfPoy8qcJXLd
aofRMH8ziz3glawLNWqla0229pjImj9oDZQ4mWNl36kQ/tEufbEJPJLxiB5tC27TVMA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794126064;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:Date:From:To:Cc:Subject:Message-ID:References:X-Mailing-List:
List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
List-Owner:Precedence:MIME-Version:Content-Type:Content-Disposition:
In-Reply-To;
bh=znRaDR7z4oQEzsVvO4SttQcnEqRJogT5i5RITknD6U8=;
b=5C0W/0mBff9/OFGIkBRaQovOISH4a+2o1IB5xWTqpXCL7i47RAT8aNKMeVQR9gZuYzA2
lNqiX0iFHCKXRljqUHORQ6dAIn9THLrvx5ljxdF7XOlCsw11UoRjCsbYe5oQo125ZuJvh
aJRA2j/OdvodS/UgPeFnoXsHpQA2zSKKa6M3Fa+PoixqmuhsKZDWu7Y4wIkx+Kt2qx4jH
k/AuVFn5NVTCG0yUEX4cuzJVAGiXuW7UFQu3Wu8AqFgtYq9Y4n5uP3X4gFgLDr0G8gylK
gFA1BjkJhWwmEk+jrbeCr0lFo7CU0iLqFi+HLIqES6jibYJbodQ6EXU8MANpim76l7g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=S+lUdZGG;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 3776E606A330;
Sun, 8 Nov 2026 08:21:04 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=S+lUdZGG
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.178
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794126063;
b=Ej3eNF+vwEnK40UtynFKEbrzF/qpDifrWvkZtytDuv8CieRuDtm/7KyXBUfz4nhpMO7u
jVX6gKXK1WNDPpFskYtYXXLRg6IiPEuABvuzIW2nlOS9q2C7U0buoOpfFrHR67iXlQXvV
ehWcnyF4hv9N8XA6D0ufqw7k5HPP5Y1wRxah+dwAciF6CimubN90ARsmdzPziSWjUhwBV
7UdNG/8gixOuiiKuygtv6AtDRgFWAti/p2ea767detUB3KUoAwz2iRRFUcO28h7XZUulB
w/1CHffj1yGUQ4WVZABtD9wlqpJU8acRho/11i2lzSewqwoU5YI2qYFJ/nOcv0YxO2A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794126063;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc:
Subject:Message-ID:References:MIME-Version:Content-Type:
Content-Disposition:In-Reply-To;
bh=znRaDR7z4oQEzsVvO4SttQcnEqRJogT5i5RITknD6U8=;
b=kOv44C8qoXIHvCI+rwGUWUmVfeHdWeSbctdCXeIfn6F25QnbhBLu1vD9Z7gwcmCWUvQN
/4TgzXKfHuHdv1k/dafiiBzc27P/3MF+bo9/5YD4GQJnXLyNbnJedNfunsAt1XZxp/h7s
yRmBSBTfGIcnZ2GtrsCE2qt048cKQ/Cln9oOWW25mKo61W+xPbqxYKgPQy3295MHuBJxi
JUR+ZeZrnfkzl9WjdfgzZ27aWuYF8hFFXru1gDIwBw79F1t6O31Yr+PYVXVSRCwgr7GcA
+BAKAfyyrNlz+tjSe3s9lAmMpZjvvNMFo8OCJcFODCTEBcf9mPBYRBARk+Hg5vviWOw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=S+lUdZGG;
arc=none smtp.remote-ip=74.125.82.178
X-Received: from mail-dy1-f178.google.com (mail-dy1-f178.google.com [74.125.82.178])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7F63606A321
for <netdev@vger.kernel.org>; Sun, 8 Nov 2026 08:21:02 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E7F63606A321
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy1-f178.google.com with SMTP id 5a478bee46e88-36f6295304dso273747eec.1
for <netdev@vger.kernel.org>; Sun, 08 Nov 2026 00:21:02 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1794126062; x=1794730862; darn=vger.kernel.org;
h=in-reply-to:content-disposition:content-type:mime-version
:references:message-id:subject:cc:to:from:date:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=znRaDR7z4oQEzsVvO4SttQcnEqRJogT5i5RITknD6U8=;
b=S+lUdZGG/6N92nUw77FQqILRd8Hd8MMfNp8Nu4V7QEBCeWZbn4GjBbhObxS+s0mFfx
Ytijt0WABYyPO2LpqX+y1y6SnG8Qp+rWJ9l3cONVMRkW/VBEDETzTQVXI60ZldK49xqK
ez6Q7iEX9pObwylcu0McP/cfnST5jU7eCXs4mGDt1j2ylsDZmQ6vIAFtvmioptqtpejp
LG27bbRxdAhNuO+k6jplT5n0lGF1zE0qGoLrb7fVjcJjkk2d3kluft/SKjNmbSGHgqh8
YSPzBt5He43VCM+XtGn8NIDAZ+6tAeP5sgc3cS+kWvyd3BF0kRgrrK/63CyiQdLotdDH
hUZA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794126062; x=1794730862;
h=in-reply-to:content-disposition:content-type:mime-version
:references:message-id:subject:cc:to:from:date:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=znRaDR7z4oQEzsVvO4SttQcnEqRJogT5i5RITknD6U8=;
b=hZsmrt04ba8Rh5C3b7HiYNP0Y7hGfTzTOSdfbdh9QopP0jFJYf+oyeyor8/TIvX1z5
+Tj/roJbhbZvghLxupXf2/F25WN6zFvvTdF5AEscy7t12UG+r7OHzTNI9im+/dsNk4uA
wOYGkHNSw/PoQoWKkruGnrfNb/voAhKryEvhMYVQl+ZP6CEIYowuKALZ9cokPOghFNqR
5pM1wwv2uQPgo72YfYnhsSMlORjLGmv0hgzlaPao/zxGYMKXnO8O8FmWW3PkZ4tbViZc
3o0C/U96gZPgf1LWyKvhGsh9YnUyIlTOBseW9lVrv8hD/K7/RMzoomY1jn61NN3iKvkA
6OPQ==
X-Gm-Message-State: APuU4Z9rddYpCzSQccFUmnb821mrHlU1zQbEoPk9nght1ypDJ3De0G09
20GFkQmtl5IZqynrbNf4zIOH9qBY7MLWfgRMl2+XWEHapoB82klsje9D
X-Gm-Gg: AYBFou29bslm6uMdyjh+wqf6Tm7/jQqYeOqU6gU/tWFH4LkOR9NRumMNIZlUzl+4SwF
D1mNtOsfeyb/KWhBzB3vxQSANUnx3tYjpyG9FBFoQh6KZ0S5AdOSLHQlKm4lIytXn8UXTHbGa/9
cRRIU7jOO8v/+Ow8ohlnas3jJvM3czxh9cqx9UQB+PbBE1DcZbCmJY9OihyOIj2QkTTQcAfQkbA
ctHADNUiEFRYPgO649PFxps3rPeB2mbcH0ObvZrM8207jqzl6oQdE0N91neyk7IEW4K5Y2+2fmI
09/y+O0qqESYZDL8QRMg4hu1tzGzRD2n/Knv0exuoues7/u3iy+JDYdhkSewDvWJivM0YRllUeh
6kp74rzSbMX1WNL2+Fd09nqjpdtaI7AJ7hDe63QBQoo+FsZwpkfUB2RAMdqwkXhRZCGez5fDYxN
kw9AwtaNXCCDsFiO+/maLKlCkTlMVUQmqFWILwcFNQJt/gMwp7kD48lcD90/oitOXTkfY6qBVQw
Bgyy8nYRZvgNi+HlKzINb06ahuNwO6YL2jeePqbOR1PQs/oPBF27yVgrrBT4Ak094lNzlCrCMnp
LtajVfUD2pTSXJE69FHiQLtoX4NO
X-Received: by 2002:a05:693c:65c4:b0:36a:1f8:a56e with SMTP id 5a478bee46e88-372570db49fmr1159844eec.23.1794126061804;
Sun, 08 Nov 2026 00:21:01 -0800 (PST)
X-Received: from gmail.com ([2a03:2880:9ff:64::])
by smtp.gmail.com with ESMTPSA id 5a478bee46e88-372665db733sm3349203eec.23.2026.11.08.00.21.00
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Sun, 08 Nov 2026 00:21:01 -0800 (PST)
X-Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
willemb@google.com, mst@redhat.com, jasowangio@gmail.com,
eperezma@redhat.com, willemdebruijn.kernel@gmail.com,
linux-kernel@vger.kernel.org
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261108100617.23840-2-yanhaishuang@cmss.chinamobile.com>