Skip to contentSkip to conversation

drm/amdgpu: lock the eviction fence for wq signals it

PATCH Superseded Prike Liang 4 participants 5 messages May 12, 2025 – May 15, 2025

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/amdgpu: lock the eviction fence for wq signals it

Lock and refer to the eviction fence before the eviction fence schedules work queue tries to signal it.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +7 -1
index 1a7469543db5..d5f176fef357 100644
@@ -108,12 +108,18 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)
 	struct amdgpu_eviction_fence *ev_fence;
 
 	mutex_lock(&uq_mgr->userq_mutex);
+	spin_lock(&evf_mgr->ev_fence_lock);
 	ev_fence = evf_mgr->ev_fence;
-	if (!ev_fence)
+	spin_unlock(&evf_mgr->ev_fence_lock);
+
+	if (ev_fence)
+		dma_fence_get(&ev_fence->base);
+	else
 		goto unlock;
 
 	amdgpu_userq_evict(uq_mgr, ev_fence);
 
+	dma_fence_put(&ev_fence->base);
 unlock:
 	mutex_unlock(&uq_mgr->userq_mutex);
 }
Signature · 1 line
2.34.1
#1 lore raw

[Public]

Soft ping.

Regards,
Prike

Quoted 45 lines

-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Monday, May 12, 2025 10:20 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Liang, Prike <[email protected]>; Koenig, Christian <[email protected]>
Subject: [PATCH v2] drm/amdgpu: lock the eviction fence for wq signals it

Lock and refer to the eviction fence before the eviction fence schedules work queue tries to signal it.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +7 -1
index 1a7469543db5..d5f176fef357 100644
@@ -108,12 +108,18 @@ amdgpu_eviction_fence_suspend_worker(struct
 work_struct *work)
      struct amdgpu_eviction_fence *ev_fence;
 
      mutex_lock(&uq_mgr->userq_mutex);
+     spin_lock(&evf_mgr->ev_fence_lock);
      ev_fence = evf_mgr->ev_fence;
-     if (!ev_fence)
+     spin_unlock(&evf_mgr->ev_fence_lock);
+
+     if (ev_fence)
+             dma_fence_get(&ev_fence->base);
+     else
              goto unlock;
 
      amdgpu_userq_evict(uq_mgr, ev_fence);
 
+     dma_fence_put(&ev_fence->base);
 unlock:
      mutex_unlock(&uq_mgr->userq_mutex);

}
--
2.34.1

Acked-by on v2 1/1
#2 lore raw
In reply to Prike Liang
Quoted 6 lines · Prike Liang

Lock and refer to the eviction fence before the eviction fence schedules work queue tries to signal it.

Quoted 31 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +7 -2
index 1a7469543db5..d5f176fef357 100644
@@ -108,12 +108,18 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)
        struct amdgpu_eviction_fence *ev_fence;
 
        mutex_lock(&uq_mgr->userq_mutex);
+       spin_lock(&evf_mgr->ev_fence_lock);
        ev_fence = evf_mgr->ev_fence;
-       if (!ev_fence)
+       spin_unlock(&evf_mgr->ev_fence_lock);
+
+       if (ev_fence)
+               dma_fence_get(&ev_fence->base);
+       else
                goto unlock;
 
        amdgpu_userq_evict(uq_mgr, ev_fence);
 
+       dma_fence_put(&ev_fence->base);
 unlock:
        mutex_unlock(&uq_mgr->userq_mutex);
 }
--

2.34.1

Reviewed-by Arvind Yadav
#3 lore raw
Quoted 39 lines · Alex Deucher
Quoted 5 lines · Prike Liang

Lock and refer to the eviction fence before the eviction fence schedules work queue tries to signal it.

Quoted 31 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +7 -2
index 1a7469543db5..d5f176fef357 100644
@@ -108,12 +108,18 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)
         struct amdgpu_eviction_fence *ev_fence;
 
         mutex_lock(&uq_mgr->userq_mutex);
+       spin_lock(&evf_mgr->ev_fence_lock);
         ev_fence = evf_mgr->ev_fence;
-       if (!ev_fence)
+       spin_unlock(&evf_mgr->ev_fence_lock);
+
+       if (ev_fence)
+               dma_fence_get(&ev_fence->base);
+       else
                 goto unlock;
 
         amdgpu_userq_evict(uq_mgr, ev_fence);
 
+       dma_fence_put(&ev_fence->base);
  unlock:
         mutex_unlock(&uq_mgr->userq_mutex);
  }
--

2.34.1

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

Lock and refer to the eviction fence before the eviction fence schedules work queue tries to signal it.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +0 -0
index 1a7469543db5..d5f176fef357 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c amdgpu_eviction_fence_suspend_worker(struct work_struct *work) · line 113

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +2 -1
@@ -108,12 +108,18 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)
 	struct amdgpu_eviction_fence *ev_fence;
 
 	mutex_lock(&uq_mgr->userq_mutex);
+	spin_lock(&evf_mgr->ev_fence_lock);
 	ev_fence = evf_mgr->ev_fence;
-	if (!ev_fence)
+	spin_unlock(&evf_mgr->ev_fence_lock);

The dma_fence_get must be done while holding the lock, otherwise the change is rather pointless.

Regards,
Christian.

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +5 -0
+
+	if (ev_fence)
+		dma_fence_get(&ev_fence->base);
+	else
 		goto unlock;
 
 	amdgpu_userq_evict(uq_mgr, ev_fence);
 
+	dma_fence_put(&ev_fence->base);
 unlock:
 	mutex_unlock(&uq_mgr->userq_mutex);
 }