linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: sboyd@codeaurora.org (Stephen Boyd)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC/PATCH 4/6] OPP: Allow notifiers to call dev_pm_opp_get_{voltage, freq} RCU-free
Date: Wed, 03 Jun 2015 15:43:34 -0700	[thread overview]
Message-ID: <556F8316.2000109@codeaurora.org> (raw)
In-Reply-To: <556D2369.2000603@samsung.com>

On 06/01/2015 08:30 PM, Krzysztof Kozlowski wrote:
> On 02.06.2015 10:47, Stephen Boyd wrote:
>> We pass the dev_pm_opp structure to OPP notifiers but the users
>> of the notifier need to surround calls to dev_pm_opp_get_*() with
>> RCU read locks to avoid lockdep warnings. The notifier is already
>> called with the dev_opp's srcu lock held, so it should be safe to
>> assume the devm_pm_opp structure is already protected inside the
>> notifier. Update the lockdep check for this.
>>
>> Cc: Krzysztof Kozlowski <k.kozlowski@samsung.com>
>> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
>> ---
>>
>> This is probably wrong, but it's what I had to hack up
>> to be able to use the OPP functions from within the notifier
>> to figure out the new values of the OPP without having to take
>> an RCU read lock.
>>
>>   drivers/base/power/opp.c | 19 +++++++++++--------
>>   1 file changed, 11 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
>> index b997a7eabcd4..6d75022c6a0e 100644
>> --- a/drivers/base/power/opp.c
>> +++ b/drivers/base/power/opp.c
>> @@ -108,9 +108,10 @@ static LIST_HEAD(dev_opp_list);
>>   /* Lock to allow exclusive modification to the device and opp lists */
>>   static DEFINE_MUTEX(dev_opp_list_lock);
>>   
>> -#define opp_rcu_lockdep_assert()					\
>> +#define opp_rcu_lockdep_assert(s)					\
>>   do {									\
>>   	rcu_lockdep_assert(rcu_read_lock_held() ||			\
>> +				(s && srcu_read_lock_held(s)) || 	\
>>   				lockdep_is_held(&dev_opp_list_lock),	\
>>   			   "Missing rcu_read_lock() or "		\
>>   			   "dev_opp_list_lock protection");		\
>> @@ -169,9 +170,10 @@ unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
>>   	struct dev_pm_opp *tmp_opp;
>>   	unsigned long v = 0;
>>   
>> -	opp_rcu_lockdep_assert();
>> +	opp_rcu_lockdep_assert(&opp->dev_opp->srcu_head.srcu);
>>   
>> -	tmp_opp = rcu_dereference(opp);
>> +	tmp_opp = srcu_dereference_check(opp, &opp->dev_opp->srcu_head.srcu,
>> +					 rcu_read_lock_held());
> It looks strange. The notifier's SRCU is part of device_opp but here we
> want to protect the dev_pm_opp.
>
> Because of this difference I am not sure that it is safe having around
> this a srcu_read_lock() from notifiers instead of rcu_read_lock().
>
>

Yeah I'm not sure, and I'll have to spend more time to figure out what's 
going on, hence the RFC. Does it make sense to allow the notifiers to 
call these functions without rcu_read_lock() though? It certainly looks 
strange to call rcu_read_lock() with a pointer that is handed to the 
notifier.

It also seems that rcu_dereference() will take care of calling 
rcu_read_lock_held() for us so having an opp_rcu_lockdep_assert() here 
is redundant.

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

  reply	other threads:[~2015-06-03 22:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-02  1:47 [PATCH 0/6] Support CPR on MSM8916 Stephen Boyd
2015-06-02  1:47 ` [PATCH 1/6] regulator: core: Don't spew backtraces on duplicate sysfs Stephen Boyd
2015-06-03 12:20   ` Mark Brown
2015-06-02  1:47 ` [PATCH 2/6] regulator: core: Print at debug level on debugfs creation failure Stephen Boyd
2015-06-03 18:39   ` Mark Brown
2015-06-02  1:47 ` [PATCH 3/6] PM / OPP: Support adjusting OPP voltages at runtime Stephen Boyd
2015-06-02  4:50   ` Viresh Kumar
2015-06-02 19:54     ` Stephen Boyd
2015-06-02  1:47 ` [RFC/PATCH 4/6] OPP: Allow notifiers to call dev_pm_opp_get_{voltage, freq} RCU-free Stephen Boyd
2015-06-02  3:30   ` [RFC/PATCH 4/6] OPP: Allow notifiers to call dev_pm_opp_get_{voltage,freq} RCU-free Krzysztof Kozlowski
2015-06-03 22:43     ` Stephen Boyd [this message]
2015-06-02  1:47 ` [PATCH 5/6] cpufreq-dt: Handle OPP voltage adjust events Stephen Boyd
2015-06-02  1:47 ` [PATCH 6/6] power: avs: Add support for CPR (Core Power Reduction) Stephen Boyd
2015-06-02 10:53 ` [PATCH 0/6] Support CPR on MSM8916 Mark Brown
2015-06-02 17:56   ` Stephen Boyd
2015-06-02 18:20     ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=556F8316.2000109@codeaurora.org \
    --to=sboyd@codeaurora.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).