Skip to contentSkip to conversation

rcu: Use IRQ_WORK_INIT_HARD for srcu's irq_work

PATCH Superseded Sebastian Andrzej Siewior 3 participants 9 messages Aug 20 – Aug 21

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Sebastian Andrzej Siewior

author maintainer
#0 lore raw

PATCH 1/1 rcu: Use IRQ_WORK_INIT_HARD for srcu's irq_work

The irq_work in srcu is used to schedule a delayed work. The work item is not scheduled directly because it is not always possible wake a thread directly.

On PREEMPT_RT the default irq_work is initialized with IRQ_WORK_LAZY and is delayed to the irq_work thread. A system booted with the command line "trace_event=…" will freeze during boot because the irq_work thread is not yet deployed (and tracing uses synchronize_srcu() in tp_rcu_cond_sync()).

The irq_work performs just a wakeup a thread, there is nothing wrong with doing this from hardirq context on PREEMPT_RT.

Use IRQ_WORK_INIT_HARD for srcu's irq_work.

Fixes 7c405fb3279b3 ("rcu: Use an intermediate irq_work to start process_srcu()")
---
 kernel/rcu/srcutree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/srcutree.c +1 -1
index 7c2f7cc131f7a..b703233d4a63f 100644
@@ -218,7 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
 	mutex_init(&ssp->srcu_sup->srcu_barrier_mutex);
 	atomic_set(&ssp->srcu_sup->srcu_barrier_cpu_cnt, 0);
 	INIT_DELAYED_WORK(&ssp->srcu_sup->work, process_srcu);
-	init_irq_work(&ssp->srcu_sup->irq_work, srcu_irq_work);
+	ssp->srcu_sup->irq_work = IRQ_WORK_INIT_HARD(srcu_irq_work);
 	ssp->srcu_sup->sda_is_static = is_static;
 	if (!is_static) {
 		ssp->sda = alloc_percpu(struct srcu_data);
Signature · 1 line
2.55.0
#1 lore raw
Quoted 26 lines · Sebastian Andrzej Siewior

The irq_work in srcu is used to schedule a delayed work. The work item is not scheduled directly because it is not always possible wake a thread directly.

On PREEMPT_RT the default irq_work is initialized with IRQ_WORK_LAZY and is delayed to the irq_work thread. A system booted with the command line "trace_event=…" will freeze during boot because the irq_work thread is not yet deployed (and tracing uses synchronize_srcu() in tp_rcu_cond_sync()).

The irq_work performs just a wakeup a thread, there is nothing wrong with doing this from hardirq context on PREEMPT_RT.

Use IRQ_WORK_INIT_HARD for srcu's irq_work.

Fixes 7c405fb3279b3 ("rcu: Use an intermediate irq_work to start process_srcu()")
---
 kernel/rcu/srcutree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/srcutree.c +0 -0
index 7c2f7cc131f7a..b703233d4a63f 100644

kernel/rcu/srcutree.c static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static) · line 221

Quoted 5 lines
kernel/rcu/srcutree.c +1 -1
@@ -218,7 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
 	mutex_init(&ssp->srcu_sup->srcu_barrier_mutex);
 	atomic_set(&ssp->srcu_sup->srcu_barrier_cpu_cnt, 0);
 	INIT_DELAYED_WORK(&ssp->srcu_sup->work, process_srcu);
-	init_irq_work(&ssp->srcu_sup->irq_work, srcu_irq_work);
+	ssp->srcu_sup->irq_work = IRQ_WORK_INIT_HARD(srcu_irq_work);

It may need a comment to not lose that.

Quoted 7 lines
kernel/rcu/srcutree.c +0 -0
 	ssp->srcu_sup->sda_is_static = is_static;
 	if (!is_static) {
 		ssp->sda = alloc_percpu(struct srcu_data);
Signature · 1 line
2.55.0

Perhaps all irq works queued before the relevant kthread is started should temporarily be queued as hard?

Thanks.

Signature · 2 lines
Frederic Weisbecker
SUSE Labs
author maintainer
#2 lore raw
Quoted 22 lines · Frederic Weisbecker
Quoted 21 lines · Sebastian Andrzej Siewior

The irq_work in srcu is used to schedule a delayed work. The work item is not scheduled directly because it is not always possible wake a thread directly.

On PREEMPT_RT the default irq_work is initialized with IRQ_WORK_LAZY and is delayed to the irq_work thread. A system booted with the command line "trace_event=…" will freeze during boot because the irq_work thread is not yet deployed (and tracing uses synchronize_srcu() in tp_rcu_cond_sync()).

The irq_work performs just a wakeup a thread, there is nothing wrong with doing this from hardirq context on PREEMPT_RT.

Use IRQ_WORK_INIT_HARD for srcu's irq_work.

Fixes 7c405fb3279b3 ("rcu: Use an intermediate irq_work to start process_srcu()")
---
 kernel/rcu/srcutree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

kernel/rcu/srcutree.c static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static) · line 221

Quoted 10 lines
kernel/rcu/srcutree.c +1 -1
index 7c2f7cc131f7a..b703233d4a63f 100644
@@ -218,7 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
 	mutex_init(&ssp->srcu_sup->srcu_barrier_mutex);
 	atomic_set(&ssp->srcu_sup->srcu_barrier_cpu_cnt, 0);
 	INIT_DELAYED_WORK(&ssp->srcu_sup->work, process_srcu);
-	init_irq_work(&ssp->srcu_sup->irq_work, srcu_irq_work);
+	ssp->srcu_sup->irq_work = IRQ_WORK_INIT_HARD(srcu_irq_work);

It may need a comment to not lose that.

We could also make irq_work.o earlier in the Makefile, right at the top so it comes before tracing. This was one of the first ideas and makes the issue also go away. But given that it is just a wake we avoid waking the irq_work/ thread just to schedule a timer/ wake workqueue.

Quoted 10 lines
Quoted 7 lines
kernel/rcu/srcutree.c +0 -0
 	ssp->srcu_sup->sda_is_static = is_static;
 	if (!is_static) {
 		ssp->sda = alloc_percpu(struct srcu_data);
Signature · 1 line
2.55.0

Perhaps all irq works queued before the relevant kthread is started should temporarily be queued as hard?

Urgh. irq_work shouldn't become a widespread user ;)
If the scheduler is up but irq_work thread is not yet created and the irq_work uses sleeping locks then it would create warnings. In testing right now I see just wake_up_klogd_work_func() which is always LAZY but would qualify otherwise for a warning. We wouldn't trigger anything yet but you get the idea.

Quoted 1 line

Thanks.

Sebastian

maintainer Reviewed-by
#3 lore raw
Quoted 4 lines · On Thu, 20 Aug 2026 15:55:00 +0200 Sebastian Andrzej Siewior…
Quoted 4 lines
Quoted 4 lines
kernel/rcu/srcutree.c +0 -0
index 7c2f7cc131f7a..b703233d4a63f 100644
Quoted 8 lines
Quoted 8 lines

kernel/rcu/srcutree.c static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static) · line 221

Quoted 6 lines
kernel/rcu/srcutree.c +1 -1
@@ -218,7 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
 	mutex_init(&ssp->srcu_sup->srcu_barrier_mutex);
 	atomic_set(&ssp->srcu_sup->srcu_barrier_cpu_cnt, 0);
 	INIT_DELAYED_WORK(&ssp->srcu_sup->work, process_srcu);
-	init_irq_work(&ssp->srcu_sup->irq_work, srcu_irq_work);
+	ssp->srcu_sup->irq_work = IRQ_WORK_INIT_HARD(srcu_irq_work);  

It may need a comment to not lose that.

I agree a comment would be useful here.

Quoted 5 lines

We could also make irq_work.o earlier in the Makefile, right at the top so it comes before tracing. This was one of the first ideas and makes the issue also go away. But given that it is just a wake we avoid waking the irq_work/ thread just to schedule a timer/ wake workqueue.

That doesn't sound as robust as this solution. Updating Makefile order is a fragile solution.

Anyway for this patch,

-- Steve

#7 lore raw
In reply to Sebastian Andrzej Siewior
Quoted 52 lines · Sebastian Andrzej Siewior
Quoted 22 lines · Frederic Weisbecker
Quoted 21 lines · Sebastian Andrzej Siewior

The irq_work in srcu is used to schedule a delayed work. The work item is not scheduled directly because it is not always possible wake a thread directly.

On PREEMPT_RT the default irq_work is initialized with IRQ_WORK_LAZY and is delayed to the irq_work thread. A system booted with the command line "trace_event=…" will freeze during boot because the irq_work thread is not yet deployed (and tracing uses synchronize_srcu() in tp_rcu_cond_sync()).

The irq_work performs just a wakeup a thread, there is nothing wrong with doing this from hardirq context on PREEMPT_RT.

Use IRQ_WORK_INIT_HARD for srcu's irq_work.

Fixes 7c405fb3279b3 ("rcu: Use an intermediate irq_work to start process_srcu()")
---
 kernel/rcu/srcutree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

kernel/rcu/srcutree.c static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static) · line 221

Quoted 10 lines
kernel/rcu/srcutree.c +1 -1
index 7c2f7cc131f7a..b703233d4a63f 100644
@@ -218,7 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
 	mutex_init(&ssp->srcu_sup->srcu_barrier_mutex);
 	atomic_set(&ssp->srcu_sup->srcu_barrier_cpu_cnt, 0);
 	INIT_DELAYED_WORK(&ssp->srcu_sup->work, process_srcu);
-	init_irq_work(&ssp->srcu_sup->irq_work, srcu_irq_work);
+	ssp->srcu_sup->irq_work = IRQ_WORK_INIT_HARD(srcu_irq_work);

It may need a comment to not lose that.

We could also make irq_work.o earlier in the Makefile, right at the top so it comes before tracing. This was one of the first ideas and makes the issue also go away. But given that it is just a wake we avoid waking the irq_work/ thread just to schedule a timer/ wake workqueue.

Quoted 10 lines
Quoted 7 lines
kernel/rcu/srcutree.c +0 -0
 	ssp->srcu_sup->sda_is_static = is_static;
 	if (!is_static) {
 		ssp->sda = alloc_percpu(struct srcu_data);
Signature · 1 line
2.55.0

Perhaps all irq works queued before the relevant kthread is started should temporarily be queued as hard?

Quoted 6 lines

Urgh. irq_work shouldn't become a widespread user ;)
If the scheduler is up but irq_work thread is not yet created and the irq_work uses sleeping locks then it would create warnings. In testing right now I see just wake_up_klogd_work_func() which is always LAZY but would qualify otherwise for a warning. We wouldn't trigger anything yet but you get the idea.

Fair enough! But should we warn if a non-hard IRQ work is queued before the kthread is created?

Thanks.

Quoted 5 lines
Quoted 2 lines

Thanks.

Sebastian

Signature · 2 lines
Frederic Weisbecker
SUSE Labs
author maintainer
#4 lore raw
In reply to Steven Rostedt
Quoted 16 lines · Steven Rostedt
Quoted 4 lines · On Thu, 20 Aug 2026 15:55:00 +0200 Sebastian Andrzej Siewior…
Quoted 4 lines
Quoted 4 lines
kernel/rcu/srcutree.c +0 -0
index 7c2f7cc131f7a..b703233d4a63f 100644
Quoted 8 lines
Quoted 8 lines

kernel/rcu/srcutree.c static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static) · line 221

Quoted 6 lines
kernel/rcu/srcutree.c +1 -1
@@ -218,7 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
 	mutex_init(&ssp->srcu_sup->srcu_barrier_mutex);
 	atomic_set(&ssp->srcu_sup->srcu_barrier_cpu_cnt, 0);
 	INIT_DELAYED_WORK(&ssp->srcu_sup->work, process_srcu);
-	init_irq_work(&ssp->srcu_sup->irq_work, srcu_irq_work);
+	ssp->srcu_sup->irq_work = IRQ_WORK_INIT_HARD(srcu_irq_work);  

It may need a comment to not lose that.

Quoted 1 line

I agree a comment would be useful here.

Urgh.

Quoted 7 lines
Quoted 4 lines

We could also make irq_work.o earlier in the Makefile, right at the top so it comes before tracing. This was one of the first ideas and makes the issue also go away. But given that it is just a wake we avoid waking the irq_work/ thread just to schedule a timer/ wake workqueue.

That doesn't sound as robust as this solution. Updating Makefile order is a fragile solution.

This is the way how ordering in initcall works. Both are early_initcall so if you don't tweak the makefile for ordering you would have to introduce a level before early.

Quoted 5 lines

Anyway for this patch,

-- Steve

Sebastian

author maintainer
#8 lore raw
In reply to Frederic Weisbecker
Quoted 9 lines · Frederic Weisbecker
Quoted 6 lines

Urgh. irq_work shouldn't become a widespread user ;)
If the scheduler is up but irq_work thread is not yet created and the irq_work uses sleeping locks then it would create warnings. In testing right now I see just wake_up_klogd_work_func() which is always LAZY but would qualify otherwise for a warning. We wouldn't trigger anything yet but you get the idea.

Fair enough! But should we warn if a non-hard IRQ work is queued before the kthread is created?

It is not a problem in general. So for instance the printk thingy is enqueued and is invoked later. The wake up can be delayed. There is no need to trigger a warning here. There is no dependency and you can't know that.
The difference with SRCU+tracing is that it first starts a grace period (the irq_wake from SRCU for tracing) and then expects the grace period to be completed (tracing). Even before SRCU is up, you can queue callbacks or start grace periods, etc. This is handled once everything is up.

Quoted 2 lines

Thanks.

Sebastian

author maintainer
#5 lore raw
In reply to Sebastian Andrzej Siewior
Quoted 17 lines · To Steven Rostedt
Quoted 16 lines · Steven Rostedt
Quoted 12 lines · On Thu, 20 Aug 2026 15:55:00 +0200 Sebastian Andrzej Siewior…
Quoted 12 lines

kernel/rcu/srcutree.c static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static) · line 221

Quoted 10 lines
kernel/rcu/srcutree.c +1 -1
index 7c2f7cc131f7a..b703233d4a63f 100644
@@ -218,7 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
 	mutex_init(&ssp->srcu_sup->srcu_barrier_mutex);
 	atomic_set(&ssp->srcu_sup->srcu_barrier_cpu_cnt, 0);
 	INIT_DELAYED_WORK(&ssp->srcu_sup->work, process_srcu);
-	init_irq_work(&ssp->srcu_sup->irq_work, srcu_irq_work);
+	ssp->srcu_sup->irq_work = IRQ_WORK_INIT_HARD(srcu_irq_work);  

It may need a comment to not lose that.

Quoted 2 lines
Quoted 1 line

I agree a comment would be useful here.

Urgh.

What do you want me to cover in the comment? The arguing pro IRQ_WORK_INIT_HARD is because it is "just" a workqueue schedule and it avoids the jump over irq_work/ thread. This makes sense regardless of the tracing issue.
If it would be not compatible with hard-irq context I would argue for the makefile change which is still sane since there is no other way to express dependencies (which we clearly have here).

Sebastian

maintainer
#6 lore raw
Quoted 7 lines · On Fri, 21 Aug 2026 13:01:08 +0200 Sebastian Andrzej Siewior…
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

kernel/rcu/srcutree.c static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static) · line 221

Quoted 1 line
kernel/rcu/srcutree.c +1 -0
+	ssp->srcu_sup->irq_work = IRQ_WORK_INIT_HARD(srcu_irq_work);    

It may need a comment to not lose that.

I agree a comment would be useful here.

Urgh.

Quoted 7 lines

What do you want me to cover in the comment? The arguing pro IRQ_WORK_INIT_HARD is because it is "just" a workqueue schedule and it avoids the jump over irq_work/ thread. This makes sense regardless of the tracing issue.
If it would be not compatible with hard-irq context I would argue for the makefile change which is still sane since there is no other way to express dependencies (which we clearly have here).

Basically just a word to why it is HARD.

atomic_set(&ssp->srcu_sup->srcu_barrier_cpu_cnt, 0); INIT_DELAYED_WORK(&ssp->srcu_sup->work, process_srcu);
- init_irq_work(&ssp->srcu_sup->irq_work, srcu_irq_work);
+ /*
+ * trace events started on the command line require SRCU before
+ * the irq_work kthread starts. Since all it does is a simple
+ * wakeup, having it as a hard irq, even on PREEMPT_RT is fine.
+ */
+ ssp->srcu_sup->irq_work = IRQ_WORK_INIT_HARD(srcu_irq_work);
ssp->srcu_sup->sda_is_static = is_static;

-- Steve