All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: <sashiko-reviews@lists.linux.dev>
Cc: "Chen, Junjia" <junjia.chen@intel.com>, <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH] drm/xe: Unwrap sync fences before adding them as job dependencies
Date: Tue, 27 Oct 2026 10:12:57 -0700	[thread overview]
Message-ID: <auDbmaWkmhP72M+q@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <sashiko-outbox-184600@kernel.org>

On Mon, Oct 26, 2026 at 02:24:16AM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] drm/xe: dma_fence leak in xe_sync_entry_add_deps() on error return
> --
> 
> commit 7c1f1992f566aa87fc231ce7e528d8b1c35d0686
> Author: Chen, Junjia <junjia.chen@intel.com>
> 
> drm/xe: Unwrap sync fences before adding them as job dependencies
> 
> This commit unwraps fence containers in xe_sync_entry_add_deps() using
> dma_fence_unwrap_for_each() before adding unsignaled underlying fences as
> job dependencies via drm_sched_job_add_dependency(). This allows the DRM
> scheduler to recognize same-entity fences wrapped inside timeline syncobj
> chain nodes instead of treating the container as a cross-queue dependency.
> 
> > diff --git a/drivers/gpu/drm/xe/xe_sync.c b/drivers/gpu/drm/xe/xe_sync.c
> > index 06b1c913588ab..73fe7f05ba166 100644
> > --- a/drivers/gpu/drm/xe/xe_sync.c
> > +++ b/drivers/gpu/drm/xe/xe_sync.c
> 
> [ ... ]
> 
> > @@ -233,9 +234,30 @@ ALLOW_ERROR_INJECTION(xe_sync_entry_parse, ERRNO);
> >  
> >  int xe_sync_entry_add_deps(struct xe_sync_entry *sync, struct xe_sched_job *job)
> >  {
> > -	if (sync->fence)
> > -		return  drm_sched_job_add_dependency(&job->drm,
> > -						     dma_fence_get(sync->fence));
> > +	struct dma_fence_unwrap iter;
> > +	struct dma_fence *fence;
> > +	int err;
> > +
> > +	if (!sync->fence)
> > +		return 0;
> > +
> > +	/*
> > +	 * Unwrap fence containers (e.g. dma_fence_chain from a timeline
> > +	 * syncobj) so the scheduler sees the underlying fences. That lets it
> > +	 * drop dependencies on jobs from the same entity and only wait for
> > +	 * jobs on the same scheduler to be scheduled, rather than waiting for
> > +	 * the container, which forces a full GPU completion wait and drains
> > +	 * the queue.
> > +	 */
> > +	dma_fence_unwrap_for_each(fence, &iter, sync->fence) {
> > +		if (dma_fence_is_signaled(fence))
> > +			continue;
> > +
> > +		err = drm_sched_job_add_dependency(&job->drm,
> > +						   dma_fence_get(fence));
> > +		if (err)
> > +			return err;
> 
> [Severity: Medium]
> Does returning early from inside dma_fence_unwrap_for_each() leak the
> dma_fence reference held in iter.chain when drm_sched_job_add_dependency()
> fails?
> 
> When dma_fence_unwrap_for_each() starts, dma_fence_unwrap_first() takes a
> reference on the head fence and stores it in cursor->chain:
> 
> drivers/dma-buf/dma-fence-unwrap.c:dma_fence_unwrap_first() {
> 	cursor->chain = dma_fence_get(head);
> 	return __dma_fence_unwrap_array(cursor);
> }
> 
> That reference is only stepped and eventually dropped as
> dma_fence_unwrap_next() walks cursor->chain to the end of the chain via
> dma_fence_chain_walk():
> 
> drivers/dma-buf/dma-fence-unwrap.c:dma_fence_unwrap_next() {
> 	...
> 	cursor->chain = dma_fence_chain_walk(cursor->chain);
> 	return __dma_fence_unwrap_array(cursor);
> }
> 
> If drm_sched_job_add_dependency() returns an error before the loop finishes
> iterating, should xe_sync_entry_add_deps() call dma_fence_put(iter.chain)

I traced this through and I believe this feedback is correct - upon
drm_sched_job_add_dependency returning an error,
dma_fence_put(iter.chain) should be called. We probably could rework
dma_fence_unwrap_for_each to be guard based so this happens
automatically when the scope is exitted but we can look at that in a
follow up.

Everything else in this patch LGTM.

Thanks - Matt

> before returning err?
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20261026020721.973291-1-junjia.chen@intel.com?part=1

  reply	other threads:[~2026-10-27 17:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-26  2:07 [PATCH] drm/xe: Unwrap sync fences before adding them as job dependencies Chen, Junjia
2026-10-26  2:16 ` ✓ CI.KUnit: success for " Patchwork
2026-10-26  2:24 ` [PATCH] " sashiko-bot
2026-10-27 17:12   ` Matthew Brost [this message]
2026-10-26  2:51 ` ✓ Xe.CI.BAT: success for " Patchwork
2026-10-26  3:59 ` ✗ 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=auDbmaWkmhP72M+q@gsse-cloud1.jf.intel.com \
    --to=matthew.brost@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=junjia.chen@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.