* [RFC] memory: exynos5422-dmc: Document mutex scope
@ 2020-07-24 18:08 Krzysztof Kozlowski
2020-08-04 10:40 ` Lukasz Luba
0 siblings, 1 reply; 4+ messages in thread
From: Krzysztof Kozlowski @ 2020-07-24 18:08 UTC (permalink / raw)
To: Lukasz Luba, Krzysztof Kozlowski, Kukjin Kim, linux-pm,
linux-samsung-soc, linux-kernel, linux-arm-kernel
Document scope of the mutex used by driver.
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
It seems mutex was introduced to protect:
1. setting actual frequency/voltage,
2. dmc->curr_rate (in exynos5_dmc_get_cur_freq()).
However dmc->curr_rate in exynos5_dmc_get_status() is not protected. Is
it a bug?
---
drivers/memory/samsung/exynos5422-dmc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/memory/samsung/exynos5422-dmc.c b/drivers/memory/samsung/exynos5422-dmc.c
index 93e9c2429c0d..0388066a7d96 100644
--- a/drivers/memory/samsung/exynos5422-dmc.c
+++ b/drivers/memory/samsung/exynos5422-dmc.c
@@ -114,6 +114,7 @@ struct exynos5_dmc {
void __iomem *base_drexi0;
void __iomem *base_drexi1;
struct regmap *clk_regmap;
+ /* Protects curr_rate and frequency/voltage setting section */
struct mutex lock;
unsigned long curr_rate;
unsigned long curr_volt;
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC] memory: exynos5422-dmc: Document mutex scope
2020-07-24 18:08 [RFC] memory: exynos5422-dmc: Document mutex scope Krzysztof Kozlowski
@ 2020-08-04 10:40 ` Lukasz Luba
2020-08-09 9:12 ` Krzysztof Kozlowski
0 siblings, 1 reply; 4+ messages in thread
From: Lukasz Luba @ 2020-08-04 10:40 UTC (permalink / raw)
To: Krzysztof Kozlowski, Kukjin Kim, linux-pm, linux-samsung-soc,
linux-kernel, linux-arm-kernel
Hi Krzysztof,
On 7/24/20 7:08 PM, Krzysztof Kozlowski wrote:
> Document scope of the mutex used by driver.
>
> Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
>
> ---
>
> It seems mutex was introduced to protect:
> 1. setting actual frequency/voltage,
> 2. dmc->curr_rate (in exynos5_dmc_get_cur_freq()).
>
> However dmc->curr_rate in exynos5_dmc_get_status() is not protected. Is
> it a bug?
The callback get_dev_status() from devfreq->profile, which here is the
exynos5_dmc_get_status() should be already called with devfreq->lock
mutex hold, like e.g from simple_ondemand governor or directly
using update_devfreq exported function:
update_devfreq()
->get_target_freq()
devfreq_update_stats()
df->profile->get_dev_status()
The dmc->curr_rate is also used from sysfs interface from devfreq.
The local dmc lock serializes also this use case (when the HW freq
has changed but not set yet into curr_rate.
> ---
> drivers/memory/samsung/exynos5422-dmc.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/memory/samsung/exynos5422-dmc.c b/drivers/memory/samsung/exynos5422-dmc.c
> index 93e9c2429c0d..0388066a7d96 100644
> --- a/drivers/memory/samsung/exynos5422-dmc.c
> +++ b/drivers/memory/samsung/exynos5422-dmc.c
> @@ -114,6 +114,7 @@ struct exynos5_dmc {
> void __iomem *base_drexi0;
> void __iomem *base_drexi1;
> struct regmap *clk_regmap;
> + /* Protects curr_rate and frequency/voltage setting section */
> struct mutex lock;
> unsigned long curr_rate;
> unsigned long curr_volt;
>
I assume this missing comment for the lock was required by some scripts.
In this case LGTM:
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Regards,
Lukasz
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC] memory: exynos5422-dmc: Document mutex scope
2020-08-04 10:40 ` Lukasz Luba
@ 2020-08-09 9:12 ` Krzysztof Kozlowski
2020-08-11 9:27 ` Lukasz Luba
0 siblings, 1 reply; 4+ messages in thread
From: Krzysztof Kozlowski @ 2020-08-09 9:12 UTC (permalink / raw)
To: Lukasz Luba
Cc: Kukjin Kim, linux-pm, linux-samsung-soc, linux-kernel, linux-arm-kernel
On Tue, Aug 04, 2020 at 11:40:07AM +0100, Lukasz Luba wrote:
> Hi Krzysztof,
>
> On 7/24/20 7:08 PM, Krzysztof Kozlowski wrote:
> > Document scope of the mutex used by driver.
> >
> > Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
> >
> > ---
> >
> > It seems mutex was introduced to protect:
> > 1. setting actual frequency/voltage,
> > 2. dmc->curr_rate (in exynos5_dmc_get_cur_freq()).
> >
> > However dmc->curr_rate in exynos5_dmc_get_status() is not protected. Is
> > it a bug?
>
> The callback get_dev_status() from devfreq->profile, which here is the
> exynos5_dmc_get_status() should be already called with devfreq->lock
> mutex hold, like e.g from simple_ondemand governor or directly
> using update_devfreq exported function:
> update_devfreq()
> ->get_target_freq()
> devfreq_update_stats()
> df->profile->get_dev_status()
>
> The dmc->curr_rate is also used from sysfs interface from devfreq.
> The local dmc lock serializes also this use case (when the HW freq
> has changed but not set yet into curr_rate.
These are different locks. You cannot protect dmc->curr_rate with
devfreq->lock in one place and dmc-lock in other place. This won't
protect it.
> > ---
> > drivers/memory/samsung/exynos5422-dmc.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/memory/samsung/exynos5422-dmc.c b/drivers/memory/samsung/exynos5422-dmc.c
> > index 93e9c2429c0d..0388066a7d96 100644
> > --- a/drivers/memory/samsung/exynos5422-dmc.c
> > +++ b/drivers/memory/samsung/exynos5422-dmc.c
> > @@ -114,6 +114,7 @@ struct exynos5_dmc {
> > void __iomem *base_drexi0;
> > void __iomem *base_drexi1;
> > struct regmap *clk_regmap;
> > + /* Protects curr_rate and frequency/voltage setting section */
> > struct mutex lock;
> > unsigned long curr_rate;
> > unsigned long curr_volt;
> >
>
> I assume this missing comment for the lock was required by some scripts.
> In this case LGTM:
>
> Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Such comments are always useful. It is also pointed by strict
checkpatch:
CHECK: struct mutex definition without comment
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC] memory: exynos5422-dmc: Document mutex scope
2020-08-09 9:12 ` Krzysztof Kozlowski
@ 2020-08-11 9:27 ` Lukasz Luba
0 siblings, 0 replies; 4+ messages in thread
From: Lukasz Luba @ 2020-08-11 9:27 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Kukjin Kim, linux-pm, linux-samsung-soc, linux-kernel, linux-arm-kernel
On 8/9/20 10:12 AM, Krzysztof Kozlowski wrote:
> On Tue, Aug 04, 2020 at 11:40:07AM +0100, Lukasz Luba wrote:
>> Hi Krzysztof,
>>
>> On 7/24/20 7:08 PM, Krzysztof Kozlowski wrote:
>>> Document scope of the mutex used by driver.
>>>
>>> Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
>>>
>>> ---
>>>
>>> It seems mutex was introduced to protect:
>>> 1. setting actual frequency/voltage,
>>> 2. dmc->curr_rate (in exynos5_dmc_get_cur_freq()).
>>>
>>> However dmc->curr_rate in exynos5_dmc_get_status() is not protected. Is
>>> it a bug?
>>
>> The callback get_dev_status() from devfreq->profile, which here is the
>> exynos5_dmc_get_status() should be already called with devfreq->lock
>> mutex hold, like e.g from simple_ondemand governor or directly
>> using update_devfreq exported function:
>> update_devfreq()
>> ->get_target_freq()
>> devfreq_update_stats()
>> df->profile->get_dev_status()
>>
>> The dmc->curr_rate is also used from sysfs interface from devfreq.
>> The local dmc lock serializes also this use case (when the HW freq
>> has changed but not set yet into curr_rate.
>
> These are different locks. You cannot protect dmc->curr_rate with
> devfreq->lock in one place and dmc-lock in other place. This won't
> protect it.
There are different paths that framework goes and mainly they are
protected by the df->lock.
But I tend to agree, I will send a patch which adds some locking.
Regards,
Lukasz
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-08-11 9:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-24 18:08 [RFC] memory: exynos5422-dmc: Document mutex scope Krzysztof Kozlowski
2020-08-04 10:40 ` Lukasz Luba
2020-08-09 9:12 ` Krzysztof Kozlowski
2020-08-11 9:27 ` Lukasz Luba
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).