Skip to content

Commit 91494de

Browse files
committed
xe: 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. Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com> 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-4-airlied@gmail.com
1 parent 3629e1b commit 91494de

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

drivers/gpu/drm/xe/xe_dma_buf.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,22 @@ struct dma_buf *xe_gem_prime_export(struct drm_gem_object *obj, int flags)
191191
{
192192
struct xe_bo *bo = gem_to_xe_bo(obj);
193193
struct dma_buf *buf;
194+
struct ttm_operation_ctx ctx = {
195+
.interruptible = true,
196+
.no_wait_gpu = true,
197+
/* We opt to avoid OOM on system pages allocations */
198+
.gfp_retry_mayfail = true,
199+
.allow_res_evict = false,
200+
};
201+
int ret;
194202

195203
if (bo->vm)
196204
return ERR_PTR(-EPERM);
197205

206+
ret = ttm_bo_setup_export(&bo->ttm, &ctx);
207+
if (ret)
208+
return ERR_PTR(ret);
209+
198210
buf = drm_gem_prime_export(obj, flags);
199211
if (!IS_ERR(buf))
200212
buf->ops = &xe_dmabuf_ops;

0 commit comments

Comments
 (0)