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 8de8f42ed4d0..146981aedf5f 100644 --- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c +++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c @@ -2932,7 +2932,38 @@ static void pf_release_vf_config(struct xe_gt *gt, unsigned int vfid) } /** - * xe_gt_sriov_pf_config_release - Release and reset VF configuration. + * xe_gt_sriov_pf_config_release_locked() - Release and reset VF configuration. + * @gt: the &xe_gt + * @vfid: the VF identifier (can't be PF) + * @force: force configuration release + * + * Note: The caller must hold the master PF mutex. + * 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_release_locked(struct xe_gt *gt, unsigned int vfid, bool force) +{ + int err; + + xe_gt_assert(gt, vfid); + lockdep_assert_held(xe_gt_sriov_pf_master_mutex(gt)); + + err = pf_send_vf_cfg_reset(gt, vfid); + if (!err || force) + pf_release_vf_config(gt, vfid); + + if (unlikely(err)) { + xe_gt_sriov_notice(gt, "VF%u unprovisioning failed with error (%pe)%s\n", + vfid, ERR_PTR(err), + force ? " but all resources were released anyway!" : ""); + } + + return force ? 0 : err; +} + +/** + * xe_gt_sriov_pf_config_release() - Release and reset VF configuration. * @gt: the &xe_gt * @vfid: the VF identifier (can't be PF) * @force: force configuration release @@ -2943,23 +2974,9 @@ static void pf_release_vf_config(struct xe_gt *gt, unsigned int vfid) */ int xe_gt_sriov_pf_config_release(struct xe_gt *gt, unsigned int vfid, bool force) { - int err; + guard(mutex)(xe_gt_sriov_pf_master_mutex(gt)); - xe_gt_assert(gt, vfid); - - mutex_lock(xe_gt_sriov_pf_master_mutex(gt)); - err = pf_send_vf_cfg_reset(gt, vfid); - if (!err || force) - pf_release_vf_config(gt, vfid); - mutex_unlock(xe_gt_sriov_pf_master_mutex(gt)); - - if (unlikely(err)) { - xe_gt_sriov_notice(gt, "VF%u unprovisioning failed with error (%pe)%s\n", - vfid, ERR_PTR(err), - force ? " but all resources were released anyway!" : ""); - } - - return force ? 0 : err; + return xe_gt_sriov_pf_config_release_locked(gt, vfid, force); } static void pf_sanitize_ggtt(struct xe_ggtt_node *ggtt_region, unsigned int vfid) 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 84246978d21e..d43da8599977 100644 --- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h +++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h @@ -90,6 +90,7 @@ int xe_gt_sriov_pf_config_set_fair_sched(struct xe_gt *gt, unsigned int num_vfs) 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_release_locked(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); ssize_t xe_gt_sriov_pf_config_save(struct xe_gt *gt, unsigned int vfid, void *buf, size_t size);