Re: [PATCH] drm/kms: Catch mode_object lifetime errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jun 14, 2019 at 08:17:23AM +0200, Daniel Vetter wrote:
> Only dynamic mode objects, i.e. those which are refcounted and have a free
> callback, can be added while the overall drm_device is visible to
> userspace. All others must be added before drm_dev_register and
> removed after drm_dev_unregister.
> 
> Small issue around drivers still using the load/unload callbacks, we
> need to make sure we set dev->registered so that load/unload code in
> these callbacks doesn't trigger false warnings. Only a small
> adjustement in drm_dev_register was needed.
> 
> Motivated by some irc discussions about object ids of dynamic objects
> like blobs become invalid, and me going on a bit an audit spree.
> 

Seems like a very worthwhile change, any idea how many drivers are going
to be sad after this change?

> Signed-off-by: Daniel Vetter <daniel.vetter@xxxxxxxxx>
> ---
>  drivers/gpu/drm/drm_drv.c         | 4 ++--
>  drivers/gpu/drm/drm_mode_object.c | 4 ++++
>  2 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index cb6f0245de7c..48c84e3e1931 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -997,14 +997,14 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
>  	if (ret)
>  		goto err_minors;
>  
> -	dev->registered = true;
> -
>  	if (dev->driver->load) {
>  		ret = dev->driver->load(dev, flags);
>  		if (ret)
>  			goto err_minors;
>  	}
>  
> +	dev->registered = true;
> +
>  	if (drm_core_check_feature(dev, DRIVER_MODESET))
>  		drm_modeset_register_all(dev);
>  
> diff --git a/drivers/gpu/drm/drm_mode_object.c b/drivers/gpu/drm/drm_mode_object.c
> index 1c6e51135962..c355ba8e6d5d 100644
> --- a/drivers/gpu/drm/drm_mode_object.c
> +++ b/drivers/gpu/drm/drm_mode_object.c
> @@ -42,6 +42,8 @@ int __drm_mode_object_add(struct drm_device *dev, struct drm_mode_object *obj,
>  {
>  	int ret;
>  
> +	WARN_ON(dev->registered && !obj_free_cb);

These should probably have a comment above them giving some guidance to the
driver developer.

With some comments, this is:

Reviewed-by: Sean Paul <sean@xxxxxxxxxx>


> +
>  	mutex_lock(&dev->mode_config.idr_mutex);
>  	ret = idr_alloc(&dev->mode_config.object_idr, register_obj ? obj : NULL,
>  			1, 0, GFP_KERNEL);
> @@ -102,6 +104,8 @@ void drm_mode_object_register(struct drm_device *dev,
>  void drm_mode_object_unregister(struct drm_device *dev,
>  				struct drm_mode_object *object)
>  {
> +	WARN_ON(dev->registered && !object->free_cb);
> +
>  	mutex_lock(&dev->mode_config.idr_mutex);
>  	if (object->id) {
>  		idr_remove(&dev->mode_config.object_idr, object->id);
> -- 
> 2.20.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@xxxxxxxxxxxxxxxxxxxxx
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux