Skip to content

Commit 3629e1b

Browse files
committed
nouveau: 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. Acked-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Dave Airlie <airlied@redhat.com> Link: https://lore.kernel.org/r/20250904021643.2050497-3-airlied@gmail.com
1 parent 619ddf5 commit 3629e1b

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

drivers/gpu/drm/nouveau/nouveau_prime.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,21 @@ struct dma_buf *nouveau_gem_prime_export(struct drm_gem_object *gobj,
108108
int flags)
109109
{
110110
struct nouveau_bo *nvbo = nouveau_gem_object(gobj);
111+
struct ttm_operation_ctx ctx = {
112+
.interruptible = true,
113+
.no_wait_gpu = true,
114+
/* We opt to avoid OOM on system pages allocations */
115+
.gfp_retry_mayfail = true,
116+
.allow_res_evict = false,
117+
};
118+
int ret;
111119

112120
if (nvbo->no_share)
113121
return ERR_PTR(-EPERM);
114122

123+
ret = ttm_bo_setup_export(&nvbo->bo, &ctx);
124+
if (ret)
125+
return ERR_PTR(ret);
126+
115127
return drm_gem_prime_export(gobj, flags);
116128
}

0 commit comments

Comments
 (0)