Article View: linux.kernel.netdev
Article #23572[PATCH net-next v3 3/3] tun: skip the virtio-net header parsing without IFF_VNET_HDR
From: Antonio Quartulli
Date: Fri, 27 Nov 2026 14:14
Date: Fri, 27 Nov 2026 14:14
45 lines
10509 bytes
10509 bytes
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. The check uses
the same copy of the flags that decided whether the header was read.
1.9% fewer instructions per 1400-byte UDP packet written and dropped at
the raw table, 1.1% 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 09f31faaced2..a644fab4321f 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1970,11 +1970,18 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
break;
}
- if (tun_vnet_hdr_tnl_to_skb(flags, features, skb, &hdr,
- (flags & TUN_TYPE_MASK) == IFF_TAP)) {
- atomic_long_inc(&tun->rx_frame_errors);
- err = -EINVAL;
- goto free_skb;
+ if (flags & IFF_VNET_HDR) {
+ bool has_eth = (flags & TUN_TYPE_MASK) == IFF_TAP;
+
+ if (tun_vnet_hdr_tnl_to_skb(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 ((flags & TUN_TYPE_MASK) == IFF_TAP)
--
2.56.1
Technical Details
Message-ID:
<20261127141406.651406-4-antonio@mandelbit.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372766-linux-kernel-netdev=dewy.ruReferences:
<20261127141406.651406-1-antonio@mandelbit.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372766-linux-kernel-netdev=dewy.ru From: antonio@mandelbit.com (Antonio Quartulli) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next v3 3/3] tun: skip the virtio-net header parsing without IFF_VNET_HDR Date: Fri, 27 Nov 2026 15:14:05 +0100 Organization: Usenet Network Message-ID: <20261127141406.651406-4-antonio@mandelbit.com> References: <20261127141406.651406-1-antonio@mandelbit.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="747256"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:ZAUNwUUEviUJs45taIFdZpaB+Ak= sha256:vnao0X0SRl9l+NJS/LM9GKc1xqvB4RsY0DU+hK0SZsY= sha1:CWAeDxvR2mdDc+TtluBXC5H9hu8= sha256:mjfCh2pYi8tHlokdpDmp65iZXdgGbIzgCes+JCKy0pE= 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 0CC2C125F5B; Fri, 27 Nov 2026 17:14:53 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.051 X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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=mandelbit.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 bZQTn_HV2kPy; Fri, 27 Nov 2026 17:14:50 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-372766-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=mandelbit.com X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 1A728125F5F; Fri, 27 Nov 2026 17:14:40 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id BD2E32313B; Fri, 27 Nov 2026 14:14:37 +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=1795788870; b=pU8S7JPwdBQeUd9Yih+td1lk9Cp1UGYgDc6lJk1z30f5oWIXQEheGLKNhLJnJe3NXAia kI/iiJqfr+bJN+Zxj1UyOPBtg6jY2/Omi0Xl+zNM69I/bOBWNKLLU0bCEEzAoVDJbHHiI tlDKDnhpZeJ4yPlINvRjIeBi7PvsiWWOPZUhrS0Yr/2419S2xfRnw+HI12uk8u3hiHy2O QRYbom/3XEfu/04G1NDM/6KLYlNllubA5c24ZEOTv/vywWCVpLSRL9x2Q0qyfsygQw3ik W1f8eUhKZTfRhRkqjz4lAArcygAeO7npmufC15AQkzXGylHAmsyb6h0UuhlvZmQCSoQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795788870; h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:From:To: Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding:X-Rspamd-Queue-Id; bh=gWmlZS2QEdndqaaG1v0KNH/Xqwd52KcDv0A7eCgo+VI=; b=My6eR+6Lk6hoBtCmxNno8W4zrlbp+ovZoa+8tOluJZe9U3KYefGdsFKFi7StmwVxp74v zbVivpwL1ueTPSYinwG5jepakvgIh9JgD3ZWM1A0IYPOSRgS+uk7Y5cF1PwHx57oV5NUw xRZZbtsnDo/opCvNFqFwJDd4TMUK8XxVRHSLknhZ08IVws6TObnIQe148FSZKNIKa0FUL 9U9CCxJIVCMZHHbu95U9sgDKDdIUJgSccP691vOYuWUKuO4ByzrXB5Km+axy/xZQtejbk YqpfGlJnKM87+uIzLaLwWu2KHXBAS9jJgV4E4ndCu5Xi4izXCUmSj/Api55zevei72g== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=mandelbit.com header.i=@mandelbit.com header.a=rsa-sha256 header.s=MBO0001 header.b=VI8QU8qU; dmarc=none header.from=mandelbit.com; spf=pass smtp.mailfrom=mandelbit.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 DC852606A339; Fri, 27 Nov 2026 14:14:29 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=mandelbit.com header.i=@mandelbit.com header.a=rsa-sha256 header.s=MBO0001 header.b=VI8QU8qU X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.10.208.42 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795788864; b=MKcCLLe868FaK/FYqtjDBeurfweFspWaA28S29oRnHdt14GZFKsewQQJJnMEtIgK91Fb DFvFklLd1BAAVSgrhBiF/RNWH7kwgF1AW4ok5iQttkfS3PHxWa63Wo6ym4um8g8AhgnyN VMQ2bH3uyIU5aK5lgnk5VegEtUCvpB7mcqyKblQE7lv2s6sBxOc+LbljHyde+syB8BEGy wIulxGgqWl2eMsiD3qGzV+IgkElF0O/Mskyh71xb7lWlol816lgVKqZOdqqY9O/IJK6TS KeIt0X1cBY8G2KYXAgexsqrxF46p/KTymWSfs6l9OWIhNpAHtgjfimKdSKGNWXUNmEg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795788864; h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Rspamd-Queue-Id; bh=gWmlZS2QEdndqaaG1v0KNH/Xqwd52KcDv0A7eCgo+VI=; b=NtBixonUb6k+t21P1yRI8opDtTUO9M6Qhbi4rYFX0Es8R+IgL/theiLQtyhuR0JZOUVN /ZesGY0dsmcthtHHuRp2VEgQ6TvtdG0sgYan38kN7jE/IHeSMQ6yjyufuVAmfbRbkBbLl Rs55d+siXDKAlQaSRQ6ecq7OVAW4A6n4s27hiAmwi1jTNmlyeNMFo1cnVvyxHaKP0A8+g ngX8S8yNWC8NbnaWpR0mVRbOtX/Txgg/XDwdw/Q52tO/AuT0wuPN6pEGs55BNKh3OWXWx 0/GxgnNwIvVTwpcqUc7yddiRNt48/zG3/mMNzsIarcafZYxfKgpxOX56BBbVIKCPIVA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=mandelbit.com; spf=pass smtp.mailfrom=mandelbit.com; dkim=pass header.d=mandelbit.com header.i=@mandelbit.com header.a=rsa-sha256 header.s=MBO0001 header.b=VI8QU8qU; arc=none smtp.remote-ip=195.10.208.42 X-Received: from mout-b-112.mailbox.org (mout-b-112.mailbox.org [195.10.208.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85923606A685; Fri, 27 Nov 2026 14:14:23 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 85923606A685 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mandelbit.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mandelbit.com X-Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-112.mailbox.org (Postfix) with ESMTPS id 4jbb530l8mz5vdq; Fri, 27 Nov 2026 15:14:15 +0100 (CET) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1795788855; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gWmlZS2QEdndqaaG1v0KNH/Xqwd52KcDv0A7eCgo+VI=; b=VI8QU8qUATvQCAUolKhM2vpwhS/noVVlQAVMhWsvzfu7mP6a7OUPoo2OgJIaNasesc+UEr OQWympo7Bj/EijtA5eWwdZjL4wp/Kvg1iM59gZfCIu0taU7hxzk+z+82oRwLz0QX40f/F5 DaKSqtW5JWXUYG0YBlUIMSph9o7HVFs13LNQ8CnIXN4kA20/eaDTBcWQQ3LVzkoKNuL+7K hUwepVBPEzo45KRd8PDPUFqDjPfGdEHPnUFATx/ei4Q2ICuw0lU5HWRYEMC18euOI5q9V/ dC1dbNbEAeaW68QPVSC/qKVufOI0xxKHCNZT9/H9lnR5WcbajLLqi+bwW09Nbg== X-Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of antonio@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=antonio@mandelbit.com X-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 X-Mailer: git-send-email 2.56.1 X-In-Reply-To: <20261127141406.651406-1-antonio@mandelbit.com> 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-Rspamd-Queue-Id: 4jbb530l8mz5vdq