Skip to contentSkip to conversation

drm/amdgpu: Fix validating flush_gpu_tlb_pasid()

PATCH In review Timur Kristóf 3 participants 9 messages Jan 18 – Jan 19

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

PATCH 1/1 drm/amdgpu: Fix validating flush_gpu_tlb_pasid()

When a function holds a lock and we return without unlocking it, it deadlocks the kernel. We should always unlock before returning.

This commit fixes suspend/resume on SI. Tested on two Tahiti GPUs: FirePro W9000 and R9 280X.

Fixes bc2dea30038a ("drm/amdgpu: validate the flush_gpu_tlb_pasid()")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2 -3
index 0e67fa4338ff..4fa24be1bf45 100644
@@ -769,7 +769,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid,
 	struct amdgpu_ring *ring = &adev->gfx.kiq[inst].ring;
 	struct amdgpu_kiq *kiq = &adev->gfx.kiq[inst];
 	unsigned int ndw;
-	int r, cnt = 0;
+	int r = 0, cnt = 0;
 	uint32_t seq;
 
 	/*
@@ -782,7 +782,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid,
 	if (!adev->gmc.flush_pasid_uses_kiq || !ring->sched.ready) {
 
 		if (!adev->gmc.gmc_funcs->flush_gpu_tlb_pasid)
-			return 0;
+			goto error_unlock_reset;
 
 		if (adev->gmc.flush_tlb_needs_extra_type_2)
 			adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev, pasid,
@@ -797,7 +797,6 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid,
 		adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev, pasid,
 							 flush_type, all_hub,
 							 inst);
-		r = 0;
 	} else {
 		/* 2 dwords flush + 8 dwords fence */
 		ndw = kiq->pmf->invalidate_tlbs_size + 8;
Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw

[Public]

Thank you for the fix. Could you please add the following the tags?

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

Regards,
Prike

Quoted 58 lines

-----Original Message-----
From: Timur Kristóf <[email protected]>
Sent: Sunday, January 18, 2026 8:58 PM
To: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Liang, Prike <[email protected]>; Limonciello, Mario <[email protected]>
Cc: Timur Kristóf <[email protected]>
Subject: [PATCH] drm/amdgpu: Fix validating flush_gpu_tlb_pasid()

When a function holds a lock and we return without unlocking it, it deadlocks the kernel. We should always unlock before returning.

This commit fixes suspend/resume on SI. Tested on two Tahiti GPUs: FirePro W9000 and R9 280X.

Fixes bc2dea30038a ("drm/amdgpu: validate the flush_gpu_tlb_pasid()")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
index 0e67fa4338ff..4fa24be1bf45 100644
@@ -769,7 +769,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct
 amdgpu_device *adev, uint16_t pasid,
      struct amdgpu_ring *ring = &adev->gfx.kiq[inst].ring;
      struct amdgpu_kiq *kiq = &adev->gfx.kiq[inst];
      unsigned int ndw;
-     int r, cnt = 0;
+     int r = 0, cnt = 0;
      uint32_t seq;
 
      /*
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
@@ -782,7 +782,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct
 amdgpu_device *adev, uint16_t pasid,
      if (!adev->gmc.flush_pasid_uses_kiq || !ring->sched.ready) {
 
              if (!adev->gmc.gmc_funcs->flush_gpu_tlb_pasid)
-                     return 0;
+                     goto error_unlock_reset;
 
              if (adev->gmc.flush_tlb_needs_extra_type_2)
                      adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev, pasid,
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -1
@@ -797,7 +797,6 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct
 amdgpu_device *adev, uint16_t pasid,
              adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev, pasid,
                                                       flush_type, all_hub,
                                                       inst);
-             r = 0;
      } else {
              /* 2 dwords flush + 8 dwords fence */
              ndw = kiq->pmf->invalidate_tlbs_size + 8;

--
2.52.0

#2 lore raw

[Public]

In order to avoid being blocked by the lock issue on some older GFX, I will push the patch to amd-staging-drm-next. If you have any concerns, please let me know.

Regards,
Prike

Quoted 80 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Liang, Prike
Sent: Monday, January 19, 2026 9:58 AM
To: Timur Kristóf <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Limonciello, Mario <[email protected]>; Dan Carpenter <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: Fix validating flush_gpu_tlb_pasid()

[Public]

Thank you for the fix. Could you please add the following the tags?

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

Regards,
Prike

Quoted 58 lines

-----Original Message-----
From: Timur Kristóf <[email protected]>
Sent: Sunday, January 18, 2026 8:58 PM
To: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Liang, Prike <[email protected]>; Limonciello, Mario <[email protected]>
Cc: Timur Kristóf <[email protected]>
Subject: [PATCH] drm/amdgpu: Fix validating flush_gpu_tlb_pasid()

When a function holds a lock and we return without unlocking it, it deadlocks the kernel. We should always unlock before returning.

This commit fixes suspend/resume on SI. Tested on two Tahiti GPUs: FirePro W9000 and R9 280X.

Fixes bc2dea30038a ("drm/amdgpu: validate the flush_gpu_tlb_pasid()")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
index 0e67fa4338ff..4fa24be1bf45 100644
@@ -769,7 +769,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct
 amdgpu_device *adev, uint16_t pasid,
      struct amdgpu_ring *ring = &adev->gfx.kiq[inst].ring;
      struct amdgpu_kiq *kiq = &adev->gfx.kiq[inst];
      unsigned int ndw;
-     int r, cnt = 0;
+     int r = 0, cnt = 0;
      uint32_t seq;
 
      /*
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
@@ -782,7 +782,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct
 amdgpu_device *adev, uint16_t pasid,
      if (!adev->gmc.flush_pasid_uses_kiq || !ring->sched.ready) {
 
              if (!adev->gmc.gmc_funcs->flush_gpu_tlb_pasid)
-                     return 0;
+                     goto error_unlock_reset;
 
              if (adev->gmc.flush_tlb_needs_extra_type_2)
                      adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev,
pasid, @@ -797,7 +797,6 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct
amdgpu_device *adev, uint16_t pasid,
              adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev, pasid,
                                                       flush_type, all_hub,
                                                       inst);
-             r = 0;
      } else {
              /* 2 dwords flush + 8 dwords fence */
              ndw = kiq->pmf->invalidate_tlbs_size + 8;

--
2.52.0

#3 lore raw
Quoted 7 lines · Prike

[Public]

In order to avoid being blocked by the lock issue on some older GFX, I will push the patch to amd-staging-drm-next.
If you have any concerns, please
let me know.

Hi Prike,

Thank you, feel free to add the necessary tags and push the patch.

Best regards,
Timur

Quoted 5 lines
Quoted 5 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Liang, Prike

Sent: Monday, January 19, 2026 9:58 AM

Quoted 2 lines
Quoted 2 lines

To: Timur Kristóf <[email protected]>;
[email protected];

Deucher, Alexander

Quoted 121 lines
Quoted 119 lines

<[email protected]>; Koenig, Christian <[email protected]>; Limonciello, Mario <[email protected]>; Dan Carpenter <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: Fix validating flush_gpu_tlb_pasid()

[Public]

Thank you for the fix. Could you please add the following the tags?

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

Regards,

Prike

Quoted 88 lines

-----Original Message-----
From: Timur Kristóf <[email protected]>
Sent: Sunday, January 18, 2026 8:58 PM
To: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Liang, Prike <[email protected]>; Limonciello, Mario <[email protected]>
Cc: Timur Kristóf <[email protected]>
Subject: [PATCH] drm/amdgpu: Fix validating flush_gpu_tlb_pasid()

When a function holds a lock and we return without unlocking it, it deadlocks the kernel. We should always unlock before returning.

This commit fixes suspend/resume on SI. Tested on two Tahiti GPUs: FirePro W9000 and R9 280X.

Fixes bc2dea30038a ("drm/amdgpu: validate the flush_gpu_tlb_pasid()")

---

 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
index 0e67fa4338ff..4fa24be1bf45 100644
@@ -769,7 +769,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct
 amdgpu_device *adev, uint16_t pasid,
 
      struct amdgpu_ring *ring = &adev->gfx.kiq[inst].ring;
      struct amdgpu_kiq *kiq = &adev->gfx.kiq[inst];
      unsigned int ndw;
 
-     int r, cnt = 0;
+     int r = 0, cnt = 0;
      uint32_t seq;



      /*
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
@@ -782,7 +782,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct
 amdgpu_device *adev, uint16_t pasid,
 
      if (!adev->gmc.flush_pasid_uses_kiq || !ring->sched.ready) {
 
 
 
              if (!adev->gmc.gmc_funcs->flush_gpu_tlb_pasid)
 
-                     return 0;
+                     goto error_unlock_reset;
 
 
 
              if (adev->gmc.flush_tlb_needs_extra_type_2)
 
                      adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev,

pasid, @@ -797,7 +797,6 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid,

              adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev, pasid,
              
                                                       flush_type,
                                                       all_hub,
                                                       inst);

- r = 0;

      } else {
      
              /* 2 dwords flush + 8 dwords fence */
              ndw = kiq->pmf->invalidate_tlbs_size + 8;

--
2.52.0

maintainer
#4 lore raw
In reply to Liang, Prike
Quoted 4 lines · Prike

[Public]

In order to avoid being blocked by the lock issue on some older GFX, I will push the patch to amd-staging-drm-next. If you have any concerns, please let me know.

I only had a coding style comment on the patch and also gave my rb with that as well.

So if you haven't pushed it yet please fix what I've pointed out. Otherwise it is not much of an issue.

Regards,
Christian.

Quoted 85 lines

Regards,
Prike

Quoted 80 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Liang, Prike
Sent: Monday, January 19, 2026 9:58 AM
To: Timur Kristóf <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Limonciello, Mario <[email protected]>; Dan Carpenter <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: Fix validating flush_gpu_tlb_pasid()

[Public]

Thank you for the fix. Could you please add the following the tags?

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

Regards,
Prike

Quoted 58 lines

-----Original Message-----
From: Timur Kristóf <[email protected]>
Sent: Sunday, January 18, 2026 8:58 PM
To: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Liang, Prike <[email protected]>; Limonciello, Mario <[email protected]>
Cc: Timur Kristóf <[email protected]>
Subject: [PATCH] drm/amdgpu: Fix validating flush_gpu_tlb_pasid()

When a function holds a lock and we return without unlocking it, it deadlocks the kernel. We should always unlock before returning.

This commit fixes suspend/resume on SI. Tested on two Tahiti GPUs: FirePro W9000 and R9 280X.

Fixes bc2dea30038a ("drm/amdgpu: validate the flush_gpu_tlb_pasid()")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
index 0e67fa4338ff..4fa24be1bf45 100644
@@ -769,7 +769,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct
 amdgpu_device *adev, uint16_t pasid,
      struct amdgpu_ring *ring = &adev->gfx.kiq[inst].ring;
      struct amdgpu_kiq *kiq = &adev->gfx.kiq[inst];
      unsigned int ndw;
-     int r, cnt = 0;
+     int r = 0, cnt = 0;
      uint32_t seq;
 
      /*
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
@@ -782,7 +782,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct
 amdgpu_device *adev, uint16_t pasid,
      if (!adev->gmc.flush_pasid_uses_kiq || !ring->sched.ready) {
 
              if (!adev->gmc.gmc_funcs->flush_gpu_tlb_pasid)
-                     return 0;
+                     goto error_unlock_reset;
 
              if (adev->gmc.flush_tlb_needs_extra_type_2)
                      adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev,
pasid, @@ -797,7 +797,6 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct
amdgpu_device *adev, uint16_t pasid,
              adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev, pasid,
                                                       flush_type, all_hub,
                                                       inst);
-             r = 0;
      } else {
              /* 2 dwords flush + 8 dwords fence */
              ndw = kiq->pmf->invalidate_tlbs_size + 8;

--
2.52.0

#5 lore raw

[Public]

Regards,
Prike

Quoted 16 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Monday, January 19, 2026 6:33 PM
To: Liang, Prike <[email protected]>; Timur Kristóf <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Limonciello, Mario <[email protected]>; Dan Carpenter <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Fix validating flush_gpu_tlb_pasid()

Quoted 3 lines · Prike

[Public]

In order to avoid being blocked by the lock issue on some older GFX, I will push

the patch to amd-staging-drm-next.

Quoted 1 line

If you have any concerns, please let me know.

Quoted 8 lines

I only had a coding style comment on the patch and also gave my rb with that as well.

So if you haven't pushed it yet please fix what I've pointed out. Otherwise it is not much of an issue.

Regards,
Christian.

The patch is still running in the CI pipeline. I’ll revise it to improve the patch style.

Quoted 89 lines
Quoted 89 lines

Regards,
Prike

Quoted 84 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Liang, Prike
Sent: Monday, January 19, 2026 9:58 AM
To: Timur Kristóf <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Limonciello, Mario <[email protected]>; Dan Carpenter <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: Fix validating flush_gpu_tlb_pasid()

[Public]

Thank you for the fix. Could you please add the following the tags?

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes:
| https://lore.kernel.org/r/[email protected]/

Regards,
Prike

Quoted 59 lines

-----Original Message-----
From: Timur Kristóf <[email protected]>
Sent: Sunday, January 18, 2026 8:58 PM
To: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Liang, Prike <[email protected]>; Limonciello, Mario <[email protected]>
Cc: Timur Kristóf <[email protected]>
Subject: [PATCH] drm/amdgpu: Fix validating flush_gpu_tlb_pasid()

When a function holds a lock and we return without unlocking it, it deadlocks the kernel. We should always unlock before returning.

This commit fixes suspend/resume on SI. Tested on two Tahiti GPUs: FirePro W9000 and R9 280X.

Fixes bc2dea30038a ("drm/amdgpu: validate the

flush_gpu_tlb_pasid()")

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
index 0e67fa4338ff..4fa24be1bf45 100644
@@ -769,7 +769,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct
 amdgpu_device *adev, uint16_t pasid,
      struct amdgpu_ring *ring = &adev->gfx.kiq[inst].ring;
      struct amdgpu_kiq *kiq = &adev->gfx.kiq[inst];
      unsigned int ndw;
-     int r, cnt = 0;
+     int r = 0, cnt = 0;
      uint32_t seq;
 
      /*
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
@@ -782,7 +782,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct
 amdgpu_device *adev, uint16_t pasid,
      if (!adev->gmc.flush_pasid_uses_kiq || !ring->sched.ready) {
 
              if (!adev->gmc.gmc_funcs->flush_gpu_tlb_pasid)
-                     return 0;
+                     goto error_unlock_reset;
 
              if (adev->gmc.flush_tlb_needs_extra_type_2)
                      adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev,
pasid, @@ -797,7 +797,6 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct
amdgpu_device *adev, uint16_t pasid,
              adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev, pasid,
                                                       flush_type, all_hub,
                                                       inst);
-             r = 0;
      } else {
              /* 2 dwords flush + 8 dwords fence */
              ndw = kiq->pmf->invalidate_tlbs_size + 8;

--
2.52.0

maintainer
#6 lore raw
In reply to Timur Kristóf
Quoted 17 lines · Timur Kristóf

When a function holds a lock and we return without unlocking it, it deadlocks the kernel. We should always unlock before returning.

This commit fixes suspend/resume on SI. Tested on two Tahiti GPUs: FirePro W9000 and R9 280X.

Fixes bc2dea30038a ("drm/amdgpu: validate the flush_gpu_tlb_pasid()")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
index 0e67fa4338ff..4fa24be1bf45 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid, · line 772

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
@@ -769,7 +769,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid,
 	struct amdgpu_ring *ring = &adev->gfx.kiq[inst].ring;
 	struct amdgpu_kiq *kiq = &adev->gfx.kiq[inst];
 	unsigned int ndw;
-	int r, cnt = 0;
+	int r = 0, cnt = 0;

Please don't initialize return values in the declaration, that is usually considered bad coding style.

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid, · line 785

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
 	uint32_t seq;
 
 	/*
@@ -782,7 +782,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid,
 	if (!adev->gmc.flush_pasid_uses_kiq || !ring->sched.ready) {
 
 		if (!adev->gmc.gmc_funcs->flush_gpu_tlb_pasid)
-			return 0;
+			goto error_unlock_reset;

Ah, yes good catch!

With the change to r initialization dropped: Reviewed-by: Christian König <[email protected]>

Regards,
Christian.

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -1
 		if (adev->gmc.flush_tlb_needs_extra_type_2)
 			adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev, pasid,
@@ -797,7 +797,6 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid,
 		adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev, pasid,
 							 flush_type, all_hub,
 							 inst);
-		r = 0;
 	} else {
 		/* 2 dwords flush + 8 dwords fence */
 		ndw = kiq->pmf->invalidate_tlbs_size + 8;
#7 lore raw
Quoted 25 lines · Central European Standard Time Christian König
Quoted 24 lines · Timur Kristóf

When a function holds a lock and we return without unlocking it, it deadlocks the kernel. We should always unlock before returning.

This commit fixes suspend/resume on SI. Tested on two Tahiti GPUs: FirePro W9000 and R9 280X.

Fixes bc2dea30038a ("drm/amdgpu: validate the flush_gpu_tlb_pasid()")

---

 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c index
0e67fa4338ff..4fa24be1bf45 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
@@ -769,7 +769,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct

amdgpu_device *adev, uint16_t pasid,>

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
 	struct amdgpu_ring *ring = &adev->gfx.kiq[inst].ring;
 	struct amdgpu_kiq *kiq = &adev->gfx.kiq[inst];
 	unsigned int ndw;
Quoted 5 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid, · line 772

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
-	int r, cnt = 0;
+	int r = 0, cnt = 0;

Please don't initialize return values in the declaration, that is usually considered bad coding style.

The initialization is necessary, otherwise the function will return an uninitialized value when flush_gpu_tlb_pasid==NULL

Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
 	uint32_t seq;
 
 	/*
@@ -782,7 +782,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct

amdgpu_device *adev, uint16_t pasid,>

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
 	if (!adev->gmc.flush_pasid_uses_kiq || !ring->sched.ready) {
 
 		if (!adev->gmc.gmc_funcs->flush_gpu_tlb_pasid)
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid, · line 785

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
-			return 0;
+			goto error_unlock_reset;

Ah, yes good catch!

With the change to r initialization dropped: Reviewed-by: Christian König <[email protected]>

If I drop it, then it will regress again because it returns an uninitialized value.

Quoted 6 lines

Regards,
Christian.

Quoted 2 lines

if (adev->gmc.flush_tlb_needs_extra_type_2)

Quoted 8 lines
Quoted 1 line

adev->gmc.gmc_funcs-

flush_gpu_tlb_pasid(adev, pasid,

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
@@ -797,7 +797,6 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct

amdgpu_device *adev, uint16_t pasid,>
adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev, pasid,

flush_type, all_hub,

Quoted 1 line
Quoted 1 line

inst);

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -1
-		r = 0;
 
 	} else {
 
 		/* 2 dwords flush + 8 dwords fence */
 		ndw = kiq->pmf->invalidate_tlbs_size + 8;
#8 lore raw

[Public]

Regards,
Prike

Quoted 37 lines

-----Original Message-----
From: Timur Kristóf <[email protected]>
Sent: Monday, January 19, 2026 7:21 PM
To: [email protected]; Deucher, Alexander <[email protected]>; Liang, Prike <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Fix validating flush_gpu_tlb_pasid()

Quoted 26 lines · Central European Standard Time Christian König
Quoted 25 lines · Timur Kristóf

When a function holds a lock and we return without unlocking it, it deadlocks the kernel. We should always unlock before returning.

This commit fixes suspend/resume on SI. Tested on two Tahiti GPUs: FirePro W9000 and R9 280X.

Fixes bc2dea30038a ("drm/amdgpu: validate the

flush_gpu_tlb_pasid()")

---

 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c index
0e67fa4338ff..4fa24be1bf45 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
@@ -769,7 +769,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct

amdgpu_device *adev, uint16_t pasid,>
struct amdgpu_ring *ring = &adev->gfx.kiq[inst].ring; struct amdgpu_kiq *kiq = &adev->gfx.kiq[inst]; unsigned int ndw;

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

- int r, cnt = 0;
+ int r = 0, cnt = 0;

Please don't initialize return values in the declaration, that is usually considered bad coding style.

The initialization is necessary, otherwise the function will return an uninitialized value when flush_gpu_tlb_pasid==NULL

We can initialize the r before goto error_unlock_reset.

Quoted 47 lines
Quoted 10 lines
Quoted 10 lines

uint32_t seq;

/*

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
@@ -782,7 +782,7 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct

amdgpu_device *adev, uint16_t pasid,>
if (!adev->gmc.flush_pasid_uses_kiq || !ring->sched.ready) {

          if (!adev->gmc.gmc_funcs->flush_gpu_tlb_pasid)
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid, · line 785

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
-                 return 0;
+                 goto error_unlock_reset;

Ah, yes good catch!

With the change to r initialization dropped: Reviewed-by: Christian König <[email protected]>

If I drop it, then it will regress again because it returns an uninitialized value.

Quoted 6 lines

Regards,
Christian.

Quoted 2 lines
          if (adev->gmc.flush_tlb_needs_extra_type_2)
Quoted 8 lines
Quoted 1 line
                  adev->gmc.gmc_funcs-

flush_gpu_tlb_pasid(adev, pasid,

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
@@ -797,7 +797,6 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct

amdgpu_device *adev, uint16_t pasid,>

          adev->gmc.gmc_funcs->flush_gpu_tlb_pasid(adev, pasid,

flush_type, all_hub,

Quoted 1 line
Quoted 1 line

inst);

Quoted 7 lines
Quoted 7 lines

- r = 0;

  } else {
          /* 2 dwords flush + 8 dwords fence */
          ndw = kiq->pmf->invalidate_tlbs_size + 8;