Skip to contentSkip to conversation

drm/amdgpu: Disable dpm_enabled flag while VF is in reset

PATCH Superseded Victor Skvortsov 2 participants 3 messages Aug 12, 2024

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/amdgpu: Disable dpm_enabled flag while VF is in reset

VFs do not perform HW fini/suspend in FLR, so the dpm_enabled is incorrectly kept enabled. Add interface to disable it in virt_pre_reset call.

v2: Made implementation generic for all asics

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c     | 6 ++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c       | 8 ++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h       | 1 +
 drivers/gpu/drm/amd/include/kgd_pp_interface.h | 1 +
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c            | 5 ++++-
 5 files changed, 16 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -4
index 29a4adee9286..a6b8d0ba4758 100644
@@ -5289,10 +5289,8 @@ int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,
 	if (reset_context->reset_req_dev == adev)
 		job = reset_context->job;
 
-	if (amdgpu_sriov_vf(adev)) {
-		/* stop the data exchange thread */
-		amdgpu_virt_fini_data_exchange(adev);
-	}
+	if (amdgpu_sriov_vf(adev))
+		amdgpu_virt_pre_reset(adev);
 
 	amdgpu_fence_driver_isr_toggle(adev, true);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +8 -0
index b287a82e6177..b6397d3229e1 100644
@@ -33,6 +33,7 @@
 #include "amdgpu.h"
 #include "amdgpu_ras.h"
 #include "amdgpu_reset.h"
+#include "amdgpu_dpm.h"
 #include "vi.h"
 #include "soc15.h"
 #include "nv.h"
@@ -849,6 +850,13 @@ enum amdgpu_sriov_vf_mode amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *ad
 	return mode;
 }
 
+void amdgpu_virt_pre_reset(struct amdgpu_device *adev)
+{
+	/* stop the data exchange thread */
+	amdgpu_virt_fini_data_exchange(adev);
+	amdgpu_dpm_set_mp1_state(adev, PP_MP1_STATE_FLR);
+}
+
 void amdgpu_virt_post_reset(struct amdgpu_device *adev)
 {
 	if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(11, 0, 3)) {
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1 -0
index b42a8854dca0..b650a2032c42 100644
@@ -376,6 +376,7 @@ u32 amdgpu_sriov_rreg(struct amdgpu_device *adev,
 		      u32 offset, u32 acc_flags, u32 hwip, u32 xcc_id);
 bool amdgpu_virt_fw_load_skip_check(struct amdgpu_device *adev,
 			uint32_t ucode_id);
+void amdgpu_virt_pre_reset(struct amdgpu_device *adev);
 void amdgpu_virt_post_reset(struct amdgpu_device *adev);
 bool amdgpu_sriov_xnack_support(struct amdgpu_device *adev);
 bool amdgpu_virt_get_rlcg_reg_access_flag(struct amdgpu_device *adev,
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -0
index 4b20e2274313..19a48d98830a 100644
@@ -218,6 +218,7 @@ enum pp_mp1_state {
 	PP_MP1_STATE_SHUTDOWN,
 	PP_MP1_STATE_UNLOAD,
 	PP_MP1_STATE_RESET,
+	PP_MP1_STATE_FLR,
 };
 
 enum pp_df_cstate {
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -1
index 8b7d6ed7e2ed..af39206a2c5f 100644
@@ -168,7 +168,10 @@ int amdgpu_dpm_set_mp1_state(struct amdgpu_device *adev,
 	int ret = 0;
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
-	if (pp_funcs && pp_funcs->set_mp1_state) {
+	if (amdgpu_sriov_vf(adev) && mp1_state == PP_MP1_STATE_FLR) {
+		/* VF lost access to SMU */
+		adev->pm.dpm_enabled = false;
+	} else if (pp_funcs && pp_funcs->set_mp1_state) {
 		mutex_lock(&adev->pm.mutex);
 
 		ret = pp_funcs->set_mp1_state(
Signature · 1 line
2.34.1
#1 lore raw
Quoted 87 lines · Victor Skvortsov

VFs do not perform HW fini/suspend in FLR, so the dpm_enabled is incorrectly kept enabled. Add interface to disable it in virt_pre_reset call.

v2: Made implementation generic for all asics

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c     | 6 ++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c       | 8 ++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h       | 1 +
 drivers/gpu/drm/amd/include/kgd_pp_interface.h | 1 +
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c            | 5 ++++-
 5 files changed, 16 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -4
index 29a4adee9286..a6b8d0ba4758 100644
@@ -5289,10 +5289,8 @@ int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,
 	if (reset_context->reset_req_dev == adev)
 		job = reset_context->job;
 
-	if (amdgpu_sriov_vf(adev)) {
-		/* stop the data exchange thread */
-		amdgpu_virt_fini_data_exchange(adev);
-	}
+	if (amdgpu_sriov_vf(adev))
+		amdgpu_virt_pre_reset(adev);
 
 	amdgpu_fence_driver_isr_toggle(adev, true);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +8 -0
index b287a82e6177..b6397d3229e1 100644
@@ -33,6 +33,7 @@
 #include "amdgpu.h"
 #include "amdgpu_ras.h"
 #include "amdgpu_reset.h"
+#include "amdgpu_dpm.h"
 #include "vi.h"
 #include "soc15.h"
 #include "nv.h"
@@ -849,6 +850,13 @@ enum amdgpu_sriov_vf_mode amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *ad
 	return mode;
 }
 
+void amdgpu_virt_pre_reset(struct amdgpu_device *adev)
+{
+	/* stop the data exchange thread */
+	amdgpu_virt_fini_data_exchange(adev);
+	amdgpu_dpm_set_mp1_state(adev, PP_MP1_STATE_FLR);
+}
+
 void amdgpu_virt_post_reset(struct amdgpu_device *adev)
 {
 	if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(11, 0, 3)) {
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1 -0
index b42a8854dca0..b650a2032c42 100644
@@ -376,6 +376,7 @@ u32 amdgpu_sriov_rreg(struct amdgpu_device *adev,
 		      u32 offset, u32 acc_flags, u32 hwip, u32 xcc_id);
 bool amdgpu_virt_fw_load_skip_check(struct amdgpu_device *adev,
 			uint32_t ucode_id);
+void amdgpu_virt_pre_reset(struct amdgpu_device *adev);
 void amdgpu_virt_post_reset(struct amdgpu_device *adev);
 bool amdgpu_sriov_xnack_support(struct amdgpu_device *adev);
 bool amdgpu_virt_get_rlcg_reg_access_flag(struct amdgpu_device *adev,
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -0
index 4b20e2274313..19a48d98830a 100644
@@ -218,6 +218,7 @@ enum pp_mp1_state {
 	PP_MP1_STATE_SHUTDOWN,
 	PP_MP1_STATE_UNLOAD,
 	PP_MP1_STATE_RESET,
+	PP_MP1_STATE_FLR,
 };
 
 enum pp_df_cstate {
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 8b7d6ed7e2ed..af39206a2c5f 100644

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_mp1_state(struct amdgpu_device *adev, · line 173

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -1
@@ -168,7 +168,10 @@ int amdgpu_dpm_set_mp1_state(struct amdgpu_device *adev,
 	int ret = 0;
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
-	if (pp_funcs && pp_funcs->set_mp1_state) {
+	if (amdgpu_sriov_vf(adev) && mp1_state == PP_MP1_STATE_FLR) {
+		/* VF lost access to SMU */
+		adev->pm.dpm_enabled = false;

For non-VF devices, PP_MP1_STATE_FLR needs to be a don't care. Preferrably, something like

if (mp1_state == PP_MP1_STATE_FLR) {
	if (amdgpu_sriov_vf(adev))
		adev->pm.dpm_enabled = false;
}else { ..

}

Thanks,
Lijo

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+	} else if (pp_funcs && pp_funcs->set_mp1_state) {
 		mutex_lock(&adev->pm.mutex);
 
 		ret = pp_funcs->set_mp1_state(
#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 115 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, August 12, 2024 9:46 AM
To: Skvortsov, Victor <[email protected]>; amd- [email protected]; Luo, Zhigang <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: Disable dpm_enabled flag while VF is in reset

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_pre_asic_reset(struct

Quoted 21 lines · Victor Skvortsov

VFs do not perform HW fini/suspend in FLR, so the dpm_enabled is incorrectly kept enabled. Add interface to disable it in virt_pre_reset call.

v2: Made implementation generic for all asics

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c     | 6 ++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c       | 8 ++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h       | 1 +
 drivers/gpu/drm/amd/include/kgd_pp_interface.h | 1 +
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c            | 5 ++++-
 5 files changed, 16 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 29a4adee9286..a6b8d0ba4758 100644
@@ -5289,10 +5289,8 @@ int amdgpu_device_pre_asic_reset(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c enum amdgpu_sriov_vf_mode

Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -4
    if (reset_context->reset_req_dev == adev)
            job = reset_context->job;
 
-   if (amdgpu_sriov_vf(adev)) {
-           /* stop the data exchange thread */
-           amdgpu_virt_fini_data_exchange(adev);
-   }
+   if (amdgpu_sriov_vf(adev))
+           amdgpu_virt_pre_reset(adev);
 
    amdgpu_fence_driver_isr_toggle(adev, true);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1 -0
index b287a82e6177..b6397d3229e1 100644
@@ -33,6 +33,7 @@
 #include "amdgpu.h"
 #include "amdgpu_ras.h"
 #include "amdgpu_reset.h"
+#include "amdgpu_dpm.h"
 #include "vi.h"
 #include "soc15.h"
 #include "nv.h"
@@ -849,6 +850,13 @@ enum amdgpu_sriov_vf_mode

amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *ad

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h u32 amdgpu_sriov_rreg(struct amdgpu_device

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +5 -0
    return mode;
 }
 
+void amdgpu_virt_pre_reset(struct amdgpu_device *adev) {
+   /* stop the data exchange thread */
+   amdgpu_virt_fini_data_exchange(adev);
+   amdgpu_dpm_set_mp1_state(adev, PP_MP1_STATE_FLR); }
+
 void amdgpu_virt_post_reset(struct amdgpu_device *adev)  {
    if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(11, 0, 3)) {
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +0 -0
index b42a8854dca0..b650a2032c42 100644
@@ -376,6 +376,7 @@ u32 amdgpu_sriov_rreg(struct amdgpu_device

*adev,

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

Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1 -0
                  u32 offset, u32 acc_flags, u32 hwip, u32 xcc_id);  bool
 amdgpu_virt_fw_load_skip_check(struct amdgpu_device *adev,
                    uint32_t ucode_id);
+void amdgpu_virt_pre_reset(struct amdgpu_device *adev);
 void amdgpu_virt_post_reset(struct amdgpu_device *adev);  bool

amdgpu_sriov_xnack_support(struct amdgpu_device *adev); bool amdgpu_virt_get_rlcg_reg_access_flag(struct amdgpu_device *adev, diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
index 4b20e2274313..19a48d98830a 100644

drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -0
@@ -218,6 +218,7 @@ enum pp_mp1_state {
    PP_MP1_STATE_SHUTDOWN,
    PP_MP1_STATE_UNLOAD,
    PP_MP1_STATE_RESET,
+   PP_MP1_STATE_FLR,
 };
 
 enum pp_df_cstate {
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 8b7d6ed7e2ed..af39206a2c5f 100644
@@ -168,7 +168,10 @@ int amdgpu_dpm_set_mp1_state(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_mp1_state(struct amdgpu_device *adev, · line 173

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -1
    int ret = 0;
    const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
-   if (pp_funcs && pp_funcs->set_mp1_state) {
+   if (amdgpu_sriov_vf(adev) && mp1_state == PP_MP1_STATE_FLR) {
+           /* VF lost access to SMU */
+           adev->pm.dpm_enabled = false;

For non-VF devices, PP_MP1_STATE_FLR needs to be a don't care. Preferrably, something like

Quoted 8 lines
if (mp1_state == PP_MP1_STATE_FLR) {
      if (amdgpu_sriov_vf(adev))
              adev->pm.dpm_enabled = false;
}else { ..

}

Thanks,
Lijo

I agree it's cleaner like that. Will send out v3.

Thanks,
Victor

Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+   } else if (pp_funcs && pp_funcs->set_mp1_state) {
            mutex_lock(&adev->pm.mutex);
 
            ret = pp_funcs->set_mp1_state(