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>
This commit is contained in:
Iliyan Malchev 2015-04-23 14:53:38 -07:00 committed by Artem Borisov
parent 563e031bd3
commit 84612c4595
3 changed files with 19 additions and 6 deletions

View file

@ -61,14 +61,20 @@ static inline void start_logging_wakeup_reasons(void)
{
extern bool log_wakeups;
extern struct completion wakeups_completion;
log_wakeups = true;
ACCESS_ONCE(log_wakeups) = true;
init_completion(&wakeups_completion);
}
static inline bool logging_wakeup_reasons_nosync(void)
{
extern bool log_wakeups;
return ACCESS_ONCE(log_wakeups);
}
static inline bool logging_wakeup_reasons(void)
{
extern bool log_wakeups;
return ACCESS_ONCE(log_wakeups);
smp_rmb();
return logging_wakeup_reasons_nosync();
}
void log_base_wakeup_reason(int irq);

View file

@ -317,7 +317,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);

View file

@ -306,6 +306,7 @@ static struct attribute_group attr_group = {
static inline void stop_logging_wakeup_reasons(void)
{
ACCESS_ONCE(log_wakeups) = false;
smp_wmb();
}
/*
@ -343,9 +344,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.
*/
@ -572,7 +580,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();
}
break;