Skip to content

Commit a3b658c

Browse files
jarodwilsondavem330
authored andcommitted
bonding: allow xfrm offload setup post-module-load
At the moment, bonding xfrm crypto offload can only be set up if the bonding module is loaded with active-backup mode already set. We need to be able to make this work with bonds set to AB after the bonding driver has already been loaded. So what's done here is: 1) move #define BOND_XFRM_FEATURES to net/bonding.h so it can be used by both bond_main.c and bond_options.c 2) set BOND_XFRM_FEATURES in bond_dev->hw_features universally, rather than only when loading in AB mode 3) wire up xfrmdev_ops universally too 4) disable BOND_XFRM_FEATURES in bond_dev->features if not AB 5) exit early (non-AB case) from bond_ipsec_offload_ok, to prevent a performance hit from traversing into the underlying drivers 5) toggle BOND_XFRM_FEATURES in bond_dev->wanted_features and call netdev_change_features() from bond_option_mode_set() In my local testing, I can change bonding modes back and forth on the fly, have hardware offload work when I'm in AB, and see no performance penalty to non-AB software encryption, despite having xfrm bits all wired up for all modes now. Fixes: 18cb261 ("bonding: support hardware encryption offload to slaves") Reported-by: Huy Nguyen <huyn@mellanox.com> CC: Saeed Mahameed <saeedm@mellanox.com> CC: Jay Vosburgh <j.vosburgh@gmail.com> CC: Veaceslav Falico <vfalico@gmail.com> CC: Andy Gospodarek <andy@greyhouse.net> CC: "David S. Miller" <davem@davemloft.net> CC: Jeff Kirsher <jeffrey.t.kirsher@intel.com> CC: Jakub Kicinski <kuba@kernel.org> CC: Steffen Klassert <steffen.klassert@secunet.com> CC: Herbert Xu <herbert@gondor.apana.org.au> CC: netdev@vger.kernel.org CC: intel-wired-lan@lists.osuosl.org Signed-off-by: Jarod Wilson <jarod@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 651f8bd commit a3b658c

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

drivers/net/bonding/bond_main.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ static bool bond_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *xs)
434434
struct slave *curr_active = rtnl_dereference(bond->curr_active_slave);
435435
struct net_device *slave_dev = curr_active->dev;
436436

437+
if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP)
438+
return true;
439+
437440
if (!(slave_dev->xfrmdev_ops
438441
&& slave_dev->xfrmdev_ops->xdo_dev_offload_ok)) {
439442
slave_warn(bond_dev, slave_dev, "%s: no slave xdo_dev_offload_ok\n", __func__);
@@ -1218,11 +1221,6 @@ static netdev_features_t bond_fix_features(struct net_device *dev,
12181221
#define BOND_ENC_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \
12191222
NETIF_F_RXCSUM | NETIF_F_ALL_TSO)
12201223

1221-
#ifdef CONFIG_XFRM_OFFLOAD
1222-
#define BOND_XFRM_FEATURES (NETIF_F_HW_ESP | NETIF_F_HW_ESP_TX_CSUM | \
1223-
NETIF_F_GSO_ESP)
1224-
#endif /* CONFIG_XFRM_OFFLOAD */
1225-
12261224
#define BOND_MPLS_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \
12271225
NETIF_F_ALL_TSO)
12281226

@@ -4654,8 +4652,7 @@ void bond_setup(struct net_device *bond_dev)
46544652

46554653
#ifdef CONFIG_XFRM_OFFLOAD
46564654
/* set up xfrm device ops (only supported in active-backup right now) */
4657-
if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP)
4658-
bond_dev->xfrmdev_ops = &bond_xfrmdev_ops;
4655+
bond_dev->xfrmdev_ops = &bond_xfrmdev_ops;
46594656
bond->xs = NULL;
46604657
#endif /* CONFIG_XFRM_OFFLOAD */
46614658

@@ -4678,11 +4675,15 @@ void bond_setup(struct net_device *bond_dev)
46784675

46794676
bond_dev->hw_features |= NETIF_F_GSO_ENCAP_ALL | NETIF_F_GSO_UDP_L4;
46804677
#ifdef CONFIG_XFRM_OFFLOAD
4681-
if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP)
4682-
bond_dev->hw_features |= BOND_XFRM_FEATURES;
4678+
bond_dev->hw_features |= BOND_XFRM_FEATURES;
46834679
#endif /* CONFIG_XFRM_OFFLOAD */
46844680
bond_dev->features |= bond_dev->hw_features;
46854681
bond_dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX;
4682+
#ifdef CONFIG_XFRM_OFFLOAD
4683+
/* Disable XFRM features if this isn't an active-backup config */
4684+
if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP)
4685+
bond_dev->features &= ~BOND_XFRM_FEATURES;
4686+
#endif /* CONFIG_XFRM_OFFLOAD */
46864687
}
46874688

46884689
/* Destroy a bonding device.

drivers/net/bonding/bond_options.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,14 @@ static int bond_option_mode_set(struct bonding *bond,
767767
if (newval->value == BOND_MODE_ALB)
768768
bond->params.tlb_dynamic_lb = 1;
769769

770+
#ifdef CONFIG_XFRM_OFFLOAD
771+
if (newval->value == BOND_MODE_ACTIVEBACKUP)
772+
bond->dev->wanted_features |= BOND_XFRM_FEATURES;
773+
else
774+
bond->dev->wanted_features &= ~BOND_XFRM_FEATURES;
775+
netdev_change_features(bond->dev);
776+
#endif /* CONFIG_XFRM_OFFLOAD */
777+
770778
/* don't cache arp_validate between modes */
771779
bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
772780
bond->params.mode = newval->value;

include/net/bonding.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@
8686
#define bond_for_each_slave_rcu(bond, pos, iter) \
8787
netdev_for_each_lower_private_rcu((bond)->dev, pos, iter)
8888

89+
#ifdef CONFIG_XFRM_OFFLOAD
90+
#define BOND_XFRM_FEATURES (NETIF_F_HW_ESP | NETIF_F_HW_ESP_TX_CSUM | \
91+
NETIF_F_GSO_ESP)
92+
#endif /* CONFIG_XFRM_OFFLOAD */
93+
8994
#ifdef CONFIG_NET_POLL_CONTROLLER
9095
extern atomic_t netpoll_block_tx;
9196

0 commit comments

Comments
 (0)