From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: Jonathan Cavitt <jonathan.cavitt@intel.com>,
<intel-xe@lists.freedesktop.org>
Cc: <saurabhg.gupta@intel.com>, <alex.zuo@intel.com>
Subject: Re: [PATCH 2/5] drm/xe: Guard against NULL GT in xe_pmu.c
Date: Fri, 26 Sep 2025 20:26:05 +0200 [thread overview]
Message-ID: <01362e3e-3ac5-4767-b652-e1f3fb367960@intel.com> (raw)
In-Reply-To: <20250926155948.145934-9-jonathan.cavitt@intel.com>
On 9/26/2025 5:59 PM, Jonathan Cavitt wrote:
> Static analysis reveals the following issue:
> xe_device_get_gt is theoretically able to return NULL in some cases, but
> several use cases don't check the return value before performing a
> dereference, resulting in a NULL pointer dereference.
>
> Add guards against this in xe_pmu.c:
> - Use xe_root_mmio_gt instead of xe_device_get_gt for the tile 0 case.
it's about GT ID case, not tile, right?
> - Check the return value of xe_device_get_gt when this is not possible.
> - Return early from xe_pmu_event_destroy if GT is NULL.
>
> Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
> ---
> drivers/gpu/drm/xe/xe_pmu.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_pmu.c b/drivers/gpu/drm/xe/xe_pmu.c
> index cab51d826345..531022d80731 100644
> --- a/drivers/gpu/drm/xe/xe_pmu.c
> +++ b/drivers/gpu/drm/xe/xe_pmu.c
> @@ -142,6 +142,9 @@ static bool event_gt_forcewake(struct perf_event *event)
>
> gt = xe_device_get_gt(xe, config_to_gt_id(config));
>
> + if (!gt)
> + return false;
this function is only called from xe_pmu_event_init() which already checks that GT is valid
so maybe instead of adding redundant check, just pass gt to event_gt_forcewake() ?
or just teach the tool about this false-positive?
> +
> fw_ref = kzalloc(sizeof(*fw_ref), GFP_KERNEL);
> if (!fw_ref)
> return false;
> @@ -219,6 +222,10 @@ static void xe_pmu_event_destroy(struct perf_event *event)
>
> if (fw_ref) {
> gt = xe_device_get_gt(xe, config_to_gt_id(event->attr.config));
> +
> + if (!gt)
> + return;
now you may leak fw_ref itself and its allocation
> +
> xe_force_wake_put(gt_to_fw(gt), *fw_ref);
> kfree(fw_ref);
> event->pmu_private = NULL;
> @@ -497,7 +504,7 @@ static const struct attribute_group *pmu_events_attr_update[] = {
> static void set_supported_events(struct xe_pmu *pmu)
> {
> struct xe_device *xe = container_of(pmu, typeof(*xe), pmu);
> - struct xe_gt *gt = xe_device_get_gt(xe, 0);
> + struct xe_gt *gt = xe_root_mmio_gt(xe);
>
> if (!xe->info.skip_guc_pc) {
> pmu->supported_events |= BIT_ULL(XE_PMU_EVENT_GT_C6_RESIDENCY);
next prev parent reply other threads:[~2025-09-26 18:26 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-26 15:59 [PATCH 0/5] drm/xe: Guard against NULL return for xe_device_get_gt Jonathan Cavitt
2025-09-26 15:59 ` [PATCH 1/5] drm/xe: Guard against NULL GT in xe_sriov_vf.c Jonathan Cavitt
2025-09-26 18:10 ` Michal Wajdeczko
2025-09-26 15:59 ` [PATCH 2/5] drm/xe: Guard against NULL GT in xe_pmu.c Jonathan Cavitt
2025-09-26 18:26 ` Michal Wajdeczko [this message]
2025-09-29 10:40 ` Upadhyay, Tejas
2025-09-29 15:41 ` Cavitt, Jonathan
2025-09-26 15:59 ` [PATCH 3/5] drm/xe: Don't call xe_device_get_gt twice in xe_hw_engine_lookup Jonathan Cavitt
2025-09-26 18:28 ` Michal Wajdeczko
2025-09-26 15:59 ` [PATCH 4/5] drm/xe: Guard against NULL GT in xe_guc.c Jonathan Cavitt
2025-09-26 18:36 ` Michal Wajdeczko
2025-09-26 19:26 ` Matt Roper
2025-09-26 22:04 ` Michal Wajdeczko
2025-09-26 15:59 ` [PATCH 5/5] drm/xe/tests: Use xe_root_mmio_gt instead of xe_device_get_gt Jonathan Cavitt
2025-09-26 18:46 ` Michal Wajdeczko
2025-09-26 16:06 ` ✓ CI.KUnit: success for drm/xe: Guard against NULL return for xe_device_get_gt Patchwork
2025-09-26 16:42 ` ✓ Xe.CI.BAT: " Patchwork
2025-09-26 23:52 ` ✓ Xe.CI.Full: " 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=01362e3e-3ac5-4767-b652-e1f3fb367960@intel.com \
--to=michal.wajdeczko@intel.com \
--cc=alex.zuo@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=jonathan.cavitt@intel.com \
--cc=saurabhg.gupta@intel.com \
/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