Skip to contentSkip to conversation

drm/amdgpu: fix use-after-unlock in eviction fence destroy

PATCH In review Arvind Yadav 3 participants 3 messages May 15, 2025

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

PATCH 1/1 drm/amdgpu: fix use-after-unlock in eviction fence destroy

The eviction fence destroy path incorrectly calls dma_fence_put() on evf_mgr->ev_fence after releasing the ev_fence_lock. This introduces a potential use-after-unlock or race because another thread concurrently modifies evf_mgr->ev_fence.

Fix this by grabbing a local reference to evf_mgr->ev_fence under the lock and using that for dma_fence_put() after waiting.

Cc Sunil Khatri <[email protected]>
Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +1 -1
index 1a7469543db5..73b629b5f56f 100644
@@ -183,7 +183,7 @@ void amdgpu_eviction_fence_destroy(struct amdgpu_eviction_fence_mgr *evf_mgr)
 	dma_fence_wait(&ev_fence->base, false);
 
 	/* Last unref of ev_fence */
-	dma_fence_put(&evf_mgr->ev_fence->base);
+	dma_fence_put(&ev_fence->base);
 }
 
 int amdgpu_eviction_fence_attach(struct amdgpu_eviction_fence_mgr *evf_mgr,
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Arvind Yadav

The eviction fence destroy path incorrectly calls dma_fence_put() on evf_mgr->ev_fence after releasing the ev_fence_lock. This introduces a potential use-after-unlock or race because another thread concurrently modifies evf_mgr->ev_fence.

Quoted 7 lines

Fix this by grabbing a local reference to evf_mgr->ev_fence under the lock and using that for dma_fence_put() after waiting.

Cc Sunil Khatri <[email protected]>
Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>
Quoted 17 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +1 -1
index 1a7469543db5..73b629b5f56f 100644
@@ -183,7 +183,7 @@ void amdgpu_eviction_fence_destroy(struct amdgpu_eviction_fence_mgr *evf_mgr)
 	dma_fence_wait(&ev_fence->base, false);
 
 	/* Last unref of ev_fence */
-	dma_fence_put(&evf_mgr->ev_fence->base);
+	dma_fence_put(&ev_fence->base);
 }
 
 int amdgpu_eviction_fence_attach(struct amdgpu_eviction_fence_mgr *evf_mgr,
Reviewed-by Reviewed-by Christian König
#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, May 15, 2025 2:30 PM
To: Yadav, Arvind <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] drm/amdgpu: fix use-after-unlock in eviction fence destroy

Quoted 5 lines · Arvind Yadav

The eviction fence destroy path incorrectly calls dma_fence_put() on evf_mgr->ev_fence after releasing the ev_fence_lock. This introduces a potential use-after-unlock or race because another thread concurrently modifies evf_mgr->ev_fence.

Quoted 7 lines

Fix this by grabbing a local reference to evf_mgr->ev_fence under the lock and using that for dma_fence_put() after waiting.

Cc Sunil Khatri <[email protected]>
Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>
Quoted 19 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +1 -1
index 1a7469543db5..73b629b5f56f 100644
@@ -183,7 +183,7 @@ void amdgpu_eviction_fence_destroy(struct amdgpu_eviction_fence_mgr *evf_mgr)
      dma_fence_wait(&ev_fence->base, false);
 
      /* Last unref of ev_fence */
-     dma_fence_put(&evf_mgr->ev_fence->base);
+     dma_fence_put(&ev_fence->base);
 }
 
 int amdgpu_eviction_fence_attach(struct amdgpu_eviction_fence_mgr

*evf_mgr,