[Intel-xe] [PATCH] drm/xe: Disallow pinning dma-bufs in VRAM
Thomas Hellström
thomas.hellstrom at linux.intel.com
Wed Sep 20 09:51:46 UTC 2023
On 9/20/23 11:35, Oded Gabbay wrote:
> On Tue, Sep 19, 2023 at 11:46 AM Thomas Hellström
> <thomas.hellstrom at linux.intel.com> wrote:
>> For now only support pinning in TT memory, for two reasons:
>> 1) Avoid pinning in a placement not accessible to some importers.
>> 2) Pinning in VRAM requires PIN accounting which is a to-do.
>>
>> Suggested-by: Oded Gabbay <ogabbay at kernel.org>
>> Signed-off-by: Thomas Hellström <thomas.hellstrom at linux.intel.com>
>> ---
>> drivers/gpu/drm/xe/xe_dma_buf.c | 25 +++++++++++++++++++++----
>> 1 file changed, 21 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_buf.c
>> index 09343b8b3e96..bd8d51e7f93f 100644
>> --- a/drivers/gpu/drm/xe/xe_dma_buf.c
>> +++ b/drivers/gpu/drm/xe/xe_dma_buf.c
>> @@ -49,13 +49,30 @@ static int xe_dma_buf_pin(struct dma_buf_attachment *attach)
>> {
>> struct drm_gem_object *obj = attach->dmabuf->priv;
>> struct xe_bo *bo = gem_to_xe_bo(obj);
>> + struct xe_device *xe = xe_bo_device(bo);
>> + int ret;
>>
>> /*
>> - * Migrate to TT first to increase the chance of non-p2p clients
>> - * can attach.
>> + * For now only support pinning in TT memory, for two reasons:
>> + * 1) Avoid pinning in a placement not accessible to some importers.
>> + * 2) Pinning in VRAM requires PIN accounting which is a to-do.
>> */
>> - (void)xe_bo_migrate(bo, XE_PL_TT);
>> - xe_bo_pin_external(bo);
>> + if (xe_bo_is_pinned(bo) && bo->ttm.resource->placement != XE_PL_TT) {
>> + drm_dbg(&xe->drm, "Can't migrate pinned bo for dma-buf pin.\n");
>> + return -EINVAL;
>> + }
>> +
>> + ret = xe_bo_migrate(bo, XE_PL_TT);
>> + if (ret) {
>> + if (ret != -EINTR && ret != -ERESTARTSYS)
>> + drm_dbg(&xe->drm,
>> + "Failed migrating dma-buf to TT memory: %pe\n",
>> + ERR_PTR(ret));
>> + return ret;
>> + }
>> +
>> + ret = xe_bo_pin_external(bo);
>> + xe_assert(xe, !ret);
>>
>> return 0;
>> }
>> --
>> 2.41.0
>>
> Reviewed-by: Oded Gabbay <ogabbay at kernel.org>
Thanks for revieiwing, Oded. Just sent a v2 with a kunit test update to
reflect the changes. Please let me know if there are any issues with that.
/Thomas
> Thanks,
> Oded
More information about the Intel-xe
mailing list