From: Dave Airlie <airl...@redhat.com>

Before exporting a buffer, make sure it has been populated with
pages at least once.

Cc: Thomas Hellström <thomas.hellst...@linux.intel.com>
Signed-off-by: Dave Airlie <airl...@redhat.com>
---
 drivers/gpu/drm/xe/xe_dma_buf.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_buf.c
index 346f857f3837..71b70e17bddd 100644
--- a/drivers/gpu/drm/xe/xe_dma_buf.c
+++ b/drivers/gpu/drm/xe/xe_dma_buf.c
@@ -191,10 +191,22 @@ struct dma_buf *xe_gem_prime_export(struct drm_gem_object 
*obj, int flags)
 {
        struct xe_bo *bo = gem_to_xe_bo(obj);
        struct dma_buf *buf;
+       struct ttm_operation_ctx ctx = {
+               .interruptible = true,
+               .no_wait_gpu = true,
+               /* We opt to avoid OOM on system pages allocations */
+               .gfp_retry_mayfail = true,
+               .allow_res_evict = false,
+       };
+       int ret;
 
        if (bo->vm)
                return ERR_PTR(-EPERM);
 
+       ret = ttm_bo_setup_export(&bo->ttm, &ctx);
+       if (ret)
+               return ERR_PTR(ret);
+
        buf = drm_gem_prime_export(obj, flags);
        if (!IS_ERR(buf))
                buf->ops = &xe_dmabuf_ops;
-- 
2.50.1

Reply via email to