[PATCH] drm: Release filp before global lock

Thomas Hellström (VMware) thomas_os at shipmail.org
Wed Jan 22 21:52:23 UTC 2020


Hi, Chris,

On 1/22/20 4:56 PM, Chris Wilson wrote:
> The file is not part of the global drm resource and can be released
> prior to take the global mutex to drop the open_count (and potentially
> close) the drm device.
>
> However, inside drm_close_helper() there are a number of dev->driver
> callbacks that take the drm_device as the first parameter... Worryingly
> some of those callbacks may be (implicitly) depending on the global
> mutex.

I read this as you suspect that there are driver callbacks inside 
drm_close_helper() that might need the global mutex held? But then it 
wouldn't be safe to move the lock? Is there a strong motivation for 
moving the locking in the first place? Also a minor nit below:

>
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> ---
>   drivers/gpu/drm/drm_file.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
> index 92d16724f949..84ed313ee2e9 100644
> --- a/drivers/gpu/drm/drm_file.c
> +++ b/drivers/gpu/drm/drm_file.c
> @@ -438,12 +438,12 @@ int drm_release(struct inode *inode, struct file *filp)
>   	struct drm_minor *minor = file_priv->minor;
>   	struct drm_device *dev = minor->dev;
>   
> -	mutex_lock(&drm_global_mutex);
> -
>   	DRM_DEBUG("open_count = %d\n", dev->open_count);

The read of dev->open_count should still be inside the lock to be 
consistent with the value that is decremented below. Perhaps move the 
DRM_DEBUG()?

>   
>   	drm_close_helper(filp);
>   
> +	mutex_lock(&drm_global_mutex);
> +
>   	if (!--dev->open_count)
>   		drm_lastclose(dev);
>   

Thanks,

Thomas




More information about the dri-devel mailing list