[PATCH v2 5/9] drm/fb-helper: Add top-level lock

Daniel Vetter daniel at ffwll.ch
Tue Jun 7 19:54:12 UTC 2016


On Tue, Jun 07, 2016 at 05:26:21PM +0200, Thierry Reding wrote:
> From: Thierry Reding <treding at nvidia.com>
> 
> Introduce a new top-level lock for the FB helper code. This will allow
> better locking granularity and avoid the need to abuse modeset locking
> for this purpose instead.
> 
> Signed-off-by: Thierry Reding <treding at nvidia.com>

I think this is now too much locking, and ime too much locking only leads
to massive confusion. It'd be great if we can clean this up (maybe in a
follow-up patch, maybe in this one here) and restrict the core locks to
just where we need them: So all the places that look at probe state need
dev->mode_config.mutex, all the places that change modeset state need the
modeset locks. But e.g. add/remove_one_connector only need the new
fb_helper->lock I think. In the future we might grabbing the other locks
even down into the legacy/atomic fbdev implementations.

> ---
>  drivers/gpu/drm/drm_fb_helper.c | 27 ++++++++++++++++++++++++++-
>  include/drm/drm_fb_helper.h     |  5 +++++
>  2 files changed, 31 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
> index 252c7557bdb5..f7722bcb0064 100644
> --- a/drivers/gpu/drm/drm_fb_helper.c
> +++ b/drivers/gpu/drm/drm_fb_helper.c
> @@ -105,6 +105,7 @@ static int __drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper,
>  	if (!drm_fbdev_emulation)
>  		return 0;
>  
> +	WARN_ON(!mutex_is_locked(&fb_helper->lock));
>  	WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex));
>  
>  	count = fb_helper->connector_count + 1;
> @@ -127,6 +128,7 @@ static int __drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper,
>  	drm_connector_reference(connector);
>  	conn->connector = connector;
>  	fb_helper->connector_info[fb_helper->connector_count++] = conn;
> +
>  	return 0;
>  }
>  
> @@ -135,11 +137,13 @@ int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper,
>  {
>  	int err;
>  
> +	mutex_lock(&fb_helper->lock);
>  	mutex_lock(&fb_helper->dev->mode_config.mutex);
>  
>  	err = __drm_fb_helper_add_one_connector(fb_helper, connector);
>  
>  	mutex_unlock(&fb_helper->dev->mode_config.mutex);
> +	mutex_unlock(&fb_helper->lock);
>  
>  	return err;
>  }
> @@ -168,6 +172,7 @@ int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
>  	if (!drm_fbdev_emulation)
>  		return 0;
>  
> +	mutex_lock(&fb_helper->lock);
>  	mutex_lock(&dev->mode_config.mutex);
>  
>  	drm_for_each_connector(connector, dev) {
> @@ -184,6 +189,7 @@ int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
>  	}
>  
>  	mutex_unlock(&dev->mode_config.mutex);
> +	mutex_unlock(&fb_helper->lock);
>  
>  	return ret;
>  }
> @@ -198,6 +204,7 @@ static int __drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
>  	if (!drm_fbdev_emulation)
>  		return 0;
>  
> +	WARN_ON(!mutex_is_locked(&fb_helper->lock));
>  	WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex));
>  
>  	for (i = 0; i < fb_helper->connector_count; i++) {
> @@ -225,11 +232,13 @@ int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
>  {
>  	int err;
>  
> +	mutex_lock(&fb_helper->lock);
>  	mutex_lock(&fb_helper->dev->mode_config.mutex);
>  
>  	err = __drm_fb_helper_remove_one_connector(fb_helper, connector);
>  
>  	mutex_unlock(&fb_helper->dev->mode_config.mutex);
> +	mutex_unlock(&fb_helper->lock);
>  
>  	return err;
>  }
> @@ -478,16 +487,21 @@ int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper)
>  	if (!drm_fbdev_emulation)
>  		return -ENODEV;
>  
> +	mutex_lock(&fb_helper->lock);
>  	drm_modeset_lock_all(dev);
> +
>  	ret = restore_fbdev_mode(fb_helper);
>  
>  	do_delayed = fb_helper->delayed_hotplug;
>  	if (do_delayed)
>  		fb_helper->delayed_hotplug = false;
> +
>  	drm_modeset_unlock_all(dev);
> +	mutex_unlock(&fb_helper->lock);
>  
>  	if (do_delayed)
>  		drm_fb_helper_hotplug_event(fb_helper);
> +
>  	return ret;
>  }
>  EXPORT_SYMBOL(drm_fb_helper_restore_fbdev_mode_unlocked);
> @@ -688,6 +702,7 @@ void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
>  	spin_lock_init(&helper->dirty_lock);
>  	INIT_WORK(&helper->dirty_work, drm_fb_helper_dirty_work);
>  	helper->dirty_clip.x1 = helper->dirty_clip.y1 = ~0;
> +	mutex_init(&helper->lock);
>  	helper->funcs = funcs;
>  	helper->dev = dev;
>  }
> @@ -853,6 +868,7 @@ void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)
>  			unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
>  	}
>  
> +	mutex_destroy(&fb_helper->lock);
>  	drm_fb_helper_crtc_free(fb_helper);
>  
>  }
> @@ -2273,16 +2289,20 @@ int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
>  {
>  	struct drm_device *dev = fb_helper->dev;
>  	u32 max_width, max_height;
> +	int err = 0;
>  
>  	if (!drm_fbdev_emulation)
>  		return 0;
>  
> +	mutex_lock(&fb_helper->lock);
>  	mutex_lock(&fb_helper->dev->mode_config.mutex);
> +
>  	if (!fb_helper->fb || !drm_fb_helper_is_bound(fb_helper)) {
>  		fb_helper->delayed_hotplug = true;
>  		mutex_unlock(&fb_helper->dev->mode_config.mutex);
> -		return 0;
> +		goto unlock;
>  	}
> +
>  	DRM_DEBUG_KMS("\n");
>  
>  	max_width = fb_helper->fb->width;
> @@ -2290,6 +2310,7 @@ int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
>  
>  	drm_fb_helper_probe_connector_modes(fb_helper, max_width, max_height);
>  	mutex_unlock(&fb_helper->dev->mode_config.mutex);
> +	mutex_unlock(&fb_helper->lock);
>  
>  	drm_modeset_lock_all(dev);
>  	drm_setup_crtcs(fb_helper);
> @@ -2297,6 +2318,10 @@ int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
>  	drm_fb_helper_set_par(fb_helper->fbdev);
>  
>  	return 0;
> +
> +unlock:
> +	mutex_unlock(&fb_helper->lock);
> +	return err;
>  }
>  EXPORT_SYMBOL(drm_fb_helper_hotplug_event);
>  
> diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper.h
> index 5b4aa35026a3..7739be08ebca 100644
> --- a/include/drm/drm_fb_helper.h
> +++ b/include/drm/drm_fb_helper.h
> @@ -198,6 +198,11 @@ struct drm_fb_helper {
>  	struct work_struct dirty_work;
>  
>  	/**
> +	 * Top-level FB helper lock.
> +	 */

need to add @lock: in the above comment, otherwise kerneldoc will still
complain about the lack of comment for this new member.
-Daniel

> +	struct mutex lock;
> +
> +	/**
>  	 * @kernel_fb_list:
>  	 *
>  	 * Entry on the global kernel_fb_helper_list, used for kgdb entry/exit.
> -- 
> 2.8.3
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the dri-devel mailing list