diff options
author | Iliyan Malchev <malchev@google.com> | 2015-04-23 14:53:38 -0700 |
---|---|---|
committer | Michael Bestas <mkbestas@lineageos.org> | 2019-12-23 23:43:35 +0200 |
commit | 8ad00b7be2aa63a208b8e72ecabce16ad1610ccb (patch) | |
tree | 9331efd054f4c05b9b855507f1db4c288001c436 /kernel | |
parent | 6edd3f1417d82add8c98d292ba39912b830c3d80 (diff) |
PM: wakeup_reasons: fix race condition
log_possible_wakeup_reason() and stop_logging_wakeup_reasons() can race, as the
latter can be called from process context, and both can run on separate cores.
Change-Id: I306441d0be46dd4fe58c55cdc162f9d61a28c27d
Signed-off-by: Iliyan Malchev <malchev@google.com>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/irq/irqdesc.c | 2 | ||||
-rw-r--r-- | kernel/power/wakeup_reason.c | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index a935c1bb768e..52fbf88cd2d8 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -353,7 +353,7 @@ int generic_handle_irq(unsigned int irq) if (!desc) return -EINVAL; - if (unlikely(logging_wakeup_reasons())) + if (unlikely(logging_wakeup_reasons_nosync())) return log_possible_wakeup_reason(irq, desc, generic_handle_irq_desc); diff --git a/kernel/power/wakeup_reason.c b/kernel/power/wakeup_reason.c index 8d509428487b..e8c60538f3f7 100644 --- a/kernel/power/wakeup_reason.c +++ b/kernel/power/wakeup_reason.c @@ -293,6 +293,7 @@ static struct attribute_group attr_group = { static inline void stop_logging_wakeup_reasons(void) { ACCESS_ONCE(log_wakeups) = false; + smp_wmb(); } /* @@ -330,9 +331,16 @@ void log_base_wakeup_reason(int irq) struct wakeup_irq_node * log_possible_wakeup_reason_start(int irq, struct irq_desc *desc, unsigned depth) { - BUG_ON(!irqs_disabled() || !logging_wakeup_reasons()); + BUG_ON(!irqs_disabled()); BUG_ON((signed)depth < 0); + /* This function can race with a call to stop_logging_wakeup_reasons() + * from a thread context. If this happens, just exit silently, as we are no + * longer interested in logging interrupts. + */ + if (!logging_wakeup_reasons()) + return NULL; + /* If suspend was aborted, the base IRQ nodes are missing, and we stop * logging interrupts immediately. */ @@ -540,7 +548,6 @@ static int wakeup_reason_pm_event(struct notifier_block *notifier, /* log_wakeups should have been cleared by now. */ if (WARN_ON(logging_wakeup_reasons())) { stop_logging_wakeup_reasons(); - mb(); print_wakeup_sources(); } /* monotonic time since boot */ |