Skip to contentSkip to conversation

drm/amd/pm: fix the deadlock issue observed on SI

PATCH In review Evan Quan 3 participants 9 messages Apr 11, 2022 – Apr 22, 2022

Subsystems (3)
lore
Share & tools
lore

Evan Quan

author
#0 lore raw

PATCH v2 1/1 drm/amd/pm: fix the deadlock issue observed on SI

The adev->pm.mutx is already held at the beginning of amdgpu_dpm_compute_clocks/amdgpu_dpm_enable_uvd/amdgpu_dpm_enable_vce. But on their calling path, amdgpu_display_bandwidth_update will be called and thus its sub functions amdgpu_dpm_get_sclk/mclk. They will then try to acquire the same adev->pm.mutex and deadlock will occur.

By placing amdgpu_display_bandwidth_update outside of adev->pm.mutex protection(considering logically they do not need such protection) and restructuring the call flow accordingly, we can eliminate the deadlock issue. This comes with no real logics change.

Fixes 3712e7a49459 ("drm/amd/pm: unified lock protections in amdgpu_dpm.c")
Link https: //lore.kernel.org/all/[email protected]/
BugLink https: //gitlab.freedesktop.org/drm/amd/-/issues/1957

--
v1->v2:
- rich the commit messages(Paul)

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 39 +++++++++++++++++++
 .../gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c    | 10 -----
 drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    | 35 -----------------
 .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  | 10 -----
 4 files changed, 39 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +39 -0
index 5504d81c77b7..72e7b5d40af6 100644
@@ -427,6 +427,7 @@ int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors senso
 void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev)
 {
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int i;
 
 	if (!adev->pm.dpm_enabled)
 		return;
@@ -434,6 +435,15 @@ void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev)
 	if (!pp_funcs->pm_compute_clocks)
 		return;
 
+	if (adev->mode_info.num_crtc)
+		amdgpu_display_bandwidth_update(adev);
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
+		struct amdgpu_ring *ring = adev->rings[i];
+		if (ring && ring->sched.ready)
+			amdgpu_fence_wait_empty(ring);
+	}
+
 	mutex_lock(&adev->pm.mutex);
 	pp_funcs->pm_compute_clocks(adev->powerplay.pp_handle);
 	mutex_unlock(&adev->pm.mutex);
@@ -443,6 +453,20 @@ void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)
 {
 	int ret = 0;
 
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.uvd_active = true;
+			adev->pm.dpm.state = POWER_STATE_TYPE_INTERNAL_UVD;
+		} else {
+			adev->pm.dpm.uvd_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
 	ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_UVD, !enable);
 	if (ret)
 		DRM_ERROR("Dpm %s uvd failed, ret = %d. \n",
@@ -453,6 +477,21 @@ void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)
 {
 	int ret = 0;
 
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.vce_active = true;
+			/* XXX select vce level based on ring/task */
+			adev->pm.dpm.vce_level = AMD_VCE_LEVEL_AC_ALL;
+		} else {
+			adev->pm.dpm.vce_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
 	ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_VCE, !enable);
 	if (ret)
 		DRM_ERROR("Dpm %s vce failed, ret = %d. \n",
drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -10
index 9613c6181c17..d3fe149d8476 100644
@@ -1028,16 +1028,6 @@ static int amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)
 void amdgpu_legacy_dpm_compute_clocks(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
 	amdgpu_dpm_get_active_displays(adev);
 
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -35
index caae54487f9c..633dab14f51c 100644
@@ -3892,40 +3892,6 @@ static int si_set_boot_state(struct amdgpu_device *adev)
 }
 #endif
 
-static int si_set_powergating_by_smu(void *handle,
-				     uint32_t block_type,
-				     bool gate)
-{
-	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
-	switch (block_type) {
-	case AMD_IP_BLOCK_TYPE_UVD:
-		if (!gate) {
-			adev->pm.dpm.uvd_active = true;
-			adev->pm.dpm.state = POWER_STATE_TYPE_INTERNAL_UVD;
-		} else {
-			adev->pm.dpm.uvd_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);
-		break;
-	case AMD_IP_BLOCK_TYPE_VCE:
-		if (!gate) {
-			adev->pm.dpm.vce_active = true;
-			/* XXX select vce level based on ring/task */
-			adev->pm.dpm.vce_level = AMD_VCE_LEVEL_AC_ALL;
-		} else {
-			adev->pm.dpm.vce_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);
-		break;
-	default:
-		break;
-	}
-	return 0;
-}
-
 static int si_set_sw_state(struct amdgpu_device *adev)
 {
 	return (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_SwitchToSwState) == PPSMC_Result_OK) ?
@@ -8125,7 +8091,6 @@ static const struct amd_pm_funcs si_dpm_funcs = {
 	.print_power_state = &si_dpm_print_power_state,
 	.debugfs_print_current_performance_level = &si_dpm_debugfs_print_current_performance_level,
 	.force_performance_level = &si_dpm_force_performance_level,
-	.set_powergating_by_smu = &si_set_powergating_by_smu,
 	.vblank_too_short = &si_dpm_vblank_too_short,
 	.set_fan_control_mode = &si_dpm_set_fan_control_mode,
 	.get_fan_control_mode = &si_dpm_get_fan_control_mode,
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -10
index dbed72c1e0c6..1eb4e613b27a 100644
@@ -1503,16 +1503,6 @@ static void pp_pm_compute_clocks(void *handle)
 {
 	struct pp_hwmgr *hwmgr = handle;
 	struct amdgpu_device *adev = hwmgr->adev;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
 	if (!amdgpu_device_has_dc_support(adev)) {
 		amdgpu_dpm_get_active_displays(adev);
Signature · 1 line
2.29.0
#1 lore raw
Quoted 7 lines · Evan Quan

The adev->pm.mutx is already held at the beginning of amdgpu_dpm_compute_clocks/amdgpu_dpm_enable_uvd/amdgpu_dpm_enable_vce. But on their calling path, amdgpu_display_bandwidth_update will be called and thus its sub functions amdgpu_dpm_get_sclk/mclk. They will then try to acquire the same adev->pm.mutex and deadlock will occur.

What about using locked versions of get_sclk/mclk and leave the rest as they are?

Thanks,
Lijo

Quoted 188 lines

By placing amdgpu_display_bandwidth_update outside of adev->pm.mutex protection(considering logically they do not need such protection) and restructuring the call flow accordingly, we can eliminate the deadlock issue. This comes with no real logics change.

Fixes 3712e7a49459 ("drm/amd/pm: unified lock protections in amdgpu_dpm.c")
Link https: //lore.kernel.org/all/[email protected]/
BugLink https: //gitlab.freedesktop.org/drm/amd/-/issues/1957

--
v1->v2:
- rich the commit messages(Paul)

---
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 39 +++++++++++++++++++
  .../gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c    | 10 -----
  drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    | 35 -----------------
  .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  | 10 -----
  4 files changed, 39 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +39 -0
index 5504d81c77b7..72e7b5d40af6 100644
@@ -427,6 +427,7 @@ int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors senso
  void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev)
  {
  	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int i;
 
  	if (!adev->pm.dpm_enabled)
  		return;
@@ -434,6 +435,15 @@ void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev)
  	if (!pp_funcs->pm_compute_clocks)
  		return;
 
+	if (adev->mode_info.num_crtc)
+		amdgpu_display_bandwidth_update(adev);
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
+		struct amdgpu_ring *ring = adev->rings[i];
+		if (ring && ring->sched.ready)
+			amdgpu_fence_wait_empty(ring);
+	}
+
  	mutex_lock(&adev->pm.mutex);
  	pp_funcs->pm_compute_clocks(adev->powerplay.pp_handle);
  	mutex_unlock(&adev->pm.mutex);
@@ -443,6 +453,20 @@ void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)
  {
  	int ret = 0;
 
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.uvd_active = true;
+			adev->pm.dpm.state = POWER_STATE_TYPE_INTERNAL_UVD;
+		} else {
+			adev->pm.dpm.uvd_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
  	ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_UVD, !enable);
  	if (ret)
  		DRM_ERROR("Dpm %s uvd failed, ret = %d. \n",
@@ -453,6 +477,21 @@ void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)
  {
  	int ret = 0;
 
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.vce_active = true;
+			/* XXX select vce level based on ring/task */
+			adev->pm.dpm.vce_level = AMD_VCE_LEVEL_AC_ALL;
+		} else {
+			adev->pm.dpm.vce_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
  	ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_VCE, !enable);
  	if (ret)
  		DRM_ERROR("Dpm %s vce failed, ret = %d. \n",
drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -10
index 9613c6181c17..d3fe149d8476 100644
@@ -1028,16 +1028,6 @@ static int amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)
  void amdgpu_legacy_dpm_compute_clocks(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
  	amdgpu_dpm_get_active_displays(adev);
 
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -35
index caae54487f9c..633dab14f51c 100644
@@ -3892,40 +3892,6 @@ static int si_set_boot_state(struct amdgpu_device *adev)
  }
  #endif
 
-static int si_set_powergating_by_smu(void *handle,
-				     uint32_t block_type,
-				     bool gate)
-{
-	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
-	switch (block_type) {
-	case AMD_IP_BLOCK_TYPE_UVD:
-		if (!gate) {
-			adev->pm.dpm.uvd_active = true;
-			adev->pm.dpm.state = POWER_STATE_TYPE_INTERNAL_UVD;
-		} else {
-			adev->pm.dpm.uvd_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);
-		break;
-	case AMD_IP_BLOCK_TYPE_VCE:
-		if (!gate) {
-			adev->pm.dpm.vce_active = true;
-			/* XXX select vce level based on ring/task */
-			adev->pm.dpm.vce_level = AMD_VCE_LEVEL_AC_ALL;
-		} else {
-			adev->pm.dpm.vce_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);
-		break;
-	default:
-		break;
-	}
-	return 0;
-}
-
  static int si_set_sw_state(struct amdgpu_device *adev)
  {
  	return (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_SwitchToSwState) == PPSMC_Result_OK) ?
@@ -8125,7 +8091,6 @@ static const struct amd_pm_funcs si_dpm_funcs = {
  	.print_power_state = &si_dpm_print_power_state,
  	.debugfs_print_current_performance_level = &si_dpm_debugfs_print_current_performance_level,
  	.force_performance_level = &si_dpm_force_performance_level,
-	.set_powergating_by_smu = &si_set_powergating_by_smu,
  	.vblank_too_short = &si_dpm_vblank_too_short,
  	.set_fan_control_mode = &si_dpm_set_fan_control_mode,
  	.get_fan_control_mode = &si_dpm_get_fan_control_mode,
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -10
index dbed72c1e0c6..1eb4e613b27a 100644
@@ -1503,16 +1503,6 @@ static void pp_pm_compute_clocks(void *handle)
  {
  	struct pp_hwmgr *hwmgr = handle;
  	struct amdgpu_device *adev = hwmgr->adev;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
  	if (!amdgpu_device_has_dc_support(adev)) {
  		amdgpu_dpm_get_active_displays(adev);
author
#2 lore raw

[AMD Official Use Only]

Quoted 15 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, April 11, 2022 6:06 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V2] drm/amd/pm: fix the deadlock issue observed on SI

Quoted 2 lines · Evan Quan

The adev->pm.mutx is already held at the beginning of

amdgpu_dpm_compute_clocks/amdgpu_dpm_enable_uvd/amdgpu_dpm_ enable_vce.

Quoted 7 lines
Quoted 4 lines

But on their calling path, amdgpu_display_bandwidth_update will be called and thus its sub functions amdgpu_dpm_get_sclk/mclk. They will then try to acquire the same adev->pm.mutex and deadlock will occur.

What about using locked versions of get_sclk/mclk and leave the rest as they are?

[Quan, Evan] Yeah, that(adding two new APIs for locked versions of get_sclk/mclk) should also work. But considering there cannot be other ASICs who need them, they are kind of redundant. Meanwhile my version is just to get everything reverted back to its original. So, it should be quite safe. How do you think?

BR
Evan

Quoted 218 lines

Thanks,
Lijo

Quoted 13 lines

By placing amdgpu_display_bandwidth_update outside of adev- pm.mutex
protection(considering logically they do not need such protection) and restructuring the call flow accordingly, we can eliminate the deadlock issue. This comes with no real logics change.

Fixes 3712e7a49459 ("drm/amd/pm: unified lock protections in

amdgpu_dpm.c")

//lore.kernel.org/all/[email protected]. de/

Quoted 7 lines
BugLink https: //gitlab.freedesktop.org/drm/amd/-/issues/1957

--
v1->v2:
- rich the commit messages(Paul)

---
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 39

+++++++++++++++++++

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_read_sensor(struct

Quoted 11 lines
  .../gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c    | 10 -----
  drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    | 35 -----------------
  .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  | 10 -----
  4 files changed, 39 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 5504d81c77b7..72e7b5d40af6 100644
@@ -427,6 +427,7 @@ int amdgpu_dpm_read_sensor(struct

amdgpu_device *adev, enum amd_pp_sensors senso

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_compute_clocks(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
  void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev)
  {
  	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int i;
 
  	if (!adev->pm.dpm_enabled)
  		return;
@@ -434,6 +435,15 @@ void amdgpu_dpm_compute_clocks(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct

Quoted 16 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
  	if (!pp_funcs->pm_compute_clocks)
  		return;
 
+	if (adev->mode_info.num_crtc)
+		amdgpu_display_bandwidth_update(adev);
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
+		struct amdgpu_ring *ring = adev->rings[i];
+		if (ring && ring->sched.ready)
+			amdgpu_fence_wait_empty(ring);
+	}
+
  	mutex_lock(&adev->pm.mutex);
  	pp_funcs->pm_compute_clocks(adev->powerplay.pp_handle);
  	mutex_unlock(&adev->pm.mutex);
@@ -443,6 +453,20 @@ void amdgpu_dpm_enable_uvd(struct

amdgpu_device *adev, bool enable)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
  {
  	int ret = 0;
 
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.uvd_active = true;
+			adev->pm.dpm.state =

POWER_STATE_TYPE_INTERNAL_UVD;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+		} else {
+			adev->pm.dpm.uvd_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
  	ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_UVD, !enable);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct · line 472

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
  	if (ret)
  		DRM_ERROR("Dpm %s uvd failed, ret = %d. \n", @@ -453,6

+477,21 @@

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 10 lines

void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)
{
int ret = 0;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.vce_active = true;
+			/* XXX select vce level based on ring/task */
+			adev->pm.dpm.vce_level =

AMD_VCE_LEVEL_AC_ALL;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+		} else {
+			adev->pm.dpm.vce_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
  	ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_VCE, !enable);

drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c static int

Quoted 8 lines

if (ret)
DRM_ERROR("Dpm %s vce failed, ret = %d. \n", diff --git
a/drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c b/drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c
index 9613c6181c17..d3fe149d8476 100644

drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -0
@@ -1028,16 +1028,6 @@ static int

amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct

Quoted 22 lines
drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -10
  void amdgpu_legacy_dpm_compute_clocks(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
  	amdgpu_dpm_get_active_displays(adev);
 
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
index caae54487f9c..633dab14f51c 100644
@@ -3892,40 +3892,6 @@ static int si_set_boot_state(struct

amdgpu_device *adev)

Quoted 4 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -1
  }
  #endif
 
-static int si_set_powergating_by_smu(void *handle,

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -10
-				     uint32_t block_type,
-				     bool gate)
-{
-	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
-	switch (block_type) {
-	case AMD_IP_BLOCK_TYPE_UVD:
-		if (!gate) {
-			adev->pm.dpm.uvd_active = true;
-			adev->pm.dpm.state =

POWER_STATE_TYPE_INTERNAL_UVD;

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 11 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -11
-		} else {
-			adev->pm.dpm.uvd_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);
-		break;
-	case AMD_IP_BLOCK_TYPE_VCE:
-		if (!gate) {
-			adev->pm.dpm.vce_active = true;
-			/* XXX select vce level based on ring/task */
-			adev->pm.dpm.vce_level =

AMD_VCE_LEVEL_AC_ALL;

Quoted 5 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -5
-		} else {
-			adev->pm.dpm.vce_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -7
-		break;
-	default:
-		break;
-	}
-	return 0;
-}
-
  static int si_set_sw_state(struct amdgpu_device *adev)
  {
  	return (amdgpu_si_send_msg_to_smc(adev,

PPSMC_MSG_SwitchToSwState) == PPSMC_Result_OK) ?

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs si_dpm_funcs

Quoted 1 line
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
@@ -8125,7 +8091,6 @@ static const struct amd_pm_funcs si_dpm_funcs

= {

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs si_dpm_funcs · line 8092

Quoted 2 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
  	.print_power_state = &si_dpm_print_power_state,
  	.debugfs_print_current_performance_level =

&si_dpm_debugfs_print_current_performance_level,

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs si_dpm_funcs = {

Quoted 5 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -1
  	.force_performance_level = &si_dpm_force_performance_level,
-	.set_powergating_by_smu = &si_set_powergating_by_smu,
  	.vblank_too_short = &si_dpm_vblank_too_short,
  	.set_fan_control_mode = &si_dpm_set_fan_control_mode,
  	.get_fan_control_mode = &si_dpm_get_fan_control_mode, diff --

git

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static void pp_pm_compute_clocks(void

Quoted 6 lines

a/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c index dbed72c1e0c6..1eb4e613b27a 100644

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
@@ -1503,16 +1503,6 @@ static void pp_pm_compute_clocks(void

*handle)

Quoted 17 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -10
  {
  	struct pp_hwmgr *hwmgr = handle;
  	struct amdgpu_device *adev = hwmgr->adev;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
  	if (!amdgpu_device_has_dc_support(adev)) {
  		amdgpu_dpm_get_active_displays(adev);
#3 lore raw
Quoted 24 lines · Evan

[AMD Official Use Only]

Quoted 20 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, April 11, 2022 6:06 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V2] drm/amd/pm: fix the deadlock issue observed on SI

Quoted 2 lines · Evan Quan

The adev->pm.mutx is already held at the beginning of

amdgpu_dpm_compute_clocks/amdgpu_dpm_enable_uvd/amdgpu_dpm_ enable_vce.

Quoted 4 lines

But on their calling path, amdgpu_display_bandwidth_update will be called and thus its sub functions amdgpu_dpm_get_sclk/mclk. They will then try to acquire the same adev->pm.mutex and deadlock will occur.

Quoted 5 lines
Quoted 2 lines

What about using locked versions of get_sclk/mclk and leave the rest as they are?

[Quan, Evan] Yeah, that(adding two new APIs for locked versions of get_sclk/mclk) should also work. But considering there cannot be other ASICs who need them, they are kind of redundant. Meanwhile my version is just to get everything reverted back to its original. So, it should be quite safe. How do you think?

As far as I see -

1) It moves display watermark updates outside of locking
2) It adds bandwidth update under common compute_clocks paths.

I guess it is not the same as pre-mutex change.

Thanks,
Lijo

Quoted 220 lines

BR
Evan

Quoted 218 lines

Thanks,
Lijo

Quoted 13 lines

By placing amdgpu_display_bandwidth_update outside of adev- pm.mutex
protection(considering logically they do not need such protection) and restructuring the call flow accordingly, we can eliminate the deadlock issue. This comes with no real logics change.

Fixes 3712e7a49459 ("drm/amd/pm: unified lock protections in

amdgpu_dpm.c")

//lore.kernel.org/all/[email protected]. de/

Quoted 7 lines
BugLink https: //gitlab.freedesktop.org/drm/amd/-/issues/1957

--
v1->v2:
- rich the commit messages(Paul)

---
   drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 39

+++++++++++++++++++

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_read_sensor(struct

Quoted 11 lines
   .../gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c    | 10 -----
   drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    | 35 -----------------
   .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  | 10 -----
   4 files changed, 39 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 5504d81c77b7..72e7b5d40af6 100644
@@ -427,6 +427,7 @@ int amdgpu_dpm_read_sensor(struct

amdgpu_device *adev, enum amd_pp_sensors senso

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_compute_clocks(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
   void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev)
   {
   	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int i;
 
   	if (!adev->pm.dpm_enabled)
   		return;
@@ -434,6 +435,15 @@ void amdgpu_dpm_compute_clocks(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct

Quoted 16 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
   	if (!pp_funcs->pm_compute_clocks)
   		return;
 
+	if (adev->mode_info.num_crtc)
+		amdgpu_display_bandwidth_update(adev);
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
+		struct amdgpu_ring *ring = adev->rings[i];
+		if (ring && ring->sched.ready)
+			amdgpu_fence_wait_empty(ring);
+	}
+
   	mutex_lock(&adev->pm.mutex);
   	pp_funcs->pm_compute_clocks(adev->powerplay.pp_handle);
   	mutex_unlock(&adev->pm.mutex);
@@ -443,6 +453,20 @@ void amdgpu_dpm_enable_uvd(struct

amdgpu_device *adev, bool enable)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
   {
   	int ret = 0;
 
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.uvd_active = true;
+			adev->pm.dpm.state =

POWER_STATE_TYPE_INTERNAL_UVD;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+		} else {
+			adev->pm.dpm.uvd_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
   	ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_UVD, !enable);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct · line 472

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
   	if (ret)
   		DRM_ERROR("Dpm %s uvd failed, ret = %d. \n", @@ -453,6

+477,21 @@

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 10 lines

void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

   {
   	int ret = 0;
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.vce_active = true;
+			/* XXX select vce level based on ring/task */
+			adev->pm.dpm.vce_level =

AMD_VCE_LEVEL_AC_ALL;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+		} else {
+			adev->pm.dpm.vce_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
   	ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_VCE, !enable);

drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c static int

Quoted 8 lines
   	if (ret)
   		DRM_ERROR("Dpm %s vce failed, ret = %d. \n", diff --git

a/drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c
b/drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c
index 9613c6181c17..d3fe149d8476 100644

drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -0
@@ -1028,16 +1028,6 @@ static int

amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct

Quoted 22 lines
drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -10
   void amdgpu_legacy_dpm_compute_clocks(void *handle)
   {
   	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
   	amdgpu_dpm_get_active_displays(adev);
 
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
index caae54487f9c..633dab14f51c 100644
@@ -3892,40 +3892,6 @@ static int si_set_boot_state(struct

amdgpu_device *adev)

Quoted 4 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -1
   }
   #endif
 
-static int si_set_powergating_by_smu(void *handle,

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -10
-				     uint32_t block_type,
-				     bool gate)
-{
-	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
-	switch (block_type) {
-	case AMD_IP_BLOCK_TYPE_UVD:
-		if (!gate) {
-			adev->pm.dpm.uvd_active = true;
-			adev->pm.dpm.state =

POWER_STATE_TYPE_INTERNAL_UVD;

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 11 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -11
-		} else {
-			adev->pm.dpm.uvd_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);
-		break;
-	case AMD_IP_BLOCK_TYPE_VCE:
-		if (!gate) {
-			adev->pm.dpm.vce_active = true;
-			/* XXX select vce level based on ring/task */
-			adev->pm.dpm.vce_level =

AMD_VCE_LEVEL_AC_ALL;

Quoted 5 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -5
-		} else {
-			adev->pm.dpm.vce_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -7
-		break;
-	default:
-		break;
-	}
-	return 0;
-}
-
   static int si_set_sw_state(struct amdgpu_device *adev)
   {
   	return (amdgpu_si_send_msg_to_smc(adev,

PPSMC_MSG_SwitchToSwState) == PPSMC_Result_OK) ?

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs si_dpm_funcs

Quoted 1 line
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
@@ -8125,7 +8091,6 @@ static const struct amd_pm_funcs si_dpm_funcs

= {

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs si_dpm_funcs · line 8092

Quoted 2 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
   	.print_power_state = &si_dpm_print_power_state,
   	.debugfs_print_current_performance_level =

&si_dpm_debugfs_print_current_performance_level,

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs si_dpm_funcs = {

Quoted 5 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -1
   	.force_performance_level = &si_dpm_force_performance_level,
-	.set_powergating_by_smu = &si_set_powergating_by_smu,
   	.vblank_too_short = &si_dpm_vblank_too_short,
   	.set_fan_control_mode = &si_dpm_set_fan_control_mode,
   	.get_fan_control_mode = &si_dpm_get_fan_control_mode, diff --

git

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static void pp_pm_compute_clocks(void

Quoted 6 lines

a/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c index dbed72c1e0c6..1eb4e613b27a 100644

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
@@ -1503,16 +1503,6 @@ static void pp_pm_compute_clocks(void

*handle)

Quoted 17 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -10
   {
   	struct pp_hwmgr *hwmgr = handle;
   	struct amdgpu_device *adev = hwmgr->adev;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
   	if (!amdgpu_device_has_dc_support(adev)) {
   		amdgpu_dpm_get_active_displays(adev);
author
#4 lore raw

[AMD Official Use Only]

Quoted 43 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, April 22, 2022 4:36 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V2] drm/amd/pm: fix the deadlock issue observed on SI

Quoted 19 lines · Evan

[AMD Official Use Only]

Quoted 15 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, April 11, 2022 6:06 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V2] drm/amd/pm: fix the deadlock issue observed on SI

Quoted 2 lines · Evan Quan

The adev->pm.mutx is already held at the beginning of

amdgpu_dpm_compute_clocks/amdgpu_dpm_enable_uvd/amdgpu_dpm_

Quoted 4 lines
Quoted 4 lines

enable_vce.

Quoted 3 lines

But on their calling path, amdgpu_display_bandwidth_update will be called and thus its sub functions amdgpu_dpm_get_sclk/mclk. They will then try to acquire the same adev->pm.mutex and deadlock will

occur.

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

What about using locked versions of get_sclk/mclk and leave the rest as they are?

[Quan, Evan] Yeah, that(adding two new APIs for locked versions of

get_sclk/mclk) should also work. But considering there cannot be other ASICs who need them, they are kind of redundant.

Quoted 8 lines
Quoted 1 line

Meanwhile my version is just to get everything reverted back to its original.

So, it should be quite safe. How do you think?

Quoted 1 line

As far as I see -

1) It moves display watermark updates outside of locking
2) It adds bandwidth update under common compute_clocks paths.

[Quan, Evan] I suppose what you mentioned is about "amdgpu_display_bandwidth_update".
No, I just double confirmed(the old code in our amd-staging-dkms-5.9/5.10 branch) and it did come with no lock protection. For those legacy ASICs, the watermark setting was performed by programming registers directly(handled at display side). That might explain why it did not have lock protection as recent ASICs.

BR
Evan

Quoted 230 lines

I guess it is not the same as pre-mutex change.

Thanks,
Lijo

Quoted 7 lines

BR
Evan

Quoted 5 lines

Thanks,
Lijo

Quoted 1 line

By placing amdgpu_display_bandwidth_update outside of adev-

pm.mutex

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

protection(considering logically they do not need such protection) and restructuring the call flow accordingly, we can eliminate the deadlock issue. This comes with no real logics change.

Fixes 3712e7a49459 ("drm/amd/pm: unified lock protections in

amdgpu_dpm.c")

//lore.kernel.org/all/9e689fea-6c69-f4b0-8dee-

[email protected].

Quoted 67 lines
Quoted 67 lines
Quoted 8 lines

de/

BugLink https: //gitlab.freedesktop.org/drm/amd/-/issues/1957

--
v1->v2:
- rich the commit messages(Paul)

---
   drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 39

+++++++++++++++++++

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_read_sensor(struct

Quoted 11 lines
   .../gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c    | 10 -----
   drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    | 35 -----------------
   .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  | 10 -----
   4 files changed, 39 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 5504d81c77b7..72e7b5d40af6 100644
@@ -427,6 +427,7 @@ int amdgpu_dpm_read_sensor(struct

amdgpu_device *adev, enum amd_pp_sensors senso

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_compute_clocks(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
   void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev)
   {
   	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int i;
 
   	if (!adev->pm.dpm_enabled)
   		return;
@@ -434,6 +435,15 @@ void amdgpu_dpm_compute_clocks(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct

Quoted 16 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
   	if (!pp_funcs->pm_compute_clocks)
   		return;
 
+	if (adev->mode_info.num_crtc)
+		amdgpu_display_bandwidth_update(adev);
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
+		struct amdgpu_ring *ring = adev->rings[i];
+		if (ring && ring->sched.ready)
+			amdgpu_fence_wait_empty(ring);
+	}
+
   	mutex_lock(&adev->pm.mutex);
   	pp_funcs->pm_compute_clocks(adev->powerplay.pp_handle);
   	mutex_unlock(&adev->pm.mutex);
@@ -443,6 +453,20 @@ void amdgpu_dpm_enable_uvd(struct

amdgpu_device *adev, bool enable)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
   {
   	int ret = 0;
 
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.uvd_active = true;
+			adev->pm.dpm.state =

POWER_STATE_TYPE_INTERNAL_UVD;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+		} else {
+			adev->pm.dpm.uvd_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
   	ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_UVD, !enable);

Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct · line 472

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
   	if (ret)
   		DRM_ERROR("Dpm %s uvd failed, ret = %d. \n", @@ -453,6

+477,21 @@

Quoted 1 line

void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool

enable)

Quoted 21 lines
Quoted 21 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 9 lines
   {
   	int ret = 0;
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.vce_active = true;
+			/* XXX select vce level based on ring/task */
+			adev->pm.dpm.vce_level =

AMD_VCE_LEVEL_AC_ALL;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+		} else {
+			adev->pm.dpm.vce_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
   	ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_VCE, !enable);

Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c static int

Quoted 8 lines
   	if (ret)
   		DRM_ERROR("Dpm %s vce failed, ret = %d. \n", diff --git

a/drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c
b/drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c
index 9613c6181c17..d3fe149d8476 100644

drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -0
@@ -1028,16 +1028,6 @@ static int

amdgpu_dpm_change_power_state_locked(struct amdgpu_device

*adev)

Quoted 66 lines
Quoted 66 lines

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct

Quoted 22 lines
drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -10
   void amdgpu_legacy_dpm_compute_clocks(void *handle)
   {
   	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
   	amdgpu_dpm_get_active_displays(adev);
 
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
index caae54487f9c..633dab14f51c 100644
@@ -3892,40 +3892,6 @@ static int si_set_boot_state(struct

amdgpu_device *adev)

Quoted 4 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -1
   }
   #endif
 
-static int si_set_powergating_by_smu(void *handle,

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -10
-				     uint32_t block_type,
-				     bool gate)
-{
-	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
-	switch (block_type) {
-	case AMD_IP_BLOCK_TYPE_UVD:
-		if (!gate) {
-			adev->pm.dpm.uvd_active = true;
-			adev->pm.dpm.state =

POWER_STATE_TYPE_INTERNAL_UVD;

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 11 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -11
-		} else {
-			adev->pm.dpm.uvd_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);
-		break;
-	case AMD_IP_BLOCK_TYPE_VCE:
-		if (!gate) {
-			adev->pm.dpm.vce_active = true;
-			/* XXX select vce level based on ring/task */
-			adev->pm.dpm.vce_level =

AMD_VCE_LEVEL_AC_ALL;

Quoted 5 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -5
-		} else {
-			adev->pm.dpm.vce_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -7
-		break;
-	default:
-		break;
-	}
-	return 0;
-}
-
   static int si_set_sw_state(struct amdgpu_device *adev)
   {
   	return (amdgpu_si_send_msg_to_smc(adev,

PPSMC_MSG_SwitchToSwState) == PPSMC_Result_OK) ?

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs

Quoted 1 line
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
@@ -8125,7 +8091,6 @@ static const struct amd_pm_funcs

si_dpm_funcs

Quoted 34 lines
Quoted 34 lines

= {

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs · line 8092

Quoted 2 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
   	.print_power_state = &si_dpm_print_power_state,
   	.debugfs_print_current_performance_level =

&si_dpm_debugfs_print_current_performance_level,

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs si_dpm_funcs = {

Quoted 5 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -1
   	.force_performance_level = &si_dpm_force_performance_level,
-	.set_powergating_by_smu = &si_set_powergating_by_smu,
   	.vblank_too_short = &si_dpm_vblank_too_short,
   	.set_fan_control_mode = &si_dpm_set_fan_control_mode,
   	.get_fan_control_mode = &si_dpm_get_fan_control_mode, diff --

git

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static void pp_pm_compute_clocks(void

Quoted 6 lines

a/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c index dbed72c1e0c6..1eb4e613b27a 100644

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
@@ -1503,16 +1503,6 @@ static void pp_pm_compute_clocks(void

*handle)

Quoted 17 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -10
   {
   	struct pp_hwmgr *hwmgr = handle;
   	struct amdgpu_device *adev = hwmgr->adev;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
   	if (!amdgpu_device_has_dc_support(adev)) {
   		amdgpu_dpm_get_active_displays(adev);
Reviewed-by
#5 lore raw
Quoted 51 lines · Evan

[AMD Official Use Only]

Quoted 47 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, April 22, 2022 4:36 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V2] drm/amd/pm: fix the deadlock issue observed on SI

Quoted 19 lines · Evan

[AMD Official Use Only]

Quoted 15 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, April 11, 2022 6:06 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V2] drm/amd/pm: fix the deadlock issue observed on SI

Quoted 2 lines · Evan Quan

The adev->pm.mutx is already held at the beginning of

amdgpu_dpm_compute_clocks/amdgpu_dpm_enable_uvd/amdgpu_dpm_

Quoted 4 lines
Quoted 4 lines

enable_vce.

Quoted 3 lines

But on their calling path, amdgpu_display_bandwidth_update will be called and thus its sub functions amdgpu_dpm_get_sclk/mclk. They will then try to acquire the same adev->pm.mutex and deadlock will

occur.

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

What about using locked versions of get_sclk/mclk and leave the rest as they are?

[Quan, Evan] Yeah, that(adding two new APIs for locked versions of

get_sclk/mclk) should also work. But considering there cannot be other ASICs who need them, they are kind of redundant.

Quoted 1 line

Meanwhile my version is just to get everything reverted back to its original.

So, it should be quite safe. How do you think?

Quoted 1 line
Quoted 9 lines
Quoted 4 lines

As far as I see -

1) It moves display watermark updates outside of locking
2) It adds bandwidth update under common compute_clocks paths.

[Quan, Evan] I suppose what you mentioned is about "amdgpu_display_bandwidth_update".
No, I just double confirmed(the old code in our amd-staging-dkms-5.9/5.10 branch) and it did come with no lock protection. For those legacy ASICs, the watermark setting was performed by programming registers directly(handled at display side). That might explain why it did not have lock protection as recent ASICs.

Yes, I was referring to amdgpu_display_bandwidth_update. You are right, I see it getting called outside of pm mutex at least. Also it is called commonly in amdgpu_pm_compute_clocks.

Let's proceed it this way for now.

Thanks,
Lijo

Quoted 232 lines

BR
Evan

Quoted 230 lines

I guess it is not the same as pre-mutex change.

Thanks,
Lijo

Quoted 7 lines

BR
Evan

Quoted 5 lines

Thanks,
Lijo

Quoted 1 line

By placing amdgpu_display_bandwidth_update outside of adev-

pm.mutex

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

protection(considering logically they do not need such protection) and restructuring the call flow accordingly, we can eliminate the deadlock issue. This comes with no real logics change.

Fixes 3712e7a49459 ("drm/amd/pm: unified lock protections in

amdgpu_dpm.c")

//lore.kernel.org/all/9e689fea-6c69-f4b0-8dee-

[email protected].

Quoted 67 lines
Quoted 67 lines
Quoted 8 lines

de/

BugLink https: //gitlab.freedesktop.org/drm/amd/-/issues/1957

--
v1->v2:
- rich the commit messages(Paul)

---
    drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 39

+++++++++++++++++++

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_read_sensor(struct

Quoted 11 lines
    .../gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c    | 10 -----
    drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    | 35 -----------------
    .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  | 10 -----
    4 files changed, 39 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 5504d81c77b7..72e7b5d40af6 100644
@@ -427,6 +427,7 @@ int amdgpu_dpm_read_sensor(struct

amdgpu_device *adev, enum amd_pp_sensors senso

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_compute_clocks(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
    void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev)
    {
    	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int i;
 
    	if (!adev->pm.dpm_enabled)
    		return;
@@ -434,6 +435,15 @@ void amdgpu_dpm_compute_clocks(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct

Quoted 16 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
    	if (!pp_funcs->pm_compute_clocks)
    		return;
 
+	if (adev->mode_info.num_crtc)
+		amdgpu_display_bandwidth_update(adev);
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
+		struct amdgpu_ring *ring = adev->rings[i];
+		if (ring && ring->sched.ready)
+			amdgpu_fence_wait_empty(ring);
+	}
+
    	mutex_lock(&adev->pm.mutex);
    	pp_funcs->pm_compute_clocks(adev->powerplay.pp_handle);
    	mutex_unlock(&adev->pm.mutex);
@@ -443,6 +453,20 @@ void amdgpu_dpm_enable_uvd(struct

amdgpu_device *adev, bool enable)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
    {
    	int ret = 0;
 
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.uvd_active = true;
+			adev->pm.dpm.state =

POWER_STATE_TYPE_INTERNAL_UVD;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+		} else {
+			adev->pm.dpm.uvd_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
    	ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_UVD, !enable);

Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct · line 472

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
    	if (ret)
    		DRM_ERROR("Dpm %s uvd failed, ret = %d. \n", @@ -453,6

+477,21 @@

Quoted 1 line

void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool

enable)

Quoted 21 lines
Quoted 21 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 9 lines
    {
    	int ret = 0;
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.vce_active = true;
+			/* XXX select vce level based on ring/task */
+			adev->pm.dpm.vce_level =

AMD_VCE_LEVEL_AC_ALL;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+		} else {
+			adev->pm.dpm.vce_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
    	ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_VCE, !enable);

Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c static int

Quoted 8 lines
    	if (ret)
    		DRM_ERROR("Dpm %s vce failed, ret = %d. \n", diff --git

a/drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c
b/drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c
index 9613c6181c17..d3fe149d8476 100644

drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -0
@@ -1028,16 +1028,6 @@ static int

amdgpu_dpm_change_power_state_locked(struct amdgpu_device

*adev)

Quoted 66 lines
Quoted 66 lines

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct

Quoted 22 lines
drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -10
    void amdgpu_legacy_dpm_compute_clocks(void *handle)
    {
    	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
    	amdgpu_dpm_get_active_displays(adev);
 
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
index caae54487f9c..633dab14f51c 100644
@@ -3892,40 +3892,6 @@ static int si_set_boot_state(struct

amdgpu_device *adev)

Quoted 4 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -1
    }
    #endif
 
-static int si_set_powergating_by_smu(void *handle,

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -10
-				     uint32_t block_type,
-				     bool gate)
-{
-	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
-	switch (block_type) {
-	case AMD_IP_BLOCK_TYPE_UVD:
-		if (!gate) {
-			adev->pm.dpm.uvd_active = true;
-			adev->pm.dpm.state =

POWER_STATE_TYPE_INTERNAL_UVD;

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 11 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -11
-		} else {
-			adev->pm.dpm.uvd_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);
-		break;
-	case AMD_IP_BLOCK_TYPE_VCE:
-		if (!gate) {
-			adev->pm.dpm.vce_active = true;
-			/* XXX select vce level based on ring/task */
-			adev->pm.dpm.vce_level =

AMD_VCE_LEVEL_AC_ALL;

Quoted 5 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -5
-		} else {
-			adev->pm.dpm.vce_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -7
-		break;
-	default:
-		break;
-	}
-	return 0;
-}
-
    static int si_set_sw_state(struct amdgpu_device *adev)
    {
    	return (amdgpu_si_send_msg_to_smc(adev,

PPSMC_MSG_SwitchToSwState) == PPSMC_Result_OK) ?

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs

Quoted 1 line
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
@@ -8125,7 +8091,6 @@ static const struct amd_pm_funcs

si_dpm_funcs

Quoted 34 lines
Quoted 34 lines

= {

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs · line 8092

Quoted 2 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
    	.print_power_state = &si_dpm_print_power_state,
    	.debugfs_print_current_performance_level =

&si_dpm_debugfs_print_current_performance_level,

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs si_dpm_funcs = {

Quoted 5 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -1
    	.force_performance_level = &si_dpm_force_performance_level,
-	.set_powergating_by_smu = &si_set_powergating_by_smu,
    	.vblank_too_short = &si_dpm_vblank_too_short,
    	.set_fan_control_mode = &si_dpm_set_fan_control_mode,
    	.get_fan_control_mode = &si_dpm_get_fan_control_mode, diff --

git

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static void pp_pm_compute_clocks(void

Quoted 6 lines

a/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c index dbed72c1e0c6..1eb4e613b27a 100644

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
@@ -1503,16 +1503,6 @@ static void pp_pm_compute_clocks(void

*handle)

Quoted 17 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -10
    {
    	struct pp_hwmgr *hwmgr = handle;
    	struct amdgpu_device *adev = hwmgr->adev;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
    	if (!amdgpu_device_has_dc_support(adev)) {
    		amdgpu_dpm_get_active_displays(adev);
author
#6 lore raw

[AMD Official Use Only]

Thanks Lijo.
@Deucher, Alexander I just landed the change on our drm-next branch.

BR
Evan

Quoted 332 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, April 22, 2022 5:25 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V2] drm/amd/pm: fix the deadlock issue observed on SI

Quoted 24 lines · Evan

[AMD Official Use Only]

Quoted 20 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, April 22, 2022 4:36 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V2] drm/amd/pm: fix the deadlock issue observed on SI

Quoted 8 lines · Evan

[AMD Official Use Only]

Quoted 4 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, April 11, 2022 6:06 PM
To: Quan, Evan <[email protected]>; amd-

[email protected]

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Cc: Deucher, Alexander <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V2] drm/amd/pm: fix the deadlock issue observed on SI

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines · Evan Quan
Quoted 2 lines

The adev->pm.mutx is already held at the beginning of

amdgpu_dpm_compute_clocks/amdgpu_dpm_enable_uvd/amdgpu_dpm_

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

enable_vce.

Quoted 3 lines

But on their calling path, amdgpu_display_bandwidth_update will be called and thus its sub functions amdgpu_dpm_get_sclk/mclk. They will then try to acquire the same adev->pm.mutex and deadlock will

occur.

Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

What about using locked versions of get_sclk/mclk and leave the rest as they are?

[Quan, Evan] Yeah, that(adding two new APIs for locked versions of

get_sclk/mclk) should also work. But considering there cannot be other ASICs who need them, they are kind of redundant.

Quoted 1 line

Meanwhile my version is just to get everything reverted back to its

original.

Quoted 8 lines
Quoted 7 lines

So, it should be quite safe. How do you think?

Quoted 1 line

As far as I see -

1) It moves display watermark updates outside of locking
2) It adds bandwidth update under common compute_clocks paths.

[Quan, Evan] I suppose what you mentioned is about

"amdgpu_display_bandwidth_update".

Quoted 1 line

No, I just double confirmed(the old code in our amd-staging-dkms-5.9/5.10

branch) and it did come with no lock protection.

Quoted 1 line

For those legacy ASICs, the watermark setting was performed by

programming registers directly(handled at display side).

Quoted 2 lines

That might explain why it did not have lock protection as recent ASICs.

Yes, I was referring to amdgpu_display_bandwidth_update. You are right, I see it getting called outside of pm mutex at least. Also it is called commonly in amdgpu_pm_compute_clocks.

Let's proceed it this way for now.

Thanks,
Lijo

Quoted 38 lines

BR
Evan

Quoted 36 lines

I guess it is not the same as pre-mutex change.

Thanks,
Lijo

Quoted 7 lines

BR
Evan

Quoted 5 lines

Thanks,
Lijo

Quoted 1 line

By placing amdgpu_display_bandwidth_update outside of adev-

pm.mutex

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

protection(considering logically they do not need such protection) and restructuring the call flow accordingly, we can eliminate the deadlock issue. This comes with no real logics change.

Fixes 3712e7a49459 ("drm/amd/pm: unified lock protections in

amdgpu_dpm.c")

//lore.kernel.org/all/9e689fea-6c69-f4b0-8dee-

[email protected].

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines

de/

BugLink https: //gitlab.freedesktop.org/drm/amd/-/issues/1957

--
v1->v2:
- rich the commit messages(Paul)

---
    drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 39

+++++++++++++++++++

Quoted 2 lines
    .../gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c    | 10 -----
    drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    | 35 ---------------

--

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_read_sensor(struct

Quoted 9 lines
    .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  | 10 -----
    4 files changed, 39 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 5504d81c77b7..72e7b5d40af6 100644
@@ -427,6 +427,7 @@ int amdgpu_dpm_read_sensor(struct

amdgpu_device *adev, enum amd_pp_sensors senso

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_compute_clocks(struct

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
    void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev)
    {
    	const struct amd_pm_funcs *pp_funcs =
 adev->powerplay.pp_funcs;
+	int i;
 
    	if (!adev->pm.dpm_enabled)
    		return;
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -434,6 +435,15 @@ void amdgpu_dpm_compute_clocks(struct

amdgpu_device *adev)

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
    	if (!pp_funcs->pm_compute_clocks)
    		return;
 
Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev)

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+	if (adev->mode_info.num_crtc)
+		amdgpu_display_bandwidth_update(adev);
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
+		struct amdgpu_ring *ring = adev->rings[i];
+		if (ring && ring->sched.ready)
+			amdgpu_fence_wait_empty(ring);
+	}
+
    	mutex_lock(&adev->pm.mutex);
    	pp_funcs->pm_compute_clocks(adev-

powerplay.pp_handle);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
    	mutex_unlock(&adev->pm.mutex); @@ -443,6 +453,20 @@

void

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 1 line

amdgpu_dpm_enable_uvd(struct

amdgpu_device *adev, bool enable)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)

Quoted 8 lines
    {
    	int ret = 0;
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.uvd_active = true;
+			adev->pm.dpm.state =

POWER_STATE_TYPE_INTERNAL_UVD;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+		} else {
+			adev->pm.dpm.uvd_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
    	ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_UVD, !enable);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
    	if (ret)
    		DRM_ERROR("Dpm %s uvd failed, ret = %d. \n", @@

-453,6

Quoted 24 lines
Quoted 24 lines
Quoted 2 lines
Quoted 2 lines

+477,21 @@

Quoted 1 line

void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool

enable)

Quoted 21 lines
Quoted 21 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 9 lines
    {
    	int ret = 0;
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.vce_active = true;
+			/* XXX select vce level based on ring/task */
+			adev->pm.dpm.vce_level =

AMD_VCE_LEVEL_AC_ALL;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+		} else {
+			adev->pm.dpm.vce_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
    	ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_VCE, !enable);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

if (ret)
DRM_ERROR("Dpm %s vce failed, ret = %d. \n", diff --

git

Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c static int

Quoted 6 lines

a/drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c
b/drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c
index 9613c6181c17..d3fe149d8476 100644

drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -0
@@ -1028,16 +1028,6 @@ static int

amdgpu_dpm_change_power_state_locked(struct amdgpu_device

*adev)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -0
    void amdgpu_legacy_dpm_compute_clocks(void *handle)
    {
    	struct amdgpu_device *adev = (struct amdgpu_device

*)handle;

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct

Quoted 19 lines
drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -10
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
    	amdgpu_dpm_get_active_displays(adev);
 
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
index caae54487f9c..633dab14f51c 100644
@@ -3892,40 +3892,6 @@ static int si_set_boot_state(struct

amdgpu_device *adev)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 8 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -5
    }
    #endif
 
-static int si_set_powergating_by_smu(void *handle,
-				     uint32_t block_type,
-				     bool gate)
-{
-	struct amdgpu_device *adev = (struct amdgpu_device

*)handle;

Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 6 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -6
-
-	switch (block_type) {
-	case AMD_IP_BLOCK_TYPE_UVD:
-		if (!gate) {
-			adev->pm.dpm.uvd_active = true;
-			adev->pm.dpm.state =

POWER_STATE_TYPE_INTERNAL_UVD;

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 11 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -11
-		} else {
-			adev->pm.dpm.uvd_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);
-		break;
-	case AMD_IP_BLOCK_TYPE_VCE:
-		if (!gate) {
-			adev->pm.dpm.vce_active = true;
-			/* XXX select vce level based on ring/task */
-			adev->pm.dpm.vce_level =

AMD_VCE_LEVEL_AC_ALL;

Quoted 5 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -5
-		} else {
-			adev->pm.dpm.vce_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -7
-		break;
-	default:
-		break;
-	}
-	return 0;
-}
-
    static int si_set_sw_state(struct amdgpu_device *adev)
    {
    	return (amdgpu_si_send_msg_to_smc(adev,

PPSMC_MSG_SwitchToSwState) == PPSMC_Result_OK) ?

Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs

Quoted 1 line
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
@@ -8125,7 +8091,6 @@ static const struct amd_pm_funcs

si_dpm_funcs

Quoted 5 lines
Quoted 5 lines

= {

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs · line 8092

Quoted 2 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
    	.print_power_state = &si_dpm_print_power_state,
    	.debugfs_print_current_performance_level =

&si_dpm_debugfs_print_current_performance_level,

Quoted 1 line
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
    	.force_performance_level =

&si_dpm_force_performance_level,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs si_dpm_funcs = { · line 8096

Quoted 4 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -1
-	.set_powergating_by_smu = &si_set_powergating_by_smu,
    	.vblank_too_short = &si_dpm_vblank_too_short,
    	.set_fan_control_mode = &si_dpm_set_fan_control_mode,
    	.get_fan_control_mode = &si_dpm_get_fan_control_mode,

diff --

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines

git

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static void pp_pm_compute_clocks(void

Quoted 6 lines

a/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c index dbed72c1e0c6..1eb4e613b27a 100644

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
@@ -1503,16 +1503,6 @@ static void pp_pm_compute_clocks(void

*handle)

Quoted 17 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -10
    {
    	struct pp_hwmgr *hwmgr = handle;
    	struct amdgpu_device *adev = hwmgr->adev;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
    	if (!amdgpu_device_has_dc_support(adev)) {
    		amdgpu_dpm_get_active_displays(adev);
#7 lore raw
In reply to Evan Quan
Quoted 12 lines · Evan Quan

The adev->pm.mutx is already held at the beginning of amdgpu_dpm_compute_clocks/amdgpu_dpm_enable_uvd/amdgpu_dpm_enable_vce. But on their calling path, amdgpu_display_bandwidth_update will be called and thus its sub functions amdgpu_dpm_get_sclk/mclk. They will then try to acquire the same adev->pm.mutex and deadlock will occur.

By placing amdgpu_display_bandwidth_update outside of adev->pm.mutex protection(considering logically they do not need such protection) and restructuring the call flow accordingly, we can eliminate the deadlock issue. This comes with no real logics change.

Quoted 5 lines
Fixes 3712e7a49459 ("drm/amd/pm: unified lock protections in amdgpu_dpm.c")
Link https: //lore.kernel.org/all/[email protected]/
BugLink https: //gitlab.freedesktop.org/drm/amd/-/issues/1957

Side note: two spaces sneaked in there. But that's not why I write this mail.

This patch is fixing a regression in 5.18-rc, but it looks like things are stuck for more than a week now. What's up there? Or was progress made somewhere and I just couldn't find it? Was the review comment from Lijo addressed?

Ciao, Thorsten (wearing his 'the Linux kernel's regression tracker' hat)

P.S.: As the Linux kernel's regression tracker I'm getting a lot of reports on my table. I can only look briefly into most of them and lack knowledge about most of the areas they concern. I thus unfortunately will sometimes get things wrong or miss something important. I hope that's not the case here; if you think it is, don't hesitate to tell me in a public reply, it's in everyone's interest to set the public record straight.

#regzbot ignore-activity
#regzbot ^backmonitor:
https://lore.kernel.org/all/[email protected]/

Quoted 177 lines

--
v1->v2:
- rich the commit messages(Paul)

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 39 +++++++++++++++++++
 .../gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c    | 10 -----
 drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    | 35 -----------------
 .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  | 10 -----
 4 files changed, 39 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +39 -0
index 5504d81c77b7..72e7b5d40af6 100644
@@ -427,6 +427,7 @@ int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors senso
 void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev)
 {
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int i;
 
 	if (!adev->pm.dpm_enabled)
 		return;
@@ -434,6 +435,15 @@ void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev)
 	if (!pp_funcs->pm_compute_clocks)
 		return;
 
+	if (adev->mode_info.num_crtc)
+		amdgpu_display_bandwidth_update(adev);
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
+		struct amdgpu_ring *ring = adev->rings[i];
+		if (ring && ring->sched.ready)
+			amdgpu_fence_wait_empty(ring);
+	}
+
 	mutex_lock(&adev->pm.mutex);
 	pp_funcs->pm_compute_clocks(adev->powerplay.pp_handle);
 	mutex_unlock(&adev->pm.mutex);
@@ -443,6 +453,20 @@ void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)
 {
 	int ret = 0;
 
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.uvd_active = true;
+			adev->pm.dpm.state = POWER_STATE_TYPE_INTERNAL_UVD;
+		} else {
+			adev->pm.dpm.uvd_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
 	ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_UVD, !enable);
 	if (ret)
 		DRM_ERROR("Dpm %s uvd failed, ret = %d. \n",
@@ -453,6 +477,21 @@ void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)
 {
 	int ret = 0;
 
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.vce_active = true;
+			/* XXX select vce level based on ring/task */
+			adev->pm.dpm.vce_level = AMD_VCE_LEVEL_AC_ALL;
+		} else {
+			adev->pm.dpm.vce_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
 	ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_VCE, !enable);
 	if (ret)
 		DRM_ERROR("Dpm %s vce failed, ret = %d. \n",
drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -10
index 9613c6181c17..d3fe149d8476 100644
@@ -1028,16 +1028,6 @@ static int amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)
 void amdgpu_legacy_dpm_compute_clocks(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
 	amdgpu_dpm_get_active_displays(adev);
 
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -35
index caae54487f9c..633dab14f51c 100644
@@ -3892,40 +3892,6 @@ static int si_set_boot_state(struct amdgpu_device *adev)
 }
 #endif
 
-static int si_set_powergating_by_smu(void *handle,
-				     uint32_t block_type,
-				     bool gate)
-{
-	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
-	switch (block_type) {
-	case AMD_IP_BLOCK_TYPE_UVD:
-		if (!gate) {
-			adev->pm.dpm.uvd_active = true;
-			adev->pm.dpm.state = POWER_STATE_TYPE_INTERNAL_UVD;
-		} else {
-			adev->pm.dpm.uvd_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);
-		break;
-	case AMD_IP_BLOCK_TYPE_VCE:
-		if (!gate) {
-			adev->pm.dpm.vce_active = true;
-			/* XXX select vce level based on ring/task */
-			adev->pm.dpm.vce_level = AMD_VCE_LEVEL_AC_ALL;
-		} else {
-			adev->pm.dpm.vce_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);
-		break;
-	default:
-		break;
-	}
-	return 0;
-}
-
 static int si_set_sw_state(struct amdgpu_device *adev)
 {
 	return (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_SwitchToSwState) == PPSMC_Result_OK) ?
@@ -8125,7 +8091,6 @@ static const struct amd_pm_funcs si_dpm_funcs = {
 	.print_power_state = &si_dpm_print_power_state,
 	.debugfs_print_current_performance_level = &si_dpm_debugfs_print_current_performance_level,
 	.force_performance_level = &si_dpm_force_performance_level,
-	.set_powergating_by_smu = &si_set_powergating_by_smu,
 	.vblank_too_short = &si_dpm_vblank_too_short,
 	.set_fan_control_mode = &si_dpm_set_fan_control_mode,
 	.get_fan_control_mode = &si_dpm_get_fan_control_mode,
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -10
index dbed72c1e0c6..1eb4e613b27a 100644
@@ -1503,16 +1503,6 @@ static void pp_pm_compute_clocks(void *handle)
 {
 	struct pp_hwmgr *hwmgr = handle;
 	struct amdgpu_device *adev = hwmgr->adev;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
 	if (!amdgpu_device_has_dc_support(adev)) {
 		amdgpu_dpm_get_active_displays(adev);
author
#8 lore raw

[AMD Official Use Only]

Quoted 26 lines

-----Original Message-----
From: Thorsten Leemhuis <[email protected]>
Sent: Thursday, April 21, 2022 4:29 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V2] drm/amd/pm: fix the deadlock issue observed on SI

Quoted 2 lines · Evan Quan

The adev->pm.mutx is already held at the beginning of

amdgpu_dpm_compute_clocks/amdgpu_dpm_enable_uvd/amdgpu_dpm_ enable_vce.

Quoted 5 lines

But on their calling path, amdgpu_display_bandwidth_update will be called and thus its sub functions amdgpu_dpm_get_sclk/mclk. They will then try to acquire the same adev->pm.mutex and deadlock will occur.

Quoted 7 lines

By placing amdgpu_display_bandwidth_update outside of adev- pm.mutex
protection(considering logically they do not need such protection) and restructuring the call flow accordingly, we can eliminate the deadlock issue. This comes with no real logics change.

Fixes 3712e7a49459 ("drm/amd/pm: unified lock protections in

amdgpu_dpm.c")

Quoted 8 lines
Quoted 3 lines
Link https: //lore.kernel.org/all/9e689fea-6c69-f4b0-8dee-

[email protected]/

Quoted 1 line

BugLink: https: //gitlab.freedesktop.org/drm/amd/-/issues/1957

Side note: two spaces sneaked in there. But that's not why I write this mail.

[Quan, Evan] Thanks! Will fix that.

Quoted 5 lines

This patch is fixing a regression in 5.18-rc, but it looks like things are stuck for more than a week now. What's up there? Or was progress made somewhere and I just couldn't find it? Was the review comment from Lijo addressed?

[Quan, Evan] Sorry, was busy with other stuffs. Let me check.

BR
Evan

Quoted 220 lines

Ciao, Thorsten (wearing his 'the Linux kernel's regression tracker' hat)

P.S.: As the Linux kernel's regression tracker I'm getting a lot of reports on my table. I can only look briefly into most of them and lack knowledge about most of the areas they concern. I thus unfortunately will sometimes get things wrong or miss something important. I hope that's not the case here; if you think it is, don't hesitate to tell me in a public reply, it's in everyone's interest to set the public record straight.

#regzbot ignore-activity
#regzbot ^backmonitor:
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.
kernel.org%2Fall%2F9e689fea-6c69-f4b0-8dee- 32c4cf7d8f9c%40molgen.mpg.de%2F&amp;data=05%7C01%7Cevan.quan%4 0amd.com%7Cf8885e7025e9445db6e508da23710586%7C3dd8961fe4884e608 e11a82d994e183d%7C0%7C0%7C637861265579473039%7CUnknown%7CTWF pbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXV CI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=47%2FiLxh3iw9jN%2B0KiUfcO 79u7kpjaNKkueZE%2BMEDtl8%3D&amp;reserved=0

Quoted 6 lines

--
v1->v2:
- rich the commit messages(Paul)

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 39

+++++++++++++++++++

Review

Quoted 6 lines
 .../gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c    | 10 -----
 drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    | 35 -----------------
 .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  | 10 -----
 4 files changed, 39 insertions(+), 55 deletions(-)
(quoted diff) +0 -0

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

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_read_sensor(struct

Quoted 4 lines

index 5504d81c77b7..72e7b5d40af6 100644

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -427,6 +427,7 @@ int amdgpu_dpm_read_sensor(struct

amdgpu_device *adev, enum amd_pp_sensors senso

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_compute_clocks(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
 void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev)
 {
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int i;
 
 	if (!adev->pm.dpm_enabled)
 		return;
@@ -434,6 +435,15 @@ void amdgpu_dpm_compute_clocks(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct

Quoted 16 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
 	if (!pp_funcs->pm_compute_clocks)
 		return;
 
+	if (adev->mode_info.num_crtc)
+		amdgpu_display_bandwidth_update(adev);
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
+		struct amdgpu_ring *ring = adev->rings[i];
+		if (ring && ring->sched.ready)
+			amdgpu_fence_wait_empty(ring);
+	}
+
 	mutex_lock(&adev->pm.mutex);
 	pp_funcs->pm_compute_clocks(adev->powerplay.pp_handle);
 	mutex_unlock(&adev->pm.mutex);
@@ -443,6 +453,20 @@ void amdgpu_dpm_enable_uvd(struct

amdgpu_device *adev, bool enable)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
 {
 	int ret = 0;
 
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.uvd_active = true;
+			adev->pm.dpm.state =

POWER_STATE_TYPE_INTERNAL_UVD;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+		} else {
+			adev->pm.dpm.uvd_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
 	ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_UVD, !enable);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
 	if (ret)
 		DRM_ERROR("Dpm %s uvd failed, ret = %d. \n",
@@ -453,6 +477,21 @@ void amdgpu_dpm_enable_vce(struct

amdgpu_device *adev, bool enable)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
 {
 	int ret = 0;
 
+	if (adev->family == AMDGPU_FAMILY_SI) {
+		mutex_lock(&adev->pm.mutex);
+		if (enable) {
+			adev->pm.dpm.vce_active = true;
+			/* XXX select vce level based on ring/task */
+			adev->pm.dpm.vce_level =

AMD_VCE_LEVEL_AC_ALL;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+		} else {
+			adev->pm.dpm.vce_active = false;
+		}
+		mutex_unlock(&adev->pm.mutex);
+
+		amdgpu_dpm_compute_clocks(adev);
+		return;
+	}
+
 	ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_VCE, !enable);

Review

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
 	if (ret)
 		DRM_ERROR("Dpm %s vce failed, ret = %d. \n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c

drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c static int

Quoted 4 lines

index 9613c6181c17..d3fe149d8476 100644

drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -0
@@ -1028,16 +1028,6 @@ static int

amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)

Review

Quoted 17 lines
drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c +0 -10
 void amdgpu_legacy_dpm_compute_clocks(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
 	amdgpu_dpm_get_active_displays(adev);
 
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct

Quoted 4 lines

index caae54487f9c..633dab14f51c 100644

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
@@ -3892,40 +3892,6 @@ static int si_set_boot_state(struct

amdgpu_device *adev)

Quoted 4 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -1
 }
 #endif
 
-static int si_set_powergating_by_smu(void *handle,

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -10
-				     uint32_t block_type,
-				     bool gate)
-{
-	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
-	switch (block_type) {
-	case AMD_IP_BLOCK_TYPE_UVD:
-		if (!gate) {
-			adev->pm.dpm.uvd_active = true;
-			adev->pm.dpm.state =

POWER_STATE_TYPE_INTERNAL_UVD;

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 11 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -11
-		} else {
-			adev->pm.dpm.uvd_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);
-		break;
-	case AMD_IP_BLOCK_TYPE_VCE:
-		if (!gate) {
-			adev->pm.dpm.vce_active = true;
-			/* XXX select vce level based on ring/task */
-			adev->pm.dpm.vce_level =

AMD_VCE_LEVEL_AC_ALL;

Quoted 5 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -5
-		} else {
-			adev->pm.dpm.vce_active = false;
-		}
-
-		amdgpu_legacy_dpm_compute_clocks(handle);

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -7
-		break;
-	default:
-		break;
-	}
-	return 0;
-}
-
 static int si_set_sw_state(struct amdgpu_device *adev)
 {
 	return (amdgpu_si_send_msg_to_smc(adev,

PPSMC_MSG_SwitchToSwState) == PPSMC_Result_OK) ?

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs si_dpm_funcs

Quoted 1 line
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
@@ -8125,7 +8091,6 @@ static const struct amd_pm_funcs si_dpm_funcs

= {

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static const struct amd_pm_funcs si_dpm_funcs · line 8092

Quoted 2 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
 	.print_power_state = &si_dpm_print_power_state,
 	.debugfs_print_current_performance_level =

&si_dpm_debugfs_print_current_performance_level,

Review

Quoted 6 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -1
 	.force_performance_level = &si_dpm_force_performance_level,
-	.set_powergating_by_smu = &si_set_powergating_by_smu,
 	.vblank_too_short = &si_dpm_vblank_too_short,
 	.set_fan_control_mode = &si_dpm_set_fan_control_mode,
 	.get_fan_control_mode = &si_dpm_get_fan_control_mode,
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static void pp_pm_compute_clocks(void

Quoted 4 lines

index dbed72c1e0c6..1eb4e613b27a 100644

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
@@ -1503,16 +1503,6 @@ static void pp_pm_compute_clocks(void

*handle)

Quoted 16 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -10
 {
 	struct pp_hwmgr *hwmgr = handle;
 	struct amdgpu_device *adev = hwmgr->adev;
-	int i = 0;
-
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
 
 	if (!amdgpu_device_has_dc_support(adev)) {
 		amdgpu_dpm_get_active_displays(adev);