Skip to contentSkip to conversation

bonding: Correctly support GSO ESP offload

PATCH Superseded Cosmin Ratiu 2 participants 4 messages Jan 24, 2025

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bonding: Correctly support GSO ESP offload

The referenced fix is incomplete. It correctly computes bond_dev->gso_partial_features across slaves, but unfortunately netdev_fix_features discards gso_partial_features from the feature set if NETIF_F_GSO_PARTIAL isn't set in bond_dev->features.

This is visible with ethtool -k bond0 | grep esp:
tx-esp-segmentation: off [requested on]
esp-hw-offload: on
esp-tx-csum-hw-offload: on

This patch reworks the bonding GSO offload support by:
- making aggregating gso_partial_features across slaves similar to the other feature sets (this part is a no-op).
- advertising the default partial gso features on empty bond devs, same as with other feature sets (also a no-op).
- adding NETIF_F_GSO_PARTIAL to hw_enc_features filtered across slaves.
- adding NETIF_F_GSO_PARTIAL to features in bond_setup()

With all of these, 'ethtool -k bond0 | grep esp' now reports:
tx-esp-segmentation: on
esp-hw-offload: on
esp-tx-csum-hw-offload: on

Fixes 4861333b4217 ("bonding: add ESP offload features when slaves support")
---
 drivers/net/bonding/bond_main.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/net/bonding/bond_main.c +10 -9
index 7b78c2bada81..e45bba240cbc 100644
@@ -1538,17 +1538,20 @@ static netdev_features_t bond_fix_features(struct net_device *dev,
 				 NETIF_F_HIGHDMA | NETIF_F_LRO)
 
 #define BOND_ENC_FEATURES	(NETIF_F_HW_CSUM | NETIF_F_SG | \
-				 NETIF_F_RXCSUM | NETIF_F_GSO_SOFTWARE)
+				 NETIF_F_RXCSUM | NETIF_F_GSO_SOFTWARE | \
+				 NETIF_F_GSO_PARTIAL)
 
 #define BOND_MPLS_FEATURES	(NETIF_F_HW_CSUM | NETIF_F_SG | \
 				 NETIF_F_GSO_SOFTWARE)
 
+#define BOND_GSO_PARTIAL_FEATURES (NETIF_F_GSO_ESP)
+
 
 static void bond_compute_features(struct bonding *bond)
 {
+	netdev_features_t gso_partial_features = BOND_GSO_PARTIAL_FEATURES;
 	unsigned int dst_release_flag = IFF_XMIT_DST_RELEASE |
 					IFF_XMIT_DST_RELEASE_PERM;
-	netdev_features_t gso_partial_features = NETIF_F_GSO_ESP;
 	netdev_features_t vlan_features = BOND_VLAN_FEATURES;
 	netdev_features_t enc_features  = BOND_ENC_FEATURES;
 #ifdef CONFIG_XFRM_OFFLOAD
@@ -1582,8 +1585,9 @@ static void bond_compute_features(struct bonding *bond)
 							  BOND_XFRM_FEATURES);
 #endif /* CONFIG_XFRM_OFFLOAD */
 
-		if (slave->dev->hw_enc_features & NETIF_F_GSO_PARTIAL)
-			gso_partial_features &= slave->dev->gso_partial_features;
+		gso_partial_features = netdev_increment_features(gso_partial_features,
+								 slave->dev->gso_partial_features,
+								 BOND_GSO_PARTIAL_FEATURES);
 
 		mpls_features = netdev_increment_features(mpls_features,
 							  slave->dev->mpls_features,
@@ -1598,12 +1602,8 @@ static void bond_compute_features(struct bonding *bond)
 	}
 	bond_dev->hard_header_len = max_hard_header_len;
 
-	if (gso_partial_features & NETIF_F_GSO_ESP)
-		bond_dev->gso_partial_features |= NETIF_F_GSO_ESP;
-	else
-		bond_dev->gso_partial_features &= ~NETIF_F_GSO_ESP;
-
 done:
+	bond_dev->gso_partial_features = gso_partial_features;
 	bond_dev->vlan_features = vlan_features;
 	bond_dev->hw_enc_features = enc_features | NETIF_F_GSO_ENCAP_ALL |
 				    NETIF_F_HW_VLAN_CTAG_TX |
@@ -6046,6 +6046,7 @@ void bond_setup(struct net_device *bond_dev)
 	bond_dev->hw_features |= NETIF_F_GSO_ENCAP_ALL;
 	bond_dev->features |= bond_dev->hw_features;
 	bond_dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX;
+	bond_dev->features |= NETIF_F_GSO_PARTIAL;
 #ifdef CONFIG_XFRM_OFFLOAD
 	bond_dev->hw_features |= BOND_XFRM_FEATURES;
 	/* Only enable XFRM features if this is an active-backup config */
Signature · 1 line
2.45.0
#1 lore raw
Quoted 47 lines · Cosmin Ratiu
---
 drivers/net/bonding/bond_main.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/net/bonding/bond_main.c +8 -4
index 7b78c2bada81..e45bba240cbc 100644
@@ -1538,17 +1538,20 @@ static netdev_features_t bond_fix_features(struct net_device *dev,
 				 NETIF_F_HIGHDMA | NETIF_F_LRO)
 
 #define BOND_ENC_FEATURES	(NETIF_F_HW_CSUM | NETIF_F_SG | \
-				 NETIF_F_RXCSUM | NETIF_F_GSO_SOFTWARE)
+				 NETIF_F_RXCSUM | NETIF_F_GSO_SOFTWARE | \
+				 NETIF_F_GSO_PARTIAL)
 
 #define BOND_MPLS_FEATURES	(NETIF_F_HW_CSUM | NETIF_F_SG | \
 				 NETIF_F_GSO_SOFTWARE)
 
+#define BOND_GSO_PARTIAL_FEATURES (NETIF_F_GSO_ESP)
+
 
 static void bond_compute_features(struct bonding *bond)
 {
+	netdev_features_t gso_partial_features = BOND_GSO_PARTIAL_FEATURES;
 	unsigned int dst_release_flag = IFF_XMIT_DST_RELEASE |
 					IFF_XMIT_DST_RELEASE_PERM;
-	netdev_features_t gso_partial_features = NETIF_F_GSO_ESP;
 	netdev_features_t vlan_features = BOND_VLAN_FEATURES;
 	netdev_features_t enc_features  = BOND_ENC_FEATURES;
 #ifdef CONFIG_XFRM_OFFLOAD
@@ -1582,8 +1585,9 @@ static void bond_compute_features(struct bonding *bond)
 							  BOND_XFRM_FEATURES);
 #endif /* CONFIG_XFRM_OFFLOAD */
 
-		if (slave->dev->hw_enc_features & NETIF_F_GSO_PARTIAL)
-			gso_partial_features &= slave->dev->gso_partial_features;
+		gso_partial_features = netdev_increment_features(gso_partial_features,
+								 slave->dev->gso_partial_features,
+								 BOND_GSO_PARTIAL_FEATURES);
 
 		mpls_features = netdev_increment_features(mpls_features,
 							  slave->dev->mpls_features,
@@ -1598,12 +1602,8 @@ static void bond_compute_features(struct bonding *bond)
 	}
 	bond_dev->hard_header_len = max_hard_header_len;
 

drivers/net/bonding/bond_main.c static void bond_compute_features(struct bonding *bond) · line 1609

Quoted 10 lines
drivers/net/bonding/bond_main.c +1 -5
-	if (gso_partial_features & NETIF_F_GSO_ESP)
-		bond_dev->gso_partial_features |= NETIF_F_GSO_ESP;
-	else
-		bond_dev->gso_partial_features &= ~NETIF_F_GSO_ESP;
-
 done:
+	bond_dev->gso_partial_features = gso_partial_features;
 	bond_dev->vlan_features = vlan_features;
 	bond_dev->hw_enc_features = enc_features | NETIF_F_GSO_ENCAP_ALL |
 				    NETIF_F_HW_VLAN_CTAG_TX |
        if (!bond_has_slaves(bond))
                goto done;

If there is no slaves, should we add the gso_partial_features?

Thanks
Hangbin

Quoted 11 lines
drivers/net/bonding/bond_main.c +1 -0
@@ -6046,6 +6046,7 @@ void bond_setup(struct net_device *bond_dev)
 	bond_dev->hw_features |= NETIF_F_GSO_ENCAP_ALL;
 	bond_dev->features |= bond_dev->hw_features;
 	bond_dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX;
+	bond_dev->features |= NETIF_F_GSO_PARTIAL;
 #ifdef CONFIG_XFRM_OFFLOAD
 	bond_dev->hw_features |= BOND_XFRM_FEATURES;
 	/* Only enable XFRM features if this is an active-backup config */
Signature · 1 line
2.45.0
#2 lore raw
Quoted 79 lines · Hangbin Liu
Quoted 70 lines · Cosmin Ratiu

---
 drivers/net/bonding/bond_main.c | 19 ++++++++++---------

 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/net/bonding/bond_main.c +0 -0
index 7b78c2bada81..e45bba240cbc 100644
@@ -1538,17 +1538,20 @@ static netdev_features_t
 bond_fix_features(struct net_device *dev,
  				 NETIF_F_HIGHDMA | NETIF_F_LRO)


 #define BOND_ENC_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \

drivers/net/bonding/bond_main.c +0 -1
-				 NETIF_F_RXCSUM |

NETIF_F_GSO_SOFTWARE)

drivers/net/bonding/bond_main.c +1 -0
+				 NETIF_F_RXCSUM |

NETIF_F_GSO_SOFTWARE | \

drivers/net/bonding/bond_main.c +1 -0
+				 NETIF_F_GSO_PARTIAL)


 #define BOND_MPLS_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \
  NETIF_F_GSO_SOFTWARE)

drivers/net/bonding/bond_main.c +2 -0
+#define BOND_GSO_PARTIAL_FEATURES (NETIF_F_GSO_ESP)
+


 static void bond_compute_features(struct bonding *bond) {

drivers/net/bonding/bond_main.c +1 -0
+	netdev_features_t gso_partial_features =

BOND_GSO_PARTIAL_FEATURES;
  unsigned int dst_release_flag = IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM;

drivers/net/bonding/bond_main.c +0 -1
-	netdev_features_t gso_partial_features = NETIF_F_GSO_ESP;

  netdev_features_t vlan_features = BOND_VLAN_FEATURES; netdev_features_t enc_features  = BOND_ENC_FEATURES; #ifdef CONFIG_XFRM_OFFLOAD

drivers/net/bonding/bond_main.c +0 -0
@@ -1582,8 +1585,9 @@ static void bond_compute_features(struct
 bonding *bond)


BOND_XFRM_FEATURES);
 #endif /* CONFIG_XFRM_OFFLOAD */

drivers/net/bonding/bond_main.c +0 -1
-		if (slave->dev->hw_enc_features &

NETIF_F_GSO_PARTIAL)

drivers/net/bonding/bond_main.c +0 -1
-			gso_partial_features &= slave->dev-
Quoted 1 line

gso_partial_features;

drivers/net/bonding/bond_main.c +1 -0
+		gso_partial_features =

netdev_increment_features(gso_partial_features,

drivers/net/bonding/bond_main.c +1 -0
+								

slave->dev->gso_partial_features,

drivers/net/bonding/bond_main.c +1 -0
+								

BOND_GSO_PARTIAL_FEATURES);

  mpls_features = netdev_increment_features(mpls_features,
    slave-

Quoted 1 line

dev->mpls_features,

drivers/net/bonding/bond_main.c +0 -0
@@ -1598,12 +1602,8 @@ static void bond_compute_features(struct
 bonding *bond)
  	}
  	bond_dev->hard_header_len = max_hard_header_len;

drivers/net/bonding/bond_main.c +0 -4
-	if (gso_partial_features & NETIF_F_GSO_ESP)
-		bond_dev->gso_partial_features |= NETIF_F_GSO_ESP;
-	else
-		bond_dev->gso_partial_features &=

~NETIF_F_GSO_ESP;
-
 done:

drivers/net/bonding/bond_main.c +1 -0
+	bond_dev->gso_partial_features = gso_partial_features;
Quoted 4 lines

  bond_dev->vlan_features = vlan_features; bond_dev->hw_enc_features = enc_features | NETIF_F_GSO_ENCAP_ALL |
      NETIF_F_HW_VLAN_CTAG_TX |

        if (!bond_has_slaves(bond))
                goto done;

Quoted 1 line

If there is no slaves, should we add the gso_partial_features?

The other partial feature sets are added after 'done:', why not do the same for gso_partial_features for consistency? 'gso_partial_features' is otherwise not set anywhere else and relies on it being set to zero when allocated in alloc_netdev_mqs. I think it's better for it to be explicitly initialized in all cases here, like the other feature sets.

Cosmin.

Reviewed-by
#3 lore raw
Quoted 82 lines · Cosmin Ratiu
Quoted 79 lines · Hangbin Liu
Quoted 70 lines · Cosmin Ratiu

---
 drivers/net/bonding/bond_main.c | 19 ++++++++++---------

 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/net/bonding/bond_main.c +0 -0
index 7b78c2bada81..e45bba240cbc 100644
@@ -1538,17 +1538,20 @@ static netdev_features_t
 bond_fix_features(struct net_device *dev,
  				 NETIF_F_HIGHDMA | NETIF_F_LRO)


 #define BOND_ENC_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \

drivers/net/bonding/bond_main.c +0 -1
-				 NETIF_F_RXCSUM |

NETIF_F_GSO_SOFTWARE)

drivers/net/bonding/bond_main.c +1 -0
+				 NETIF_F_RXCSUM |

NETIF_F_GSO_SOFTWARE | \

drivers/net/bonding/bond_main.c +1 -0
+				 NETIF_F_GSO_PARTIAL)


 #define BOND_MPLS_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \
  NETIF_F_GSO_SOFTWARE)

drivers/net/bonding/bond_main.c +2 -0
+#define BOND_GSO_PARTIAL_FEATURES (NETIF_F_GSO_ESP)
+


 static void bond_compute_features(struct bonding *bond) {

drivers/net/bonding/bond_main.c +1 -0
+	netdev_features_t gso_partial_features =

BOND_GSO_PARTIAL_FEATURES;
  unsigned int dst_release_flag = IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM;

drivers/net/bonding/bond_main.c +0 -1
-	netdev_features_t gso_partial_features = NETIF_F_GSO_ESP;

  netdev_features_t vlan_features = BOND_VLAN_FEATURES; netdev_features_t enc_features  = BOND_ENC_FEATURES; #ifdef CONFIG_XFRM_OFFLOAD

drivers/net/bonding/bond_main.c +0 -0
@@ -1582,8 +1585,9 @@ static void bond_compute_features(struct
 bonding *bond)


BOND_XFRM_FEATURES);
 #endif /* CONFIG_XFRM_OFFLOAD */

drivers/net/bonding/bond_main.c +0 -1
-		if (slave->dev->hw_enc_features &

NETIF_F_GSO_PARTIAL)

drivers/net/bonding/bond_main.c +0 -1
-			gso_partial_features &= slave->dev-
Quoted 1 line

gso_partial_features;

drivers/net/bonding/bond_main.c +1 -0
+		gso_partial_features =

netdev_increment_features(gso_partial_features,

drivers/net/bonding/bond_main.c +1 -0
+								

slave->dev->gso_partial_features,

drivers/net/bonding/bond_main.c +1 -0
+								

BOND_GSO_PARTIAL_FEATURES);

  mpls_features = netdev_increment_features(mpls_features,
    slave-

Quoted 1 line

dev->mpls_features,

drivers/net/bonding/bond_main.c +0 -0
@@ -1598,12 +1602,8 @@ static void bond_compute_features(struct
 bonding *bond)
  	}
  	bond_dev->hard_header_len = max_hard_header_len;

drivers/net/bonding/bond_main.c +0 -4
-	if (gso_partial_features & NETIF_F_GSO_ESP)
-		bond_dev->gso_partial_features |= NETIF_F_GSO_ESP;
-	else
-		bond_dev->gso_partial_features &=

~NETIF_F_GSO_ESP;
-
 done:

drivers/net/bonding/bond_main.c +1 -0
+	bond_dev->gso_partial_features = gso_partial_features;
Quoted 4 lines

  bond_dev->vlan_features = vlan_features; bond_dev->hw_enc_features = enc_features | NETIF_F_GSO_ENCAP_ALL |
      NETIF_F_HW_VLAN_CTAG_TX |

        if (!bond_has_slaves(bond))
                goto done;

Quoted 1 line

If there is no slaves, should we add the gso_partial_features?

Quoted 7 lines

The other partial feature sets are added after 'done:', why not do the same for gso_partial_features for consistency? 'gso_partial_features' is otherwise not set anywhere else and relies on it being set to zero when allocated in alloc_netdev_mqs. I think it's better for it to be explicitly initialized in all cases here, like the other feature sets.

Cosmin.

OK.