Commit 7963e9db authored by Dave Airlie's avatar Dave Airlie

Revert "drm: drop redundant drm_file->is_master"

This reverts commit 48ba8137.

Thanks to Chris:
"drm_file->is_master is not synomous with having drm_file->master ==
drm_file->minor->master. This is because drm_file->master is the same
for all drm_files of the same generation and so when there is a master,
every drm_file believes itself to be the master. Confusion ensues and
things go pear shaped when one file is closed and there is no master
anymore."

Conflicts:
	drivers/gpu/drm/drm_drv.c
	drivers/gpu/drm/drm_stub.c
parent fa1d0ee6
...@@ -3244,7 +3244,7 @@ int drm_mode_getfb(struct drm_device *dev, ...@@ -3244,7 +3244,7 @@ int drm_mode_getfb(struct drm_device *dev,
r->bpp = fb->bits_per_pixel; r->bpp = fb->bits_per_pixel;
r->pitch = fb->pitches[0]; r->pitch = fb->pitches[0];
if (fb->funcs->create_handle) { if (fb->funcs->create_handle) {
if (drm_is_master(file_priv) || capable(CAP_SYS_ADMIN) || if (file_priv->is_master || capable(CAP_SYS_ADMIN) ||
drm_is_control_client(file_priv)) { drm_is_control_client(file_priv)) {
ret = fb->funcs->create_handle(fb, file_priv, ret = fb->funcs->create_handle(fb, file_priv,
&r->handle); &r->handle);
......
...@@ -179,7 +179,7 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data, ...@@ -179,7 +179,7 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data,
int ret = 0; int ret = 0;
mutex_lock(&dev->master_mutex); mutex_lock(&dev->master_mutex);
if (drm_is_master(file_priv)) if (file_priv->is_master)
goto out_unlock; goto out_unlock;
if (file_priv->minor->master) { if (file_priv->minor->master) {
...@@ -193,10 +193,13 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data, ...@@ -193,10 +193,13 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data,
} }
file_priv->minor->master = drm_master_get(file_priv->master); file_priv->minor->master = drm_master_get(file_priv->master);
file_priv->is_master = 1;
if (dev->driver->master_set) { if (dev->driver->master_set) {
ret = dev->driver->master_set(dev, file_priv, false); ret = dev->driver->master_set(dev, file_priv, false);
if (unlikely(ret != 0)) if (unlikely(ret != 0)) {
file_priv->is_master = 0;
drm_master_put(&file_priv->minor->master); drm_master_put(&file_priv->minor->master);
}
} }
out_unlock: out_unlock:
...@@ -210,7 +213,7 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data, ...@@ -210,7 +213,7 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
int ret = -EINVAL; int ret = -EINVAL;
mutex_lock(&dev->master_mutex); mutex_lock(&dev->master_mutex);
if (!drm_is_master(file_priv)) if (!file_priv->is_master)
goto out_unlock; goto out_unlock;
if (!file_priv->minor->master) if (!file_priv->minor->master)
...@@ -220,6 +223,7 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data, ...@@ -220,6 +223,7 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
if (dev->driver->master_drop) if (dev->driver->master_drop)
dev->driver->master_drop(dev, file_priv, false); dev->driver->master_drop(dev, file_priv, false);
drm_master_put(&file_priv->minor->master); drm_master_put(&file_priv->minor->master);
file_priv->is_master = 0;
out_unlock: out_unlock:
mutex_unlock(&dev->master_mutex); mutex_unlock(&dev->master_mutex);
......
...@@ -194,6 +194,7 @@ static int drm_open_helper(struct file *filp, struct drm_minor *minor) ...@@ -194,6 +194,7 @@ static int drm_open_helper(struct file *filp, struct drm_minor *minor)
goto out_close; goto out_close;
} }
priv->is_master = 1;
/* take another reference for the copy in the local file priv */ /* take another reference for the copy in the local file priv */
priv->master = drm_master_get(priv->minor->master); priv->master = drm_master_get(priv->minor->master);
priv->authenticated = 1; priv->authenticated = 1;
...@@ -425,7 +426,7 @@ int drm_release(struct inode *inode, struct file *filp) ...@@ -425,7 +426,7 @@ int drm_release(struct inode *inode, struct file *filp)
mutex_lock(&dev->master_mutex); mutex_lock(&dev->master_mutex);
if (drm_is_master(file_priv)) { if (file_priv->is_master) {
struct drm_master *master = file_priv->master; struct drm_master *master = file_priv->master;
/** /**
...@@ -453,6 +454,7 @@ int drm_release(struct inode *inode, struct file *filp) ...@@ -453,6 +454,7 @@ int drm_release(struct inode *inode, struct file *filp)
/* drop the master reference held by the file priv */ /* drop the master reference held by the file priv */
if (file_priv->master) if (file_priv->master)
drm_master_put(&file_priv->master); drm_master_put(&file_priv->master);
file_priv->is_master = 0;
mutex_unlock(&dev->master_mutex); mutex_unlock(&dev->master_mutex);
if (dev->driver->postclose) if (dev->driver->postclose)
......
...@@ -607,7 +607,7 @@ static int drm_ioctl_permit(u32 flags, struct drm_file *file_priv) ...@@ -607,7 +607,7 @@ static int drm_ioctl_permit(u32 flags, struct drm_file *file_priv)
return -EACCES; return -EACCES;
/* MASTER is only for master or control clients */ /* MASTER is only for master or control clients */
if (unlikely((flags & DRM_MASTER) && !drm_is_master(file_priv) && if (unlikely((flags & DRM_MASTER) && !file_priv->is_master &&
!drm_is_control_client(file_priv))) !drm_is_control_client(file_priv)))
return -EACCES; return -EACCES;
......
...@@ -112,7 +112,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv) ...@@ -112,7 +112,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
/* don't set the block all signals on the master process for now /* don't set the block all signals on the master process for now
* really probably not the correct answer but lets us debug xkb * really probably not the correct answer but lets us debug xkb
* xserver for now */ * xserver for now */
if (!drm_is_master(file_priv)) { if (!file_priv->is_master) {
sigemptyset(&dev->sigmask); sigemptyset(&dev->sigmask);
sigaddset(&dev->sigmask, SIGSTOP); sigaddset(&dev->sigmask, SIGSTOP);
sigaddset(&dev->sigmask, SIGTSTP); sigaddset(&dev->sigmask, SIGTSTP);
......
...@@ -1260,7 +1260,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, ...@@ -1260,7 +1260,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
flags = 0; flags = 0;
if (args->flags & I915_EXEC_SECURE) { if (args->flags & I915_EXEC_SECURE) {
if (!drm_is_master(file) || !capable(CAP_SYS_ADMIN)) if (!file->is_master || !capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
flags |= I915_DISPATCH_SECURE; flags |= I915_DISPATCH_SECURE;
...@@ -1369,7 +1369,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, ...@@ -1369,7 +1369,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
ret = i915_parse_cmds(ring, ret = i915_parse_cmds(ring,
batch_obj, batch_obj,
args->batch_start_offset, args->batch_start_offset,
drm_is_master(file)); file->is_master);
if (ret) if (ret)
goto err; goto err;
......
...@@ -990,7 +990,7 @@ static struct vmw_master *vmw_master_check(struct drm_device *dev, ...@@ -990,7 +990,7 @@ static struct vmw_master *vmw_master_check(struct drm_device *dev,
if (unlikely(ret != 0)) if (unlikely(ret != 0))
return ERR_PTR(-ERESTARTSYS); return ERR_PTR(-ERESTARTSYS);
if (drm_is_master(file_priv)) { if (file_priv->is_master) {
mutex_unlock(&dev->master_mutex); mutex_unlock(&dev->master_mutex);
return NULL; return NULL;
} }
......
...@@ -182,7 +182,7 @@ static void imx_drm_driver_preclose(struct drm_device *drm, ...@@ -182,7 +182,7 @@ static void imx_drm_driver_preclose(struct drm_device *drm,
{ {
int i; int i;
if (!drm_is_master(file)) if (!file->is_master)
return; return;
for (i = 0; i < MAX_CRTC; i++) for (i = 0; i < MAX_CRTC; i++)
......
...@@ -384,6 +384,8 @@ struct drm_prime_file_private { ...@@ -384,6 +384,8 @@ struct drm_prime_file_private {
/** File private data */ /** File private data */
struct drm_file { struct drm_file {
unsigned authenticated :1; unsigned authenticated :1;
/* Whether we're master for a minor. Protected by master_mutex */
unsigned is_master :1;
/* true when the client has asked us to expose stereo 3D mode flags */ /* true when the client has asked us to expose stereo 3D mode flags */
unsigned stereo_allowed :1; unsigned stereo_allowed :1;
/* /*
...@@ -1020,7 +1022,7 @@ struct drm_device { ...@@ -1020,7 +1022,7 @@ struct drm_device {
/** \name Locks */ /** \name Locks */
/*@{ */ /*@{ */
struct mutex struct_mutex; /**< For others */ struct mutex struct_mutex; /**< For others */
struct mutex master_mutex; /**< For drm_minor::master */ struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */
/*@} */ /*@} */
/** \name Usage Counters */ /** \name Usage Counters */
...@@ -1158,21 +1160,6 @@ static inline bool drm_is_primary_client(const struct drm_file *file_priv) ...@@ -1158,21 +1160,6 @@ static inline bool drm_is_primary_client(const struct drm_file *file_priv)
return file_priv->minor->type == DRM_MINOR_LEGACY; return file_priv->minor->type == DRM_MINOR_LEGACY;
} }
/**
* drm_is_master() - Check whether a DRM open-file is DRM-Master
* @file: DRM open-file context
*
* This checks whether a DRM open-file context is owner of the master context
* attached to it. If a file owns a master context, it's called DRM-Master.
* Per DRM device, only one such file can be DRM-Master at a time.
*
* Returns: True if the file is DRM-Master, otherwise false.
*/
static inline bool drm_is_master(const struct drm_file *file)
{
return file->master && file->master == file->minor->master;
}
/******************************************************************/ /******************************************************************/
/** \name Internal function definitions */ /** \name Internal function definitions */
/*@{*/ /*@{*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment