From: sashiko-bot@kernel.org
To: "Lukas Zapolskas" <lukas.zapolskas@arm.com>
Cc: dri-devel@lists.freedesktop.org, ojeda@kernel.org, gary@garyguo.net
Subject: Re: [PATCH v8 3/3] drm/panthor: Expose performance counter queries and ioctls
Date: Thu, 26 Nov 2026 21:16:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-236225@kernel.org> (raw)
In-Reply-To: <20261126-panthor-performance-counters-v8-3-6e7db0ec33f5@arm.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/panthor: infinite busy-loop in
panthor_perf_handle_fw_events()
- [Medium] drm/panthor: race between panthor_perf_pool_destroy() and
unplug
- [Medium] drm/panthor: PRFCNT_EN overwrite in
panthor_perf_handle_fw_samples()
--
commit b28f9d76443cda266099b6a812924734c3213c0a
Author: Lukas Zapolskas <lukas.zapolskas@arm.com>
drm/panthor: Expose performance counter queries and ioctls
This commit exposes the DRM_PANTHOR_DEV_QUERY_PERF_INFO device query and the
five performance counter session ioctls, and wraps the session ioctls with a
drm_dev_enter()/drm_dev_exit() cleanup class.
> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
> index 09cc3f699154a..e6e708d9e18f0 100644
> --- a/drivers/gpu/drm/panthor/panthor_drv.c
> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
[ ... ]
> @@ -1590,6 +1599,110 @@ static int panthor_ioctl_bo_query_info(struct drm_device *ddev, void *data,
> return 0;
> }
>
> +static int panthor_drm_dev_enter(struct drm_device *ddev)
> +{
> + int cookie;
> +
> + if (!drm_dev_enter(ddev, &cookie))
> + return -ENODEV;
> +
> + return cookie;
> +}
> +
> +static void panthor_drm_dev_exit(int cookie)
> +{
> + if (cookie >= 0)
> + drm_dev_exit(cookie);
> +}
> +
> +DEFINE_CLASS(panthor_drm_dev, int, panthor_drm_dev_exit(_T),
> + panthor_drm_dev_enter(ddev), struct drm_device *ddev)
> +
> +static int panthor_ioctl_perf_session_create(struct drm_device *ddev, void *data,
> + struct drm_file *file)
> +{
> + int ret;
> + unsigned long sid = 0;
> + struct drm_panthor_perf_session_create *args = data;
> +
> + CLASS(panthor_drm_dev, cookie)(ddev);
> + if (cookie < 0)
> + return cookie;
> +
> + if (args->pad)
> + return -EINVAL;
> +
> + ret = panthor_perf_session_create(file, args, &sid);
> + if (ret)
> + return ret;
> +
> + return sid;
> +}
[Severity: Medium]
Once panthor_ioctl_perf_session_create() registers a session in
pfile->sessions, can closing the DRM file race with panthor_device_unplug()
and cause a use-after-free or NULL pointer dereference in
panthor_perf_pool_destroy()?
The session ioctls guard against device unplug with panthor_drm_dev, but
panthor_postclose() -> panthor_perf_pool_destroy() does not call
drm_dev_enter(), and panthor_perf_unplug() does not take perf->op_lock:
CPU0 CPU1
panthor_postclose()
panthor_perf_pool_destroy()
perf = pfile->ptdev->perf
panthor_device_unplug()
panthor_fw_unplug()
panthor_perf_unplug()
panthor_kernel_bo_destroy(perf->rb)
perf->rb = NULL
ptdev->perf = NULL
/* destroys fw section BOs */
guard(mutex)(&perf->op_lock)
perf_disable(perf)
panthor_perf_fw_stop_sampling()
/* accesses destroyed glb_iface BO */ <-- use-after-free
perf_enable(perf)
panthor_perf_fw_start_sampling()
panthor_perf_fw_write_config(ptdev->perf)
<-- NULL pointer dereference
> +
> +static int panthor_ioctl_perf_session_start(struct drm_device *ddev, void *data,
> + struct drm_file *file)
> +{
> + struct panthor_file *pfile = file->driver_priv;
> + struct drm_panthor_perf_session_start *args = data;
> +
> + CLASS(panthor_drm_dev, cookie)(ddev);
> + if (cookie < 0)
> + return cookie;
> +
> + if (args->pad0)
> + return -EINVAL;
> +
> + return panthor_perf_session_start(pfile, args->handle, args->user_data);
> +}
[Severity: High]
When a session is active or transitioning while a GPU reset is pending, does
panthor_perf_handle_fw_events() spin in an unthrottled busy-loop on the
WQ_HIGHPRI perf->sample_workq workqueue?
drivers/gpu/drm/panthor/panthor_perf.c:panthor_perf_handle_fw_events() {
...
if (panthor_device_reset_is_pending(ptdev)) {
queue_work(perf->sample_workq, &perf->sample_work);
return;
}
...
}
Because perf->sample_work is a non-delayed work item executing on a
WQ_HIGHPRI | WQ_UNBOUND workqueue, re-queueing it from inside its own handler
while ptdev->reset.pending is set causes it to re-run immediately at high
priority without yielding, starving normal-priority workers such as
ptdev->reset.wq or spinning until resume if reset.pending was left set by an
aborted reset during suspend.
> +
> +static int panthor_ioctl_perf_session_sample(struct drm_device *ddev, void *data,
> + struct drm_file *file)
> +{
> + struct panthor_file *pfile = file->driver_priv;
> + struct drm_panthor_perf_session_sample *args = data;
> +
> + CLASS(panthor_drm_dev, cookie)(ddev);
> + if (cookie < 0)
> + return cookie;
> +
> + if (args->pad0)
> + return -EINVAL;
> +
> + return panthor_perf_session_sample(pfile, args->handle, args->user_data);
> +}
[Severity: Medium]
When panthor_perf_handle_fw_samples() accumulates multiple firmware samples
in one pass (insert_idx - extract_idx > 1), does overwriting
blk->counters[PANTHOR_CTR_PRFCNT_EN] cause session_populate_sample() to leave
unrequested counter values in the user ringbuffer?
drivers/gpu/drm/panthor/panthor_perf.c:panthor_perf_handle_fw_samples() {
...
blk->counters[PANTHOR_CTR_TIMESTAMP_LO] = block[PANTHOR_CTR_TIMESTAMP_LO];
blk->counters[PANTHOR_CTR_TIMESTAMP_HI] = block[PANTHOR_CTR_TIMESTAMP_HI];
blk->counters[PANTHOR_CTR_PRFCNT_EN] = block[PANTHOR_CTR_PRFCNT_EN];
...
if (prfcnt_en == 1)
goto advance_block;
for (size_t k = PANTHOR_HEADER_COUNTERS;
k < ptdev->perf_info.counters_per_block; k++)
blk->counters[k] += block[k];
...
}
The counter values are summed across all samples in [extract_idx, insert_idx),
but PANTHOR_CTR_PRFCNT_EN is overwritten with the last non-zero prfcnt_en
instead of being bitwise-ORed. Because session_populate_sample() copies the
entire accumulated perf_sample into the user-mapped session BO with memcpy()
and only zeroes out unrequested counters that are set in the final
PANTHOR_CTR_PRFCNT_EN mask, any counter group enabled in an earlier sample of
the batch but not the last one is not cleared.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-panthor-performance-counters-v8-0-6e7db0ec33f5@arm.com?part=3
prev parent reply other threads:[~2026-11-26 21:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 20:57 [PATCH v8 0/3] drm/panthor: Performance counter implementation with single manual client support Lukas Zapolskas
2026-11-26 20:57 ` [PATCH v8 1/3] drm/panthor: Add perf setup and session management Lukas Zapolskas
2026-11-26 21:14 ` sashiko-bot
2026-11-27 6:56 ` kernel test robot
2026-11-28 15:33 ` kernel test robot
2026-11-26 20:57 ` [PATCH v8 2/3] drm/panthor: Implement performance counter firmware sampling Lukas Zapolskas
2026-11-26 21:31 ` sashiko-bot
2026-11-28 18:17 ` kernel test robot
2026-11-26 20:57 ` [PATCH v8 3/3] drm/panthor: Expose performance counter queries and ioctls Lukas Zapolskas
2026-11-26 21:16 ` sashiko-bot [this message]
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-236225@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=lukas.zapolskas@arm.com \
--cc=ojeda@kernel.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.