Skip to content

Commit 4541e4f

Browse files
committed
drm/msm/gem: Mark active before pinning
Mark all the bos in the submit as active, before pinning, to prevent evicting a buffer in the same submit to make room for a buffer earlier in the table. Signed-off-by: Rob Clark <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rob Clark <[email protected]>
1 parent fc40e5e commit 4541e4f

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

drivers/gpu/drm/msm/msm_gem.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ static struct page **get_pages(struct drm_gem_object *obj)
131131
if (msm_obj->flags & (MSM_BO_WC|MSM_BO_UNCACHED))
132132
sync_for_device(msm_obj);
133133

134-
GEM_WARN_ON(msm_obj->active_count);
135134
update_inactive(msm_obj);
136135
}
137136

@@ -813,7 +812,6 @@ void msm_gem_active_get(struct drm_gem_object *obj, struct msm_gpu *gpu)
813812
GEM_WARN_ON(!msm_gem_is_locked(obj));
814813
GEM_WARN_ON(msm_obj->madv != MSM_MADV_WILLNEED);
815814
GEM_WARN_ON(msm_obj->dontneed);
816-
GEM_WARN_ON(!msm_obj->sgt);
817815

818816
if (msm_obj->active_count++ == 0) {
819817
mutex_lock(&priv->mm_lock);

drivers/gpu/drm/msm/msm_gem_submit.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
/* make sure these don't conflict w/ MSM_SUBMIT_BO_x */
2525
#define BO_VALID 0x8000 /* is current addr in cmdstream correct/valid? */
2626
#define BO_LOCKED 0x4000 /* obj lock is held */
27-
#define BO_PINNED 0x2000 /* obj is pinned and on active list */
27+
#define BO_ACTIVE 0x2000 /* active refcnt is held */
28+
#define BO_PINNED 0x1000 /* obj is pinned and on active list */
2829

2930
static struct msm_gem_submit *submit_create(struct drm_device *dev,
3031
struct msm_gpu *gpu,
@@ -239,10 +240,11 @@ static void submit_cleanup_bo(struct msm_gem_submit *submit, int i,
239240
struct drm_gem_object *obj = &submit->bos[i].obj->base;
240241
unsigned flags = submit->bos[i].flags & cleanup_flags;
241242

242-
if (flags & BO_PINNED) {
243+
if (flags & BO_PINNED)
243244
msm_gem_unpin_iova_locked(obj, submit->aspace);
245+
246+
if (flags & BO_ACTIVE)
244247
msm_gem_active_put(obj);
245-
}
246248

247249
if (flags & BO_LOCKED)
248250
dma_resv_unlock(obj->resv);
@@ -252,7 +254,7 @@ static void submit_cleanup_bo(struct msm_gem_submit *submit, int i,
252254

253255
static void submit_unlock_unpin_bo(struct msm_gem_submit *submit, int i)
254256
{
255-
submit_cleanup_bo(submit, i, BO_PINNED | BO_LOCKED);
257+
submit_cleanup_bo(submit, i, BO_PINNED | BO_ACTIVE | BO_LOCKED);
256258

257259
if (!(submit->bos[i].flags & BO_VALID))
258260
submit->bos[i].iova = 0;
@@ -356,6 +358,18 @@ static int submit_pin_objects(struct msm_gem_submit *submit)
356358

357359
submit->valid = true;
358360

361+
/*
362+
* Increment active_count first, so if under memory pressure, we
363+
* don't inadvertently evict a bo needed by the submit in order
364+
* to pin an earlier bo in the same submit.
365+
*/
366+
for (i = 0; i < submit->nr_bos; i++) {
367+
struct drm_gem_object *obj = &submit->bos[i].obj->base;
368+
369+
msm_gem_active_get(obj, submit->gpu);
370+
submit->bos[i].flags |= BO_ACTIVE;
371+
}
372+
359373
for (i = 0; i < submit->nr_bos; i++) {
360374
struct drm_gem_object *obj = &submit->bos[i].obj->base;
361375
uint64_t iova;
@@ -367,8 +381,6 @@ static int submit_pin_objects(struct msm_gem_submit *submit)
367381
if (ret)
368382
break;
369383

370-
msm_gem_active_get(obj, submit->gpu);
371-
372384
submit->bos[i].flags |= BO_PINNED;
373385

374386
if (iova == submit->bos[i].iova) {
@@ -502,7 +514,7 @@ static void submit_cleanup(struct msm_gem_submit *submit, bool error)
502514
unsigned i;
503515

504516
if (error)
505-
cleanup_flags |= BO_PINNED;
517+
cleanup_flags |= BO_PINNED | BO_ACTIVE;
506518

507519
for (i = 0; i < submit->nr_bos; i++) {
508520
struct msm_gem_object *msm_obj = submit->bos[i].obj;
@@ -520,7 +532,7 @@ void msm_submit_retire(struct msm_gem_submit *submit)
520532
struct drm_gem_object *obj = &submit->bos[i].obj->base;
521533

522534
msm_gem_lock(obj);
523-
submit_cleanup_bo(submit, i, BO_PINNED);
535+
submit_cleanup_bo(submit, i, BO_PINNED | BO_ACTIVE);
524536
msm_gem_unlock(obj);
525537
drm_gem_object_put(obj);
526538
}

0 commit comments

Comments
 (0)