Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] net/mlx5: Speed up device teardown by avoiding RCU grace periods
@ 2026-11-29 11:27 Tariq Toukan
  2026-11-29 11:27 ` [PATCH net-next 1/2] net/mlx5: Avoid RCU synchronization when detaching IRQ notifiers Tariq Toukan
  2026-11-29 11:27 ` [PATCH net-next 2/2] net/mlx5: Use a single EQ notifier for core events Tariq Toukan
  0 siblings, 2 replies; 3+ messages in thread
From: Tariq Toukan @ 2026-11-29 11:27 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni, Willem de Bruijn
  Cc: Carolina Jubran, Gal Pressman, Leon Romanovsky, linux-rdma,
	Mark Bloch, Saeed Mahameed, Shay Drori, Tariq Toukan

Hi,

This series by Carolina reduces the time it takes to tear down an mlx5
device, which is dominated by repeated waits for RCU grace periods
during notifier unregistration.

EQ teardown unregisters IRQ notifiers one by one, and the core event
handling registers 18 separate EQ notifiers that are unregistered
individually in mlx5_events_stop(). Each unregister waits for an RCU
grace period, which adds significant latency when destroying multiple
EQs and when stopping the device.

Patch 1 switches the IRQ notifier chain to a raw notifier chain
protected by a spinlock for updates. Since the chain is walked only by
the handler of the same IRQ, synchronize_irq() after unlinking a
notifier is enough to ensure no handler still uses it, so no RCU grace
period is needed per unregister.

Patch 2 replaces the 18 per-event-type EQ notifiers registered by
mlx5_events_start() with a single NOTIFY_ANY notifier that dispatches
the events by type, so mlx5_events_stop() waits for one grace period
instead of 18.

Measured on "rmmod mlx5_ib mlx5_dpll mlx5_fwctl mlx5_core", with
rcu_expedited=0, two PFs and 72 channels per PF, patch 1 reduces the
time from 6.316 s to 4.287 s (239 to 89 synchronize_rcu() calls), and
patch 2 further reduces it to 3.878 s.

Regards,
Tariq

Carolina Jubran (2):
  net/mlx5: Avoid RCU synchronization when detaching IRQ notifiers
  net/mlx5: Use a single EQ notifier for core events

 .../net/ethernet/mellanox/mlx5/core/events.c  | 78 ++++++++++---------
 .../net/ethernet/mellanox/mlx5/core/pci_irq.c | 28 +++++--
 2 files changed, 64 insertions(+), 42 deletions(-)


base-commit: f89726ffabef1b08c52e6163b7ab94b0d5f15503
-- 
2.44.0


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

* [PATCH net-next 1/2] net/mlx5: Avoid RCU synchronization when detaching IRQ notifiers
  2026-11-29 11:27 [PATCH net-next 0/2] net/mlx5: Speed up device teardown by avoiding RCU grace periods Tariq Toukan
@ 2026-11-29 11:27 ` Tariq Toukan
  2026-11-29 11:27 ` [PATCH net-next 2/2] net/mlx5: Use a single EQ notifier for core events Tariq Toukan
  1 sibling, 0 replies; 3+ messages in thread
From: Tariq Toukan @ 2026-11-29 11:27 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni, Willem de Bruijn
  Cc: Carolina Jubran, Gal Pressman, Leon Romanovsky, linux-rdma,
	Mark Bloch, Saeed Mahameed, Shay Drori, Tariq Toukan

From: Carolina Jubran <cjubran@nvidia.com>

EQ teardown unregisters IRQ notifiers individually, with each
unregister waiting for an RCU grace period. This introduces
significant latency when destroying multiple EQs.

The IRQ notifier chain is walked only by the handler of the same IRQ,
so once a notifier is unlinked, synchronize_irq() is enough to ensure
no handler still uses it.

Use a raw notifier chain and synchronize_irq() instead.

Measurements of "rmmod mlx5_ib mlx5_dpll mlx5_fwctl mlx5_core", with
rcu_expedited=0, two PFs, and 72 channels per PF:

Before: 6.316 s, 239 synchronize_rcu() calls
After:  4.287 s,  89 synchronize_rcu() calls

Signed-off-by: Carolina Jubran <cjubran@nvidia.com>
Reviewed-by: Shay Drori <shayd@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../net/ethernet/mellanox/mlx5/core/pci_irq.c | 28 +++++++++++++++----
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c b/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c
index 2bcafc572a42..4bf1af8ef205 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c
@@ -4,6 +4,7 @@
 #include <linux/pci.h>
 #include <linux/interrupt.h>
 #include <linux/notifier.h>
+#include <linux/rcupdate.h>
 #include <linux/mlx5/driver.h>
 #include <linux/mlx5/vport.h>
 #include "mlx5_core.h"
@@ -28,7 +29,9 @@
 #define MLX5_EQ_SHARE_IRQ_MIN_CTRL (4)
 
 struct mlx5_irq {
-	struct atomic_notifier_head nh;
+	/* Walked only by irq_int_handler(), see mlx5_irq_detach_nb() */
+	struct raw_notifier_head nh;
+	spinlock_t nh_lock; /* serializes nh updates */
 	cpumask_var_t mask;
 	char name[MLX5_MAX_IRQ_FORMATTED_NAME];
 	struct mlx5_irq_pool *pool;
@@ -213,7 +216,9 @@ static int irq_get(struct mlx5_irq *irq)
 
 static irqreturn_t irq_int_handler(int irq, void *nh)
 {
-	atomic_notifier_call_chain(nh, 0, NULL);
+	rcu_read_lock();
+	raw_notifier_call_chain(nh, 0, NULL);
+	rcu_read_unlock();
 	return IRQ_HANDLED;
 }
 
@@ -281,7 +286,8 @@ struct mlx5_irq *mlx5_irq_alloc(struct mlx5_irq_pool *pool, int i,
 		irq_set_name(pool, name, i);
 	else
 		irq_sf_set_name(pool, name, i);
-	ATOMIC_INIT_NOTIFIER_HEAD(&irq->nh);
+	RAW_INIT_NOTIFIER_HEAD(&irq->nh);
+	spin_lock_init(&irq->nh_lock);
 	snprintf(irq->name, MLX5_MAX_IRQ_FORMATTED_NAME,
 		 MLX5_IRQ_NAME_FORMAT_STR, name, pci_name(dev->pdev));
 	err = request_irq(irq->map.virq, irq_int_handler, 0, irq->name,
@@ -325,6 +331,7 @@ struct mlx5_irq *mlx5_irq_alloc(struct mlx5_irq_pool *pool, int i,
 
 int mlx5_irq_attach_nb(struct mlx5_irq *irq, struct notifier_block *nb)
 {
+	unsigned long flags;
 	int ret;
 
 	ret = irq_get(irq);
@@ -333,7 +340,9 @@ int mlx5_irq_attach_nb(struct mlx5_irq *irq, struct notifier_block *nb)
 		 * on non-existing IRQ.
 		 */
 		return -ENOENT;
-	ret = atomic_notifier_chain_register(&irq->nh, nb);
+	spin_lock_irqsave(&irq->nh_lock, flags);
+	ret = raw_notifier_chain_register(&irq->nh, nb);
+	spin_unlock_irqrestore(&irq->nh_lock, flags);
 	if (ret)
 		mlx5_irq_put(irq);
 	return ret;
@@ -341,9 +350,16 @@ int mlx5_irq_attach_nb(struct mlx5_irq *irq, struct notifier_block *nb)
 
 int mlx5_irq_detach_nb(struct mlx5_irq *irq, struct notifier_block *nb)
 {
-	int err = 0;
+	unsigned long flags;
+	int err;
 
-	err = atomic_notifier_chain_unregister(&irq->nh, nb);
+	spin_lock_irqsave(&irq->nh_lock, flags);
+	err = raw_notifier_chain_unregister(&irq->nh, nb);
+	spin_unlock_irqrestore(&irq->nh_lock, flags);
+	/* The chain is walked only by irq_int_handler(), so waiting for
+	 * in flight handlers is enough to stop using nb.
+	 */
+	synchronize_irq(irq->map.virq);
 	mlx5_irq_put(irq);
 	return err;
 }
-- 
2.44.0


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

* [PATCH net-next 2/2] net/mlx5: Use a single EQ notifier for core events
  2026-11-29 11:27 [PATCH net-next 0/2] net/mlx5: Speed up device teardown by avoiding RCU grace periods Tariq Toukan
  2026-11-29 11:27 ` [PATCH net-next 1/2] net/mlx5: Avoid RCU synchronization when detaching IRQ notifiers Tariq Toukan
@ 2026-11-29 11:27 ` Tariq Toukan
  1 sibling, 0 replies; 3+ messages in thread
From: Tariq Toukan @ 2026-11-29 11:27 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni, Willem de Bruijn
  Cc: Carolina Jubran, Gal Pressman, Leon Romanovsky, linux-rdma,
	Mark Bloch, Saeed Mahameed, Shay Drori, Tariq Toukan

From: Carolina Jubran <cjubran@nvidia.com>

mlx5_events_start() registers 18 EQ notifiers, one per event type
handled by the core, and mlx5_events_stop() unregisters them one by
one. Each unregister waits for an RCU grace period, which adds
significant latency to device teardown.

Register a single NOTIFY_ANY notifier and dispatch the events by type,
so mlx5_events_stop() waits for one grace period instead of 18.

Measurements of "rmmod mlx5_ib mlx5_dpll mlx5_fwctl mlx5_core", with
rcu_expedited=0, two PFs, 72 channels per PF and with the IRQ notifier
optimization already applied:

Before: 4.287 s
After:  3.878 s

Signed-off-by: Carolina Jubran <cjubran@nvidia.com>
Reviewed-by: Shay Drori <shayd@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../net/ethernet/mellanox/mlx5/core/events.c  | 78 ++++++++++---------
 1 file changed, 42 insertions(+), 36 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/events.c b/drivers/net/ethernet/mellanox/mlx5/core/events.c
index 4d7f35b96876..56c06edd6770 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/events.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/events.c
@@ -27,36 +27,10 @@ static int pcie_core(struct notifier_block *, unsigned long, void *);
 /* handler which forwards the event to events->fw_nh, driver notifiers */
 static int forward_event(struct notifier_block *, unsigned long, void *);
 
-static struct mlx5_nb events_nbs_ref[] = {
-	/* Events to be processed by mlx5_core */
-	{.nb.notifier_call = any_notifier,  .event_type = MLX5_EVENT_TYPE_NOTIFY_ANY },
-	{.nb.notifier_call = temp_warn,     .event_type = MLX5_EVENT_TYPE_TEMP_WARN_EVENT },
-	{.nb.notifier_call = port_module,   .event_type = MLX5_EVENT_TYPE_PORT_MODULE_EVENT },
-	{.nb.notifier_call = pcie_core,     .event_type = MLX5_EVENT_TYPE_GENERAL_EVENT },
-
-	/* Events to be forwarded (as is) to mlx5 core interfaces (mlx5e/mlx5_ib) */
-	{.nb.notifier_call = forward_event,   .event_type = MLX5_EVENT_TYPE_PORT_CHANGE },
-	{.nb.notifier_call = forward_event,   .event_type = MLX5_EVENT_TYPE_GENERAL_EVENT },
-	{.nb.notifier_call = forward_event,   .event_type = MLX5_EVENT_TYPE_OBJECT_CHANGE },
-	/* QP/WQ resource events to forward */
-	{.nb.notifier_call = forward_event,   .event_type = MLX5_EVENT_TYPE_DCT_DRAINED },
-	{.nb.notifier_call = forward_event,   .event_type = MLX5_EVENT_TYPE_PATH_MIG },
-	{.nb.notifier_call = forward_event,   .event_type = MLX5_EVENT_TYPE_COMM_EST },
-	{.nb.notifier_call = forward_event,   .event_type = MLX5_EVENT_TYPE_SQ_DRAINED },
-	{.nb.notifier_call = forward_event,   .event_type = MLX5_EVENT_TYPE_SRQ_LAST_WQE },
-	{.nb.notifier_call = forward_event,   .event_type = MLX5_EVENT_TYPE_WQ_CATAS_ERROR },
-	{.nb.notifier_call = forward_event,   .event_type = MLX5_EVENT_TYPE_PATH_MIG_FAILED },
-	{.nb.notifier_call = forward_event,   .event_type = MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR },
-	{.nb.notifier_call = forward_event,   .event_type = MLX5_EVENT_TYPE_WQ_ACCESS_ERROR },
-	/* SRQ events */
-	{.nb.notifier_call = forward_event,   .event_type = MLX5_EVENT_TYPE_SRQ_CATAS_ERROR },
-	{.nb.notifier_call = forward_event,   .event_type = MLX5_EVENT_TYPE_SRQ_RQ_LIMIT },
-};
-
 struct mlx5_events {
 	struct mlx5_core_dev *dev;
 	struct workqueue_struct *wq;
-	struct mlx5_event_nb  notifiers[ARRAY_SIZE(events_nbs_ref)];
+	struct mlx5_event_nb notifier;
 	/* driver notifier chain for fw events */
 	struct atomic_notifier_head fw_nh;
 	/* port module events stats */
@@ -372,6 +346,42 @@ static int forward_event(struct notifier_block *nb, unsigned long event, void *d
 	return NOTIFY_OK;
 }
 
+/* Dispatch internal events through a single EQ notifier. */
+static int mlx5_event_dispatch(struct notifier_block *nb, unsigned long type,
+			       void *data)
+{
+	switch (type) {
+	case MLX5_EVENT_TYPE_TEMP_WARN_EVENT:
+		temp_warn(nb, type, data);
+		break;
+	case MLX5_EVENT_TYPE_PORT_MODULE_EVENT:
+		port_module(nb, type, data);
+		break;
+	case MLX5_EVENT_TYPE_GENERAL_EVENT:
+		pcie_core(nb, type, data);
+		fallthrough;
+	case MLX5_EVENT_TYPE_COMM_EST:
+	case MLX5_EVENT_TYPE_DCT_DRAINED:
+	case MLX5_EVENT_TYPE_OBJECT_CHANGE:
+	case MLX5_EVENT_TYPE_PATH_MIG:
+	case MLX5_EVENT_TYPE_PATH_MIG_FAILED:
+	case MLX5_EVENT_TYPE_PORT_CHANGE:
+	case MLX5_EVENT_TYPE_SQ_DRAINED:
+	case MLX5_EVENT_TYPE_SRQ_CATAS_ERROR:
+	case MLX5_EVENT_TYPE_SRQ_LAST_WQE:
+	case MLX5_EVENT_TYPE_SRQ_RQ_LIMIT:
+	case MLX5_EVENT_TYPE_WQ_ACCESS_ERROR:
+	case MLX5_EVENT_TYPE_WQ_CATAS_ERROR:
+	case MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
+		forward_event(nb, type, data);
+		break;
+	default:
+		break;
+	}
+
+	return any_notifier(nb, type, data);
+}
+
 int mlx5_events_init(struct mlx5_core_dev *dev)
 {
 	struct mlx5_events *events = kzalloc_obj(*events);
@@ -402,22 +412,18 @@ void mlx5_events_cleanup(struct mlx5_core_dev *dev)
 void mlx5_events_start(struct mlx5_core_dev *dev)
 {
 	struct mlx5_events *events = dev->priv.events;
-	int i;
 
-	for (i = 0; i < ARRAY_SIZE(events_nbs_ref); i++) {
-		events->notifiers[i].nb  = events_nbs_ref[i];
-		events->notifiers[i].ctx = events;
-		mlx5_eq_notifier_register(dev, &events->notifiers[i].nb);
-	}
+	events->notifier.nb.nb.notifier_call = mlx5_event_dispatch;
+	events->notifier.nb.event_type = MLX5_EVENT_TYPE_NOTIFY_ANY;
+	events->notifier.ctx = events;
+	mlx5_eq_notifier_register(dev, &events->notifier.nb);
 }
 
 void mlx5_events_stop(struct mlx5_core_dev *dev)
 {
 	struct mlx5_events *events = dev->priv.events;
-	int i;
 
-	for (i = ARRAY_SIZE(events_nbs_ref) - 1; i >= 0 ; i--)
-		mlx5_eq_notifier_unregister(dev, &events->notifiers[i].nb);
+	mlx5_eq_notifier_unregister(dev, &events->notifier.nb);
 	flush_workqueue(events->wq);
 }
 
-- 
2.44.0


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

end of thread, other threads:[~2026-11-29 11:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 11:27 [PATCH net-next 0/2] net/mlx5: Speed up device teardown by avoiding RCU grace periods Tariq Toukan
2026-11-29 11:27 ` [PATCH net-next 1/2] net/mlx5: Avoid RCU synchronization when detaching IRQ notifiers Tariq Toukan
2026-11-29 11:27 ` [PATCH net-next 2/2] net/mlx5: Use a single EQ notifier for core events Tariq Toukan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox