Skip to content

Commit ea0212f

Browse files
KAGA-KOKOrafaeljw
authored andcommitted
PM / wakeirq: Convert to SRCU
The wakeirq infrastructure uses RCU to protect the list of wakeirqs. That breaks the irq bus locking infrastructure, which is allows sleeping functions to be called so interrupt controllers behind slow busses, e.g. i2c, can be handled. The wakeirq functions hold rcu_read_lock and call into irq functions, which in case of interrupts using the irq bus locking will trigger a might_sleep() splat. Convert the wakeirq infrastructure to Sleepable RCU and unbreak it. Fixes: 4990d4f (PM / Wakeirq: Add automated device wake IRQ handling) Reported-by: Brian Norris <briannorris@chromium.org> Suggested-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Tested-by: Tony Lindgren <tony@atomide.com> Tested-by: Brian Norris <briannorris@chromium.org> Cc: 4.2+ <stable@vger.kernel.org> # 4.2+ Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent c0bc126 commit ea0212f

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

‎drivers/base/power/wakeup.c‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ static LIST_HEAD(wakeup_sources);
6060

6161
static DECLARE_WAIT_QUEUE_HEAD(wakeup_count_wait_queue);
6262

63+
DEFINE_STATIC_SRCU(wakeup_srcu);
64+
6365
static struct wakeup_source deleted_ws = {
6466
.name = "deleted",
6567
.lock = __SPIN_LOCK_UNLOCKED(deleted_ws.lock),
@@ -198,7 +200,7 @@ void wakeup_source_remove(struct wakeup_source *ws)
198200
spin_lock_irqsave(&events_lock, flags);
199201
list_del_rcu(&ws->entry);
200202
spin_unlock_irqrestore(&events_lock, flags);
201-
synchronize_rcu();
203+
synchronize_srcu(&wakeup_srcu);
202204
}
203205
EXPORT_SYMBOL_GPL(wakeup_source_remove);
204206

@@ -332,12 +334,12 @@ void device_wakeup_detach_irq(struct device *dev)
332334
void device_wakeup_arm_wake_irqs(void)
333335
{
334336
struct wakeup_source *ws;
337+
int srcuidx;
335338

336-
rcu_read_lock();
339+
srcuidx = srcu_read_lock(&wakeup_srcu);
337340
list_for_each_entry_rcu(ws, &wakeup_sources, entry)
338341
dev_pm_arm_wake_irq(ws->wakeirq);
339-
340-
rcu_read_unlock();
342+
srcu_read_unlock(&wakeup_srcu, srcuidx);
341343
}
342344

343345
/**
@@ -348,12 +350,12 @@ void device_wakeup_arm_wake_irqs(void)
348350
void device_wakeup_disarm_wake_irqs(void)
349351
{
350352
struct wakeup_source *ws;
353+
int srcuidx;
351354

352-
rcu_read_lock();
355+
srcuidx = srcu_read_lock(&wakeup_srcu);
353356
list_for_each_entry_rcu(ws, &wakeup_sources, entry)
354357
dev_pm_disarm_wake_irq(ws->wakeirq);
355-
356-
rcu_read_unlock();
358+
srcu_read_unlock(&wakeup_srcu, srcuidx);
357359
}
358360

359361
/**
@@ -804,10 +806,10 @@ EXPORT_SYMBOL_GPL(pm_wakeup_dev_event);
804806
void pm_print_active_wakeup_sources(void)
805807
{
806808
struct wakeup_source *ws;
807-
int active = 0;
809+
int srcuidx, active = 0;
808810
struct wakeup_source *last_activity_ws = NULL;
809811

810-
rcu_read_lock();
812+
srcuidx = srcu_read_lock(&wakeup_srcu);
811813
list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
812814
if (ws->active) {
813815
pr_debug("active wakeup source: %s\n", ws->name);
@@ -823,7 +825,7 @@ void pm_print_active_wakeup_sources(void)
823825
if (!active && last_activity_ws)
824826
pr_debug("last active wakeup source: %s\n",
825827
last_activity_ws->name);
826-
rcu_read_unlock();
828+
srcu_read_unlock(&wakeup_srcu, srcuidx);
827829
}
828830
EXPORT_SYMBOL_GPL(pm_print_active_wakeup_sources);
829831

@@ -950,8 +952,9 @@ void pm_wakep_autosleep_enabled(bool set)
950952
{
951953
struct wakeup_source *ws;
952954
ktime_t now = ktime_get();
955+
int srcuidx;
953956

954-
rcu_read_lock();
957+
srcuidx = srcu_read_lock(&wakeup_srcu);
955958
list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
956959
spin_lock_irq(&ws->lock);
957960
if (ws->autosleep_enabled != set) {
@@ -965,7 +968,7 @@ void pm_wakep_autosleep_enabled(bool set)
965968
}
966969
spin_unlock_irq(&ws->lock);
967970
}
968-
rcu_read_unlock();
971+
srcu_read_unlock(&wakeup_srcu, srcuidx);
969972
}
970973
#endif /* CONFIG_PM_AUTOSLEEP */
971974

@@ -1026,15 +1029,16 @@ static int print_wakeup_source_stats(struct seq_file *m,
10261029
static int wakeup_sources_stats_show(struct seq_file *m, void *unused)
10271030
{
10281031
struct wakeup_source *ws;
1032+
int srcuidx;
10291033

10301034
seq_puts(m, "name\t\tactive_count\tevent_count\twakeup_count\t"
10311035
"expire_count\tactive_since\ttotal_time\tmax_time\t"
10321036
"last_change\tprevent_suspend_time\n");
10331037

1034-
rcu_read_lock();
1038+
srcuidx = srcu_read_lock(&wakeup_srcu);
10351039
list_for_each_entry_rcu(ws, &wakeup_sources, entry)
10361040
print_wakeup_source_stats(m, ws);
1037-
rcu_read_unlock();
1041+
srcu_read_unlock(&wakeup_srcu, srcuidx);
10381042

10391043
print_wakeup_source_stats(m, &deleted_ws);
10401044

0 commit comments

Comments
 (0)