Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Umesh Nerlige Ramappa" <umesh.nerlige.ramappa@intel.com>,
	intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v6 5/7] drm/xe/oa: Wait for in-flight OA batches before stream HW teardown
Date: Mon, 16 Nov 2026 23:00:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-217833@kernel.org> (raw)
In-Reply-To: <20261116222752.3677159-14-umesh.nerlige.ramappa@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/xe/oa: killing exec queue in xe_oa_stream_drain() leaks
  jobs and wedges GPU
- [High] drm/xe/oa: context LRI batch fence in xe_oa_load_with_lri() is
  never drained
--

commit 78c0868da376abbc9e627eede4220f1019cbf62e
Author: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>

drm/xe/oa: Wait for in-flight OA batches before stream HW teardown

This commit records the LRI batch fence in stream->last_fence and adds
xe_oa_stream_drain() to wait for stream->last_fence before hardware
teardown, killing the exec queue if the wait times out.

> diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
> index 8ed427ad67b48..1a37312de099c 100644
> --- a/drivers/gpu/drm/xe/xe_oa.c
> +++ b/drivers/gpu/drm/xe/xe_oa.c
> @@ -733,6 +733,12 @@ static void xe_oa_free_configs(struct xe_oa_stream *stream)
>  	dma_fence_put(stream->last_fence);
>  }
>  
> +static void xe_oa_update_last_fence(struct xe_oa_stream *stream, struct dma_fence *fence)
> +{
> +	dma_fence_put(stream->last_fence);
> +	stream->last_fence = dma_fence_get(fence);
> +}
> +
>  static int xe_oa_load_with_lri(struct xe_oa_stream *stream, struct xe_oa_reg *reg_lri, u32 count)
>  {
>  	struct dma_fence *fence;
> @@ -753,6 +759,7 @@ static int xe_oa_load_with_lri(struct xe_oa_stream *stream, struct xe_oa_reg *re
>  		goto free_bb;
>  	}
>  	xe_bb_free(bb, fence);
> +	xe_oa_update_last_fence(stream, fence);
>  	dma_fence_put(fence);
>  
>  	return 0;
> @@ -876,6 +883,38 @@ static void xe_oa_disable_metric_set(struct xe_oa_stream *stream)
>  		xe_mmio_rmw32(mmio, OAM_COMPRESSION_T3_CONTROL, OAM_LAT_MEASURE_ENABLE, 0);
>  }
>  
> +/*
> + * Wait for the last OA batch of the stream, so that it can't program the HW after the HW
> + * teardown.
> + */
> +static void xe_oa_stream_drain(struct xe_oa_stream *stream)
> +{
> +	struct xe_exec_queue *q = stream->exec_q ?: stream->k_exec_q;
> +	long timeout;
> +
> +	if (!stream->last_fence || dma_fence_is_signaled(stream->last_fence))
> +		return;
> +
> +	timeout = msecs_to_jiffies(q->sched_props.job_timeout_ms) + HZ;
> +	if (dma_fence_wait_timeout(stream->last_fence, false, timeout))
> +		return;
> +
> +	drm_err(&stream->oa->xe->drm, "Timed out waiting for OA batch, killing exec queue\n");
> +
> +	/*
> +	 * The batch is most likely still waiting for an input sync, which no TDR covers. Kill
> +	 * the exec queue, so the batch is dropped instead of run when the input sync signals.
> +	 * A batch already on the HW gets cleaned up by the TDR the kill triggers, give it a
> +	 * moment.
> +	 */
> +	if (q->vm)
> +		xe_exec_queue_kill(q);
> +	else
> +		q->ops->kill(q);
> +
> +	dma_fence_wait_timeout(stream->last_fence, false, HZ);
> +}

[Severity: High]
Can killing q here wedge the GPU when q is stream->k_exec_q, and leak
jobs that are still waiting on an input sync?

When stream->exec_q is NULL, q is stream->k_exec_q, which is created with
EXEC_QUEUE_FLAG_KERNEL.  Calling q->ops->kill(q) invokes
guc_exec_queue_kill(), marking the queue killed and arming immediate TDR.
Once the job reaches sched->pending_list, guc_exec_queue_timedout_job()
checks timeout_needs_gt_reset():

drivers/gpu/drm/xe/xe_guc_submit.c:timeout_needs_gt_reset() {
	if (q->flags & EXEC_QUEUE_FLAG_KERNEL)
		return true;

	return !skip_timeout_check && !xe_sched_job_started(job);
}

Because EXEC_QUEUE_FLAG_KERNEL unconditionally returns true even when the
queue was killed, guc_exec_queue_timedout_job() triggers two asynchronous
GT resets and then fires a kernel WARN and wedges the device.

In addition, a batch blocked on an unsignaled input sync sits in
q->entity->job_queue rather than sched->pending_list.
guc_exec_queue_kill() only schedules TDR on sched->pending_list and does
not call drm_sched_entity_kill(q->entity), so stream->last_fence is not
signaled and the second dma_fence_wait_timeout() always waits out the
full HZ.  Because the queued xe_sched_job holds a reference on q via
xe_exec_queue_get(), xe_exec_queue_put() never reaches
xe_sched_entity_fini(), leaking the job, exec queue, config buffer, and
runtime PM reference if the input sync never signals.

> +
>  static void xe_oa_stream_hw_teardown(struct xe_oa_stream *stream)
>  {
>  	if (stream->sample)
> @@ -909,6 +948,7 @@ static void xe_oa_stream_destroy(struct xe_oa_stream *stream)
>  	/* The poll timer may still be armed if the OA disable was skipped */
>  	hrtimer_cancel(&stream->poll_check_timer);
>  
> +	xe_oa_stream_drain(stream);
>  	if (!xe_wedged(stream->oa->xe))
>  		xe_oa_stream_hw_teardown(stream);

[Severity: High]
Does xe_oa_stream_drain() ever wait for the fence recorded by
xe_oa_load_with_lri()?

xe_oa_load_with_lri() is only called from xe_oa_configure_oa_context(),
which runs in xe_oa_enable_metric_set() and xe_oa_disable_metric_set().
During xe_oa_enable_metric_set(), xe_oa_emit_oa_config() runs right after
xe_oa_configure_oa_context(stream, true) and overwrites
stream->last_fence; if xe_oa_emit_oa_config() fails, xe_oa_stream_init()
tears down the stream via err_put_k_exec_q without calling
xe_oa_stream_drain().

During xe_oa_stream_destroy(), xe_oa_stream_drain() runs before
xe_oa_stream_hw_teardown() -> xe_oa_disable_metric_set() ->
xe_oa_configure_oa_context(stream, false) submits the context-disable LRI
batch.  That teardown LRI batch is never waited on before
xe_oa_free_oa_buffer() unpins the OA buffer and xe_force_wake_put() drops
forcewake (and for OAC, after xe_oa_configure_oac_context() writes
__oa_ccs_select(stream) to OAG_OACONTROL).  Moreover, if
xe_oa_stream_drain() timed out and killed stream->exec_q,
xe_oa_configure_oa_context(stream, false) submits the disable LRI batch
to a killed queue that will never run it on hardware.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116222752.3677159-9-umesh.nerlige.ramappa@intel.com?part=5

  reply	other threads:[~2026-11-16 23:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 22:27 [PATCH v6 0/7] Cleanup OA stream on PCI unbind/remove Umesh Nerlige Ramappa
2026-11-16 22:27 ` [PATCH v6 1/7] drm/xe/oa: Use the drm device address_space for the OA stream fd Umesh Nerlige Ramappa
2026-11-16 22:46   ` sashiko-bot
2026-11-16 22:27 ` [PATCH v6 2/7] drm/xe/oa: Split OA stream destroy into HW teardown and resource release Umesh Nerlige Ramappa
2026-11-16 22:27 ` [PATCH v6 3/7] drm/xe/oa: Take the runtime PM reference in xe_oa_destroy_locked() Umesh Nerlige Ramappa
2026-11-16 22:27 ` [PATCH v6 4/7] drm/xe/oa: Skip OA HW teardown on a wedged device Umesh Nerlige Ramappa
2026-11-16 22:27 ` [PATCH v6 5/7] drm/xe/oa: Wait for in-flight OA batches before stream HW teardown Umesh Nerlige Ramappa
2026-11-16 23:00   ` sashiko-bot [this message]
2026-11-16 22:27 ` [PATCH v6 6/7] drm/xe: Reject vm_ops->access on BO mappings of an unplugged device Umesh Nerlige Ramappa
2026-11-16 22:54   ` sashiko-bot
2026-11-16 22:28 ` [PATCH v6 7/7] drm/xe/oa: Quiesce OA streams on driver unbind and PCI reset Umesh Nerlige Ramappa
2026-11-16 23:10   ` sashiko-bot
2026-11-16 22:39 ` ✓ CI.KUnit: success for Cleanup OA stream on PCI unbind/remove (rev6) Patchwork
2026-11-16 23:11 ` ✓ 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=sashiko-outbox-217833@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=umesh.nerlige.ramappa@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