public inbox for intel-xe@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: Shuicheng Lin <shuicheng.lin@intel.com>
Cc: <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH] drm/xe: Fix potential NULL deref in xe_exec_queue_tlb_inval_last_fence_put_unlocked
Date: Wed, 8 Apr 2026 17:47:00 -0700	[thread overview]
Message-ID: <adb3BKQE5hFW6cye@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <20260409003449.3405767-1-shuicheng.lin@intel.com>

On Thu, Apr 09, 2026 at 12:34:49AM +0000, Shuicheng Lin wrote:
> xe_exec_queue_tlb_inval_last_fence_put_unlocked() uses q->vm->xe as the
> first argument to xe_assert(). This function is called unconditionally
> from xe_exec_queue_destroy() for all queues, including kernel queues
> that have q->vm == NULL (e.g., queues created during GT init in
> xe_gt_record_default_lrcs() with vm=NULL).
> 
> While current compilers optimize away the q->vm->xe dereference (even
> in CONFIG_DRM_XE_DEBUG=y builds, the compiler pushes the dereference
> into the WARN branch that is only taken when the assert condition is
> false), the code is semantically incorrect and constitutes undefined
> behavior in the C abstract machine for the NULL pointer case.
> 
> Use gt_to_xe(q->gt) instead, which is always valid for any exec queue.
> This is consistent with how xe_exec_queue_destroy() itself obtains the
> xe_device pointer in its own xe_assert at the top of the function.
> 
> Fixes: b2d7ec41f2a3 ("drm/xe: Attach last fence to TLB invalidation job queues")
> Cc: Matthew Brost <matthew.brost@intel.com>

Reviewed-by: Matthew Brost <matthew.brost@intel.com>

> Assisted-by: Claude:claude-opus-4.6
> Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
> ---
>  drivers/gpu/drm/xe/xe_exec_queue.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_exec_queue.c b/drivers/gpu/drm/xe/xe_exec_queue.c
> index 4603ff08d860..071b8c41df43 100644
> --- a/drivers/gpu/drm/xe/xe_exec_queue.c
> +++ b/drivers/gpu/drm/xe/xe_exec_queue.c
> @@ -1763,7 +1763,7 @@ void xe_exec_queue_tlb_inval_last_fence_put(struct xe_exec_queue *q,
>  void xe_exec_queue_tlb_inval_last_fence_put_unlocked(struct xe_exec_queue *q,
>  						     unsigned int type)
>  {
> -	xe_assert(q->vm->xe, type == XE_EXEC_QUEUE_TLB_INVAL_MEDIA_GT ||
> +	xe_assert(gt_to_xe(q->gt), type == XE_EXEC_QUEUE_TLB_INVAL_MEDIA_GT ||
>  		  type == XE_EXEC_QUEUE_TLB_INVAL_PRIMARY_GT);
>  
>  	dma_fence_put(q->tlb_inval[type].last_fence);
> -- 
> 2.43.0
> 

  parent reply	other threads:[~2026-04-09  0:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-09  0:34 [PATCH] drm/xe: Fix potential NULL deref in xe_exec_queue_tlb_inval_last_fence_put_unlocked Shuicheng Lin
2026-04-09  0:44 ` ✗ CI.checkpatch: warning for " Patchwork
2026-04-09  0:45 ` ✗ CI.KUnit: failure " Patchwork
2026-04-09  0:47 ` Matthew Brost [this message]
2026-04-10  1:28 ` ✗ CI.checkpatch: warning for drm/xe: Fix potential NULL deref in xe_exec_queue_tlb_inval_last_fence_put_unlocked (rev2) Patchwork
2026-04-10  1:30 ` ✓ CI.KUnit: success " Patchwork
2026-04-10  2:29 ` ✓ Xe.CI.BAT: " Patchwork
2026-04-10  6:04 ` ✓ 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=adb3BKQE5hFW6cye@gsse-cloud1.jf.intel.com \
    --to=matthew.brost@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=shuicheng.lin@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