Skip to contentSkip to conversation

Patch "PM / OPP: Call notifier without holding opp_table->lock" has been added to the 4.13-stable tree

PATCH [email protected] 1 participant 1 message Oct 2, 2017

Subsystems (5)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

    PM / OPP: Call notifier without holding opp_table->lock

to the 4.13-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
pm-opp-call-notifier-without-holding-opp_table-lock.patch
and it can be found in the queue-4.13 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From e4d8ae00169f7686e1da5a62e5cf797d12bf8822 Mon Sep 17 00:00:00 2001

From: Viresh Kumar <[email protected]>
Date: Thu, 21 Sep 2017 10:44:36 -0700
Subject: PM / OPP: Call notifier without holding opp_table->lock

From: Viresh Kumar <[email protected]>

commit e4d8ae00169f7686e1da5a62e5cf797d12bf8822 upstream.

The notifier callbacks may want to call some OPP helper routines which may try to take the same opp_table->lock again and cause a deadlock. One such usecase was reported by Chanwoo Choi, where calling dev_pm_opp_disable() leads us to the devfreq's OPP notifier handler, which further calls dev_pm_opp_find_freq_floor() and it deadlocks.

We don't really need the opp_table->lock to be held across the notifier call though, all we want to make sure is that the 'opp' doesn't get freed while being used from within the notifier chain. We can do it with help of dev_pm_opp_get/put() as well. Let's do it.

---
 drivers/base/power/opp/core.c |    7 +++++++
 1 file changed, 7 insertions(+)
drivers/base/power/opp/core.c +7 -0
@@ -1581,6 +1581,9 @@ static int _opp_set_availability(struct
 
 	opp->available = availability_req;
 
+	dev_pm_opp_get(opp);
+	mutex_unlock(&opp_table->lock);
+
 	/* Notify the change of the OPP availability */
 	if (availability_req)
 		blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ENABLE,
@@ -1589,8 +1592,12 @@ static int _opp_set_availability(struct
 		blocking_notifier_call_chain(&opp_table->head,
 					     OPP_EVENT_DISABLE, opp);
 
+	dev_pm_opp_put(opp);
+	goto put_table;
+
 unlock:
 	mutex_unlock(&opp_table->lock);
+put_table:
 	dev_pm_opp_put_opp_table(opp_table);
 	return r;
 }

Patches currently in stable-queue which might be from [email protected] are

queue-4.13/pm-opp-call-notifier-without-holding-opp_table-lock.patch