mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Erik Faye-Lund <erik.faye-lund@collabora.com>
To: "Lukas Zapolskas" <lukas.zapolskas@arm.com>,
	"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>
Cc: nd@arm.com, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org,
	 Mihail Atanassov <mihail.atanassov@arm.com>
Subject: Re: [PATCH v6 7/7] drm/panthor: Expose the panthor perf ioctls
Date: Mon, 18 May 2026 19:00:28 +0200	[thread overview]
Message-ID: <707cb1b4d1b1957951d50c27eaa920f2da849750.camel@collabora.com> (raw)
In-Reply-To: <20251215171453.2506348-8-lukas.zapolskas@arm.com>

On Mon, 2025-12-15 at 17:14 +0000, Lukas Zapolskas wrote:
> This patch implements the PANTHOR_PERF_CONTROL ioctl series, and
> a PANTHOR_GET_UOBJ wrapper to deal with the backwards and forwards
> compatibility of the uAPI.
> 
> The minor version is bumped to indicate that the feature is now
> supported.
> 
> Signed-off-by: Lukas Zapolskas <lukas.zapolskas@arm.com>
> Reviewed-by: Adrián Larumbe <adrian.larumbe@collabora.com>
> ---
>  drivers/gpu/drm/panthor/panthor_drv.c | 141
> +++++++++++++++++++++++++-
>  1 file changed, 139 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c
> b/drivers/gpu/drm/panthor/panthor_drv.c
> index f9e01c42d237..276c87985422 100644
> --- a/drivers/gpu/drm/panthor/panthor_drv.c
> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
> @@ -33,6 +33,7 @@
>  #include "panthor_gpu.h"
>  #include "panthor_heap.h"
>  #include "panthor_mmu.h"
> +#include "panthor_perf.h"
>  #include "panthor_regs.h"
>  #include "panthor_sched.h"
>  
> @@ -75,6 +76,39 @@ panthor_set_uobj(u64 usr_ptr, u32 usr_size, u32
> min_size, u32 kern_size, const v
>  	return 0;
>  }
>  
> +/**
> + * panthor_get_uobj() - Copy user object to kernel object.
> + * @usr_ptr: Users pointer.
> + * @usr_size: Size of the user object.
> + * @min_size: Minimum size for this object.
> + *
> + * Helper automating user -> kernel object copies.
> + *
> + * Don't use this function directly, use PANTHOR_UOBJ_GET() instead.
> + *
> + * Return: valid pointer on success, an encoded error code
> otherwise.
> + */
> +static void*
> +panthor_get_uobj(u64 usr_ptr, u32 usr_size, u32 min_size, u32
> kern_size)
> +{
> +	int ret;
> +	void *out_alloc __free(kvfree) = NULL;
> +
> +	/* User size shouldn't be smaller than the minimal object
> size. */
> +	if (usr_size < min_size)
> +		return ERR_PTR(-EINVAL);
> +
> +	out_alloc = kvmalloc(min_size, GFP_KERNEL);
> +	if (!out_alloc)
> +		return ERR_PTR(-ENOMEM);
> +
> +	ret = copy_struct_from_user(out_alloc, min_size,
> u64_to_user_ptr(usr_ptr), usr_size);
> +	if (ret)
> +		return ERR_PTR(ret);
> +
> +	return_ptr(out_alloc);
> +}
> +
>  /**
>   * panthor_get_uobj_array() - Copy a user object array into a kernel
> accessible object array.
>   * @in: The object array to copy.
> @@ -179,7 +213,11 @@ panthor_get_uobj_array(const struct
> drm_panthor_obj_array *in, u32 min_stride,
>  		 PANTHOR_UOBJ_DECL(struct drm_panthor_queue_create,
> ringbuf_size), \
>  		 PANTHOR_UOBJ_DECL(struct drm_panthor_vm_bind_op,
> syncs), \
>  		 PANTHOR_UOBJ_DECL(struct drm_panthor_bo_sync_op,
> size), \
> -		 PANTHOR_UOBJ_DECL(struct drm_panthor_perf_info,
> shader_blocks))
> +		 PANTHOR_UOBJ_DECL(struct drm_panthor_perf_info,
> shader_blocks), \
> +		 PANTHOR_UOBJ_DECL(struct
> drm_panthor_perf_cmd_setup, shader_enable_mask), \
> +		 PANTHOR_UOBJ_DECL(struct
> drm_panthor_perf_cmd_start, user_data), \
> +		 PANTHOR_UOBJ_DECL(struct drm_panthor_perf_cmd_stop,
> user_data), \
> +		 PANTHOR_UOBJ_DECL(struct
> drm_panthor_perf_cmd_sample, user_data))
>  
>  /**
>   * PANTHOR_UOBJ_SET() - Copy a kernel object to a user object.
> @@ -194,6 +232,25 @@ panthor_get_uobj_array(const struct
> drm_panthor_obj_array *in, u32 min_stride,
>  			 PANTHOR_UOBJ_MIN_SIZE(_src_obj), \
>  			 sizeof(_src_obj), &(_src_obj))
>  
> +/**
> + * PANTHOR_UOBJ_GET() - Copies a user object from _usr_ptr to a
> kernel accessible _dest_ptr.
> + * @_dest_ptr: Local variable
> + * @_usr_size: Size of the user object.
> + * @_usr_ptr: The pointer of the object in userspace.
> + *
> + * Return: Error code. See panthor_get_uobj().
> + */
> +#define PANTHOR_UOBJ_GET(_dest_ptr, _usr_size, _usr_ptr) \
> +	({ \
> +		typeof(_dest_ptr) _tmp; \
> +		_tmp = panthor_get_uobj(_usr_ptr, _usr_size, \
> +				PANTHOR_UOBJ_MIN_SIZE(_tmp[0]), \
> +				sizeof(_tmp[0])); \
> +		if (!IS_ERR(_tmp)) \
> +			_dest_ptr = _tmp; \
> +		PTR_ERR_OR_ZERO(_tmp); \
> +	})
> +
>  /**
>   * PANTHOR_UOBJ_GET_ARRAY() - Copy a user object array to a kernel
> accessible
>   * object array.
> @@ -1470,6 +1527,83 @@ static int panthor_ioctl_bo_query_info(struct
> drm_device *ddev, void *data,
>  	return 0;
>  }
>  
> +#define perf_cmd(command) \
> +	({ \
> +		struct drm_panthor_perf_cmd_##command
> *command##_args __free(kvfree) = NULL; \
> +		int _ret = PANTHOR_UOBJ_GET(command##_args, args-
> >size, args->pointer); \
> +		if (_ret) \
> +			return _ret; \
> +		return panthor_perf_session_##command(pfile, ptdev-
> >perf, args->handle, \
> +						     
> command##_args->user_data); \
> +	})
> +
> +static int panthor_ioctl_perf_control(struct drm_device *ddev, void
> *data,
> +				      struct drm_file *file)
> +{
> +	struct panthor_device *ptdev = container_of(ddev, struct
> panthor_device, base);
> +	struct panthor_file *pfile = file->driver_priv;
> +	struct drm_panthor_perf_control *args = data;
> +	int ret;
> +
> +	if (!args->pointer) {
> +		switch (args->cmd) {
> +		case DRM_PANTHOR_PERF_COMMAND_SETUP:
> +			args->size = sizeof(struct
> drm_panthor_perf_cmd_setup);
> +			return 0;
> +
> +		case DRM_PANTHOR_PERF_COMMAND_TEARDOWN:
> +			args->size = 0;
> +			return 0;
> +
> +		case DRM_PANTHOR_PERF_COMMAND_START:
> +			args->size = sizeof(struct
> drm_panthor_perf_cmd_start);
> +			return 0;
> +
> +		case DRM_PANTHOR_PERF_COMMAND_STOP:
> +			args->size = sizeof(struct
> drm_panthor_perf_cmd_stop);
> +			return 0;
> +
> +		case DRM_PANTHOR_PERF_COMMAND_SAMPLE:
> +			args->size = sizeof(struct
> drm_panthor_perf_cmd_sample);
> +			return 0;
> +
> +		default:
> +			return -EINVAL;
> +		}
> +	}
> +
> +	switch (args->cmd) {
> +	case DRM_PANTHOR_PERF_COMMAND_SETUP:
> +	{
> +		struct drm_panthor_perf_cmd_setup *setup_args
> __free(kvfree) = NULL;
> +
> +		ret = PANTHOR_UOBJ_GET(setup_args, args->size, args-
> >pointer);
> +		if (ret)
> +			return -EINVAL;
> +
> +		return panthor_perf_session_setup(file, ptdev->perf,
> setup_args);
> +	}
> +	case DRM_PANTHOR_PERF_COMMAND_TEARDOWN:
> +	{
> +		return panthor_perf_session_teardown(pfile, ptdev-
> >perf, args->handle);
> +	}
> +	case DRM_PANTHOR_PERF_COMMAND_START:
> +	{
> +		perf_cmd(start);
> +	}
> +	case DRM_PANTHOR_PERF_COMMAND_STOP:
> +	{
> +		perf_cmd(stop);
> +	}
> +	case DRM_PANTHOR_PERF_COMMAND_SAMPLE:
> +	{
> +		perf_cmd(sample);
> +	}
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +

These IOCTLs needs to be privileged to avoid data leaks across
applications, according to the HW docs. So we should probably check for
CAP_PERFMON somehow. This probably means validating using
perfmon_capable() and returning -EACCES if not. That seems to be what
i915 and XE does.


>  static int
>  panthor_open(struct drm_device *ddev, struct drm_file *file)
>  {
> @@ -1546,6 +1680,7 @@ static const struct drm_ioctl_desc
> panthor_drm_driver_ioctls[] = {
>  	PANTHOR_IOCTL(SET_USER_MMIO_OFFSET, set_user_mmio_offset,
> DRM_RENDER_ALLOW),
>  	PANTHOR_IOCTL(BO_SYNC, bo_sync, DRM_RENDER_ALLOW),
>  	PANTHOR_IOCTL(BO_QUERY_INFO, bo_query_info,
> DRM_RENDER_ALLOW),
> +	PANTHOR_IOCTL(PERF_CONTROL, perf_control, DRM_RENDER_ALLOW),
>  };
>  
>  static int panthor_mmap(struct file *filp, struct vm_area_struct
> *vma)
> @@ -1686,6 +1821,8 @@ static void panthor_debugfs_init(struct
> drm_minor *minor)
>   *       - adds DRM_IOCTL_PANTHOR_BO_SYNC ioctl
>   *       - adds DRM_IOCTL_PANTHOR_BO_QUERY_INFO ioctl
>   *       - adds drm_panthor_gpu_info::selected_coherency
> + * - 1.8 - adds DEV_QUERY_PERF_INFO query
> + *       - adds PERF_CONTROL ioctl
>   */
>  static const struct drm_driver panthor_drm_driver = {
>  	.driver_features = DRIVER_RENDER | DRIVER_GEM |
> DRIVER_SYNCOBJ |
> @@ -1699,7 +1836,7 @@ static const struct drm_driver
> panthor_drm_driver = {
>  	.name = "panthor",
>  	.desc = "Panthor DRM driver",
>  	.major = 1,
> -	.minor = 7,
> +	.minor = 8,
>  
>  	.gem_create_object = panthor_gem_create_object,
>  	.gem_prime_import_sg_table =
> drm_gem_shmem_prime_import_sg_table,

      reply	other threads:[~2026-05-18 17:00 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
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 [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=707cb1b4d1b1957951d50c27eaa920f2da849750.camel@collabora.com \
    --to=erik.faye-lund@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

all inboxes | Powered by JetHome®