Skip to contentSkip to conversation

drm/amdgpu: disable cstate properly for driver reloading scenario

PATCH In review Evan Quan 3 participants 9 messages Mar 2, 2023 – Mar 6, 2023

Subsystems (2)
lore
Share & tools
lore

Evan Quan

author
#0 lore raw

PATCH 1/1 drm/amdgpu: disable cstate properly for driver reloading scenario

Gpu reset might be needed during driver reloading. To guard that(gpu reset) work, df cstate needs to be disabled properly.

Change-Id I5c074c265c0b08a67b6934ae1ad9aa3fed245461
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +9 -0
index 51bbeaa1f311..3c854461ef32 100644
@@ -2816,6 +2816,15 @@ static int amdgpu_device_ip_fini_early(struct amdgpu_device *adev)
 	amdgpu_device_set_pg_state(adev, AMD_PG_STATE_UNGATE);
 	amdgpu_device_set_cg_state(adev, AMD_CG_STATE_UNGATE);
 
+	/*
+	 * Get df cstate disabled properly on driver unloading.
+	 * Since on the succeeding driver reloading, gpu reset might
+	 * be required. And cstate disabled is a prerequisite for
+	 * that(gpu reset).
+	 */
+	if (amdgpu_dpm_set_df_cstate(adev, DF_CSTATE_DISALLOW))
+		dev_warn(adev->dev, "Failed to disallow df cstate");
+
 	amdgpu_amdkfd_suspend(adev, false);
 
 	/* Workaroud for ASICs need to disable SMC first */
Signature · 1 line
2.34.1
#1 lore raw
Quoted 16 lines · Evan Quan

Gpu reset might be needed during driver reloading. To guard that(gpu reset) work, df cstate needs to be disabled properly.

Change-Id I5c074c265c0b08a67b6934ae1ad9aa3fed245461
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 9 +++++++++
  1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 51bbeaa1f311..3c854461ef32 100644
@@ -2816,6 +2816,15 @@ static int amdgpu_device_ip_fini_early(struct amdgpu_device *adev)
  	amdgpu_device_set_pg_state(adev, AMD_PG_STATE_UNGATE);
  	amdgpu_device_set_cg_state(adev, AMD_CG_STATE_UNGATE);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_fini_early(struct amdgpu_device *adev) · line 2827

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +9 -0
 
+	/*
+	 * Get df cstate disabled properly on driver unloading.
+	 * Since on the succeeding driver reloading, gpu reset might
+	 * be required. And cstate disabled is a prerequisite for
+	 * that(gpu reset).
+	 */
+	if (amdgpu_dpm_set_df_cstate(adev, DF_CSTATE_DISALLOW))
+		dev_warn(adev->dev, "Failed to disallow df cstate");
+

This looks more like a firmware bug. Driver sends the Unload message to FW. In that case FW should disable all features including C-state.

Thanks,
Lijo

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
  	amdgpu_amdkfd_suspend(adev, false);
 
  	/* Workaroud for ASICs need to disable SMC first */
author
#2 lore raw

[AMD Official Use Only - General]

Quoted 30 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, March 2, 2023 4:28 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

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

Quoted 15 lines · Evan Quan

Gpu reset might be needed during driver reloading. To guard that(gpu reset) work, df cstate needs to be disabled properly.

Change-Id I5c074c265c0b08a67b6934ae1ad9aa3fed245461
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 9 +++++++++
  1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 51bbeaa1f311..3c854461ef32 100644
@@ -2816,6 +2816,15 @@ static int amdgpu_device_ip_fini_early(struct

amdgpu_device *adev)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
  	amdgpu_device_set_pg_state(adev, AMD_PG_STATE_UNGATE);
  	amdgpu_device_set_cg_state(adev, AMD_CG_STATE_UNGATE);
 
Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_fini_early(struct amdgpu_device *adev) · line 2827

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +9 -0
+	/*
+	 * Get df cstate disabled properly on driver unloading.
+	 * Since on the succeeding driver reloading, gpu reset might
+	 * be required. And cstate disabled is a prerequisite for
+	 * that(gpu reset).
+	 */
+	if (amdgpu_dpm_set_df_cstate(adev, DF_CSTATE_DISALLOW))
+		dev_warn(adev->dev, "Failed to disallow df cstate");
+

This looks more like a firmware bug. Driver sends the Unload message to FW. In that case FW should disable all features including C-state.

Driver does not send the Unload message. We want PMFM alive and ready for handling possible gpu reset on reloading.

BR
Evan

Quoted 7 lines

Thanks,
Lijo

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
  	amdgpu_amdkfd_suspend(adev, false);
 
  	/* Workaroud for ASICs need to disable SMC first */
#3 lore raw
Quoted 46 lines · Evan

[AMD Official Use Only - General]

Quoted 30 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, March 2, 2023 4:28 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

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

Quoted 15 lines · Evan Quan

Gpu reset might be needed during driver reloading. To guard that(gpu reset) work, df cstate needs to be disabled properly.

Change-Id I5c074c265c0b08a67b6934ae1ad9aa3fed245461
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 9 +++++++++
   1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 51bbeaa1f311..3c854461ef32 100644
@@ -2816,6 +2816,15 @@ static int amdgpu_device_ip_fini_early(struct

amdgpu_device *adev)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
   	amdgpu_device_set_pg_state(adev, AMD_PG_STATE_UNGATE);
   	amdgpu_device_set_cg_state(adev, AMD_CG_STATE_UNGATE);
 
Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_fini_early(struct amdgpu_device *adev) · line 2827

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +9 -0
+	/*
+	 * Get df cstate disabled properly on driver unloading.
+	 * Since on the succeeding driver reloading, gpu reset might
+	 * be required. And cstate disabled is a prerequisite for
+	 * that(gpu reset).
+	 */
+	if (amdgpu_dpm_set_df_cstate(adev, DF_CSTATE_DISALLOW))
+		dev_warn(adev->dev, "Failed to disallow df cstate");
+

This looks more like a firmware bug. Driver sends the Unload message to FW. In that case FW should disable all features including C-state.

Quoted 2 lines

Driver does not send the Unload message. We want PMFM alive and ready for handling possible gpu reset on reloading.

Actually, soc21_need_reset_on_init code itself has a bug. PSP won't get unloaded by default on ring destruction. Even if PSP stops, it could just keep the heartbeat value as non-zero (just that it won't increment).

Probably, that needs to be fixed first rather than keeping PMFW alive for a reset.

Thanks,
Lijo

Quoted 9 lines

BR
Evan

Quoted 7 lines

Thanks,
Lijo

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
   	amdgpu_amdkfd_suspend(adev, false);
 
   	/* Workaroud for ASICs need to disable SMC first */
author
#4 lore raw

[AMD Official Use Only - General]

Quoted 62 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, March 2, 2023 5:21 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

Quoted 45 lines · Evan

[AMD Official Use Only - General]

Quoted 41 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, March 2, 2023 4:28 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

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

Quoted 15 lines · Evan Quan

Gpu reset might be needed during driver reloading. To guard that(gpu reset) work, df cstate needs to be disabled properly.

Change-Id I5c074c265c0b08a67b6934ae1ad9aa3fed245461
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 9 +++++++++
   1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 51bbeaa1f311..3c854461ef32 100644
@@ -2816,6 +2816,15 @@ static int amdgpu_device_ip_fini_early(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_fini_early(struct amdgpu_device *adev) · line 2827

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +9 -0
   	amdgpu_device_set_pg_state(adev, AMD_PG_STATE_UNGATE);
   	amdgpu_device_set_cg_state(adev, AMD_CG_STATE_UNGATE);
 
+	/*
+	 * Get df cstate disabled properly on driver unloading.
+	 * Since on the succeeding driver reloading, gpu reset might
+	 * be required. And cstate disabled is a prerequisite for
+	 * that(gpu reset).
+	 */
+	if (amdgpu_dpm_set_df_cstate(adev, DF_CSTATE_DISALLOW))
+		dev_warn(adev->dev, "Failed to disallow df cstate");
+

This looks more like a firmware bug. Driver sends the Unload message to

FW.

Quoted 2 lines
Quoted 1 line

In that case FW should disable all features including C-state.

Driver does not send the Unload message. We want PMFM alive and ready

for handling possible gpu reset on reloading.

Quoted 1 line
Quoted 6 lines

Actually, soc21_need_reset_on_init code itself has a bug. PSP won't get unloaded by default on ring destruction. Even if PSP stops, it could just keep the heartbeat value as non-zero (just that it won't increment).

Probably, that needs to be fixed first rather than keeping PMFW alive for a reset.

As I remembered, the change(asic reset during reloading) seemed introduced to address some sriov issues. @Deucher, Alexander might share more backgrounds about this.
To be honest, I'm not a fan of this(perform asic reset during reloading).

Evan

Quoted 13 lines

Thanks,
Lijo

Quoted 9 lines

BR
Evan

Quoted 7 lines

Thanks,
Lijo

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
   	amdgpu_amdkfd_suspend(adev, false);
 
   	/* Workaroud for ASICs need to disable SMC first */
#5 lore raw

[AMD Official Use Only - General]

Quoted 84 lines

-----Original Message-----
From: Quan, Evan <[email protected]>
Sent: Thursday, March 2, 2023 4:31 AM
To: Lazar, Lijo <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

[AMD Official Use Only - General]

Quoted 10 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, March 2, 2023 5:21 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

Quoted 9 lines
Quoted 8 lines · Evan

[AMD Official Use Only - General]

Quoted 4 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, March 2, 2023 4:28 PM
To: Quan, Evan <[email protected]>; amd-

[email protected]

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines

Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

Quoted 16 lines · Evan Quan

Gpu reset might be needed during driver reloading. To guard that(gpu
reset) work, df cstate needs to be disabled properly.

Change-Id I5c074c265c0b08a67b6934ae1ad9aa3fed245461
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 9 +++++++++
   1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 51bbeaa1f311..3c854461ef32 100644
@@ -2816,6 +2816,15 @@ static int
Quoted 1 line

amdgpu_device_ip_fini_early(struct

amdgpu_device *adev)

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

amdgpu_device_set_pg_state(adev,

AMD_PG_STATE_UNGATE);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

amdgpu_device_set_cg_state(adev,

AMD_CG_STATE_UNGATE);

Quoted 15 lines
Quoted 13 lines
Quoted 13 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_fini_early(struct amdgpu_device *adev) · line 2827

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +9 -0
+	/*
+	 * Get df cstate disabled properly on driver unloading.
+	 * Since on the succeeding driver reloading, gpu reset might
+	 * be required. And cstate disabled is a prerequisite for
+	 * that(gpu reset).
+	 */
+	if (amdgpu_dpm_set_df_cstate(adev, DF_CSTATE_DISALLOW))
+		dev_warn(adev->dev, "Failed to disallow df cstate");
+

This looks more like a firmware bug. Driver sends the Unload message to

FW.

Quoted 1 line
Quoted 1 line

In that case FW should disable all features including C-state.

Quoted 8 lines
Quoted 2 lines

Driver does not send the Unload message. We want PMFM alive and ready

for handling possible gpu reset on reloading.

Quoted 1 line

Actually, soc21_need_reset_on_init code itself has a bug. PSP won't get unloaded by default on ring destruction. Even if PSP stops, it could just keep the heartbeat value as non-zero (just that it won't

Quoted 8 lines

increment).

Quoted 3 lines

Probably, that needs to be fixed first rather than keeping PMFW alive for a reset.

As I remembered, the change(asic reset during reloading) seemed introduced to address some sriov issues.
@Deucher, Alexander might share more backgrounds about this. To be honest, I'm not a fan of this(perform asic reset during reloading).

I'm open to doing it a better way. We did it for two reasons:
1. often times the device was left in a weird state after the driver unload/VM killed. Etc. We needed a way to put the device into a known good state so the driver could re-initialize it. Plus, IIRC, on some of the older ASICS, once the SMU or PSP firmware was loaded, there was no way to reload it without a reset so you needed one anyway. This is largely why we have to reset for S4 as well.
2. Some large servers didn't power off PCI devices on reboots to save time. This left the devices with whatever state they had before the system was rebooted which led to driver initialization problems on subsequent boots because the device was in an unknown state.

If there is a better way to handle these situations, I'm all for it.

Alex

Quoted 15 lines

Evan

Quoted 13 lines

Thanks,
Lijo

Quoted 9 lines

BR
Evan

Quoted 7 lines

Thanks,
Lijo

Quoted 3 lines
   	amdgpu_amdkfd_suspend(adev, false);
   	/* Workaroud for ASICs need to disable SMC first */
#6 lore raw
Quoted 95 lines · Alexander

[AMD Official Use Only - General]

Quoted 84 lines

-----Original Message-----
From: Quan, Evan <[email protected]>
Sent: Thursday, March 2, 2023 4:31 AM
To: Lazar, Lijo <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

[AMD Official Use Only - General]

Quoted 10 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, March 2, 2023 5:21 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

Quoted 9 lines
Quoted 8 lines · Evan

[AMD Official Use Only - General]

Quoted 4 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, March 2, 2023 4:28 PM
To: Quan, Evan <[email protected]>; amd-

[email protected]

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines

Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

Quoted 16 lines · Evan Quan

Gpu reset might be needed during driver reloading. To guard that(gpu
reset) work, df cstate needs to be disabled properly.

Change-Id I5c074c265c0b08a67b6934ae1ad9aa3fed245461
---
    drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 9 +++++++++
    1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 51bbeaa1f311..3c854461ef32 100644
@@ -2816,6 +2816,15 @@ static int
Quoted 1 line

amdgpu_device_ip_fini_early(struct

amdgpu_device *adev)

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

amdgpu_device_set_pg_state(adev,

AMD_PG_STATE_UNGATE);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

amdgpu_device_set_cg_state(adev,

AMD_CG_STATE_UNGATE);

Quoted 15 lines
Quoted 13 lines
Quoted 13 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_fini_early(struct amdgpu_device *adev) · line 2827

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +9 -0
+	/*
+	 * Get df cstate disabled properly on driver unloading.
+	 * Since on the succeeding driver reloading, gpu reset might
+	 * be required. And cstate disabled is a prerequisite for
+	 * that(gpu reset).
+	 */
+	if (amdgpu_dpm_set_df_cstate(adev, DF_CSTATE_DISALLOW))
+		dev_warn(adev->dev, "Failed to disallow df cstate");
+

This looks more like a firmware bug. Driver sends the Unload message to

FW.

Quoted 1 line
Quoted 1 line

In that case FW should disable all features including C-state.

Quoted 8 lines
Quoted 2 lines

Driver does not send the Unload message. We want PMFM alive and ready

for handling possible gpu reset on reloading.

Quoted 1 line

Actually, soc21_need_reset_on_init code itself has a bug. PSP won't get unloaded by default on ring destruction. Even if PSP stops, it could just keep the heartbeat value as non-zero (just that it won't

Quoted 8 lines

increment).

Quoted 3 lines

Probably, that needs to be fixed first rather than keeping PMFW alive for a reset.

As I remembered, the change(asic reset during reloading) seemed introduced to address some sriov issues.
@Deucher, Alexander might share more backgrounds about this. To be honest, I'm not a fan of this(perform asic reset during reloading).

Quoted 6 lines

I'm open to doing it a better way. We did it for two reasons:
1. often times the device was left in a weird state after the driver unload/VM killed. Etc. We needed a way to put the device into a known good state so the driver could re-initialize it. Plus, IIRC, on some of the older ASICS, once the SMU or PSP firmware was loaded, there was no way to reload it without a reset so you needed one anyway. This is largely why we have to reset for S4 as well.
2. Some large servers didn't power off PCI devices on reboots to save time. This left the devices with whatever state they had before the system was rebooted which led to driver initialization problems on subsequent boots because the device was in an unknown state.

If there is a better way to handle these situations, I'm all for it.

Are those cases valid still? We have this for GFX9 - reset done only for pass through. And some of the GFX9 ASICs are used in large servers.

        /* Just return false for soc15 GPUs.  Reset does not seem to
         * be necessary.
         */
        if (!amdgpu_passthrough(adev))
                return false;

Thanks,
Lijo

Quoted 18 lines

Alex

Quoted 15 lines

Evan

Quoted 13 lines

Thanks,
Lijo

Quoted 9 lines

BR
Evan

Quoted 7 lines

Thanks,
Lijo

Quoted 3 lines
    	amdgpu_amdkfd_suspend(adev, false);

    	/* Workaroud for ASICs need to disable SMC first */
#7 lore raw
Quoted 98 lines · Lijo
Quoted 95 lines · Alexander

[AMD Official Use Only - General]

Quoted 92 lines

-----Original Message-----
From: Quan, Evan <[email protected]>
Sent: Thursday, March 2, 2023 4:31 AM
To: Lazar, Lijo <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

[AMD Official Use Only - General]

Quoted 10 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, March 2, 2023 5:21 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

Quoted 9 lines
Quoted 8 lines · Evan

[AMD Official Use Only - General]

Quoted 4 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, March 2, 2023 4:28 PM
To: Quan, Evan <[email protected]>; amd-

[email protected]

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines

Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

Quoted 16 lines · Evan Quan

Gpu reset might be needed during driver reloading. To guard that(gpu
reset) work, df cstate needs to be disabled properly.

Change-Id I5c074c265c0b08a67b6934ae1ad9aa3fed245461

---
    drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 9 +++++++++

    1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 51bbeaa1f311..3c854461ef32 100644
@@ -2816,6 +2816,15 @@ static int
Quoted 1 line

amdgpu_device_ip_fini_early(struct

amdgpu_device *adev)

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

        amdgpu_device_set_pg_state(adev,

AMD_PG_STATE_UNGATE);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

        amdgpu_device_set_cg_state(adev,

AMD_CG_STATE_UNGATE);

Quoted 15 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

+    /*
+     * Get df cstate disabled properly on driver unloading. +     * Since on the succeeding driver reloading, gpu reset might +     * be required. And cstate disabled is a prerequisite for +     * that(gpu reset).
+     */
+    if (amdgpu_dpm_set_df_cstate(adev, DF_CSTATE_DISALLOW)) +        dev_warn(adev->dev, "Failed to disallow df cstate"); +

Quoted 2 lines
Quoted 2 lines

This looks more like a firmware bug. Driver sends the Unload message to

FW.

Quoted 1 line
Quoted 1 line

In that case FW should disable all features including C-state.

Quoted 8 lines
Quoted 2 lines

Driver does not send the Unload message. We want PMFM alive and ready

for handling possible gpu reset on reloading.

Quoted 1 line

Actually, soc21_need_reset_on_init code itself has a bug. PSP won't get unloaded by default on ring destruction. Even if PSP stops, it could just keep the heartbeat value as non-zero (just that it won't

increment).

Quoted 3 lines

Probably, that needs to be fixed first rather than keeping PMFW alive for a reset.

As I remembered, the change(asic reset during reloading) seemed introduced to address some sriov issues.
@Deucher, Alexander might share more backgrounds about this. To be honest, I'm not a fan of this(perform asic reset during reloading).

Quoted 5 lines
Quoted 5 lines

I'm open to doing it a better way.  We did it for two reasons:
1. often times the device was left in a weird state after the driver unload/VM killed. Etc.  We needed a way to put the device into a known good state so the driver could re-initialize it.  Plus, IIRC, on some of the older ASICS, once the SMU or PSP firmware was loaded, there was no way to reload it without a reset so you needed one anyway.  This is largely why we have to reset for S4 as well.
2. Some large servers didn't power off PCI devices on reboots to save time.  This left the devices with whatever state they had before the system was rebooted which led to driver initialization problems on subsequent boots because the device was in an unknown state.

If there is a better way to handle these situations, I'm all for it.

Hi Alex,

There is a part of FW running to handle generic reset requests on SOC21 SOCs. Can we remove the reset-on-reload for soc21 SOCs, unload PMFW as usual and see how it goes?

Thanks,
Lijo

Quoted 31 lines
Quoted 1 line

Are those cases valid still? We have this for GFX9 - reset done only for pass through. And some of the GFX9 ASICs are used in large servers.

        /* Just return false for soc15 GPUs.  Reset does not seem to
         * be necessary.
         */
        if (!amdgpu_passthrough(adev))
                return false;

Thanks,
Lijo

Quoted 18 lines

Alex

Quoted 15 lines

Evan

Quoted 13 lines

Thanks,
Lijo

Quoted 9 lines

BR
Evan

Quoted 7 lines

Thanks,
Lijo

Quoted 3 lines

        amdgpu_amdkfd_suspend(adev, false);

        /* Workaroud for ASICs need to disable SMC first */

#8 lore raw

[AMD Official Use Only - General]

Quoted 125 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, March 6, 2023 12:42 AM
To: Deucher, Alexander <[email protected]>; Quan, Evan <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

Quoted 13 lines · Lijo
Quoted 10 lines · Alexander

[AMD Official Use Only - General]

Quoted 8 lines

-----Original Message-----
From: Quan, Evan <[email protected]>
Sent: Thursday, March 2, 2023 4:31 AM
To: Lazar, Lijo <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

[AMD Official Use Only - General]

Quoted 4 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, March 2, 2023 5:21 PM
To: Quan, Evan <[email protected]>; amd-

[email protected]

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 6 lines

Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

Quoted 9 lines
Quoted 8 lines · Evan

[AMD Official Use Only - General]

Quoted 4 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, March 2, 2023 4:28 PM
To: Quan, Evan <[email protected]>; amd-

[email protected]

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: disable cstate properly for driver reloading scenario

On 3/2/2023 12:28 PM, Evan Quan wrote:

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

Gpu reset might be needed during driver reloading. To guard that(gpu
reset) work, df cstate needs to be disabled properly.

Change-Id I5c074c265c0b08a67b6934ae1ad9aa3fed245461

---
    drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 9

+++++++++

Quoted 60 lines
Quoted 60 lines
Quoted 40 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 9 lines
    1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 51bbeaa1f311..3c854461ef32 100644
@@ -2816,6 +2816,15 @@ static int

amdgpu_device_ip_fini_early(struct

amdgpu_device *adev)

Quoted 1 line

        amdgpu_device_set_pg_state(adev,

AMD_PG_STATE_UNGATE);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

        amdgpu_device_set_cg_state(adev,

AMD_CG_STATE_UNGATE);

Quoted 16 lines
Quoted 14 lines
Quoted 14 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

Quoted 11 lines

+    /*
+     * Get df cstate disabled properly on driver unloading. +     * Since on the succeeding driver reloading, gpu reset

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7 -0
+might
+     * be required. And cstate disabled is a prerequisite for
+     * that(gpu reset).
+     */
+    if (amdgpu_dpm_set_df_cstate(adev, DF_CSTATE_DISALLOW))
+        dev_warn(adev->dev, "Failed to disallow df cstate");
+

This looks more like a firmware bug. Driver sends the Unload message to

FW.

Quoted 1 line
Quoted 1 line

In that case FW should disable all features including C-state.

Quoted 8 lines
Quoted 2 lines

Driver does not send the Unload message. We want PMFM alive and ready

for handling possible gpu reset on reloading.

Quoted 1 line

Actually, soc21_need_reset_on_init code itself has a bug. PSP won't get unloaded by default on ring destruction. Even if PSP stops, it could just keep the heartbeat value as non-zero (just that it won't

increment).

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

Probably, that needs to be fixed first rather than keeping PMFW alive for a reset.

As I remembered, the change(asic reset during reloading) seemed introduced to address some sriov issues.
@Deucher, Alexander might share more backgrounds about this. To be honest, I'm not a fan of this(perform asic reset during reloading).

I'm open to doing it a better way.  We did it for two reasons:
1. often times the device was left in a weird state after the driver unload/VM killed. Etc.  We needed a way to put the device into a known good state so the driver could re-initialize it.  Plus, IIRC, on some of the older ASICS, once the SMU or PSP firmware was loaded, there was no way to reload it without a reset so you needed one anyway.  This is largely why we have to reset for S4 as well.
2. Some large servers didn't power off PCI devices on reboots to save time.  This left the devices with whatever state they had before the system was rebooted which led to driver initialization problems on subsequent boots because the device was in an unknown state.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

If there is a better way to handle these situations, I'm all for it.

Hi Alex,

There is a part of FW running to handle generic reset requests on SOC21 SOCs. Can we remove the reset-on-reload for soc21 SOCs, unload PMFW as usual and see how it goes?

Sure.

Alex

Quoted 36 lines

Thanks,
Lijo

Quoted 32 lines
Quoted 1 line

Are those cases valid still? We have this for GFX9 - reset done only for pass through. And some of the GFX9 ASICs are used in large servers.

        /* Just return false for soc15 GPUs.  Reset does not seem to
         * be necessary.
         */
        if (!amdgpu_passthrough(adev))
                return false;

Thanks,
Lijo

Quoted 18 lines

Alex

Quoted 15 lines

Evan

Quoted 13 lines

Thanks,
Lijo

Quoted 9 lines

BR
Evan

Quoted 7 lines

Thanks,
Lijo

Quoted 3 lines

        amdgpu_amdkfd_suspend(adev, false);

        /* Workaroud for ASICs need to disable SMC first */