netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net/mlx5: Don't zero user_count when destroying FDB tables
@ 2025-10-26 20:20 Tariq Toukan
  2025-10-28 16:57 ` Simon Horman
  2025-10-30  1:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Tariq Toukan @ 2025-10-26 20:20 UTC (permalink / raw)
  To: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Andrew Lunn,
	David S. Miller
  Cc: Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Mark Bloch, netdev,
	linux-rdma, linux-kernel, Gal Pressman, Dragos Tatulea,
	Cosmin Ratiu

From: Cosmin Ratiu <cratiu@nvidia.com>

esw->user_count tracks how many TC rules are added on an esw via
mlx5e_configure_flower -> mlx5_esw_get -> atomic64_inc(&esw->user_count)

esw.user_count was unconditionally set to 0 in
esw_destroy_legacy_fdb_table and esw_destroy_offloads_fdb_tables.

These two together can lead to the following sequence of events:
1. echo 1 > /sys/class/net/eth2/device/sriov_numvfs
  - mlx5_core_sriov_configure -...-> esw_create_legacy_table ->
    atomic64_set(&esw->user_count, 0)
2. tc qdisc add dev eth2 ingress && \
   tc filter replace dev eth2 pref 1 protocol ip chain 0 ingress \
       handle 1 flower action ct nat zone 64000 pipe
  - mlx5e_configure_flower -> mlx5_esw_get ->
    atomic64_inc(&esw->user_count)
3. echo 0 > /sys/class/net/eth2/device/sriov_numvfs
  - mlx5_core_sriov_configure -..-> esw_destroy_legacy_fdb_table
    -> atomic64_set(&esw->user_count, 0)
4. devlink dev eswitch set pci/0000:08:00.0 mode switchdev
  - mlx5_devlink_eswitch_mode_set -> mlx5_esw_try_lock ->
    atomic64_read(&esw->user_count) == 0
  - then proceed to a WARN_ON in:
  esw_offloads_start -> mlx5_eswitch_enable_locke -> esw_offloads_enable
  -> mlx5_esw_offloads_rep_load -> mlx5e_vport_rep_load ->
  mlx5e_netdev_change_profile -> mlx5e_detach_netdev ->
  mlx5e_cleanup_nic_rx -> mlx5e_tc_nic_cleanup ->
  mlx5e_mod_hdr_tbl_destroy

Fix this by not clearing out the user_count when destroying FDB tables,
so that the check in mlx5_esw_try_lock can prevent the mode change when
there are TC rules configured, as originally intended.

Fixes: 2318b8bb94a3 ("net/mlx5: E-switch, Destroy legacy fdb table when needed")
Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/esw/legacy.c       | 1 -
 drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/legacy.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/legacy.c
index 76382626ad41..929adeb50a98 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/esw/legacy.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/legacy.c
@@ -66,7 +66,6 @@ static void esw_destroy_legacy_fdb_table(struct mlx5_eswitch *esw)
 	esw->fdb_table.legacy.addr_grp = NULL;
 	esw->fdb_table.legacy.allmulti_grp = NULL;
 	esw->fdb_table.legacy.promisc_grp = NULL;
-	atomic64_set(&esw->user_count, 0);
 }
 
 static int esw_create_legacy_fdb_table(struct mlx5_eswitch *esw)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index 34749814f19b..44a142a041b2 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -1978,7 +1978,6 @@ static void esw_destroy_offloads_fdb_tables(struct mlx5_eswitch *esw)
 	/* Holds true only as long as DMFS is the default */
 	mlx5_flow_namespace_set_mode(esw->fdb_table.offloads.ns,
 				     MLX5_FLOW_STEERING_MODE_DMFS);
-	atomic64_set(&esw->user_count, 0);
 }
 
 static int esw_get_nr_ft_offloads_steering_src_ports(struct mlx5_eswitch *esw)

base-commit: 84a905290cb4c3d9a71a9e3b2f2e02e031e7512f
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net/mlx5: Don't zero user_count when destroying FDB tables
  2025-10-26 20:20 [PATCH net] net/mlx5: Don't zero user_count when destroying FDB tables Tariq Toukan
@ 2025-10-28 16:57 ` Simon Horman
  2025-10-30  1:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2025-10-28 16:57 UTC (permalink / raw)
  To: Tariq Toukan
  Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Andrew Lunn,
	David S. Miller, Saeed Mahameed, Leon Romanovsky, Mark Bloch,
	netdev, linux-rdma, linux-kernel, Gal Pressman, Dragos Tatulea,
	Cosmin Ratiu

On Sun, Oct 26, 2025 at 10:20:19PM +0200, Tariq Toukan wrote:
> From: Cosmin Ratiu <cratiu@nvidia.com>
> 
> esw->user_count tracks how many TC rules are added on an esw via
> mlx5e_configure_flower -> mlx5_esw_get -> atomic64_inc(&esw->user_count)
> 
> esw.user_count was unconditionally set to 0 in
> esw_destroy_legacy_fdb_table and esw_destroy_offloads_fdb_tables.
> 
> These two together can lead to the following sequence of events:
> 1. echo 1 > /sys/class/net/eth2/device/sriov_numvfs
>   - mlx5_core_sriov_configure -...-> esw_create_legacy_table ->
>     atomic64_set(&esw->user_count, 0)
> 2. tc qdisc add dev eth2 ingress && \
>    tc filter replace dev eth2 pref 1 protocol ip chain 0 ingress \
>        handle 1 flower action ct nat zone 64000 pipe
>   - mlx5e_configure_flower -> mlx5_esw_get ->
>     atomic64_inc(&esw->user_count)
> 3. echo 0 > /sys/class/net/eth2/device/sriov_numvfs
>   - mlx5_core_sriov_configure -..-> esw_destroy_legacy_fdb_table
>     -> atomic64_set(&esw->user_count, 0)
> 4. devlink dev eswitch set pci/0000:08:00.0 mode switchdev
>   - mlx5_devlink_eswitch_mode_set -> mlx5_esw_try_lock ->
>     atomic64_read(&esw->user_count) == 0
>   - then proceed to a WARN_ON in:
>   esw_offloads_start -> mlx5_eswitch_enable_locke -> esw_offloads_enable
>   -> mlx5_esw_offloads_rep_load -> mlx5e_vport_rep_load ->
>   mlx5e_netdev_change_profile -> mlx5e_detach_netdev ->
>   mlx5e_cleanup_nic_rx -> mlx5e_tc_nic_cleanup ->
>   mlx5e_mod_hdr_tbl_destroy
> 
> Fix this by not clearing out the user_count when destroying FDB tables,
> so that the check in mlx5_esw_try_lock can prevent the mode change when
> there are TC rules configured, as originally intended.
> 
> Fixes: 2318b8bb94a3 ("net/mlx5: E-switch, Destroy legacy fdb table when needed")
> Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
> Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
> Signed-off-by: Tariq Toukan <tariqt@nvidia.com>

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net/mlx5: Don't zero user_count when destroying FDB tables
  2025-10-26 20:20 [PATCH net] net/mlx5: Don't zero user_count when destroying FDB tables Tariq Toukan
  2025-10-28 16:57 ` Simon Horman
@ 2025-10-30  1:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-10-30  1:00 UTC (permalink / raw)
  To: Tariq Toukan
  Cc: edumazet, kuba, pabeni, andrew+netdev, davem, saeedm, leon,
	mbloch, netdev, linux-rdma, linux-kernel, gal, dtatulea, cratiu

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Sun, 26 Oct 2025 22:20:19 +0200 you wrote:
> From: Cosmin Ratiu <cratiu@nvidia.com>
> 
> esw->user_count tracks how many TC rules are added on an esw via
> mlx5e_configure_flower -> mlx5_esw_get -> atomic64_inc(&esw->user_count)
> 
> esw.user_count was unconditionally set to 0 in
> esw_destroy_legacy_fdb_table and esw_destroy_offloads_fdb_tables.
> 
> [...]

Here is the summary with links:
  - [net] net/mlx5: Don't zero user_count when destroying FDB tables
    https://git.kernel.org/netdev/net/c/53110232c95f

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-30  1:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-26 20:20 [PATCH net] net/mlx5: Don't zero user_count when destroying FDB tables Tariq Toukan
2025-10-28 16:57 ` Simon Horman
2025-10-30  1:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).