Skip to content

Commit 9fdd3bc

Browse files
committed
rcu: Break more call_rcu() deadlock involving scheduler and perf
Commit 96d3fd0 (rcu: Break call_rcu() deadlock involving scheduler and perf) covered the case where __call_rcu_nocb_enqueue() needs to wake the rcuo kthread due to the queue being initially empty, but did not do anything for the case where the queue was overflowing. This commit therefore also defers wakeup for the overflow case. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent 66d701e commit 9fdd3bc

3 files changed

Lines changed: 28 additions & 10 deletions

File tree

‎include/trace/events/rcu.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,12 @@ TRACE_EVENT(rcu_grace_period_init,
180180
* argument is a string as follows:
181181
*
182182
* "WakeEmpty": Wake rcuo kthread, first CB to empty list.
183+
* "WakeEmptyIsDeferred": Wake rcuo kthread later, first CB to empty list.
183184
* "WakeOvf": Wake rcuo kthread, CB list is huge.
185+
* "WakeOvfIsDeferred": Wake rcuo kthread later, CB list is huge.
184186
* "WakeNot": Don't wake rcuo kthread.
185187
* "WakeNotPoll": Don't wake rcuo kthread because it is polling.
188+
* "DeferredWake": Carried out the "IsDeferred" wakeup.
186189
* "Poll": Start of new polling cycle for rcu_nocb_poll.
187190
* "Sleep": Sleep waiting for CBs for !rcu_nocb_poll.
188191
* "WokeEmpty": rcuo kthread woke to find empty list.

‎kernel/rcu/tree.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ struct rcu_data {
350350
int nocb_p_count_lazy; /* (approximate). */
351351
wait_queue_head_t nocb_wq; /* For nocb kthreads to sleep on. */
352352
struct task_struct *nocb_kthread;
353-
bool nocb_defer_wakeup; /* Defer wakeup of nocb_kthread. */
353+
int nocb_defer_wakeup; /* Defer wakeup of nocb_kthread. */
354354

355355
/* The following fields are used by the leader, hence own cacheline. */
356356
struct rcu_head *nocb_gp_head ____cacheline_internodealigned_in_smp;
@@ -383,6 +383,11 @@ struct rcu_data {
383383
#define RCU_FORCE_QS 3 /* Need to force quiescent state. */
384384
#define RCU_SIGNAL_INIT RCU_SAVE_DYNTICK
385385

386+
/* Values for nocb_defer_wakeup field in struct rcu_data. */
387+
#define RCU_NOGP_WAKE_NOT 0
388+
#define RCU_NOGP_WAKE 1
389+
#define RCU_NOGP_WAKE_FORCE 2
390+
386391
#define RCU_JIFFIES_TILL_FORCE_QS (1 + (HZ > 250) + (HZ > 500))
387392
/* For jiffies_till_first_fqs and */
388393
/* and jiffies_till_next_fqs. */
@@ -589,7 +594,7 @@ static bool __call_rcu_nocb(struct rcu_data *rdp, struct rcu_head *rhp,
589594
static bool rcu_nocb_adopt_orphan_cbs(struct rcu_state *rsp,
590595
struct rcu_data *rdp,
591596
unsigned long flags);
592-
static bool rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp);
597+
static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp);
593598
static void do_nocb_deferred_wakeup(struct rcu_data *rdp);
594599
static void rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp);
595600
static void rcu_spawn_nocb_kthreads(struct rcu_state *rsp);

‎kernel/rcu/tree_plugin.h‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,16 +2121,23 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
21212121
trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
21222122
TPS("WakeEmpty"));
21232123
} else {
2124-
rdp->nocb_defer_wakeup = true;
2124+
rdp->nocb_defer_wakeup = RCU_NOGP_WAKE;
21252125
trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
21262126
TPS("WakeEmptyIsDeferred"));
21272127
}
21282128
rdp->qlen_last_fqs_check = 0;
21292129
} else if (len > rdp->qlen_last_fqs_check + qhimark) {
21302130
/* ... or if many callbacks queued. */
2131-
wake_nocb_leader(rdp, true);
2131+
if (!irqs_disabled_flags(flags)) {
2132+
wake_nocb_leader(rdp, true);
2133+
trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2134+
TPS("WakeOvf"));
2135+
} else {
2136+
rdp->nocb_defer_wakeup = RCU_NOGP_WAKE_FORCE;
2137+
trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2138+
TPS("WakeOvfIsDeferred"));
2139+
}
21322140
rdp->qlen_last_fqs_check = LONG_MAX / 2;
2133-
trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("WakeOvf"));
21342141
} else {
21352142
trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("WakeNot"));
21362143
}
@@ -2438,19 +2445,22 @@ static int rcu_nocb_kthread(void *arg)
24382445
}
24392446

24402447
/* Is a deferred wakeup of rcu_nocb_kthread() required? */
2441-
static bool rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp)
2448+
static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp)
24422449
{
24432450
return ACCESS_ONCE(rdp->nocb_defer_wakeup);
24442451
}
24452452

24462453
/* Do a deferred wakeup of rcu_nocb_kthread(). */
24472454
static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
24482455
{
2456+
int ndw;
2457+
24492458
if (!rcu_nocb_need_deferred_wakeup(rdp))
24502459
return;
2451-
ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
2452-
wake_nocb_leader(rdp, false);
2453-
trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
2460+
ndw = ACCESS_ONCE(rdp->nocb_defer_wakeup);
2461+
ACCESS_ONCE(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
2462+
wake_nocb_leader(rdp, ndw == RCU_NOGP_WAKE_FORCE);
2463+
trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWake"));
24542464
}
24552465

24562466
/* Initialize per-rcu_data variables for no-CBs CPUs. */
@@ -2557,7 +2567,7 @@ static void __init rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp)
25572567
{
25582568
}
25592569

2560-
static bool rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp)
2570+
static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp)
25612571
{
25622572
return false;
25632573
}

0 commit comments

Comments
 (0)