drm/amdgpu: Use dma_resv_lock instead in BO release_notify
Subsystems (3)
PATCH 1/1 drm/amdgpu: Use dma_resv_lock instead in BO release_notify
The reservation object might be locked again by evict/swap after individualized. The race is like below.
cpu 0 cpu 1
BO release BO evict or swapttm_bo_individualize_resv {resv = &_resv}
ttm_bo_evict_swapout_allowable
dma_resv_trylock(resv)
->release_notify() {BUG_ON(!trylock(resv))}
if (!ttm_bo_get_unless_zero)) dma_resv_unlock(resv)
Actually this is not a bug if trylock fails. So use dma_resv_lock instead.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -1
@@ -318,7 +318,7 @@ int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo) ef =container_of (dma_fence_get (&info->eviction_fence->base), struct amdgpu_amdkfd_fence, base); -BUG_ON (!dma_resv_trylock (bo->tbo.base.resv)); +dma_resv_lock (bo->tbo.base.resv,NULL ); ret =amdgpu_amdkfd_remove_eviction_fence (bo, ef);dma_resv_unlock (bo->tbo.base.resv);
Signature · 6 lines
2.25.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerAm 2021-05-21 um 1:26 a.m. schrieb xinhui pan:
Quoted 8 lines
The reservation object might be locked again by evict/swap after individualized. The race is like below.
cpu 0 cpu 1
BO release BO evict or swapttm_bo_individualize_resv{resv =&_resv}
ttm_bo_evict_swapout_allowable
dma_resv_trylock(resv)
->release_notify() {BUG_ON(!trylock(resv))}
Quoted 4 lines
if (!ttm_bo_get_unless_zero)) dma_resv_unlock(resv)Actually this is not a bug if trylock fails. So use
dma_resv_lockinstead.
Please test this with LOCKDEP enabled. I believe the trylock here was needed to avoid potential deadlocks. Maybe Christian can fill in more details.
Regards,
Felix
Quoted 11 lines
Signed-off-by xinhui pan <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo) · line 324
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-1@@ -318,7 +318,7 @@ int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo) ef =container_of (dma_fence_get (&info->eviction_fence->base), struct amdgpu_amdkfd_fence, base); -BUG_ON (!dma_resv_trylock (bo->tbo.base.resv)); +dma_resv_lock (bo->tbo.base.resv,NULL ); ret =amdgpu_amdkfd_remove_eviction_fence (bo, ef);dma_resv_unlock (bo->tbo.base.resv);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerAm 21.05.21 um 20:24 schrieb Felix Kuehling:
Quoted 13 lines
Am 2021-05-21 um 1:26 a.m. schrieb xinhui pan:
Quoted 8 lines
The reservation object might be locked again by evict/swap after individualized. The race is like below.
cpu 0 cpu 1
BO release BO evict or swapttm_bo_individualize_resv{resv =&_resv}
ttm_bo_evict_swapout_allowable
dma_resv_trylock(resv)
->release_notify() {BUG_ON(!trylock(resv))}Quoted 4 lines
if (!ttm_bo_get_unless_zero)) dma_resv_unlock(resv)Actually this is not a bug if trylock fails. So use
dma_resv_lockinstead.
Quoted 3 lines
Please test this with LOCKDEP enabled. I believe the trylock here was needed to avoid potential deadlocks. Maybe Christian can fill in more details.
Unfortunately I don't remember why trylock was needed here either.
But yes, testing with lockdep enabled is a really good idea.
Regards,
Christian.
Quoted 18 lines
Regards,
FelixQuoted 13 lines
Signed-off-by xinhui pan <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0@@ -318,7 +318,7 @@ int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo) ef =container_of (dma_fence_get (&info->eviction_fence->base), struct amdgpu_amdkfd_fence, base);
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo) · line 324
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-1-BUG_ON (!dma_resv_trylock (bo->tbo.base.resv)); +dma_resv_lock (bo->tbo.base.resv,NULL ); ret =amdgpu_amdkfd_remove_eviction_fence (bo, ef);dma_resv_unlock (bo->tbo.base.resv);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[AMD Official Use Only]
Oh, sorry for that. I notice the lockdep warning too.
I just think we use trylock elsewhere because we hold the lru_lock mostly. So I think we can do something like below. Let me verify it later.
@@ -318,7 +318,9 @@ int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo)
ef = container_of(dma_fence_get(&info->eviction_fence->base),
struct amdgpu_amdkfd_fence, base);+ spin_lock(&bo->tbo.bdev->lru_lock);
BUG_ON(!dma_resv_trylock(bo->tbo.base.resv));
+ spin_unlock(&bo->tbo.bdev->lru_lock);
ret = amdgpu_amdkfd_remove_eviction_fence(bo, ef);
dma_resv_unlock(bo->tbo.base.resv);________________________________________
发件人: Kuehling, Felix <[email protected]>
发送时间: 2021年5月22日 2:24
收件人: Pan, Xinhui; [email protected]
抄送: Deucher, Alexander; Koenig, Christian
主题: Re: [PATCH] drm/amdgpu: Use dma_resv_lock instead in BO release_notify
Am 2021-05-21 um 1:26 a.m. schrieb xinhui pan:
Quoted 8 lines
The reservation object might be locked again by evict/swap after individualized. The race is like below.
cpu 0 cpu 1
BO release BO evict or swapttm_bo_individualize_resv{resv =&_resv}
ttm_bo_evict_swapout_allowable
dma_resv_trylock(resv)
->release_notify() {BUG_ON(!trylock(resv))}
Quoted 4 lines
if (!ttm_bo_get_unless_zero)) dma_resv_unlock(resv)Actually this is not a bug if trylock fails. So use
dma_resv_lockinstead.
Please test this with LOCKDEP enabled. I believe the trylock here was needed to avoid potential deadlocks. Maybe Christian can fill in more details.
Regards,
Felix
Quoted 11 lines
Signed-off-by xinhui pan <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo) · line 324
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-1@@ -318,7 +318,7 @@ int amdgpu_amdkfd_remove_fence_on_pt_pd_bos(struct amdgpu_bo *bo) ef =container_of (dma_fence_get (&info->eviction_fence->base), struct amdgpu_amdkfd_fence, base); -BUG_ON (!dma_resv_trylock (bo->tbo.base.resv)); +dma_resv_lock (bo->tbo.base.resv,NULL ); ret =amdgpu_amdkfd_remove_eviction_fence (bo, ef);dma_resv_unlock (bo->tbo.base.resv);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx