Skip to content

Commit 08784c7

Browse files
Cosmin Ratiugregkh
authored andcommitted
net/mlx5: Avoid using xso.real_dev unnecessarily
[ Upstream commit d79444e ] 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 <cratiu@nvidia.com> Reviewed-by: Leon Romanovsky <leonro@nvidia.com> Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 9d57de8 commit 08784c7

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
@@ -266,8 +266,7 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,
266266
struct mlx5_accel_esp_xfrm_attrs *attrs)
267267
{
268268
struct mlx5_core_dev *mdev = mlx5e_ipsec_sa2dev(sa_entry);
269-
struct xfrm_state *x = sa_entry->x;
270-
struct net_device *netdev;
269+
struct net_device *netdev = sa_entry->dev;
271270
struct neighbour *n;
272271
u8 addr[ETH_ALEN];
273272
const void *pkey;
@@ -277,8 +276,6 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,
277276
attrs->type != XFRM_DEV_OFFLOAD_PACKET)
278277
return;
279278

280-
netdev = x->xso.real_dev;
281-
282279
mlx5_query_mac_address(mdev, addr);
283280
switch (attrs->dir) {
284281
case XFRM_DEV_OFFLOAD_IN:
@@ -707,6 +704,7 @@ static int mlx5e_xfrm_add_state(struct xfrm_state *x,
707704
return -ENOMEM;
708705

709706
sa_entry->x = x;
707+
sa_entry->dev = netdev;
710708
sa_entry->ipsec = ipsec;
711709
/* Check if this SA is originated from acquire flow temporary SA */
712710
if (x->xso.flags & XFRM_DEV_OFFLOAD_FLAG_ACQ)
@@ -849,8 +847,6 @@ static int mlx5e_ipsec_netevent_event(struct notifier_block *nb,
849847
struct mlx5e_ipsec_sa_entry *sa_entry;
850848
struct mlx5e_ipsec *ipsec;
851849
struct neighbour *n = ptr;
852-
struct net_device *netdev;
853-
struct xfrm_state *x;
854850
unsigned long idx;
855851

856852
if (event != NETEVENT_NEIGH_UPDATE || !(n->nud_state & NUD_VALID))
@@ -870,11 +866,9 @@ static int mlx5e_ipsec_netevent_event(struct notifier_block *nb,
870866
continue;
871867
}
872868

873-
x = sa_entry->x;
874-
netdev = x->xso.real_dev;
875869
data = sa_entry->work->data;
876870

877-
neigh_ha_snapshot(data->addr, n, netdev);
871+
neigh_ha_snapshot(data->addr, n, sa_entry->dev);
878872
queue_work(ipsec->wq, &sa_entry->work->work);
879873
}
880874

@@ -1005,8 +999,8 @@ static void mlx5e_xfrm_update_stats(struct xfrm_state *x)
1005999
size_t headers;
10061000

10071001
lockdep_assert(lockdep_is_held(&x->lock) ||
1008-
lockdep_is_held(&dev_net(x->xso.real_dev)->xfrm.xfrm_cfg_mutex) ||
1009-
lockdep_is_held(&dev_net(x->xso.real_dev)->xfrm.xfrm_state_lock));
1002+
lockdep_is_held(&net->xfrm.xfrm_cfg_mutex) ||
1003+
lockdep_is_held(&net->xfrm.xfrm_state_lock));
10101004

10111005
if (x->xso.flags & XFRM_DEV_OFFLOAD_FLAG_ACQ)
10121006
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
@@ -260,6 +260,7 @@ struct mlx5e_ipsec_limits {
260260
struct mlx5e_ipsec_sa_entry {
261261
struct mlx5e_ipsec_esn_state esn_state;
262262
struct xfrm_state *x;
263+
struct net_device *dev;
263264
struct mlx5e_ipsec *ipsec;
264265
struct mlx5_accel_esp_xfrm_attrs attrs;
265266
void (*set_iv_op)(struct sk_buff *skb, struct xfrm_state *x,

0 commit comments

Comments
 (0)