virtio-net: avoid unnecessary checksum calculation on guest RX
Subsystems (6)
PATCH v4 1/1 virtio-net: avoid unnecessary checksum calculation on guest RX
Commit a2fb4bc4e2a6 ("net: implement virtio helpers to handle UDP GSO tunneling.") inadvertently altered checksum offload behavior for guests not using UDP GSO tunneling.
Before, tun_put_user called tun_vnet_hdr_from_skb, which passed has_data_valid = true to virtio_net_hdr_from_skb.
After, tun_put_user began calling tun_vnet_hdr_tnl_from_skb instead, which passes has_data_valid = false into both call sites.
This caused virtio hdr flags to not include VIRTIO_NET_HDR_F_DATA_VALID for SKBs where skb->ip_summed == CHECKSUM_UNNECESSARY. As a result, guests are forced to recalculate checksums unnecessarily.
Restore the previous behavior by ensuring has_data_valid = true is passed in the !tnl_gso_type case, but only from tun side, as virtio_net_hdr_tnl_from_skb() is used also by the virtio_net driver, which in turn must not use VIRTIO_NET_HDR_F_DATA_VALID on tx.
---
v3: https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
v2: https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
v3-v4: Collect acked-by (MST, Jason) and cc stable (Jason)
v2-v3: Add net tag (whoops, sorry!)
v1-v2: Add arg to avoid conflict from driver (Paolo) and send to net
instead of net-next.
drivers/net/tun_vnet.h | 2 +- drivers/net/virtio_net.c | 3 ++- include/linux/virtio_net.h | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-)
drivers/net/tun_vnet.h +1 -1
@@ -244,7 +244,7 @@ tun_vnet_hdr_tnl_from_skb(unsigned int flags,if (virtio_net_hdr_tnl_from_skb (skb, tnl_hdr, has_tnl_offload,tun_vnet_is_little_endian (flags), - vlan_hlen)) { + vlan_hlen, true)) {struct virtio_net_hdr_v1 *hdr = &tnl_hdr->hash_hdr.hdr;struct skb_shared_info *sinfo =skb_shinfo (skb);
drivers/net/virtio_net.c +2 -1
@@ -3344,7 +3344,8 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan) hdr = &skb_vnet_common_hdr (skb)->tnl_hdr;if (virtio_net_hdr_tnl_from_skb (skb, hdr, vi->tx_tnl, -virtio_is_little_endian (vi->vdev),0 )) +virtio_is_little_endian (vi->vdev),0 , + false))return -EPROTO ;if (vi->mergeable_rx_bufs)
include/linux/virtio_net.h +4 -3
@@ -384,7 +384,8 @@ virtio_net_hdr_tnl_from_skb(const struct sk_buff *skb,struct virtio_net_hdr_v1_hash_tunnel *vhdr, bool tnl_hdr_negotiated, bool little_endian, - int vlan_hlen) + int vlan_hlen, + bool has_data_valid) { struct virtio_net_hdr *hdr = (struct virtio_net_hdr *)vhdr;unsigned int inner_nh, outer_th;
@@ -394,8 +395,8 @@ virtio_net_hdr_tnl_from_skb(const struct sk_buff *skb, tnl_gso_type =skb_shinfo (skb)->gso_type & (SKB_GSO_UDP_TUNNEL |SKB_GSO_UDP_TUNNEL_CSUM );if (!tnl_gso_type) -return virtio_net_hdr_from_skb (skb, hdr, little_endian, false, - vlan_hlen); +return virtio_net_hdr_from_skb (skb, hdr, little_endian, + has_data_valid, vlan_hlen);/* Tunnel support not negotiated but skb ask for it. */ if (!tnl_hdr_negotiated)
Signature · 1 line
2.43.0
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Wed, 26 Nov 2025 20:38:36 -0700 you wrote:
Commit
a2fb4bc4e2a6("net: implement virtio helpers to handle UDP GSO tunneling.") inadvertently altered checksum offload behavior for guests not using UDP GSO tunneling.Before,
tun_put_usercalledtun_vnet_hdr_from_skb, which passedhas_data_valid= true tovirtio_net_hdr_from_skb.[...]
Here is the summary with links:
- [net,v4] virtio-net: avoid unnecessary checksum calculation on guest RX
https://git.kernel.org/netdev/net/c/1cd1c472343b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html