From: Sam Ravnborg <sam@ravnborg.org>
To: Daniel Vetter <daniel@ffwll.ch>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
Intel Graphics Development <intel-gfx@lists.freedesktop.org>,
DRI Development <dri-devel@lists.freedesktop.org>,
Paul Kocialkowski <paul.kocialkowski@bootlin.com>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Daniel Vetter <daniel.vetter@intel.com>
Subject: Re: [Intel-gfx] [PATCH 02/44] drm: Add devm_drm_dev_alloc macro
Date: Wed, 8 Apr 2020 20:55:53 +0200 [thread overview]
Message-ID: <20200408185552.GA22814@ravnborg.org> (raw)
In-Reply-To: <20200408121147.GL3456981@phenom.ffwll.local>
Hi Daniel.
On Wed, Apr 08, 2020 at 02:11:47PM +0200, Daniel Vetter wrote:
> On Wed, Apr 08, 2020 at 08:57:14AM +0200, Sam Ravnborg wrote:
> > Hi Daniel.
> >
> > Finally managed to dive into this..
> >
> > Maybe I need more coffee, it is still morning here.
> > But alas this patch triggered a few comments.
> >
> > Sam
> >
> > On Fri, Apr 03, 2020 at 03:57:46PM +0200, Daniel Vetter wrote:
> > > The kerneldoc is only added for this new function. Existing kerneldoc
> > > and examples will be udated at the very end, since once all drivers
> > > are converted over to devm_drm_dev_alloc we can unexport a lot of
> > > interim functions and make the documentation for driver authors a lot
> > > cleaner and less confusing. There will be only one true way to
> > > initialize a drm_device at the end of this, which is going to be
> > > devm_drm_dev_alloc.
> >
> > This changelog entry does a poor job describing what the purpose of this
> > change is.
> > Try to read it outside context.
>
> Something like:
>
> Add a new macro helper to combine the usual init sequence in drivers,
> consisting of a kzalloc + devm_drm_dev_init + drmm_add_final_kfree
> triplet. This allows us to remove the rather unsightly
> drmm_add_final_kfree from all currently merged drivers.
Much better - thanks!
>
> This good enough, as an intro paragraph?
>
> >
> >
> > >
> > > Cc: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> > > Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > > ---
> > > drivers/gpu/drm/drm_drv.c | 23 +++++++++++++++++++++++
> > > include/drm/drm_drv.h | 33 +++++++++++++++++++++++++++++++++
> > > 2 files changed, 56 insertions(+)
> > >
> > > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> > > index 1bb4f636b83c..9e60b784b3ac 100644
> > > --- a/drivers/gpu/drm/drm_drv.c
> > > +++ b/drivers/gpu/drm/drm_drv.c
> > > @@ -739,6 +739,29 @@ int devm_drm_dev_init(struct device *parent,
> > > }
> > > EXPORT_SYMBOL(devm_drm_dev_init);
> > >
> > > +void* __devm_drm_dev_alloc(struct device *parent, struct drm_driver *driver,
> > > + size_t size, size_t offset)
> > > +{
> > > + void *container;
> > > + struct drm_device *drm;
> > > + int ret;
> > > +
> > > + container = kzalloc(size, GFP_KERNEL);
> > > + if (!container)
> > > + return ERR_PTR(-ENOMEM);
> > > +
> > > + drm = container + offset;
> > > + ret = devm_drm_dev_init(parent, drm, driver);
> > > + if (ret) {
> > > + kfree(container);
> > > + return ERR_PTR(ret);
> > > + }
> > > + drmm_add_final_kfree(drm, container);
> > > +
> > > + return container;
> > > +}
> > > +EXPORT_SYMBOL(__devm_drm_dev_alloc);
> > > +
> > > /**
> > > * drm_dev_alloc - Allocate new DRM device
> > > * @driver: DRM driver to allocate device for
> > > diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
> > > index e7c6ea261ed1..26776be5a21e 100644
> > > --- a/include/drm/drm_drv.h
> > > +++ b/include/drm/drm_drv.h
> > > @@ -626,6 +626,39 @@ int devm_drm_dev_init(struct device *parent,
> > > struct drm_device *dev,
> > > struct drm_driver *driver);
> > >
> > > +void* __devm_drm_dev_alloc(struct device *parent, struct drm_driver *driver,
> > > + size_t size, size_t offset);
> > > +
> > > +/**
> > > + * devm_drm_dev_alloc - Resource managed allocation of a &drm_device instance
> > > + * @parent: Parent device object
> > > + * @driver: DRM driver
> > > + * @type: the type of the struct which contains struct &drm_device
> > > + * @member: the name of the &drm_device within @type.
> > I am confused about the naming here.
> > devm_ implies we allocate something with a lifetime equal that of a
> > driver. So when the driver are gone what we allocate is also gone.
> > Like everythign else devm_ prefixed.
> >
> > But the lifetime of a drm_device is until the last userspace reference
> > is gone (final drm_dev_put() is called).
>
> The kerneldoc for this is largely copied from the existing
> devm_drm_dev_init. And yes the lifetime is bound to the device, we do the
> drm_dev_put() when that disappears. Now other users of drm_device might
> still hold references and delay cleanup, but "cleanup is done as a devres
> action" is very much what devm_ signifies.
After discussing this on IRC I took one more look at the code.
We have something like this:
devm_drm_dev_alloc()
|
+-> devm_drm_dev_init()
| |
| +-> drm_dev_init()
| | |
| | +- kref_init(&dev->ref)
| | |
| | +- drmm_add_action(drm_dev_init_release)
| |
| +-> devm_add_action(devm_drm_dev_init_release)
|
+-> drmm_add_final_kfree()
drm_dev_init_release() - does all the release stuff
devm_drm_dev_init_release() do a simple drm_dev_put()
In other words we use the devres functionality to keep track of the
reference count for the structure allocated by devm_drm_dev_alloc()
So the naming makes some sense anyway.
When there are no users left of drm_dev_init() outside drm_drv.c this
can be simplified a little.
After re-reading the code it made sense again.
With the updated changelog:
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
PS. There is a few trivial checkpatch warnings to look at before pushing
out.
Sam
> "
> > > + *
> > > + * This allocates and initialize a new DRM device. No device registration is done.
> > > + * Call drm_dev_register() to advertice the device to user space and register it
> > > + * with other core subsystems. This should be done last in the device
> > s/This/Calling drm_dev_register()/ will make this sentence a bit more
> > explicit.
> >
> > > + * initialization sequence to make sure userspace can't access an inconsistent
> > > + * state.
> > > + *
> > > + * The initial ref-count of the object is 1. Use drm_dev_get() and
> > > + * drm_dev_put() to take and drop further ref-counts.
> > > + *
> > > + * It is recommended that drivers embed &struct drm_device into their own device
> > > + * structure.
> > > + *
> > > + * Note that this manages the lifetime of the resulting &drm_device
> > > + * automatically using devres.
> > Hmm, no this is managed by drmres???
>
> Yup, the next sentence explains how. And note that we're already using
> this in the form of devm_drm_dev_init. So not clear what's unclear here
> ...
>
> Thanks for your comments.
> -Daniel
>
>
> >
> >
> > > + * The DRM device initialized with this function is
> > > + * automatically put on driver detach using drm_dev_put().
> > > + *
> > > + * RETURNS:
> > > + * Pointer to new DRM device, or ERR_PTR on failure.
> > > + */
> > > +#define devm_drm_dev_alloc(parent, driver, type, member) \
> > > + ((type *) __devm_drm_dev_alloc(parent, driver, sizeof(type), \
> > > + offsetof(type, member)))
> > > +
> > > struct drm_device *drm_dev_alloc(struct drm_driver *driver,
> > > struct device *parent);
> > > int drm_dev_register(struct drm_device *dev, unsigned long flags);
> > > --
> > > 2.25.1
> > >
> > > _______________________________________________
> > > dri-devel mailing list
> > > dri-devel@lists.freedesktop.org
> > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
>
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2020-04-08 18:56 UTC|newest]
Thread overview: 126+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-03 13:57 [Intel-gfx] [PATCH 00/44] devm_drm_dev_alloc, no more drmm_add_final_kfree Daniel Vetter
2020-04-03 13:57 ` [Intel-gfx] [PATCH 01/44] drivers/base: Always release devres on device_del Daniel Vetter
2020-04-03 14:17 ` Greg Kroah-Hartman
2020-04-03 14:47 ` Daniel Vetter
2020-04-03 14:51 ` Daniel Vetter
2020-04-03 15:01 ` Greg Kroah-Hartman
2020-04-03 15:06 ` Greg Kroah-Hartman
2020-04-03 15:15 ` Daniel Vetter
2020-04-03 15:33 ` Daniel Vetter
2020-04-06 12:32 ` Daniel Vetter
2020-04-06 13:38 ` Greg Kroah-Hartman
2020-04-06 13:55 ` Daniel Vetter
2020-04-28 13:15 ` Daniel Vetter
2020-05-15 12:55 ` Greg Kroah-Hartman
2020-05-15 14:05 ` Daniel Vetter
2020-04-03 13:57 ` [Intel-gfx] [PATCH 02/44] drm: Add devm_drm_dev_alloc macro Daniel Vetter
2020-04-05 10:20 ` Noralf Trønnes
2020-04-06 12:00 ` Laurent Pinchart
2020-04-06 12:18 ` Daniel Vetter
2020-04-08 6:57 ` Sam Ravnborg
2020-04-08 12:11 ` Daniel Vetter
2020-04-08 18:55 ` Sam Ravnborg [this message]
2020-04-03 13:57 ` [Intel-gfx] [PATCH 03/44] drm/device: Deprecate dev_private harder Daniel Vetter
2020-04-08 7:02 ` Sam Ravnborg
2020-04-14 16:43 ` Daniel Vetter
2020-04-03 13:57 ` [Intel-gfx] [PATCH 04/44] drm/vgem: Use devm_drm_dev_alloc Daniel Vetter
2020-04-03 13:57 ` [Intel-gfx] [PATCH 05/44] drm/vkms: " Daniel Vetter
2020-04-03 13:57 ` [Intel-gfx] [PATCH 06/44] drm/vboxvideo: drop DRM_MTRR_WC #define Daniel Vetter
2020-04-08 7:03 ` Sam Ravnborg
2020-04-03 13:57 ` [Intel-gfx] [PATCH 07/44] drm/vboxvideo: Use devm_drm_dev_alloc Daniel Vetter
2020-04-03 13:57 ` [Intel-gfx] [PATCH 08/44] drm/vboxvideo: Stop using drm_device->dev_private Daniel Vetter
2020-04-06 11:56 ` Thomas Zimmermann
2020-04-07 7:24 ` Daniel Vetter
2020-04-08 6:33 ` Thomas Zimmermann
2020-04-08 7:19 ` Sam Ravnborg
2020-04-03 13:57 ` [Intel-gfx] [PATCH 09/44] drm/vboxvidoe: use managed pci functions Daniel Vetter
2020-04-08 7:21 ` Sam Ravnborg
2020-04-14 16:30 ` Daniel Vetter
2020-04-03 13:57 ` [Intel-gfx] [PATCH 10/44] drm/vboxvideo: Use devm_gen_pool_create Daniel Vetter
2020-04-08 7:24 ` Sam Ravnborg
2020-04-03 13:57 ` [Intel-gfx] [PATCH 11/44] drm/v3d: Don't set drm_device->dev_private Daniel Vetter
2020-04-03 17:39 ` Eric Anholt
2020-04-03 13:57 ` [Intel-gfx] [PATCH 12/44] drm/v3d: Use devm_drm_dev_alloc Daniel Vetter
2020-04-03 17:38 ` Eric Anholt
2020-04-03 13:57 ` [Intel-gfx] [PATCH 13/44] drm/v3d: Delete v3d_dev->dev Daniel Vetter
2020-04-03 17:35 ` Eric Anholt
2020-04-03 13:57 ` [Intel-gfx] [PATCH 14/44] drm/v3d: Delete v3d_dev->pdev Daniel Vetter
2020-04-03 17:35 ` Eric Anholt
2020-04-08 7:27 ` Sam Ravnborg
2020-04-08 12:13 ` Daniel Vetter
2020-04-03 13:57 ` [Intel-gfx] [PATCH 15/44] drm/udl: Use demv_drm_dev_alloc Daniel Vetter
2020-04-05 10:18 ` Noralf Trønnes
2020-04-05 13:47 ` Daniel Vetter
2020-04-05 14:46 ` Noralf Trønnes
2020-04-06 12:05 ` Thomas Zimmermann
2020-04-03 13:58 ` [Intel-gfx] [PATCH 16/44] drm/udl: don't set drm_device->dev_private Daniel Vetter
2020-04-06 11:52 ` Thomas Zimmermann
2020-04-08 7:29 ` Sam Ravnborg
2020-04-03 13:58 ` [Intel-gfx] [PATCH 17/44] drm/st7735r: Use devm_drm_dev_alloc Daniel Vetter
2020-04-03 17:00 ` David Lechner
2020-04-03 13:58 ` [Intel-gfx] [PATCH 18/44] drm/st7586: " Daniel Vetter
2020-04-03 17:01 ` David Lechner
2020-04-03 13:58 ` [Intel-gfx] [PATCH 19/44] drm/repaper: " Daniel Vetter
2020-04-05 10:00 ` Noralf Trønnes
2020-04-03 13:58 ` [Intel-gfx] [PATCH 20/44] drm/mi0283qt: " Daniel Vetter
2020-04-05 10:01 ` Noralf Trønnes
2020-04-03 13:58 ` [Intel-gfx] [PATCH 21/44] drm/ili9486: " Daniel Vetter
2020-04-05 10:02 ` Noralf Trønnes
2020-04-03 13:58 ` [Intel-gfx] [PATCH 22/44] drm/ili9341: " Daniel Vetter
2020-04-03 17:02 ` David Lechner
2020-04-03 13:58 ` [Intel-gfx] [PATCH 23/44] drm/ili9225: " Daniel Vetter
2020-04-03 17:02 ` David Lechner
2020-04-03 13:58 ` [Intel-gfx] [PATCH 24/44] drm/hx8357d: " Daniel Vetter
2020-04-03 17:38 ` Eric Anholt
2020-04-03 13:58 ` [Intel-gfx] [PATCH 25/44] drm/gm12u320: " Daniel Vetter
2020-04-03 13:58 ` [Intel-gfx] [PATCH 26/44] drm/gm12u320: Don't use drm_device->dev_private Daniel Vetter
2020-04-03 13:58 ` [Intel-gfx] [PATCH 27/44] drm/tidss: Use devm_drm_dev_alloc Daniel Vetter
2020-04-08 7:52 ` Sam Ravnborg
2020-04-14 9:55 ` Jyri Sarha
2020-04-03 13:58 ` [Intel-gfx] [PATCH 28/44] drm/tidss: Don't use drm_device->dev_private Daniel Vetter
2020-04-08 7:52 ` Sam Ravnborg
2020-04-14 9:55 ` Jyri Sarha
2020-04-03 13:58 ` [Intel-gfx] [PATCH 29/44] drm/tidss: Delete tidss->saved_state Daniel Vetter
2020-04-08 7:53 ` Sam Ravnborg
2020-04-14 9:55 ` Jyri Sarha
2020-04-03 13:58 ` [Intel-gfx] [PATCH 30/44] drm/qxl: Use devm_drm_dev_alloc Daniel Vetter
2020-04-06 6:55 ` Gerd Hoffmann
2020-04-06 12:11 ` Thomas Zimmermann
2020-04-07 7:19 ` Daniel Vetter
2020-04-03 13:58 ` [Intel-gfx] [PATCH 31/44] drm/qxl: Don't use drm_device->dev_private Daniel Vetter
2020-04-06 6:55 ` Gerd Hoffmann
2020-04-03 13:58 ` [Intel-gfx] [PATCH 32/44] drm/mcde: Use devm_drm_dev_alloc Daniel Vetter
2020-04-08 7:57 ` Sam Ravnborg
2020-04-03 13:58 ` [Intel-gfx] [PATCH 33/44] drm/mcde: Don't use drm_device->dev_private Daniel Vetter
2020-04-08 7:58 ` Sam Ravnborg
2020-04-12 0:44 ` Linus Walleij
2020-04-03 13:58 ` [Intel-gfx] [PATCH 34/44] drm/ingenic: Use devm_drm_dev_alloc Daniel Vetter
2020-04-08 7:59 ` Sam Ravnborg
2020-04-03 13:58 ` [Intel-gfx] [PATCH 35/44] drm/ingenic: Don't set drm_device->dev_private Daniel Vetter
2020-04-08 8:00 ` Sam Ravnborg
2020-04-03 13:58 ` [Intel-gfx] [PATCH 36/44] drm/komeda: use devm_drm_dev_alloc Daniel Vetter
2020-04-08 8:40 ` james qian wang (Arm Technology China)
2020-04-08 9:03 ` Daniel Vetter
2020-04-03 13:58 ` [Intel-gfx] [PATCH 37/44] drm/armada: Use devm_drm_dev_alloc Daniel Vetter
2020-04-03 13:58 ` [Intel-gfx] [PATCH 38/44] drm/armada: Don't use drm_device->dev_private Daniel Vetter
2020-04-03 13:58 ` [Intel-gfx] [PATCH 39/44] drm/cirrus: Use devm_drm_dev_alloc Daniel Vetter
2020-04-05 10:04 ` Noralf Trønnes
2020-04-08 8:01 ` Sam Ravnborg
2020-04-03 13:58 ` [Intel-gfx] [PATCH 40/44] drm/cirrus: Don't use drm_device->dev_private Daniel Vetter
2020-04-03 17:40 ` Eric Anholt
2020-04-06 11:58 ` Thomas Zimmermann
2020-04-08 8:04 ` Sam Ravnborg
2020-04-08 8:01 ` Sam Ravnborg
2020-04-03 13:58 ` [Intel-gfx] [PATCH 41/44] drm/i915: Use devm_drm_dev_alloc Daniel Vetter
2020-04-03 13:58 ` [Intel-gfx] [PATCH 42/44] drm/i915/selftest: Create mock_destroy_device Daniel Vetter
2020-04-03 22:31 ` [Intel-gfx] [PATCH] " Daniel Vetter
2020-04-03 13:58 ` [Intel-gfx] [PATCH 43/44] drm/i915/selftests: align more to real device lifetimes Daniel Vetter
2020-04-03 22:31 ` [Intel-gfx] [PATCH] " Daniel Vetter
2020-04-03 13:58 ` [Intel-gfx] [PATCH 44/44] drm/managed: Cleanup of unused functions and polishing docs Daniel Vetter
2020-04-05 10:29 ` Noralf Trønnes
2020-04-03 14:15 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for devm_drm_dev_alloc, no more drmm_add_final_kfree Patchwork
2020-04-03 23:01 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for devm_drm_dev_alloc, no more drmm_add_final_kfree (rev3) Patchwork
2020-04-03 23:26 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2020-04-04 10:39 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
2020-04-08 8:08 ` [Intel-gfx] [PATCH 00/44] devm_drm_dev_alloc, no more drmm_add_final_kfree Sam Ravnborg
2020-04-08 12:15 ` Daniel Vetter
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=20200408185552.GA22814@ravnborg.org \
--to=sam@ravnborg.org \
--cc=daniel.vetter@ffwll.ch \
--cc=daniel.vetter@intel.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=paul.kocialkowski@bootlin.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