From: Alice Ryhl <aliceryhl@google.com>
To: Boris Brezillon <boris.brezillon@collabora.com>
Cc: "Danilo Krummrich" <dakr@kernel.org>,
"Matthew Brost" <matthew.brost@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.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>,
"Steven Price" <steven.price@arm.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Liviu Dudau" <liviu.dudau@arm.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v3 1/2] drm/gpuvm: add deferred vm_bo cleanup
Date: Mon, 6 Oct 2025 13:49:52 +0200 [thread overview]
Message-ID: <CAH5fLghbbybzaQx0kwoEU9aCew8RAMyzVcO7JXytWPUseHvHaA@mail.gmail.com> (raw)
In-Reply-To: <20251006134108.6a5cdcb7@fedora>
On Mon, Oct 6, 2025 at 1:41 PM Boris Brezillon
<boris.brezillon@collabora.com> wrote:
>
> On Mon, 6 Oct 2025 13:31:51 +0200
> Alice Ryhl <aliceryhl@google.com> wrote:
>
> > On Wed, Oct 1, 2025 at 5:13 PM Boris Brezillon
> > <boris.brezillon@collabora.com> wrote:
> > >
> > > On Wed, 1 Oct 2025 16:42:35 +0200
> > > Alice Ryhl <aliceryhl@google.com> wrote:
> > >
> > > > On Wed, Oct 1, 2025 at 4:01 PM Danilo Krummrich <dakr@kernel.org> wrote:
> > > > >
> > > > > On Wed Oct 1, 2025 at 12:41 PM CEST, Alice Ryhl wrote:
> > > > > > +/*
> > > > > > + * Must be called with GEM mutex held. After releasing GEM mutex,
> > > > > > + * drm_gpuvm_bo_defer_free_unlocked() must be called.
> > > > > > + */
> > > > > > +static void
> > > > > > +drm_gpuvm_bo_defer_free_locked(struct kref *kref)
> > > > > > +{
> > > > > > + struct drm_gpuvm_bo *vm_bo = container_of(kref, struct drm_gpuvm_bo,
> > > > > > + kref);
> > > > > > + struct drm_gpuvm *gpuvm = vm_bo->vm;
> > > > > > +
> > > > > > + if (!drm_gpuvm_resv_protected(gpuvm)) {
> > > > > > + drm_gpuvm_bo_list_del(vm_bo, extobj, true);
> > > > > > + drm_gpuvm_bo_list_del(vm_bo, evict, true);
> > > > > > + }
> > > > > > +
> > > > > > + list_del(&vm_bo->list.entry.gem);
> > > > > > +}
> > > > > > +
> > > > > > +/*
> > > > > > + * GEM mutex must not be held. Called after drm_gpuvm_bo_defer_free_locked().
> > > > > > + */
> > > > > > +static void
> > > > > > +drm_gpuvm_bo_defer_free_unlocked(struct drm_gpuvm_bo *vm_bo)
> > > > > > +{
> > > > > > + struct drm_gpuvm *gpuvm = vm_bo->vm;
> > > > > > +
> > > > > > + llist_add(&vm_bo->list.entry.bo_defer, &gpuvm->bo_defer);
> > > > > > +}
> > > > > > +
> > > > > > +static void
> > > > > > +drm_gpuvm_bo_defer_free(struct kref *kref)
> > > > > > +{
> > > > > > + struct drm_gpuvm_bo *vm_bo = container_of(kref, struct drm_gpuvm_bo,
> > > > > > + kref);
> > > > > > +
> > > > > > + mutex_lock(&vm_bo->obj->gpuva.lock);
> > > > > > + drm_gpuvm_bo_defer_free_locked(kref);
> > > > > > + mutex_unlock(&vm_bo->obj->gpuva.lock);
> > > > > > +
> > > > > > + /*
> > > > > > + * It's important that the GEM stays alive for the duration in which we
> > > > > > + * hold the mutex, but the instant we add the vm_bo to bo_defer,
> > > > > > + * another thread might call drm_gpuvm_bo_deferred_cleanup() and put
> > > > > > + * the GEM. Therefore, to avoid kfreeing a mutex we are holding, we add
> > > > > > + * the vm_bo to bo_defer *after* releasing the GEM's mutex.
> > > > > > + */
> > > > > > + drm_gpuvm_bo_defer_free_unlocked(vm_bo);
> > > > > > +}
> > > > >
> > > > > So, you're splitting drm_gpuvm_bo_defer_free() into two functions, one doing the
> > > > > work that is required to be called with the gpuva lock held and one that does
> > > > > the work that does not require a lock, which makes perfect sense.
> > > > >
> > > > > However, the naming chosen for the two functions, i.e.
> > > > > drm_gpuvm_bo_defer_free_unlocked() and drm_gpuvm_bo_defer_free_locked() is
> > > > > confusing:
> > > > >
> > > > > What you mean semantically mean is "do part 1 with lock held" and "do part 2
> > > > > without lock held", but the the chosen names suggest that both functions are
> > > > > identical, with the only difference that one takes the lock internally and the
> > > > > other one requires the caller to take the lock.
> > > > >
> > > > > It's probably better to name them after what they do and not what they're part
> > > > > of. If you prefer the latter, that's fine with me too, but please choose a name
> > > > > that makes this circumstance obvious.
> > > >
> > > > Fair point. Do you have naming suggestions? Otherwise I can name them
> > > > drm_gpuvm_bo_defer_free_part1() and drm_gpuvm_bo_defer_free_part2().
> > > > :)
> > >
> > > drm_gpuvm_bo_free_deferral_extract_locked() and
> > > drm_gpuvm_bo_free_deferral_enqueue()? Definitely not short names though.
> >
> > With those names I have to do some additional line breaks. How about:
> >
> > drm_gpuvm_bo_into_zombie()
> > drm_gpuvm_bo_defer_zombie()
>
> Sounds good. I think I'd prefer if the second one was called
> drm_gpuvm_bo_defer_zombie_cleanup() to make clear what the deferral is
> about, but feel free to ignore this if you think it's too long.
Sounds good. It's more the first one that I want to keep short because
it's used with kref_put().
Alice
next prev parent reply other threads:[~2025-10-06 11:50 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-01 10:41 [PATCH v3 0/2] Defer vm_bo cleanup in GPUVM with DRM_GPUVM_IMMEDIATE_MODE Alice Ryhl
2025-10-01 10:41 ` [PATCH v3 1/2] drm/gpuvm: add deferred vm_bo cleanup Alice Ryhl
2025-10-01 11:27 ` Boris Brezillon
2025-10-01 11:45 ` Alice Ryhl
2025-10-01 12:04 ` Boris Brezillon
2025-10-01 12:13 ` Boris Brezillon
2025-10-01 12:22 ` Alice Ryhl
2025-10-01 13:01 ` Boris Brezillon
2025-10-01 14:01 ` Danilo Krummrich
2025-10-01 14:42 ` Alice Ryhl
2025-10-01 15:13 ` Boris Brezillon
2025-10-06 11:31 ` Alice Ryhl
2025-10-06 11:41 ` Boris Brezillon
2025-10-06 11:49 ` Alice Ryhl [this message]
2025-10-06 11:30 ` Alice Ryhl
2025-10-06 11:38 ` Boris Brezillon
2025-10-01 10:41 ` [PATCH v3 2/2] panthor: use drm_gpuva_unlink_defer() Alice Ryhl
2025-10-01 11:31 ` 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=CAH5fLghbbybzaQx0kwoEU9aCew8RAMyzVcO7JXytWPUseHvHaA@mail.gmail.com \
--to=aliceryhl@google.com \
--cc=airlied@gmail.com \
--cc=boris.brezillon@collabora.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.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=matthew.brost@intel.com \
--cc=mripard@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=steven.price@arm.com \
--cc=thomas.hellstrom@linux.intel.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;
as well as URLs for NNTP newsgroup(s).