Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Matthew Brost <matthew.brost@intel.com>,
	intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: dakr@kernel.org, pstanner@redhat.com
Subject: Re: [PATCH] drm/sched: Increment job count before swapping tail spsc queue
Date: Tue, 1 Jul 2025 09:40:05 +0200	[thread overview]
Message-ID: <8b288dcd-81ed-4047-89b4-4bc8a4062fb2@amd.com> (raw)
In-Reply-To: <20250613212013.719312-1-matthew.brost@intel.com>

On 13.06.25 23:20, Matthew Brost wrote:
> A small race exists between spsc_queue_push and the run-job worker, in
> which spsc_queue_push may return not-first while the run-job worker has
> already idled due to the job count being zero. If this race occurs, job
> scheduling stops, leading to hangs while waiting on the job’s DMA
> fences.
> 
> Seal this race by incrementing the job count before appending to the
> SPSC queue.
> 
> This race was observed on a drm-tip 6.16-rc1 build with the Xe driver in
> an SVM test case.
> 
> Fixes: 1b1f42d8fde4 ("drm: move amd_gpu_scheduler into common location")
> Fixes: 27105db6c63a ("drm/amdgpu: Add SPSC queue to scheduler.")
> Cc: stable@vger.kernel.org
> Signed-off-by: Matthew Brost <matthew.brost@intel.com>

Sorry for the late response, if it isn't already pushed to drm-misc-fixes then feel free to add Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>  include/drm/spsc_queue.h | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/include/drm/spsc_queue.h b/include/drm/spsc_queue.h
> index 125f096c88cb..ee9df8cc67b7 100644
> --- a/include/drm/spsc_queue.h
> +++ b/include/drm/spsc_queue.h
> @@ -70,9 +70,11 @@ static inline bool spsc_queue_push(struct spsc_queue *queue, struct spsc_node *n
>  
>  	preempt_disable();
>  
> +	atomic_inc(&queue->job_count);
> +	smp_mb__after_atomic();
> +
>  	tail = (struct spsc_node **)atomic_long_xchg(&queue->tail, (long)&node->next);
>  	WRITE_ONCE(*tail, node);
> -	atomic_inc(&queue->job_count);
>  
>  	/*
>  	 * In case of first element verify new node will be visible to the consumer


  parent reply	other threads:[~2025-07-01  7:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-13 21:20 [PATCH] drm/sched: Increment job count before swapping tail spsc queue Matthew Brost
2025-06-13 22:03 ` Cavitt, Jonathan
2025-06-14  0:18 ` ✗ CI.checkpatch: warning for " Patchwork
2025-06-14  0:19 ` ✓ CI.KUnit: success " Patchwork
2025-06-14  0:56 ` ✓ Xe.CI.BAT: " Patchwork
2025-06-16  1:36 ` ✓ Xe.CI.Full: " Patchwork
2025-07-01  7:40 ` Christian König [this message]
2025-07-01 23:19   ` [PATCH] " Matthew Brost

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=8b288dcd-81ed-4047-89b4-4bc8a4062fb2@amd.com \
    --to=christian.koenig@amd.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    --cc=pstanner@redhat.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