]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/msm/gem: Mark active before pinning
authorRob Clark <robdclark@chromium.org>
Wed, 28 Jul 2021 01:06:18 +0000 (18:06 -0700)
committerRob Clark <robdclark@chromium.org>
Wed, 28 Jul 2021 16:19:00 +0000 (09:19 -0700)
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 <robdclark@chromium.org>
Link: https://lore.kernel.org/r/20210728010632.2633470-14-robdclark@gmail.com
Signed-off-by: Rob Clark <robdclark@chromium.org>
drivers/gpu/drm/msm/msm_gem.c
drivers/gpu/drm/msm/msm_gem_submit.c

index cfcca3975055c1f91e276e0e3ab26cdf8894d6cc..5db07fc287ad4e3c470f052af3c360361aa296ae 100644 (file)
@@ -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);
index c2ecec5b11c49c14c2bb29ca783953db7d1f653a..fc25a85eb1cae31b1ee01c7026e08ce2d453af45 100644 (file)
@@ -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);
        }