On 04.09.25 04:16, Dave Airlie wrote:
> From: Dave Airlie <airl...@redhat.com>
> 
> 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.koe...@amd.com>
> Cc: Thomas Hellström <thomas.hellst...@linux.intel.com>
> Cc: Simona Vetter <simona.vet...@ffwll.ch>
> Signed-off-by: Dave Airlie <airl...@redhat.com>

Patches #1 and #2 Reviewed-by: Christian König <christian.koe...@amd.com>

I don't see patches #3 and #4 in my inbox, but I guess it's the same for other 
drivers.

Regards,
Christian.

> ---
>  drivers/gpu/drm/ttm/ttm_bo.c | 15 +++++++++++++++
>  include/drm/ttm/ttm_bo.h     |  2 ++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 273757974b9f..a815c7478d3f 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1284,3 +1284,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, bo->resource->placement & TTM_PL_FLAG_MEMCG, 
> ctx);
> +     ttm_bo_unreserve(bo);
> +     return ret;
> +}
> +EXPORT_SYMBOL(ttm_bo_setup_export);
> diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
> index c33b3667ae76..cdc9f5d1b420 100644
> --- a/include/drm/ttm/ttm_bo.h
> +++ b/include/drm/ttm/ttm_bo.h
> @@ -473,6 +473,8 @@ void ttm_bo_tt_destroy(struct ttm_buffer_object *bo);
>  int ttm_bo_populate(struct ttm_buffer_object *bo,
>                   bool memcg_account,
>                   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. */
>  

Reply via email to