Skip to content

Commit 619ddf5

Browse files
committed
amdgpu: populate buffers before exporting them.
Before exporting a buffer, make sure it has been populated with pages at least once. 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> Signed-off-by: Dave Airlie <airlied@redhat.com> Link: https://lore.kernel.org/r/20250904021643.2050497-2-airlied@gmail.com
1 parent 5024307 commit 619ddf5

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,23 @@ struct dma_buf *amdgpu_gem_prime_export(struct drm_gem_object *gobj,
313313
{
314314
struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj);
315315
struct dma_buf *buf;
316+
struct ttm_operation_ctx ctx = {
317+
.interruptible = true,
318+
.no_wait_gpu = true,
319+
/* We opt to avoid OOM on system pages allocations */
320+
.gfp_retry_mayfail = true,
321+
.allow_res_evict = false,
322+
};
323+
int ret;
316324

317325
if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm) ||
318326
bo->flags & AMDGPU_GEM_CREATE_VM_ALWAYS_VALID)
319327
return ERR_PTR(-EPERM);
320328

329+
ret = ttm_bo_setup_export(&bo->tbo, &ctx);
330+
if (ret)
331+
return ERR_PTR(ret);
332+
321333
buf = drm_gem_prime_export(gobj, flags);
322334
if (!IS_ERR(buf))
323335
buf->ops = &amdgpu_dmabuf_ops;

0 commit comments

Comments
 (0)