Skip to content

Commit 3063b33

Browse files
committed
rcu-tasks: Avoid raw-spinlocked wakeups from call_rcu_tasks_generic()
If the caller of of call_rcu_tasks(), call_rcu_tasks_rude(), or call_rcu_tasks_trace() holds a raw spinlock, and then if call_rcu_tasks_generic() determines that the grace-period kthread must be awakened, then the wakeup might acquire a normal spinlock while a raw spinlock is held. This results in lockdep splats when the kernel is built with CONFIG_PROVE_RAW_LOCK_NESTING=y. This commit therefore defers the wakeup using irq_work_queue(). It would be nice to directly invoke wakeup when a raw spinlock is not held, but there is currently no way to check for this in all kernels. Reported-by: Martin Lau <kafai@fb.com> Cc: Neeraj Upadhyay <neeraj.iitr10@gmail.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent 7d13d30 commit 3063b33

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

kernel/rcu/tasks.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ typedef void (*postgp_func_t)(struct rcu_tasks *rtp);
2727
* @rtp_jiffies: Jiffies counter value for statistics.
2828
* @rtp_n_lock_retries: Rough lock-contention statistic.
2929
* @rtp_work: Work queue for invoking callbacks.
30+
* @rtp_irq_work: IRQ work queue for deferred wakeups.
3031
* @barrier_q_head: RCU callback for barrier operation.
3132
* @cpu: CPU number corresponding to this entry.
3233
* @rtpp: Pointer to the rcu_tasks structure.
@@ -37,6 +38,7 @@ struct rcu_tasks_percpu {
3738
unsigned long rtp_jiffies;
3839
unsigned long rtp_n_lock_retries;
3940
struct work_struct rtp_work;
41+
struct irq_work rtp_irq_work;
4042
struct rcu_head barrier_q_head;
4143
int cpu;
4244
struct rcu_tasks *rtpp;
@@ -102,9 +104,12 @@ struct rcu_tasks {
102104
char *kname;
103105
};
104106

107+
static void call_rcu_tasks_iw_wakeup(struct irq_work *iwp);
108+
105109
#define DEFINE_RCU_TASKS(rt_name, gp, call, n) \
106110
static DEFINE_PER_CPU(struct rcu_tasks_percpu, rt_name ## __percpu) = { \
107111
.lock = __RAW_SPIN_LOCK_UNLOCKED(rt_name ## __percpu.cbs_pcpu_lock), \
112+
.rtp_irq_work = IRQ_WORK_INIT(call_rcu_tasks_iw_wakeup), \
108113
}; \
109114
static struct rcu_tasks rt_name = \
110115
{ \
@@ -230,6 +235,16 @@ static void cblist_init_generic(struct rcu_tasks *rtp)
230235
pr_info("%s: Setting shift to %d and lim to %d.\n", __func__, data_race(rtp->percpu_enqueue_shift), data_race(rtp->percpu_enqueue_lim));
231236
}
232237

238+
// IRQ-work handler that does deferred wakeup for call_rcu_tasks_generic().
239+
static void call_rcu_tasks_iw_wakeup(struct irq_work *iwp)
240+
{
241+
struct rcu_tasks *rtp;
242+
struct rcu_tasks_percpu *rtpcp = container_of(iwp, struct rcu_tasks_percpu, rtp_irq_work);
243+
244+
rtp = rtpcp->rtpp;
245+
wake_up(&rtp->cbs_wq);
246+
}
247+
233248
// Enqueue a callback for the specified flavor of Tasks RCU.
234249
static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func,
235250
struct rcu_tasks *rtp)
@@ -263,7 +278,7 @@ static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func,
263278
raw_spin_unlock_irqrestore_rcu_node(rtpcp, flags);
264279
/* We can't create the thread unless interrupts are enabled. */
265280
if (needwake && READ_ONCE(rtp->kthread_ptr))
266-
wake_up(&rtp->cbs_wq);
281+
irq_work_queue(&rtpcp->rtp_irq_work);
267282
}
268283

269284
// Wait for a grace period for the specified flavor of Tasks RCU.

0 commit comments

Comments
 (0)