From: willemb@google.com
To: Antonio Quartulli <antonio@mandelbit.com>,
willemdebruijn.kernel@gmail.com, jasowangio@gmail.com
Cc: Antonio Quartulli <antonio@mandelbit.com>,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, ast@kernel.org,
daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
sdf@fomichev.me, netdev@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH net-next v2 2/2] tun: skip the virtio-net header parsing without IFF_VNET_HDR
Date: Thu, 26 Nov 2026 13:48:59 -0500 [thread overview]
Message-ID: <willemb.880316e8f949@google.com> (raw)
In-Reply-To: <20261124235959.1141963-3-antonio@mandelbit.com>
Antonio Quartulli wrote:
> Without IFF_VNET_HDR, tun_get_user() still passes an all-zero header to
> tun_vnet_hdr_tnl_to_skb(), which then only resets the MAC header. The
> parser is not inlined, so that costs two nested calls per packet. Reset
> the MAC header directly, as tap_get_user() already does.
> 2.0% fewer instructions per 1400-byte UDP packet written and dropped at
> the raw table, 1.2% fewer when forwarded (qemu -icount, x86_64).
> Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
> ---
> drivers/net/tun.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index 408bb0b40348..79aaadd9a2aa 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1951,11 +1951,18 @@ static ssize_t tun_get_user(struct tun_struct
> *tun, struct tun_file *tfile,
> break;
> }
> - if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, &hdr,
> - (tun->flags & TUN_TYPE_MASK) == IFF_TAP)) {
> - atomic_long_inc(&tun->rx_frame_errors);
> - err = -EINVAL;
> - goto free_skb;
> + if (tun->flags & IFF_VNET_HDR) {
Checking tun->flags & IFF_VNET_HDR a second time here is not tied to the
earlier check at line 1832 and introduces a narrow TOCTOU race with
tun_set_iff()
snapshot `unsigned int flags = READ_ONCE(tun->flags);` once at the
start of tun_get_user()
> + bool has_eth = (tun->flags & TUN_TYPE_MASK) == IFF_TAP;
> +
> + if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, &hdr,
> + has_eth)) {
> + atomic_long_inc(&tun->rx_frame_errors);
> + err = -EINVAL;
> + goto free_skb;
> + }
> + } else {
> + /* a zero hdr would only reset the MAC header */
> + skb_reset_mac_header(skb);
> }
> if ((tun->flags & TUN_TYPE_MASK) == IFF_TAP)
> --
> 2.56.1
next prev parent reply other threads:[~2026-11-26 18:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 23:59 [PATCH net-next v2 0/2] tun: trim per-packet work on the write path Antonio Quartulli
2026-11-24 23:59 ` [PATCH net-next v2 1/2] tun: don't disable BHs for the XDP program check of every packet Antonio Quartulli
2026-11-24 23:59 ` [PATCH net-next v2 2/2] tun: skip the virtio-net header parsing without IFF_VNET_HDR Antonio Quartulli
2026-11-26 18:48 ` willemb [this message]
2026-11-27 13:26 ` Antonio Quartulli
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=willemb.880316e8f949@google.com \
--to=willemb@google.com \
--cc=andrew+netdev@lunn.ch \
--cc=antonio@mandelbit.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hawk@kernel.org \
--cc=jasowangio@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=willemdebruijn.kernel@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.