Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: Matt Roper <matthew.d.roper@intel.com>
Cc: Jonathan Cavitt <jonathan.cavitt@intel.com>,
	<intel-xe@lists.freedesktop.org>, <saurabhg.gupta@intel.com>,
	<alex.zuo@intel.com>
Subject: Re: [PATCH 4/5] drm/xe: Guard against NULL GT in xe_guc.c
Date: Sat, 27 Sep 2025 00:04:53 +0200	[thread overview]
Message-ID: <ff327184-b6e5-4414-8d9a-6320297d9c7e@intel.com> (raw)
In-Reply-To: <20250926192628.GD10167@mdroper-desk1.amr.corp.intel.com>



On 9/26/2025 9:26 PM, Matt Roper wrote:
> On Fri, Sep 26, 2025 at 08:36:31PM +0200, Michal Wajdeczko wrote:
>>
>>
>> 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.
>>>
>>> Use xe_root_mmio_gt instead of xe_device_get_gt to prevent this in
>>> xe_guc.c
>>>
>>> Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
>>> ---
>>>  drivers/gpu/drm/xe/xe_guc.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/xe/xe_guc.c b/drivers/gpu/drm/xe/xe_guc.c
>>> index d5adbbb013ec..0bf1402c61a0 100644
>>> --- a/drivers/gpu/drm/xe/xe_guc.c
>>> +++ b/drivers/gpu/drm/xe/xe_guc.c
>>> @@ -466,7 +466,7 @@ static int guc_g2g_alloc(struct xe_guc *guc)
>>>  		return 0;
>>>  
>>>  	if (gt->info.id != 0) {
>>> -		struct xe_gt *root_gt = xe_device_get_gt(xe, 0);
>>> +		struct xe_gt *root_gt = xe_root_mmio_gt(xe);
>>
>> while this looks ok today, I'm not sure how this will work after [1]
>>
>> maybe we should check and abort here? + @Matt
> 
> On today's driver, xe_device_get_gt(xe, 0); can never return NULL.
> Hardware-wise there's always at least one tile, and every tile has a
> primary GT.  If something went wrong during init of the tile or GT and
> we couldn't create/initialize the structures, then we already aborted
> the device probe immediately and we'll never get further on to places in
> the code that would be chasing a NULL pointer.
> 
> As Michal pointed out, there's work to change this (i.e., allow the
> primary GT to be disabled via configfs for debugging purposes), but even
> with the referenced series we're not at the point where that can happen
> yet.  More patches will need to be written and land before we relax the
> probe-time checks and allow probe without a primary GT.  Once that
> happens, xe_device_get_gt(xe, 0) and xe_root_mmio_gt(xe) are both
> equally problematic, so replacing one with the other doesn't really
> help.

maybe we should have two helpers

* one that never fails - to be used when are sure that given GT exists
* other that may return NULL - in case we don't know if ID is valid

	/**
	 * @gtid: the GT ID of the valid GT to get
	 * Return: asserted pointer to &xe_gt
	 */
	xe_device_get_gt(xe, gtid)
vs
	/**
	 * @gtid: the GT ID to lookup
	 * Return: asserted pointer to &xe_gt or NULL if not found
	 */
	xe_device_lookup_gt(xe, gtid)

> 
> 
> Matt
> 
>>
>> [1] https://patchwork.freedesktop.org/series/154739/
>>
>>>  		struct xe_guc *root_guc = &root_gt->uc.guc;
>>>  		struct xe_bo *bo;
>>>  
>>
> 


  reply	other threads:[~2025-09-26 22:05 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
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 [this message]
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=ff327184-b6e5-4414-8d9a-6320297d9c7e@intel.com \
    --to=michal.wajdeczko@intel.com \
    --cc=alex.zuo@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jonathan.cavitt@intel.com \
    --cc=matthew.d.roper@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