Skip to contentSkip to conversation

mlx5 misc fixes 2024-12-20

PATCH Applied Tariq Toukan 4 participants 9 messages Dec 20, 2024 – Dec 23, 2024

Subsystems (6)
lore
Share & tools
lore

Tariq Toukan

author maintainer
#0 lore raw

cover mlx5 misc fixes 2024-12-20

Hi,

This small patchset provides misc bug fixes from the team to the mlx5 core and Eth drivers.

Thanks,
Tariq.

Dragos Tatulea (1):
net/mlx5e: macsec: Maintain TX SA from encoding_sa

Jianbo Liu (2):
net/mlx5e: Skip restore TC rules for vport rep without loaded flag net/mlx5e: Keep netdev when leave switchdev for devlink set legacy
only

Shahar Shitrit (1):
net/mlx5: DR, select MSIX vector 0 for completion queue creation

 .../mellanox/mlx5/core/en_accel/macsec.c      |  4 ++++
 .../net/ethernet/mellanox/mlx5/core/en_main.c | 19 +++++++++++++++++--
 .../net/ethernet/mellanox/mlx5/core/en_rep.c  | 15 +++++++++++++++
 .../mellanox/mlx5/core/esw/ipsec_fs.c         |  6 +++---
 .../net/ethernet/mellanox/mlx5/core/eswitch.h |  3 +++
 .../mellanox/mlx5/core/eswitch_offloads.c     |  5 ++---
 .../mellanox/mlx5/core/steering/sws/dr_send.c |  4 +---
 include/linux/mlx5/driver.h                   |  1 +
 8 files changed, 46 insertions(+), 11 deletions(-)

base-commit: b6075c80537558b16ff72861af4c0539c375e11b

Signature · 1 line
2.45.0
author maintainer
#1 lore raw

PATCH 1/4 net/mlx5: DR, select MSIX vector 0 for completion queue creation

From: Shahar Shitrit <[email protected]>

When creating a software steering completion queue (CQ), an arbitrary MSIX vector n is selected. This results in the CQ sharing the same Ethernet traffic channel n associated with the chosen vector. However, the value of n is often unpredictable, which can introduce complications for interrupt monitoring and verification tools.

Moreover, SW steering uses polling rather than event-driven interrupts. Therefore, there is no need to select any MSIX vector other than the existing vector 0 for CQ creation.

In light of these factors, and to enhance predictability, we modify the code to consistently select MSIX vector 0 for CQ creation.

Fixes 297cccebdc5a ("net/mlx5: DR, Expose an internal API to issue RDMA operations")
---
 .../net/ethernet/mellanox/mlx5/core/steering/sws/dr_send.c    | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_send.c +1 -3
index 6fa06ba2d346..f57c84e5128b 100644
@@ -1067,7 +1067,6 @@ static struct mlx5dr_cq *dr_create_cq(struct mlx5_core_dev *mdev,
 	int inlen, err, eqn;
 	void *cqc, *in;
 	__be64 *pas;
-	int vector;
 	u32 i;
 
 	cq = kzalloc(sizeof(*cq), GFP_KERNEL);
@@ -1096,8 +1095,7 @@ static struct mlx5dr_cq *dr_create_cq(struct mlx5_core_dev *mdev,
 	if (!in)
 		goto err_cqwq;
 
-	vector = raw_smp_processor_id() % mlx5_comp_vectors_max(mdev);
-	err = mlx5_comp_eqn_get(mdev, vector, &eqn);
+	err = mlx5_comp_eqn_get(mdev, 0, &eqn);
 	if (err) {
 		kvfree(in);
 		goto err_cqwq;
Signature · 1 line
2.45.0
author maintainer
#2 lore raw

PATCH 2/4 net/mlx5e: macsec: Maintain TX SA from encoding_sa

In reply to Tariq Toukan

From: Dragos Tatulea <[email protected]>

In MACsec, it is possible to create multiple active TX SAs on a SC, but only one such SA can be used at a time for transmission. This SA is selected through the encoding_sa link parameter.

When there are 2 or more active TX SAs configured (encoding_sa=0):
ip macsec add macsec0 tx sa 0 pn 1 on key 00 <KEY1> ip macsec add macsec0 tx sa 1 pn 1 on key 00 <KEY2>

... the traffic should be still sent via TX SA 0 as the encoding_sa was not changed. However, the driver ignores the encoding_sa and overrides it to SA 1 by installing the flow steering id of the newly created TX SA into the SCI -> flow steering id hash map. The future packet tx descriptors will point to the incorrect flow steering rule (SA 1).

This patch fixes the issue by avoiding the creation of the flow steering rule for an active TX SA that is not the encoding_sa. The driver side tx_sa object and the FW side macsec object are still created. When the encoding_sa link parameter is changed to another active TX SA, only the new flow steering rule will be created in the mlx5e_macsec_upd_txsa() handler.

Fixes 8ff0ac5be144 ("net/mlx5: Add MACsec offload Tx command support")
---
 drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c +4 -0
index cc9bcc420032..6ab02f3fc291 100644
@@ -339,9 +339,13 @@ static int mlx5e_macsec_init_sa_fs(struct macsec_context *ctx,
 {
 	struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
 	struct mlx5_macsec_fs *macsec_fs = priv->mdev->macsec_fs;
+	const struct macsec_tx_sc *tx_sc = &ctx->secy->tx_sc;
 	struct mlx5_macsec_rule_attrs rule_attrs;
 	union mlx5_macsec_rule *macsec_rule;
 
+	if (is_tx && tx_sc->encoding_sa != sa->assoc_num)
+		return 0;
+
 	rule_attrs.macsec_obj_id = sa->macsec_obj_id;
 	rule_attrs.sci = sa->sci;
 	rule_attrs.assoc_num = sa->assoc_num;
Signature · 1 line
2.45.0
author maintainer
#3 lore raw

PATCH 3/4 net/mlx5e: Skip restore TC rules for vport rep without loaded flag

In reply to Tariq Toukan

From: Jianbo Liu <[email protected]>

During driver unload, unregister_netdev is called after unloading vport rep. So, the mlx5e_rep_priv is already freed while trying to get rpriv->netdev, or walk rpriv->tc_ht, which results in use-after-free. So add the checking to make sure access the data of vport rep which is still loaded.

Fixes d1569537a837 ("net/mlx5e: Modify and restore TC rules for IPSec TX rules")
---
 drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.c     | 6 +++---
 drivers/net/ethernet/mellanox/mlx5/core/eswitch.h          | 3 +++
 drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c | 3 ---
 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec_fs.c +3 -3
index 5a0047bdcb51..ed977ae75fab 100644
@@ -150,11 +150,11 @@ void mlx5_esw_ipsec_restore_dest_uplink(struct mlx5_core_dev *mdev)
 	unsigned long i;
 	int err;
 
-	xa_for_each(&esw->offloads.vport_reps, i, rep) {
-		rpriv = rep->rep_data[REP_ETH].priv;
-		if (!rpriv || !rpriv->netdev)
+	mlx5_esw_for_each_rep(esw, i, rep) {
+		if (atomic_read(&rep->rep_data[REP_ETH].state) != REP_LOADED)
 			continue;
 
+		rpriv = rep->rep_data[REP_ETH].priv;
 		rhashtable_walk_enter(&rpriv->tc_ht, &iter);
 		rhashtable_walk_start(&iter);
 		while ((flow = rhashtable_walk_next(&iter)) != NULL) {
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +3 -0
index a83d41121db6..8573d36785f4 100644
@@ -714,6 +714,9 @@ void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw);
 			  MLX5_CAP_GEN_2((esw->dev), ec_vf_vport_base) +\
 			  (last) - 1)
 
+#define mlx5_esw_for_each_rep(esw, i, rep) \
+	xa_for_each(&((esw)->offloads.vport_reps), i, rep)
+
 struct mlx5_eswitch *__must_check
 mlx5_devlink_eswitch_get(struct devlink *devlink);
 
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +0 -3
index d5b42b3a19fd..40359f320724 100644
@@ -53,9 +53,6 @@
 #include "lag/lag.h"
 #include "en/tc/post_meter.h"
 
-#define mlx5_esw_for_each_rep(esw, i, rep) \
-	xa_for_each(&((esw)->offloads.vport_reps), i, rep)
-
 /* There are two match-all miss flows, one for unicast dst mac and
  * one for multicast.
  */
Signature · 1 line
2.45.0
author maintainer
#4 lore raw

PATCH 4/4 net/mlx5e: Keep netdev when leave switchdev for devlink set legacy only

In reply to Tariq Toukan

From: Jianbo Liu <[email protected]>

In the cited commit, when changing from switchdev to legacy mode, uplink representor's netdev is kept, and its profile is replaced with nic profile, so netdev is detached from old profile, then attach to new profile.

During profile change, the hardware resources allocated by the old profile will be cleaned up. However, the cleanup is relying on the related kernel modules. And they may need to flush themselves first, which is triggered by netdev events, for example, NETDEV_UNREGISTER. However, netdev is kept, or netdev_register is called after the cleanup, which may cause troubles because the resources are still referred by kernel modules.

The same process applies to all the caes when uplink is leaving switchdev mode, including devlink eswitch mode set legacy, driver unload and devlink reload. For the first one, it can be blocked and returns failure to users, whenever possible. But it's hard for the others. Besides, the attachment to nic profile is unnecessary as the netdev will be unregistered anyway for such cases.

So in this patch, the original behavior is kept only for devlink eswitch set mode legacy. For the others, moves netdev unregistration before the profile change.

Fixes 7a9fb35e8c3a ("net/mlx5e: Do not reload ethernet ports when changing eswitch mode")
---
 .../net/ethernet/mellanox/mlx5/core/en_main.c | 19 +++++++++++++++++--
 .../net/ethernet/mellanox/mlx5/core/en_rep.c  | 15 +++++++++++++++
 .../mellanox/mlx5/core/eswitch_offloads.c     |  2 ++
 include/linux/mlx5/driver.h                   |  1 +
 4 files changed, 35 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +17 -2
index dd16d73000c3..0ec17c276bdd 100644
@@ -6542,8 +6542,23 @@ static void _mlx5e_remove(struct auxiliary_device *adev)
 
 	mlx5_core_uplink_netdev_set(mdev, NULL);
 	mlx5e_dcbnl_delete_app(priv);
-	unregister_netdev(priv->netdev);
-	_mlx5e_suspend(adev, false);
+	/* When unload driver, the netdev is in registered state
+	 * if it's from legacy mode. If from switchdev mode, it
+	 * is already unregistered before changing to NIC profile.
+	 */
+	if (priv->netdev->reg_state == NETREG_REGISTERED) {
+		unregister_netdev(priv->netdev);
+		_mlx5e_suspend(adev, false);
+	} else {
+		struct mlx5_core_dev *pos;
+		int i;
+
+		if (test_bit(MLX5E_STATE_DESTROYING, &priv->state))
+			mlx5_sd_for_each_dev(i, mdev, pos)
+				mlx5e_destroy_mdev_resources(pos);
+		else
+			_mlx5e_suspend(adev, true);
+	}
 	/* Avoid cleanup if profile rollback failed. */
 	if (priv->profile)
 		priv->profile->cleanup(priv);
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +15 -0
index 554f9cb5b53f..fdff9fd8a89e 100644
@@ -1509,6 +1509,21 @@ mlx5e_vport_uplink_rep_unload(struct mlx5e_rep_priv *rpriv)
 
 	priv = netdev_priv(netdev);
 
+	/* This bit is set when using devlink to change eswitch mode from
+	 * switchdev to legacy. As need to keep uplink netdev ifindex, we
+	 * detach uplink representor profile and attach NIC profile only.
+	 * The netdev will be unregistered later when unload NIC auxiliary
+	 * driver for this case.
+	 * We explicitly block devlink eswitch mode change if any IPSec rules
+	 * offloaded, but can't block other cases, such as driver unload
+	 * and devlink reload. We have to unregister netdev before profile
+	 * change for those cases. This is to avoid resource leak because
+	 * the offloaded rules don't have the chance to be unoffloaded before
+	 * cleanup which is triggered by detach uplink representor profile.
+	 */
+	if (!(priv->mdev->priv.flags & MLX5_PRIV_FLAGS_SWITCH_LEGACY))
+		unregister_netdev(netdev);
+
 	mlx5e_netdev_attach_nic_profile(priv);
 }
 
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +2 -0
index 40359f320724..06076dd9ec64 100644
@@ -3777,6 +3777,8 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
 	esw->eswitch_operation_in_progress = true;
 	up_write(&esw->mode_lock);
 
+	if (mode == DEVLINK_ESWITCH_MODE_LEGACY)
+		esw->dev->priv.flags |= MLX5_PRIV_FLAGS_SWITCH_LEGACY;
 	mlx5_eswitch_disable_locked(esw);
 	if (mode == DEVLINK_ESWITCH_MODE_SWITCHDEV) {
 		if (mlx5_devlink_trap_get_num_active(esw->dev)) {
include/linux/mlx5/driver.h +1 -0
index fc7e6153b73d..8f5991168ccd 100644
@@ -524,6 +524,7 @@ enum {
 	 * creation/deletion on drivers rescan. Unset during device attach.
 	 */
 	MLX5_PRIV_FLAGS_DETACH = 1 << 2,
+	MLX5_PRIV_FLAGS_SWITCH_LEGACY = 1 << 3,
 };
 
 struct mlx5_adev {
Signature · 1 line
2.45.0
#5 lore raw

Re: [PATCH net 4/4] net/mlx5e: Keep netdev when leave switchdev for devlink set legacy only

Quoted 15 lines · Tariq Toukan

From: Jianbo Liu <[email protected]>

In the cited commit, when changing from switchdev to legacy mode, uplink representor's netdev is kept, and its profile is replaced with nic profile, so netdev is detached from old profile, then attach to new profile.

During profile change, the hardware resources allocated by the old profile will be cleaned up. However, the cleanup is relying on the related kernel modules. And they may need to flush themselves first, which is triggered by netdev events, for example, NETDEV_UNREGISTER. However, netdev is kept, or netdev_register is called after the cleanup, which may cause troubles because the resources are still referred by kernel modules.

Quoted 1 line

The same process applies to all the caes when uplink is leaving

case

Quoted 13 lines

switchdev mode, including devlink eswitch mode set legacy, driver unload and devlink reload. For the first one, it can be blocked and returns failure to users, whenever possible. But it's hard for the others. Besides, the attachment to nic profile is unnecessary as the netdev will be unregistered anyway for such cases.

So in this patch, the original behavior is kept only for devlink eswitch set mode legacy. For the others, moves netdev unregistration before the profile change.

Fixes 7a9fb35e8c3a ("net/mlx5e: Do not reload ethernet ports when changing eswitch mode")
Quoted 7 lines
---
  .../net/ethernet/mellanox/mlx5/core/en_main.c | 19 +++++++++++++++++--
  .../net/ethernet/mellanox/mlx5/core/en_rep.c  | 15 +++++++++++++++
  .../mellanox/mlx5/core/eswitch_offloads.c     |  2 ++
  include/linux/mlx5/driver.h                   |  1 +
  4 files changed, 35 insertions(+), 2 deletions(-)

sorry for nitpick-only review
I didn't spotted anything bad in the logic through the series OTOH

drivers/net/ethernet/mellanox/mlx5/core/en_main.c static void _mlx5e_remove(struct auxiliary_device *adev) · line 6545

Quoted 11 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +1 -2
index dd16d73000c3..0ec17c276bdd 100644
@@ -6542,8 +6542,23 @@ static void _mlx5e_remove(struct auxiliary_device *adev)
 
  	mlx5_core_uplink_netdev_set(mdev, NULL);
  	mlx5e_dcbnl_delete_app(priv);
-	unregister_netdev(priv->netdev);
-	_mlx5e_suspend(adev, false);
+	/* When unload driver, the netdev is in registered state

/*
* Netdev dropped the special comment allowance rule,
* now you have to put one line almost blank at the front. */

drivers/net/ethernet/mellanox/mlx5/core/en_main.c static void _mlx5e_remove(struct auxiliary_device *adev) · line 6556

Quoted 11 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +11 -0
+	 * if it's from legacy mode. If from switchdev mode, it
+	 * is already unregistered before changing to NIC profile.
+	 */
+	if (priv->netdev->reg_state == NETREG_REGISTERED) {
+		unregister_netdev(priv->netdev);
+		_mlx5e_suspend(adev, false);
+	} else {
+		struct mlx5_core_dev *pos;
+		int i;
+
+		if (test_bit(MLX5E_STATE_DESTROYING, &priv->state))

you have more than one statement/expression inside the if, so you must wrap with braces

Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +5 -0
+			mlx5_sd_for_each_dev(i, mdev, pos)
+				mlx5e_destroy_mdev_resources(pos);
+		else
+			_mlx5e_suspend(adev, true);
+	}
  	/* Avoid cleanup if profile rollback failed. */
  	if (priv->profile)
  		priv->profile->cleanup(priv);
maintainer
#6 lore raw

Re: [PATCH net 4/4] net/mlx5e: Keep netdev when leave switchdev for devlink set legacy only

Quoted 10 lines · On Fri, 20 Dec 2024 09:48:11 +0100 Przemek Kitszel wrote:

drivers/net/ethernet/mellanox/mlx5/core/en_main.c static void _mlx5e_remove(struct auxiliary_device *adev) · line 6545

Quoted 5 lines
  	mlx5_core_uplink_netdev_set(mdev, NULL);
  	mlx5e_dcbnl_delete_app(priv);
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +1 -2
-	unregister_netdev(priv->netdev);
-	_mlx5e_suspend(adev, false);
+	/* When unload driver, the netdev is in registered state  

/*
* Netdev dropped the special comment allowance rule,
* now you have to put one line almost blank at the front. */

Incorrect, we still prefer the old comment style, we just give a pass now to people who have a strong preference the opposite way.

Quoted 6 lines
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +6 -0
+	 * if it's from legacy mode. If from switchdev mode, it
+	 * is already unregistered before changing to NIC profile.
+	 */
+	if (priv->netdev->reg_state == NETREG_REGISTERED) {
+		unregister_netdev(priv->netdev);
+		_mlx5e_suspend(adev, false);
Quoted 8 lines

drivers/net/ethernet/mellanox/mlx5/core/en_main.c static void _mlx5e_remove(struct auxiliary_device *adev) · line 6556

Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +5 -0
+	} else {
+		struct mlx5_core_dev *pos;
+		int i;
+
+		if (test_bit(MLX5E_STATE_DESTROYING, &priv->state))  

you have more than one statement/expression inside the if, so you must wrap with braces

I'm not aware of that as a hard rule either.

#7 lore raw

Re: [PATCH net 4/4] net/mlx5e: Keep netdev when leave switchdev for devlink set legacy only

Quoted 12 lines · Jakub Kicinski
Quoted 10 lines · On Fri, 20 Dec 2024 09:48:11 +0100 Przemek Kitszel wrote:

drivers/net/ethernet/mellanox/mlx5/core/en_main.c static void _mlx5e_remove(struct auxiliary_device *adev) · line 6545

Quoted 5 lines
   	mlx5_core_uplink_netdev_set(mdev, NULL);
   	mlx5e_dcbnl_delete_app(priv);
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +1 -2
-	unregister_netdev(priv->netdev);
-	_mlx5e_suspend(adev, false);
+	/* When unload driver, the netdev is in registered state

/*
* Netdev dropped the special comment allowance rule,
* now you have to put one line almost blank at the front. */

Quoted 2 lines

Incorrect, we still prefer the old comment style, we just give a pass now to people who have a strong preference the opposite way.

good to know, I will pass it down to my folks

Quoted 16 lines
Quoted 15 lines

drivers/net/ethernet/mellanox/mlx5/core/en_main.c static void _mlx5e_remove(struct auxiliary_device *adev) · line 6556

Quoted 12 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +11 -0
+	 * if it's from legacy mode. If from switchdev mode, it
+	 * is already unregistered before changing to NIC profile.
+	 */
+	if (priv->netdev->reg_state == NETREG_REGISTERED) {
+		unregister_netdev(priv->netdev);
+		_mlx5e_suspend(adev, false);
+	} else {
+		struct mlx5_core_dev *pos;
+		int i;
+
+		if (test_bit(MLX5E_STATE_DESTROYING, &priv->state))

you have more than one statement/expression inside the if, so you must wrap with braces

Quoted 1 line

I'm not aware of that as a hard rule either.

[1] says
"Also, use braces when a loop contains more than a single simple statement:"

And I see that here we have and if() instead of a loop, but I believe that the intent of "the rule" (not sure how hard) was to pet the brace in such cases.
To be clear, I don't want to stop an otherwise good PR just for this!

[1] https://www.kernel.org/doc/html/latest/process/coding-style.html#placing-braces-and-spaces

#8 lore raw
In reply to Tariq Toukan
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Fri, 20 Dec 2024 10:15:01 +0200 you wrote:

Hi,

This small patchset provides misc bug fixes from the team to the mlx5 core and Eth drivers.

Thanks,
Tariq.

[...]

Here is the summary with links:
- [net,1/4] net/mlx5: DR, select MSIX vector 0 for completion queue creation

    https://git.kernel.org/netdev/net/c/050a4c011b0d
  - [net,2/4] net/mlx5e: macsec: Maintain TX SA from encoding_sa
    https://git.kernel.org/netdev/net/c/8c6254479b3d
  - [net,3/4] net/mlx5e: Skip restore TC rules for vport rep without loaded flag
    https://git.kernel.org/netdev/net/c/5a03b368562a
  - [net,4/4] net/mlx5e: Keep netdev when leave switchdev for devlink set legacy only
    https://git.kernel.org/netdev/net/c/2a4f56fbcc47

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html