drm/amdgpu: lock the eviction fence before signaling it
Subsystems (2)
PATCH 1/1 drm/amdgpu: lock the eviction fence before signaling it
Lock and refer to the eviction fence before trying to signal it.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +4 -1
@@ -108,13 +108,16 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)struct amdgpu_eviction_fence *ev_fence;mutex_lock (&uq_mgr->userq_mutex); - ev_fence = evf_mgr->ev_fence; +spin_lock (&evf_mgr->ev_fence_lock); + ev_fence = (struct amdgpu_eviction_fence *)dma_fence_get (&evf_mgr->ev_fence->base); +spin_unlock (&evf_mgr->ev_fence_lock);if (!ev_fence) goto unlock;amdgpu_userq_evict (uq_mgr, ev_fence); unlock: +dma_fence_put (&evf_mgr->ev_fence->base);mutex_unlock (&uq_mgr->userq_mutex); }
Signature · 1 line
2.34.1
Christian König
maintainerQuoted 12 lines · Prike Liang
Lock and refer to the eviction fence before trying to signal it.
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c amdgpu_eviction_fence_suspend_worker(struct work_struct *work) · line 112
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +2
-1@@ -108,13 +108,16 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)struct amdgpu_eviction_fence *ev_fence;mutex_lock (&uq_mgr->userq_mutex); - ev_fence = evf_mgr->ev_fence; +spin_lock (&evf_mgr->ev_fence_lock); + ev_fence = (struct amdgpu_eviction_fence *)dma_fence_get (&evf_mgr->ev_fence->base);
That case is not a good approach, instead put the dma_fence_get on a separate line.
Apart from that it looks good to me.
Christian.
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +2
-0+spin_unlock (&evf_mgr->ev_fence_lock);if (!ev_fence) goto unlock;amdgpu_userq_evict (uq_mgr, ev_fence); unlock: +dma_fence_put (&evf_mgr->ev_fence->base);mutex_unlock (&uq_mgr->userq_mutex); }
[Public]
Quoted 26 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, May 8, 2025 9:56 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: lock the eviction fence before signaling itReview
Quoted 8 lines · Prike Liang
Lock and refer to the eviction fence before trying to signal it.
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.cdrivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c amdgpu_eviction_fence_suspend_worker(struct
Quoted 4 lines
index
1a7469543db5..dd272c1fcbb4100644drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +0
-0@@ -108,13 +108,16 @@ amdgpu_eviction_fence_suspend_worker(struct
work_struct*work)Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +0
-0struct amdgpu_eviction_fence *ev_fence;
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c amdgpu_eviction_fence_suspend_worker(struct work_struct *work)
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +2
-1mutex_lock (&uq_mgr->userq_mutex); - ev_fence = evf_mgr->ev_fence; +spin_lock (&evf_mgr->ev_fence_lock); + ev_fence = (struct amdgpu_eviction_fence *)dma_fence_get (&evf_mgr- ev_fence->base);That case is not a good approach, instead put the
dma_fence_geton a separate line.
Thank for the suggestion, as such change can benefit on the readability? Do you mean something like the following change?
struct amdgpu_eviction_fence *ev_fence;
+ struct amdgpu_eviction_fence *ev_fence = NULL;
+ struct dma_fence *base_fence;
mutex_lock(&uq_mgr->userq_mutex);
- ev_fence = evf_mgr->ev_fence;
+ spin_lock(&evf_mgr->ev_fence_lock);
+ base_fence = dma_fence_get(&evf_mgr->ev_fence->base);
+ if (base_fence)
+ ev_fence = (struct amdgpu_eviction_fence *)base_fence;
+ spin_unlock(&evf_mgr->ev_fence_lock);
if (!ev_fence)
goto unlock;
amdgpu_userq_evict(uq_mgr, ev_fence); unlock:
+ dma_fence_put(base_fence);
Quoted 15 lines
Apart from that it looks good to me.
Christian.
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +2
-0+spin_unlock (&evf_mgr->ev_fence_lock);if (!ev_fence) goto unlock;amdgpu_userq_evict (uq_mgr, ev_fence); unlock: +dma_fence_put (&evf_mgr->ev_fence->base);mutex_unlock (&uq_mgr->userq_mutex); }
Christian König
maintainerQuoted 40 lines · Prike
[Public]
Quoted 26 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, May 8, 2025 9:56 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: lock the eviction fence before signaling itReview
Quoted 8 lines · Prike Liang
Lock and refer to the eviction fence before trying to signal it.
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.cdrivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c amdgpu_eviction_fence_suspend_worker(struct
Quoted 4 lines
index
1a7469543db5..dd272c1fcbb4100644drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +0
-0@@ -108,13 +108,16 @@ amdgpu_eviction_fence_suspend_worker(struct
work_struct*work)Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +0
-0struct amdgpu_eviction_fence *ev_fence;Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c amdgpu_eviction_fence_suspend_worker(struct work_struct *work)
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +2
-1mutex_lock (&uq_mgr->userq_mutex); - ev_fence = evf_mgr->ev_fence; +spin_lock (&evf_mgr->ev_fence_lock); + ev_fence = (struct amdgpu_eviction_fence *)dma_fence_get (&evf_mgr- ev_fence->base);That case is not a good approach, instead put the
dma_fence_geton a separate line.Thank for the suggestion, as such change can benefit on the readability? Do you mean something like the following change?
struct amdgpu_eviction_fence *ev_fence;
Review
Quoted 9 lines
(quoted diff) +6
-1+ struct amdgpu_eviction_fence *ev_fence = NULL; + struct dma_fence *base_fence; mutex_lock(&uq_mgr->userq_mutex); - ev_fence = evf_mgr->ev_fence; + spin_lock(&evf_mgr->ev_fence_lock); + base_fence = dma_fence_get(&evf_mgr->ev_fence->base); + if (base_fence) + ev_fence = (struct amdgpu_eviction_fence *)base_fence;
No what I mean was this just the other way around:
ev_fence = evf_mgr->ev_fence;
if (ev_fence)
dma_fence_get(&ev_fence->base);
E.g. try to avoid the return value of dma_fence_get(). That is only meant to be used in macros or when we pass the value to functions who take ownership of the reference.
Regards,
Christian.
Quoted 25 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +2
-0+spin_unlock (&evf_mgr->ev_fence_lock);if (!ev_fence) goto unlock;amdgpu_userq_evict (uq_mgr, ev_fence); unlock: +dma_fence_put (base_fence);Quoted 16 lines
Apart from that it looks good to me.
Christian.
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +2
-0+spin_unlock (&evf_mgr->ev_fence_lock);if (!ev_fence) goto unlock;amdgpu_userq_evict (uq_mgr, ev_fence); unlock: +dma_fence_put (&evf_mgr->ev_fence->base);mutex_unlock (&uq_mgr->userq_mutex); }