* [PATCH v2] rcu: Remove local_irq_save/restore() in rcu_preempt_deferred_qs_handler()
@ 2025-08-13 13:30 Zqiang
2025-08-13 21:13 ` Paul E. McKenney
0 siblings, 1 reply; 3+ messages in thread
From: Zqiang @ 2025-08-13 13:30 UTC (permalink / raw)
To: paulmck, frederic, neeraj.upadhyay, joelagnelf, boqun.feng,
urezki
Cc: qiang.zhang, rcu
Currently, the per-cpu rcu_data structure's->defer_qs_iw is initialized by
IRQ_WORK_INIT_HARD(), this means the rcu_preempt_deferred_qs_handler()
always be executed in the hardirq context of irq-disabled.
This commit therefore remove local_irq_save/restore() operations in
rcu_preempt_deferred_qs_handler() and add lockdep_assert_irqs_disabled()
check, if someone mistakenly invokes this function in hardirq enabled
context will splat.
Signed-off-by: Zqiang <qiang.zhang@linux.dev>
---
kernel/rcu/tree_plugin.h | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index fc14adf15cbb..57e2ae51c0b2 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -626,11 +626,10 @@ notrace void rcu_preempt_deferred_qs(struct task_struct *t)
*/
static void rcu_preempt_deferred_qs_handler(struct irq_work *iwp)
{
- unsigned long flags;
struct rcu_data *rdp;
+ lockdep_assert_irqs_disabled();
rdp = container_of(iwp, struct rcu_data, defer_qs_iw);
- local_irq_save(flags);
/*
* If the IRQ work handler happens to run in the middle of RCU read-side
@@ -647,8 +646,6 @@ static void rcu_preempt_deferred_qs_handler(struct irq_work *iwp)
*/
if (rcu_preempt_depth() > 0)
WRITE_ONCE(rdp->defer_qs_iw_pending, DEFER_QS_IDLE);
-
- local_irq_restore(flags);
}
/*
--
2.48.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] rcu: Remove local_irq_save/restore() in rcu_preempt_deferred_qs_handler()
2025-08-13 13:30 [PATCH v2] rcu: Remove local_irq_save/restore() in rcu_preempt_deferred_qs_handler() Zqiang
@ 2025-08-13 21:13 ` Paul E. McKenney
2025-08-14 13:11 ` Zqiang
0 siblings, 1 reply; 3+ messages in thread
From: Paul E. McKenney @ 2025-08-13 21:13 UTC (permalink / raw)
To: Zqiang; +Cc: frederic, neeraj.upadhyay, joelagnelf, boqun.feng, urezki, rcu
On Wed, Aug 13, 2025 at 09:30:02PM +0800, Zqiang wrote:
> Currently, the per-cpu rcu_data structure's->defer_qs_iw is initialized by
> IRQ_WORK_INIT_HARD(), this means the rcu_preempt_deferred_qs_handler()
> always be executed in the hardirq context of irq-disabled.
> This commit therefore remove local_irq_save/restore() operations in
> rcu_preempt_deferred_qs_handler() and add lockdep_assert_irqs_disabled()
> check, if someone mistakenly invokes this function in hardirq enabled
> context will splat.
>
> Signed-off-by: Zqiang <qiang.zhang@linux.dev>
Queued for further review and testing. With luck, this will make the
v6.18 merge window. I could not resist editing the commit log, so could
you please check whether I messed something up?
Thanx, Paul
------------------------------------------------------------------------
commit 523e71ba3007f8f7c260b9c2baf69c9461a84f55
Author: Zqiang <qiang.zhang@linux.dev>
Date: Wed Aug 13 21:30:02 2025 +0800
rcu: Remove local_irq_save/restore() in rcu_preempt_deferred_qs_handler()
The per-CPU rcu_data structure's ->defer_qs_iw field is initialized
by IRQ_WORK_INIT_HARD(), which means that the subsequent invocation of
rcu_preempt_deferred_qs_handler() will always be executed with interrupts
disabled. This commit therefore removes the local_irq_save/restore()
operations from rcu_preempt_deferred_qs_handler() and adds a call to
lockdep_assert_irqs_disabled() in order to enable lockdep to diagnose
mistaken invocations of this function from interrupts-enabled code.
Signed-off-by: Zqiang <qiang.zhang@linux.dev>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index fc14adf15cbb34..57e2ae51c0b2cb 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -626,11 +626,10 @@ notrace void rcu_preempt_deferred_qs(struct task_struct *t)
*/
static void rcu_preempt_deferred_qs_handler(struct irq_work *iwp)
{
- unsigned long flags;
struct rcu_data *rdp;
+ lockdep_assert_irqs_disabled();
rdp = container_of(iwp, struct rcu_data, defer_qs_iw);
- local_irq_save(flags);
/*
* If the IRQ work handler happens to run in the middle of RCU read-side
@@ -647,8 +646,6 @@ static void rcu_preempt_deferred_qs_handler(struct irq_work *iwp)
*/
if (rcu_preempt_depth() > 0)
WRITE_ONCE(rdp->defer_qs_iw_pending, DEFER_QS_IDLE);
-
- local_irq_restore(flags);
}
/*
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] rcu: Remove local_irq_save/restore() in rcu_preempt_deferred_qs_handler()
2025-08-13 21:13 ` Paul E. McKenney
@ 2025-08-14 13:11 ` Zqiang
0 siblings, 0 replies; 3+ messages in thread
From: Zqiang @ 2025-08-14 13:11 UTC (permalink / raw)
To: paulmck; +Cc: frederic, neeraj.upadhyay, joelagnelf, boqun.feng, urezki, rcu
>
> On Wed, Aug 13, 2025 at 09:30:02PM +0800, Zqiang wrote:
>
> >
> > Currently, the per-cpu rcu_data structure's->defer_qs_iw is initialized by
> > IRQ_WORK_INIT_HARD(), this means the rcu_preempt_deferred_qs_handler()
> > always be executed in the hardirq context of irq-disabled.
> > This commit therefore remove local_irq_save/restore() operations in
> > rcu_preempt_deferred_qs_handler() and add lockdep_assert_irqs_disabled()
> > check, if someone mistakenly invokes this function in hardirq enabled
> > context will splat.
> >
> > Signed-off-by: Zqiang <qiang.zhang@linux.dev>
> >
> Queued for further review and testing. With luck, this will make the
> v6.18 merge window. I could not resist editing the commit log, so could
> you please check whether I messed something up?
No problem, thanks for editing the commit log :) .
Thanks
Zqiang
>
> Thanx, Paul
>
> ------------------------------------------------------------------------
>
> commit 523e71ba3007f8f7c260b9c2baf69c9461a84f55
> Author: Zqiang <qiang.zhang@linux.dev>
> Date: Wed Aug 13 21:30:02 2025 +0800
>
> rcu: Remove local_irq_save/restore() in rcu_preempt_deferred_qs_handler()
>
> The per-CPU rcu_data structure's ->defer_qs_iw field is initialized
> by IRQ_WORK_INIT_HARD(), which means that the subsequent invocation of
> rcu_preempt_deferred_qs_handler() will always be executed with interrupts
> disabled. This commit therefore removes the local_irq_save/restore()
> operations from rcu_preempt_deferred_qs_handler() and adds a call to
> lockdep_assert_irqs_disabled() in order to enable lockdep to diagnose
> mistaken invocations of this function from interrupts-enabled code.
>
> Signed-off-by: Zqiang <qiang.zhang@linux.dev>
> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
>
> diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
> index fc14adf15cbb34..57e2ae51c0b2cb 100644
> --- a/kernel/rcu/tree_plugin.h
> +++ b/kernel/rcu/tree_plugin.h
> @@ -626,11 +626,10 @@ notrace void rcu_preempt_deferred_qs(struct task_struct *t)
> */
> static void rcu_preempt_deferred_qs_handler(struct irq_work *iwp)
> {
> - unsigned long flags;
> struct rcu_data *rdp;
>
> + lockdep_assert_irqs_disabled();
> rdp = container_of(iwp, struct rcu_data, defer_qs_iw);
> - local_irq_save(flags);
>
> /*
> * If the IRQ work handler happens to run in the middle of RCU read-side
> @@ -647,8 +646,6 @@ static void rcu_preempt_deferred_qs_handler(struct irq_work *iwp)
> */
> if (rcu_preempt_depth() > 0)
> WRITE_ONCE(rdp->defer_qs_iw_pending, DEFER_QS_IDLE);
> -
> - local_irq_restore(flags);
> }
>
> /*
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-14 13:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-13 13:30 [PATCH v2] rcu: Remove local_irq_save/restore() in rcu_preempt_deferred_qs_handler() Zqiang
2025-08-13 21:13 ` Paul E. McKenney
2025-08-14 13:11 ` Zqiang
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).