mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Changyul Lee <lcy8047@gmail.com>
To: Saeed Mahameed <saeedm@nvidia.com>,
	Leon Romanovsky <leon@kernel.org>,
	Tariq Toukan <tariqt@nvidia.com>, Mark Bloch <mbloch@nvidia.com>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Parav Pandit <parav@nvidia.com>, Shay Drory <shayd@nvidia.com>,
	netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-kernel@vger.kernel.org, Changyul Lee <lcy8047@gmail.com>
Subject: [PATCH net] net/mlx5: SF, remove probed SF devices when arming vhca events fails
Date: Mon, 16 Nov 2026 22:11:41 -0500	[thread overview]
Message-ID: <20261117031141.1720619-1-lcy8047@gmail.com> (raw)

mlx5_sf_dev_table_create() queues work that probes the SFs which are
already active, and then arms the vhca state events. If arming fails,
the arm_err path stops and flushes that work and frees the table, but
the SF devices that the work already added stay on the auxiliary bus
and in table->devices. dev->priv.sf_dev_table is set to NULL, so
mlx5_sf_dev_table_destroy() returns early later and nothing removes
them, while they keep pointing at the parent mlx5_core_dev.

Remove them with mlx5_sf_dev_destroy_all() after the work is flushed,
as mlx5_sf_dev_table_destroy() does. Move the helper up so that it is
defined before the new caller.

Fixes: 4f57332d6a55 ("net/mlx5: SF: Fix probing active SFs during driver probe phase")
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
---
Found with a static analysis tool we are developing.

Compile-tested only, with x86_64_defconfig plus MLX5_CORE, MLX5_CORE_EN,
MLX5_ESWITCH, MLX5_SF and W=1.

 .../ethernet/mellanox/mlx5/core/sf/dev/dev.c  | 23 ++++++++++---------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c
index e75cbf333898..44f6292ad59e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c
@@ -328,6 +328,17 @@ int mlx5_sf_dev_notifier_init(struct mlx5_core_dev *dev)
 	return mlx5_vhca_event_notifier_register(dev, &dev->priv.sf_dev_nb);
 }
 
+static void mlx5_sf_dev_destroy_all(struct mlx5_sf_dev_table *table)
+{
+	struct mlx5_sf_dev *sf_dev;
+	unsigned long index;
+
+	xa_for_each(&table->devices, index, sf_dev) {
+		xa_erase(&table->devices, index);
+		mlx5_sf_dev_remove_aux(table->dev, sf_dev);
+	}
+}
+
 void mlx5_sf_dev_table_create(struct mlx5_core_dev *dev)
 {
 	struct mlx5_sf_dev_table *table;
@@ -360,6 +371,7 @@ void mlx5_sf_dev_table_create(struct mlx5_core_dev *dev)
 arm_err:
 	mlx5_sf_dev_destroy_active_works(table);
 	mlx5_vhca_event_work_queues_flush(dev);
+	mlx5_sf_dev_destroy_all(table);
 add_active_err:
 	kfree(table);
 	dev->priv.sf_dev_table = NULL;
@@ -367,17 +379,6 @@ void mlx5_sf_dev_table_create(struct mlx5_core_dev *dev)
 	mlx5_core_err(dev, "SF DEV table create err = %d\n", err);
 }
 
-static void mlx5_sf_dev_destroy_all(struct mlx5_sf_dev_table *table)
-{
-	struct mlx5_sf_dev *sf_dev;
-	unsigned long index;
-
-	xa_for_each(&table->devices, index, sf_dev) {
-		xa_erase(&table->devices, index);
-		mlx5_sf_dev_remove_aux(table->dev, sf_dev);
-	}
-}
-
 void mlx5_sf_dev_notifier_cleanup(struct mlx5_core_dev *dev)
 {
 	if (mlx5_core_is_sf(dev))

base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
-- 
2.43.0


                 reply	other threads:[~2026-11-17  3:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261117031141.1720619-1-lcy8047@gmail.com \
    --to=lcy8047@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=parav@nvidia.com \
    --cc=saeedm@nvidia.com \
    --cc=shayd@nvidia.com \
    --cc=tariqt@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®