From: Lu Yao <[email protected]>

If xe_lmtt_init() fails on a PF, the driver currently keeps going
with an unusable LMTT: xe_lmtt_init() clears lmtt->ops and leaves
lmtt->pd NULL, so xe_lmtt_init_hw() returns early and VF local memory
is left without a translation directory.

Log the error in gt_init_lmtt() and keep the PF alive, but refuse to
operate on VFs afterwards from xe_sriov_pf_wait_ready(), which gates
VF enabling as well as the PF-side VF sysfs/debugfs operations.

Fixes: b1d204058218 ("drm/xe/pf: Introduce Local Memory Translation Table")
Suggested-by: Piotr Piórkowski <[email protected]>
Suggested-by: Summers Stuart <[email protected]>
Signed-off-by: Lu Yao <[email protected]>
---
v1->v2:
 - Do not abort GT init when the LMTT allocation fails; log the error and
   keep the PF usable instead of failing probe.
 - Refuse VF operations in xe_sriov_pf_wait_ready() when the LMTT is not
   ready (new xe_lmtt_is_ready() and pf_check_lmtt()).
Link: 
https://lore.kernel.org/dri-devel/[email protected]/

---
 drivers/gpu/drm/xe/xe_gt.c       | 24 ++++++++++++++++++++++--
 drivers/gpu/drm/xe/xe_lmtt.c     | 16 ++++++++++++++++
 drivers/gpu/drm/xe/xe_lmtt.h     |  1 +
 drivers/gpu/drm/xe/xe_sriov_pf.c | 18 ++++++++++++++++++
 4 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_gt.c b/drivers/gpu/drm/xe/xe_gt.c
index 286aee5775c0..3ec1b1f027d4 100644
--- a/drivers/gpu/drm/xe/xe_gt.c
+++ b/drivers/gpu/drm/xe/xe_gt.c
@@ -36,6 +36,7 @@
 #include "xe_gt_mcr.h"
 #include "xe_gt_printk.h"
 #include "xe_gt_sriov_pf.h"
+#include "xe_gt_sriov_printk.h"
 #include "xe_gt_sriov_vf.h"
 #include "xe_gt_stats.h"
 #include "xe_gt_sysfs.h"
@@ -563,6 +564,25 @@ static void dump_pat_on_error(struct xe_gt *gt)
        xe_pat_dump(gt, &p);
 }
 
+static void gt_init_lmtt(struct xe_gt *gt)
+{
+       struct xe_lmtt *lmtt = &gt_to_tile(gt)->sriov.pf.lmtt;
+       int err;
+
+       if (!IS_SRIOV_PF(gt_to_xe(gt)))
+               return;
+
+       /*
+        * LMTT is required to enable VFs only, so keep the PF usable even if
+        * the allocation failed. VF operations are then refused by
+        * xe_sriov_pf_wait_ready().
+        */
+       err = xe_lmtt_init(lmtt);
+       if (err)
+               xe_gt_sriov_err(gt, "LMTT init failed (%pe), VFs will be 
unavailable\n",
+                               ERR_PTR(err));
+}
+
 static int gt_init_with_gt_forcewake(struct xe_gt *gt)
 {
        int err;
@@ -584,8 +604,8 @@ static int gt_init_with_gt_forcewake(struct xe_gt *gt)
                err = xe_ggtt_init(gt_to_tile(gt)->mem.ggtt);
                if (err)
                        return err;
-               if (IS_SRIOV_PF(gt_to_xe(gt)))
-                       xe_lmtt_init(&gt_to_tile(gt)->sriov.pf.lmtt);
+
+               gt_init_lmtt(gt);
        }
 
        /* Enable per hw engine IRQs */
diff --git a/drivers/gpu/drm/xe/xe_lmtt.c b/drivers/gpu/drm/xe/xe_lmtt.c
index 8a5a434931b0..6d46aaadb422 100644
--- a/drivers/gpu/drm/xe/xe_lmtt.c
+++ b/drivers/gpu/drm/xe/xe_lmtt.c
@@ -212,6 +212,22 @@ int xe_lmtt_init(struct xe_lmtt *lmtt)
        return err;
 }
 
+/**
+ * xe_lmtt_is_ready() - Check if LMTT is ready to be used.
+ * @lmtt: the &xe_lmtt to check
+ *
+ * This function shall be called only by PF.
+ *
+ * Return: true if LMTT is not needed on this device or was successfully
+ * initialized by xe_lmtt_init(), false otherwise.
+ */
+bool xe_lmtt_is_ready(struct xe_lmtt *lmtt)
+{
+       lmtt_assert(lmtt, IS_SRIOV_PF(lmtt_to_xe(lmtt)));
+
+       return !xe_device_has_lmtt(lmtt_to_xe(lmtt)) || lmtt->pd;
+}
+
 static void lmtt_setup_dir_ptr_gt(struct xe_gt *gt, u32 config)
 {
        struct xe_device *xe = gt_to_xe(gt);
diff --git a/drivers/gpu/drm/xe/xe_lmtt.h b/drivers/gpu/drm/xe/xe_lmtt.h
index 5ef065dd573c..980b3126b952 100644
--- a/drivers/gpu/drm/xe/xe_lmtt.h
+++ b/drivers/gpu/drm/xe/xe_lmtt.h
@@ -15,6 +15,7 @@ struct xe_lmtt_ops;
 
 #ifdef CONFIG_PCI_IOV
 int xe_lmtt_init(struct xe_lmtt *lmtt);
+bool xe_lmtt_is_ready(struct xe_lmtt *lmtt);
 void xe_lmtt_init_hw(struct xe_gt *gt);
 void xe_lmtt_invalidate_hw(struct xe_lmtt *lmtt);
 int xe_lmtt_prepare_pages(struct xe_lmtt *lmtt, unsigned int vfid, u64 range);
diff --git a/drivers/gpu/drm/xe/xe_sriov_pf.c b/drivers/gpu/drm/xe/xe_sriov_pf.c
index 33bd754d138f..2122964610a0 100644
--- a/drivers/gpu/drm/xe/xe_sriov_pf.c
+++ b/drivers/gpu/drm/xe/xe_sriov_pf.c
@@ -11,6 +11,7 @@
 #include "xe_configfs.h"
 #include "xe_device.h"
 #include "xe_gt_sriov_pf.h"
+#include "xe_lmtt.h"
 #include "xe_module.h"
 #include "xe_sriov.h"
 #include "xe_sriov_pf.h"
@@ -19,6 +20,7 @@
 #include "xe_sriov_pf_service.h"
 #include "xe_sriov_pf_sysfs.h"
 #include "xe_sriov_printk.h"
+#include "xe_tile.h"
 
 static unsigned int wanted_max_vfs(struct xe_device *xe)
 {
@@ -143,6 +145,18 @@ int xe_sriov_pf_init_late(struct xe_device *xe)
        return 0;
 }
 
+static int pf_check_lmtt(struct xe_device *xe)
+{
+       struct xe_tile *tile;
+       unsigned int id;
+
+       for_each_tile(tile, xe, id)
+               if (!xe_lmtt_is_ready(&tile->sriov.pf.lmtt))
+                       return -ENODEV;
+
+       return 0;
+}
+
 /**
  * xe_sriov_pf_wait_ready() - Wait until PF is ready to operate.
  * @xe: the &xe_device to test
@@ -160,6 +174,10 @@ int xe_sriov_pf_wait_ready(struct xe_device *xe)
        if (xe_device_wedged(xe))
                return -ECANCELED;
 
+       err = pf_check_lmtt(xe);
+       if (err)
+               return err;
+
        for_each_gt(gt, xe, id) {
                err = xe_gt_sriov_pf_wait_ready(gt);
                if (err)
-- 
2.25.1

Reply via email to