Skip to contentSkip to conversation

memory: exynos5422-dmc: Document mutex scope

RFC In review Krzysztof Kozlowski 2 participants 4 messages Jul 24, 2020 – Aug 11, 2020

Subsystems (3)
lore
Share & tools
lore

Krzysztof Kozlowski

author maintainer
#0 lore raw

RFC 1/1 memory: exynos5422-dmc: Document mutex scope

Document scope of the mutex used by driver.

---

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(+)
drivers/memory/samsung/exynos5422-dmc.c +1 -0
index 93e9c2429c0d..0388066a7d96 100644
@@ -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;
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi Krzysztof,

Quoted 4 lines · Krzysztof Kozlowski

Document scope of the mutex used by driver.

Quoted 8 lines

---

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.

Quoted 10 lines
---
  drivers/memory/samsung/exynos5422-dmc.c | 1 +
  1 file changed, 1 insertion(+)
drivers/memory/samsung/exynos5422-dmc.c +0 -0
index 93e9c2429c0d..0388066a7d96 100644

drivers/memory/samsung/exynos5422-dmc.c struct exynos5_dmc { · line 120

Quoted 7 lines
drivers/memory/samsung/exynos5422-dmc.c +1 -0
@@ -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:

Regards,
Lukasz

author maintainer
#2 lore raw
Quoted 22 lines · Lukasz Luba

Hi Krzysztof,

Quoted 4 lines · Krzysztof Kozlowski

Document scope of the mutex used by driver.

Quoted 8 lines

---

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()

Quoted 6 lines
    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.

Quoted 21 lines
Quoted 10 lines
---
  drivers/memory/samsung/exynos5422-dmc.c | 1 +
  1 file changed, 1 insertion(+)
drivers/memory/samsung/exynos5422-dmc.c +0 -0
index 93e9c2429c0d..0388066a7d96 100644

drivers/memory/samsung/exynos5422-dmc.c struct exynos5_dmc { · line 120

Quoted 7 lines
drivers/memory/samsung/exynos5422-dmc.c +1 -0
@@ -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:

Quoted 1 line

Such comments are always useful. It is also pointed by strict checkpatch:
CHECK: struct mutex definition without comment

Best regards,
Krzysztof

maintainer
#3 lore raw
Quoted 26 lines · Krzysztof Kozlowski
Quoted 25 lines · Lukasz Luba

Hi Krzysztof,

Quoted 4 lines · Krzysztof Kozlowski

Document scope of the mutex used by driver.

Quoted 8 lines

---

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()
Quoted 7 lines
Quoted 3 lines

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