Skip to contentSkip to conversation

drm/amdgpu: fix userq resource double freed

PATCH In review Prike Liang 3 participants 5 messages May 12, 2025 – May 14, 2025

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

PATCH 1/1 drm/amdgpu: fix userq resource double freed

As the userq resource was already freed at the drm_release early phase, it should avoid freeing userq resource again at the later kms postclose callback.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -4
index 8d4a2aed7231..cf0f35a7daee 100644
@@ -1502,10 +1502,11 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
 		amdgpu_bo_unreserve(pd);
 	}
 
-	fpriv->evf_mgr.fd_closing = true;
-	amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
-	amdgpu_eviction_fence_destroy(&fpriv->evf_mgr);
-
+	if (!fpriv->evf_mgr.fd_closing) {
+		fpriv->evf_mgr.fd_closing = true;
+		amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
+		amdgpu_eviction_fence_destroy(&fpriv->evf_mgr);
+	}
 	amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr);
 	amdgpu_vm_fini(adev, &fpriv->vm);
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

This patch fixed a similar problem for me.

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Prike Liang
Sent: Monday, May 12, 2025 3:30 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH] drm/amdgpu: fix userq resource double freed

As the userq resource was already freed at the drm_release early phase, it should avoid freeing userq resource again at the later kms postclose callback.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -4
index 8d4a2aed7231..cf0f35a7daee 100644
@@ -1502,10 +1502,11 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
                amdgpu_bo_unreserve(pd);
        }
 
-       fpriv->evf_mgr.fd_closing = true;
-       amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
-       amdgpu_eviction_fence_destroy(&fpriv->evf_mgr);
-
+       if (!fpriv->evf_mgr.fd_closing) {
+               fpriv->evf_mgr.fd_closing = true;
+               amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
+               amdgpu_eviction_fence_destroy(&fpriv->evf_mgr);
+       }
        amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr);
        amdgpu_vm_fini(adev, &fpriv->vm);
 

--
2.34.1

maintainer
#2 lore raw
In reply to Prike Liang
Quoted 3 lines · Prike Liang

As the userq resource was already freed at the drm_release early phase, it should avoid freeing userq resource again at the later kms postclose callback.

Clear NAK. You are just hiding a bug.

The userq resources should always be only cleaned up here and that function can't be called twice.

Regards,
Christian.

Quoted 26 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -4
index 8d4a2aed7231..cf0f35a7daee 100644
@@ -1502,10 +1502,11 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
 		amdgpu_bo_unreserve(pd);
 	}
 
-	fpriv->evf_mgr.fd_closing = true;
-	amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
-	amdgpu_eviction_fence_destroy(&fpriv->evf_mgr);
-
+	if (!fpriv->evf_mgr.fd_closing) {
+		fpriv->evf_mgr.fd_closing = true;
+		amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
+		amdgpu_eviction_fence_destroy(&fpriv->evf_mgr);
+	}
 	amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr);
 	amdgpu_vm_fini(adev, &fpriv->vm);
 
#3 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 7 lines

From: Koenig, Christian <[email protected]>
Sent: Wednesday, May 14, 2025 3:02 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix userq resource double freed

On 5/12/25 09:30, Prike Liang wrote:

Quoted 8 lines
Quoted 3 lines

As the userq resource was already freed at the drm_release early phase, it should avoid freeing userq resource again at the later kms postclose callback.

Clear NAK. You are just hiding a bug.

The userq resources should always be only cleaned up here and that function can't be called twice.

The original issue is that the userq resource is freed first at amdgpu_drm_release(), and then second freed at amdgpu_driver_postclose_km(). At this point, it's more reasonable to remove the userq resource cleanup at drm file release phase and just keep freeing the userq resource at postclose moment?

Quoted 32 lines

Regards,
Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c void amdgpu_driver_postclose_kms(struct

Quoted 12 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
index 8d4a2aed7231..cf0f35a7daee 100644
@@ -1502,10 +1502,11 @@ void amdgpu_driver_postclose_kms(struct

drm_device *dev,

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -4
            amdgpu_bo_unreserve(pd);
    }
 
-   fpriv->evf_mgr.fd_closing = true;
-   amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
-   amdgpu_eviction_fence_destroy(&fpriv->evf_mgr);
-
+   if (!fpriv->evf_mgr.fd_closing) {
+           fpriv->evf_mgr.fd_closing = true;
+           amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
+           amdgpu_eviction_fence_destroy(&fpriv->evf_mgr);
+   }
    amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr);
    amdgpu_vm_fini(adev, &fpriv->vm);
 
maintainer
#4 lore raw
Quoted 13 lines · Prike

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 11 lines

From: Koenig, Christian <[email protected]>
Sent: Wednesday, May 14, 2025 3:02 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix userq resource double freed

Quoted 3 lines · Prike Liang

As the userq resource was already freed at the drm_release early phase, it should avoid freeing userq resource again at the later kms postclose callback.

Quoted 6 lines
Quoted 4 lines

Clear NAK. You are just hiding a bug.

The userq resources should always be only cleaned up here and that function can't be called twice.

The original issue is that the userq resource is freed first at amdgpu_drm_release(), and then second freed at amdgpu_driver_postclose_km(). At this point, it's more reasonable to remove the userq resource cleanup at drm file release phase and just keep freeing the userq resource at postclose moment?

Ah! In that case this code here should just be removed.

Regards,
Christian.

Quoted 34 lines
Quoted 33 lines

Regards,
Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c void amdgpu_driver_postclose_kms(struct

Quoted 12 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
index 8d4a2aed7231..cf0f35a7daee 100644
@@ -1502,10 +1502,11 @@ void amdgpu_driver_postclose_kms(struct

drm_device *dev,

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -4
            amdgpu_bo_unreserve(pd);
    }
 
-   fpriv->evf_mgr.fd_closing = true;
-   amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
-   amdgpu_eviction_fence_destroy(&fpriv->evf_mgr);
-
+   if (!fpriv->evf_mgr.fd_closing) {
+           fpriv->evf_mgr.fd_closing = true;
+           amdgpu_userq_mgr_fini(&fpriv->userq_mgr);
+           amdgpu_eviction_fence_destroy(&fpriv->evf_mgr);
+   }
    amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr);
    amdgpu_vm_fini(adev, &fpriv->vm);