Skip to contentSkip to conversation

cpufreq/amd-pstate: Remove unnecessary driver_lock in set_boost

PATCH Applied Dhananjay Ugwekar 4 participants 5 messages Jan 30, 2025 – Feb 3, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq/amd-pstate: Remove unnecessary driver_lock in set_boost

set_boost is a per-policy function call, hence a driver wide lock is unnecessary. Also this mutex_acquire can collide with the mutex_acquire from the mode-switch path in status_store(), which can lead to a deadlock. So, remove it.

---
PS: This patch should ideally go before [1], as that patch uncovers this
bug and actually leads to a deadlock when switching the amd_pstate driver
mode.
[1] https://lore.kernel.org/linux-pm/e16c06d4b8ffdb20e802ffe648f14dc515e60426.1737707712.git.viresh.kumar@linaro.org/

---
 drivers/cpufreq/amd-pstate.c | 1 -
 1 file changed, 1 deletion(-)
drivers/cpufreq/amd-pstate.c +0 -1
index d5be51bf8692..93788bce7e6a 100644
@@ -740,7 +740,6 @@ static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
 		pr_err("Boost mode is not supported by this processor or SBIOS\n");
 		return -EOPNOTSUPP;
 	}
-	guard(mutex)(&amd_pstate_driver_lock);
 
 	ret = amd_pstate_cpu_boost_update(policy, state);
 	refresh_frequency_limits(policy);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 4 lines · Dhananjay Ugwekar

set_boost is a per-policy function call, hence a driver wide lock is unnecessary. Also this mutex_acquire can collide with the mutex_acquire from the mode-switch path in status_store(), which can lead to a deadlock. So, remove it.

Looks good to me. The driver lock should only guard the state changes. Everything else is a per-policy change and is better guarded by the per-cpudata mutex.

Once Mario acks this patch, please respond to Viresh's series and let him know that this patch needs to go in before his series. If he is ok with it, he can include it in his series.

Quoted 26 lines

---
PS: This patch should ideally go before [1], as that patch uncovers this
bug and actually leads to a deadlock when switching the amd_pstate driver
mode.
[1] https://lore.kernel.org/linux-pm/e16c06d4b8ffdb20e802ffe648f14dc515e60426.1737707712.git.viresh.kumar@linaro.org/

---
 drivers/cpufreq/amd-pstate.c | 1 -
 1 file changed, 1 deletion(-)
drivers/cpufreq/amd-pstate.c +0 -1
index d5be51bf8692..93788bce7e6a 100644
@@ -740,7 +740,6 @@ static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
 		pr_err("Boost mode is not supported by this processor or SBIOS\n");
 		return -EOPNOTSUPP;
 	}
-	guard(mutex)(&amd_pstate_driver_lock);
 
 	ret = amd_pstate_cpu_boost_update(policy, state);
 	refresh_frequency_limits(policy);
Signature · 1 line
2.34.1
Signature · 2 lines
Thanks and Regards
gautham.
maintainer
#2 lore raw
Quoted 6 lines · Gautham R. Shenoy
Quoted 4 lines · Dhananjay Ugwekar

set_boost is a per-policy function call, hence a driver wide lock is unnecessary. Also this mutex_acquire can collide with the mutex_acquire from the mode-switch path in status_store(), which can lead to a deadlock. So, remove it.

Quoted 7 lines

Looks good to me. The driver lock should only guard the state changes. Everything else is a per-policy change and is better guarded by the per-cpudata mutex.

Once Mario acks this patch, please respond to Viresh's series and let him know that this patch needs to go in before his series. If he is ok with it, he can include it in his series.

Yeah, I will apply this once rc1 is out.

Signature · 1 line
viresh
maintainer Applied
#3 lore raw
In reply to Dhananjay Ugwekar
Quoted 20 lines · Dhananjay Ugwekar

set_boost is a per-policy function call, hence a driver wide lock is unnecessary. Also this mutex_acquire can collide with the mutex_acquire from the mode-switch path in status_store(), which can lead to a deadlock. So, remove it.

---
PS: This patch should ideally go before [1], as that patch uncovers this
bug and actually leads to a deadlock when switching the amd_pstate driver
mode.
[1] https://lore.kernel.org/linux-pm/e16c06d4b8ffdb20e802ffe648f14dc515e60426.1737707712.git.viresh.kumar@linaro.org/

---
 drivers/cpufreq/amd-pstate.c | 1 -
 1 file changed, 1 deletion(-)
drivers/cpufreq/amd-pstate.c +0 -0
index d5be51bf8692..93788bce7e6a 100644

drivers/cpufreq/amd-pstate.c static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state) · line 745

Quoted 7 lines
drivers/cpufreq/amd-pstate.c +0 -1
@@ -740,7 +740,6 @@ static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
 		pr_err("Boost mode is not supported by this processor or SBIOS\n");
 		return -EOPNOTSUPP;
 	}
-	guard(mutex)(&amd_pstate_driver_lock);
 
 	ret = amd_pstate_cpu_boost_update(policy, state);
 	refresh_frequency_limits(policy);

Applied. Thanks.

Signature · 1 line
viresh
maintainer Acked-by
#4 lore raw
Quoted 26 lines · Viresh Kumar
Quoted 25 lines · Dhananjay Ugwekar

set_boost is a per-policy function call, hence a driver wide lock is unnecessary. Also this mutex_acquire can collide with the mutex_acquire from the mode-switch path in status_store(), which can lead to a deadlock. So, remove it.

---
PS: This patch should ideally go before [1], as that patch uncovers this
bug and actually leads to a deadlock when switching the amd_pstate driver
mode.
[1] https://lore.kernel.org/linux-pm/e16c06d4b8ffdb20e802ffe648f14dc515e60426.1737707712.git.viresh.kumar@linaro.org/

---
  drivers/cpufreq/amd-pstate.c | 1 -
  1 file changed, 1 deletion(-)
drivers/cpufreq/amd-pstate.c +0 -1
index d5be51bf8692..93788bce7e6a 100644
@@ -740,7 +740,6 @@ static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
  		pr_err("Boost mode is not supported by this processor or SBIOS\n");
  		return -EOPNOTSUPP;
  	}
-	guard(mutex)(&amd_pstate_driver_lock);
 
Quoted 5 lines

drivers/cpufreq/amd-pstate.c static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state) · line 745

Quoted 2 lines
drivers/cpufreq/amd-pstate.c +0 -0
  	ret = amd_pstate_cpu_boost_update(policy, state);
  	refresh_frequency_limits(policy);

Applied. Thanks.

Sorry for my delay with the recent holiday.
I have no concerns with this going to the start of the series.