[PATCH 3/4] drm/xe: Fix small leak in migration error path.

Matthew Brost matthew.brost at intel.com
Fri May 2 16:59:46 UTC 2025


On Fri, May 02, 2025 at 11:35:12AM +0200, Maarten Lankhorst wrote:
> When logical_mask or hwe are zero, we should call xe_vm_close_and_put,
> and on error, m->pt_bo is also not cleared.
> 
> Also call xe_bo_unpin_map_no_vm even though it is a vm bo,
> to ensure the BO is freed.
> 
> Signed-off-by: Maarten Lankhorst <dev at lankhorst.se>

Reviewed-by: Matthew Brost <matthew.brost at intel.com>

> ---
>  drivers/gpu/drm/xe/xe_migrate.c | 60 +++++++++++++++++++--------------
>  1 file changed, 35 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
> index 673a5d165482e..7ee27c9f77bac 100644
> --- a/drivers/gpu/drm/xe/xe_migrate.c
> +++ b/drivers/gpu/drm/xe/xe_migrate.c
> @@ -386,6 +386,38 @@ static bool xe_migrate_needs_ccs_emit(struct xe_device *xe)
>  	return xe_device_has_flat_ccs(xe) && !(GRAPHICS_VER(xe) >= 20 && IS_DGFX(xe));
>  }
>  
> +static struct xe_exec_queue *xe_migrate_create_queue(struct xe_tile *tile,
> +						     struct xe_vm *vm)
> +{
> +	struct xe_device *xe = tile_to_xe(tile);
> +	struct xe_gt *primary_gt = tile->primary_gt;
> +
> +	if (xe->info.has_usm) {
> +		struct xe_hw_engine *hwe = xe_gt_hw_engine(primary_gt,
> +							   XE_ENGINE_CLASS_COPY,
> +							   primary_gt->usm.reserved_bcs_instance,
> +							   false);
> +		u32 logical_mask = xe_migrate_usm_logical_mask(primary_gt);
> +
> +		if (!hwe || !logical_mask)
> +			return ERR_PTR(-EINVAL);
> +
> +		/*
> +		 * XXX: Currently only reserving 1 (likely slow) BCS instance on
> +		 * PVC, may want to revisit if performance is needed.
> +		 */
> +		return xe_exec_queue_create(xe, vm, logical_mask, 1, hwe,
> +					    EXEC_QUEUE_FLAG_KERNEL |
> +					    EXEC_QUEUE_FLAG_PERMANENT |
> +					    EXEC_QUEUE_FLAG_HIGH_PRIORITY, 0);
> +	} else {
> +		return xe_exec_queue_create_class(xe, primary_gt, vm,
> +						  XE_ENGINE_CLASS_COPY,
> +						  EXEC_QUEUE_FLAG_KERNEL |
> +						  EXEC_QUEUE_FLAG_PERMANENT, 0);
> +	}
> +}
> +
>  /**
>   * xe_migrate_init() - Initialize a migrate context
>   * @tile: Back-pointer to the tile we're initializing for.
> @@ -395,7 +427,6 @@ static bool xe_migrate_needs_ccs_emit(struct xe_device *xe)
>  struct xe_migrate *xe_migrate_init(struct xe_tile *tile)
>  {
>  	struct xe_device *xe = tile_to_xe(tile);
> -	struct xe_gt *primary_gt = tile->primary_gt;
>  	struct xe_migrate *m;
>  	struct xe_vm *vm;
>  	int err;
> @@ -420,32 +451,11 @@ struct xe_migrate *xe_migrate_init(struct xe_tile *tile)
>  		return ERR_PTR(err);
>  	}
>  
> -	if (xe->info.has_usm) {
> -		struct xe_hw_engine *hwe = xe_gt_hw_engine(primary_gt,
> -							   XE_ENGINE_CLASS_COPY,
> -							   primary_gt->usm.reserved_bcs_instance,
> -							   false);
> -		u32 logical_mask = xe_migrate_usm_logical_mask(primary_gt);
> -
> -		if (!hwe || !logical_mask)
> -			return ERR_PTR(-EINVAL);
> -
> -		/*
> -		 * XXX: Currently only reserving 1 (likely slow) BCS instance on
> -		 * PVC, may want to revisit if performance is needed.
> -		 */
> -		m->q = xe_exec_queue_create(xe, vm, logical_mask, 1, hwe,
> -					    EXEC_QUEUE_FLAG_KERNEL |
> -					    EXEC_QUEUE_FLAG_PERMANENT |
> -					    EXEC_QUEUE_FLAG_HIGH_PRIORITY, 0);
> -	} else {
> -		m->q = xe_exec_queue_create_class(xe, primary_gt, vm,
> -						  XE_ENGINE_CLASS_COPY,
> -						  EXEC_QUEUE_FLAG_KERNEL |
> -						  EXEC_QUEUE_FLAG_PERMANENT, 0);
> -	}
> +	m->q = xe_migrate_create_queue(tile, vm);
>  	if (IS_ERR(m->q)) {
> +		xe_bo_unpin_map_no_vm(m->pt_bo);
>  		xe_vm_close_and_put(vm);
> +		drm_suballoc_manager_fini(&m->vm_update_sa);
>  		return ERR_CAST(m->q);
>  	}
>  
> -- 
> 2.45.2
> 


More information about the Intel-xe mailing list