PM / devfreq: Introduce an event lock

Currently, concurrent writes to sysfs entries leave the	possibility
for race conditions within the devfreq framework.  For example,
concurrently executing max_freq_store and governor_store can result
in attempting to perform an update_devfreq() before the new governor's
start handler can be executed.

A more concrete case is a race between polling_interval_store and
governor_store.  Because no lock is used after calling into the event
handler of the old governor and there's nothing preventing work from
being queued after the monitor is stopped, it's possible to
accidentally cause delayed work to be queued on the governor being
switched to.  This can be seen if you create two threads, one which
changes a device's governor between simple_ondemand and performance,
and one which changes its polling interval between 45 and 50.

All of these races can be addressed with the introduction of a lock
that prevents sysfs operations from interleaving in this fashion.

Change-Id: Ia6887dcb2d69dc2576837a6c09fed55a28943abc
Signed-off-by: Jonathan Avila <avilaj@codeaurora.org>
[avajid@codeaurora.org: renamed to event lock and only used when CONFIG_QCOM_DEVFREQ_ICC is enabled]
Signed-off-by: Amir Vajid <avajid@codeaurora.org>
This commit is contained in:
Jonathan Avila
2019-01-16 20:28:27 -08:00
committed by Amir Vajid
parent 52ab3535b2
commit 9693b4d620
2 changed files with 41 additions and 1 deletions

View File

@@ -149,6 +149,9 @@ struct devfreq {
struct list_head node;
struct mutex lock;
#ifdef CONFIG_QCOM_DEVFREQ_ICC
struct mutex event_lock;
#endif
struct device dev;
struct devfreq_dev_profile *profile;
const struct devfreq_governor *governor;
@@ -185,6 +188,31 @@ struct devfreq_freqs {
unsigned long new;
};
static inline void event_mutex_init(struct devfreq *devfreq)
{
#ifdef CONFIG_QCOM_DEVFREQ_ICC
mutex_init(&devfreq->event_lock);
#endif
}
static inline void event_mutex_destroy(struct devfreq *devfreq)
{
#ifdef CONFIG_QCOM_DEVFREQ_ICC
mutex_destroy(&devfreq->event_lock);
#endif
}
static inline void event_mutex_lock(struct devfreq *devfreq)
{
#ifdef CONFIG_QCOM_DEVFREQ_ICC
mutex_lock(&devfreq->event_lock);
#endif
}
static inline void event_mutex_unlock(struct devfreq *devfreq)
{
#ifdef CONFIG_QCOM_DEVFREQ_ICC
mutex_unlock(&devfreq->event_lock);
#endif
}
#if defined(CONFIG_PM_DEVFREQ)
extern struct devfreq *devfreq_add_device(struct device *dev,
struct devfreq_dev_profile *profile,