Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
Subject: [PATCH 01/12] drm/xe/pf: Add function to sanitize VF resources
Date: Fri,  9 Aug 2024 18:51:48 +0200	[thread overview]
Message-ID: <20240809165159.662-2-michal.wajdeczko@intel.com> (raw)
In-Reply-To: <20240809165159.662-1-michal.wajdeczko@intel.com>

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@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


  reply	other threads:[~2024-08-09 16:52 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-09 16:51 [PATCH 00/12] PF: Improve VF control Michal Wajdeczko
2024-08-09 16:51 ` Michal Wajdeczko [this message]
2024-08-16 12:58   ` [PATCH 01/12] drm/xe/pf: Add function to sanitize VF resources Piotr Piórkowski
2024-08-19 20:47   ` Lucas De Marchi
2024-08-20  9:38     ` Michal Wajdeczko
2024-08-20 13:16       ` Lucas De Marchi
2024-09-05 18:07         ` Rodrigo Vivi
2024-08-09 16:51 ` [PATCH 02/12] drm/xe/pf: Fix documentation formatting Michal Wajdeczko
2024-08-16 12:59   ` Piotr Piórkowski
2024-08-09 16:51 ` [PATCH 03/12] drm/xe/pf: Drop GuC notifications for non-existing VF Michal Wajdeczko
2024-08-16 13:01   ` Piotr Piórkowski
2024-08-19 17:51     ` Michal Wajdeczko
2024-08-22 10:48       ` Piotr Piórkowski
2024-08-09 16:51 ` [PATCH 04/12] drm/xe/pf: Improve VF control Michal Wajdeczko
2024-08-16 13:06   ` Piotr Piórkowski
2024-08-19 17:52     ` Michal Wajdeczko
2024-08-20  7:56   ` Piotr Piórkowski
2024-08-20 10:04     ` Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 05/12] drm/xe/tests: Allow deferred function call during KUnit test Michal Wajdeczko
2024-08-19 21:38   ` Lucas De Marchi
2024-08-20 10:23     ` Michal Wajdeczko
2024-08-20 13:21       ` Lucas De Marchi
2024-08-20 13:27       ` Lucas De Marchi
2024-08-09 16:51 ` [PATCH 06/12] drm/xe/tests: Add helper macro to detect if KUnit is running Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 07/12] drm/xe/tests: Add helpers to call stubs out of KUnit context Michal Wajdeczko
2024-08-19 21:52   ` Lucas De Marchi
2024-08-20 10:31     ` Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 08/12] drm/xe/guc: Define stub for xe_guc_ct_send_recv() Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 09/12] drm/xe/pf: Define stub for pf_sanitize_vf_resources() Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 10/12] drm/xe/pf: Define stub for pf_send_vf_control_cmd() Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 11/12] drm/xe/tests: Add KUnit tests for VF control state machines Michal Wajdeczko
2024-08-09 17:23   ` [PATCH v2 " Michal Wajdeczko
2024-08-22 10:51     ` Piotr Piórkowski
2024-08-22 10:47   ` [PATCH " Piotr Piórkowski
2024-08-09 16:51 ` [PATCH 12/12] drm/xe/tests: Add KUnit tests for VF control GuC messages Michal Wajdeczko
2024-08-23 13:18   ` Piotr Piórkowski
2024-08-09 16:57 ` ✓ CI.Patch_applied: success for PF: Improve VF control Patchwork
2024-08-09 16:58 ` ✗ CI.checkpatch: warning " Patchwork
2024-08-09 16:58 ` ✗ CI.KUnit: failure " Patchwork
2024-08-09 17:28 ` ✓ CI.Patch_applied: success for PF: Improve VF control (rev2) Patchwork
2024-08-09 17:29 ` ✗ CI.checkpatch: warning " Patchwork
2024-08-09 17:30 ` ✓ CI.KUnit: success " Patchwork
2024-08-09 17:42 ` ✓ CI.Build: " Patchwork
2024-08-09 17:44 ` ✗ CI.Hooks: failure " Patchwork
2024-08-09 17:46 ` ✓ CI.checksparse: success " Patchwork
2024-08-09 18:06 ` ✓ CI.BAT: " Patchwork
2024-08-09 20:35 ` ✗ CI.FULL: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240809165159.662-2-michal.wajdeczko@intel.com \
    --to=michal.wajdeczko@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox