611-02-v6.11-net-Make-USO-depend-on-CSUM-offload.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. From: Jakub Sitnicki <[email protected]>
  2. Date: Thu, 8 Aug 2024 11:56:21 +0200
  3. Subject: [PATCH] net: Make USO depend on CSUM offload
  4. UDP segmentation offload inherently depends on checksum offload. It should
  5. not be possible to disable checksum offload while leaving USO enabled.
  6. Enforce this dependency in code.
  7. There is a single tx-udp-segmentation feature flag to indicate support for
  8. both IPv4/6, hence the devices wishing to support USO must offer checksum
  9. offload for both IP versions.
  10. Fixes: 10154dbded6d ("udp: Allow GSO transmit from devices with no checksum offload")
  11. Suggested-by: Willem de Bruijn <[email protected]>
  12. Signed-off-by: Jakub Sitnicki <[email protected]>
  13. Reviewed-by: Willem de Bruijn <[email protected]>
  14. Link: https://patch.msgid.link/20240808-udp-gso-egress-from-tunnel-v4-1-f5c5b4149ab9@cloudflare.com
  15. Signed-off-by: Jakub Kicinski <[email protected]>
  16. ---
  17. --- a/net/core/dev.c
  18. +++ b/net/core/dev.c
  19. @@ -9761,6 +9761,15 @@ static void netdev_sync_lower_features(s
  20. }
  21. }
  22. +static bool netdev_has_ip_or_hw_csum(netdev_features_t features)
  23. +{
  24. + netdev_features_t ip_csum_mask = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
  25. + bool ip_csum = (features & ip_csum_mask) == ip_csum_mask;
  26. + bool hw_csum = features & NETIF_F_HW_CSUM;
  27. +
  28. + return ip_csum || hw_csum;
  29. +}
  30. +
  31. static netdev_features_t netdev_fix_features(struct net_device *dev,
  32. netdev_features_t features)
  33. {
  34. @@ -9842,15 +9851,9 @@ static netdev_features_t netdev_fix_feat
  35. features &= ~NETIF_F_LRO;
  36. }
  37. - if (features & NETIF_F_HW_TLS_TX) {
  38. - bool ip_csum = (features & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)) ==
  39. - (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
  40. - bool hw_csum = features & NETIF_F_HW_CSUM;
  41. -
  42. - if (!ip_csum && !hw_csum) {
  43. - netdev_dbg(dev, "Dropping TLS TX HW offload feature since no CSUM feature.\n");
  44. - features &= ~NETIF_F_HW_TLS_TX;
  45. - }
  46. + if ((features & NETIF_F_HW_TLS_TX) && !netdev_has_ip_or_hw_csum(features)) {
  47. + netdev_dbg(dev, "Dropping TLS TX HW offload feature since no CSUM feature.\n");
  48. + features &= ~NETIF_F_HW_TLS_TX;
  49. }
  50. if ((features & NETIF_F_HW_TLS_RX) && !(features & NETIF_F_RXCSUM)) {
  51. @@ -9858,6 +9861,11 @@ static netdev_features_t netdev_fix_feat
  52. features &= ~NETIF_F_HW_TLS_RX;
  53. }
  54. + if ((features & NETIF_F_GSO_UDP_L4) && !netdev_has_ip_or_hw_csum(features)) {
  55. + netdev_dbg(dev, "Dropping USO feature since no CSUM feature.\n");
  56. + features &= ~NETIF_F_GSO_UDP_L4;
  57. + }
  58. +
  59. return features;
  60. }