From: Boris Brezillon <boris.brezillon@collabora.com>
To: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Cc: kernel@collabora.com, "Thomas Zimmermann" <tzimmermann@suse.de>,
"Emma Anholt" <emma@anholt.net>,
"Christian König" <christian.koenig@amd.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
"Maxime Ripard" <mripard@kernel.org>,
"Gurchetan Singh" <gurchetansingh@chromium.org>,
"Melissa Wen" <mwen@igalia.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Steven Price" <steven.price@arm.com>,
virtualization@lists.linux-foundation.org,
"Qiang Yu" <yuq825@gmail.com>
Subject: Re: [PATCH v18 04/26] drm/shmem-helper: Refactor locked/unlocked functions
Date: Wed, 29 Nov 2023 11:57:01 +0100 [thread overview]
Message-ID: <20231129115701.6d672ae3@collabora.com> (raw)
In-Reply-To: <bcc8013d-d107-934f-71fa-98ab2e0275ee@collabora.com>
On Wed, 29 Nov 2023 13:47:21 +0300
Dmitry Osipenko <dmitry.osipenko@collabora.com> wrote:
> On 11/29/23 10:53, Boris Brezillon wrote:
> > On Wed, 29 Nov 2023 01:05:14 +0300
> > Dmitry Osipenko <dmitry.osipenko@collabora.com> wrote:
> >
> >> On 11/28/23 15:37, Boris Brezillon wrote:
> >>> On Tue, 28 Nov 2023 12:14:42 +0100
> >>> Maxime Ripard <mripard@kernel.org> wrote:
> >>>
> >>>> Hi,
> >>>>
> >>>> On Fri, Nov 24, 2023 at 11:59:11AM +0100, Boris Brezillon wrote:
> >>>>> On Fri, 24 Nov 2023 11:40:06 +0100
> >>>>> Maxime Ripard <mripard@kernel.org> wrote:
> >>>>>
> >>>>>> On Mon, Oct 30, 2023 at 02:01:43AM +0300, Dmitry Osipenko wrote:
> >>>>>>> Add locked and remove unlocked postfixes from drm-shmem function names,
> >>>>>>> making names consistent with the drm/gem core code.
> >>>>>>>
> >>>>>>> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
> >>>>>>> Suggested-by: Boris Brezillon <boris.brezillon@collabora.com>
> >>>>>>> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> >>>>>>
> >>>>>> This contradicts my earlier ack on a patch but...
> >>>>>>
> >>>>>>> ---
> >>>>>>> drivers/gpu/drm/drm_gem_shmem_helper.c | 64 +++++++++----------
> >>>>>>> drivers/gpu/drm/lima/lima_gem.c | 8 +--
> >>>>>>> drivers/gpu/drm/panfrost/panfrost_drv.c | 2 +-
> >>>>>>> drivers/gpu/drm/panfrost/panfrost_gem.c | 6 +-
> >>>>>>> .../gpu/drm/panfrost/panfrost_gem_shrinker.c | 2 +-
> >>>>>>> drivers/gpu/drm/panfrost/panfrost_mmu.c | 2 +-
> >>>>>>> drivers/gpu/drm/v3d/v3d_bo.c | 4 +-
> >>>>>>> drivers/gpu/drm/virtio/virtgpu_object.c | 4 +-
> >>>>>>> include/drm/drm_gem_shmem_helper.h | 36 +++++------
> >>>>>>> 9 files changed, 64 insertions(+), 64 deletions(-)
> >>>>>>>
> >>>>>>> diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
> >>>>>>> index 0d61f2b3e213..154585ddae08 100644
> >>>>>>> --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> >>>>>>> +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> >>>>>>> @@ -43,8 +43,8 @@ static const struct drm_gem_object_funcs drm_gem_shmem_funcs = {
> >>>>>>> .pin = drm_gem_shmem_object_pin,
> >>>>>>> .unpin = drm_gem_shmem_object_unpin,
> >>>>>>> .get_sg_table = drm_gem_shmem_object_get_sg_table,
> >>>>>>> - .vmap = drm_gem_shmem_object_vmap,
> >>>>>>> - .vunmap = drm_gem_shmem_object_vunmap,
> >>>>>>> + .vmap = drm_gem_shmem_object_vmap_locked,
> >>>>>>> + .vunmap = drm_gem_shmem_object_vunmap_locked,
> >>>>>>
> >>>>>> While I think we should indeed be consistent with the names, I would
> >>>>>> also expect helpers to get the locking right by default.
> >>>>>
> >>>>> Wait, actually I think this patch does what you suggest already. The
> >>>>> _locked() prefix tells the caller: "you should take care of the locking,
> >>>>> I expect the lock to be held when this is hook/function is called". So
> >>>>> helpers without the _locked() prefix take care of the locking (which I
> >>>>> guess matches your 'helpers get the locking right' expectation), and
> >>>>> those with the _locked() prefix don't.
> >>>>
> >>>> What I meant by "getting the locking right" is indeed a bit ambiguous,
> >>>> sorry. What I'm trying to say I guess is that, in this particular case,
> >>>> I don't think you can expect the vmap implementation to be called with
> >>>> or without the locks held. The doc for that function will say that it's
> >>>> either one or the other, but not both.
> >>>>
> >>>> So helpers should follow what is needed to provide a default vmap/vunmap
> >>>> implementation, including what locking is expected from a vmap/vunmap
> >>>> implementation.
> >>>
> >>> Hm, yeah, I think that's a matter of taste. When locking is often
> >>> deferrable, like it is in DRM, I find it beneficial for funcions and
> >>> function pointers to reflect the locking scheme, rather than relying on
> >>> people properly reading the doc, especially when this is the only
> >>> outlier in the group of drm_gem_object_funcs we already have, and it's
> >>> not event documented at the drm_gem_object_funcs level [1] :P.
> >>>
> >>>>
> >>>> If that means that vmap is always called with the locks taken, then
> >>>> drm_gem_shmem_object_vmap can just assume that it will be called with
> >>>> the locks taken and there's no need to mention it in the name (and you
> >>>> can probably sprinkle a couple of lockdep assertion to make sure the
> >>>> locking is indeed consistent).
> >>>
> >>> Things get very confusing when you end up having drm_gem_shmem helpers
> >>> that are suffixed with _locked() to encode the fact locking is the
> >>> caller's responsibility and no suffix for the
> >>> callee-takes-care-of-the-locking semantics, while other helpers that are
> >>> not suffixed at all actually implement the
> >>> caller-should-take-care-of-the-locking semantics.
> >>>
> >>>>
> >>>>>> I'm not sure how reasonable it is, but I think I'd prefer to turn this
> >>>>>> around and keep the drm_gem_shmem_object_vmap/unmap helpers name, and
> >>>>>> convert whatever function needs to be converted to the unlock suffix so
> >>>>>> we get a consistent naming.
> >>>>>
> >>>>> That would be an _unlocked() prefix if we do it the other way around. I
> >>>>> think the main confusion comes from the names of the hooks in
> >>>>> drm_gem_shmem_funcs. Some of them, like drm_gem_shmem_funcs::v[un]map()
> >>>>> are called with the GEM resv lock held, and locking is handled by the
> >>>>> core, others, like drm_gem_shmem_funcs::[un]pin() are called
> >>>>> without the GEM resv lock held, and locking is deferred to the
> >>>>> implementation. As I said, I don't mind prefixing hooks/helpers with
> >>>>> _unlocked() for those that take care of the locking, and no prefix for
> >>>>> those that expects locks to be held, as long as it's consistent, but I
> >>>>> just wanted to make sure we're on the same page :-).
> >>>>
> >>>> What about _nolock then? It's the same number of characters than
> >>>> _locked, plus it expresses what the function is (not) doing, not what
> >>>> context it's supposed to be called in?
> >>>
> >>> Just did a quick
> >>>
> >>> git grep _nolock drivers/gpu/drm
> >>>
> >>> and it returns zero result, where the _locked/_unlocked pattern seems
> >>> to already be widely used. Not saying we shouldn't change that, but it
> >>> doesn't feel like a change we should do as part of this series.
> >>>
> >>> Regards,
> >>>
> >>> Boris
> >>>
> >>> [1]https://elixir.bootlin.com/linux/v6.7-rc3/source/include/drm/drm_gem.h#L155
> >>
> >> I'm fine with dropping the _locked() postfix from the common GEM helpers
> >> and documenting the locking rule in drm_gem. Thank you all for the
> >> suggestions :)
> >
> > Sorry to disagree, but I think a proper function name/suffix is
> > sometimes worth a few lines of doc. Not saying we should do one or the
> > other, I think we should do both. But when I see a function suffixed
> > _locked, _unlocked or _nolock, I can immediately tell if this function
> > defers the locking to the caller or not, and then go check which lock
> > in the function doc.
> >
> > And the second thing I'm not happy with, is the fact we go back to an
> > inconsistent naming in drm_gem_shmem_helper.c, where some functions
> > deferring the locking to the caller are suffixed _locked and others are
> > not, because ultimately, you need a different name when you expose the
> > two variants...
>
> By the `common GEM helpers` I meant the .vmap drm-shmem common helpers
> used for drm_gem_object_funcs, like was suggested by Maxime. The rest of
> functions will retain the _locked part. Sorry for the confusion :)
Well, even if it's just
s/drm_gem_shmem_v[un]map_locked/drm_gem_shmem_v[un]map/, it's still
inconsistent with the rest of the helpers we have there (_locked suffix
for those deferring the locking to the caller, and no suffix when the
lock is taken by the helper). To be clear, I won't block the patch
because of that, but I still think this is the wrong move...
next prev parent reply other threads:[~2023-11-29 10:57 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-29 23:01 [PATCH v18 00/26] Add generic memory shrinker to VirtIO-GPU and Panfrost DRM drivers Dmitry Osipenko
2023-10-29 23:01 ` [PATCH v18 01/26] drm/gem: Change locked/unlocked postfix of drm_gem_v/unmap() function names Dmitry Osipenko
2023-11-24 10:34 ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 02/26] drm/gem: Add _locked postfix to functions that have unlocked counterpart Dmitry Osipenko
2023-11-24 10:35 ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 03/26] drm/shmem-helper: Make all exported symbols GPL Dmitry Osipenko
2023-11-24 10:36 ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 04/26] drm/shmem-helper: Refactor locked/unlocked functions Dmitry Osipenko
2023-11-24 10:40 ` Maxime Ripard
2023-11-24 10:44 ` Boris Brezillon
2023-11-24 10:59 ` Boris Brezillon
2023-11-28 11:14 ` Maxime Ripard
2023-11-28 12:37 ` Boris Brezillon
2023-11-28 22:05 ` Dmitry Osipenko
2023-11-29 7:53 ` Boris Brezillon
2023-11-29 10:47 ` Dmitry Osipenko
2023-11-29 10:57 ` Boris Brezillon [this message]
2023-11-29 13:09 ` Maxime Ripard
2023-11-29 13:46 ` Boris Brezillon
2023-11-29 15:15 ` Maxime Ripard
2023-11-29 15:47 ` Boris Brezillon
2023-12-04 12:55 ` Maxime Ripard
2023-12-05 11:43 ` Dmitry Osipenko
2023-12-14 18:16 ` Maxime Ripard
2023-12-15 0:42 ` Dmitry Osipenko
2023-10-29 23:01 ` [PATCH v18 05/26] drm/shmem-helper: Remove obsoleted is_iomem test Dmitry Osipenko
2023-11-10 10:08 ` Boris Brezillon
2023-11-24 10:40 ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 06/26] drm/shmem-helper: Add and use pages_pin_count Dmitry Osipenko
2023-11-24 10:41 ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 07/26] drm/shmem-helper: Use refcount_t for pages_use_count Dmitry Osipenko
2023-11-24 10:41 ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 08/26] drm/shmem-helper: Add and use lockless drm_gem_shmem_get_pages() Dmitry Osipenko
2023-11-24 10:47 ` Maxime Ripard
2023-11-24 11:20 ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 09/26] drm/shmem-helper: Switch drm_gem_shmem_vmap/vunmap to use pin/unpin Dmitry Osipenko
2023-11-24 10:48 ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 10/26] drm/shmem-helper: Use refcount_t for vmap_use_count Dmitry Osipenko
2023-11-24 10:48 ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 11/26] drm/shmem-helper: Prepare drm_gem_shmem_free() to shrinker addition Dmitry Osipenko
2023-11-10 10:16 ` Boris Brezillon
2023-11-20 11:02 ` Dmitry Osipenko
2023-11-20 11:19 ` Boris Brezillon
2023-11-20 11:38 ` Dmitry Osipenko
2023-10-29 23:01 ` [PATCH v18 12/26] drm/shmem-helper: Make drm_gem_shmem_get_pages() public Dmitry Osipenko
2023-11-10 10:17 ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 13/26] drm/shmem-helper: Add drm_gem_shmem_put_pages() Dmitry Osipenko
2023-10-29 23:01 ` [PATCH v18 14/26] drm/lima: Explicitly get and put drm-shmem pages Dmitry Osipenko
2023-11-10 10:30 ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 15/26] drm/panfrost: " Dmitry Osipenko
2023-11-10 10:53 ` Boris Brezillon
2023-11-22 22:04 ` Dmitry Osipenko
2023-11-23 9:05 ` Boris Brezillon
2023-11-23 12:24 ` Dmitry Osipenko
2023-11-23 14:33 ` Boris Brezillon
2023-11-23 14:48 ` Boris Brezillon
2023-11-24 9:40 ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 16/26] drm/virtio: " Dmitry Osipenko
2023-11-10 10:59 ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 17/26] drm/v3d: " Dmitry Osipenko
2023-11-10 11:01 ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 18/26] drm/shmem-helper: Change sgt allocation policy Dmitry Osipenko
2023-11-10 11:15 ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 19/26] drm/shmem-helper: Add common memory shrinker Dmitry Osipenko
2023-11-10 14:58 ` Boris Brezillon
2023-11-13 9:35 ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 20/26] drm/shmem-helper: Export drm_gem_shmem_get_pages_sgt_locked() Dmitry Osipenko
2023-10-29 23:02 ` [PATCH v18 21/26] drm/shmem-helper: Optimize unlocked get_pages_sgt() Dmitry Osipenko
2023-11-13 9:49 ` Boris Brezillon
2023-10-29 23:02 ` [PATCH v18 22/26] drm/shmem-helper: Don't free refcounted GEM Dmitry Osipenko
2023-11-13 9:54 ` Boris Brezillon
2023-11-22 22:30 ` Dmitry Osipenko
2023-11-23 9:08 ` Boris Brezillon
2023-11-23 12:36 ` Dmitry Osipenko
2023-10-29 23:02 ` [PATCH v18 23/26] drm/virtio: Pin display framebuffer BO Dmitry Osipenko
2023-10-29 23:02 ` [PATCH v18 24/26] drm/virtio: Attach shmem BOs dynamically Dmitry Osipenko
2023-11-13 9:57 ` Boris Brezillon
2023-11-22 22:37 ` Dmitry Osipenko
2023-11-22 22:41 ` Dmitry Osipenko
2023-10-29 23:02 ` [PATCH v18 25/26] drm/virtio: Support shmem shrinking Dmitry Osipenko
2023-11-03 22:55 ` Gurchetan Singh
2023-11-06 2:02 ` Dmitry Osipenko
2023-10-29 23:02 ` [PATCH v18 26/26] drm/panfrost: Switch to generic memory shrinker Dmitry Osipenko
2023-11-24 10:04 ` 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=20231129115701.6d672ae3@collabora.com \
--to=boris.brezillon@collabora.com \
--cc=christian.koenig@amd.com \
--cc=dmitry.osipenko@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=emma@anholt.net \
--cc=gurchetansingh@chromium.org \
--cc=kernel@collabora.com \
--cc=kraxel@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mripard@kernel.org \
--cc=mwen@igalia.com \
--cc=steven.price@arm.com \
--cc=tzimmermann@suse.de \
--cc=virtualization@lists.linux-foundation.org \
--cc=yuq825@gmail.com \
/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).