From: Boris Brezillon <boris.brezillon@collabora.com>
To: Steven Price <steven.price@arm.com>
Cc: "Liviu Dudau" <liviu.dudau@arm.com>,
"Adrián Larumbe" <adrian.larumbe@collabora.com>,
dri-devel@lists.freedesktop.org,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Akash Goel" <akash.goel@arm.com>,
"Rob Clark" <robin.clark@oss.qualcomm.com>,
"Sean Paul" <sean@poorly.run>,
"Konrad Dybcio" <konradybcio@kernel.org>,
"Akhil P Oommen" <akhilpo@oss.qualcomm.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"Dmitry Osipenko" <dmitry.osipenko@collabora.com>,
"Chris Diamand" <chris.diamand@arm.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Matthew Brost" <matthew.brost@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Alice Ryhl" <aliceryhl@google.com>,
kernel@collabora.com
Subject: Re: [PATCH v1 5/9] drm/panthor: Part ways with drm_gem_shmem_object
Date: Mon, 12 Jan 2026 17:45:07 +0100 [thread overview]
Message-ID: <20260112174507.1ef006b9@fedora> (raw)
In-Reply-To: <00c89251-5d2e-4a50-a99b-cf09cde85264@arm.com>
On Mon, 12 Jan 2026 16:03:18 +0000
Steven Price <steven.price@arm.com> wrote:
> On 12/01/2026 14:17, Boris Brezillon wrote:
> > On Mon, 12 Jan 2026 12:06:17 +0000
> > Steven Price <steven.price@arm.com> wrote:
> >
> >> On 09/01/2026 13:07, Boris Brezillon wrote:
> >>> While drm_gem_shmem_object does most of the job we need it to do, the
> >>> way sub-resources (pages, sgt, vmap) are handled and their lifetimes
> >>> gets in the way of BO reclaim. There has been attempts to address
> >>> that [1], but in the meantime, new gem_shmem users were introduced
> >>> (accel drivers), and some of them manually free some of these resources.
> >>> This makes things harder to control/sanitize/validate.
> >>>
> >>> Thomas Zimmerman is not a huge fan of enforcing lifetimes of sub-resources
> >>> and forcing gem_shmem users to go through new gem_shmem helpers when they
> >>> need manual control of some sort, and I believe this is a dead end if
> >>> we don't force users to follow some stricter rules through carefully
> >>> designed helpers, because there will always be one user doing crazy things
> >>> with gem_shmem_object internals, which ends up tripping out the common
> >>> helpers when they are called.
> >>>
> >>> The consensus we reached was that we would be better off forking
> >>> gem_shmem in panthor. So here we are, parting ways with gem_shmem. The
> >>> current transition tries to minimize the changes, but there are still
> >>> some aspects that are different, the main one being that we no longer
> >>> have a pages_use_count, and pages stays around until the GEM object is
> >>> destroyed (or when evicted once we've added a shrinker). The sgt also
> >>> no longer retains pages. This is losely based on how msm does things by
> >>> the way.
> >>
> >> From a reviewing perspective it's a little tricky trying to match up the
> >> implementation to shmem because of these changes. I don't know how
> >> difficult it would be to split the changes to a patch which literally
> >> copies (with renames) from shmem, followed by simplifying out the parts
> >> we don't want.
> >
> > It's a bit annoying as the new implementation is not based on shmem at
> > all, but if you think it helps the review, I can try what you're
> > suggesting. I mean, I'm not convinced it will be significantly easier
> > to review with this extra step, since the new logic is different enough
> > (especially when it comes to resource refcounting) that it needs a
> > careful review anyway (which you started doing here).
>
> I wasn't sure how much you had originally based it on shmem. I noticed
> some comments were copied over and in some places it was easy to match
> up. But in others it's much less clear.
>
> If you haven't actually started from a direct copy of shmem then it's
> probably not going to be much clearer doing that as an extra step. It's
> just in places it looked like you had.
The reason both look similar has more to do with the fact they both
use shmem for their memory allocation than one being a copy of the
other. That's not to say I didn't pick bits and pieces here and there
(including comments), but it didn't start as a full copy followed by
incremental modifications.
> >>
> >>> + }
> >>> +
> >>> + return 0;
> >>> +}
> >>> +
> >>> +static int panthor_gem_backing_pin_locked(struct panthor_gem_object *bo)
> >>> +{
> >>> + int ret;
> >>> +
> >>> + dma_resv_assert_held(bo->base.resv);
> >>> + drm_WARN_ON_ONCE(bo->base.dev, drm_gem_is_imported(&bo->base));
> >>> +
> >>> + if (refcount_inc_not_zero(&bo->backing.pin_count))
> >>> + return 0;
> >>> +
> >>> + ret = panthor_gem_backing_get_pages_locked(bo);
> >>> + if (!ret)
> >>> + refcount_set(&bo->backing.pin_count, 1);
> >>> +
> >>> + return ret;
> >>> +}
> >>> +
> >>> +static void panthor_gem_backing_unpin_locked(struct panthor_gem_object *bo)
> >>> +{
> >>> + dma_resv_assert_held(bo->base.resv);
> >>> + drm_WARN_ON_ONCE(bo->base.dev, drm_gem_is_imported(&bo->base));
> >>> +
> >>> + /* We don't release anything when pin_count drops to zero.
> >>> + * Pages stay there until an explicit cleanup is requested.
> >>> + */
> >>> + if (!refcount_dec_not_one(&bo->backing.pin_count))
> >>> + refcount_set(&bo->backing.pin_count, 0);
> >>
> >> Why not just refcount_dec()?
> >
> > Because refcount_dec() complains when it's passed a value that's less
> > than 2. The rational being that you need to do something special
> > (release resources) when you reach zero. In our case we don't, because
> > pages are lazily reclaimed, so we just set the counter back to zero.
>
> Ah, yes I'd misread the "old <= 1" check as "old < 1". Hmm, I dislike it
> because it's breaking the atomicity - if another thread does a increment
> between the two operations then we lose a reference count.
I don't think we do, because any 0 <-> 1 transition needs to happen
with the resv lock held (see the dma_resv_assert_held() in both
panthor_gem_backing_unpin_locked() and
panthor_gem_backing_pin_locked()).
>
> It does make me think that perhaps the refcount APIs are not designed
> for this case and perhaps we should just use atomics directly.
It's the lazy/deferred put_pages() that makes it look weird I think,
but for the rest, refcount_t looks like the right tool (!locked variants
and even _pin_locked() look sane).
next prev parent reply other threads:[~2026-01-12 16:45 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-09 13:07 [PATCH v1 0/9] drm/panthor: Add a GEM shrinker Boris Brezillon
2026-01-09 13:07 ` [PATCH v1 1/9] drm/gem: Consider GEM object reclaimable if shrinking fails Boris Brezillon
2026-01-12 9:25 ` Alice Ryhl
2026-01-12 10:02 ` Boris Brezillon
2026-01-15 13:28 ` Liviu Dudau
2026-01-09 13:07 ` [PATCH v1 2/9] drm/gpuvm: Validate BOs in the extobj list when VM is resv protected Boris Brezillon
2026-01-09 19:38 ` Danilo Krummrich
2026-01-12 7:30 ` Boris Brezillon
2026-01-09 13:07 ` [PATCH v1 3/9] drm/panthor: Move panthor_gems_debugfs_init() to panthor_gem.c Boris Brezillon
2026-01-12 11:27 ` Steven Price
2026-01-15 13:39 ` Liviu Dudau
2026-01-09 13:07 ` [PATCH v1 4/9] drm/panthor: Group panthor_kernel_bo_xxx() helpers Boris Brezillon
2026-01-12 11:29 ` Steven Price
2026-01-15 13:41 ` Liviu Dudau
2026-01-09 13:07 ` [PATCH v1 5/9] drm/panthor: Part ways with drm_gem_shmem_object Boris Brezillon
2026-01-12 12:06 ` Steven Price
2026-01-12 14:17 ` Boris Brezillon
2026-01-12 16:03 ` Steven Price
2026-01-12 16:45 ` Boris Brezillon [this message]
2026-01-21 11:11 ` Akash Goel
2026-01-21 15:17 ` Boris Brezillon
2026-01-15 16:51 ` Liviu Dudau
2026-01-15 17:27 ` Boris Brezillon
2026-01-15 17:45 ` Liviu Dudau
2026-01-16 12:09 ` Steven Price
2026-01-09 13:07 ` [PATCH v1 6/9] drm/panthor: Lazily allocate pages on mmap() Boris Brezillon
2026-01-12 12:15 ` Steven Price
2026-01-12 14:32 ` Boris Brezillon
2026-01-12 16:41 ` Steven Price
2026-01-12 16:50 ` Boris Brezillon
2026-01-15 17:34 ` Liviu Dudau
2026-01-15 19:27 ` Boris Brezillon
2026-01-16 8:19 ` kernel test robot
2026-01-09 13:07 ` [PATCH v1 7/9] drm/panthor: Split panthor_vm_prepare_map_op_ctx() to prepare for reclaim Boris Brezillon
2026-01-12 12:21 ` Steven Price
2026-01-15 17:40 ` Liviu Dudau
2026-01-09 13:08 ` [PATCH v1 8/9] drm/panthor: Track the number of mmap on a BO Boris Brezillon
2026-01-12 12:33 ` Steven Price
2026-01-12 14:39 ` Boris Brezillon
2026-01-12 15:19 ` Alice Ryhl
2026-01-12 15:49 ` Boris Brezillon
2026-01-12 15:51 ` Alice Ryhl
2026-01-12 16:06 ` Boris Brezillon
2026-01-12 16:49 ` Steven Price
2026-01-12 16:59 ` Boris Brezillon
2026-01-12 17:10 ` Steven Price
2026-01-12 17:18 ` Boris Brezillon
2026-01-13 12:26 ` Boris Brezillon
2026-01-09 13:08 ` [PATCH v1 9/9] drm/panthor: Add a GEM shrinker Boris Brezillon
2026-01-14 15:05 ` Steven Price
2026-01-15 10:50 ` Boris Brezillon
2026-01-15 11:24 ` Steven Price
2026-01-15 12:01 ` Boris Brezillon
2026-01-15 13:56 ` Akash Goel
2026-01-15 14:36 ` Boris Brezillon
2026-01-15 14:37 ` Boris Brezillon
2026-01-21 11:49 ` Akash Goel
2026-01-21 14:52 ` Boris Brezillon
2026-01-28 11:21 ` Akash Goel
2026-01-28 15:52 ` Boris Brezillon
2026-01-28 16:26 ` Akash Goel
2026-01-12 8:37 ` [PATCH v1 0/9] " 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=20260112174507.1ef006b9@fedora \
--to=boris.brezillon@collabora.com \
--cc=adrian.larumbe@collabora.com \
--cc=airlied@gmail.com \
--cc=akash.goel@arm.com \
--cc=akhilpo@oss.qualcomm.com \
--cc=aliceryhl@google.com \
--cc=chris.diamand@arm.com \
--cc=dakr@kernel.org \
--cc=dmitry.osipenko@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel@collabora.com \
--cc=konradybcio@kernel.org \
--cc=liviu.dudau@arm.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.brost@intel.com \
--cc=mripard@kernel.org \
--cc=robin.clark@oss.qualcomm.com \
--cc=sean@poorly.run \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.