Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: Make USO depend on CSUM offload

UDP segmentation offload inherently depends on checksum offload. It should
not be possible to disable checksum offload while leaving USO enabled.
Enforce this dependency in code.

There is a single tx-udp-segmentation feature flag to indicate support for
both IPv4/6, hence the devices wishing to support USO must offer checksum
offload for both IP versions.

Fixes: 10154dbded6d ("udp: Allow GSO transmit from devices with no checksum offload")
Suggested-by: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20240808-udp-gso-egress-from-tunnel-v4-1-f5c5b4149ab9@cloudflare.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Jakub Sitnicki and committed by
Jakub Kicinski
2b2bc3ba 3a3be7ff

+17 -9
+17 -9
net/core/dev.c
··· 9912 9912 } 9913 9913 } 9914 9914 9915 + static bool netdev_has_ip_or_hw_csum(netdev_features_t features) 9916 + { 9917 + netdev_features_t ip_csum_mask = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; 9918 + bool ip_csum = (features & ip_csum_mask) == ip_csum_mask; 9919 + bool hw_csum = features & NETIF_F_HW_CSUM; 9920 + 9921 + return ip_csum || hw_csum; 9922 + } 9923 + 9915 9924 static netdev_features_t netdev_fix_features(struct net_device *dev, 9916 9925 netdev_features_t features) 9917 9926 { ··· 10002 9993 features &= ~NETIF_F_LRO; 10003 9994 } 10004 9995 10005 - if (features & NETIF_F_HW_TLS_TX) { 10006 - bool ip_csum = (features & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)) == 10007 - (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM); 10008 - bool hw_csum = features & NETIF_F_HW_CSUM; 10009 - 10010 - if (!ip_csum && !hw_csum) { 10011 - netdev_dbg(dev, "Dropping TLS TX HW offload feature since no CSUM feature.\n"); 10012 - features &= ~NETIF_F_HW_TLS_TX; 10013 - } 9996 + if ((features & NETIF_F_HW_TLS_TX) && !netdev_has_ip_or_hw_csum(features)) { 9997 + netdev_dbg(dev, "Dropping TLS TX HW offload feature since no CSUM feature.\n"); 9998 + features &= ~NETIF_F_HW_TLS_TX; 10014 9999 } 10015 10000 10016 10001 if ((features & NETIF_F_HW_TLS_RX) && !(features & NETIF_F_RXCSUM)) { 10017 10002 netdev_dbg(dev, "Dropping TLS RX HW offload feature since no RXCSUM feature.\n"); 10018 10003 features &= ~NETIF_F_HW_TLS_RX; 10004 + } 10005 + 10006 + if ((features & NETIF_F_GSO_UDP_L4) && !netdev_has_ip_or_hw_csum(features)) { 10007 + netdev_dbg(dev, "Dropping USO feature since no CSUM feature.\n"); 10008 + features &= ~NETIF_F_GSO_UDP_L4; 10019 10009 } 10020 10010 10021 10011 return features;