Skip to content

Commit b38f57c

Browse files
committed
rcu-tasks: Allow rcu_read_unlock_trace() under scheduler locks
The rcu_read_unlock_trace() can invoke rcu_read_unlock_trace_special(), which in turn can call wake_up(). Therefore, if any scheduler lock is held across a call to rcu_read_unlock_trace(), self-deadlock can occur. This commit therefore uses the irq_work facility to defer the wake_up() to a clean environment where no scheduler locks will be held. Reported-by: Steven Rostedt <[email protected]> [ paulmck: Update #includes for m68k per kbuild test robot. ] Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 7d0c9c5 commit b38f57c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

kernel/rcu/tasks.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,16 @@ void call_rcu_tasks_trace(struct rcu_head *rhp, rcu_callback_t func);
729729
DEFINE_RCU_TASKS(rcu_tasks_trace, rcu_tasks_wait_gp, call_rcu_tasks_trace,
730730
"RCU Tasks Trace");
731731

732+
/*
733+
* This irq_work handler allows rcu_read_unlock_trace() to be invoked
734+
* while the scheduler locks are held.
735+
*/
736+
static void rcu_read_unlock_iw(struct irq_work *iwp)
737+
{
738+
wake_up(&trc_wait);
739+
}
740+
static DEFINE_IRQ_WORK(rcu_tasks_trace_iw, rcu_read_unlock_iw);
741+
732742
/* If we are the last reader, wake up the grace-period kthread. */
733743
void rcu_read_unlock_trace_special(struct task_struct *t, int nesting)
734744
{
@@ -742,7 +752,7 @@ void rcu_read_unlock_trace_special(struct task_struct *t, int nesting)
742752
WRITE_ONCE(t->trc_reader_special.b.need_qs, false);
743753
WRITE_ONCE(t->trc_reader_nesting, nesting);
744754
if (nq && atomic_dec_and_test(&trc_n_readers_need_end))
745-
wake_up(&trc_wait);
755+
irq_work_queue(&rcu_tasks_trace_iw);
746756
}
747757
EXPORT_SYMBOL_GPL(rcu_read_unlock_trace_special);
748758

kernel/rcu/update.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <linux/sched/isolation.h>
4242
#include <linux/kprobes.h>
4343
#include <linux/slab.h>
44+
#include <linux/irq_work.h>
4445

4546
#define CREATE_TRACE_POINTS
4647

0 commit comments

Comments
 (0)