Skip to contentSkip to conversation

drm/amdgpu/evf: skip BOs no longer in the VM

PATCH In review Benjamin Cheng 2 participants 4 messages Oct 13

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

PATCH 1/1 drm/amdgpu/evf: skip BOs no longer in the VM

If the eviction fence restore gets triggered while a BO unmap is happening, the attempt to lock the BO for restore will fail. On retry, drm_exec locks the contended BO first, but it is not actually required to be locked, and the eviction fence should not be attached to such a BO.

If the BO was freed, this extra lock will cause BUG_ON to fire in dma_resv_add_fence, since the gem object and its resv lists are freed already.

drm_exec::prelocked remains set only if the object was locked on retry but not actually requested to be locked, so use that to detect this case and skip it.

Fixes 2cd7284ba54b ("drm/amdgpu: completely rework eviction fence handling v2")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +4 -0
index a0802012de49..1e119173564b 100644
@@ -145,6 +145,10 @@ int amdgpu_evf_mgr_rearm(struct amdgpu_eviction_fence_mgr *evf_mgr,
 	/* And add it to all existing BOs */
 	drm_exec_for_each_locked_object(exec, index, obj) {
 		struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
+		/* A BO may be locked after it has been dropped from the VM due
+		 * to how drm_exec treats contention. */
+		if (obj == exec->prelocked)
+			continue;
 
 		amdgpu_evf_mgr_attach_fence(evf_mgr, bo);
 	}
Signature · 1 line
2.55.0
#1 lore raw
Quoted 1 line · Benjamin Cheng

If the eviction fence restore gets triggered while a BO unmap is

Sorry, this should be s/eviction fence restore/userq vm restore/

Quoted 34 lines

happening, the attempt to lock the BO for restore will fail. On retry, drm_exec locks the contended BO first, but it is not actually required to be locked, and the eviction fence should not be attached to such a BO.

If the BO was freed, this extra lock will cause BUG_ON to fire in dma_resv_add_fence, since the gem object and its resv lists are freed already.

drm_exec::prelocked remains set only if the object was locked on retry but not actually requested to be locked, so use that to detect this case and skip it.

Fixes 2cd7284ba54b ("drm/amdgpu: completely rework eviction fence handling v2")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +4 -0
index a0802012de49..1e119173564b 100644
@@ -145,6 +145,10 @@ int amdgpu_evf_mgr_rearm(struct amdgpu_eviction_fence_mgr *evf_mgr,
 	/* And add it to all existing BOs */
 	drm_exec_for_each_locked_object(exec, index, obj) {
 		struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
+		/* A BO may be locked after it has been dropped from the VM due
+		 * to how drm_exec treats contention. */
+		if (obj == exec->prelocked)
+			continue;
 
 		amdgpu_evf_mgr_attach_fence(evf_mgr, bo);
 	}
maintainer
#2 lore raw
In reply to Benjamin Cheng
Quoted 6 lines · Benjamin Cheng

If the eviction fence restore gets triggered while a BO unmap is happening, the attempt to lock the BO for restore will fail. On retry, drm_exec locks the contended BO first, but it is not actually required to be locked, and the eviction fence should not be attached to such a BO.

Quoted 7 lines

If the BO was freed, this extra lock will cause BUG_ON to fire in dma_resv_add_fence, since the gem object and its resv lists are freed already.

drm_exec::prelocked remains set only if the object was locked on retry but not actually requested to be locked, so use that to detect this case and skip it.

Vitaly and I already found the real root cause for this and I'm about to push the fix to amd-staging-drm-next.

Regards,
Christian.

Quoted 22 lines
Fixes 2cd7284ba54b ("drm/amdgpu: completely rework eviction fence handling v2")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +4 -0
index a0802012de49..1e119173564b 100644
@@ -145,6 +145,10 @@ int amdgpu_evf_mgr_rearm(struct amdgpu_eviction_fence_mgr *evf_mgr,
 	/* And add it to all existing BOs */
 	drm_exec_for_each_locked_object(exec, index, obj) {
 		struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
+		/* A BO may be locked after it has been dropped from the VM due
+		 * to how drm_exec treats contention. */
+		if (obj == exec->prelocked)
+			continue;
 
 		amdgpu_evf_mgr_attach_fence(evf_mgr, bo);
 	}
#3 lore raw
Quoted 7 lines · Christian König
Quoted 6 lines · Benjamin Cheng

If the eviction fence restore gets triggered while a BO unmap is happening, the attempt to lock the BO for restore will fail. On retry, drm_exec locks the contended BO first, but it is not actually required to be locked, and the eviction fence should not be attached to such a BO.

Quoted 8 lines
Quoted 7 lines

If the BO was freed, this extra lock will cause BUG_ON to fire in dma_resv_add_fence, since the gem object and its resv lists are freed already.

drm_exec::prelocked remains set only if the object was locked on retry but not actually requested to be locked, so use that to detect this case and skip it.

Vitaly and I already found the real root cause for this and I'm about to push the fix to amd-staging-drm-next.

Ah, thanks I did not see that one. Indeed the same issue.

Quoted 25 lines

Regards,
Christian.

Quoted 21 lines
Fixes 2cd7284ba54b ("drm/amdgpu: completely rework eviction fence handling v2")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +4 -0
index a0802012de49..1e119173564b 100644
@@ -145,6 +145,10 @@ int amdgpu_evf_mgr_rearm(struct amdgpu_eviction_fence_mgr *evf_mgr,
 	/* And add it to all existing BOs */
 	drm_exec_for_each_locked_object(exec, index, obj) {
 		struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
+		/* A BO may be locked after it has been dropped from the VM due
+		 * to how drm_exec treats contention. */
+		if (obj == exec->prelocked)
+			continue;
 
 		amdgpu_evf_mgr_attach_fence(evf_mgr, bo);
 	}