* [PATCH v2] drm: Provide a driver hook for drm_dev_release()
@ 2017-01-21 10:48 Chris Wilson
2017-01-21 10:58 ` [PATCH v3] " Chris Wilson
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Chris Wilson @ 2017-01-21 10:48 UTC (permalink / raw)
To: dri-devel; +Cc: Daniel Vetter, intel-gfx, Laurent Pinchart
Some state is coupled into the device lifetime outside of the
load/unload timeframe and requires teardown during final unreference
from drm_dev_release(). For example, dmabufs hold both a device and
module reference and may live longer than expected (i.e. the current
pattern of the driver tearing down its state and then releasing a
reference to the drm device) and yet touch driver private state when
destroyed.
v2: Export drm_dev_fini() and move the responsible for finalizing the
drm_device and freeing it to the release callback. (If no callback is
provided, the core will call drm_dev_fini() and kfree(dev) as before.)
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.c>
---
drivers/gpu/drm/drm_drv.c | 56 +++++++++++++++++++++++++++++++++--------------
include/drm/drm_drv.h | 9 ++++++++
2 files changed, 48 insertions(+), 17 deletions(-)
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 1b11ab628da7..517718e4f6e4 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -553,6 +553,39 @@ int drm_dev_init(struct drm_device *dev,
EXPORT_SYMBOL(drm_dev_init);
/**
+ * drm_dev_fini - Finalize a dead DRM device
+ * @dev: DRM device
+ *
+ * Finalize a dead DRM device. This is the converse to drm_dev_init() and
+ * frees up all state allocated by it. All driver state should be finalized
+ * first. Note that this function does not free the @dev, that is left to the
+ * caller. drm_dev_fini() should only
+ *
+ * The ref-count of @dev must be zero, and drm_dev_fini() should only be called
+ * from a drm_driver->release() callback.
+ */
+void drm_dev_fini(struct drm_device *dev)
+{
+ if (drm_core_check_feature(dev, DRIVER_GEM))
+ drm_gem_destroy(dev);
+
+ drm_legacy_ctxbitmap_cleanup(dev);
+ drm_ht_remove(&dev->map_hash);
+ drm_fs_inode_free(dev->anon_inode);
+
+ drm_minor_free(dev, DRM_MINOR_PRIMARY);
+ drm_minor_free(dev, DRM_MINOR_RENDER);
+ drm_minor_free(dev, DRM_MINOR_CONTROL);
+
+ mutex_destroy(&dev->master_mutex);
+ mutex_destroy(&dev->ctxlist_mutex);
+ mutex_destroy(&dev->filelist_mutex);
+ mutex_destroy(&dev->struct_mutex);
+ kfree(dev->unique);
+}
+EXPORT_SYMBOL(drm_dev_fini);
+
+/**
* drm_dev_alloc - Allocate new DRM device
* @driver: DRM driver to allocate device for
* @parent: Parent device object
@@ -598,23 +631,12 @@ static void drm_dev_release(struct kref *ref)
{
struct drm_device *dev = container_of(ref, struct drm_device, ref);
- if (drm_core_check_feature(dev, DRIVER_GEM))
- drm_gem_destroy(dev);
-
- drm_legacy_ctxbitmap_cleanup(dev);
- drm_ht_remove(&dev->map_hash);
- drm_fs_inode_free(dev->anon_inode);
-
- drm_minor_free(dev, DRM_MINOR_PRIMARY);
- drm_minor_free(dev, DRM_MINOR_RENDER);
- drm_minor_free(dev, DRM_MINOR_CONTROL);
-
- mutex_destroy(&dev->master_mutex);
- mutex_destroy(&dev->ctxlist_mutex);
- mutex_destroy(&dev->filelist_mutex);
- mutex_destroy(&dev->struct_mutex);
- kfree(dev->unique);
- kfree(dev);
+ if (dev->driver->release) {
+ dev->driver->release(dev);
+ } else {
+ drm_dev_fini(dev);
+ kfree(dev);
+ }
}
/**
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index 34ece393c639..dfddd8c15b62 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -103,6 +103,15 @@ struct drm_driver {
*
*/
void (*unload) (struct drm_device *);
+
+ /**
+ * @release:
+ *
+ * Optional callback for destroying device state after the final
+ * reference is released, i.e. the device is being destroyed.
+ */
+ void (*release) (struct drm_device *);
+
int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
int (*dma_quiescent) (struct drm_device *);
int (*context_dtor) (struct drm_device *dev, int context);
--
2.11.0
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3] drm: Provide a driver hook for drm_dev_release()
2017-01-21 10:48 [PATCH v2] drm: Provide a driver hook for drm_dev_release() Chris Wilson
@ 2017-01-21 10:58 ` Chris Wilson
2017-01-21 11:02 ` Noralf Trønnes
2017-01-21 21:21 ` Laurent Pinchart
2017-01-21 12:24 ` ✓ Fi.CI.BAT: success for drm: Provide a driver hook for drm_dev_release() (rev3) Patchwork
2017-01-24 10:47 ` [PATCH v5] drm: Provide a driver hook for drm_dev_release() Chris Wilson
2 siblings, 2 replies; 8+ messages in thread
From: Chris Wilson @ 2017-01-21 10:58 UTC (permalink / raw)
To: dri-devel; +Cc: Daniel Vetter, intel-gfx, Laurent Pinchart
Some state is coupled into the device lifetime outside of the
load/unload timeframe and requires teardown during final unreference
from drm_dev_release(). For example, dmabufs hold both a device and
module reference and may live longer than expected (i.e. the current
pattern of the driver tearing down its state and then releasing a
reference to the drm device) and yet touch driver private state when
destroyed.
v2: Export drm_dev_fini() and move the responsible for finalizing the
drm_device and freeing it to the release callback. (If no callback is
provided, the core will call drm_dev_fini() and kfree(dev) as before.)
v3: Remember to add drm_dev_fini() to drm_drv.h
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
---
drivers/gpu/drm/drm_drv.c | 56 +++++++++++++++++++++++++++++++++--------------
include/drm/drm_drv.h | 11 ++++++++++
2 files changed, 50 insertions(+), 17 deletions(-)
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 1b11ab628da7..517718e4f6e4 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -553,6 +553,39 @@ int drm_dev_init(struct drm_device *dev,
EXPORT_SYMBOL(drm_dev_init);
/**
+ * drm_dev_fini - Finalize a dead DRM device
+ * @dev: DRM device
+ *
+ * Finalize a dead DRM device. This is the converse to drm_dev_init() and
+ * frees up all state allocated by it. All driver state should be finalized
+ * first. Note that this function does not free the @dev, that is left to the
+ * caller. drm_dev_fini() should only
+ *
+ * The ref-count of @dev must be zero, and drm_dev_fini() should only be called
+ * from a drm_driver->release() callback.
+ */
+void drm_dev_fini(struct drm_device *dev)
+{
+ if (drm_core_check_feature(dev, DRIVER_GEM))
+ drm_gem_destroy(dev);
+
+ drm_legacy_ctxbitmap_cleanup(dev);
+ drm_ht_remove(&dev->map_hash);
+ drm_fs_inode_free(dev->anon_inode);
+
+ drm_minor_free(dev, DRM_MINOR_PRIMARY);
+ drm_minor_free(dev, DRM_MINOR_RENDER);
+ drm_minor_free(dev, DRM_MINOR_CONTROL);
+
+ mutex_destroy(&dev->master_mutex);
+ mutex_destroy(&dev->ctxlist_mutex);
+ mutex_destroy(&dev->filelist_mutex);
+ mutex_destroy(&dev->struct_mutex);
+ kfree(dev->unique);
+}
+EXPORT_SYMBOL(drm_dev_fini);
+
+/**
* drm_dev_alloc - Allocate new DRM device
* @driver: DRM driver to allocate device for
* @parent: Parent device object
@@ -598,23 +631,12 @@ static void drm_dev_release(struct kref *ref)
{
struct drm_device *dev = container_of(ref, struct drm_device, ref);
- if (drm_core_check_feature(dev, DRIVER_GEM))
- drm_gem_destroy(dev);
-
- drm_legacy_ctxbitmap_cleanup(dev);
- drm_ht_remove(&dev->map_hash);
- drm_fs_inode_free(dev->anon_inode);
-
- drm_minor_free(dev, DRM_MINOR_PRIMARY);
- drm_minor_free(dev, DRM_MINOR_RENDER);
- drm_minor_free(dev, DRM_MINOR_CONTROL);
-
- mutex_destroy(&dev->master_mutex);
- mutex_destroy(&dev->ctxlist_mutex);
- mutex_destroy(&dev->filelist_mutex);
- mutex_destroy(&dev->struct_mutex);
- kfree(dev->unique);
- kfree(dev);
+ if (dev->driver->release) {
+ dev->driver->release(dev);
+ } else {
+ drm_dev_fini(dev);
+ kfree(dev);
+ }
}
/**
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index 34ece393c639..bc5865ad0bbd 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -103,6 +103,15 @@ struct drm_driver {
*
*/
void (*unload) (struct drm_device *);
+
+ /**
+ * @release:
+ *
+ * Optional callback for destroying device state after the final
+ * reference is released, i.e. the device is being destroyed.
+ */
+ void (*release) (struct drm_device *);
+
int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
int (*dma_quiescent) (struct drm_device *);
int (*context_dtor) (struct drm_device *dev, int context);
@@ -451,6 +460,8 @@ extern unsigned int drm_debug;
int drm_dev_init(struct drm_device *dev,
struct drm_driver *driver,
struct device *parent);
+void drm_dev_fini(struct drm_device *dev);
+
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.11.0
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v3] drm: Provide a driver hook for drm_dev_release()
2017-01-21 10:58 ` [PATCH v3] " Chris Wilson
@ 2017-01-21 11:02 ` Noralf Trønnes
2017-01-21 11:12 ` Chris Wilson
2017-01-21 21:21 ` Laurent Pinchart
1 sibling, 1 reply; 8+ messages in thread
From: Noralf Trønnes @ 2017-01-21 11:02 UTC (permalink / raw)
To: Chris Wilson, dri-devel; +Cc: Daniel Vetter, intel-gfx, Laurent Pinchart
Den 21.01.2017 11:58, skrev Chris Wilson:
> Some state is coupled into the device lifetime outside of the
> load/unload timeframe and requires teardown during final unreference
> from drm_dev_release(). For example, dmabufs hold both a device and
> module reference and may live longer than expected (i.e. the current
> pattern of the driver tearing down its state and then releasing a
> reference to the drm device) and yet touch driver private state when
> destroyed.
>
> v2: Export drm_dev_fini() and move the responsible for finalizing the
> drm_device and freeing it to the release callback. (If no callback is
> provided, the core will call drm_dev_fini() and kfree(dev) as before.)
> v3: Remember to add drm_dev_fini() to drm_drv.h
>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
> drivers/gpu/drm/drm_drv.c | 56 +++++++++++++++++++++++++++++++++--------------
> include/drm/drm_drv.h | 11 ++++++++++
> 2 files changed, 50 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index 1b11ab628da7..517718e4f6e4 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -553,6 +553,39 @@ int drm_dev_init(struct drm_device *dev,
> EXPORT_SYMBOL(drm_dev_init);
>
> /**
> + * drm_dev_fini - Finalize a dead DRM device
> + * @dev: DRM device
> + *
> + * Finalize a dead DRM device. This is the converse to drm_dev_init() and
> + * frees up all state allocated by it. All driver state should be finalized
> + * first. Note that this function does not free the @dev, that is left to the
> + * caller. drm_dev_fini() should only
Looks like the end of the sentence is missing.
Noralf.
> + *
> + * The ref-count of @dev must be zero, and drm_dev_fini() should only be called
> + * from a drm_driver->release() callback.
> + */
> +void drm_dev_fini(struct drm_device *dev)
> +{
> + if (drm_core_check_feature(dev, DRIVER_GEM))
> + drm_gem_destroy(dev);
> +
> + drm_legacy_ctxbitmap_cleanup(dev);
> + drm_ht_remove(&dev->map_hash);
> + drm_fs_inode_free(dev->anon_inode);
> +
> + drm_minor_free(dev, DRM_MINOR_PRIMARY);
> + drm_minor_free(dev, DRM_MINOR_RENDER);
> + drm_minor_free(dev, DRM_MINOR_CONTROL);
> +
> + mutex_destroy(&dev->master_mutex);
> + mutex_destroy(&dev->ctxlist_mutex);
> + mutex_destroy(&dev->filelist_mutex);
> + mutex_destroy(&dev->struct_mutex);
> + kfree(dev->unique);
> +}
> +EXPORT_SYMBOL(drm_dev_fini);
> +
> +/**
> * drm_dev_alloc - Allocate new DRM device
> * @driver: DRM driver to allocate device for
> * @parent: Parent device object
> @@ -598,23 +631,12 @@ static void drm_dev_release(struct kref *ref)
> {
> struct drm_device *dev = container_of(ref, struct drm_device, ref);
>
> - if (drm_core_check_feature(dev, DRIVER_GEM))
> - drm_gem_destroy(dev);
> -
> - drm_legacy_ctxbitmap_cleanup(dev);
> - drm_ht_remove(&dev->map_hash);
> - drm_fs_inode_free(dev->anon_inode);
> -
> - drm_minor_free(dev, DRM_MINOR_PRIMARY);
> - drm_minor_free(dev, DRM_MINOR_RENDER);
> - drm_minor_free(dev, DRM_MINOR_CONTROL);
> -
> - mutex_destroy(&dev->master_mutex);
> - mutex_destroy(&dev->ctxlist_mutex);
> - mutex_destroy(&dev->filelist_mutex);
> - mutex_destroy(&dev->struct_mutex);
> - kfree(dev->unique);
> - kfree(dev);
> + if (dev->driver->release) {
> + dev->driver->release(dev);
> + } else {
> + drm_dev_fini(dev);
> + kfree(dev);
> + }
> }
>
> /**
> diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
> index 34ece393c639..bc5865ad0bbd 100644
> --- a/include/drm/drm_drv.h
> +++ b/include/drm/drm_drv.h
> @@ -103,6 +103,15 @@ struct drm_driver {
> *
> */
> void (*unload) (struct drm_device *);
> +
> + /**
> + * @release:
> + *
> + * Optional callback for destroying device state after the final
> + * reference is released, i.e. the device is being destroyed.
> + */
> + void (*release) (struct drm_device *);
> +
> int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
> int (*dma_quiescent) (struct drm_device *);
> int (*context_dtor) (struct drm_device *dev, int context);
> @@ -451,6 +460,8 @@ extern unsigned int drm_debug;
> int drm_dev_init(struct drm_device *dev,
> struct drm_driver *driver,
> struct device *parent);
> +void drm_dev_fini(struct drm_device *dev);
> +
> struct drm_device *drm_dev_alloc(struct drm_driver *driver,
> struct device *parent);
> int drm_dev_register(struct drm_device *dev, unsigned long flags);
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] drm: Provide a driver hook for drm_dev_release()
2017-01-21 11:02 ` Noralf Trønnes
@ 2017-01-21 11:12 ` Chris Wilson
0 siblings, 0 replies; 8+ messages in thread
From: Chris Wilson @ 2017-01-21 11:12 UTC (permalink / raw)
To: Noralf Trønnes; +Cc: Daniel Vetter, intel-gfx, Laurent Pinchart, dri-devel
On Sat, Jan 21, 2017 at 12:02:03PM +0100, Noralf Trønnes wrote:
>
> Den 21.01.2017 11:58, skrev Chris Wilson:
> >Some state is coupled into the device lifetime outside of the
> >load/unload timeframe and requires teardown during final unreference
> >from drm_dev_release(). For example, dmabufs hold both a device and
> >module reference and may live longer than expected (i.e. the current
> >pattern of the driver tearing down its state and then releasing a
> >reference to the drm device) and yet touch driver private state when
> >destroyed.
> >
> >v2: Export drm_dev_fini() and move the responsible for finalizing the
> >drm_device and freeing it to the release callback. (If no callback is
> >provided, the core will call drm_dev_fini() and kfree(dev) as before.)
> >v3: Remember to add drm_dev_fini() to drm_drv.h
> >
> >Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> >Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> >Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> >---
> > drivers/gpu/drm/drm_drv.c | 56 +++++++++++++++++++++++++++++++++--------------
> > include/drm/drm_drv.h | 11 ++++++++++
> > 2 files changed, 50 insertions(+), 17 deletions(-)
> >
> >diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> >index 1b11ab628da7..517718e4f6e4 100644
> >--- a/drivers/gpu/drm/drm_drv.c
> >+++ b/drivers/gpu/drm/drm_drv.c
> >@@ -553,6 +553,39 @@ int drm_dev_init(struct drm_device *dev,
> > EXPORT_SYMBOL(drm_dev_init);
> > /**
> >+ * drm_dev_fini - Finalize a dead DRM device
> >+ * @dev: DRM device
> >+ *
> >+ * Finalize a dead DRM device. This is the converse to drm_dev_init() and
> >+ * frees up all state allocated by it. All driver state should be finalized
> >+ * first. Note that this function does not free the @dev, that is left to the
> >+ * caller. drm_dev_fini() should only
>
> Looks like the end of the sentence is missing.
Ah, started then moved it to the note about ref-count.
-Chris
--
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* ✓ Fi.CI.BAT: success for drm: Provide a driver hook for drm_dev_release() (rev3)
2017-01-21 10:48 [PATCH v2] drm: Provide a driver hook for drm_dev_release() Chris Wilson
2017-01-21 10:58 ` [PATCH v3] " Chris Wilson
@ 2017-01-21 12:24 ` Patchwork
2017-01-24 10:47 ` [PATCH v5] drm: Provide a driver hook for drm_dev_release() Chris Wilson
2 siblings, 0 replies; 8+ messages in thread
From: Patchwork @ 2017-01-21 12:24 UTC (permalink / raw)
To: Chris Wilson; +Cc: intel-gfx
== Series Details ==
Series: drm: Provide a driver hook for drm_dev_release() (rev3)
URL : https://patchwork.freedesktop.org/series/16538/
State : success
== Summary ==
Series 16538v3 drm: Provide a driver hook for drm_dev_release()
https://patchwork.freedesktop.org/api/1.0/series/16538/revisions/3/mbox/
Test kms_force_connector_basic:
Subgroup prune-stale-modes:
dmesg-warn -> PASS (fi-snb-2520m)
fi-bdw-5557u total:246 pass:232 dwarn:0 dfail:0 fail:0 skip:14
fi-bsw-n3050 total:246 pass:207 dwarn:0 dfail:0 fail:0 skip:39
fi-bxt-j4205 total:246 pass:224 dwarn:0 dfail:0 fail:0 skip:22
fi-bxt-t5700 total:79 pass:66 dwarn:0 dfail:0 fail:0 skip:12
fi-byt-j1900 total:246 pass:219 dwarn:0 dfail:0 fail:0 skip:27
fi-byt-n2820 total:246 pass:215 dwarn:0 dfail:0 fail:0 skip:31
fi-hsw-4770 total:246 pass:227 dwarn:0 dfail:0 fail:0 skip:19
fi-hsw-4770r total:246 pass:227 dwarn:0 dfail:0 fail:0 skip:19
fi-ivb-3520m total:246 pass:225 dwarn:0 dfail:0 fail:0 skip:21
fi-ivb-3770 total:246 pass:225 dwarn:0 dfail:0 fail:0 skip:21
fi-kbl-7500u total:246 pass:225 dwarn:0 dfail:0 fail:0 skip:21
fi-skl-6260u total:246 pass:233 dwarn:0 dfail:0 fail:0 skip:13
fi-skl-6700hq total:246 pass:226 dwarn:0 dfail:0 fail:0 skip:20
fi-skl-6700k total:246 pass:222 dwarn:3 dfail:0 fail:0 skip:21
fi-skl-6770hq total:246 pass:233 dwarn:0 dfail:0 fail:0 skip:13
fi-snb-2520m total:246 pass:215 dwarn:0 dfail:0 fail:0 skip:31
fi-snb-2600 total:246 pass:214 dwarn:0 dfail:0 fail:0 skip:32
f62d6104306f3ec835f3776434a70ca9bb6f820e drm-tip: 2017y-01m-21d-11h-28m-52s UTC integration manifest
d0c8cc5 drm: Provide a driver hook for drm_dev_release()
== Logs ==
For more details see: https://intel-gfx-ci.01.org/CI/Patchwork_3571/
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] drm: Provide a driver hook for drm_dev_release()
2017-01-21 10:58 ` [PATCH v3] " Chris Wilson
2017-01-21 11:02 ` Noralf Trønnes
@ 2017-01-21 21:21 ` Laurent Pinchart
2017-01-23 9:45 ` Chris Wilson
1 sibling, 1 reply; 8+ messages in thread
From: Laurent Pinchart @ 2017-01-21 21:21 UTC (permalink / raw)
To: Chris Wilson; +Cc: Daniel Vetter, intel-gfx, dri-devel
Hi Chris,
Thank you for the patch.
On Saturday 21 Jan 2017 10:58:25 Chris Wilson wrote:
> Some state is coupled into the device lifetime outside of the
> load/unload timeframe and requires teardown during final unreference
> from drm_dev_release(). For example, dmabufs hold both a device and
> module reference and may live longer than expected (i.e. the current
> pattern of the driver tearing down its state and then releasing a
> reference to the drm device) and yet touch driver private state when
> destroyed.
>
> v2: Export drm_dev_fini() and move the responsible for finalizing the
> drm_device and freeing it to the release callback. (If no callback is
> provided, the core will call drm_dev_fini() and kfree(dev) as before.)
> v3: Remember to add drm_dev_fini() to drm_drv.h
This takes my comments into account, thank you for that. Do you have a patch
that shows usage of the release callback in a driver ?
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
> drivers/gpu/drm/drm_drv.c | 56 ++++++++++++++++++++++++++++++--------------
> include/drm/drm_drv.h | 11 ++++++++++
> 2 files changed, 50 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index 1b11ab628da7..517718e4f6e4 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -553,6 +553,39 @@ int drm_dev_init(struct drm_device *dev,
> EXPORT_SYMBOL(drm_dev_init);
>
> /**
> + * drm_dev_fini - Finalize a dead DRM device
> + * @dev: DRM device
> + *
> + * Finalize a dead DRM device. This is the converse to drm_dev_init() and
> + * frees up all state allocated by it. All driver state should be finalized
> + * first. Note that this function does not free the @dev, that is left to
> the + * caller. drm_dev_fini() should only
> + *
> + * The ref-count of @dev must be zero, and drm_dev_fini() should only be
> called + * from a drm_driver->release() callback.
> + */
> +void drm_dev_fini(struct drm_device *dev)
> +{
> + if (drm_core_check_feature(dev, DRIVER_GEM))
> + drm_gem_destroy(dev);
> +
> + drm_legacy_ctxbitmap_cleanup(dev);
> + drm_ht_remove(&dev->map_hash);
> + drm_fs_inode_free(dev->anon_inode);
> +
> + drm_minor_free(dev, DRM_MINOR_PRIMARY);
> + drm_minor_free(dev, DRM_MINOR_RENDER);
> + drm_minor_free(dev, DRM_MINOR_CONTROL);
> +
> + mutex_destroy(&dev->master_mutex);
> + mutex_destroy(&dev->ctxlist_mutex);
> + mutex_destroy(&dev->filelist_mutex);
> + mutex_destroy(&dev->struct_mutex);
> + kfree(dev->unique);
> +}
> +EXPORT_SYMBOL(drm_dev_fini);
> +
> +/**
> * drm_dev_alloc - Allocate new DRM device
> * @driver: DRM driver to allocate device for
> * @parent: Parent device object
> @@ -598,23 +631,12 @@ static void drm_dev_release(struct kref *ref)
> {
> struct drm_device *dev = container_of(ref, struct drm_device, ref);
>
> - if (drm_core_check_feature(dev, DRIVER_GEM))
> - drm_gem_destroy(dev);
> -
> - drm_legacy_ctxbitmap_cleanup(dev);
> - drm_ht_remove(&dev->map_hash);
> - drm_fs_inode_free(dev->anon_inode);
> -
> - drm_minor_free(dev, DRM_MINOR_PRIMARY);
> - drm_minor_free(dev, DRM_MINOR_RENDER);
> - drm_minor_free(dev, DRM_MINOR_CONTROL);
> -
> - mutex_destroy(&dev->master_mutex);
> - mutex_destroy(&dev->ctxlist_mutex);
> - mutex_destroy(&dev->filelist_mutex);
> - mutex_destroy(&dev->struct_mutex);
> - kfree(dev->unique);
> - kfree(dev);
> + if (dev->driver->release) {
> + dev->driver->release(dev);
> + } else {
> + drm_dev_fini(dev);
> + kfree(dev);
> + }
> }
>
> /**
> diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
> index 34ece393c639..bc5865ad0bbd 100644
> --- a/include/drm/drm_drv.h
> +++ b/include/drm/drm_drv.h
> @@ -103,6 +103,15 @@ struct drm_driver {
> *
> */
> void (*unload) (struct drm_device *);
> +
> + /**
> + * @release:
> + *
> + * Optional callback for destroying device state after the final
> + * reference is released, i.e. the device is being destroyed.
> + */
> + void (*release) (struct drm_device *);
> +
> int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file
> *file_priv); int (*dma_quiescent) (struct drm_device *);
> int (*context_dtor) (struct drm_device *dev, int context);
> @@ -451,6 +460,8 @@ extern unsigned int drm_debug;
> int drm_dev_init(struct drm_device *dev,
> struct drm_driver *driver,
> struct device *parent);
> +void drm_dev_fini(struct drm_device *dev);
> +
> struct drm_device *drm_dev_alloc(struct drm_driver *driver,
> struct device *parent);
> int drm_dev_register(struct drm_device *dev, unsigned long flags);
--
Regards,
Laurent Pinchart
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] drm: Provide a driver hook for drm_dev_release()
2017-01-21 21:21 ` Laurent Pinchart
@ 2017-01-23 9:45 ` Chris Wilson
0 siblings, 0 replies; 8+ messages in thread
From: Chris Wilson @ 2017-01-23 9:45 UTC (permalink / raw)
To: Laurent Pinchart; +Cc: Daniel Vetter, intel-gfx, dri-devel
On Sat, Jan 21, 2017 at 11:21:28PM +0200, Laurent Pinchart wrote:
> Hi Chris,
>
> Thank you for the patch.
>
> On Saturday 21 Jan 2017 10:58:25 Chris Wilson wrote:
> > Some state is coupled into the device lifetime outside of the
> > load/unload timeframe and requires teardown during final unreference
> > from drm_dev_release(). For example, dmabufs hold both a device and
> > module reference and may live longer than expected (i.e. the current
> > pattern of the driver tearing down its state and then releasing a
> > reference to the drm device) and yet touch driver private state when
> > destroyed.
> >
> > v2: Export drm_dev_fini() and move the responsible for finalizing the
> > drm_device and freeing it to the release callback. (If no callback is
> > provided, the core will call drm_dev_fini() and kfree(dev) as before.)
> > v3: Remember to add drm_dev_fini() to drm_drv.h
>
> This takes my comments into account, thank you for that. Do you have a patch
> that shows usage of the release callback in a driver ?
I haven't yet dared start to split i915 between pci-device teardown and
system teardown, but
https://cgit.freedesktop.org/~ickle/linux-2.6/commit/?h=prescheduler&id=00a6ab3689ad09a0f2ea1df8e4a03a38721d2328
shows a use of driver->release to avoid the memory corruption with
dmabuf versus the virtual device. vgem should also provide a useful
example.
-Chris
--
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v5] drm: Provide a driver hook for drm_dev_release()
2017-01-21 10:48 [PATCH v2] drm: Provide a driver hook for drm_dev_release() Chris Wilson
2017-01-21 10:58 ` [PATCH v3] " Chris Wilson
2017-01-21 12:24 ` ✓ Fi.CI.BAT: success for drm: Provide a driver hook for drm_dev_release() (rev3) Patchwork
@ 2017-01-24 10:47 ` Chris Wilson
2 siblings, 0 replies; 8+ messages in thread
From: Chris Wilson @ 2017-01-24 10:47 UTC (permalink / raw)
To: dri-devel; +Cc: Daniel Vetter, Laurent Pinchart
Some state is coupled into the device lifetime outside of the
load/unload timeframe and requires teardown during final unreference
from drm_dev_release(). For example, dmabufs hold both a device and
module reference and may live longer than expected (i.e. the current
pattern of the driver tearing down its state and then releasing a
reference to the drm device) and yet touch driver private state when
destroyed.
v2: Export drm_dev_fini() and move the responsibility for finalizing the
drm_device and freeing it to the release callback. (If no callback is
provided, the core will call drm_dev_fini() and kfree(dev) as before.)
v3: Remember to add drm_dev_fini() to drm_drv.h
v4: Tidy language for kerneldoc
v5: Cross reference from drm_dev_init() to note that driver->release()
allows for arbitrary embedding.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
---
drivers/gpu/drm/drm_drv.c | 67 +++++++++++++++++++++++++++++++++--------------
include/drm/drm_drv.h | 13 +++++++++
2 files changed, 60 insertions(+), 20 deletions(-)
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 72116978ec06..3db1f9003cc8 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -465,7 +465,10 @@ static void drm_fs_inode_free(struct inode *inode)
* that do embed &struct drm_device it must be placed first in the overall
* structure, and the overall structure must be allocated using kmalloc(): The
* drm core's release function unconditionally calls kfree() on the @dev pointer
- * when the final reference is released.
+ * when the final reference is released. To override this behaviour, and so
+ * allow embedding of the drm_device inside the driver's device struct at an
+ * arbitrary offset, you must supply a driver->release() callback and control
+ * the finalization explicitly.
*
* RETURNS:
* 0 on success, or error code on failure.
@@ -553,6 +556,43 @@ int drm_dev_init(struct drm_device *dev,
EXPORT_SYMBOL(drm_dev_init);
/**
+ * drm_dev_fini - Finalize a dead DRM device
+ * @dev: DRM device
+ *
+ * Finalize a dead DRM device. This is the converse to drm_dev_init() and
+ * frees up all state allocated by it. All driver state should be finalized
+ * first. Note that this function does not free the @dev, that is left to the
+ * caller.
+ *
+ * The ref-count of @dev must be zero, and drm_dev_fini() should only be called
+ * from a drm_driver->release() callback.
+ */
+void drm_dev_fini(struct drm_device *dev)
+{
+ WARN_ON(atomic_read(&dev->ref.refcount));
+
+ drm_vblank_cleanup(dev);
+
+ if (drm_core_check_feature(dev, DRIVER_GEM))
+ drm_gem_destroy(dev);
+
+ drm_legacy_ctxbitmap_cleanup(dev);
+ drm_ht_remove(&dev->map_hash);
+ drm_fs_inode_free(dev->anon_inode);
+
+ drm_minor_free(dev, DRM_MINOR_PRIMARY);
+ drm_minor_free(dev, DRM_MINOR_RENDER);
+ drm_minor_free(dev, DRM_MINOR_CONTROL);
+
+ mutex_destroy(&dev->master_mutex);
+ mutex_destroy(&dev->ctxlist_mutex);
+ mutex_destroy(&dev->filelist_mutex);
+ mutex_destroy(&dev->struct_mutex);
+ kfree(dev->unique);
+}
+EXPORT_SYMBOL(drm_dev_fini);
+
+/**
* drm_dev_alloc - Allocate new DRM device
* @driver: DRM driver to allocate device for
* @parent: Parent device object
@@ -598,25 +638,12 @@ static void drm_dev_release(struct kref *ref)
{
struct drm_device *dev = container_of(ref, struct drm_device, ref);
- drm_vblank_cleanup(dev);
-
- if (drm_core_check_feature(dev, DRIVER_GEM))
- drm_gem_destroy(dev);
-
- drm_legacy_ctxbitmap_cleanup(dev);
- drm_ht_remove(&dev->map_hash);
- drm_fs_inode_free(dev->anon_inode);
-
- drm_minor_free(dev, DRM_MINOR_PRIMARY);
- drm_minor_free(dev, DRM_MINOR_RENDER);
- drm_minor_free(dev, DRM_MINOR_CONTROL);
-
- mutex_destroy(&dev->master_mutex);
- mutex_destroy(&dev->ctxlist_mutex);
- mutex_destroy(&dev->filelist_mutex);
- mutex_destroy(&dev->struct_mutex);
- kfree(dev->unique);
- kfree(dev);
+ if (dev->driver->release) {
+ dev->driver->release(dev);
+ } else {
+ drm_dev_fini(dev);
+ kfree(dev);
+ }
}
/**
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index 34ece393c639..3562f5be547e 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -103,6 +103,17 @@ struct drm_driver {
*
*/
void (*unload) (struct drm_device *);
+
+ /**
+ * @release:
+ *
+ * Optional callback for destroying device state after the final
+ * reference is released, i.e. the device is being destroyed. Drivers
+ * using this callback are responsible for calling drm_dev_fini()
+ * to finalize the device and then freeing the struct themselves.
+ */
+ void (*release) (struct drm_device *);
+
int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
int (*dma_quiescent) (struct drm_device *);
int (*context_dtor) (struct drm_device *dev, int context);
@@ -451,6 +462,8 @@ extern unsigned int drm_debug;
int drm_dev_init(struct drm_device *dev,
struct drm_driver *driver,
struct device *parent);
+void drm_dev_fini(struct drm_device *dev);
+
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.11.0
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-01-24 10:47 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-21 10:48 [PATCH v2] drm: Provide a driver hook for drm_dev_release() Chris Wilson
2017-01-21 10:58 ` [PATCH v3] " Chris Wilson
2017-01-21 11:02 ` Noralf Trønnes
2017-01-21 11:12 ` Chris Wilson
2017-01-21 21:21 ` Laurent Pinchart
2017-01-23 9:45 ` Chris Wilson
2017-01-21 12:24 ` ✓ Fi.CI.BAT: success for drm: Provide a driver hook for drm_dev_release() (rev3) Patchwork
2017-01-24 10:47 ` [PATCH v5] drm: Provide a driver hook for drm_dev_release() Chris Wilson
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.