Skip to contentSkip to conversation

drm/amd: Add a helper to tell whether an IP block HW is enabled

PATCH In review Mario Limonciello 3 participants 11 messages Oct 14, 2025 – Oct 15, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 drm/amd: Add a helper to tell whether an IP block HW is enabled

There is already a helper for telling if a block is valid, but if IP handling wants to check if it's HW is enabled no such helper exists.

---
Cc: Harry Wentland <[email protected]>

 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 23 +++++++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index d8bb339d4ebd..17b3f00af756 100644
@@ -372,6 +372,8 @@ void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev,
 					    u64 *flags);
 int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
 				   enum amd_ip_block_type block_type);
+bool amdgpu_device_ip_is_hw(struct amdgpu_device *adev,
+			    enum amd_ip_block_type block_type);
 bool amdgpu_device_ip_is_valid(struct amdgpu_device *adev,
 			      enum amd_ip_block_type block_type);
 int amdgpu_ip_block_suspend(struct amdgpu_ip_block *ip_block);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +22 -1
index c7c999ae2a28..a431ddeb540a 100644
@@ -2387,7 +2387,7 @@ int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
 }
 
 /**
- * amdgpu_device_ip_is_valid - is the hardware IP enabled
+ * amdgpu_device_ip_is_hw - is the hardware IP enabled
  *
  * @adev: amdgpu_device pointer
  * @block_type: Type of hardware IP (SMU, GFX, UVD, etc.)
@@ -2395,6 +2395,27 @@ int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
  * Check if the hardware IP is enable or not.
  * Returns true if it the IP is enable, false if not.
  */
+bool amdgpu_device_ip_is_hw(struct amdgpu_device *adev,
+			    enum amd_ip_block_type block_type)
+{
+	int i;
+
+	for (i = 0; i < adev->num_ip_blocks; i++) {
+		if (adev->ip_blocks[i].version->type == block_type)
+			return adev->ip_blocks[i].status.hw;
+	}
+	return false;
+}
+
+/**
+ * amdgpu_device_ip_is_valid - is the hardware IP valid
+ *
+ * @adev: amdgpu_device pointer
+ * @block_type: Type of hardware IP (SMU, GFX, UVD, etc.)
+ *
+ * Check if the hardware IP is valid or not.
+ * Returns true if it the IP is valid, false if not.
+ */
 bool amdgpu_device_ip_is_valid(struct amdgpu_device *adev,
 			       enum amd_ip_block_type block_type)
 {
Signature · 1 line
2.49.0
#1 lore raw

PATCH v2 2/2 drm/amd/display: Check if display HW is enabled in amdgpu_dm_atomic_check()

[Why]
If userspace hasn't frozen user processes (like systemd does with user.slice) then an aborted hibernate could give control back to userspace before display hardware is resumed. IoW an atomic commit could be done while the hardware is in D3, which could hang a system.

[How]
Add a check whether the IP block hardware is ready to the atomic check handler and return a failure. Userspace shouldn't do an atomic commit if the atomic check fails.

---
Cc: Harry Wentland <[email protected]>
v2:
* Return -EBUSY instead (Harry)

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5 -0
index 6446ec6c21d4..f5cd9982af99 100644
@@ -12010,6 +12010,11 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
 
 	trace_amdgpu_dm_atomic_check_begin(state);
 
+	if (WARN_ON(unlikely(!amdgpu_device_ip_is_hw(adev, AMD_IP_BLOCK_TYPE_DCE)))) {
+		ret = -EBUSY;
+		goto fail;
+	}
+
 	ret = drm_atomic_helper_check_modeset(dev, state);
 	if (ret) {
 		drm_dbg_atomic(dev, "drm_atomic_helper_check_modeset() failed\n");
Signature · 1 line
2.49.0
maintainer Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] drm/amd/display: Check if display HW is enabled in amdgpu_dm_atomic_check()

Quoted 11 lines · Mario Limonciello

[Why]
If userspace hasn't frozen user processes (like systemd does with user.slice) then an aborted hibernate could give control back to userspace before display hardware is resumed. IoW an atomic commit could be done while the hardware is in D3, which could hang a system.

[How]
Add a check whether the IP block hardware is ready to the atomic check handler and return a failure. Userspace shouldn't do an atomic commit if the atomic check fails.

Quoted 4 lines

---
Cc: Harry Wentland <[email protected]>

Series is

Harry

Quoted 22 lines

v2:
* Return -EBUSY instead (Harry)

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5 -0
index 6446ec6c21d4..f5cd9982af99 100644
@@ -12010,6 +12010,11 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
 
 	trace_amdgpu_dm_atomic_check_begin(state);
 
+	if (WARN_ON(unlikely(!amdgpu_device_ip_is_hw(adev, AMD_IP_BLOCK_TYPE_DCE)))) {
+		ret = -EBUSY;
+		goto fail;
+	}
+
 	ret = drm_atomic_helper_check_modeset(dev, state);
 	if (ret) {
 		drm_dbg_atomic(dev, "drm_atomic_helper_check_modeset() failed\n");
#3 lore raw

Re: [PATCH v2 2/2] drm/amd/display: Check if display HW is enabled in amdgpu_dm_atomic_check()

In reply to Mario Limonciello
Quoted 6 lines · Mario Limonciello

[Why]
If userspace hasn't frozen user processes (like systemd does with user.slice) then an aborted hibernate could give control back to userspace before display hardware is resumed. IoW an atomic commit could be done while the hardware is in D3, which could hang a system.

Is there any way to prevent this altogether? This seems like a recipe for trouble for any driver.

Alex

Quoted 35 lines

[How]
Add a check whether the IP block hardware is ready to the atomic check handler and return a failure. Userspace shouldn't do an atomic commit if the atomic check fails.

---
Cc: Harry Wentland <[email protected]>
v2:
* Return -EBUSY instead (Harry)

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5 -1
index 6446ec6c21d4..f5cd9982af99 100644
@@ -12010,6 +12010,11 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
 
        trace_amdgpu_dm_atomic_check_begin(state);
 
+       if (WARN_ON(unlikely(!amdgpu_device_ip_is_hw(adev, AMD_IP_BLOCK_TYPE_DCE)))) {
+               ret = -EBUSY;
+               goto fail;
+       }
+
        ret = drm_atomic_helper_check_modeset(dev, state);
        if (ret) {
                drm_dbg_atomic(dev, "drm_atomic_helper_check_modeset() failed\n");
--

2.49.0

#4 lore raw

Re: [PATCH v2 2/2] drm/amd/display: Check if display HW is enabled in amdgpu_dm_atomic_check()

Quoted 10 lines · Alex Deucher
Quoted 6 lines · Mario Limonciello

[Why]
If userspace hasn't frozen user processes (like systemd does with user.slice) then an aborted hibernate could give control back to userspace before display hardware is resumed. IoW an atomic commit could be done while the hardware is in D3, which could hang a system.

Is there any way to prevent this altogether?

The obvious way is that userspace should be freezing user processes. That's what systemd does.

Quoted 2 lines

This seems like a recipe
for trouble for any driver.

If we want to uplevel this kind of check I think we would need some helper to report hardware status into drm and drm would have to call that.

Most distros use systemd, and this only happened in an aborted hibernate. I guess I'd like to see how much this warning actually comes up before deciding if all that plumbing is worth it.

Quoted 38 lines

Alex

Quoted 35 lines

[How]
Add a check whether the IP block hardware is ready to the atomic check handler and return a failure. Userspace shouldn't do an atomic commit if the atomic check fails.

---
Cc: Harry Wentland <[email protected]>
v2:
* Return -EBUSY instead (Harry)

---
  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5 -1
index 6446ec6c21d4..f5cd9982af99 100644
@@ -12010,6 +12010,11 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
 
         trace_amdgpu_dm_atomic_check_begin(state);
 
+       if (WARN_ON(unlikely(!amdgpu_device_ip_is_hw(adev, AMD_IP_BLOCK_TYPE_DCE)))) {
+               ret = -EBUSY;
+               goto fail;
+       }
+
         ret = drm_atomic_helper_check_modeset(dev, state);
         if (ret) {
                 drm_dbg_atomic(dev, "drm_atomic_helper_check_modeset() failed\n");
--

2.49.0

maintainer
#5 lore raw

Re: [PATCH v2 2/2] drm/amd/display: Check if display HW is enabled in amdgpu_dm_atomic_check()

Quoted 14 lines · Mario Limonciello
Quoted 10 lines · Alex Deucher
Quoted 6 lines · Mario Limonciello

[Why]
If userspace hasn't frozen user processes (like systemd does with user.slice) then an aborted hibernate could give control back to userspace before display hardware is resumed.  IoW an atomic commit could be done while the hardware is in D3, which could hang a system.

Is there any way to prevent this altogether?

Quoted 8 lines

The obvious way is that userspace should be freezing user processes. That's what systemd does.

Quoted 2 lines

This seems like a recipe
for trouble for any driver.

If we want to uplevel this kind of check I think we would need some helper to report hardware status into drm and drm would have to call that.

Most distros use systemd, and this only happened in an aborted hibernate.  I guess I'd like to see how much this warning actually comes up before deciding if all that plumbing is worth it.

I was briefly thinking about a generic solution as well and don't think it's worth it at this point. This is mostly about internal driver/HW state.

Harry

Quoted 39 lines
Quoted 38 lines

Alex

Quoted 35 lines

[How]
Add a check whether the IP block hardware is ready to the atomic check handler and return a failure. Userspace shouldn't do an atomic commit if the atomic check fails.

---
Cc: Harry Wentland <[email protected]>
v2:
  * Return -EBUSY instead (Harry)
---
  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 5 +++++

  1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5 -0
index 6446ec6c21d4..f5cd9982af99 100644
@@ -12010,6 +12010,11 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
 
          trace_amdgpu_dm_atomic_check_begin(state);
 
+       if (WARN_ON(unlikely(!amdgpu_device_ip_is_hw(adev, AMD_IP_BLOCK_TYPE_DCE)))) {
+               ret = -EBUSY;
+               goto fail;
+       }
+
          ret = drm_atomic_helper_check_modeset(dev, state);
          if (ret) {
                  drm_dbg_atomic(dev, "drm_atomic_helper_check_modeset() failed\n");
Signature · 1 line
2.49.0
#6 lore raw

Re: [PATCH v2 2/2] drm/amd/display: Check if display HW is enabled in amdgpu_dm_atomic_check()

Quoted 23 lines · Harry Wentland
Quoted 19 lines · Mario Limonciello
Quoted 10 lines · Alex Deucher
Quoted 6 lines · Mario Limonciello

[Why]
If userspace hasn't frozen user processes (like systemd does with user.slice) then an aborted hibernate could give control back to userspace before display hardware is resumed. IoW an atomic commit could be done while the hardware is in D3, which could hang a system.

Is there any way to prevent this altogether?

The obvious way is that userspace should be freezing user processes. That's what systemd does.

Quoted 2 lines

This seems like a recipe
for trouble for any driver.

Quoted 7 lines
Quoted 3 lines

If we want to uplevel this kind of check I think we would need some helper to report hardware status into drm and drm would have to call that.

Most distros use systemd, and this only happened in an aborted hibernate. I guess I'd like to see how much this warning actually comes up before deciding if all that plumbing is worth it.

I was briefly thinking about a generic solution as well and don't think it's worth it at this point. This is mostly about internal driver/HW state.

Allowing userspace to be running while the kernel is either entering or exiting suspend or hibernation is a recipe for problems. It seems to me that the kernel should stop userspace before it tries to do any of this and only restores it when everything has resumed. Having userspace stop itself seems broken by design. Applications can allocate memory or call IOCTLs into any driver which may not be functional at that point in time, or depending on the timing, the user's state is lost because they did something to it after the kernel already created the hibernation image. Fixes like this seem like playing wack-a-mole. It might be the GPU driver today, but it might be a usb driver tomorrow.

Alex

Quoted 43 lines

Harry

Quoted 39 lines
Quoted 38 lines

Alex

Quoted 35 lines

[How]
Add a check whether the IP block hardware is ready to the atomic check handler and return a failure. Userspace shouldn't do an atomic commit if the atomic check fails.

---
Cc: Harry Wentland <[email protected]>
v2:
* Return -EBUSY instead (Harry)

---
  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5 -1
index 6446ec6c21d4..f5cd9982af99 100644
@@ -12010,6 +12010,11 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
 
         trace_amdgpu_dm_atomic_check_begin(state);
 
+       if (WARN_ON(unlikely(!amdgpu_device_ip_is_hw(adev, AMD_IP_BLOCK_TYPE_DCE)))) {
+               ret = -EBUSY;
+               goto fail;
+       }
+
         ret = drm_atomic_helper_check_modeset(dev, state);
         if (ret) {
                 drm_dbg_atomic(dev, "drm_atomic_helper_check_modeset() failed\n");
--

2.49.0

#7 lore raw

Re: [PATCH v2 2/2] drm/amd/display: Check if display HW is enabled in amdgpu_dm_atomic_check()

Quoted 32 lines · Alex Deucher
Quoted 23 lines · Harry Wentland
Quoted 19 lines · Mario Limonciello
Quoted 10 lines · Alex Deucher
Quoted 6 lines · Mario Limonciello

[Why]
If userspace hasn't frozen user processes (like systemd does with user.slice) then an aborted hibernate could give control back to userspace before display hardware is resumed. IoW an atomic commit could be done while the hardware is in D3, which could hang a system.

Is there any way to prevent this altogether?

The obvious way is that userspace should be freezing user processes. That's what systemd does.

Quoted 2 lines

This seems like a recipe
for trouble for any driver.

Quoted 7 lines
Quoted 3 lines

If we want to uplevel this kind of check I think we would need some helper to report hardware status into drm and drm would have to call that.

Most distros use systemd, and this only happened in an aborted hibernate. I guess I'd like to see how much this warning actually comes up before deciding if all that plumbing is worth it.

I was briefly thinking about a generic solution as well and don't think it's worth it at this point. This is mostly about internal driver/HW state.

Quoted 11 lines

Allowing userspace to be running while the kernel is either entering or exiting suspend or hibernation is a recipe for problems. It seems to me that the kernel should stop userspace before it tries to do any of this and only restores it when everything has resumed. Having userspace stop itself seems broken by design. Applications can allocate memory or call IOCTLs into any driver which may not be functional at that point in time, or depending on the timing, the user's state is lost because they did something to it after the kernel already created the hibernation image. Fixes like this seem like playing wack-a-mole. It might be the GPU driver today, but it might be a usb driver tomorrow.

The kernel does freeze threads once you're far enough "into" the sequence.

I'll look through the aborted hibernate flow and see if I can find out why this is happening. Maybe they are thawing at the wrong time.

Quoted 46 lines

Alex

Quoted 43 lines

Harry

Quoted 39 lines
Quoted 38 lines

Alex

Quoted 35 lines

[How]
Add a check whether the IP block hardware is ready to the atomic check handler and return a failure. Userspace shouldn't do an atomic commit if the atomic check fails.

---
Cc: Harry Wentland <[email protected]>
v2:
* Return -EBUSY instead (Harry)

---
   drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 5 +++++
   1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5 -1
index 6446ec6c21d4..f5cd9982af99 100644
@@ -12010,6 +12010,11 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
 
          trace_amdgpu_dm_atomic_check_begin(state);
 
+       if (WARN_ON(unlikely(!amdgpu_device_ip_is_hw(adev, AMD_IP_BLOCK_TYPE_DCE)))) {
+               ret = -EBUSY;
+               goto fail;
+       }
+
          ret = drm_atomic_helper_check_modeset(dev, state);
          if (ret) {
                  drm_dbg_atomic(dev, "drm_atomic_helper_check_modeset() failed\n");
--

2.49.0

#8 lore raw

Re: [PATCH v2 2/2] drm/amd/display: Check if display HW is enabled in amdgpu_dm_atomic_check()

In reply to Harry Wentland
Quoted 24 lines · Harry Wentland
Quoted 21 lines · Mario Limonciello
Quoted 10 lines · Alex Deucher
Quoted 6 lines · Mario Limonciello

[Why]
If userspace hasn't frozen user processes (like systemd does with user.slice) then an aborted hibernate could give control back to userspace before display hardware is resumed.  IoW an atomic commit could be done while the hardware is in D3, which could hang a system.

Is there any way to prevent this altogether?

The obvious way is that userspace should be freezing user processes. That's what systemd does.

Quoted 2 lines

This seems like a recipe
for trouble for any driver.

If we want to uplevel this kind of check I think we would need some helper to report hardware status into drm and drm would have to call that.

Quoted 7 lines
Quoted 1 line

Most distros use systemd, and this only happened in an aborted hibernate.  I guess I'd like to see how much this warning actually comes up before deciding if all that plumbing is worth it.

I was briefly thinking about a generic solution as well and don't think it's worth it at this point. This is mostly about internal driver/HW state.

Harry

FWIW IGT testing seems to have thrown up some problems with this which didn't show up in my unit testing.

[  471.261018]  ? drm_atomic_helper_resume+0x2b/0x150 [drm_kms_helper]
[  471.261031]  ? dm_resume+0x459/0x8f0 [amdgpu]
[  471.261396]  ? amdgpu_ip_block_resume+0x27/0x70 [amdgpu]
[  471.261635]  ? dpm_run_callback+0x9c/0x200
[  471.261640]  ? device_resume+0x1b4/0x2b0
[  471.261645]  drm_atomic_check_only+0x5d9/0x9e0 [drm]
[  471.261672]  drm_atomic_commit+0x6d/0xe0 [drm]
[  471.261697]  ? __pfx___drm_printfn_info+0x10/0x10 [drm]
[  471.261729]  drm_atomic_helper_commit_duplicated_state+0xcd/0xe0 [drm_kms_helper]
[  471.261739]  drm_atomic_helper_resume+0x93/0x150 [drm_kms_helper]
[  471.261751]  dm_resume+0x459/0x8f0 [amdgpu]
[  471.262119]  ? preempt_count_add+0x7b/0xc0
[  471.262125]  amdgpu_ip_block_resume+0x27/0x70 [amdgpu]
[  471.262363]  amdgpu_device_ip_resume_phase3+0x54/0x80 [amdgpu]
[  471.262598]  amdgpu_device_resume+0x188/0x3b0 [amdgpu]
[  471.262842]  amdgpu_pmops_resume+0x4c/0x90 [amdgpu]
[  471.263078]  pci_pm_resume+0x6b/0x100

The issue appears to me to be that ip_block->status.hw isn't set again until the end of amdgpu_ip_block_resume().

I am tempted to move it before the call to ip_block->version->funcs->resume().

Thoughts?

Quoted 41 lines
Quoted 40 lines
Quoted 39 lines

Alex

Quoted 35 lines

[How]
Add a check whether the IP block hardware is ready to the atomic check handler and return a failure. Userspace shouldn't do an atomic commit if the atomic check fails.

---
Cc: Harry Wentland <[email protected]>
v2:
  * Return -EBUSY instead (Harry)

---
   drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 5 +++++
   1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5 -0
index 6446ec6c21d4..f5cd9982af99 100644
@@ -12010,6 +12010,11 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
 
          trace_amdgpu_dm_atomic_check_begin(state);
 
+       if (WARN_ON(unlikely(!amdgpu_device_ip_is_hw(adev, AMD_IP_BLOCK_TYPE_DCE)))) {
+               ret = -EBUSY;
+               goto fail;
+       }
+
          ret = drm_atomic_helper_check_modeset(dev, state);
          if (ret) {
                  drm_dbg_atomic(dev, "drm_atomic_helper_check_modeset() failed\n");
Signature · 1 line
2.49.0
#9 lore raw

Re: [PATCH v2 2/2] drm/amd/display: Check if display HW is enabled in amdgpu_dm_atomic_check()

Quoted 56 lines · Mario Limonciello
Quoted 24 lines · Harry Wentland
Quoted 21 lines · Mario Limonciello
Quoted 10 lines · Alex Deucher
Quoted 6 lines · Mario Limonciello

[Why]
If userspace hasn't frozen user processes (like systemd does with user.slice) then an aborted hibernate could give control back to userspace before display hardware is resumed. IoW an atomic commit could be done while the hardware is in D3, which could hang a system.

Is there any way to prevent this altogether?

The obvious way is that userspace should be freezing user processes. That's what systemd does.

Quoted 2 lines

This seems like a recipe
for trouble for any driver.

If we want to uplevel this kind of check I think we would need some helper to report hardware status into drm and drm would have to call that.

Quoted 7 lines
Quoted 1 line

Most distros use systemd, and this only happened in an aborted hibernate. I guess I'd like to see how much this warning actually comes up before deciding if all that plumbing is worth it.

I was briefly thinking about a generic solution as well and don't think it's worth it at this point. This is mostly about internal driver/HW state.

Harry

FWIW IGT testing seems to have thrown up some problems with this which didn't show up in my unit testing.

[  471.261018]  ? drm_atomic_helper_resume+0x2b/0x150 [drm_kms_helper]
[  471.261031]  ? dm_resume+0x459/0x8f0 [amdgpu]
[  471.261396]  ? amdgpu_ip_block_resume+0x27/0x70 [amdgpu]
[  471.261635]  ? dpm_run_callback+0x9c/0x200
[  471.261640]  ? device_resume+0x1b4/0x2b0
[  471.261645]  drm_atomic_check_only+0x5d9/0x9e0 [drm]
[  471.261672]  drm_atomic_commit+0x6d/0xe0 [drm]
[  471.261697]  ? __pfx___drm_printfn_info+0x10/0x10 [drm]
[  471.261729]  drm_atomic_helper_commit_duplicated_state+0xcd/0xe0
[drm_kms_helper]
[  471.261739]  drm_atomic_helper_resume+0x93/0x150 [drm_kms_helper]
[  471.261751]  dm_resume+0x459/0x8f0 [amdgpu]
[  471.262119]  ? preempt_count_add+0x7b/0xc0
[  471.262125]  amdgpu_ip_block_resume+0x27/0x70 [amdgpu]
[  471.262363]  amdgpu_device_ip_resume_phase3+0x54/0x80 [amdgpu]
[  471.262598]  amdgpu_device_resume+0x188/0x3b0 [amdgpu]
[  471.262842]  amdgpu_pmops_resume+0x4c/0x90 [amdgpu]
[  471.263078]  pci_pm_resume+0x6b/0x100
Quoted 7 lines

The issue appears to me to be that ip_block->status.hw isn't set again until the end of amdgpu_ip_block_resume().

I am tempted to move it before the call to
ip_block->version->funcs->resume().

Thoughts?

Then it won't actually reflect the hw state.

Alex

Alex

Quoted 43 lines
Quoted 42 lines
Quoted 41 lines
Quoted 40 lines

Alex

Quoted 35 lines

[How]
Add a check whether the IP block hardware is ready to the atomic check handler and return a failure. Userspace shouldn't do an atomic commit if the atomic check fails.

---
Cc: Harry Wentland <[email protected]>
v2:
* Return -EBUSY instead (Harry)

---
   drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 5 +++++
   1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5 -1
index 6446ec6c21d4..f5cd9982af99 100644
@@ -12010,6 +12010,11 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
 
          trace_amdgpu_dm_atomic_check_begin(state);
 
+       if (WARN_ON(unlikely(!amdgpu_device_ip_is_hw(adev, AMD_IP_BLOCK_TYPE_DCE)))) {
+               ret = -EBUSY;
+               goto fail;
+       }
+
          ret = drm_atomic_helper_check_modeset(dev, state);
          if (ret) {
                  drm_dbg_atomic(dev, "drm_atomic_helper_check_modeset() failed\n");
--

2.49.0

#10 lore raw

Re: [PATCH v2 2/2] drm/amd/display: Check if display HW is enabled in amdgpu_dm_atomic_check()

Quoted 61 lines · Alex Deucher
Quoted 59 lines · Mario Limonciello
Quoted 24 lines · Harry Wentland
Quoted 21 lines · Mario Limonciello
Quoted 10 lines · Alex Deucher
Quoted 6 lines · Mario Limonciello

[Why]
If userspace hasn't frozen user processes (like systemd does with user.slice) then an aborted hibernate could give control back to userspace before display hardware is resumed. IoW an atomic commit could be done while the hardware is in D3, which could hang a system.

Is there any way to prevent this altogether?

The obvious way is that userspace should be freezing user processes. That's what systemd does.

Quoted 2 lines

This seems like a recipe
for trouble for any driver.

If we want to uplevel this kind of check I think we would need some helper to report hardware status into drm and drm would have to call that.

Quoted 7 lines
Quoted 1 line

Most distros use systemd, and this only happened in an aborted hibernate. I guess I'd like to see how much this warning actually comes up before deciding if all that plumbing is worth it.

I was briefly thinking about a generic solution as well and don't think it's worth it at this point. This is mostly about internal driver/HW state.

Harry

FWIW IGT testing seems to have thrown up some problems with this which didn't show up in my unit testing.

[  471.261018]  ? drm_atomic_helper_resume+0x2b/0x150 [drm_kms_helper]
[  471.261031]  ? dm_resume+0x459/0x8f0 [amdgpu]
[  471.261396]  ? amdgpu_ip_block_resume+0x27/0x70 [amdgpu]
[  471.261635]  ? dpm_run_callback+0x9c/0x200
[  471.261640]  ? device_resume+0x1b4/0x2b0
[  471.261645]  drm_atomic_check_only+0x5d9/0x9e0 [drm]
[  471.261672]  drm_atomic_commit+0x6d/0xe0 [drm]
[  471.261697]  ? __pfx___drm_printfn_info+0x10/0x10 [drm]
[  471.261729]  drm_atomic_helper_commit_duplicated_state+0xcd/0xe0
[drm_kms_helper]
[  471.261739]  drm_atomic_helper_resume+0x93/0x150 [drm_kms_helper]
[  471.261751]  dm_resume+0x459/0x8f0 [amdgpu]
[  471.262119]  ? preempt_count_add+0x7b/0xc0
[  471.262125]  amdgpu_ip_block_resume+0x27/0x70 [amdgpu]
[  471.262363]  amdgpu_device_ip_resume_phase3+0x54/0x80 [amdgpu]
[  471.262598]  amdgpu_device_resume+0x188/0x3b0 [amdgpu]
[  471.262842]  amdgpu_pmops_resume+0x4c/0x90 [amdgpu]
[  471.263078]  pci_pm_resume+0x6b/0x100

The issue appears to me to be that ip_block->status.hw isn't set again until the end of amdgpu_ip_block_resume().

Quoted 10 lines
Quoted 4 lines

I am tempted to move it before the call to
ip_block->version->funcs->resume().

Thoughts?

Then it won't actually reflect the hw state.

Alex

FWIW I misinterpreted the original issue. The actual problem was that there is no recovery sequence if suspend fails part way through. From the PM core perspective the device is operable, so it never runs the restore() sequence like it normally would.

With some contrived failures I experimented with an ASIC reset, unwind the suspend sequence and call the whole resume sequence and landed on the whole resume sequence is the most scalable and workable approach [1].

[1] https://lore.kernel.org/amd-gfx/[email protected]/T/#u