From: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
To: "Boris Brezillon" <boris.brezillon@collabora.com>,
"Liviu Dudau" <liviu.dudau@arm.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Adrián Larumbe" <adrian.larumbe@collabora.com>,
dri-devel@lists.freedesktop.org,
"Lukas Zapolskas" <lukas.zapolskas@arm.com>
Cc: nd@arm.com, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org,
Mihail Atanassov <mihail.atanassov@arm.com>,
Lukas Zapolskas <lukas.zapolskas@arm.com>
Subject: Re: [PATCH v6 4/7] drm/panthor: Introduce sampling sessions to handle userspace clients
Date: Tue, 26 May 2026 18:36:22 +0200 [thread overview]
Message-ID: <qNyBEQ6rTuGUNU0cUjgOqA@collabora.com> (raw)
In-Reply-To: <20251215171453.2506348-5-lukas.zapolskas@arm.com>
Hello,
I know I'm a bit late, but I've found a bug.
On Monday, 15 December 2025 18:14:50 Central European Summer Time 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_CONTROL.START, and
> explicitly stopped via PERF_CONTROL.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_CONTROL 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.
>
> The counter set enum is added to the uapi to clarify the restrictions
> on calling the interface.
>
> Signed-off-by: Lukas Zapolskas <lukas.zapolskas@arm.com>
> ---
> drivers/gpu/drm/panthor/panthor_perf.c | 706 ++++++++++++++++++++++++-
> drivers/gpu/drm/panthor/panthor_perf.h | 16 +
> 2 files changed, 716 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_perf.c b/drivers/gpu/drm/panthor/panthor_perf.c
> index 3a65d6d326e8..cea8f678c4e1 100644
> --- a/drivers/gpu/drm/panthor/panthor_perf.c
> +++ b/drivers/gpu/drm/panthor/panthor_perf.c
> [ ... snip ...]
> +
> +static int session_destroy(struct panthor_perf *perf, struct panthor_perf_session *session)
> +{
> + session_put(session);
> +
> + return 0;
> +}
> +
> +static int session_teardown(struct panthor_perf *perf, struct panthor_perf_session *session)
> +{
> + if (test_bit(PANTHOR_PERF_SESSION_ACTIVE, session->state))
> + return -EINVAL;
> +
> + if (READ_ONCE(session->pending_sample_request) != SAMPLE_TYPE_NONE)
> + return -EBUSY;
> +
> + return session_destroy(perf, session);
> +}
> +
> +/**
> + * panthor_perf_session_teardown - Teardown the session associated with the @sid.
> + * @pfile: Open panthor file.
> + * @perf: Handle to the perf control structure.
> + * @sid: Session identifier.
> + *
> + * Destroys a stopped session where the last sample has been explicitly consumed
> + * or discarded. Active sessions will be ignored.
> + *
> + * Return: 0 on success, negative error code on failure.
> + */
> +int panthor_perf_session_teardown(struct panthor_file *pfile, struct panthor_perf *perf, u32 sid)
> +{
> + int err;
> + struct panthor_perf_session *session;
> +
> + xa_lock(&perf->sessions);
> + session = __xa_erase(&perf->sessions, sid);
This also needs to check for !session. __xa_erase will return NULL
on a bogus `sid`, and the ioctl handler doesn't actually check if
the `sid` userspace passed in is still around.
A simple
if (!session) {
xa_unlock(&perf->sessions);
return -EINVAL;
}
did the trick for me.
Kind regards,
Nicolas Frattaroli
> +
> + if (xa_is_err(session)) {
> + err = xa_err(session);
> + goto restore;
> + }
> +
> + if (session->pfile != pfile) {
> + err = -EINVAL;
> + goto restore;
> + }
> +
> + session_get(session);
> + xa_unlock(&perf->sessions);
> +
> + err = session_teardown(perf, session);
> +
> + session_put(session);
> +
> + return err;
> +
> +restore:
> + __xa_store(&perf->sessions, sid, session, GFP_KERNEL);
> + xa_unlock(&perf->sessions);
> +
> + return err;
> +}
> +
> [... snip ...]
next prev parent reply other threads:[~2026-05-26 16:36 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-15 17:14 [PATCH v6 0/7] Performance counter implementation with single manual client support Lukas Zapolskas
2025-12-15 17:14 ` [PATCH v6 1/7] drm/panthor: Add performance counter uAPI Lukas Zapolskas
2025-12-16 10:59 ` Boris Brezillon
2025-12-16 17:30 ` Boris Brezillon
2026-01-07 15:14 ` Lukas Zapolskas
2025-12-17 14:37 ` Boris Brezillon
2026-01-07 15:13 ` Lukas Zapolskas
2026-01-07 15:32 ` Boris Brezillon
2025-12-22 18:15 ` kernel test robot
2026-01-14 13:06 ` Boris Brezillon
2025-12-15 17:14 ` [PATCH v6 2/7] drm/panthor: Add DEV_QUERY.PERF_INFO handling for Gx10 Lukas Zapolskas
2026-01-14 10:11 ` Boris Brezillon
2025-12-15 17:14 ` [PATCH v6 3/7] drm/panthor: Add panthor perf initialization and termination Lukas Zapolskas
2025-12-18 10:33 ` Boris Brezillon
2025-12-18 10:37 ` Boris Brezillon
2025-12-18 13:30 ` Boris Brezillon
2025-12-15 17:14 ` [PATCH v6 4/7] drm/panthor: Introduce sampling sessions to handle userspace clients Lukas Zapolskas
2026-01-14 12:07 ` Boris Brezillon
2026-05-26 16:36 ` Nicolas Frattaroli [this message]
2025-12-15 17:14 ` [PATCH v6 5/7] drm/panthor: Implement the counter sampler and sample handling Lukas Zapolskas
2025-12-20 14:34 ` kernel test robot
2025-12-21 5:13 ` kernel test robot
2026-01-13 16:19 ` Boris Brezillon
2025-12-15 17:14 ` [PATCH v6 6/7] drm/panthor: Add suspend, resume and reset handling Lukas Zapolskas
2025-12-15 17:14 ` [PATCH v6 7/7] drm/panthor: Expose the panthor perf ioctls Lukas Zapolskas
2026-05-18 17:00 ` Erik Faye-Lund
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=qNyBEQ6rTuGUNU0cUjgOqA@collabora.com \
--to=nicolas.frattaroli@collabora.com \
--cc=adrian.larumbe@collabora.com \
--cc=airlied@gmail.com \
--cc=boris.brezillon@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liviu.dudau@arm.com \
--cc=lukas.zapolskas@arm.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mihail.atanassov@arm.com \
--cc=mripard@kernel.org \
--cc=nd@arm.com \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/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