Re: [PATCH] drm/xe: Fix exporting xe buffers multiple times

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 18, 2025 at 11:03:53AM +0100, Jacek Lawrynowicz wrote:
> From: Tomasz Rusinowicz <tomasz.rusinowicz@xxxxxxxxx>
> 
> The `struct ttm_resource->placement` contains TTM_PL_FLAG_* flags, but
> it was incorrectly tested for XE_PL_* flags.
> This caused xe_dma_buf_pin() to always fail when invoked for
> the second time. Fix this by checking the `mem_type` field instead.
> 
> Fixes: 7764222d54b7 ("drm/xe: Disallow pinning dma-bufs in VRAM")
> Cc: Thomas Hellström <thomas.hellstrom@xxxxxxxxxxxxxxx>
> Cc: Rodrigo Vivi <rodrigo.vivi@xxxxxxxxx>
> Cc: Lucas De Marchi <lucas.demarchi@xxxxxxxxx>
> Cc: "Thomas Hellström" <thomas.hellstrom@xxxxxxxxxxxxxxx>
> Cc: Michal Wajdeczko <michal.wajdeczko@xxxxxxxxx>
> Cc: Matthew Brost <matthew.brost@xxxxxxxxx>
> Cc: Matthew Auld <matthew.auld@xxxxxxxxx>
> Cc: Nirmoy Das <nirmoy.das@xxxxxxxxx>
> Cc: Jani Nikula <jani.nikula@xxxxxxxxx>
> Cc: intel-xe@xxxxxxxxxxxxxxxxxxxxx
> Cc: <stable@xxxxxxxxxxxxxxx> # v6.8+
> Signed-off-by: Tomasz Rusinowicz <tomasz.rusinowicz@xxxxxxxxx>
> Signed-off-by: Jacek Lawrynowicz <jacek.lawrynowicz@xxxxxxxxxxxxxxx>
> ---
>  drivers/gpu/drm/xe/xe_bo.h      | 2 --
>  drivers/gpu/drm/xe/xe_dma_buf.c | 2 +-
>  2 files changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
> index d9386ab031404..43bf6f140d40d 100644
> --- a/drivers/gpu/drm/xe/xe_bo.h
> +++ b/drivers/gpu/drm/xe/xe_bo.h
> @@ -341,7 +341,6 @@ static inline unsigned int xe_sg_segment_size(struct device *dev)
>  	return round_down(max / 2, PAGE_SIZE);
>  }
>  
> -#if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST)
>  /**
>   * xe_bo_is_mem_type - Whether the bo currently resides in the given
>   * TTM memory type
> @@ -356,4 +355,3 @@ static inline bool xe_bo_is_mem_type(struct xe_bo *bo, u32 mem_type)
>  	return bo->ttm.resource->mem_type == mem_type;
>  }
>  #endif
> -#endif
> diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_buf.c
> index c5b95470fa324..f67803e15a0e6 100644
> --- a/drivers/gpu/drm/xe/xe_dma_buf.c
> +++ b/drivers/gpu/drm/xe/xe_dma_buf.c
> @@ -58,7 +58,7 @@ static int xe_dma_buf_pin(struct dma_buf_attachment *attach)
>  	 * 1) Avoid pinning in a placement not accessible to some importers.
>  	 * 2) Pinning in VRAM requires PIN accounting which is a to-do.
>  	 */
> -	if (xe_bo_is_pinned(bo) && bo->ttm.resource->placement != XE_PL_TT) {
> +	if (xe_bo_is_pinned(bo) && !xe_bo_is_mem_type(bo, XE_PL_TT)) {

This fix looks correct. With that:
Reviewed-by: Matthew Brost <matthew.brost@xxxxxxxxx>

But question for Thomas. I'm thinking as a follow up we rename this
variable in TTM to something like placement_flags to avoid confusion
like this. What do you think?

Matt 

>  		drm_dbg(&xe->drm, "Can't migrate pinned bo for dma-buf pin.\n");
>  		return -EINVAL;
>  	}
> -- 
> 2.45.1
> 




[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux