Commit 4541e4f2 authored by Rob Clark's avatar Rob Clark

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: default avatarRob Clark <robdclark@chromium.org>
Link: https://lore.kernel.org/r/20210728010632.2633470-14-robdclark@gmail.comSigned-off-by: default avatarRob Clark <robdclark@chromium.org>
parent fc40e5e1
......@@ -131,7 +131,6 @@ static struct page **get_pages(struct drm_gem_object *obj)
if (msm_obj->flags & (MSM_BO_WC|MSM_BO_UNCACHED))
sync_for_device(msm_obj);
GEM_WARN_ON(msm_obj->active_count);
update_inactive(msm_obj);
}
......@@ -813,7 +812,6 @@ void msm_gem_active_get(struct drm_gem_object *obj, struct msm_gpu *gpu)
GEM_WARN_ON(!msm_gem_is_locked(obj));
GEM_WARN_ON(msm_obj->madv != MSM_MADV_WILLNEED);
GEM_WARN_ON(msm_obj->dontneed);
GEM_WARN_ON(!msm_obj->sgt);
if (msm_obj->active_count++ == 0) {
mutex_lock(&priv->mm_lock);
......
......@@ -24,7 +24,8 @@
/* make sure these don't conflict w/ MSM_SUBMIT_BO_x */
#define BO_VALID 0x8000 /* is current addr in cmdstream correct/valid? */
#define BO_LOCKED 0x4000 /* obj lock is held */
#define BO_PINNED 0x2000 /* obj is pinned and on active list */
#define BO_ACTIVE 0x2000 /* active refcnt is held */
#define BO_PINNED 0x1000 /* obj is pinned and on active list */
static struct msm_gem_submit *submit_create(struct drm_device *dev,
struct msm_gpu *gpu,
......@@ -239,10 +240,11 @@ static void submit_cleanup_bo(struct msm_gem_submit *submit, int i,
struct drm_gem_object *obj = &submit->bos[i].obj->base;
unsigned flags = submit->bos[i].flags & cleanup_flags;
if (flags & BO_PINNED) {
if (flags & BO_PINNED)
msm_gem_unpin_iova_locked(obj, submit->aspace);
if (flags & BO_ACTIVE)
msm_gem_active_put(obj);
}
if (flags & BO_LOCKED)
dma_resv_unlock(obj->resv);
......@@ -252,7 +254,7 @@ static void submit_cleanup_bo(struct msm_gem_submit *submit, int i,
static void submit_unlock_unpin_bo(struct msm_gem_submit *submit, int i)
{
submit_cleanup_bo(submit, i, BO_PINNED | BO_LOCKED);
submit_cleanup_bo(submit, i, BO_PINNED | BO_ACTIVE | BO_LOCKED);
if (!(submit->bos[i].flags & BO_VALID))
submit->bos[i].iova = 0;
......@@ -356,6 +358,18 @@ static int submit_pin_objects(struct msm_gem_submit *submit)
submit->valid = true;
/*
* Increment active_count first, so if under memory pressure, we
* don't inadvertently evict a bo needed by the submit in order
* to pin an earlier bo in the same submit.
*/
for (i = 0; i < submit->nr_bos; i++) {
struct drm_gem_object *obj = &submit->bos[i].obj->base;
msm_gem_active_get(obj, submit->gpu);
submit->bos[i].flags |= BO_ACTIVE;
}
for (i = 0; i < submit->nr_bos; i++) {
struct drm_gem_object *obj = &submit->bos[i].obj->base;
uint64_t iova;
......@@ -367,8 +381,6 @@ static int submit_pin_objects(struct msm_gem_submit *submit)
if (ret)
break;
msm_gem_active_get(obj, submit->gpu);
submit->bos[i].flags |= BO_PINNED;
if (iova == submit->bos[i].iova) {
......@@ -502,7 +514,7 @@ static void submit_cleanup(struct msm_gem_submit *submit, bool error)
unsigned i;
if (error)
cleanup_flags |= BO_PINNED;
cleanup_flags |= BO_PINNED | BO_ACTIVE;
for (i = 0; i < submit->nr_bos; i++) {
struct msm_gem_object *msm_obj = submit->bos[i].obj;
......@@ -520,7 +532,7 @@ void msm_submit_retire(struct msm_gem_submit *submit)
struct drm_gem_object *obj = &submit->bos[i].obj->base;
msm_gem_lock(obj);
submit_cleanup_bo(submit, i, BO_PINNED);
submit_cleanup_bo(submit, i, BO_PINNED | BO_ACTIVE);
msm_gem_unlock(obj);
drm_gem_object_put(obj);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment