From: Mark Tseng <chun-jen.tseng@mediatek.com>
To: "Rafael J . Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
MyungJoo Ham <myungjoo.ham@samsung.com>,
"Kyungmin Park" <kyungmin.park@samsung.com>,
Chanwoo Choi <cw00.choi@samsung.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>
Cc: <linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-mediatek@lists.infradead.org>,
<Project_Global_Chrome_Upstream_Group@mediatek.com>,
<chun-jen.tseng@mediatek.com>
Subject: [PATCH v1 1/2] PM / devfreq: mediatek: protect oop in critical session
Date: Fri, 13 Sep 2024 18:39:32 +0800 [thread overview]
Message-ID: <20240913103933.30895-2-chun-jen.tseng@mediatek.com> (raw)
In-Reply-To: <20240913103933.30895-1-chun-jen.tseng@mediatek.com>
mtk_ccifreq_target() & mtk_ccifreq_opp_notifier() is re-enter funtion
when cpufreq governor is more than one. It should add global mutex to
protect OPP , avoid get wrong frequency & voltage.
Signed-off-by: Mark Tseng <chun-jen.tseng@mediatek.com>
---
drivers/devfreq/mtk-cci-devfreq.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/drivers/devfreq/mtk-cci-devfreq.c b/drivers/devfreq/mtk-cci-devfreq.c
index 7ad5225b0381..293cf81e53fe 100644
--- a/drivers/devfreq/mtk-cci-devfreq.c
+++ b/drivers/devfreq/mtk-cci-devfreq.c
@@ -29,13 +29,14 @@ struct mtk_ccifreq_drv {
struct clk *inter_clk;
int inter_voltage;
unsigned long pre_freq;
- /* Avoid race condition for regulators between notify and policy */
- struct mutex reg_lock;
struct notifier_block opp_nb;
const struct mtk_ccifreq_platform_data *soc_data;
int vtrack_max;
};
+/* Avoid race condition for regulators between notify and policy */
+static DEFINE_MUTEX(reg_lock);
+
static int mtk_ccifreq_set_voltage(struct mtk_ccifreq_drv *drv, int new_voltage)
{
const struct mtk_ccifreq_platform_data *soc_data = drv->soc_data;
@@ -125,22 +126,20 @@ static int mtk_ccifreq_set_voltage(struct mtk_ccifreq_drv *drv, int new_voltage)
static int mtk_ccifreq_target(struct device *dev, unsigned long *freq,
u32 flags)
{
- struct mtk_ccifreq_drv *drv = dev_get_drvdata(dev);
+ struct mtk_ccifreq_drv *drv;
struct clk *cci_pll;
struct dev_pm_opp *opp;
unsigned long opp_rate;
int voltage, pre_voltage, inter_voltage, target_voltage, ret;
+ mutex_lock(®_lock);
+
+ drv = dev_get_drvdata(dev);
if (!drv)
return -EINVAL;
- if (drv->pre_freq == *freq)
- return 0;
-
- mutex_lock(&drv->reg_lock);
-
- inter_voltage = drv->inter_voltage;
cci_pll = clk_get_parent(drv->cci_clk);
+ inter_voltage = drv->inter_voltage;
opp_rate = *freq;
opp = devfreq_recommended_opp(dev, &opp_rate, 1);
@@ -206,7 +205,7 @@ static int mtk_ccifreq_target(struct device *dev, unsigned long *freq,
}
drv->pre_freq = *freq;
- mutex_unlock(&drv->reg_lock);
+ mutex_unlock(®_lock);
return 0;
@@ -214,21 +213,23 @@ static int mtk_ccifreq_target(struct device *dev, unsigned long *freq,
mtk_ccifreq_set_voltage(drv, pre_voltage);
out_unlock:
- mutex_unlock(&drv->reg_lock);
+ mutex_unlock(®_lock);
return ret;
}
static int mtk_ccifreq_opp_notifier(struct notifier_block *nb,
unsigned long event, void *data)
{
- struct dev_pm_opp *opp = data;
+ struct dev_pm_opp *opp;
struct mtk_ccifreq_drv *drv;
unsigned long freq, volt;
+ mutex_lock(®_lock);
+
+ opp = data;
drv = container_of(nb, struct mtk_ccifreq_drv, opp_nb);
if (event == OPP_EVENT_ADJUST_VOLTAGE) {
- mutex_lock(&drv->reg_lock);
freq = dev_pm_opp_get_freq(opp);
/* current opp item is changed */
@@ -236,8 +237,8 @@ static int mtk_ccifreq_opp_notifier(struct notifier_block *nb,
volt = dev_pm_opp_get_voltage(opp);
mtk_ccifreq_set_voltage(drv, volt);
}
- mutex_unlock(&drv->reg_lock);
}
+ mutex_unlock(®_lock);
return 0;
}
@@ -262,7 +263,6 @@ static int mtk_ccifreq_probe(struct platform_device *pdev)
drv->dev = dev;
drv->soc_data = (const struct mtk_ccifreq_platform_data *)
of_device_get_match_data(&pdev->dev);
- mutex_init(&drv->reg_lock);
platform_set_drvdata(pdev, drv);
drv->cci_clk = devm_clk_get(dev, "cci");
--
2.45.2
next prev parent reply other threads:[~2024-09-13 10:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-13 10:39 [PATCH v1 0/2] fixed mediatek-cpufreq has multi policy concurrency issue Mark Tseng
2024-09-13 10:39 ` Mark Tseng [this message]
2024-10-01 6:39 ` [PATCH v1 1/2] PM / devfreq: mediatek: protect oop in critical session Viresh Kumar
2024-10-01 6:41 ` Viresh Kumar
2024-09-13 10:39 ` [PATCH v1 2/2] cpufreq: mediatek: Fixed cpufreq has 2 policy will cause concurrency Mark Tseng
2024-10-01 6:43 ` Viresh Kumar
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=20240913103933.30895-2-chun-jen.tseng@mediatek.com \
--to=chun-jen.tseng@mediatek.com \
--cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=cw00.choi@samsung.com \
--cc=kyungmin.park@samsung.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=myungjoo.ham@samsung.com \
--cc=rafael@kernel.org \
--cc=viresh.kumar@linaro.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