Skip to content

Commit d79444e

Browse files
Cosmin Ratiuklassert
authored andcommitted
net/mlx5: Avoid using xso.real_dev unnecessarily
xso.real_dev is the active device of an offloaded xfrm state and is managed by bonding. As such, it's subject to change when states are migrated to a new device. Using it in places other than offloading/unoffloading the states is risky. This commit saves the device into the driver-specific struct mlx5e_ipsec_sa_entry and switches mlx5e_ipsec_init_macs() and mlx5e_ipsec_netevent_event() to make use of it. Additionally, mlx5e_xfrm_update_stats() used xso.real_dev to validate that correct net locks are held. But in a bonding config, the net of the master device is the same as the underlying devices, and the net is already a local var, so use that instead. The only remaining references to xso.real_dev are now in the .xdo_dev_state_add() / .xdo_dev_state_delete() path. Signed-off-by: Cosmin Ratiu <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Reviewed-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 20eb35d commit d79444e

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,
259259
struct mlx5_accel_esp_xfrm_attrs *attrs)
260260
{
261261
struct mlx5_core_dev *mdev = mlx5e_ipsec_sa2dev(sa_entry);
262-
struct xfrm_state *x = sa_entry->x;
263-
struct net_device *netdev;
262+
struct net_device *netdev = sa_entry->dev;
264263
struct neighbour *n;
265264
u8 addr[ETH_ALEN];
266265
const void *pkey;
@@ -270,8 +269,6 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,
270269
attrs->type != XFRM_DEV_OFFLOAD_PACKET)
271270
return;
272271

273-
netdev = x->xso.real_dev;
274-
275272
mlx5_query_mac_address(mdev, addr);
276273
switch (attrs->dir) {
277274
case XFRM_DEV_OFFLOAD_IN:
@@ -713,6 +710,7 @@ static int mlx5e_xfrm_add_state(struct xfrm_state *x,
713710
return -ENOMEM;
714711

715712
sa_entry->x = x;
713+
sa_entry->dev = netdev;
716714
sa_entry->ipsec = ipsec;
717715
/* Check if this SA is originated from acquire flow temporary SA */
718716
if (x->xso.flags & XFRM_DEV_OFFLOAD_FLAG_ACQ)
@@ -855,8 +853,6 @@ static int mlx5e_ipsec_netevent_event(struct notifier_block *nb,
855853
struct mlx5e_ipsec_sa_entry *sa_entry;
856854
struct mlx5e_ipsec *ipsec;
857855
struct neighbour *n = ptr;
858-
struct net_device *netdev;
859-
struct xfrm_state *x;
860856
unsigned long idx;
861857

862858
if (event != NETEVENT_NEIGH_UPDATE || !(n->nud_state & NUD_VALID))
@@ -876,11 +872,9 @@ static int mlx5e_ipsec_netevent_event(struct notifier_block *nb,
876872
continue;
877873
}
878874

879-
x = sa_entry->x;
880-
netdev = x->xso.real_dev;
881875
data = sa_entry->work->data;
882876

883-
neigh_ha_snapshot(data->addr, n, netdev);
877+
neigh_ha_snapshot(data->addr, n, sa_entry->dev);
884878
queue_work(ipsec->wq, &sa_entry->work->work);
885879
}
886880

@@ -996,8 +990,8 @@ static void mlx5e_xfrm_update_stats(struct xfrm_state *x)
996990
size_t headers;
997991

998992
lockdep_assert(lockdep_is_held(&x->lock) ||
999-
lockdep_is_held(&dev_net(x->xso.real_dev)->xfrm.xfrm_cfg_mutex) ||
1000-
lockdep_is_held(&dev_net(x->xso.real_dev)->xfrm.xfrm_state_lock));
993+
lockdep_is_held(&net->xfrm.xfrm_cfg_mutex) ||
994+
lockdep_is_held(&net->xfrm.xfrm_state_lock));
1001995

1002996
if (x->xso.flags & XFRM_DEV_OFFLOAD_FLAG_ACQ)
1003997
return;

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ struct mlx5e_ipsec_limits {
274274
struct mlx5e_ipsec_sa_entry {
275275
struct mlx5e_ipsec_esn_state esn_state;
276276
struct xfrm_state *x;
277+
struct net_device *dev;
277278
struct mlx5e_ipsec *ipsec;
278279
struct mlx5_accel_esp_xfrm_attrs attrs;
279280
void (*set_iv_op)(struct sk_buff *skb, struct xfrm_state *x,

0 commit comments

Comments
 (0)