From: sashiko-bot@kernel.org
To: "Adrián Larumbe" <adrian.larumbe@collabora.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v7 16/17] drm/panfrost: Fix races between perfcnt and reset sequence
Date: Fri, 28 Aug 2026 21:17:28 +0000 [thread overview]
Message-ID: <20260828211728.DBB9E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260828-claude-fixes-v7-16-72a13b2c125d@collabora.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [High] Hardware reset notifications are permanently lost on interrupted ioctl waits.
- [High] Unprotected GPU register writes to GPU_CMD race with device reset.
- [Low] Mixing goto-based error handling with scoped_guard() cleanup in the same function.
Pre-existing issues:
- [High] Spurious WARN_ON due to an off-by-one boundary check in panfrost_mmu_as_get.
--
commit f478a9bf05ba523f5eb295d8a3b40bf995a8444e
Author: Adrián Larumbe <adrian.larumbe@collabora.com>
drm/panfrost: Fix races between perfcnt and reset sequence
This commit updates the reset sequence to use the reset r/w semaphore to
govern hardware access. It also expands the DRM uAPI for the perfcnt dump
operation to inform userspace when a reset occurs, which resets the counters
back to zero.
> diff --git a/drivers/gpu/drm/panfrost/panfrost_perfcnt.c b/drivers/gpu/drm/panfrost/panfrost_perfcnt.c
> --- a/drivers/gpu/drm/panfrost/panfrost_perfcnt.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_perfcnt.c
[ ... ]
> @@ -58,25 +63,107 @@ void panfrost_perfcnt_sample_done(struct panfrost_device *pfdev)
[ ... ]
> +static int panfrost_perfcnt_dump_locked(struct panfrost_device *pfdev,
> + u64 *reset_happened)
> +{
[ ... ]
> +dump_retry:
> + retry = false;
> + scoped_guard(rwsem_read, &pfdev->reset.lock) {
> + *reset_happened = perfcnt->reset_happened;
> + perfcnt->reset_happened = false;
[Severity: High]
If this wait is interrupted by a signal,
wait_for_completion_interruptible_timeout() returns -ERESTARTSYS. Because
we already cleared perfcnt->reset_happened to false above, when the syscall
is automatically restarted, will it see the cleared flag and falsely report
hw_reset = 0 to userspace?
Could this cause userspace to permanently lose notifications about hardware
resets?
> + if (perfcnt->reset_failed) {
> + ret = panfrost_perfcnt_hw_enable(pfdev);
> + if (ret)
> + return ret;
> + perfcnt->reset_failed = false;
> + }
> +
> + reinit_completion(&pfdev->perfcnt->dump_comp);
> +
> + gpu_write(pfdev, GPU_PERFCNT_BASE_LO, lower_32_bits(gpuva));
> + gpu_write(pfdev, GPU_PERFCNT_BASE_HI, upper_32_bits(gpuva));
> + gpu_write(pfdev, GPU_INT_CLEAR, GPU_IRQ_CLEAN_CACHES_COMPLETED |
> + GPU_IRQ_PERFCNT_SAMPLE_COMPLETED);
> + gpu_write(pfdev, GPU_CMD, GPU_CMD_PERFCNT_SAMPLE);
> + }
> +
> + /*
> + * Here we release the reset semaphore because perfcnt should not get in the way
> + * of a HW reset. The downside is in the gap between the completion is flagged
> + * by the GPU IRQ handler and the sempahore taken once again, yet another reset
> + * could happen, which would lead to a valid sample being discarded. This is
> + * a solution of compromise between ensuring synchronisation with the reset
> + * sequence and letting it happen as quickly as possible for jobs to be rerun.
> + */
> +
> ret = wait_for_completion_interruptible_timeout(&pfdev->perfcnt->dump_comp,
> msecs_to_jiffies(1000));
[ ... ]
> @@ -132,44 +220,19 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,
[ ... ]
> /*
> * Clear the counters to start from a fresh state.
> */
> gpu_write(pfdev, GPU_INT_CLEAR, GPU_IRQ_PERFCNT_SAMPLE_COMPLETED);
> gpu_write(pfdev, GPU_CMD, GPU_CMD_PERFCNT_CLEAR);
[Severity: High]
Are these register writes exposed to the exact race condition this patch
intends to fix?
Executing gpu_write(pfdev, GPU_CMD, GPU_CMD_PERFCNT_CLEAR) without holding
pfdev->reset.lock means a concurrent soft reset (which writes
GPU_CMD_SOFT_RESET) could race on the GPU_CMD register.
> - ret = panfrost_mmu_as_get(pfdev, perfcnt->mapping->mmu);
> - if (ret < 0)
> - goto err_vunmap;
> -
[ ... ]
> + scoped_guard(rwsem_read, &pfdev->reset.lock) {
> + ret = panfrost_perfcnt_hw_enable(pfdev);
[Severity: High]
This is a pre-existing issue, but does panfrost_mmu_as_get() contain an
off-by-one boundary check that could trigger a spurious kernel warning?
Looking at panfrost_mmu_as_get() in drivers/gpu/drm/panfrost/panfrost_mmu.c:
/*
* AS can be retained by active jobs or a perfcnt context,
* hence the '+ 1' here.
*/
WARN_ON(en >= (NUM_JOB_SLOTS + 1));
If a user process submits jobs to all 3 available slots (NUM_JOB_SLOTS = 3)
and simultaneously enables a performance counter session, there are 4
references. atomic_inc_return() returns 4, satisfying 4 >= 4, which
erroneously triggers the WARN_ON.
> + if (ret)
> + goto err_vunmap;
[Severity: Low]
Does mixing goto with scoped_guard() here violate the subsystem cleanup
guidelines?
Jumping to a manual cleanup label from inside a scoped_guard creates
confusing ownership semantics.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260828-claude-fixes-v7-0-72a13b2c125d@collabora.com?part=16
next prev parent reply other threads:[~2026-08-28 21:17 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 20:56 [PATCH v7 00/17] Collection of fixes for Panfrost: Perfcnt, RPM, refactorings Adrián Larumbe
2026-08-28 20:56 ` [PATCH v7 01/17] drm/panfrost: Move shrinker initialization and unplug one level down Adrián Larumbe
2026-09-01 11:28 ` Boris Brezillon
2026-09-02 15:36 ` Adrián Larumbe
2026-08-28 20:56 ` [PATCH v7 02/17] drm/panfrost: Move all DRM device initialisation into device_init() Adrián Larumbe
2026-09-01 11:49 ` Boris Brezillon
2026-09-02 15:38 ` Adrián Larumbe
2026-09-02 15:50 ` Boris Brezillon
2026-08-28 20:56 ` [PATCH v7 03/17] drm/panfrost: Move lock and modparam initialisations into their subsystems Adrián Larumbe
2026-08-28 21:14 ` sashiko-bot
2026-09-01 12:10 ` Boris Brezillon
2026-08-28 20:56 ` [PATCH v7 04/17] drm/panfrost: Move debugfs initialisation to relevant subsystems Adrián Larumbe
2026-09-01 12:30 ` Boris Brezillon
2026-09-02 15:40 ` Adrián Larumbe
2026-08-28 20:56 ` [PATCH v7 05/17] drm/panfrost: Skip NULL checks for clock enable/disabling Adrián Larumbe
2026-09-01 12:31 ` Boris Brezillon
2026-08-28 20:56 ` [PATCH v7 06/17] drm/panfrost: Consolidate device clock management and reset Adrián Larumbe
2026-09-01 12:38 ` Boris Brezillon
2026-09-02 15:41 ` Adrián Larumbe
2026-08-28 20:56 ` [PATCH v7 07/17] drm/panfrost: Stop all jobs before commencing device teardown Adrián Larumbe
2026-08-28 21:16 ` sashiko-bot
2026-09-01 12:58 ` Boris Brezillon
2026-08-28 20:56 ` [PATCH v7 08/17] drm/panfrost: Split subsystem init/reset from interrupt enablement Adrián Larumbe
2026-08-28 21:11 ` sashiko-bot
2026-09-01 13:08 ` Boris Brezillon
2026-09-02 15:41 ` Adrián Larumbe
2026-09-02 16:05 ` Boris Brezillon
2026-08-28 20:56 ` [PATCH v7 09/17] drm/panfrost: Fix PM refcnt and autosuspend issues at device probe/remove Adrián Larumbe
2026-08-28 21:09 ` sashiko-bot
2026-09-01 13:18 ` Boris Brezillon
2026-09-02 15:42 ` Adrián Larumbe
2026-09-02 16:14 ` Boris Brezillon
2026-08-28 20:56 ` [PATCH v7 10/17] drm/panfrost: Add warning messages to fatal error conditions Adrián Larumbe
2026-08-28 21:10 ` sashiko-bot
2026-09-01 13:20 ` Boris Brezillon
2026-08-28 20:56 ` [PATCH v7 11/17] drm/panfrost: Add debugfs knob for manually triggering a GPU reset Adrián Larumbe
2026-08-28 21:12 ` sashiko-bot
2026-09-01 13:27 ` Boris Brezillon
2026-09-02 15:42 ` Adrián Larumbe
2026-09-02 16:23 ` Boris Brezillon
2026-08-28 20:56 ` [PATCH v7 12/17] drm/panfrost: Move perfcnt GPU disable sequence into a helper Adrián Larumbe
2026-08-28 20:56 ` [PATCH v7 13/17] drm/panfrost: Skip cache flush/invalidate when enabling perfcnt Adrián Larumbe
2026-09-01 13:32 ` Boris Brezillon
2026-09-02 15:43 ` Adrián Larumbe
2026-09-02 16:29 ` Boris Brezillon
2026-08-28 20:56 ` [PATCH v7 14/17] drm/panfrost: Avoid cache flush after perfcnt sample in fully coherent systems Adrián Larumbe
2026-08-28 21:14 ` sashiko-bot
2026-09-01 13:37 ` Boris Brezillon
2026-09-02 15:44 ` Adrián Larumbe
2026-09-02 16:33 ` Boris Brezillon
2026-09-02 16:34 ` Boris Brezillon
2026-08-28 20:56 ` [PATCH v7 15/17] drm/panfrost: Introduce a reset lock Adrián Larumbe
2026-08-28 20:56 ` [PATCH v7 16/17] drm/panfrost: Fix races between perfcnt and reset sequence Adrián Larumbe
2026-08-28 21:17 ` sashiko-bot [this message]
2026-09-01 14:03 ` Boris Brezillon
2026-09-02 15:45 ` Adrián Larumbe
2026-09-02 16:51 ` Boris Brezillon
2026-08-28 20:56 ` [PATCH v7 17/17] drm/panfrost: Bump driver minor to reflect new DUMP IOCTL req field Adrián Larumbe
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=20260828211728.DBB9E1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=adrian.larumbe@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--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.