public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][net-next] net/mlx5: Expedite notifier unregistration during device teardown
@ 2026-03-12  9:48 lirongqing
  2026-03-14 17:54 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: lirongqing @ 2026-03-12  9:48 UTC (permalink / raw)
  To: Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Mark Bloch,
	Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Li RongQing, Paul E . McKenney, Frederic Weisbecker,
	netdev, linux-rdma, linux-kernel, Andrew Morton
  Cc: liyongkang

From: Li RongQing <lirongqing@baidu.com>

During device hot-unplug, the mlx5 driver expects quickly unregister
notification chains. The standard atomic_notifier_chain_unregister()
calls synchronize_rcu(), which introduces significant latency and
can become a bottleneck during mass resource cleanup.

Introduce atomic_notifier_chain_unregister_expedited() to leverage
synchronize_rcu_expedited(), and use it significantly reducing wait
times in the following paths:
 - Event Queue (EQ) notifier chain
 - Firmware event notifier chain
 - IRQ notifier chain

This acceleration ensures faster teardown during hot-unplug events.

Co-developed-by: liyongkang <liyongkang01@baidu.com>
Signed-off-by: liyongkang <liyongkang01@baidu.com>
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/eq.c      |  2 +-
 drivers/net/ethernet/mellanox/mlx5/core/events.c  |  2 +-
 drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c |  2 +-
 include/linux/notifier.h                          |  2 ++
 kernel/notifier.c                                 | 24 +++++++++++++++++++++++
 5 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eq.c b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
index 22a6371..03ae6ed 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eq.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
@@ -1244,6 +1244,6 @@ int mlx5_eq_notifier_unregister(struct mlx5_core_dev *dev, struct mlx5_nb *nb)
 {
 	struct mlx5_eq_table *eqt = dev->priv.eq_table;
 
-	return atomic_notifier_chain_unregister(&eqt->nh[nb->event_type], &nb->nb);
+	return atomic_notifier_chain_unregister_expedited(&eqt->nh[nb->event_type], &nb->nb);
 }
 EXPORT_SYMBOL(mlx5_eq_notifier_unregister);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/events.c b/drivers/net/ethernet/mellanox/mlx5/core/events.c
index 4d7f35b..753cb15 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/events.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/events.c
@@ -436,7 +436,7 @@ int mlx5_notifier_unregister(struct mlx5_core_dev *dev, struct notifier_block *n
 {
 	struct mlx5_events *events = dev->priv.events;
 
-	return atomic_notifier_chain_unregister(&events->fw_nh, nb);
+	return atomic_notifier_chain_unregister_expedited(&events->fw_nh, nb);
 }
 EXPORT_SYMBOL(mlx5_notifier_unregister);
 
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c b/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c
index e051b9a..826685d 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c
@@ -356,7 +356,7 @@ int mlx5_irq_detach_nb(struct mlx5_irq *irq, struct notifier_block *nb)
 {
 	int err = 0;
 
-	err = atomic_notifier_chain_unregister(&irq->nh, nb);
+	err = atomic_notifier_chain_unregister_expedited(&irq->nh, nb);
 	mlx5_irq_put(irq);
 	return err;
 }
diff --git a/include/linux/notifier.h b/include/linux/notifier.h
index 01b6c9d..156d958 100644
--- a/include/linux/notifier.h
+++ b/include/linux/notifier.h
@@ -159,6 +159,8 @@ extern int blocking_notifier_chain_register_unique_prio(
 
 extern int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
 		struct notifier_block *nb);
+extern int atomic_notifier_chain_unregister_expedited(struct atomic_notifier_head *nh,
+		struct notifier_block *nb);
 extern int blocking_notifier_chain_unregister(struct blocking_notifier_head *nh,
 		struct notifier_block *nb);
 extern int raw_notifier_chain_unregister(struct raw_notifier_head *nh,
diff --git a/kernel/notifier.c b/kernel/notifier.c
index 2f9fe7c..c6552e7 100644
--- a/kernel/notifier.c
+++ b/kernel/notifier.c
@@ -198,6 +198,30 @@ int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
 EXPORT_SYMBOL_GPL(atomic_notifier_chain_unregister);
 
 /**
+ *	atomic_notifier_chain_unregister_expedited - Remove notifier from an atomic notifier chain
+ *	@nh: Pointer to head of the atomic notifier chain
+ *	@n: Entry to remove from notifier chain
+ *
+ *	Removes a notifier from an atomic notifier chain and forcefully
+ *	accelerates the RCU grace period.
+ *
+ *	Returns zero on success or %-ENOENT on failure.
+ */
+int atomic_notifier_chain_unregister_expedited(struct atomic_notifier_head *nh,
+		struct notifier_block *n)
+{
+	unsigned long flags;
+	int ret;
+
+	spin_lock_irqsave(&nh->lock, flags);
+	ret = notifier_chain_unregister(&nh->head, n);
+	spin_unlock_irqrestore(&nh->lock, flags);
+	synchronize_rcu_expedited();
+	return ret;
+}
+EXPORT_SYMBOL_GPL(atomic_notifier_chain_unregister_expedited);
+
+/**
  *	atomic_notifier_call_chain - Call functions in an atomic notifier chain
  *	@nh: Pointer to head of the atomic notifier chain
  *	@val: Value passed unmodified to notifier function
-- 
2.9.4


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

* Re: [PATCH][net-next] net/mlx5: Expedite notifier unregistration during device teardown
  2026-03-12  9:48 [PATCH][net-next] net/mlx5: Expedite notifier unregistration during device teardown lirongqing
@ 2026-03-14 17:54 ` Jakub Kicinski
  2026-03-16  2:21   ` 答复: [????] " Li,Rongqing(ACG CCN)
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2026-03-14 17:54 UTC (permalink / raw)
  To: lirongqing
  Cc: Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Mark Bloch,
	Andrew Lunn, David S . Miller, Eric Dumazet, Paolo Abeni,
	Paul E . McKenney, Frederic Weisbecker, netdev, linux-rdma,
	linux-kernel, Andrew Morton, liyongkang

On Thu, 12 Mar 2026 05:48:04 -0400 lirongqing wrote:
> During device hot-unplug, the mlx5 driver expects quickly unregister
> notification chains. The standard atomic_notifier_chain_unregister()
> calls synchronize_rcu(), which introduces significant latency and
> can become a bottleneck during mass resource cleanup.
> 
> Introduce atomic_notifier_chain_unregister_expedited() to leverage
> synchronize_rcu_expedited(), and use it significantly reducing wait
> times in the following paths:
>  - Event Queue (EQ) notifier chain
>  - Firmware event notifier chain
>  - IRQ notifier chain
> 
> This acceleration ensures faster teardown during hot-unplug events.

Some detailed example and how long the whole operation takes would be
great in the commit msg.

>  /**
> + *	atomic_notifier_chain_unregister_expedited - Remove notifier from an atomic notifier chain
> + *	@nh: Pointer to head of the atomic notifier chain
> + *	@n: Entry to remove from notifier chain
> + *
> + *	Removes a notifier from an atomic notifier chain and forcefully
> + *	accelerates the RCU grace period.
> + *
> + *	Returns zero on success or %-ENOENT on failure.

Warning: kernel/notifier.c:211 No description found for return value of 'atomic_notifier_chain_unregister_expedited'

kdoc wants you to use Return: or Returns: the colon is how it knows this
is the doc for return value not just a random mention of the word
Returns
-- 
pw-bot: cr

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

* 答复: [????] Re: [PATCH][net-next] net/mlx5: Expedite notifier unregistration during device teardown
  2026-03-14 17:54 ` Jakub Kicinski
@ 2026-03-16  2:21   ` Li,Rongqing(ACG CCN)
  0 siblings, 0 replies; 3+ messages in thread
From: Li,Rongqing(ACG CCN) @ 2026-03-16  2:21 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Mark Bloch,
	Andrew Lunn, David S . Miller, Eric Dumazet, Paolo Abeni,
	Paul E . McKenney, Frederic Weisbecker, netdev@vger.kernel.org,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
	Andrew Morton, Li,Yongkang(ACG CCN)

> On Thu, 12 Mar 2026 05:48:04 -0400 lirongqing wrote:
> > During device hot-unplug, the mlx5 driver expects quickly unregister
> > notification chains. The standard atomic_notifier_chain_unregister()
> > calls synchronize_rcu(), which introduces significant latency and can
> > become a bottleneck during mass resource cleanup.
> >
> > Introduce atomic_notifier_chain_unregister_expedited() to leverage
> > synchronize_rcu_expedited(), and use it significantly reducing wait
> > times in the following paths:
> >  - Event Queue (EQ) notifier chain
> >  - Firmware event notifier chain
> >  - IRQ notifier chain
> >
> > This acceleration ensures faster teardown during hot-unplug events.
> 
> Some detailed example and how long the whole operation takes would be great
> in the commit msg.
> 
OK, I will add in v2 
> >  /**
> > + *	atomic_notifier_chain_unregister_expedited - Remove notifier from an
> atomic notifier chain
> > + *	@nh: Pointer to head of the atomic notifier chain
> > + *	@n: Entry to remove from notifier chain
> > + *
> > + *	Removes a notifier from an atomic notifier chain and forcefully
> > + *	accelerates the RCU grace period.
> > + *
> > + *	Returns zero on success or %-ENOENT on failure.
> 
> Warning: kernel/notifier.c:211 No description found for return value of
> 'atomic_notifier_chain_unregister_expedited'
> 
> kdoc wants you to use Return: or Returns: the colon is how it knows this is the
> doc for return value not just a random mention of the word Returns
> --
I will fix this in v2

Thank you

[Li,Rongqing] 

> pw-bot: cr

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

end of thread, other threads:[~2026-03-16  2:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-12  9:48 [PATCH][net-next] net/mlx5: Expedite notifier unregistration during device teardown lirongqing
2026-03-14 17:54 ` Jakub Kicinski
2026-03-16  2:21   ` 答复: [????] " Li,Rongqing(ACG CCN)

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