Re: [PATCH net-next v2 5/9] tun: use bulk NAPI cache allocation in tun_xdp_one

From: Sebastian Andrzej Siewior

Date: Fri Dec 05 2025 - 02:58:11 EST


On 2025-12-03 15:35:24 [+0000], Jon Kohler wrote:
> Thanks, Sebastian - so if I’m reading this correct, it *is* fine to do
> the two following patterns, outside of NAPI:
>
> local_bh_disable();
> skb = napi_build_skb(buf, len);
> local_bh_enable();
>
> local_bh_disable();
> napi_consume_skb(skb, 1);
> local_bh_enable();
>
> If so, I wonder if it would be cleaner to have something like
> build_skb_bh(buf, len);
>
> consume_skb_bh(skb, 1);
>
> Then have those methods handle the local_bh enable/disable, so that
> the toggle was a property of a call, not a requirement of the call?

Having budget = 0 would be for non-NAPI users. So passing the 1 is
superfluous. You goal seems to be to re-use napi_alloc_cache. Right? And
this is better than skb_pool?

There is already napi_alloc_skb() which expects BH to be disabled and
netdev_alloc_skb() (and friends) which do disable BH if needed. I don't
see an equivalent for non-NAPI users. Haven't checked if any of these
could replace your napi_build_skb().

Historically non-NAPI users would be IRQ users and those can't do
local_bh_disable(). Therefore there is dev_kfree_skb_irq_reason() for
them. You need to delay the free for two reasons.
It seems pure software implementations didn't bother so far.

It might make sense to do napi_consume_skb() similar to
__netdev_alloc_skb() so that also budget=0 users fill the pool if this
is really a benefit.

Sebastian