]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
drm/etnaviv: populate GEM objects on cpu_prep
authorLucas Stach <dev@lynxeye.de>
Tue, 6 Jun 2017 07:17:08 +0000 (09:17 +0200)
committerLucas Stach <l.stach@pengutronix.de>
Mon, 3 Jul 2017 08:54:54 +0000 (10:54 +0200)
CPU prep is the point where we can reasonably return an error to userspace
when something goes wrong while populating the object. If we leave the
object unpopulated at this point, the allocation will happen in the
fault handler when userspace accesses the object through the mmap space,
where we don't have any other option than to OOM the system.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
drivers/gpu/drm/etnaviv/etnaviv_gem.c

index a4f392c38b38d544475a69f7664f3f1347381476..408c0fc476dd51e03a75c3cca1a5794023e6d19c 100644 (file)
@@ -413,6 +413,16 @@ int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op,
        bool write = !!(op & ETNA_PREP_WRITE);
        int ret;
 
+       if (!etnaviv_obj->sgt) {
+               void *ret;
+
+               mutex_lock(&etnaviv_obj->lock);
+               ret = etnaviv_gem_get_pages(etnaviv_obj);
+               mutex_unlock(&etnaviv_obj->lock);
+               if (IS_ERR(ret))
+                       return PTR_ERR(ret);
+       }
+
        if (op & ETNA_PREP_NOSYNC) {
                if (!reservation_object_test_signaled_rcu(etnaviv_obj->resv,
                                                          write))
@@ -427,16 +437,6 @@ int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op,
        }
 
        if (etnaviv_obj->flags & ETNA_BO_CACHED) {
-               if (!etnaviv_obj->sgt) {
-                       void *ret;
-
-                       mutex_lock(&etnaviv_obj->lock);
-                       ret = etnaviv_gem_get_pages(etnaviv_obj);
-                       mutex_unlock(&etnaviv_obj->lock);
-                       if (IS_ERR(ret))
-                               return PTR_ERR(ret);
-               }
-
                dma_sync_sg_for_cpu(dev->dev, etnaviv_obj->sgt->sgl,
                                    etnaviv_obj->sgt->nents,
                                    etnaviv_op_to_dma_dir(op));