From: Boris Brezillon <boris.brezillon@collabora.com>
To: Adrian Larumbe <adrian.larumbe@collabora.com>
Cc: Steven Price <steven.price@arm.com>,
Liviu Dudau <liviu.dudau@arm.com>,
Chris Diamand <chris.diamand@arm.com>,
Akash Goel <akash.goel@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>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 08/18] drm/panthor: Split panthor_vm
Date: Fri, 11 Sep 2026 11:48:37 +0200 [thread overview]
Message-ID: <20260911114837.23e28e6b@fedora-21.home> (raw)
In-Reply-To: <aqK1DzIYzFLVz3od@sobremesa>
On Fri, 11 Sep 2026 04:37:48 +0100
Adrian Larumbe <adrian.larumbe@collabora.com> wrote:
> On 26.08.2026 16:56, Boris Brezillon wrote:
> > The way things are currently defined makes the cleanup procedure harder
> > because the panthor_vm object cleanup happens after drm_gpuvm_fini() has
> > been called, and sometimes we need a drm_gpuvm to undo things.
> > This has been worked around by things like the panthor_vm_unmap_range()
> > call in panthor_vm_destroy(), but there are still situations where this
> > is problematic, like the show_each_vm() where we walk a list of VM and
> > call drm_debugfs_gpuva_info() on each, with the risk of hitting an object
> > that had drm_gpuvm_fini() called on it already.
>
> I think you haven't changed show_each_vm() in the whole series. Inside show_vm_gpuvas(),
> it keeps accessing struct panthor_as from its unique reference in a struct panthor_vm,
> but I thought the main goal of this commit was ensuring you can still access panthor_as's
> when the referencing VM's have been released.
The goal of this series is to not be able to access a panthor_as whose
underlying drm_gpuvm object has been destroyed. This is addressed by
having panthor_vm own a panthor_as ref, and given show_each_vm()
operates on the panthor_vm objects in the panthor_mmu::vms list, it
can't happen anymore: either the VM is in the list, and we know for
sure its panthor_vm::as is valid, or it's not in the list (we remove
the vm from the list in panthor_vm_release() before we release the ref
we have on panthor_vm::as in the same function).
> > /**
> > * struct panthor_vm - VM object
> > *
> > * A VM is an object representing a GPU (or MCU) virtual address space.
> > - * It embeds the MMU page table for this address space, a tree containing
> > - * all the virtual mappings of GEM objects, and other things needed to manage
> > - * the VM.
> > *
> > * Except for the MCU VM, which is managed by the kernel, all other VMs are
> > * created by userspace and mostly managed by userspace, using the
> > @@ -243,13 +360,11 @@ struct panthor_vm_op_ctx {
> > * by default).
> > */
> > struct panthor_vm {
> > - /**
> > - * @base: Inherit from drm_gpuvm.
> > - *
> > - * We delegate all the VA management to the common drm_gpuvm framework
> > - * and only implement hooks to update the MMU page table.
> > - */
> > - struct drm_gpuvm base;
> > + /** @refcount: VM refcount. */
> > + struct kref refcount;
> > +
> > + /** @as: VM address space. */
> > + struct panthor_as *as;
>
> Overall although I understand that an AS must be kept around for longer than a panthor_vm to avoid
> UAF after driver unplug, I find panthor_vm keeping a reference to a panthor_as while the latter is
> the true superclass around a generic gpu_vm a bit confusing.
Well, that's more of a naming issue than a relationship issue IMHO.
panthor_vm is actually the user-facing object and does more than just
managing the virtual space (there's the asynchronous VM_BIND queue
in there, which is more a user of the VM than the VM itself).
Similarly, drm_gpuvm is really mostly about page table updates and cache
maintenance operation around it, which is exactly what an AS (in Arm's
naming convention) is.
The problem really is that we're conflating all these VM-related
concepts in our uAPI, which is why I decided to keep panthor_vm for the
user-facing object, and picked a new name (panthor_as) for the internal
object that deals with just the page-table, cache maintenance and AS
residency bits.
> Also, wouldn't this kind of UAF risk
> also affect all the other drivers?
I guess they did it right from day one, and we're the outlier. The point
is, what we do currently is not only cumbersome, it's just wrong. The
vm_unmap_range(ALL) happening in vm_destroy() is a symptom of this
improper relationship between user-facing VM objects, and their
internal representation backed by a drm_gpuvm.
I don't mind changing the names if you have a better suggestion, but
the isolation between what I call VM and AS are needed IMO.
> In the commit message it is claimed that 'This object owns a drm_gpuvm ref' when describing
> a struct panthor_vm. However, it seems that reference, other than in vm/as creation error
> paths, is only put either when the panthor_vm is being released or at BO reclaim time.
>
> I think this makes it look like a reference count is not truly necessary, because it's
> always one.
drm_gpuvm refs are dispatched to all the active mappings that exist
under this VM, so even if panthor_vm itself doesn't need a refcnt
because it's always a 1:1 relationship between AS and VM, other bits in
the VM logic do.
> > @@ -3316,20 +3391,20 @@ panthor_mmu_reclaim_priv_bos(struct panthor_device *ptdev,
> > /* If the VM is still in the temporary list, remove it so we
> > * can proceed with the next VM.
> > */
> > - if (vm == list_first_entry_or_null(&vms, typeof(*vm), reclaim.lru_node)) {
> > - list_del_init(&vm->reclaim.lru_node);
> > + if (as == list_first_entry_or_null(&vms, typeof(*as), reclaim.lru_node)) {
> > + list_del_init(&as->reclaim.lru_node);
> >
> > /* Keep the VM around if there are still things to
> > * reclaim, so we can preserve the LRU order when
> > * re-inserting in ptdev->reclaim.vms at the end.
> > */
> > - if (vm->reclaim.lru.count > 0)
> > - list_add_tail(&vm->reclaim.lru_node, &remaining_vms);
> > + if (as->reclaim.lru.count > 0)
> > + list_add_tail(&as->reclaim.lru_node, &remaining_vms);
> > }
> >
> > mutex_unlock(&ptdev->base.gem_lru_mutex);
> >
> > - panthor_vm_put(vm);
> > + drm_gpuvm_put(&as->base);
>
> Because of my impression that a struct_as->base refcnt is always 1, wouldn't putting it right here
> mean this particular panthor_as will be immediately released?
It's just releasing the ref we acquired earlier in the function through
kref_get_unless_zero(), so that alone proves it's not always 1 or zero
;-). And yes, it might be that the refcnt drops to zero in this path,
which just means that the VM got released while we were considering the
AS for reclaim, and that's fine.
next prev parent reply other threads:[~2026-09-11 9:48 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 14:55 [PATCH v4 00/18] drm/panthor: Fix the unplug logic Boris Brezillon
2026-08-26 14:56 ` [PATCH v4 01/18] drm/panthor: Disable reset work before unplug Boris Brezillon
2026-08-27 13:00 ` Liviu Dudau
2026-09-10 1:12 ` Adrian Larumbe
2026-08-26 14:56 ` [PATCH v4 02/18] drm/panthor: Revisit the reset logic to avoid reset request loss Boris Brezillon
2026-08-27 15:04 ` Liviu Dudau
2026-09-10 1:13 ` Adrian Larumbe
2026-08-26 14:56 ` [PATCH v4 03/18] drm/panthor: Make panthor_device::pm::state non-atomic Boris Brezillon
2026-08-27 15:12 ` Liviu Dudau
2026-09-10 1:13 ` Adrian Larumbe
2026-08-26 14:56 ` [PATCH v4 04/18] drm/panthor: Flush the cleanup_wq in the unplug path Boris Brezillon
2026-08-27 15:14 ` Liviu Dudau
2026-09-10 1:14 ` Adrian Larumbe
2026-08-26 14:56 ` [PATCH v4 05/18] drm/panthor: Make the page table cache and cleanup workqueue device-local Boris Brezillon
2026-08-27 15:20 ` Liviu Dudau
2026-09-10 1:14 ` Adrian Larumbe
2026-08-26 14:56 ` [PATCH v4 06/18] drm/panthor: Drop unused vm argument passed to panthor_vm_prepare_sync_only_op_ctx() Boris Brezillon
2026-08-27 15:21 ` Liviu Dudau
2026-09-10 1:15 ` Adrian Larumbe
2026-08-26 14:56 ` [PATCH v4 07/18] drm/panthor: Move the debugfs initialization to panthor_device.c Boris Brezillon
2026-09-10 1:18 ` Adrian Larumbe
2026-08-26 14:56 ` [PATCH v4 08/18] drm/panthor: Split panthor_vm Boris Brezillon
2026-09-11 3:37 ` Adrian Larumbe
2026-09-11 9:48 ` Boris Brezillon [this message]
2026-09-11 22:55 ` Adrian Larumbe
2026-08-26 14:56 ` [PATCH v4 09/18] drm/panthor: Add fine-grained restrictions on VMs Boris Brezillon
2026-09-11 3:38 ` Adrian Larumbe
2026-08-26 14:56 ` [PATCH v4 10/18] drm/panthor: Check AS state before disabling Boris Brezillon
2026-09-11 3:38 ` Adrian Larumbe
2026-08-26 14:56 ` [PATCH v4 11/18] drm/panthor: Don't pre-allocate VMAs or page tables when preparing a full VM unmap Boris Brezillon
2026-09-11 3:38 ` Adrian Larumbe
2026-08-26 14:56 ` [PATCH v4 12/18] drm/panthor: Let l2_power_off return errors and force users to check it Boris Brezillon
2026-09-11 3:39 ` Adrian Larumbe
2026-08-26 14:56 ` [PATCH v4 13/18] drm/panthor: Complain if the SOFT_RESET fails Boris Brezillon
2026-09-11 3:40 ` Adrian Larumbe
2026-09-11 9:54 ` Boris Brezillon
2026-08-26 14:56 ` [PATCH v4 14/18] drm/panthor: Make the VM cleanup path more robust against UAF Boris Brezillon
2026-09-11 19:15 ` Adrian Larumbe
2026-08-26 14:56 ` [PATCH v4 15/18] drm/panthor: Track user owned VMs Boris Brezillon
2026-09-11 19:17 ` Adrian Larumbe
2026-08-26 14:56 ` [PATCH v4 16/18] drm/panthor: Track user owned groups Boris Brezillon
2026-09-11 19:17 ` Adrian Larumbe
2026-08-26 14:56 ` [PATCH v4 17/18] drm/panthor: Fix the unplug logic Boris Brezillon
2026-09-11 22:44 ` Adrian Larumbe
2026-09-14 7:53 ` Boris Brezillon
2026-08-26 14:56 ` [PATCH v4 18/18] drm/panthor: Add debugfs knobs to simulate reset failures Boris Brezillon
2026-09-11 19:18 ` Adrian Larumbe
2026-09-12 19:27 ` Adrian Larumbe
2026-09-14 8:07 ` Boris Brezillon
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=20260911114837.23e28e6b@fedora-21.home \
--to=boris.brezillon@collabora.com \
--cc=adrian.larumbe@collabora.com \
--cc=airlied@gmail.com \
--cc=akash.goel@arm.com \
--cc=chris.diamand@arm.com \
--cc=dri-devel@lists.freedesktop.org \
--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
all inboxes | Powered by JetHome®