From: Narcisa Vasile <narcisav.kernel@gmail.com>
To: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>
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
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 [thread overview]
Message-ID: <avAwu/1w6+2TJoE6@gmail.com> (raw)
In-Reply-To: <20261108100617.23840-2-yanhaishuang@cmss.chinamobile.com>
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) |
next prev parent reply other threads:[~2026-11-08 8:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-08 10:06 [PATCH net 0/2] " Haishuang Yan
2026-11-08 10:06 ` [PATCH net 1/2] " Haishuang Yan
2026-11-08 8:20 ` Narcisa Vasile [this message]
2026-11-08 10:06 ` [PATCH net 2/2] net: add a KUnit test for the alloc_skb_with_frags() tail split Haishuang Yan
2026-11-08 8:24 ` Narcisa Vasile
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=avAwu/1w6+2TJoE6@gmail.com \
--to=narcisav.kernel@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=eperezma@redhat.com \
--cc=horms@kernel.org \
--cc=jasowangio@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
--cc=willemdebruijn.kernel@gmail.com \
--cc=yanhaishuang@cmss.chinamobile.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®