dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nicolas Frattaroli" <nicolas.frattaroli@collabora.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 2/3] drm/panthor: Revisit reqs_lock handling in flush/reset paths
Date: Thu, 30 Jul 2026 12:02:29 +0000	[thread overview]
Message-ID: <20260730120229.9EC5F1F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260730-panthor-cache-flush-fix-v2-2-28790478bfff@collabora.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Race condition between the threaded IRQ handler and the wait timeout logic causes spurious GPU resets.
--

--- Patch [2]: [PATCH v2 2/3] drm/panthor: Revisit reqs_lock handling in flush/reset paths ---
commit ec14154f1ff35bca85396f0f6f71d7d7b1d6eb6d
Author: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>

drm/panthor: Revisit reqs_lock handling in flush/reset paths

The patch updates the handling of reqs_lock in panthor_gpu_flush_caches() and
panthor_gpu_soft_reset(). It replaces wait_event_timeout() with
wait_event_lock_timeout(), and uses spin_lock() instead of spin_lock_irqsave()
since the lock is not acquired in an atomic context.

> diff --git a/drivers/gpu/drm/panthor/panthor_gpu.c b/drivers/gpu/drm/panthor/panthor_gpu.c
> index e52c5675981f5..cd591c17198be 100644
> --- a/drivers/gpu/drm/panthor/panthor_gpu.c
> +++ b/drivers/gpu/drm/panthor/panthor_gpu.c
> @@ -329,35 +329,34 @@ int panthor_gpu_flush_caches(struct panthor_device *ptdev,

[ ... ]

> -	if (!wait_event_timeout(ptdev->gpu->reqs_acked,
> +	if (!wait_event_lock_timeout(ptdev->gpu->reqs_acked,
>  				!(ptdev->gpu->pending_reqs & GPU_IRQ_CLEAN_CACHES_COMPLETED),
> -				msecs_to_jiffies(100))) {
> -		spin_lock_irqsave(&ptdev->gpu->reqs_lock, flags);
> +				ptdev->gpu->reqs_lock, msecs_to_jiffies(100))) {
>  		if ((ptdev->gpu->pending_reqs & GPU_IRQ_CLEAN_CACHES_COMPLETED) != 0 &&
>  		    !(gpu_read(gpu->irq.iomem, INT_RAWSTAT) & GPU_IRQ_CLEAN_CACHES_COMPLETED))
>  			ret = -ETIMEDOUT;

[Severity: High]
This isn't a bug introduced by this patch, but is there a race condition here
with the threaded IRQ handler?

If panthor_gpu_irq_handler() clears the hardware interrupt status via
INT_CLEAR before acquiring reqs_lock, it can be preempted:

    gpu_write(gpu->irq.iomem, INT_CLEAR, status);
    
    // ... preemptible window ...
    
    spin_lock(&ptdev->gpu->reqs_lock);
    if (status & ptdev->gpu->pending_reqs) {

If the 100ms timeout expires during this precise window, the fallback condition
above evaluates under reqs_lock.

It finds that pending_reqs still indicates the request is pending, but
checking INT_RAWSTAT shows the interrupt is not pending (because it was just
cleared by the preempted thread). 

Could this cause the wait logic to falsely conclude the hardware timed out,
return -ETIMEDOUT, and schedule a spurious full GPU reset?

[ ... ]

> @@ -377,27 +376,25 @@ int panthor_gpu_soft_reset(struct panthor_device *ptdev)

[ ... ]

> -	if (!wait_event_timeout(ptdev->gpu->reqs_acked,
> +	if (!wait_event_lock_timeout(ptdev->gpu->reqs_acked,
>  				!(ptdev->gpu->pending_reqs & GPU_IRQ_RESET_COMPLETED),
> +				ptdev->gpu->reqs_lock,
>  				msecs_to_jiffies(100))) {
> -		spin_lock_irqsave(&ptdev->gpu->reqs_lock, flags);
>  		if ((ptdev->gpu->pending_reqs & GPU_IRQ_RESET_COMPLETED) != 0 &&
>  		    !(gpu_read(gpu->irq.iomem, INT_RAWSTAT) & GPU_IRQ_RESET_COMPLETED))
>  			timedout = true;

[Severity: High]
This is a pre-existing issue, but does this suffer from the same race condition
with the threaded IRQ handler as the flush caches timeout logic above?

>  		else
>  			ptdev->gpu->pending_reqs &= ~GPU_IRQ_RESET_COMPLETED;
> -		spin_unlock_irqrestore(&ptdev->gpu->reqs_lock, flags);
>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260730-panthor-cache-flush-fix-v2-0-28790478bfff@collabora.com?part=2

  reply	other threads:[~2026-07-30 12:02 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30 11:45 [PATCH v2 0/3] Rework panthor's cache flush and soft reset locking Nicolas Frattaroli
2026-07-30 11:45 ` [PATCH v2 1/3] wait: Introduce non-irq variants of wait_event_lock_timeout Nicolas Frattaroli
2026-07-30 11:53   ` sashiko-bot
2026-07-30 15:08   ` Liviu Dudau
2026-07-31  8:00   ` Steven Price
2026-07-30 11:45 ` [PATCH v2 2/3] drm/panthor: Revisit reqs_lock handling in flush/reset paths Nicolas Frattaroli
2026-07-30 12:02   ` sashiko-bot [this message]
2026-07-30 14:56   ` Liviu Dudau
2026-07-31  8:01   ` Steven Price
2026-08-03  8:53   ` Boris Brezillon
2026-08-03 13:13     ` Nicolas Frattaroli
2026-08-03 13:20       ` Nicolas Frattaroli
2026-08-03 15:59       ` Boris Brezillon
2026-07-30 11:45 ` [PATCH v2 3/3] drm/panthor: Add tracepoints for cache flushing Nicolas Frattaroli
2026-07-30 13:46   ` Steven Rostedt
2026-07-30 15:14   ` Liviu Dudau
2026-07-31  8:03   ` Steven Price
2026-08-03  9:03   ` Boris Brezillon
2026-08-04 14:44     ` Nicolas Frattaroli

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=20260730120229.9EC5F1F00A3E@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=nicolas.frattaroli@collabora.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox