cpufreq: drop redundant cpus_read_lock() from store_local_boost()
PATCH 1/1 cpufreq: drop redundant cpus_read_lock() from store_local_boost()
Lockdep reports a possible circular locking dependency[1] when cpu_hotplug_lock is acquired inside store_local_boost(), after policy->rwsem has already been taken by store().
However, the boost update is strictly per-policy and does not access shared state or iterate over all policies. Since policy->rwsem is already held, this is enough to serialize against concurrent topology changes for the current policy.
Remove the cpus_read_lock() to resolve the lockdep warning and avoid unnecessary locking.
[1]
======================================================
WARNING: possible circular locking dependency detected 6.15.0-rc6-debug-gb01fc4eca73c #1 Not tainted
------------------------------------------------------
power-profiles-/588 is trying to acquire lock:
ffffffffb3a7d910 (cpu_hotplug_lock){++++}-{0:0}, at: store_local_boost+0x56/0xd0
but task is already holding lock:
ffff8b6e5a12c380 (&policy->rwsem){++++}-{4:4}, at: store+0x37/0x90
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #2 (&policy->rwsem){++++}-{4:4}:
down_write+0x29/0xb0
cpufreq_online+0x7e8/0xa40
cpufreq_add_dev+0x82/0xa0
subsys_interface_register+0x148/0x160
cpufreq_register_driver+0x15d/0x260
amd_pstate_register_driver+0x36/0x90
amd_pstate_init+0x1e7/0x270
do_one_initcall+0x68/0x2b0
kernel_init_freeable+0x231/0x270
kernel_init+0x15/0x130
ret_from_fork+0x2c/0x50
ret_from_fork_asm+0x11/0x20-> #1 (subsys mutex#3){+.+.}-{4:4}:
__mutex_lock+0xc2/0x930
subsys_interface_register+0x7f/0x160
cpufreq_register_driver+0x15d/0x260
amd_pstate_register_driver+0x36/0x90
amd_pstate_init+0x1e7/0x270
do_one_initcall+0x68/0x2b0
kernel_init_freeable+0x231/0x270
kernel_init+0x15/0x130
ret_from_fork+0x2c/0x50
ret_from_fork_asm+0x11/0x20-> #0 (cpu_hotplug_lock){++++}-{0:0}:
__lock_acquire+0x10ed/0x1850
lock_acquire.part.0+0x69/0x1b0
cpus_read_lock+0x2a/0xc0
store_local_boost+0x56/0xd0
store+0x50/0x90
kernfs_fop_write_iter+0x132/0x200
vfs_write+0x2b3/0x590
ksys_write+0x74/0xf0
do_syscall_64+0xbb/0x1d0
entry_SYSCALL_64_after_hwframe+0x56/0x5e--- drivers/cpufreq/cpufreq.c | 3 --- 1 file changed, 3 deletions(-)
drivers/cpufreq/cpufreq.c +0 -3
@@ -622,10 +622,7 @@ static ssize_t store_local_boost(struct cpufreq_policy *policy,if (!policy->boost_supported)return -EINVAL ; -cpus_read_lock (); ret =policy_set_boost (policy, enable); -cpus_read_unlock (); -if (!ret)return count;
Signature · 1 line
2.49.0
Quoted 77 lines · Seyediman Seyedarab
Lockdep reports a possible circular locking dependency[1] when
cpu_hotplug_lockis acquired insidestore_local_boost(), afterpolicy->rwsemhas already been taken bystore().However, the boost update is strictly per-policy and does not access shared state or iterate over all policies. Since
policy->rwsemis already held, this is enough to serialize against concurrent topology changes for the current policy.Remove the
cpus_read_lock()to resolve the lockdep warning and avoid unnecessary locking.[1]
======================================================
WARNING: possible circular locking dependency detected 6.15.0-rc6-debug-gb01fc4eca73c #1 Not tainted
------------------------------------------------------
power-profiles-/588 is trying to acquire lock:
ffffffffb3a7d910(cpu_hotplug_lock){++++}-{0:0}, at:store_local_boost+0x56/0xd0but task is already holding lock:
ffff8b6e5a12c380(&policy->rwsem){++++}-{4:4}, at:store+0x37/0x90which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #2 (&policy->rwsem){++++}-{4:4}:
down_write+0x29/0xb0 cpufreq_online+0x7e8/0xa40 cpufreq_add_dev+0x82/0xa0 subsys_interface_register+0x148/0x160 cpufreq_register_driver+0x15d/0x260 amd_pstate_register_driver+0x36/0x90 amd_pstate_init+0x1e7/0x270 do_one_initcall+0x68/0x2b0 kernel_init_freeable+0x231/0x270 kernel_init+0x15/0x130 ret_from_fork+0x2c/0x50 ret_from_fork_asm+0x11/0x20-> #1 (subsys mutex#3){+.+.}-{4:4}:
__mutex_lock+0xc2/0x930 subsys_interface_register+0x7f/0x160 cpufreq_register_driver+0x15d/0x260 amd_pstate_register_driver+0x36/0x90 amd_pstate_init+0x1e7/0x270 do_one_initcall+0x68/0x2b0 kernel_init_freeable+0x231/0x270 kernel_init+0x15/0x130 ret_from_fork+0x2c/0x50 ret_from_fork_asm+0x11/0x20-> #0 (cpu_hotplug_lock){++++}-{0:0}:
__lock_acquire+0x10ed/0x1850 lock_acquire.part.0+0x69/0x1b0 cpus_read_lock+0x2a/0xc0 store_local_boost+0x56/0xd0 store+0x50/0x90 kernfs_fop_write_iter+0x132/0x200 vfs_write+0x2b3/0x590 ksys_write+0x74/0xf0 do_syscall_64+0xbb/0x1d0 entry_SYSCALL_64_after_hwframe+0x56/0x5eSigned-off-by Seyediman Seyedarab <[email protected]>--- drivers/cpufreq/cpufreq.c | 3 --- 1 file changed, 3 deletions(-)drivers/cpufreq/cpufreq.c +0
-0@@ -622,10 +622,7 @@ static ssize_t store_local_boost(struct cpufreq_policy *policy,if (!policy->boost_supported)
drivers/cpufreq/cpufreq.c static ssize_t store_local_boost(struct cpufreq_policy *policy,
Quoted 10 lines
drivers/cpufreq/cpufreq.c +0
-4return -EINVAL ; -cpus_read_lock (); ret =policy_set_boost (policy, enable); -cpus_read_unlock (); -if (!ret)return count; --
Applied as 6.16 material, thanks!