* [PATCH] drm/xe/gt: Abort GT init on LMTT initialization failure
@ 2026-11-18 8:54 yaolu
2026-11-18 20:03 ` Summers, Stuart
0 siblings, 1 reply; 5+ messages in thread
From: yaolu @ 2026-11-18 8:54 UTC (permalink / raw)
To: matthew.brost, thomas.hellstrom, rodrigo.vivi
Cc: michal.wajdeczko, intel-xe, dri-devel, linux-kernel, Lu Yao
From: Lu Yao <yaolu@kylinos.cn>
xe_lmtt_init() can fail, but gt_init_with_gt_forcewake() ignores its
return value. On a PF the probe then continues with a half-initialized
LMTT: lmtt->pd is never set (and lmtt->ops is cleared), so
xe_lmtt_init_hw() returns early and the VF local memory is left without
a translation directory while the driver still reports success.
Return the xe_lmtt_init() error and abort GT init instead, as required
by the documented LMTT contract ("Any LMTT initialization failure
should block VFs enabling").
Fixes: b1d204058218 ("drm/xe/pf: Introduce Local Memory Translation Table")
Signed-off-by: Lu Yao <yaolu@kylinos.cn>
---
drivers/gpu/drm/xe/xe_gt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_gt.c b/drivers/gpu/drm/xe/xe_gt.c
index 286aee5775c0..1239cbb7c84c 100644
--- a/drivers/gpu/drm/xe/xe_gt.c
+++ b/drivers/gpu/drm/xe/xe_gt.c
@@ -582,10 +582,10 @@ static int gt_init_with_gt_forcewake(struct xe_gt *gt)
if (xe_gt_is_main_type(gt)) {
err = xe_ggtt_init(gt_to_tile(gt)->mem.ggtt);
+ if (!err && IS_SRIOV_PF(gt_to_xe(gt)))
+ err = xe_lmtt_init(>_to_tile(gt)->sriov.pf.lmtt);
if (err)
return err;
- if (IS_SRIOV_PF(gt_to_xe(gt)))
- xe_lmtt_init(>_to_tile(gt)->sriov.pf.lmtt);
}
/* Enable per hw engine IRQs */
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] drm/xe/gt: Abort GT init on LMTT initialization failure 2026-11-18 8:54 [PATCH] drm/xe/gt: Abort GT init on LMTT initialization failure yaolu @ 2026-11-18 20:03 ` Summers, Stuart 2026-11-19 9:50 ` Piotr Piórkowski 0 siblings, 1 reply; 5+ messages in thread From: Summers, Stuart @ 2026-11-18 20:03 UTC (permalink / raw) To: Brost, Matthew, yaolu@kylinos.cn, K V P, Satyanarayana, Vivi, Rodrigo, Piorkowski, Piotr, thomas.hellstrom@linux.intel.com Cc: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, michal.wajdeczko@intel.com On Wed, 2026-11-18 at 16:54 +0800, yaolu@kylinos.cn wrote: > From: Lu Yao <yaolu@kylinos.cn> > > xe_lmtt_init() can fail, but gt_init_with_gt_forcewake() ignores its > return value. On a PF the probe then continues with a half- > initialized > LMTT: lmtt->pd is never set (and lmtt->ops is cleared), so > xe_lmtt_init_hw() returns early and the VF local memory is left > without > a translation directory while the driver still reports success. > > Return the xe_lmtt_init() error and abort GT init instead, as > required > by the documented LMTT contract ("Any LMTT initialization failure > should block VFs enabling"). > > Fixes: b1d204058218 ("drm/xe/pf: Introduce Local Memory Translation > Table") > Signed-off-by: Lu Yao <yaolu@kylinos.cn> I'm not an expert in this code, but it does look like if we tried to allocate memory here and that failed for some reason, causing the LMTT init to fail, it would cause downstream issues later in the PF's LMTT management. But the change as-is doesn't seem like the right approach here IMO. I don't think we want to kill the whole driver load because of this, it seems better to just log the error and not enumerate the VFs. But it would be good to get feedback from Piotr/Satya here. Thanks, Stuart > --- > drivers/gpu/drm/xe/xe_gt.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/xe/xe_gt.c b/drivers/gpu/drm/xe/xe_gt.c > index 286aee5775c0..1239cbb7c84c 100644 > --- a/drivers/gpu/drm/xe/xe_gt.c > +++ b/drivers/gpu/drm/xe/xe_gt.c > @@ -582,10 +582,10 @@ static int gt_init_with_gt_forcewake(struct > xe_gt *gt) > > if (xe_gt_is_main_type(gt)) { > err = xe_ggtt_init(gt_to_tile(gt)->mem.ggtt); > + if (!err && IS_SRIOV_PF(gt_to_xe(gt))) > + err = xe_lmtt_init(>_to_tile(gt)- > >sriov.pf.lmtt); > if (err) > return err; > - if (IS_SRIOV_PF(gt_to_xe(gt))) > - xe_lmtt_init(>_to_tile(gt)->sriov.pf.lmtt); > } > > /* Enable per hw engine IRQs */ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drm/xe/gt: Abort GT init on LMTT initialization failure 2026-11-18 20:03 ` Summers, Stuart @ 2026-11-19 9:50 ` Piotr Piórkowski 2026-11-26 13:14 ` [PATCH v2] drm/xe/gt: Log LMTT init failure and block VF operations yaolu 0 siblings, 1 reply; 5+ messages in thread From: Piotr Piórkowski @ 2026-11-19 9:50 UTC (permalink / raw) To: Summers, Stuart Cc: Brost, Matthew, yaolu@kylinos.cn, K V P, Satyanarayana, Vivi, Rodrigo, thomas.hellstrom@linux.intel.com, intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, michal.wajdeczko@intel.com Summers, Stuart <stuart.summers@intel.com> wrote on śro [2026-lis-18 21:03:09 +0100]: > On Wed, 2026-11-18 at 16:54 +0800, yaolu@kylinos.cn wrote: > > From: Lu Yao <yaolu@kylinos.cn> > > > > xe_lmtt_init() can fail, but gt_init_with_gt_forcewake() ignores its > > return value. On a PF the probe then continues with a half- > > initialized > > LMTT: lmtt->pd is never set (and lmtt->ops is cleared), so > > xe_lmtt_init_hw() returns early and the VF local memory is left > > without > > a translation directory while the driver still reports success. > > > > Return the xe_lmtt_init() error and abort GT init instead, as > > required > > by the documented LMTT contract ("Any LMTT initialization failure > > should block VFs enabling"). > > > > Fixes: b1d204058218 ("drm/xe/pf: Introduce Local Memory Translation > > Table") > > Signed-off-by: Lu Yao <yaolu@kylinos.cn> > > I'm not an expert in this code, but it does look like if we tried to > allocate memory here and that failed for some reason, causing the LMTT > init to fail, it would cause downstream issues later in the PF's LMTT > management. But the change as-is doesn't seem like the right approach > here IMO. I don't think we want to kill the whole driver load because > of this, it seems better to just log the error and not enumerate the > VFs. > > But it would be good to get feedback from Piotr/Satya here. I agree with Stuart that, since LMTT is only necessary for creating VFs, we could simply block the creation of VFs (and all operations related to SR-IOV). It seems that switching back to native mode at this point is already too late. Interrupting the driver's probe is definitely too radical an approach. We could do something like this: --- a/drivers/gpu/drm/xe/xe_lmtt.h +++ b/drivers/gpu/drm/xe/xe_lmtt.h @@ #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); --- a/drivers/gpu/drm/xe/xe_lmtt.c +++ b/drivers/gpu/drm/xe/xe_lmtt.c @@ +/** + * 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; +} --- a/drivers/gpu/drm/xe/xe_gt.c +++ b/drivers/gpu/drm/xe/xe_gt.c @@ static int gt_init_with_gt_forcewake(struct xe_gt *gt) if (xe_gt_is_main_type(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(>_to_tile(gt)->sriov.pf.lmtt); + if (IS_SRIOV_PF(gt_to_xe(gt))) { + err = xe_lmtt_init(>_to_tile(gt)->sriov.pf.lmtt); + if (err) + xe_gt_sriov_err(gt, "Failed to initialize LMTT (%pe), VFs will be unavailable\n", + ERR_PTR(err)); + } } --- a/drivers/gpu/drm/xe/xe_sriov_pf.c +++ b/drivers/gpu/drm/xe/xe_sriov_pf.c @@ +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; +} + int xe_sriov_pf_wait_ready(struct xe_device *xe) { struct xe_gt *gt; unsigned int id; int err; if (xe_wedged(xe)) return -ECANCELED; + err = pf_check_lmtt(xe); + if (err) + return err; + for_each_gt(gt, xe, id) { Thanks Piotr > > Thanks, > Stuart > > > --- > > drivers/gpu/drm/xe/xe_gt.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/gpu/drm/xe/xe_gt.c b/drivers/gpu/drm/xe/xe_gt.c > > index 286aee5775c0..1239cbb7c84c 100644 > > --- a/drivers/gpu/drm/xe/xe_gt.c > > +++ b/drivers/gpu/drm/xe/xe_gt.c > > @@ -582,10 +582,10 @@ static int gt_init_with_gt_forcewake(struct > > xe_gt *gt) > > > > if (xe_gt_is_main_type(gt)) { > > err = xe_ggtt_init(gt_to_tile(gt)->mem.ggtt); > > + if (!err && IS_SRIOV_PF(gt_to_xe(gt))) > > + err = xe_lmtt_init(>_to_tile(gt)- > > >sriov.pf.lmtt); > > if (err) > > return err; > > - if (IS_SRIOV_PF(gt_to_xe(gt))) > > - xe_lmtt_init(>_to_tile(gt)->sriov.pf.lmtt); > > } > > > > /* Enable per hw engine IRQs */ > -- ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] drm/xe/gt: Log LMTT init failure and block VF operations 2026-11-19 9:50 ` Piotr Piórkowski @ 2026-11-26 13:14 ` yaolu 2026-11-26 13:27 ` sashiko-bot 0 siblings, 1 reply; 5+ messages in thread From: yaolu @ 2026-11-26 13:14 UTC (permalink / raw) To: piotr.piorkowski Cc: dri-devel, intel-xe, linux-kernel, matthew.brost, michal.wajdeczko, rodrigo.vivi, satyanarayana.k.v.p, stuart.summers, thomas.hellstrom, yaolu From: Lu Yao <yaolu@kylinos.cn> 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 <piotr.piorkowski@intel.com> Suggested-by: Summers Stuart <stuart.summers@intel.com> Signed-off-by: Lu Yao <yaolu@kylinos.cn> --- 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/20261119095003.reakox5n3mhp5utx@intel.com/ --- 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 = >_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(>_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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] drm/xe/gt: Log LMTT init failure and block VF operations 2026-11-26 13:14 ` [PATCH v2] drm/xe/gt: Log LMTT init failure and block VF operations yaolu @ 2026-11-26 13:27 ` sashiko-bot 0 siblings, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-11-26 13:27 UTC (permalink / raw) To: yaolu; +Cc: dri-devel, intel-xe Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/xe/pf: NULL deref in xe_lmtt_page_size() via unguarded debugfs paths -- commit 2b2063f5a4b0e6ca91307ed198eee693dd8674d9 Author: Lu Yao <yaolu@kylinos.cn> drm/xe/gt: Log LMTT init failure and block VF operations This commit logs an error when xe_lmtt_init() fails during GT initialization while keeping the PF alive, and adds a readiness check in xe_sriov_pf_wait_ready() to reject subsequent VF operations when the LMTT is uninitialized. Link: https://lore.kernel.org/dri-devel/20261119095003.reakox5n3mhp5utx@intel.com/ > diff --git a/drivers/gpu/drm/xe/xe_sriov_pf.c b/drivers/gpu/drm/xe/xe_sriov_pf.c > index 33bd754d138fa..2122964610a0f 100644 > --- a/drivers/gpu/drm/xe/xe_sriov_pf.c > +++ b/drivers/gpu/drm/xe/xe_sriov_pf.c [ ... ] > @@ -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; [Severity: Medium] Can PF-side VF debugfs handlers still reach the uninitialized LMTT and dereference a NULL lmtt->ops pointer when xe_lmtt_init() fails? When xe_lmtt_init() fails, it clears lmtt->ops and leaves lmtt->pd NULL, while gt_init_lmtt() lets probe complete and register SR-IOV debugfs files. Not all PF-side VF debugfs entry points call xe_sriov_pf_wait_ready(). For example, writing a KLV blob containing GUC_KLV_VF_CFG_LMEM_SIZE_KEY to config_blob runs config_blob_write() -> xe_gt_sriov_pf_config_restore() -> pf_restore_vf_config_klv() -> pf_provision_vf_lmem() -> pf_get_lmem_alignment() -> xe_lmtt_page_size(), which hits lmtt_assert(lmtt, lmtt->ops) and dereferences lmtt->ops in lmtt_page_size(). -- Sashiko AI review · https://sashiko.dev/#/patchset/20261126131441.1734445-1-yaolu@kylinos.cn?part=1 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-26 13:27 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-18 8:54 [PATCH] drm/xe/gt: Abort GT init on LMTT initialization failure yaolu 2026-11-18 20:03 ` Summers, Stuart 2026-11-19 9:50 ` Piotr Piórkowski 2026-11-26 13:14 ` [PATCH v2] drm/xe/gt: Log LMTT init failure and block VF operations yaolu 2026-11-26 13:27 ` sashiko-bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox