From: sashiko-bot@kernel.org
To: "Adrián Larumbe" <adrian.larumbe@collabora.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 1/2] drm/panfrost: Enable cycle counting when perfcnt is enabled
Date: Tue, 03 Nov 2026 20:46:26 +0000 [thread overview]
Message-ID: <sashiko-outbox-196011@kernel.org> (raw)
In-Reply-To: <20261103-panfrost-reset-races-fixes-v2-1-454207b1d4e3@collabora.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] drm/panfrost: cycle_counter ref leak in panfrost_perfcnt_reset() on timeout
--
commit bc0ac72ceaf78a79c6a160afa6594381db03f37c
Author: Boris Brezillon <boris.brezillon@collabora.com>
drm/panfrost: Enable cycle counting when perfcnt is enabled
This commit enables the GPU cycle counter while performance counters are
enabled so block headers receive valid timestamps, and drops the warning on
a non-zero cycle counter reference count during GPU soft reset.
> diff --git a/drivers/gpu/drm/panfrost/panfrost_gpu.c b/drivers/gpu/drm/panfrost/panfrost_gpu.c
> index 6081b27829e1f..7d66b1b509689 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_gpu.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_gpu.c
> @@ -94,10 +94,10 @@ int panfrost_gpu_soft_reset(struct panfrost_device *pfdev)
> GPU_IRQ_CLEAN_CACHES_COMPLETED);
>
> /*
> - * All in-flight jobs should have released their cycle
> - * counter references upon reset, but let us make sure
> + * Even though all in-flight jobs should have released their cycle counter
> + * references upon reset, perfcnt's might still hang about.
> */
> - if (drm_WARN_ON(&pfdev->base, atomic_read(&pfdev->cycle_counter.use_count) != 0))
> + if (atomic_read(&pfdev->cycle_counter.use_count) != 0)
> atomic_set(&pfdev->cycle_counter.use_count, 0);
>
> return 0;
> diff --git a/drivers/gpu/drm/panfrost/panfrost_perfcnt.c b/drivers/gpu/drm/panfrost/panfrost_perfcnt.c
> index a9def452d5ef9..b26da057a1a01 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_perfcnt.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_perfcnt.c
[ ... ]
> @@ -84,6 +86,7 @@ static int panfrost_perfcnt_hw_enable(struct panfrost_device *pfdev)
> return ret;
>
> perfcnt->owns_as_ref = true;
> + panfrost_cycle_counter_get(pfdev);
[Severity: Medium]
Can this leak a reference on pfdev->cycle_counter.use_count if the GPU reset
times out in panfrost_gpu_soft_reset()?
In drivers/gpu/drm/panfrost/panfrost_gpu.c, panfrost_gpu_soft_reset() returns
early if both soft and hard resets time out, before resetting
pfdev->cycle_counter.use_count to 0:
drivers/gpu/drm/panfrost/panfrost_gpu.c:panfrost_gpu_soft_reset() {
...
if (ret) {
dev_err(pfdev->base.dev, "gpu hard reset timed out\n");
return ret;
}
}
...
if (atomic_read(&pfdev->cycle_counter.use_count) != 0)
atomic_set(&pfdev->cycle_counter.use_count, 0);
}
However, in drivers/gpu/drm/panfrost/panfrost_device.c,
panfrost_device_reset() ignores the return value of panfrost_gpu_soft_reset()
and still proceeds to call panfrost_mmu_reset() and panfrost_perfcnt_reset():
drivers/gpu/drm/panfrost/panfrost_device.c:panfrost_device_reset() {
guard(rwsem_write)(&pfdev->reset.lock);
panfrost_gpu_soft_reset(pfdev);
panfrost_gpu_power_on(pfdev);
panfrost_mmu_reset(pfdev);
...
panfrost_perfcnt_reset(pfdev);
}
When an active perfcnt session is present, panfrost_perfcnt_reset() clears
perfcnt->owns_as_ref without dropping the existing cycle_counter reference
and calls panfrost_perfcnt_hw_enable():
drivers/gpu/drm/panfrost/panfrost_perfcnt.c:panfrost_perfcnt_reset() {
...
/* All active AS are released during the MMU post_reset. */
perfcnt->owns_as_ref = false;
perfcnt->state |= PANFROST_PERFCNT_SESSION_INTERRUPTED_BY_RESET;
if (panfrost_perfcnt_hw_enable(pfdev))
perfcnt->state |= PANFROST_PERFCNT_SESSION_DEAD;
...
}
Because panfrost_mmu_reset() cleared pfdev->as_alloc_mask,
panfrost_mmu_as_get() succeeds in panfrost_perfcnt_hw_enable() and
panfrost_cycle_counter_get() increments pfdev->cycle_counter.use_count a
second time without the prior reference having been cleared or released. When
panfrost_perfcnt_hw_disable() is later called, panfrost_cycle_counter_put()
only decrements pfdev->cycle_counter.use_count once, leaving it non-zero and
preventing GPU_CMD_CYCLE_COUNT_STOP from being issued.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261103-panfrost-reset-races-fixes-v2-0-454207b1d4e3@collabora.com?part=1
next prev parent reply other threads:[~2026-11-03 20:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 20:36 [PATCH v2 0/2] Two small perfcnt fixes for Panfrost Adrián Larumbe
2026-11-03 20:36 ` [PATCH v2 1/2] drm/panfrost: Enable cycle counting when perfcnt is enabled Adrián Larumbe
2026-11-03 20:46 ` sashiko-bot [this message]
2026-11-04 16:51 ` Steven Price
2026-11-03 20:36 ` [PATCH v2 2/2] drm/panfrost: Fix race when restoring reset state in perfcnt Adrián Larumbe
2026-11-04 16:51 ` Steven Price
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-196011@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.