[PATCH 01/12] drm/xe/pf: Add function to sanitize VF resources

Piotr Piórkowski piotr.piorkowski at intel.com
Fri Aug 16 12:58:54 UTC 2024


Michal Wajdeczko <michal.wajdeczko at intel.com> wrote on pią [2024-sie-09 18:51:48 +0200]:
> On current platforms it is a PF driver responsibility to clear
> some of the VF's resources during a VF FLR. Add simple function
> that will clear configured VF resources (GGTT, LMEM). We will
> start using this function soon.
> 
> Signed-off-by: Michal Wajdeczko <michal.wajdeczko at intel.com>
> ---
>  drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 84 ++++++++++++++++++++++
>  drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h |  1 +
>  2 files changed, 85 insertions(+)
> 
> diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> index 227527785afd..eba6793294f3 100644
> --- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> +++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> @@ -29,6 +29,7 @@
>  #include "xe_guc_submit.h"
>  #include "xe_lmtt.h"
>  #include "xe_map.h"
> +#include "xe_migrate.h"
>  #include "xe_sriov.h"
>  #include "xe_ttm_vram_mgr.h"
>  #include "xe_wopcm.h"
> @@ -1893,6 +1894,89 @@ int xe_gt_sriov_pf_config_release(struct xe_gt *gt, unsigned int vfid, bool forc
>  	return force ? 0 : err;
>  }
>  
> +static void pf_sanitize_ggtt(struct xe_tile *tile, struct drm_mm_node *node, unsigned int vfid)
> +{
> +	struct xe_ggtt *ggtt = tile->mem.ggtt;
> +
> +	if (drm_mm_node_allocated(node))
> +		xe_ggtt_assign(ggtt, node, vfid);
> +}
> +
> +static int pf_sanitize_lmem(struct xe_tile *tile, struct xe_bo *bo, long timeout)
> +{
> +	struct xe_migrate *m = tile->migrate;
> +	struct dma_fence *fence;
> +	int err;
> +
> +	if (!bo)
> +		return 0;
> +
> +	xe_bo_lock(bo, false);
> +	fence = xe_migrate_clear(m, bo, bo->ttm.resource);
> +	if (IS_ERR(fence)) {
> +		err = PTR_ERR(fence);
> +	} else if (!fence) {
> +		err = -ENOMEM;
> +	} else {
> +		long ret = dma_fence_wait_timeout(fence, false, timeout);
> +
> +		err = ret > 0 ? 0 : ret < 0 ? ret : -ETIMEDOUT;
> +		dma_fence_put(fence);
> +		if (!err)
> +			xe_gt_sriov_dbg_verbose(tile->primary_gt, "LMEM cleared in %dms\n",
> +						jiffies_to_msecs(timeout - ret));
> +	}
> +	xe_bo_unlock(bo);
> +
> +	return err;
> +}
> +
> +static int pf_sanitize_vf_resources(struct xe_gt *gt, u32 vfid, long timeout)
> +{
> +	struct xe_gt_sriov_config *config = pf_pick_vf_config(gt, vfid);
> +	struct xe_tile *tile = gt_to_tile(gt);
> +	struct xe_device *xe = gt_to_xe(gt);
> +	int err = 0;
> +
> +	/*
> +	 * Only GGTT and LMEM requires to be cleared by the PF.
> +	 * GuC doorbell IDs and context IDs do not need any clearing.
> +	 */
> +	if (!xe_gt_is_media_type(gt)) {
> +		pf_sanitize_ggtt(tile, &config->ggtt_region, vfid);
> +		if (IS_DGFX(xe))
> +			err = pf_sanitize_lmem(tile, config->lmem_obj, timeout);
> +	}
> +
> +	return err;
> +}
> +
> +/**
> + * xe_gt_sriov_pf_config_sanitize() - Sanitize VF's resources.
> + * @gt: the &xe_gt
> + * @vfid: the VF identifier (can't be PF)
> + * @timeout: maximum timeout to wait for completion in jiffies
> + *
> + * This function can only be called on PF.
> + *
> + * Return: 0 on success or a negative error code on failure.
> + */
> +int xe_gt_sriov_pf_config_sanitize(struct xe_gt *gt, unsigned int vfid, long timeout)
> +{
> +	int err;
> +
> +	xe_gt_assert(gt, vfid != PFID);
> +
> +	mutex_lock(xe_gt_sriov_pf_master_mutex(gt));
> +	err = pf_sanitize_vf_resources(gt, vfid, timeout);
> +	mutex_unlock(xe_gt_sriov_pf_master_mutex(gt));
> +
> +	if (unlikely(err))
> +		xe_gt_sriov_notice(gt, "VF%u resource sanitizing failed (%pe)\n",
> +				   vfid, ERR_PTR(err));
> +	return err;
> +}
> +
>  /**
>   * xe_gt_sriov_pf_config_push - Reprovision VF's configuration.
>   * @gt: the &xe_gt
> diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h
> index c0e6e4743dc2..42e64769f666 100644
> --- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h
> +++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h
> @@ -50,6 +50,7 @@ int xe_gt_sriov_pf_config_set_threshold(struct xe_gt *gt, unsigned int vfid,
>  					enum xe_guc_klv_threshold_index index, u32 value);
>  
>  int xe_gt_sriov_pf_config_set_fair(struct xe_gt *gt, unsigned int vfid, unsigned int num_vfs);
> +int xe_gt_sriov_pf_config_sanitize(struct xe_gt *gt, unsigned int vfid, long timeout);
>  int xe_gt_sriov_pf_config_release(struct xe_gt *gt, unsigned int vfid, bool force);
>  int xe_gt_sriov_pf_config_push(struct xe_gt *gt, unsigned int vfid, bool refresh);
>  
> -- 
> 2.43.0
> 

LGTM:
Reviewed-by: Piotr Piórkowski <piotr.piorkowski at intel.com>


-- 


More information about the Intel-xe mailing list