Skip to contentSkip to conversation

drm/amgpu: Check return value of amdgpu_device_baco_enter/exit

PATCH In review Ma Jun 3 participants 4 messages Feb 29, 2024

Subsystems (2)
lore
Share & tools
lore

Ma Jun

author
#0 lore raw

PATCH v2 1/1 drm/amgpu: Check return value of amdgpu_device_baco_enter/exit

Check return value of amdgpu_device_baco_enter/exit and print warning message because these errors may cause runtime resume failure

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 29 ++++++++++++++++------
 1 file changed, 22 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +22 -7
index e68bd6f8a6a4..4928b588cd12 100644
@@ -6000,15 +6000,24 @@ int amdgpu_device_baco_enter(struct drm_device *dev)
 {
 	struct amdgpu_device *adev = drm_to_adev(dev);
 	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
+	int ret = 0;
 
-	if (!amdgpu_device_supports_baco(dev))
-		return -ENOTSUPP;
+	if (!amdgpu_device_supports_baco(dev)) {
+		ret = -ENOTSUPP;
+		goto baco_error;
+	}
 
 	if (ras && adev->ras_enabled &&
 	    adev->nbio.funcs->enable_doorbell_interrupt)
 		adev->nbio.funcs->enable_doorbell_interrupt(adev, false);
 
-	return amdgpu_dpm_baco_enter(adev);
+	ret = amdgpu_dpm_baco_enter(adev);
+
+baco_error:
+	if (ret)
+		dev_warn(adev->dev, "warning: device fails to enter baco. ret=%d\n", ret);
+
+	return ret;
 }
 
 int amdgpu_device_baco_exit(struct drm_device *dev)
@@ -6017,12 +6026,14 @@ int amdgpu_device_baco_exit(struct drm_device *dev)
 	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
 	int ret = 0;
 
-	if (!amdgpu_device_supports_baco(dev))
-		return -ENOTSUPP;
+	if (!amdgpu_device_supports_baco(dev)) {
+		ret = -ENOTSUPP;
+		goto baco_error;
+	}
 
 	ret = amdgpu_dpm_baco_exit(adev);
 	if (ret)
-		return ret;
+		goto baco_error;
 
 	if (ras && adev->ras_enabled &&
 	    adev->nbio.funcs->enable_doorbell_interrupt)
@@ -6032,7 +6043,11 @@ int amdgpu_device_baco_exit(struct drm_device *dev)
 	    adev->nbio.funcs->clear_doorbell_interrupt)
 		adev->nbio.funcs->clear_doorbell_interrupt(adev);
 
-	return 0;
+baco_error:
+	if (ret)
+		dev_warn(adev->dev, "warning: device fails to exit from baco. ret=%d\n", ret);
+
+	return ret;
 }
 
 /**
Signature · 1 line
2.34.1
#1 lore raw
Quoted 26 lines · Ma Jun

Check return value of amdgpu_device_baco_enter/exit and print warning message because these errors may cause runtime resume failure

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 29 ++++++++++++++++------
 1 file changed, 22 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -2
index e68bd6f8a6a4..4928b588cd12 100644
@@ -6000,15 +6000,24 @@ int amdgpu_device_baco_enter(struct drm_device *dev)
 {
 	struct amdgpu_device *adev = drm_to_adev(dev);
 	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
+	int ret = 0;
 
-	if (!amdgpu_device_supports_baco(dev))
-		return -ENOTSUPP;
+	if (!amdgpu_device_supports_baco(dev)) {
+		ret = -ENOTSUPP;
+		goto baco_error;
+	}
 
 	if (ras && adev->ras_enabled &&

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_baco_enter(struct drm_device *dev) · line 6019

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6 -1
 	    adev->nbio.funcs->enable_doorbell_interrupt)
 		adev->nbio.funcs->enable_doorbell_interrupt(adev, false);
 
-	return amdgpu_dpm_baco_enter(adev);
+	ret = amdgpu_dpm_baco_enter(adev);
+
+baco_error:
+	if (ret)
+		dev_warn(adev->dev, "warning: device fails to enter baco. ret=%d\n", ret);
+

This doesn't look like a real case, moreover the warning message is misleading. If the device doesn't support baco, driver is not supposed to call it for runpm purpose -
https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c#L2664

Thanks,
Lijo

Quoted 35 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +11 -4
+	return ret;
 }
 
 int amdgpu_device_baco_exit(struct drm_device *dev)
@@ -6017,12 +6026,14 @@ int amdgpu_device_baco_exit(struct drm_device *dev)
 	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
 	int ret = 0;
 
-	if (!amdgpu_device_supports_baco(dev))
-		return -ENOTSUPP;
+	if (!amdgpu_device_supports_baco(dev)) {
+		ret = -ENOTSUPP;
+		goto baco_error;
+	}
 
 	ret = amdgpu_dpm_baco_exit(adev);
 	if (ret)
-		return ret;
+		goto baco_error;
 
 	if (ras && adev->ras_enabled &&
 	    adev->nbio.funcs->enable_doorbell_interrupt)
@@ -6032,7 +6043,11 @@ int amdgpu_device_baco_exit(struct drm_device *dev)
 	    adev->nbio.funcs->clear_doorbell_interrupt)
 		adev->nbio.funcs->clear_doorbell_interrupt(adev);
 
-	return 0;
+baco_error:
+	if (ret)
+		dev_warn(adev->dev, "warning: device fails to exit from baco. ret=%d\n", ret);
+
+	return ret;
 }
 
 /**
#2 lore raw

Hi Lijo,

Quoted 32 lines · Lijo
Quoted 29 lines · Ma Jun

Check return value of amdgpu_device_baco_enter/exit and print warning message because these errors may cause runtime resume failure

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 29 ++++++++++++++++------
 1 file changed, 22 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -2
index e68bd6f8a6a4..4928b588cd12 100644
@@ -6000,15 +6000,24 @@ int amdgpu_device_baco_enter(struct drm_device *dev)
 {
 	struct amdgpu_device *adev = drm_to_adev(dev);
 	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
+	int ret = 0;
 
-	if (!amdgpu_device_supports_baco(dev))
-		return -ENOTSUPP;
+	if (!amdgpu_device_supports_baco(dev)) {
+		ret = -ENOTSUPP;
+		goto baco_error;
+	}
 
 	if (ras && adev->ras_enabled &&
 	    adev->nbio.funcs->enable_doorbell_interrupt)
 		adev->nbio.funcs->enable_doorbell_interrupt(adev, false);
 
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_baco_enter(struct drm_device *dev) · line 6019

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6 -1
-	return amdgpu_dpm_baco_enter(adev);
+	ret = amdgpu_dpm_baco_enter(adev);
+
+baco_error:
+	if (ret)
+		dev_warn(adev->dev, "warning: device fails to enter baco. ret=%d\n", ret);
+

This doesn't look like a real case, moreover the warning message is

In fact this is a case that actually happened.

When amdgpu_device_supports_baco returns with error because of some reasons, device will enter runtime suspend without calling the amdgpu_device_baco_enter() and without any warning message being printed. Then, device is usually fails to resume.
So, I add this message as a warning to help us find the real reason.

Quoted 4 lines

misleading. If the device doesn't support baco, driver is not supposed to call it for runpm purpose -
https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c#L2664

I changed this code in another patch.
https://lists.freedesktop.org/archives/amd-gfx/2024-February/104929.html

Regards,
Ma Jun

Quoted 38 lines

Thanks,
Lijo

Quoted 35 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +11 -4
+	return ret;
 }
 
 int amdgpu_device_baco_exit(struct drm_device *dev)
@@ -6017,12 +6026,14 @@ int amdgpu_device_baco_exit(struct drm_device *dev)
 	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
 	int ret = 0;
 
-	if (!amdgpu_device_supports_baco(dev))
-		return -ENOTSUPP;
+	if (!amdgpu_device_supports_baco(dev)) {
+		ret = -ENOTSUPP;
+		goto baco_error;
+	}
 
 	ret = amdgpu_dpm_baco_exit(adev);
 	if (ret)
-		return ret;
+		goto baco_error;
 
 	if (ras && adev->ras_enabled &&
 	    adev->nbio.funcs->enable_doorbell_interrupt)
@@ -6032,7 +6043,11 @@ int amdgpu_device_baco_exit(struct drm_device *dev)
 	    adev->nbio.funcs->clear_doorbell_interrupt)
 		adev->nbio.funcs->clear_doorbell_interrupt(adev);
 
-	return 0;
+baco_error:
+	if (ret)
+		dev_warn(adev->dev, "warning: device fails to exit from baco. ret=%d\n", ret);
+
+	return ret;
 }
 
 /**
#3 lore raw
Quoted 53 lines · Jun

Hi Lijo,

Quoted 32 lines · Lijo
Quoted 29 lines · Ma Jun

Check return value of amdgpu_device_baco_enter/exit and print warning message because these errors may cause runtime resume failure

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 29 ++++++++++++++++------
 1 file changed, 22 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -2
index e68bd6f8a6a4..4928b588cd12 100644
@@ -6000,15 +6000,24 @@ int amdgpu_device_baco_enter(struct drm_device *dev)
 {
 	struct amdgpu_device *adev = drm_to_adev(dev);
 	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
+	int ret = 0;
 
-	if (!amdgpu_device_supports_baco(dev))
-		return -ENOTSUPP;
+	if (!amdgpu_device_supports_baco(dev)) {
+		ret = -ENOTSUPP;
+		goto baco_error;
+	}
 
 	if (ras && adev->ras_enabled &&
 	    adev->nbio.funcs->enable_doorbell_interrupt)
 		adev->nbio.funcs->enable_doorbell_interrupt(adev, false);
 
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_baco_enter(struct drm_device *dev) · line 6019

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6 -1
-	return amdgpu_dpm_baco_enter(adev);
+	ret = amdgpu_dpm_baco_enter(adev);
+
+baco_error:
+	if (ret)
+		dev_warn(adev->dev, "warning: device fails to enter baco. ret=%d\n", ret);
+

This doesn't look like a real case, moreover the warning message is

In fact this is a case that actually happened.

When amdgpu_device_supports_baco returns with error because of some reasons, device will enter runtime suspend without calling the amdgpu_device_baco_enter() and without any warning message being printed. Then, device is usually fails to resume.
So, I add this message as a warning to help us find the real reason.

Quoted 7 lines
Quoted 4 lines

misleading. If the device doesn't support baco, driver is not supposed to call it for runpm purpose -
https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c#L2664

I changed this code in another patch.
https://lists.freedesktop.org/archives/amd-gfx/2024-February/104929.html

Baco support checks are all based on cached software variables and not based on hardware interactions. So this is very unlikely. It might also be that driver really called baco entry, but even before baco entry happened a device usage is detected for which resume is called.

One other way to really check this is to check if baco exit is called when the software state is not really SMU_BACO_STATE_ENTER (applicable only for swsmu). Since baco entry is driver triggered, the imbalance shouldn't happen.

Thanks,
Lijo

Quoted 41 lines

Regards,
Ma Jun

Quoted 38 lines

Thanks,
Lijo

Quoted 35 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +11 -4
+	return ret;
 }
 
 int amdgpu_device_baco_exit(struct drm_device *dev)
@@ -6017,12 +6026,14 @@ int amdgpu_device_baco_exit(struct drm_device *dev)
 	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
 	int ret = 0;
 
-	if (!amdgpu_device_supports_baco(dev))
-		return -ENOTSUPP;
+	if (!amdgpu_device_supports_baco(dev)) {
+		ret = -ENOTSUPP;
+		goto baco_error;
+	}
 
 	ret = amdgpu_dpm_baco_exit(adev);
 	if (ret)
-		return ret;
+		goto baco_error;
 
 	if (ras && adev->ras_enabled &&
 	    adev->nbio.funcs->enable_doorbell_interrupt)
@@ -6032,7 +6043,11 @@ int amdgpu_device_baco_exit(struct drm_device *dev)
 	    adev->nbio.funcs->clear_doorbell_interrupt)
 		adev->nbio.funcs->clear_doorbell_interrupt(adev);
 
-	return 0;
+baco_error:
+	if (ret)
+		dev_warn(adev->dev, "warning: device fails to exit from baco. ret=%d\n", ret);
+
+	return ret;
 }
 
 /**