Skip to content

Commit 7593439

Browse files
cjubranPaolo Abeni
authored andcommitted
net/mlx5: Prevent tunnel mode conflicts between FDB and NIC IPsec tables
When creating IPsec flow tables with tunnel mode enabled, the driver uses mlx5_eswitch_block_encap() to prevent tunnel encapsulation conflicts across different domains (NIC_RX/NIC_TX and FDB), since the firmware doesn’t allow both at the same time. Currently, the driver attempts to reserve tunnel mode unconditionally for both NIC and FDB IPsec tables. This can lead to conflicting tunnel mode setups, for example, if a flow table was created in the FDB domain with tunnel offload enabled, and we later try to create another one in the NIC, or vice versa. To resolve this, adjust the blocking logic so that tunnel mode is only reserved by NIC flows. This ensures that tunnel offload is exclusively used in either the NIC or the FDB, and avoids unintended offload conflicts. Fixes: 1762f13 ("net/mlx5e: Support IPsec packet offload for RX in switchdev mode") Fixes: c6c2bf5 ("net/mlx5e: Support IPsec packet offload for TX in switchdev mode") Signed-off-by: Carolina Jubran <[email protected]> Reviewed-by: Jianbo Liu <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Signed-off-by: Tariq Toukan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 3d3c4cd commit 7593439

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,9 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
10691069

10701070
/* Create FT */
10711071
if (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_TUNNEL)
1072-
rx->allow_tunnel_mode = mlx5_eswitch_block_encap(mdev);
1072+
rx->allow_tunnel_mode =
1073+
mlx5_eswitch_block_encap(mdev, rx == ipsec->rx_esw);
1074+
10731075
if (rx->allow_tunnel_mode)
10741076
flags = MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT;
10751077
ft = ipsec_ft_create(attr.ns, attr.sa_level, attr.prio, 1, 2, flags);
@@ -1310,7 +1312,9 @@ static int tx_create(struct mlx5e_ipsec *ipsec, struct mlx5e_ipsec_tx *tx,
13101312
goto err_status_rule;
13111313

13121314
if (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_TUNNEL)
1313-
tx->allow_tunnel_mode = mlx5_eswitch_block_encap(mdev);
1315+
tx->allow_tunnel_mode =
1316+
mlx5_eswitch_block_encap(mdev, tx == ipsec->tx_esw);
1317+
13141318
if (tx->allow_tunnel_mode)
13151319
flags = MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT;
13161320
ft = ipsec_ft_create(tx->ns, attr.sa_level, attr.prio, 1, 4, flags);

drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ void mlx5_eswitch_offloads_single_fdb_del_one(struct mlx5_eswitch *master_esw,
879879
struct mlx5_eswitch *slave_esw);
880880
int mlx5_eswitch_reload_ib_reps(struct mlx5_eswitch *esw);
881881

882-
bool mlx5_eswitch_block_encap(struct mlx5_core_dev *dev);
882+
bool mlx5_eswitch_block_encap(struct mlx5_core_dev *dev, bool from_fdb);
883883
void mlx5_eswitch_unblock_encap(struct mlx5_core_dev *dev);
884884

885885
int mlx5_eswitch_block_mode(struct mlx5_core_dev *dev);
@@ -974,7 +974,8 @@ mlx5_eswitch_reload_ib_reps(struct mlx5_eswitch *esw)
974974
return 0;
975975
}
976976

977-
static inline bool mlx5_eswitch_block_encap(struct mlx5_core_dev *dev)
977+
static inline bool
978+
mlx5_eswitch_block_encap(struct mlx5_core_dev *dev, bool from_fdb)
978979
{
979980
return true;
980981
}

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4006,23 +4006,25 @@ int mlx5_devlink_eswitch_inline_mode_get(struct devlink *devlink, u8 *mode)
40064006
return esw_inline_mode_to_devlink(esw->offloads.inline_mode, mode);
40074007
}
40084008

4009-
bool mlx5_eswitch_block_encap(struct mlx5_core_dev *dev)
4009+
bool mlx5_eswitch_block_encap(struct mlx5_core_dev *dev, bool from_fdb)
40104010
{
40114011
struct mlx5_eswitch *esw = dev->priv.eswitch;
4012+
enum devlink_eswitch_encap_mode encap;
4013+
bool allow_tunnel = false;
40124014

40134015
if (!mlx5_esw_allowed(esw))
40144016
return true;
40154017

40164018
down_write(&esw->mode_lock);
4017-
if (esw->mode != MLX5_ESWITCH_LEGACY &&
4018-
esw->offloads.encap != DEVLINK_ESWITCH_ENCAP_MODE_NONE) {
4019-
up_write(&esw->mode_lock);
4020-
return false;
4019+
encap = esw->offloads.encap;
4020+
if (esw->mode == MLX5_ESWITCH_LEGACY ||
4021+
(encap == DEVLINK_ESWITCH_ENCAP_MODE_NONE && !from_fdb)) {
4022+
allow_tunnel = true;
4023+
esw->offloads.num_block_encap++;
40214024
}
4022-
4023-
esw->offloads.num_block_encap++;
40244025
up_write(&esw->mode_lock);
4025-
return true;
4026+
4027+
return allow_tunnel;
40264028
}
40274029

40284030
void mlx5_eswitch_unblock_encap(struct mlx5_core_dev *dev)

0 commit comments

Comments
 (0)