Skip to contentSkip to conversation

virtio-net: avoid unnecessary checksum calculation on guest RX

PATCH Superseded Jon Kohler 3 participants 9 messages Nov 25, 2025 – Nov 26, 2025

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jon Kohler

author
#0 lore raw

PATCH 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.

Cc Paolo Abeni <[email protected]>
Fixes a2fb4bc4e2a6 ("net: implement virtio helpers to handle UDP GSO tunneling.")
---
 include/linux/virtio_net.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/virtio_net.h +1 -1
index b673c31569f3..570c6dd1666d 100644
@@ -394,7 +394,7 @@ 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,
+		return virtio_net_hdr_from_skb(skb, hdr, little_endian, true,
 					       vlan_hlen);
 
 	/* Tunnel support not negotiated but skb ask for it. */
Signature · 1 line
2.43.0
maintainer
#1 lore raw

CC netdev

Quoted 29 lines · Jon Kohler

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.

Cc Paolo Abeni <[email protected]>
Fixes a2fb4bc4e2a6 ("net: implement virtio helpers to handle UDP GSO tunneling.")
---
 include/linux/virtio_net.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/virtio_net.h +0 -0
index b673c31569f3..570c6dd1666d 100644

include/linux/virtio_net.h virtio_net_hdr_tnl_from_skb(const struct sk_buff *skb, · line 400

Quoted 8 lines
include/linux/virtio_net.h +1 -1
@@ -394,7 +394,7 @@ 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,
+		return virtio_net_hdr_from_skb(skb, hdr, little_endian, true,
 					       vlan_hlen);
 
 	/* Tunnel support not negotiated but skb ask for it. */

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.

I think you need to add another argument to virtio_net_hdr_tnl_from_skb(), or possibly implement a separate helper to take care of csum offload - the symmetric of virtio_net_handle_csum_offload().

Also you need to CC netdev, otherwise the patch will not be processed by patchwork.

/P

maintainer
#2 lore raw
Quoted 42 lines · Paolo Abeni
Quoted 29 lines · Jon Kohler

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.

Cc Paolo Abeni <[email protected]>
Fixes a2fb4bc4e2a6 ("net: implement virtio helpers to handle UDP GSO tunneling.")
---
 include/linux/virtio_net.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/virtio_net.h +0 -0
index b673c31569f3..570c6dd1666d 100644

include/linux/virtio_net.h virtio_net_hdr_tnl_from_skb(const struct sk_buff *skb, · line 400

Quoted 8 lines
include/linux/virtio_net.h +1 -1
@@ -394,7 +394,7 @@ 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,
+		return virtio_net_hdr_from_skb(skb, hdr, little_endian, true,
 					       vlan_hlen);
 
 	/* Tunnel support not negotiated but skb ask for it. */

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.

Quoted 7 lines

I think you need to add another argument to virtio_net_hdr_tnl_from_skb(), or possibly implement a separate helper to take care of csum offload - the symmetric of virtio_net_handle_csum_offload().

Also you need to CC netdev, otherwise the patch will not be processed by patchwork.

whoops... I almost forgot... this is 'net' material, the subj prefix should be adjusted accordingly.

Thanks,

Paolo

author
#3 lore raw
In reply to Paolo Abeni
Quoted 5 lines · Paolo Abeni

CC netdev

Thats odd, I used git send-email --to-cmd='./scripts/get_maintainer.pl, but it looks like in MAINTAINERS, that only would have hit VIRTIO CORE AND NET DRIVERS, which does not include netdev@

Should that have ?
L: [email protected] <mailto:[email protected]>

Said another way, should all changes to include/linux/virtio_net.h be cc’d to netdev DL?

I suspect the answer is yes, I’ll send a patch for that in the interest of not having this issue again :)

Quoted 38 lines · Jon Kohler
Quoted 36 lines

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.

Cc Paolo Abeni <[email protected]>
Fixes a2fb4bc4e2a6 ("net: implement virtio helpers to handle UDP GSO tunneling.")

---
include/linux/virtio_net.h | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/virtio_net.h +0 -0
index b673c31569f3..570c6dd1666d 100644
@@ -394,7 +394,7 @@ 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,
+ return virtio_net_hdr_from_skb(skb, hdr, little_endian, true,
       vlan_hlen);
Quoted 4 lines
Quoted 1 line

/* Tunnel support not negotiated but skb ask for it. */

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.

Ah! Good eye, I’ll see what trouble I can get into and send a v2

Quoted 10 lines

I think you need to add another argument to virtio_net_hdr_tnl_from_skb(), or possibly implement a separate helper to take care of csum offload - the symmetric of virtio_net_handle_csum_offload().

Also you need to CC netdev, otherwise the patch will not be processed by patchwork.

/P

No problems on cc’ing netdev, just didn’t realize this one header didn’t auto cc the list. Will keep an eye on that, and happy to send a patch to MAINTAINERS file for discussion.

#4 lore raw
Quoted 10 lines · Jon Kohler
Quoted 5 lines · Paolo Abeni

CC netdev

Thats odd, I used git send-email --to-cmd='./scripts/get_maintainer.pl, but it looks like in MAINTAINERS, that only would have hit VIRTIO CORE AND NET DRIVERS, which does not include netdev@

Quoted 8 lines

Should that have ?
L: [email protected] <mailto:[email protected]>

Said another way, should all changes to include/linux/virtio_net.h be cc’d to netdev DL?

I suspect the answer is yes, I’ll send a patch for that in the interest of not having this issue again :)

I think yes. But only virtio net not core. I guess we should split net from core then.

Quoted 58 lines
Quoted 38 lines · Jon Kohler
Quoted 36 lines

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.

Cc Paolo Abeni <[email protected]>
Fixes a2fb4bc4e2a6 ("net: implement virtio helpers to handle UDP GSO tunneling.")

---
include/linux/virtio_net.h | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/virtio_net.h +0 -0
index b673c31569f3..570c6dd1666d 100644
@@ -394,7 +394,7 @@ 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,
+ return virtio_net_hdr_from_skb(skb, hdr, little_endian, true,
       vlan_hlen);
Quoted 4 lines
Quoted 1 line

/* Tunnel support not negotiated but skb ask for it. */

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.

Ah! Good eye, I’ll see what trouble I can get into and send a v2

Quoted 10 lines

I think you need to add another argument to virtio_net_hdr_tnl_from_skb(), or possibly implement a separate helper to take care of csum offload - the symmetric of virtio_net_handle_csum_offload().

Also you need to CC netdev, otherwise the patch will not be processed by patchwork.

/P

No problems on cc’ing netdev, just didn’t realize this one header didn’t auto cc the list. Will keep an eye on that, and happy to send a patch to MAINTAINERS file for discussion.

maintainer
#5 lore raw
In reply to Jon Kohler
Quoted 7 lines · Jon Kohler
Quoted 3 lines · Paolo Abeni

CC netdev

Thats odd, I used git send-email --to-cmd='./scripts/get_maintainer.pl, but it looks like in MAINTAINERS, that only would have hit VIRTIO CORE AND NET DRIVERS,

?!? not here:

./scripts/get_maintainer.pl drivers/net/virtio_net.c
"Michael S. Tsirkin" <[email protected]> (maintainer:VIRTIO CORE AND NET DRIVERS)
Jason Wang <[email protected]> (maintainer:VIRTIO CORE AND NET DRIVERS) Xuan Zhuo <[email protected]> (reviewer:VIRTIO CORE AND NET DRIVERS)
"Eugenio Pérez" <[email protected]> (reviewer:VIRTIO CORE AND NET DRIVERS) Andrew Lunn <[email protected]> (maintainer:NETWORKING DRIVERS) "David S. Miller" <[email protected]> (maintainer:NETWORKING DRIVERS) Eric Dumazet <[email protected]> (maintainer:NETWORKING DRIVERS) Jakub Kicinski <[email protected]> (maintainer:NETWORKING DRIVERS) Paolo Abeni <[email protected]> (maintainer:NETWORKING DRIVERS) [email protected] (open list:VIRTIO CORE AND NET DRIVERS) [email protected] (open list:NETWORKING DRIVERS) [email protected] (open list)

The "NETWORKING DRIVER" entry should catch even virtio_net. Something odd in your setup?!?

BTW, this is a bit too late, but you should wait at least 24h before reposting on netdev:

https://elixir.bootlin.com/linux/v6.17.9/source/Documentation/process/maintainer-netdev.rst#L422

/P

#6 lore raw
Quoted 5 lines · Paolo Abeni
Quoted 4 lines · Jon Kohler
Quoted 3 lines · Paolo Abeni

CC netdev

Quoted 7 lines
Quoted 3 lines

Thats odd, I used git send-email --to-cmd='./scripts/get_maintainer.pl, but it looks like in MAINTAINERS, that only would have hit VIRTIO CORE AND NET DRIVERS,

?!? not here:

./scripts/get_maintainer.pl drivers/net/virtio_net.c

yes but not include/linux/virtio_net.h

Quoted 24 lines

"Michael S. Tsirkin" <[email protected]> (maintainer:VIRTIO CORE AND NET DRIVERS)
Jason Wang <[email protected]> (maintainer:VIRTIO CORE AND NET DRIVERS) Xuan Zhuo <[email protected]> (reviewer:VIRTIO CORE AND NET DRIVERS)
"Eugenio Pérez" <[email protected]> (reviewer:VIRTIO CORE AND NET DRIVERS) Andrew Lunn <[email protected]> (maintainer:NETWORKING DRIVERS) "David S. Miller" <[email protected]> (maintainer:NETWORKING DRIVERS) Eric Dumazet <[email protected]> (maintainer:NETWORKING DRIVERS) Jakub Kicinski <[email protected]> (maintainer:NETWORKING DRIVERS) Paolo Abeni <[email protected]> (maintainer:NETWORKING DRIVERS) [email protected] (open list:VIRTIO CORE AND NET DRIVERS) [email protected] (open list:NETWORKING DRIVERS) [email protected] (open list)

The "NETWORKING DRIVER" entry should catch even virtio_net. Something odd in your setup?!?

BTW, this is a bit too late, but you should wait at least 24h before reposting on netdev:

https://elixir.bootlin.com/linux/v6.17.9/source/Documentation/process/maintainer-netdev.rst#L422

/P

author
#7 lore raw
Quoted 14 lines · Michael S. Tsirkin
Quoted 9 lines · Paolo Abeni
Quoted 7 lines · Jon Kohler
Quoted 3 lines · Paolo Abeni

CC netdev

Thats odd, I used git send-email --to-cmd='./scripts/get_maintainer.pl, but it looks like in MAINTAINERS, that only would have hit VIRTIO CORE AND NET DRIVERS,

Quoted 5 lines
Quoted 3 lines

?!? not here:

./scripts/get_maintainer.pl drivers/net/virtio_net.c

yes but not include/linux/virtio_net.h

Indeed! This fell thru a very small gap, will be fixed now in the MAINTAINERS update I sent.

Small side note: the virtio_blk.c is a duplicate within core, it isn’t hurting anything, but could be cleaned up. I left it as-is for now.

author
#8 lore raw
In reply to Paolo Abeni
Quoted 31 lines · Paolo Abeni
Quoted 7 lines · Jon Kohler
Quoted 3 lines · Paolo Abeni

CC netdev

Thats odd, I used git send-email --to-cmd='./scripts/get_maintainer.pl, but it looks like in MAINTAINERS, that only would have hit VIRTIO CORE AND NET DRIVERS,

?!? not here:

./scripts/get_maintainer.pl drivers/net/virtio_net.c
"Michael S. Tsirkin" <[email protected]> (maintainer:VIRTIO CORE AND NET DRIVERS)
Jason Wang <[email protected]> (maintainer:VIRTIO CORE AND NET DRIVERS) Xuan Zhuo <[email protected]> (reviewer:VIRTIO CORE AND NET DRIVERS)
"Eugenio Pérez" <[email protected]> (reviewer:VIRTIO CORE AND NET DRIVERS) Andrew Lunn <[email protected]> (maintainer:NETWORKING DRIVERS) "David S. Miller" <[email protected]> (maintainer:NETWORKING DRIVERS) Eric Dumazet <[email protected]> (maintainer:NETWORKING DRIVERS) Jakub Kicinski <[email protected]> (maintainer:NETWORKING DRIVERS) Paolo Abeni <[email protected]> (maintainer:NETWORKING DRIVERS) [email protected] (open list:VIRTIO CORE AND NET DRIVERS) [email protected] (open list:NETWORKING DRIVERS) [email protected] (open list)

Quoted 2 lines

The "NETWORKING DRIVER" entry should catch even virtio_net. Something odd in your setup?!?

Literally all I’ve got is a clone of net-next and using get_maintainer.pl but yea the issue is the header-only change. I have a knack for falling exactly into these sorts of process holes :) It’ll be a good cleanup anyhow

Quoted 3 lines

BTW, this is a bit too late, but you should wait at least 24h before reposting on netdev:

Thanks for the guidance again, I’ll be sure to pace things out if/when I find myself in this situation again! I appreciate the help