Skip to content

Commit 5024307

Browse files
committed
ttm/bo: add an API to populate a bo before exporting.
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
1 parent 7df7b72 commit 5024307

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

drivers/gpu/drm/ttm/ttm_bo.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,3 +1283,18 @@ int ttm_bo_populate(struct ttm_buffer_object *bo,
12831283
return 0;
12841284
}
12851285
EXPORT_SYMBOL(ttm_bo_populate);
1286+
1287+
int ttm_bo_setup_export(struct ttm_buffer_object *bo,
1288+
struct ttm_operation_ctx *ctx)
1289+
{
1290+
int ret;
1291+
1292+
ret = ttm_bo_reserve(bo, false, false, NULL);
1293+
if (ret != 0)
1294+
return ret;
1295+
1296+
ret = ttm_bo_populate(bo, ctx);
1297+
ttm_bo_unreserve(bo);
1298+
return ret;
1299+
}
1300+
EXPORT_SYMBOL(ttm_bo_setup_export);

include/drm/ttm/ttm_bo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ pgprot_t ttm_io_prot(struct ttm_buffer_object *bo, struct ttm_resource *res,
466466
void ttm_bo_tt_destroy(struct ttm_buffer_object *bo);
467467
int ttm_bo_populate(struct ttm_buffer_object *bo,
468468
struct ttm_operation_ctx *ctx);
469+
int ttm_bo_setup_export(struct ttm_buffer_object *bo,
470+
struct ttm_operation_ctx *ctx);
469471

470472
/* Driver LRU walk helpers initially targeted for shrinking. */
471473

0 commit comments

Comments
 (0)