Re: [PATCH v7 5/8] drm/panthor: Introduce sampling sessions to handle userspace clients

From: Steven Price

Date: Mon Nov 23 2026 - 10:11:21 EST


On 11/10/2026 18:36, Lukas Zapolskas wrote:
> To allow for combining the requests from multiple userspace clients,
> an intermediary layer between the HW/FW interfaces and userspace is
> created, containing the information for the counter requests and
> tracking of insert and extract indices. Each session starts inactive
> and must be explicitly activated via PERF_SESSION_START and
> explicitly stopped via PERF_SESSION_STOP. Userspace identifies a
> single client with its session ID and the panthor file it is
> associated with.
>
> The SAMPLE and STOP commands both produce a single sample when called,
> and these samples can be disambiguated via the opaque user data field
> passed in the PERF_SESSION uAPI. If this functionality is not desired,
> these fields can be kept as zero, as the kernel copies this value into
> the corresponding sample without attempting to interpret it.
>
> Currently, only manual sampling sessions are supported, providing
> samples when userspace calls PERF_CONTROL_SAMPLE, and only a single
> session is allowed at a time. Multiple sessions and periodic sampling
> will be enabled in following patches.
>
> No protection is provided against the 32-bit hardware counter
> overflows, so for the moment it is up to userspace to ensure that
> the counters are sampled at a reasonable frequency.
>
> Signed-off-by: Lukas Zapolskas <lukas.zapolskas@xxxxxxx>
> ---
> drivers/gpu/drm/panthor/panthor_perf.c | 657 ++++++++++++++++++++++++++++++++-
> drivers/gpu/drm/panthor/panthor_perf.h | 11 +
> 2 files changed, 664 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_perf.c b/drivers/gpu/drm/panthor/panthor_perf.c
> index ba466e22c50d..76c346981150 100644
> --- a/drivers/gpu/drm/panthor/panthor_perf.c
> +++ b/drivers/gpu/drm/panthor/panthor_perf.c

[...]

> +/**
> + * panthor_perf_session_create - Create a user-visible session.
> + *
> + * @file: DRM file associated with the request.
> + * @create_args: Creation arguments passed in via ioctl.
> + * @sid: Session identifier output.
> + *
> + * Creates a new session associated with the session ID returned. When initialized, the
> + * session must explicitly request sampling to start with a successive call to PERF_SESSION_START.
> + *
> + * Return: 0 on success, negative error code on failure.
> + */
> +int panthor_perf_session_create(struct drm_file *file,
> + struct drm_panthor_perf_session_create *create_args,
> + unsigned long *sid)
> +{
> + struct panthor_file *pfile = file->driver_priv;
> + struct panthor_device *ptdev = pfile->ptdev;
> + struct panthor_perf_bo ringbuffer = {}, control = {};
> + const size_t slots = create_args->sample_slots;
> + struct panthor_perf_pool *pool = pfile->sessions;
> + struct panthor_perf_session *session;
> + struct panthor_perf_enable_masks *em;
> + size_t user_sample_size;
> + u32 session_id;
> + int ret;
> +
> + if (!ptdev->perf)
> + return -EOPNOTSUPP;
> +
> + if (!pool)
> + return -EINVAL;
> +
> + if (!perfmon_capable())
> + return -EACCES;

This requirement isn't mentioned in the uAPI.

I also don't see any validation of "block_set". And I think the check
the padding should be moved here rather than hidden in
panthor_ioctl_perf_session_create().

> +
> + session = kzalloc_obj(*session);
> + if (ZERO_OR_NULL_PTR(session))
> + return -ENOMEM;
> +
> + if (!is_power_of_2(slots)) {
> + drm_err(&ptdev->base,
> + "Number of slots is not power-of-2 aligned\n");
> + ret = -EINVAL;
> + goto cleanup_session;
> + }
> +
> + user_sample_size = ptdev->perf_info.sample_size * slots;

create_args->sample_slots (slots) is user supplied and I believe this
could overflow (on a 32 bit system). Specifically 1 << 31 (as this has
to be power-of-2).

Thanks,
Steve