Commit 9e7bc3fc authored by chr[]'s avatar chr[] Committed by Wentao Guan
Browse files

amdgpu/pm/legacy: fix suspend/resume issues

stable inclusion
from stable-v6.6.81
commit c52d6aaf8ee8acab146fc8c851f339ec8e94cf3b
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBYZED

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=c52d6aaf8ee8acab146fc8c851f339ec8e94cf3b

--------------------------------

commit 91dcc66b34beb72dde8412421bdc1b4cd40e4fb8 upstream.

resume and irq handler happily races in set_power_state()

* amdgpu_legacy_dpm_compute_clocks() needs lock
* protect irq work handler
* fix dpm_enabled usage

v2: fix clang build, integrate Lijo's comments (Alex)

Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/2524


Fixes: 3712e7a4 ("drm/amd/pm: unified lock protections in amdgpu_dpm.c")
Reviewed-by: default avatarLijo Lazar <lijo.lazar@amd.com>
Tested-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name> # on Oland PRO
Signed-off-by: default avatarchr[] <chris@rudorff.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
(cherry picked from commit ee3dc9e204d271c9c7a8d4d38a0bce4745d33e71)
Cc: stable@vger.kernel.org
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit c52d6aaf8ee8acab146fc8c851f339ec8e94cf3b)
Signed-off-by: default avatarWentao Guan <guanwentao@uniontech.com>
parent 91a164bb
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -3043,6 +3043,7 @@ static int kv_dpm_hw_init(void *handle)
	if (!amdgpu_dpm)
		return 0;

	mutex_lock(&adev->pm.mutex);
	kv_dpm_setup_asic(adev);
	ret = kv_dpm_enable(adev);
	if (ret)
@@ -3050,6 +3051,8 @@ static int kv_dpm_hw_init(void *handle)
	else
		adev->pm.dpm_enabled = true;
	amdgpu_legacy_dpm_compute_clocks(adev);
	mutex_unlock(&adev->pm.mutex);

	return ret;
}

@@ -3067,32 +3070,42 @@ static int kv_dpm_suspend(void *handle)
{
	struct amdgpu_device *adev = (struct amdgpu_device *)handle;

	cancel_work_sync(&adev->pm.dpm.thermal.work);

	if (adev->pm.dpm_enabled) {
		mutex_lock(&adev->pm.mutex);
		adev->pm.dpm_enabled = false;
		/* disable dpm */
		kv_dpm_disable(adev);
		/* reset the power state */
		adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps;
		mutex_unlock(&adev->pm.mutex);
	}
	return 0;
}

static int kv_dpm_resume(void *handle)
{
	int ret;
	int ret = 0;
	struct amdgpu_device *adev = (struct amdgpu_device *)handle;

	if (adev->pm.dpm_enabled) {
	if (!amdgpu_dpm)
		return 0;

	if (!adev->pm.dpm_enabled) {
		mutex_lock(&adev->pm.mutex);
		/* asic init will reset to the boot state */
		kv_dpm_setup_asic(adev);
		ret = kv_dpm_enable(adev);
		if (ret)
		if (ret) {
			adev->pm.dpm_enabled = false;
		else
		} else {
			adev->pm.dpm_enabled = true;
		if (adev->pm.dpm_enabled)
			amdgpu_legacy_dpm_compute_clocks(adev);
		}
	return 0;
		mutex_unlock(&adev->pm.mutex);
	}
	return ret;
}

static bool kv_dpm_is_idle(void *handle)
+6 −2
Original line number Diff line number Diff line
@@ -1018,9 +1018,12 @@ void amdgpu_dpm_thermal_work_handler(struct work_struct *work)
	enum amd_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL;
	int temp, size = sizeof(temp);

	if (!adev->pm.dpm_enabled)
		return;
	mutex_lock(&adev->pm.mutex);

	if (!adev->pm.dpm_enabled) {
		mutex_unlock(&adev->pm.mutex);
		return;
	}
	if (!pp_funcs->read_sensor(adev->powerplay.pp_handle,
				   AMDGPU_PP_SENSOR_GPU_TEMP,
				   (void *)&temp,
@@ -1042,4 +1045,5 @@ void amdgpu_dpm_thermal_work_handler(struct work_struct *work)
	adev->pm.dpm.state = dpm_state;

	amdgpu_legacy_dpm_compute_clocks(adev->powerplay.pp_handle);
	mutex_unlock(&adev->pm.mutex);
}
+20 −6
Original line number Diff line number Diff line
@@ -7789,6 +7789,7 @@ static int si_dpm_hw_init(void *handle)
	if (!amdgpu_dpm)
		return 0;

	mutex_lock(&adev->pm.mutex);
	si_dpm_setup_asic(adev);
	ret = si_dpm_enable(adev);
	if (ret)
@@ -7796,6 +7797,7 @@ static int si_dpm_hw_init(void *handle)
	else
		adev->pm.dpm_enabled = true;
	amdgpu_legacy_dpm_compute_clocks(adev);
	mutex_unlock(&adev->pm.mutex);
	return ret;
}

@@ -7813,32 +7815,44 @@ static int si_dpm_suspend(void *handle)
{
	struct amdgpu_device *adev = (struct amdgpu_device *)handle;

	cancel_work_sync(&adev->pm.dpm.thermal.work);

	if (adev->pm.dpm_enabled) {
		mutex_lock(&adev->pm.mutex);
		adev->pm.dpm_enabled = false;
		/* disable dpm */
		si_dpm_disable(adev);
		/* reset the power state */
		adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps;
		mutex_unlock(&adev->pm.mutex);
	}

	return 0;
}

static int si_dpm_resume(void *handle)
{
	int ret;
	int ret = 0;
	struct amdgpu_device *adev = (struct amdgpu_device *)handle;

	if (adev->pm.dpm_enabled) {
	if (!amdgpu_dpm)
		return 0;

	if (!adev->pm.dpm_enabled) {
		/* asic init will reset to the boot state */
		mutex_lock(&adev->pm.mutex);
		si_dpm_setup_asic(adev);
		ret = si_dpm_enable(adev);
		if (ret)
		if (ret) {
			adev->pm.dpm_enabled = false;
		else
		} else {
			adev->pm.dpm_enabled = true;
		if (adev->pm.dpm_enabled)
			amdgpu_legacy_dpm_compute_clocks(adev);
		}
	return 0;
		mutex_unlock(&adev->pm.mutex);
	}

	return ret;
}

static bool si_dpm_is_idle(void *handle)