mlx5 fixes 2021-08-26
From: Saeed Mahameed <[email protected]>
Hi Dave and Jakub,
This series introduces some fixes to mlx5 driver. Please pull and let me know if there is any problem.
Thanks,
Saeed.
---
The following changes since commit 73367f05b25dbd064061aee780638564d15b01d1:
Merge tag 'nfsd-5.14-1' of git://linux-nfs.org/~bfields/linux (2021-08-26 13:26:40 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/saeed/linux.git tags/mlx5-fixes-2021-08-26
for you to fetch changes up to 6cc64770fb386b10a64a1fe09328396de7bb5262:
net/mlx5: DR, fix a potential use-after-free bug (2021-08-26 15:15:42 -0700)
----------------------------------------------------------------
mlx5-fixes-2021-08-26
----------------------------------------------------------------
Dima Chumak (1):
net/mlx5: Lag, fix multipath lag activation
Dmytro Linkin (1):
net/mlx5e: Use correct eswitch for stack devices with lag
Leon Romanovsky (1):
net/mlx5: Remove all auxiliary devices at the unregister event
Maor Dickman (1):
net/mlx5: E-Switch, Set vhca id valid flag when creating indir fwd group
Roi Dayan (1):
net/mlx5e: Fix possible use-after-free deleting fdb rule
Wentao_Liang (1):
net/mlx5: DR, fix a potential use-after-free bug
drivers/net/ethernet/mellanox/mlx5/core/dev.c | 2 +- .../net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c | 4 ++-- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 18 ++++++++++++++++++ .../net/ethernet/mellanox/mlx5/core/esw/indir_table.c | 1 + drivers/net/ethernet/mellanox/mlx5/core/lag.c | 1 + drivers/net/ethernet/mellanox/mlx5/core/lag_mp.c | 8 ++++++++ drivers/net/ethernet/mellanox/mlx5/core/lag_mp.h | 2 ++ .../net/ethernet/mellanox/mlx5/core/steering/dr_rule.c | 2 +- 8 files changed, 34 insertions(+), 4 deletions(-)
PATCH 1/6 net/mlx5: Lag, fix multipath lag activation
From: Dima Chumak <[email protected]>
When handling FIB_EVENT_ENTRY_REPLACE event for a new multipath route, lag activation can be missed if a stale (struct lag_mp)->mfi pointer exists, which was associated with an older multipath route that had been removed.
Normally, when a route is removed, it triggers mlx5_lag_fib_event(), which handles FIB_EVENT_ENTRY_DEL and clears mfi pointer. But, if mlx5_lag_check_prereq() condition isn't met, for example when eswitch is in legacy mode, the fib event is skipped and mfi pointer becomes stale.
Fix by resetting mfi pointer to NULL in mlx5_deactivate_lag().
--- drivers/net/ethernet/mellanox/mlx5/core/lag.c | 1 + drivers/net/ethernet/mellanox/mlx5/core/lag_mp.c | 8 ++++++++ drivers/net/ethernet/mellanox/mlx5/core/lag_mp.h | 2 ++ 3 files changed, 11 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/lag.c +1 -0
@@ -277,6 +277,7 @@ static int mlx5_deactivate_lag(struct mlx5_lag *ldev)int err; ldev->flags &= ~MLX5_LAG_MODE_FLAGS ; +mlx5_lag_mp_reset (ldev);MLX5_SET (destroy_lag_in, in, opcode,MLX5_CMD_OP_DESTROY_LAG ); err =mlx5_cmd_exec_in (dev0, destroy_lag, in);
drivers/net/ethernet/mellanox/mlx5/core/lag_mp.c +8 -0
@@ -302,6 +302,14 @@ static int mlx5_lag_fib_event(struct notifier_block *nb,return NOTIFY_DONE ; } +void mlx5_lag_mp_reset (struct mlx5_lag *ldev) +{ +/* Clear mfi, as it might become stale when a route delete event +* has been missed, see mlx5_lag_fib_route_event(). +*/ + ldev->lag_mp.mfi =NULL ; +} +int mlx5_lag_mp_init (struct mlx5_lag *ldev) {struct lag_mp *mp = &ldev->lag_mp;
drivers/net/ethernet/mellanox/mlx5/core/lag_mp.h +2 -0
@@ -21,11 +21,13 @@ struct lag_mp {#ifdef CONFIG_MLX5_ESWITCH +void mlx5_lag_mp_reset (struct mlx5_lag *ldev);int mlx5_lag_mp_init (struct mlx5_lag *ldev);void mlx5_lag_mp_cleanup (struct mlx5_lag *ldev);#else /* CONFIG_MLX5_ESWITCH */ +static inline void mlx5_lag_mp_reset (struct mlx5_lag *ldev) {};static inline int mlx5_lag_mp_init (struct mlx5_lag *ldev) {return 0 ; }static inline void mlx5_lag_mp_cleanup (struct mlx5_lag *ldev) {}
Signature · 1 line
2.31.1
Re: [net 1/6] net/mlx5: Lag, fix multipath lag activation
This series was applied to netdev/net.git (refs/heads/master):
Hello:
This series was applied to netdev/net.git (refs/heads/master):
Quoted 8 lines · On Thu, 26 Aug 2021 15:18:05 -0700 you wrote:
From: Dima Chumak <[email protected]>
When handling
FIB_EVENT_ENTRY_REPLACEevent for a new multipath route, lag activation can be missed if a stale (struct lag_mp)->mfi pointer exists, which was associated with an older multipath route that had been removed.[...]
Here is the summary with links:
- [net,1/6] net/mlx5: Lag, fix multipath lag activation
https://git.kernel.org/netdev/net/c/2f8b6161cca5 - [net,2/6] net/mlx5: Remove all auxiliary devices at the unregister event https://git.kernel.org/netdev/net/c/8e7e2e8ed0e2 - [net,3/6] net/mlx5e: Fix possible use-after-free deleting fdb rule https://git.kernel.org/netdev/net/c/9a5f9cc794e1 - [net,4/6] net/mlx5: E-Switch, Set vhca id valid flag when creating indir fwd group https://git.kernel.org/netdev/net/c/ca6891f9b27d - [net,5/6] net/mlx5e: Use correct eswitch for stack devices with lag https://git.kernel.org/netdev/net/c/f9d196bd632b - [net,6/6] net/mlx5: DR, fix a potential use-after-free bug https://git.kernel.org/netdev/net/c/6cc64770fb38
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
PATCH 2/6 net/mlx5: Remove all auxiliary devices at the unregister event
In reply to Saeed MahameedFrom: Leon Romanovsky <[email protected]>
The call to mlx5_unregister_device() means that mlx5_core driver is removed. In such scenario, we need to disregard all other flags like attach/detach and forcibly remove all auxiliary devices.
--- drivers/net/ethernet/mellanox/mlx5/core/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/dev.c +1 -1
@@ -397,7 +397,7 @@ int mlx5_register_device(struct mlx5_core_dev *dev)void mlx5_unregister_device (struct mlx5_core_dev *dev) {mutex_lock (&mlx5_intf_mutex); - dev->priv.flags |=MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV ; + dev->priv.flags =MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV ;mlx5_rescan_drivers_locked (dev);mutex_unlock (&mlx5_intf_mutex); }
Signature · 1 line
2.31.1
PATCH 3/6 net/mlx5e: Fix possible use-after-free deleting fdb rule
In reply to Saeed MahameedFrom: Roi Dayan <[email protected]>
After neigh-update-add failure we are still with a slow path rule but the driver always assume the rule is an fdb rule.
Fix neigh-update-del by checking slow path tc flag on the flow. Also fix neigh-update-add for when neigh-update-del fails the same.
--- drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +2 -2
@@ -147,7 +147,7 @@ void mlx5e_tc_encap_flows_add(struct mlx5e_priv *priv,mlx5e_rep_queue_neigh_stats_work (priv);list_for_each_entry (flow, flow_list, tmp_list) { -if (!mlx5e_is_offloaded_flow (flow)) +if (!mlx5e_is_offloaded_flow (flow) || !flow_flag_test (flow,SLOW ))continue ; attr = flow->attr; esw_attr = attr->esw_attr;
@@ -188,7 +188,7 @@ void mlx5e_tc_encap_flows_del(struct mlx5e_priv *priv,int err;list_for_each_entry (flow, flow_list, tmp_list) { -if (!mlx5e_is_offloaded_flow (flow)) +if (!mlx5e_is_offloaded_flow (flow) ||flow_flag_test (flow,SLOW ))continue ; attr = flow->attr; esw_attr = attr->esw_attr;
Signature · 1 line
2.31.1
PATCH 4/6 net/mlx5: E-Switch, Set vhca id valid flag when creating indir fwd group
In reply to Saeed MahameedFrom: Maor Dickman <[email protected]>
When indirect forward group is created, flow is added with vhca id but without setting vhca id valid flag which violates the PRM.
Fix by setting the missing flag, vhca id valid.
--- drivers/net/ethernet/mellanox/mlx5/core/esw/indir_table.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/mellanox/mlx5/core/esw/indir_table.c +1 -0
@@ -364,6 +364,7 @@ static int mlx5_create_indir_fwd_group(struct mlx5_eswitch *esw, dest.type =MLX5_FLOW_DESTINATION_TYPE_VPORT ; dest.vport.num = e->vport; dest.vport.vhca_id =MLX5_CAP_GEN (esw->dev, vhca_id); + dest.vport.flags =MLX5_FLOW_DEST_VPORT_VHCA_ID ; e->fwd_rule =mlx5_add_flow_rules (e->ft, spec, &flow_act, &dest,1 );if (IS_ERR (e->fwd_rule)) {mlx5_destroy_flow_group (e->fwd_grp);
Signature · 1 line
2.31.1
PATCH 5/6 net/mlx5e: Use correct eswitch for stack devices with lag
In reply to Saeed MahameedFrom: Dmytro Linkin <[email protected]>
If link aggregation is used within stack devices driver rejects encap rules if PF of the VF tunnel device is down. This happens because route resolved for other PF and its eswitch instance is used to determine correct vport.
To fix that use devcom feature to retrieve other eswitch instance if failed to find vport for the 1st eswitch and LAG is active.
--- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +18 -0
@@ -1338,6 +1338,7 @@ bool mlx5e_tc_is_vf_tunnel(struct net_device *out_dev, struct net_device *route_int mlx5e_tc_query_route_vport (struct net_device *out_dev,struct net_device *route_dev,u16 *vport) {struct mlx5e_priv *out_priv, *route_priv; +struct mlx5_devcom *devcom =NULL ;struct mlx5_core_dev *route_mdev;struct mlx5_eswitch *esw;u16 vhca_id;
@@ -1349,7 +1350,24 @@ int mlx5e_tc_query_route_vport(struct net_device *out_dev, struct net_device *ro route_mdev = route_priv->mdev; vhca_id =MLX5_CAP_GEN (route_mdev, vhca_id); +if (mlx5_lag_is_active (out_priv->mdev)) { +/* In lag case we may get devices from different eswitch instances. +* If we failed to get vport num, it means, mostly, that we on the wrong +* eswitch. +*/ + err =mlx5_eswitch_vhca_id_to_vport (esw, vhca_id, vport); +if (err != -ENOENT ) +return err; + + devcom = out_priv->mdev->priv.devcom; + esw =mlx5_devcom_get_peer_data (devcom,MLX5_DEVCOM_ESW_OFFLOADS ); +if (!esw) +return -ENODEV ; + } + err =mlx5_eswitch_vhca_id_to_vport (esw, vhca_id, vport); +if (devcom) +mlx5_devcom_release_peer_data (devcom,MLX5_DEVCOM_ESW_OFFLOADS );return err; }
Signature · 1 line
2.31.1
PATCH 6/6 net/mlx5: DR, fix a potential use-after-free bug
In reply to Saeed MahameedFrom: Wentao_Liang <[email protected]>
In line 849 (#1), "mlx5dr_htbl_put(cur_htbl);" drops the reference to cur_htbl and may cause cur_htbl to be freed.
However, cur_htbl is subsequently used in the next line, which may result in an use-after-free bug.
Fix this by calling mlx5dr_err() before the cur_htbl is put.
--- drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c +1 -1
@@ -846,9 +846,9 @@ dr_rule_handle_ste_branch(struct mlx5dr_rule *rule, new_htbl =dr_rule_rehash (rule, nic_rule, cur_htbl, ste_location, send_ste_list);if (!new_htbl) { -mlx5dr_htbl_put (cur_htbl);mlx5dr_err (dmn,"Failed creating rehash table, htbl-log_size: %d\n" , cur_htbl->chunk_size); +mlx5dr_htbl_put (cur_htbl); }else { cur_htbl = new_htbl; }
Signature · 1 line
2.31.1