Skip to contentSkip to conversation

drm/msm/gem: Unpin objects slightly later

PATCH In review Rob Clark 2 participants 2 messages Sep 23, 2022 – Sep 29, 2022

Subsystems (4)
lore
Share & tools
lore

Rob Clark

author
#0 lore raw

PATCH 1/1 drm/msm/gem: Unpin objects slightly later

From: Rob Clark <[email protected]>

The introduction of 025d27239a2f exposes a problem with f371bcc0c2ac, in that we need to keep the object pinned in the time the submit is queued up in the gpu scheduler. Otherwise the shrinker will see it as a thing that can be evicted if we wait for it to be signaled. But if the shrinker path is waiting on it with the obj lock held, the job cannot be scheduled, as that also requires briefly grabbing the obj lock, leading to deadlock. (Not to mention, we don't want the shrinker to evict an obj queued up in gpu scheduler.)

Fixes f371bcc0c2ac ("drm/msm/gem: Unpin buffers earlier")
Fixes 025d27239a2f ("drm/msm/gem: Evict active GEM objects when necessary")
---
 drivers/gpu/drm/msm/msm_gem_submit.c | 4 ++--
 drivers/gpu/drm/msm/msm_ringbuffer.c | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/msm/msm_gem_submit.c +2 -2
index 5599d93ec0d2..c670591995e6 100644
@@ -501,11 +501,11 @@ static int submit_reloc(struct msm_gem_submit *submit, struct msm_gem_object *ob
  */
 static void submit_cleanup(struct msm_gem_submit *submit, bool error)
 {
-	unsigned cleanup_flags = BO_LOCKED | BO_OBJ_PINNED;
+	unsigned cleanup_flags = BO_LOCKED;
 	unsigned i;
 
 	if (error)
-		cleanup_flags |= BO_VMA_PINNED;
+		cleanup_flags |= BO_VMA_PINNED | BO_OBJ_PINNED;
 
 	for (i = 0; i < submit->nr_bos; i++) {
 		struct msm_gem_object *msm_obj = submit->bos[i].obj;
drivers/gpu/drm/msm/msm_ringbuffer.c +2 -1
index cad4c3525f0b..57a8e9564540 100644
@@ -25,7 +25,8 @@ static struct dma_fence *msm_job_run(struct drm_sched_job *job)
 
 		msm_gem_lock(obj);
 		msm_gem_unpin_vma_fenced(submit->bos[i].vma, fctx);
-		submit->bos[i].flags &= ~BO_VMA_PINNED;
+		msm_gem_unpin_locked(obj);
+		submit->bos[i].flags &= ~(BO_VMA_PINNED | BO_OBJ_PINNED);
 		msm_gem_unlock(obj);
 	}
 
Signature · 1 line
2.37.2
Tested-by on v1 1/1
#1 lore raw
Quoted 12 lines · Rob Clark

From: Rob Clark <[email protected]>

The introduction of 025d27239a2f exposes a problem with f371bcc0c2ac, in that we need to keep the object pinned in the time the submit is queued up in the gpu scheduler. Otherwise the shrinker will see it as a thing that can be evicted if we wait for it to be signaled. But if the shrinker path is waiting on it with the obj lock held, the job cannot be scheduled, as that also requires briefly grabbing the obj lock, leading to deadlock. (Not to mention, we don't want the shrinker to evict an obj queued up in gpu scheduler.)

Quoted 4 lines
Fixes f371bcc0c2ac ("drm/msm/gem: Unpin buffers earlier")
Fixes 025d27239a2f ("drm/msm/gem: Evict active GEM objects when necessary")
Quoted 40 lines
---
 drivers/gpu/drm/msm/msm_gem_submit.c | 4 ++--
 drivers/gpu/drm/msm/msm_ringbuffer.c | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/msm/msm_gem_submit.c +2 -2
index 5599d93ec0d2..c670591995e6 100644
@@ -501,11 +501,11 @@ static int submit_reloc(struct msm_gem_submit *submit, struct msm_gem_object *ob
  */
 static void submit_cleanup(struct msm_gem_submit *submit, bool error)
 {
-       unsigned cleanup_flags = BO_LOCKED | BO_OBJ_PINNED;
+       unsigned cleanup_flags = BO_LOCKED;
        unsigned i;
 
        if (error)
-               cleanup_flags |= BO_VMA_PINNED;
+               cleanup_flags |= BO_VMA_PINNED | BO_OBJ_PINNED;
 
        for (i = 0; i < submit->nr_bos; i++) {
                struct msm_gem_object *msm_obj = submit->bos[i].obj;
drivers/gpu/drm/msm/msm_ringbuffer.c +2 -2
index cad4c3525f0b..57a8e9564540 100644
@@ -25,7 +25,8 @@ static struct dma_fence *msm_job_run(struct drm_sched_job *job)
 
                msm_gem_lock(obj);
                msm_gem_unpin_vma_fenced(submit->bos[i].vma, fctx);
-               submit->bos[i].flags &= ~BO_VMA_PINNED;
+               msm_gem_unpin_locked(obj);
+               submit->bos[i].flags &= ~(BO_VMA_PINNED | BO_OBJ_PINNED);
                msm_gem_unlock(obj);
        }
 
--

2.37.2