Skip to content

Commit ee8d07c

Browse files
Yang Wangalexdeucher
authored andcommitted
drm/amd/pm: fix race in power state check before mutex lock
The power state check in amdgpu_dpm_set_powergating_by_smu() is done before acquiring the pm mutex, leading to a race condition where: 1. Thread A checks state and thinks no change is needed 2. Thread B acquires mutex and modifies the state 3. Thread A returns without updating state, causing inconsistency Fix this by moving the mutex lock before the power state check, ensuring atomicity of the state check and modification. Fixes: 6ee27ee ("drm/amd/pm: avoid duplicate powergate/ungate setting") Signed-off-by: Yang Wang <kevinyang.wang@amd.com> Reviewed-by: Kenneth Feng <kenneth.feng@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 7a3fbdf)
1 parent 8b1ecc9 commit ee8d07c

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev,
8080
enum ip_power_state pwr_state = gate ? POWER_STATE_OFF : POWER_STATE_ON;
8181
bool is_vcn = block_type == AMD_IP_BLOCK_TYPE_VCN;
8282

83+
mutex_lock(&adev->pm.mutex);
84+
8385
if (atomic_read(&adev->pm.pwr_state[block_type]) == pwr_state &&
8486
(!is_vcn || adev->vcn.num_vcn_inst == 1)) {
8587
dev_dbg(adev->dev, "IP block%d already in the target %s state!",
8688
block_type, gate ? "gate" : "ungate");
87-
return 0;
89+
goto out_unlock;
8890
}
8991

90-
mutex_lock(&adev->pm.mutex);
91-
9292
switch (block_type) {
9393
case AMD_IP_BLOCK_TYPE_UVD:
9494
case AMD_IP_BLOCK_TYPE_VCE:
@@ -115,6 +115,7 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev,
115115
if (!ret)
116116
atomic_set(&adev->pm.pwr_state[block_type], pwr_state);
117117

118+
out_unlock:
118119
mutex_unlock(&adev->pm.mutex);
119120

120121
return ret;

0 commit comments

Comments
 (0)