All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rodrigo Vivi" <rodrigo.vivi@intel.com>, intel-xe@lists.freedesktop.org
Subject: Re: [CI] drm/xe: Crescent Island PMT support + hwmon use-after-free debug
Date: Tue, 24 Nov 2026 20:20:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-231984@kernel.org> (raw)
In-Reply-To: <20261124194656.3508212-2-rodrigo.vivi@intel.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] drm/xe: devres group race with component_bind() frees xe->hwmon
  causing UAF
- [Medium] drm/xe/vsec: missing wait_for_fw() before reading GUID in
  xe_vsec_get_guid()
- [Medium] drm/xe/hwmon: leftover CI debug logging, stack dumps, and
  unchecked devm action
- [Medium] drm/xe/vsec: missing wait_for_fw() in xe_pmt_discovery_read()
- [Medium] drm/xe/vsec: pmt.work not stopped in xe_device_suspend()
  during PCIe FLR
It also noticed 2 related pre-existing issues this patch does not
introduce:
- [High] drm/xe: missing capability type validation in xe_guid_decode()
  [1]
- [Critical] drm/xe: out-of-bounds read in xe_pmt_telem_read() [2]
--

commit daff6eb7dced704e86958267a6127a89b5f6d8fa
Author: Rodrigo Vivi <rodrigo.vivi@intel.com>

drm/xe: Crescent Island PMT support + hwmon use-after-free debug

This commit adds Platform Monitoring Technology (PMT) support for Crescent
Island devices via VSEC and includes temporary debug instrumentation in
xe_hwmon to investigate a use-after-free on unbind.

> diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
> index eafc66d686e2f..614b7e376739b 100644
> --- a/drivers/gpu/drm/xe/xe_device.c
> +++ b/drivers/gpu/drm/xe/xe_device.c
> @@ -1092,18 +1092,18 @@ int xe_device_probe(struct xe_device *xe)
>  	if (err)
>  		goto err_unregister_display;
>  
> +	xe_vsec_init(xe);
> +
>  	xe_debugfs_register(xe);
>  
>  	err = xe_hwmon_register(xe);
>  	if (err)
> -		goto err_unregister_display;
> +		goto err_unregister_vsec;
>  
>  	err = xe_i2c_probe(xe);
>  	if (err)
>  		goto err_unregister_hwmon;
>  
> -	xe_vsec_init(xe);
> -

[Severity: High]
Can moving xe_vsec_init() ahead of xe_hwmon_register() cause
component_bind() to capture xe->hwmon into the late-bind component's
devres group and free it prematurely on component_unbind()?

Earlier in xe_device_probe(), xe_heci_gsc_init() registers the mei-gscfi
auxiliary device and xe_late_bind_init() registers xe->drm.dev as a
component via component_add_typed().  Running xe_vsec_init() before
xe_hwmon_register() delays the devm allocations in xe_hwmon_register() into
the window where the asynchronous MEI client probe binds the component on
xe->drm.dev:

CPU0 (xe_device_probe)            CPU1 (MEI client probe)
xe_heci_gsc_init(xe)
xe_late_bind_init(&xe->late_bind)
  component_add_typed(xe->drm.dev, ...)
...
xe_vsec_init(xe)
                                  mei_late_bind_probe()
                                    component_master_add_with_match()
                                      component_bind_all()
                                        component_bind()
                                          devres_open_group(xe->drm.dev,
                                                            component, ...)
                                          component->ops->bind(...)
xe_hwmon_register(xe)
  hwmon = devm_kzalloc_obj(xe->drm.dev, *hwmon)
  devm_mutex_init(xe->drm.dev, &hwmon->hwmon_lock)
  xe->hwmon = hwmon
                                          devres_close_group(xe->drm.dev, ...)
...
                                  component_unbind()
                                    devres_release_group(xe->drm.dev,
                                                         component)
                                      /* frees hwmon */
xe_device_remove(xe)
  xe_hwmon_unregister(xe)
    hwmon_device_unregister(xe->hwmon->hwmon_dev)  <-- use-after-free

Because devres_open_group() on xe->drm.dev captures any concurrent devm
allocations on that device, hwmon is released when the component unbinds
while xe->hwmon remains non-NULL.

> diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
> index 9cbb65891aa40..272ef2aca80a9 100644
> --- a/drivers/gpu/drm/xe/xe_hwmon.c
> +++ b/drivers/gpu/drm/xe/xe_hwmon.c
[ ... ]
> @@ -1867,6 +1874,13 @@ xe_hwmon_get_preregistration_info(struct xe_hwmon *hwmon)
>  	return xe_hwmon_init_temp_info(hwmon);
>  }
>  
> +/* CI DEBUG ONLY: show who releases the hwmon devres */
> +static void xe_hwmon_devres_dbg(void *data)
> +{
> +	pr_err("xe_hwmon CI DEBUG: devres releasing hwmon %p\n", data);
> +	dump_stack();
> +}
> +
>  int xe_hwmon_register(struct xe_device *xe)
>  {
>  	struct device *dev = xe->drm.dev;
> @@ -1885,6 +1899,9 @@ int xe_hwmon_register(struct xe_device *xe)
>  	if (!hwmon)
>  		return -ENOMEM;
>  
> +	pr_err("xe_hwmon CI DEBUG: allocated hwmon %p for xe %p\n", hwmon, xe);
> +	devm_add_action(dev, xe_hwmon_devres_dbg, hwmon);
> +
>  	ret = devm_mutex_init(dev, &hwmon->hwmon_lock);
>  	if (ret)
>  		return ret;
> @@ -1925,9 +1942,13 @@ int xe_hwmon_register(struct xe_device *xe)
>   */
>  void xe_hwmon_unregister(struct xe_device *xe)
>  {
> +	pr_err("xe_hwmon CI DEBUG: unregister xe %p hwmon %p\n", xe, xe->hwmon);
>  	if (!xe->hwmon)
>  		return;
>  
> +	/* prints the alloc and free stacks if the object was already freed */
> +	kmem_dump_obj(xe->hwmon);
> +
>  	hwmon_device_unregister(xe->hwmon->hwmon_dev);
>  	xe->hwmon = NULL;
>  }

[Severity: Medium]
Should this temporary CI debug instrumentation be dropped before merging?
It unconditionally logs KERN_ERR messages with raw %p pointers, calls
dump_stack() and kmem_dump_obj() on every probe and unbind, and leaves the
unchecked devm_add_action() callback installed if xe_hwmon_register() fails.

> diff --git a/drivers/gpu/drm/xe/xe_vsec.c b/drivers/gpu/drm/xe/xe_vsec.c
> index a9baf0bfe572c..33a5237cf5b42 100644
> --- a/drivers/gpu/drm/xe/xe_vsec.c
> +++ b/drivers/gpu/drm/xe/xe_vsec.c
[ ... ]
> @@ -94,44 +197,45 @@ enum capability {
>  	WATCHER,
>  };
[ ... ]
>  	switch (record_id) {
>  	case PUNIT:
> -		*index = 0;
> +		*index = BMG_IDX_TELEM_PUNIT;
>  		if (cap_type == TELEMETRY)
> -			*offset = PUNIT_TELEMETRY_OFFSET;
> +			*offset = BMG_PUNIT_TELEMETRY_OFFSET;
>  		else
> -			*offset = PUNIT_WATCHER_OFFSET;
> +			*offset = BMG_PUNIT_WATCHER_OFFSET;
>  		break;
>  
>  	case OOBMSM_0:
> -		*index = 1;
> +		*index = BMG_IDX_TELEM_OOBMSM;
>  		if (cap_type == WATCHER)
> -			*offset = OOBMSM_0_WATCHER_OFFSET;
> +			*offset = BMG_OOBMSM_0_WATCHER_OFFSET;
>  		break;
>  
>  	case OOBMSM_1:
> -		*index = 1;
> +		*index = BMG_IDX_TELEM_OOBMSM;
>  		if (cap_type == TELEMETRY)
> -			*offset = OOBMSM_1_TELEMETRY_OFFSET;
> +			*offset = BMG_OOBMSM_1_TELEMETRY_OFFSET;
>  		break;
>  	default:
>  		return -EINVAL;
>  	}
>  
>  	return 0;
>  }

[Severity: High]
This problem wasn't introduced by this patch, but can bmg_guid_decode() and
cri_guid_decode() return 0 with *offset left at 0 when an OOBMSM record_id
is paired with an unsupported cap_type [1]?

For example, OOBMSM_0 with TELEMETRY in bmg_guid_decode() (or OOBMSM_0
instance 0 with TELEMETRY in cri_guid_decode()) breaks out of the switch
without setting *offset or returning -EINVAL, allowing xe_pmt_telem_read()
to read from offset 0 of the telemetry region instead of rejecting the GUID.

> +static void cri_late_bind_probe_work(struct work_struct *work)
> +{
> +	struct xe_device *xe = container_of(work, struct xe_device, pmt.work.work);
> +
> +	if (xe_sysctrl_is_oobmsm_fw_ready(xe)) {
> +		cri_late_bind_probe(xe);
> +		xe_pm_runtime_put(xe);
> +		return;
> +	}
> +
> +	xe->pmt.retry_count++;
> +
> +	/* wait up to 20 seconds */
> +	if (xe->pmt.retry_count == VSEC_LATE_BIND_RETRY) {
> +		drm_warn(&xe->drm, "PMT probe: Late Binding failed to complete\n");
> +		xe_pm_runtime_put(xe);
> +		return;
> +	}
> +
> +	if (!queue_delayed_work(system_freezable_wq, &xe->pmt.work,
> +				msecs_to_jiffies(VSEC_LATE_BIND_DELAY_MSEC)))
> +		xe_pm_runtime_put(xe);
> +}

[Severity: Medium]
Can cri_late_bind_probe_work() race with a PCIe Function Level Reset (FLR)?

During an FLR, xe_pci_reset_prepare() calls xe_device_suspend(), which
flushes the late-bind worker via xe_late_bind_pm_suspend() before PCI core
clears PCI_COMMAND_MEMORY and resets the function.  Because a PCIe FLR does
not freeze system_freezable_wq and xe_device_suspend() does not cancel or
flush xe->pmt.work, cri_late_bind_probe_work() can continue polling
xe_sysctrl_is_oobmsm_fw_ready() and calling cri_late_bind_probe() while
MMIO decoding is disabled and the device is being reset.

[ ... ]

>  int xe_pmt_telem_read(struct device *dev, u32 guid, u64 *data, loff_t user_offset,
>  		      u32 count)
>  {
>  	struct xe_device *xe = kdev_to_xe_device(dev);
> -	void __iomem *telem_addr = xe->mmio.regs + BMG_TELEMETRY_OFFSET;
> +	u32 cap_type = FIELD_GET(GUID_CAP_TYPE, guid);
> +	void __iomem *telem_addr = xe->mmio.regs + xe->pmt.base_offset;
>  	u32 mem_region;
>  	u32 offset;
> -	int ret;
> +	int ret = 0;
> +	int idx;
> +
> +	xe_assert(xe, !IS_SRIOV_VF(xe));
> +
> +	if (!drm_dev_enter(&xe->drm, &idx))
> +		return -ENODEV;
> +
> +	if (!xe->pmt.base_offset) {
> +		ret = -EAGAIN;
> +		goto dev_exit;
> +	}
>  
>  	ret = xe_guid_decode(guid, &mem_region, &offset);
>  	if (ret)
> -		return ret;
> +		goto dev_exit;
>  
>  	telem_addr += offset + user_offset;
[ ... ]
> +	scoped_guard(mutex, &xe->pmt.lock) {
> +		u32 device_id = FIELD_GET(GUID_DEVICE_ID, guid);
> +
> +		/* set SoC re-mapper index register based on GUID memory region */
> +		xe->soc_remapper.set_telem_region(xe, mem_region);
> +
> +		memcpy_fromio(data, telem_addr, count);
> +
> +		if (device_id == CRI_DEVICE_ID)
> +			xe->soc_remapper.set_telem_region(xe, CRI_IDX_TELEM_DISCOVERY);
> +	}

[Severity: Critical]
This problem wasn't introduced by this patch, but can xe_pmt_telem_read()
read past the end of the mapped MMIO region (xe->mmio.size) when given a
large user_offset or count [2]?  telem_addr += offset + user_offset
is passed directly to memcpy_fromio(data, telem_addr, count) without
bounds-checking against the mapped MMIO window, which can fault on unmapped
MMIO space.

[ ... ]

> +static int xe_pmt_discovery_read(struct device *dev, unsigned long cap_id, u32 element,
> +				 u32 *disc_data)
> +{
> +	struct xe_device *xe = kdev_to_xe_device(dev);
> +	void __iomem *disc_addr = xe->mmio.regs;
> +	struct intel_vsec_header *headers;
> +	int ret = 0;
> +	u32 offset;
> +	int idx;
>  
> -	if (!xe->soc_remapper.set_telem_region)
> +	if (!drm_dev_enter(&xe->drm, &idx))
>  		return -ENODEV;
>  
> -	/* indicate that we are not at an appropriate power level */
> -	if (!xe_pm_runtime_get_if_active(xe))
> -		return -ENODATA;
> +	if (xe->info.platform != XE_CRESCENTISLAND) {
> +		ret = -EINVAL;
> +		goto dev_exit;
> +	}
> +
> +	if (!xe_pm_runtime_get_if_active(xe)) {
> +		ret = -ENODATA;
> +		goto dev_exit;
> +	}
> +
> +	switch (cap_id) {
> +	case ilog2(VSEC_CAP_TELEMETRY):
> +		headers = &cri_telemetry;
> +		break;
> +
> +	case ilog2(VSEC_CAP_CRASHLOG):
> +		headers = &cri_crashlog;
> +		break;
> +
> +	default:
> +		ret = -EINVAL;
> +		goto runtime_exit;
> +	}
>  
> -	/* set SoC re-mapper index register based on GUID memory region */
> -	xe->soc_remapper.set_telem_region(xe, mem_region);
> +	offset = element * (headers->entry_size * sizeof(u32));
> +	disc_addr += headers->offset + offset;
>  
> -	memcpy_fromio(data, telem_addr, count);
> +	scoped_guard(mutex, &xe->pmt.lock) {
> +		xe->soc_remapper.set_telem_region(xe, CRI_IDX_TELEM_DISCOVERY);
> +		memcpy_fromio(disc_data, disc_addr, PMT_DISC_DWORDS * sizeof(u32));
> +	}

[Severity: Medium]
Should xe_pmt_discovery_read() call wait_for_fw(xe) before reading the
discovery table, like xe_pmt_telem_read(), xe_pmt_read_reg(), and
xe_pmt_write_reg() do?

On runtime resume from D3cold or system resume, xe_late_bind_pm_resume()
reloads the OOBMSM firmware asynchronously on late_bind->wq.  If a PMT
auxiliary driver probes or rebinds right after resume,
xe_pm_runtime_get_if_active(xe) succeeds while the firmware reload is still
in flight, so xe_pmt_discovery_read() can read uninitialized discovery
headers.

[ ... ]

> +int xe_vsec_get_guid(struct xe_device *xe, u32 *guid)
> +{
> +	struct xe_mmio *mmio = xe_root_tile_mmio(xe);
> +	int ret = 0;
> +
> +	xe_assert(xe, !IS_SRIOV_VF(xe));
> +
> +	if (!xe_pm_runtime_get_if_active(xe))
> +		return -ENODATA;
> +
> +	mutex_lock(&xe->pmt.lock);
> +
> +	if (xe->pmt.punit_guid_cache) {
> +		*guid = xe->pmt.punit_guid_cache;
> +		goto unlock;
> +	}
> +
> +	switch (xe->info.platform) {
> +	case XE_BATTLEMAGE:
> +		*guid = xe_mmio_read32(mmio, BMG_PUNIT_TELEMETRY_GUID);
> +		break;
> +
> +	case XE_CRESCENTISLAND:
> +		xe->soc_remapper.set_telem_region(xe, CRI_IDX_TELEM_DISCOVERY);
> +		*guid = xe_mmio_read32(mmio, CRI_PUNIT_TELEMETRY_GUID);
> +		break;
> +
> +	default:
> +		*guid = 0;
> +		drm_err(&xe->drm, "Unsupported platform: %u\n", xe->info.platform);
> +		ret = -EINVAL;
> +		goto unlock;
> +	}
> +
> +	/* the GUID is static, read once and cache for all requests */
> +	if (*guid) {
> +		xe->pmt.punit_guid_cache = *guid;
> +	} else {
> +		drm_err(&xe->drm, "Invalid GUID: 0x%x\n", *guid);
> +		ret = -EINVAL;
> +	}

[Severity: Medium]
Does xe_vsec_get_guid() also need to call wait_for_fw(xe) before reading
CRI_PUNIT_TELEMETRY_GUID on XE_CRESCENTISLAND?

read_residency_counter() and xe_get_pcode_version() both call
xe_vsec_get_guid() before xe_pmt_telem_read(), and their debugfs files are
registered in xe_device_probe() while OOBMSM late-binding firmware is still
loading asynchronously.  Reading CRI_PUNIT_TELEMETRY_GUID before the
firmware is ready either fails immediately with -EINVAL if the register
reads 0, or permanently caches an uninitialized non-zero value in
xe->pmt.punit_guid_cache and breaks all subsequent telemetry reads.

[1] https://sashiko.dev/#/bug/linux-17a44bac-9019-44db-b82d-0af69951b65b
[2] https://sashiko.dev/#/bug/linux-2e09e5e1-327b-4507-bb98-d9a607e0a9e5

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124194656.3508212-2-rodrigo.vivi@intel.com?part=1

  reply	other threads:[~2026-11-24 20:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 19:46 [CI] drm/xe: Crescent Island PMT support + hwmon use-after-free debug Rodrigo Vivi
2026-11-24 20:20 ` sashiko-bot [this message]
2026-11-24 20:40 ` ✗ CI.checkpatch: warning for " Patchwork
2026-11-24 20:43 ` ✓ CI.KUnit: success " Patchwork
2026-11-24 21:29 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-24 23:36 ` ✗ Xe.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=sashiko-outbox-231984@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.