Update last_fence in the vm-bind path instead of kernel managed path.

last_fence is used to wait for work to finish in vm_bind contexts but not
used for kernel managed contexts.

This fixes a bug where last_fence is not waited on context close leading
to faults as resources are freed while in use.

Fixes: 92395af63a99 ("drm/msm: Add VM_BIND submitqueue")
Signed-off-by: Anna Maniscalco <[email protected]>
---
Changes in v3:
- Fixed Signed-off-by tag
- Link to v2: 
https://lore.kernel.org/r/[email protected]

Changes in v2:
- Only update last_fence on vm_bind path
- Link to v1: 
https://lore.kernel.org/r/[email protected]
---
 drivers/gpu/drm/msm/msm_gem_submit.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c 
b/drivers/gpu/drm/msm/msm_gem_submit.c
index 
3ab3b27134f93b01236fec5833a18a6e2ad2cf5e..75d9f357437006ff261db148901e176eae670d41
 100644
--- a/drivers/gpu/drm/msm/msm_gem_submit.c
+++ b/drivers/gpu/drm/msm/msm_gem_submit.c
@@ -414,6 +414,11 @@ static void submit_attach_object_fences(struct 
msm_gem_submit *submit)
                                         submit->user_fence,
                                         DMA_RESV_USAGE_BOOKKEEP,
                                         DMA_RESV_USAGE_BOOKKEEP);
+
+               last_fence = vm->last_fence;
+               vm->last_fence = dma_fence_unwrap_merge(submit->user_fence, 
last_fence);
+               dma_fence_put(last_fence);
+
                return;
        }
 
@@ -427,10 +432,6 @@ static void submit_attach_object_fences(struct 
msm_gem_submit *submit)
                        dma_resv_add_fence(obj->resv, submit->user_fence,
                                           DMA_RESV_USAGE_READ);
        }
-
-       last_fence = vm->last_fence;
-       vm->last_fence = dma_fence_unwrap_merge(submit->user_fence, last_fence);
-       dma_fence_put(last_fence);
 }
 
 static int submit_bo(struct msm_gem_submit *submit, uint32_t idx,

---
base-commit: b5bad77e1e3c7249e4c0c88f98477e1ee7669b63
change-id: 20251009-close_fence_wait_fix-00e1c2521eee

Best regards,
-- 
Anna Maniscalco <[email protected]>

Reply via email to