]> www.infradead.org Git - users/hch/misc.git/commitdiff
ttm/bo: add an API to populate a bo before exporting.
authorDave Airlie <airlied@redhat.com>
Thu, 4 Sep 2025 02:16:39 +0000 (12:16 +1000)
committerDave Airlie <airlied@redhat.com>
Thu, 11 Sep 2025 00:01:38 +0000 (10:01 +1000)
While discussing cgroups we noticed a problem where you could export
a BO to a dma-buf without having it ever being backed or accounted for.

This meant in low memory situations or eventually with cgroups, a
lower privledged process might cause the compositor to try and allocate
a lot of memory on it's behalf and this could fail. At least make
sure the exporter has managed to allocate the RAM at least once
before exporting the object.

This only applies currently to TTM_PL_SYSTEM objects, because
GTT objects get populated on first validate, and VRAM doesn't
use TT.

Reviewed-by: Christian Koenig <christian.koenig@amd.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Simona Vetter <simona.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Link: https://lore.kernel.org/r/20250904021643.2050497-1-airlied@gmail.com
drivers/gpu/drm/ttm/ttm_bo.c
include/drm/ttm/ttm_bo.h

index f4d9e68b21e70cb25d0db5e79391233e1dc72221..29423ceeec5c7214e8f6d5d58b333a10c11b3a1d 100644 (file)
@@ -1283,3 +1283,18 @@ int ttm_bo_populate(struct ttm_buffer_object *bo,
        return 0;
 }
 EXPORT_SYMBOL(ttm_bo_populate);
+
+int ttm_bo_setup_export(struct ttm_buffer_object *bo,
+                       struct ttm_operation_ctx *ctx)
+{
+       int ret;
+
+       ret = ttm_bo_reserve(bo, false, false, NULL);
+       if (ret != 0)
+               return ret;
+
+       ret = ttm_bo_populate(bo, ctx);
+       ttm_bo_unreserve(bo);
+       return ret;
+}
+EXPORT_SYMBOL(ttm_bo_setup_export);
index 479b7ed075c0ffba21df971db7fef914c531a51d..e664a96540eb642d1b65f3daaa33704166d2295e 100644 (file)
@@ -466,6 +466,8 @@ pgprot_t ttm_io_prot(struct ttm_buffer_object *bo, struct ttm_resource *res,
 void ttm_bo_tt_destroy(struct ttm_buffer_object *bo);
 int ttm_bo_populate(struct ttm_buffer_object *bo,
                    struct ttm_operation_ctx *ctx);
+int ttm_bo_setup_export(struct ttm_buffer_object *bo,
+                       struct ttm_operation_ctx *ctx);
 
 /* Driver LRU walk helpers initially targeted for shrinking. */