From: Matthew Brost <matthew.brost@intel.com>
To: Bommu Krishnaiah <krishnaiah.bommu@intel.com>
Cc: <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH 2/2] drm/xe: Centralize migration fence updates
Date: Tue, 24 Nov 2026 13:56:05 -0800 [thread overview]
Message-ID: <awYH9SbYvaT45pm+@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <20261120070822.3834209-3-krishnaiah.bommu@intel.com>
On Fri, Nov 20, 2026 at 12:38:22PM +0530, Bommu Krishnaiah wrote:
> Add a helper for replacing the migration fence. Assert that job_mutex
> is held when updating the stored fence and document how readers must
> acquire a reference before using it outside the lock.
>
> Use the helper at each migration fence update site, and use
> scoped_guard when taking the reference in xe_migrate_wait().
> This keeps the fence ownership and locking rules explicit
> across the migrate layer.
>
> Cc: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
> Signed-off-by: Bommu Krishnaiah <krishnaiah.bommu@intel.com>
> ---
> drivers/gpu/drm/xe/xe_migrate.c | 36 ++++++++++++++++++---------------
> 1 file changed, 20 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
> index 57a81eda2088..99d4ce53f0b2 100644
> --- a/drivers/gpu/drm/xe/xe_migrate.c
> +++ b/drivers/gpu/drm/xe/xe_migrate.c
> @@ -227,7 +227,9 @@ struct xe_migrate {
> u64 large_page_copy_pdes;
> /**
> * @fence: dma-fence representing the last migration job batch.
> - * Protected by @job_mutex.
> + * Updated under @job_mutex. Readers must take a reference while holding
> + * the mutex before using the fence outside the critical section. The
> + * stored reference is released during final teardown.
> */
> struct dma_fence *fence;
> /** @min_chunk_size: For dgfx, Minimum chunk size */
> @@ -273,6 +275,13 @@ static void xe_migrate_ulls_toggle_enable(struct xe_migrate *m, bool enabled)
> m->ulls.enabled = enabled;
> }
>
> +static void xe_migrate_fence_set(struct xe_migrate *m, struct dma_fence *fence)
> +{
> + lockdep_assert_held(&m->job_mutex);
> + dma_fence_put(m->fence);
> + m->fence = dma_fence_get(fence);
> +}
> +
> static void xe_migrate_ulls_fini(struct xe_migrate *m)
> {
> struct xe_device *xe = tile_to_xe(m->tile);
> @@ -1433,8 +1442,7 @@ static struct dma_fence *__xe_migrate_copy(struct xe_migrate *m,
> dma_fence_put(fence);
> fence = xe_migrate_job_push(m, job);
>
> - dma_fence_put(m->fence);
> - m->fence = dma_fence_get(fence);
> + xe_migrate_fence_set(m, fence);
>
> mutex_unlock(&m->job_mutex);
>
> @@ -1862,8 +1870,7 @@ struct dma_fence *xe_migrate_vram_copy_chunk(struct xe_bo *vram_bo, u64 vram_off
> dma_fence_put(fence);
> fence = xe_migrate_job_push(m, job);
>
> - dma_fence_put(m->fence);
> - m->fence = dma_fence_get(fence);
> + xe_migrate_fence_set(m, fence);
> }
>
> xe_bb_free(bb, fence);
> @@ -2097,8 +2104,7 @@ struct dma_fence *xe_migrate_clear(struct xe_migrate *m,
> dma_fence_put(fence);
> fence = xe_migrate_job_push(m, job);
>
> - dma_fence_put(m->fence);
> - m->fence = dma_fence_get(fence);
> + xe_migrate_fence_set(m, fence);
>
> mutex_unlock(&m->job_mutex);
>
> @@ -2152,9 +2158,9 @@ void xe_migrate_wait(struct xe_migrate *m)
> {
> struct dma_fence *fence;
>
> - mutex_lock(&m->job_mutex);
> - fence = dma_fence_get(m->fence);
> - mutex_unlock(&m->job_mutex);
> + scoped_guard(mutex, &m->job_mutex) {
> + fence = dma_fence_get(m->fence);
> + }
>
> if (fence) {
> dma_fence_wait(fence, false);
> @@ -2463,12 +2469,10 @@ static struct dma_fence *xe_migrate_vram(struct xe_migrate *m,
> err = 0;
> }
>
> - mutex_lock(&m->job_mutex);
> - fence = xe_migrate_job_push(m, job);
> -
> - dma_fence_put(m->fence);
> - m->fence = dma_fence_get(fence);
> - mutex_unlock(&m->job_mutex);
> + scoped_guard(mutex, &m->job_mutex) {
> + fence = xe_migrate_job_push(m, job);
> + xe_migrate_fence_set(m, fence);
> + }
>
> xe_bb_free(bb, fence);
>
> --
> 2.43.0
>
next prev parent reply other threads:[~2026-11-24 22:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 7:08 [PATCH 0/2] drm/xe: Hold a fence reference while waiting for migration Bommu Krishnaiah
2026-11-20 7:08 ` [PATCH 1/2] " Bommu Krishnaiah
2026-11-24 21:55 ` Matthew Brost
2026-11-20 7:08 ` [PATCH 2/2] drm/xe: Centralize migration fence updates Bommu Krishnaiah
2026-11-24 21:56 ` Matthew Brost [this message]
2026-11-20 8:10 ` ✓ CI.KUnit: success for drm/xe: Hold a fence reference while waiting for migration (rev2) Patchwork
2026-11-20 9:01 ` ✓ Xe.CI.BAT: " 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=awYH9SbYvaT45pm+@gsse-cloud1.jf.intel.com \
--to=matthew.brost@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=krishnaiah.bommu@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 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.