Re: [PATCH v7 09/12] drm/xe/dma_buf: Block export of DONTNEED/purged BOs

Thomas Hellström
2026-03-24T14:47:29Z

On Mon, 2026-03-23 at 15:00 +0530, Arvind Yadav wrote:
> Don't allow exporting BOs marked DONTNEED or PURGED as dma-bufs.
> DONTNEED BOs can have their contents discarded at any time, making
> the exported dma-buf unusable for external devices. PURGED BOs have
> no backing store and are permanently invalid.
>
> Return -EBUSY for DONTNEED BOs (temporary purgeable state) and
> -EINVAL for purged BOs (permanent, no backing store).
>
> The export path now checks the BO's purgeable state before creating
> the dma-buf, preventing external devices from accessing memory that
> may be purged at any time.
>
> v6:
> - Split DONTNEED → -EBUSY and PURGED → -EINVAL for consistency
>   with the rest of the series (Thomas, Matt)
>
> v7:
> - Use Interruptible lock. (Thomas)
>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
> Signed-off-by: Arvind Yadav <arvind.yadav@intel.com>
> ---
>  drivers/gpu/drm/xe/xe_dma_buf.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c
> b/drivers/gpu/drm/xe/xe_dma_buf.c
> index ea370cd373e9..4edbe9f3c001 100644
> --- a/drivers/gpu/drm/xe/xe_dma_buf.c
> +++ b/drivers/gpu/drm/xe/xe_dma_buf.c
> @@ -223,6 +223,23 @@ struct dma_buf *xe_gem_prime_export(struct
> drm_gem_object *obj, int flags)
>   if (bo->vm)
>   return ERR_PTR(-EPERM);
>
> + /*
> + * Reject exporting purgeable BOs. DONTNEED BOs can be
> purged
> + * at any time, making the exported dma-buf unusable. Purged
> BOs
> + * have no backing store and are permanently invalid.
> + */
> + xe_bo_lock(bo, true);

Missing error check.

/Thomas

> + if (xe_bo_madv_is_dontneed(bo)) {
> + ret = -EBUSY;
> + goto out_unlock;
> + }
> +
> + if (xe_bo_is_purged(bo)) {
> + ret = -EINVAL;
> + goto out_unlock;
> + }
> + xe_bo_unlock(bo);
> +
>   ret = ttm_bo_setup_export(&bo->ttm, &ctx);
>   if (ret)
>   return ERR_PTR(ret);
> @@ -232,6 +249,10 @@ struct dma_buf *xe_gem_prime_export(struct
> drm_gem_object *obj, int flags)
>   buf->ops = &xe_dmabuf_ops;
>
>   return buf;
> +
> +out_unlock:
> + xe_bo_unlock(bo);
> + return ERR_PTR(ret);
>  }
>
>  static struct drm_gem_object *