Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 896a4f47 authored by Iliyan Malchev's avatar Iliyan Malchev Committed by Venkatesh Yadav Abbarapu
Browse files

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: default avatarIliyan Malchev <malchev@google.com>
Git-commit: 0654cdc20b7463d948434931477b35a018e76db1
Git-repo: https://android.googlesource.com/kernel/msm


Signed-off-by: default avatarVenkatesh Yadav Abbarapu <vabbar@codeaurora.org>
parent ab2c849f
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -61,16 +61,22 @@ 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(void)
static inline bool logging_wakeup_reasons_nosync(void)
{
	extern bool log_wakeups;
	return ACCESS_ONCE(log_wakeups);
}

static inline bool logging_wakeup_reasons(void)
{
	smp_rmb();
	return logging_wakeup_reasons_nosync();
}

void log_base_wakeup_reason(int irq);

void log_suspend_abort_reason(const char *fmt, ...);
+1 −1
Original line number Diff line number Diff line
@@ -354,7 +354,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);
+9 −2
Original line number Diff line number Diff line
@@ -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 */