From: Boris Brezillon <boris.brezillon@collabora.com>
To: "Adrián Larumbe" <adrian.larumbe@collabora.com>
Cc: Steven Price <steven.price@arm.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>,
kernel@collabora.com, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] drm/panthor: register size of internal objects through fdinfo
Date: Mon, 25 Nov 2024 16:07:58 +0100 [thread overview]
Message-ID: <20241125160758.2e0fa766@collabora.com> (raw)
In-Reply-To: <20241115191426.3101123-1-adrian.larumbe@collabora.com>
Hi Adrian,
On Fri, 15 Nov 2024 19:14:18 +0000
Adrián Larumbe <adrian.larumbe@collabora.com> wrote:
> @@ -71,9 +112,9 @@ void panthor_kernel_bo_destroy(struct panthor_kernel_bo *bo)
> * Return: A valid pointer in case of success, an ERR_PTR() otherwise.
> */
> struct panthor_kernel_bo *
> -panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
> - size_t size, u32 bo_flags, u32 vm_map_flags,
> - u64 gpu_va)
> +panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_file *pfile,
> + struct panthor_vm *vm, size_t size, u32 bo_flags,
> + u32 vm_map_flags, u64 gpu_va)
> {
> struct drm_gem_shmem_object *obj;
> struct panthor_kernel_bo *kbo;
> @@ -116,6 +157,16 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
> bo->exclusive_vm_root_gem = panthor_vm_root_gem(vm);
> drm_gem_object_get(bo->exclusive_vm_root_gem);
> bo->base.base.resv = bo->exclusive_vm_root_gem->resv;
> +
> + INIT_LIST_HEAD(&kbo->private_obj);
> +
> + /* Only FW regions are not bound to an open file */
> + if (pfile) {
> + mutex_lock(&ptdev->private_obj_list_lock);
> + list_add(&kbo->private_obj, &pfile->private_file_list);
> + mutex_unlock(&ptdev->private_obj_list_lock);
I hate the fact we have to take a device lock to insert/remove elements
in the private_file list. I'd rather opt for an idr map (like we have
for public GEM handles), with the pfile owning a ref to the internal
GEMs.
When the kbo needs to be added to the pfile kbo list, you pass a
non-NULL pfile and let panthor_kernel_bo_create() add the entry to the
IDR. In the destroy path, you remove the entry, and reset the
kbo->handle value, to make sure panthor_kernel_bo_destroy() is not
called a second time with a non-NULL pfile. This way your lock can be
moved to panthor_file, and you don't have to worry about UAFs on the
pfile object.
> + }
> +
> return kbo;
>
> err_free_va:
Regards,
Boris
prev parent reply other threads:[~2024-11-25 15:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-15 19:14 [PATCH v2] drm/panthor: register size of internal objects through fdinfo Adrián Larumbe
2024-11-18 3:08 ` kernel test robot
2024-11-25 15:07 ` Boris Brezillon [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=20241125160758.2e0fa766@collabora.com \
--to=boris.brezillon@collabora.com \
--cc=adrian.larumbe@collabora.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=liviu.dudau@arm.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=steven.price@arm.com \
--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