Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cavitt <jonathan.cavitt@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: saurabhg.gupta@intel.com, alex.zuo@intel.com,
	jonathan.cavitt@intel.com, michal.wajdeczko@intel.com,
	matthew.d.roper@intel.com, rodrigo.vivi@intel.com,
	tejas.upadhyay@intel.com
Subject: [PATCH v3 5/7] drm/xe: Guard against NULL GT in xe_pmu.c
Date: Tue, 14 Oct 2025 16:48:04 +0000	[thread overview]
Message-ID: <20251014164758.125598-14-jonathan.cavitt@intel.com> (raw)
In-Reply-To: <20251014164758.125598-9-jonathan.cavitt@intel.com>

Static analysis reveals the following issue:
xe_device_lookup_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.

Use xe_device_get_gt in places where this is not already covered.
Additionally, only perform xe_force_wake_put in xe_pmu_event_destroy if
gt exists.

v2:
- Pass xe_gt to event_gt_forcewake (Michal)
  - Above necessitated passing xe_gt to event_supported (jcavitt)
- Only perform xe_force_wake_put in xe_pmu_event_destroy if gt exists.

v3:
- Use xe_device_get_gt

Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
---
 drivers/gpu/drm/xe/xe_pmu.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_pmu.c b/drivers/gpu/drm/xe/xe_pmu.c
index 6c428f1e9e23..60b19d625229 100644
--- a/drivers/gpu/drm/xe/xe_pmu.c
+++ b/drivers/gpu/drm/xe/xe_pmu.c
@@ -140,7 +140,7 @@ static bool event_gt_forcewake(struct perf_event *event)
 	if (!is_engine_event(config) && !is_gt_frequency_event(event))
 		return true;
 
-	gt = xe_device_lookup_gt(xe, config_to_gt_id(config));
+	gt = xe_device_get_gt(xe, config_to_gt_id(config));
 
 	fw_ref = kzalloc(sizeof(*fw_ref), GFP_KERNEL);
 	if (!fw_ref)
@@ -219,7 +219,10 @@ static void xe_pmu_event_destroy(struct perf_event *event)
 
 	if (fw_ref) {
 		gt = xe_device_lookup_gt(xe, config_to_gt_id(event->attr.config));
-		xe_force_wake_put(gt_to_fw(gt), *fw_ref);
+
+		if (gt)
+			xe_force_wake_put(gt_to_fw(gt), *fw_ref);
+
 		kfree(fw_ref);
 		event->pmu_private = NULL;
 	}
-- 
2.43.0


  parent reply	other threads:[~2025-10-14 16:48 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14 16:47 [PATCH v3 0/7] drm/xe: Guard against NULL return for xe_device_get_gt Jonathan Cavitt
2025-10-14 16:48 ` [PATCH v3 1/7] drm/xe: s/xe_device_get_gt/xe_device_lookup_gt Jonathan Cavitt
2025-10-14 17:17   ` Michal Wajdeczko
2025-10-14 17:21     ` Cavitt, Jonathan
2025-10-14 16:48 ` [PATCH v3 2/7] drm/xe: Don't call xe_device_lookup_gt twice in xe_hw_engine_lookup Jonathan Cavitt
2025-10-14 16:48 ` [PATCH v3 3/7] drm/xe/xe_device: Reintroduce xe_device_get_gt Jonathan Cavitt
2025-10-14 17:28   ` Michal Wajdeczko
2025-10-14 16:48 ` [PATCH v3 4/7] drm/xe: Guard against NULL GT in xe_sriov_vf.c Jonathan Cavitt
2025-10-14 17:32   ` Michal Wajdeczko
2025-10-14 17:34     ` Cavitt, Jonathan
2025-10-14 16:48 ` Jonathan Cavitt [this message]
2025-10-14 16:48 ` [PATCH v3 6/7] drm/xe: Guard against NULL GT in xe_guc.c Jonathan Cavitt
2025-10-14 16:48 ` [PATCH v3 7/7] drm/xe/tests: Use any available GT for testing Jonathan Cavitt
2025-10-14 17:51   ` Michal Wajdeczko
2025-10-14 18:06     ` Cavitt, Jonathan
2025-10-14 16:55 ` ✓ CI.KUnit: success for drm/xe: Guard against NULL return for xe_device_get_gt Patchwork
2025-10-14 17:44 ` ✓ Xe.CI.BAT: " Patchwork
2025-10-15  2:37 ` ✗ 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=20251014164758.125598-14-jonathan.cavitt@intel.com \
    --to=jonathan.cavitt@intel.com \
    --cc=alex.zuo@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.d.roper@intel.com \
    --cc=michal.wajdeczko@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=saurabhg.gupta@intel.com \
    --cc=tejas.upadhyay@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