drm/msm: remove the drm_device_is_unplugged check
Subsystems (4)
PATCH 1/2 drm/msm: remove the drm_device_is_unplugged check
This flag is only used for drm/udl.
--- drivers/gpu/drm/msm/msm_fbdev.c | 3 --- 1 file changed, 3 deletions(-)
drivers/gpu/drm/msm/msm_fbdev.c +0 -3
@@ -65,9 +65,6 @@ static int msm_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma)struct drm_device *dev = helper->dev;int ret =0 ; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - ret =drm_gem_mmap_obj (drm_obj, drm_obj->size, vma);if (ret) {pr_err ("%s:drm_gem_mmap_obj fail\n" , __func__);
Signature · 6 lines
2.7.0.rc3.207.g0ac5344 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/2 drm: make unplugged flag specific to udl driver
Remove the general drm_device_is_unplugged() checks, and move the unplugged flag handling logic into drm/udl. In general we want to keep driver-specific logic out of common drm code.
--- drivers/gpu/drm/drm_drv.c | 6 ------ drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 --- drivers/gpu/drm/drm_ioctl.c | 3 --- drivers/gpu/drm/drm_vm.c | 3 --- drivers/gpu/drm/udl/udl_connector.c | 2 +- drivers/gpu/drm/udl/udl_drv.c | 1 + drivers/gpu/drm/udl/udl_drv.h | 3 +++ drivers/gpu/drm/udl/udl_fb.c | 2 +- drivers/gpu/drm/udl/udl_main.c | 15 +++++++++++++++ include/drm/drmP.h | 14 -------------- 11 files changed, 21 insertions(+), 33 deletions(-)
drivers/gpu/drm/drm_drv.c +0 -6
@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id)if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }return minor;
@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -if (dev->open_count ==0 ) {drm_put_dev (dev); }
drivers/gpu/drm/drm_fops.c +0 -2
@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file *filp)if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev); }mutex_unlock (&drm_global_mutex);
drivers/gpu/drm/drm_gem.c +0 -3
@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -drm_vma_offset_lock_lookup (dev->vma_offset_manager); node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager, vma->vm_pgoff,
drivers/gpu/drm/drm_ioctl.c +0 -3
@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {
drivers/gpu/drm/drm_vm.c +0 -3
@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);
drivers/gpu/drm/udl/udl_connector.c +1 -1
@@ -96,7 +96,7 @@ static int udl_mode_valid(struct drm_connector *connector,static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) +if (udl_device_is_unplugged (connector->dev))return connector_status_disconnected;return connector_status_connected; }
drivers/gpu/drm/udl/udl_drv.c +1 -0
@@ -97,6 +97,7 @@ static void udl_usb_disconnect(struct usb_interface *interface)drm_connector_unplug_all (dev);udl_fbdev_unplug (dev);udl_drop_usb (dev); +udl_device_set_unplugged (dev);drm_unplug_dev (dev); }
drivers/gpu/drm/udl/udl_drv.h +3 -0
@@ -65,6 +65,7 @@ struct udl_device {atomic_t bytes_identical;/* saved effort with backbuffer comparison */ atomic_t bytes_sent;/* to usb, after compression including overhead */ atomic_t cpu_kcycles_used;/* transpired during pixel processing */ +atomic_t unplugged;/* device has been unplugged or gone away */ };struct udl_gem_object {
@@ -140,6 +141,8 @@ int udl_handle_damage(struct udl_framebuffer *fb, int x, int y, int width, int height);int udl_drop_usb (struct drm_device *dev); +void udl_device_set_unplugged (struct drm_device *dev); +int udl_device_is_unplugged (struct drm_device *dev);#define CMD_WRITE_RAW8 "\xAF\x60"/**< 8 bit raw write command. */ #define CMD_WRITE_RL8 "\xAF\x61"/**< 8 bit run length command. */
drivers/gpu/drm/udl/udl_fb.c +1 -1
@@ -325,7 +325,7 @@ static int udl_fb_open(struct fb_info *info, int user)struct udl_device *udl = dev->dev_private;/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) +if (udl_device_is_unplugged (udl->ddev))return -ENODEV ; ufbdev->fb_count++;
drivers/gpu/drm/udl/udl_main.c +15 -0
@@ -350,3 +350,18 @@ int udl_driver_unload(struct drm_device *dev)kfree (udl);return 0 ; } + +void udl_device_set_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +smp_wmb (); +atomic_set (&udl->unplugged,1 ); +} + +int udl_device_is_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +int ret =atomic_read (&udl->unplugged); +smp_rmb (); +return ret; +}
include/drm/drmP.h +0 -14
@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */ struct inode *anon_inode;/**< inode for private address-space */ char *unique;/**< unique name of the device */ /*@} */
@@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,return ((dev->driver->driver_features & feature) ?1 :0 ); } -static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 ); -} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} -static inline bool drm_is_render_client (const struct drm_file *file_priv) {return file_priv->minor->type ==DRM_MINOR_RENDER ;
Signature · 6 lines
2.7.0.rc3.207.g0ac5344 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
Hi
Quoted 3 lines · Haixia Shi
Remove the general
drm_device_is_unplugged()checks, and move the unplugged flag handling logic into drm/udl. In general we want to keep driver-specific logic out of common drm code.
I like the idea of moving this hack into udl. However, I don't think this patch is sufficient, see below for comments.
Btw., hotplug might happen on other buses as well. It just happens that no-one tried pci/platform unplugging so far.. We used to have some patches flying around to make it work properly (with enter/leave markers), but no-one picked those up. But I like the idea of moving this unplugged marker into UDL, to make clear if someone else needs it, they better do it properly.
Quoted 21 lines
Signed-off-by Haixia Shi <[email protected]>Reviewed-by Stéphane Marchesin <[email protected]>--- drivers/gpu/drm/drm_drv.c | 6 ------ drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 --- drivers/gpu/drm/drm_ioctl.c | 3 --- drivers/gpu/drm/drm_vm.c | 3 --- drivers/gpu/drm/udl/udl_connector.c | 2 +- drivers/gpu/drm/udl/udl_drv.c | 1 + drivers/gpu/drm/udl/udl_drv.h | 3 +++ drivers/gpu/drm/udl/udl_fb.c | 2 +- drivers/gpu/drm/udl/udl_main.c | 15 +++++++++++++++ include/drm/drmP.h | 14 -------------- 11 files changed, 21 insertions(+), 33 deletions(-)drivers/gpu/drm/drm_drv.c +0
-0
drivers/gpu/drm/drm_drv.c struct drm_minor *drm_minor_acquire(unsigned int minor_id) · line 379
Quoted 7 lines
drivers/gpu/drm/drm_drv.c +0
-3@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id)if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }
You cannot just drop this without a replacement. You should add a drm_driver.open callback to UDL which checks for this. drm_minor_acquire() is only ever called from drm_stub_open(), and as such only from drm_open().
Alternatively, you can provide fops.open from UDL and wrap drm_open().
drivers/gpu/drm/drm_drv.c void drm_unplug_dev(struct drm_device *dev) · line 469
Quoted 9 lines
drivers/gpu/drm/drm_drv.c +0
-3return minor;@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -
You replace this by moving it into the caller of drm_unplug_dev(). Sounds good to me. There has never been a real reason to put it underneath the global mutex, anyway.
drivers/gpu/drm/drm_fops.c int drm_release(struct inode *inode, struct file *filp) · line 501
Quoted 13 lines
drivers/gpu/drm/drm_drv.c +0
-0if (dev->open_count ==0 ) {drm_put_dev (dev); }drivers/gpu/drm/drm_fops.c +0
-2@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file *filp)if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev);
Again, you cannot drop this without replacement! In this case, you really should wrap fops.release() from UDL and call into drm_release() before copying this unplug-logic.
Quoted 8 lines
drivers/gpu/drm/drm_fops.c +0
-0}mutex_unlock (&drm_global_mutex);drivers/gpu/drm/drm_gem.c +0
-0
drivers/gpu/drm/drm_gem.c int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) · line 905
Quoted 6 lines
drivers/gpu/drm/drm_gem.c +0
-3@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -
Rather than just dropping it, you better move it into udl_drm_gem_mmap().
Quoted 8 lines
drivers/gpu/drm/drm_gem.c +0
-0drm_vma_offset_lock_lookup (dev->vma_offset_manager); node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager, vma->vm_pgoff,drivers/gpu/drm/drm_ioctl.c +0
-0
drivers/gpu/drm/drm_ioctl.c long drm_ioctl(struct file *filp, · line 700
Quoted 6 lines
drivers/gpu/drm/drm_ioctl.c +0
-3@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -
You *must* provide a wrapper for fops.ioctl() in udl which does this check.
Quoted 8 lines
drivers/gpu/drm/drm_ioctl.c +0
-0is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {drivers/gpu/drm/drm_vm.c +0
-0
drivers/gpu/drm/drm_vm.c int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma) · line 662
Quoted 6 lines
drivers/gpu/drm/drm_vm.c +0
-3@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -
This looks fine to me.
Quoted 21 lines
drivers/gpu/drm/drm_vm.c +0
-0mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);drivers/gpu/drm/udl/udl_connector.c +1
-1@@ -96,7 +96,7 @@ static int udl_mode_valid(struct drm_connector *connector,static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) +if (udl_device_is_unplugged (connector->dev))return connector_status_disconnected;return connector_status_connected; }drivers/gpu/drm/udl/udl_drv.c +0
-0
drivers/gpu/drm/udl/udl_drv.c static void udl_usb_disconnect(struct usb_interface *interface) · line 101
Quoted 5 lines
drivers/gpu/drm/udl/udl_drv.c +1
-0@@ -97,6 +97,7 @@ static void udl_usb_disconnect(struct usb_interface *interface)drm_connector_unplug_all (dev);udl_fbdev_unplug (dev);udl_drop_usb (dev); +udl_device_set_unplugged (dev);drm_unplug_dev (dev);
This looks good.
Quoted 49 lines
drivers/gpu/drm/udl/udl_drv.c +0
-0}drivers/gpu/drm/udl/udl_drv.h +3
-0@@ -65,6 +65,7 @@ struct udl_device {atomic_t bytes_identical;/* saved effort with backbuffer comparison */ atomic_t bytes_sent;/* to usb, after compression including overhead */ atomic_t cpu_kcycles_used;/* transpired during pixel processing */ +atomic_t unplugged;/* device has been unplugged or gone away */ };struct udl_gem_object {@@ -140,6 +141,8 @@ int udl_handle_damage(struct udl_framebuffer *fb, int x, int y, int width, int height);int udl_drop_usb (struct drm_device *dev); +void udl_device_set_unplugged (struct drm_device *dev); +int udl_device_is_unplugged (struct drm_device *dev);#define CMD_WRITE_RAW8 "\xAF\x60"/**< 8 bit raw write command. */ #define CMD_WRITE_RL8 "\xAF\x61"/**< 8 bit run length command. */ drivers/gpu/drm/udl/udl_fb.c +1
-1@@ -325,7 +325,7 @@ static int udl_fb_open(struct fb_info *info, int user)struct udl_device *udl = dev->dev_private;/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) +if (udl_device_is_unplugged (udl->ddev))return -ENODEV ; ufbdev->fb_count++;drivers/gpu/drm/udl/udl_main.c +5
-0@@ -350,3 +350,18 @@ int udl_driver_unload(struct drm_device *dev)kfree (udl);return 0 ; } + +void udl_device_set_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +smp_wmb ();
drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev) · line 367
Quoted 10 lines
drivers/gpu/drm/udl/udl_main.c +10
-0+atomic_set (&udl->unplugged,1 ); +} + +int udl_device_is_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +int ret =atomic_read (&udl->unplugged); +smp_rmb (); +return ret; +}
This looks fine to me.
Please make sure to wrap most of the file_operations callbacks in UDL and protect them with the "unplugged" check. Yes, we all know that this is racy, and always has been. However, it is still better than nothing. So please don't just drop them without any explanation!
Thanks
David
Quoted 35 lines
include/drm/drmP.h +0
-15@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */ struct inode *anon_inode;/**< inode for private address-space */ char *unique;/**< unique name of the device */ /*@} */ @@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,return ((dev->driver->driver_features & feature) ?1 :0 ); } -static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 ); -} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} -static inline bool drm_is_render_client (const struct drm_file *file_priv) {return file_priv->minor->type ==DRM_MINOR_RENDER ; --2.7.0.rc3.207.g0ac5344
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
Regarding the following comment:
drivers/gpu/drm/drm_fops.c int drm_release(struct inode *inode, struct file
Quoted 5 lines
drivers/gpu/drm/drm_fops.c +0
-0@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file
*filp)
Quoted 9 lines
drivers/gpu/drm/drm_fops.c +0
-2if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev);Again, you cannot drop this without replacement! In this case, you really should wrap
fops.release()from UDL and call intodrm_release()before copying this unplug-logic.
Does this really work? drm_release() will release minor at the end, regardless of dev->open_count.
If minor is released, can I still safely get dev and call drm_put_dev(dev) afterwards?
Quoted 273 lines · David Herrmann
Hi
Quoted 1 line · Haixia Shi
Remove the general
drm_device_is_unplugged()checks, and move theunplugged
Quoted 1 line
flag handling logic into drm/udl. In general we want to keep
driver-specific
Quoted 1 line
logic out of common drm code.
I like the idea of moving this hack into udl. However, I don't think this patch is sufficient, see below for comments.
Btw., hotplug might happen on other buses as well. It just happens that no-one tried pci/platform unplugging so far.. We used to have some patches flying around to make it work properly (with enter/leave markers), but no-one picked those up. But I like the idea of moving this unplugged marker into UDL, to make clear if someone else needs it, they better do it properly.
drivers/gpu/drm/drm_drv.c struct drm_minor *drm_minor_acquire(unsigned int
Quoted 21 lines
Signed-off-by Haixia Shi <[email protected]>Reviewed-by Stéphane Marchesin <[email protected]>--- drivers/gpu/drm/drm_drv.c | 6 ------ drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 --- drivers/gpu/drm/drm_ioctl.c | 3 --- drivers/gpu/drm/drm_vm.c | 3 --- drivers/gpu/drm/udl/udl_connector.c | 2 +- drivers/gpu/drm/udl/udl_drv.c | 1 + drivers/gpu/drm/udl/udl_drv.h | 3 +++ drivers/gpu/drm/udl/udl_fb.c | 2 +- drivers/gpu/drm/udl/udl_main.c | 15 +++++++++++++++ include/drm/drmP.h | 14 -------------- 11 files changed, 21 insertions(+), 33 deletions(-)drivers/gpu/drm/drm_drv.c +0
-0@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int
minor_id)drivers/gpu/drm/drm_drv.c struct drm_minor *drm_minor_acquire(unsigned int minor_id) · line 379
Quoted 7 lines
drivers/gpu/drm/drm_drv.c +0
-3if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }You cannot just drop this without a replacement. You should add a drm_driver.open callback to UDL which checks for this.
drm_minor_acquire()is only ever called fromdrm_stub_open(), and as such only fromdrm_open().Alternatively, you can provide fops.open from UDL and wrap
drm_open().drivers/gpu/drm/drm_drv.c void drm_unplug_dev(struct drm_device *dev) · line 469
Quoted 9 lines
drivers/gpu/drm/drm_drv.c +0
-3return minor;@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -You replace this by moving it into the caller of
drm_unplug_dev(). Sounds good to me. There has never been a real reason to put it underneath the global mutex, anyway.drivers/gpu/drm/drm_fops.c int drm_release(struct inode *inode, struct file
Quoted 8 lines
drivers/gpu/drm/drm_drv.c +0
-0if (dev->open_count ==0 ) {drm_put_dev (dev); }drivers/gpu/drm/drm_fops.c +0
-0@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file*filp)
drivers/gpu/drm/drm_fops.c int drm_release(struct inode *inode, struct file *filp) · line 501
Quoted 5 lines
drivers/gpu/drm/drm_fops.c +0
-2if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev);Again, you cannot drop this without replacement! In this case, you really should wrap
fops.release()from UDL and call intodrm_release()before copying this unplug-logic.drivers/gpu/drm/drm_gem.c int drm_gem_mmap(struct file *filp, struct
Quoted 8 lines
drivers/gpu/drm/drm_fops.c +0
-0}mutex_unlock (&drm_global_mutex);drivers/gpu/drm/drm_gem.c +0
-0@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct
vm_area_struct*vma)drivers/gpu/drm/drm_gem.c int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) · line 905
Quoted 6 lines
drivers/gpu/drm/drm_gem.c +0
-3struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -Rather than just dropping it, you better move it into
udl_drm_gem_mmap().drivers/gpu/drm/drm_gem.c int drm_gem_mmap(struct file *filp, struct · line 904
Quoted 2 lines
drivers/gpu/drm/drm_gem.c +0
-0drm_vma_offset_lock_lookup (dev->vma_offset_manager); node =drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager,
drivers/gpu/drm/drm_ioctl.c long drm_ioctl(struct file *filp, · line 700
Quoted 12 lines
drivers/gpu/drm/drm_gem.c +0
-0vma->vm_pgoff,drivers/gpu/drm/drm_ioctl.c +0
-3@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -You *must* provide a wrapper for
fops.ioctl()in udl which does this check.drivers/gpu/drm/drm_vm.c int drm_legacy_mmap(struct file *filp, struct
Quoted 8 lines
drivers/gpu/drm/drm_ioctl.c +0
-0is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {drivers/gpu/drm/drm_vm.c +0
-0@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct
vm_area_struct*vma)drivers/gpu/drm/drm_vm.c int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma) · line 662
Quoted 6 lines
drivers/gpu/drm/drm_vm.c +0
-3struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -This looks fine to me.
Review
Quoted 4 lines
drivers/gpu/drm/drm_vm.c +0
-0mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_connector.cdrivers/gpu/drm/udl/udl_connector.c static int udl_mode_valid(struct drm_connector
Quoted 4 lines
index 4709b54..b168f2c 100644
drivers/gpu/drm/udl/udl_connector.c +0
-0@@ -96,7 +96,7 @@ static int udl_mode_valid(struct drm_connector*connector,
Review
Quoted 9 lines
drivers/gpu/drm/udl/udl_connector.c +1
-1static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) +if (udl_device_is_unplugged (connector->dev))return connector_status_disconnected;return connector_status_connected; }(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_drv.cdrivers/gpu/drm/udl/udl_drv.c static void udl_usb_disconnect(struct usb_interface
Quoted 4 lines
index d5728ec..3cbafe7 100644
drivers/gpu/drm/udl/udl_drv.c +0
-0@@ -97,6 +97,7 @@ static void udl_usb_disconnect(struct usb_interface*interface)
drivers/gpu/drm/udl/udl_drv.c static void udl_usb_disconnect(struct usb_interface *interface) · line 101
Quoted 5 lines
drivers/gpu/drm/udl/udl_drv.c +1
-0drm_connector_unplug_all (dev);udl_fbdev_unplug (dev);udl_drop_usb (dev); +udl_device_set_unplugged (dev);drm_unplug_dev (dev);This looks good.
Review
Quoted 3 lines
drivers/gpu/drm/udl/udl_drv.c +0
-0}(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_drv.hdrivers/gpu/drm/udl/udl_drv.h struct udl_device { · line 65
Quoted 5 lines
index 4a064ef..61e117a 100644
drivers/gpu/drm/udl/udl_drv.h +0
-0@@ -65,6 +65,7 @@ struct udl_device {atomic_t bytes_identical;/* saved effort with backbuffer comparison */
drivers/gpu/drm/udl/udl_drv.h struct udl_device { · line 66
Quoted 1 line
drivers/gpu/drm/udl/udl_drv.h +0
-0atomic_t bytes_sent;/* to usb, after compression including overhead */
drivers/gpu/drm/udl/udl_drv.h struct udl_device { · line 67
Quoted 1 line
drivers/gpu/drm/udl/udl_drv.h +0
-0atomic_t cpu_kcycles_used;/* transpired during pixel processing */
drivers/gpu/drm/udl/udl_drv.h int udl_handle_damage(struct udl_framebuffer *fb,
Quoted 5 lines
drivers/gpu/drm/udl/udl_drv.h +1
-0+atomic_t unplugged;/* device has been unplugged or gone away */ };struct udl_gem_object {@@ -140,6 +141,8 @@ int udl_handle_damage(struct udl_framebuffer *fb,int x, int y,
drivers/gpu/drm/udl/udl_fb.c static int udl_fb_open(struct fb_info *info, int
Quoted 13 lines
drivers/gpu/drm/udl/udl_drv.h +2
-0int width, int height);int udl_drop_usb (struct drm_device *dev); +void udl_device_set_unplugged (struct drm_device *dev); +int udl_device_is_unplugged (struct drm_device *dev);#define CMD_WRITE_RAW8 "\xAF\x60"/**< 8 bit raw write command. */ #define CMD_WRITE_RL8 "\xAF\x61"/**< 8 bit run length command. */ drivers/gpu/drm/udl/udl_fb.c +0
-0@@ -325,7 +325,7 @@ static int udl_fb_open(struct fb_info *info, intuser)
Review
Quoted 9 lines
drivers/gpu/drm/udl/udl_fb.c +1
-1struct udl_device *udl = dev->dev_private;/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) +if (udl_device_is_unplugged (udl->ddev))return -ENODEV ; ufbdev->fb_count++;(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_main.cQuoted 12 lines
index 33dbfb2..f6028a4 100644
drivers/gpu/drm/udl/udl_main.c +5
-0@@ -350,3 +350,18 @@ int udl_driver_unload(struct drm_device *dev)kfree (udl);return 0 ; } + +void udl_device_set_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +smp_wmb ();drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev) · line 367
Quoted 10 lines
drivers/gpu/drm/udl/udl_main.c +10
-0+atomic_set (&udl->unplugged,1 ); +} + +int udl_device_is_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +int ret =atomic_read (&udl->unplugged); +smp_rmb (); +return ret; +}This looks fine to me.
Please make sure to wrap most of the
file_operationscallbacks in UDL and protect them with the "unplugged" check. Yes, we all know that this is racy, and always has been. However, it is still better than nothing. So please don't just drop them without any explanation!Thanks
Davidinclude/drm/drmP.h struct drm_device { · line 751
Quoted 9 lines
include/drm/drmP.h +0
-1@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */
include/drm/drmP.h struct drm_device { · line 751
Quoted 1 line
include/drm/drmP.h +0
-0struct inode *anon_inode;/**< inode for private address-space */
include/drm/drmP.h struct drm_device { · line 752
Quoted 1 line
include/drm/drmP.h +0
-0char *unique;/**< unique name of the device */
include/drm/drmP.h static __inline__ int drm_core_check_feature(struct
Quoted 2 lines
include/drm/drmP.h +0
-0/*@} */ @@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct
drm_device*dev,Quoted 3 lines
include/drm/drmP.h +0
-0return ((dev->driver->driver_features & feature) ?1 :0 ); }
Quoted 25 lines
Quoted 4 lines
include/drm/drmP.h +0
-4-static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 );include/drm/drmP.h static __inline__ int drm_core_check_feature(struct drm_device *dev,
Quoted 10 lines
include/drm/drmP.h +0
-9-} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} - static inline bool drm_is_render_client(const struct drm_file
*file_priv)Quoted 9 lines
include/drm/drmP.h +0
-1{return file_priv->minor->type ==DRM_MINOR_RENDER ; --2.7.0.rc3.207.g0ac5344
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
Hi
Quoted 14 lines · Haixia Shi
Regarding the following comment:
Quoted 11 lines
drivers/gpu/drm/drm_fops.c +0
-2@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file *filp)if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev);
Quoted 6 lines
Quoted 3 lines
Again, you cannot drop this without replacement! In this case, you really should wrap
fops.release()from UDL and call intodrm_release()before copying this unplug-logic.Does this really work?
drm_release()will release minor at the end, regardless ofdev->open_count.
"open_count" is about "drm_device". "drm_minor" is completely unrelated to this.
Quoted 2 lines
If minor is released, can I still safely get dev and call
drm_put_dev(dev)afterwards?
Of course!
David
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 2/2 drm: remove drm_device_is_unplugged checks in common drm code.
In reply to Haixia ShiWhen USB cable is disconnected, we mark udl device as unplugged so that udl_detect reports connector status as disconnected, but still keep the drm device alive until user-space closes it.
--- drivers/gpu/drm/drm_drv.c | 6 ------ drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 --- drivers/gpu/drm/drm_ioctl.c | 3 --- drivers/gpu/drm/drm_vm.c | 3 --- drivers/gpu/drm/udl/udl_connector.c | 2 +- drivers/gpu/drm/udl/udl_drv.c | 1 + drivers/gpu/drm/udl/udl_drv.h | 3 +++ drivers/gpu/drm/udl/udl_fb.c | 2 +- drivers/gpu/drm/udl/udl_main.c | 15 +++++++++++++++ include/drm/drmP.h | 14 -------------- 11 files changed, 21 insertions(+), 33 deletions(-)
drivers/gpu/drm/drm_drv.c +0 -6
@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id)if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }return minor;
@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -if (dev->open_count ==0 ) {drm_put_dev (dev); }
drivers/gpu/drm/drm_fops.c +0 -2
@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file *filp)if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev); }mutex_unlock (&drm_global_mutex);
drivers/gpu/drm/drm_gem.c +0 -3
@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -drm_vma_offset_lock_lookup (dev->vma_offset_manager); node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager, vma->vm_pgoff,
drivers/gpu/drm/drm_ioctl.c +0 -3
@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {
drivers/gpu/drm/drm_vm.c +0 -3
@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);
drivers/gpu/drm/udl/udl_connector.c +1 -1
@@ -96,7 +96,7 @@ static int udl_mode_valid(struct drm_connector *connector,static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) +if (udl_device_is_unplugged (connector->dev))return connector_status_disconnected;return connector_status_connected; }
drivers/gpu/drm/udl/udl_drv.c +1 -0
@@ -97,6 +97,7 @@ static void udl_usb_disconnect(struct usb_interface *interface)drm_connector_unplug_all (dev);udl_fbdev_unplug (dev);udl_drop_usb (dev); +udl_device_set_unplugged (dev);drm_unplug_dev (dev); }
drivers/gpu/drm/udl/udl_drv.h +3 -0
@@ -65,6 +65,7 @@ struct udl_device {atomic_t bytes_identical;/* saved effort with backbuffer comparison */ atomic_t bytes_sent;/* to usb, after compression including overhead */ atomic_t cpu_kcycles_used;/* transpired during pixel processing */ +atomic_t unplugged;/* device has been unplugged or gone away */ };struct udl_gem_object {
@@ -140,6 +141,8 @@ int udl_handle_damage(struct udl_framebuffer *fb, int x, int y, int width, int height);int udl_drop_usb (struct drm_device *dev); +void udl_device_set_unplugged (struct drm_device *dev); +int udl_device_is_unplugged (struct drm_device *dev);#define CMD_WRITE_RAW8 "\xAF\x60"/**< 8 bit raw write command. */ #define CMD_WRITE_RL8 "\xAF\x61"/**< 8 bit run length command. */
drivers/gpu/drm/udl/udl_fb.c +1 -1
@@ -325,7 +325,7 @@ static int udl_fb_open(struct fb_info *info, int user)struct udl_device *udl = dev->dev_private;/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) +if (udl_device_is_unplugged (udl->ddev))return -ENODEV ; ufbdev->fb_count++;
drivers/gpu/drm/udl/udl_main.c +15 -0
@@ -350,3 +350,18 @@ int udl_driver_unload(struct drm_device *dev)kfree (udl);return 0 ; } + +void udl_device_set_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +smp_wmb (); +atomic_set (&udl->unplugged,1 ); +} + +int udl_device_is_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +int ret =atomic_read (&udl->unplugged); +smp_rmb (); +return ret; +}
include/drm/drmP.h +0 -14
@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */ struct inode *anon_inode;/**< inode for private address-space */ char *unique;/**< unique name of the device */ /*@} */
@@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,return ((dev->driver->driver_features & feature) ?1 :0 ); } -static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 ); -} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} -static inline bool drm_is_render_client (const struct drm_file *file_priv) {return file_priv->minor->type ==DRM_MINOR_RENDER ;
Signature · 6 lines
2.7.0.rc3.207.g0ac5344 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi
Quoted 1 line · Haixia Shi
This flag is only used for drm/udl.
Furthermore, it is horribly racy. Lets not make use of it outside of udl.
Thanks
David
Quoted 23 lines
Signed-off-by Haixia Shi <[email protected]>Reviewed-by Stéphane Marchesin <[email protected]>--- drivers/gpu/drm/msm/msm_fbdev.c | 3 --- 1 file changed, 3 deletions(-)drivers/gpu/drm/msm/msm_fbdev.c +0
-4@@ -65,9 +65,6 @@ static int msm_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma)struct drm_device *dev = helper->dev;int ret =0 ; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - ret =drm_gem_mmap_obj (drm_obj, drm_obj->size, vma);if (ret) {pr_err ("%s:drm_gem_mmap_obj fail\n" , __func__); --2.7.0.rc3.207.g0ac5344
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Daniel Vetter
AppliedQuoted 8 lines · David Herrmann
Hi
Quoted 1 line · Haixia Shi
This flag is only used for drm/udl.
Furthermore, it is horribly racy. Lets not make use of it outside of udl.
Reviewed-by David Herrmann <[email protected]>
Applied to drm-misc (assuming that 2/2 will go in there too). -Daniel
Quoted 35 lines
Thanks
DavidQuoted 23 lines
Signed-off-by Haixia Shi <[email protected]>Reviewed-by Stéphane Marchesin <[email protected]>--- drivers/gpu/drm/msm/msm_fbdev.c | 3 --- 1 file changed, 3 deletions(-)drivers/gpu/drm/msm/msm_fbdev.c +0
-4@@ -65,9 +65,6 @@ static int msm_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma)struct drm_device *dev = helper->dev;int ret =0 ; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - ret =drm_gem_mmap_obj (drm_obj, drm_obj->size, vma);if (ret) {pr_err ("%s:drm_gem_mmap_obj fail\n" , __func__); --2.7.0.rc3.207.g0ac5344
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/2 drm: make unplugged flag specific to udl driver
In reply to Haixia ShiRemove the general drm_device_is_unplugged() checks, and move the unplugged flag handling logic into drm/udl. In general we want to keep driver-specific logic out of common drm code.
--- drivers/gpu/drm/drm_drv.c | 6 ---- drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 -- drivers/gpu/drm/drm_ioctl.c | 3 -- drivers/gpu/drm/drm_vm.c | 3 -- drivers/gpu/drm/udl/udl_connector.c | 2 +- drivers/gpu/drm/udl/udl_drv.c | 7 +++-- drivers/gpu/drm/udl/udl_drv.h | 6 ++++ drivers/gpu/drm/udl/udl_fb.c | 2 +- drivers/gpu/drm/udl/udl_gem.c | 5 +++ drivers/gpu/drm/udl/udl_main.c | 61 +++++++++++++++++++++++++++++++++++++ include/drm/drmP.h | 14 --------- 12 files changed, 78 insertions(+), 36 deletions(-)
drivers/gpu/drm/drm_drv.c +0 -6
@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id)if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }return minor;
@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -if (dev->open_count ==0 ) {drm_put_dev (dev); }
drivers/gpu/drm/drm_fops.c +0 -2
@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file *filp)if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev); }mutex_unlock (&drm_global_mutex);
drivers/gpu/drm/drm_gem.c +0 -3
@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -drm_vma_offset_lock_lookup (dev->vma_offset_manager); node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager, vma->vm_pgoff,
drivers/gpu/drm/drm_ioctl.c +0 -3
@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {
drivers/gpu/drm/drm_vm.c +0 -3
@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);
drivers/gpu/drm/udl/udl_connector.c +1 -1
@@ -96,7 +96,7 @@ static int udl_mode_valid(struct drm_connector *connector,static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) +if (udl_device_is_unplugged (connector->dev))return connector_status_disconnected;return connector_status_connected; }
drivers/gpu/drm/udl/udl_drv.c +4 -3
@@ -24,12 +24,12 @@ static const struct vm_operations_struct udl_gem_vm_ops = {static const struct file_operations udl_driver_fops = { .owner =THIS_MODULE , - .open = drm_open, + .open = udl_drm_open, .mmap = udl_drm_gem_mmap, .poll = drm_poll, .read = drm_read, - .unlocked_ioctl = drm_ioctl, - .release = drm_release, + .unlocked_ioctl = udl_drm_ioctl, + .release = udl_drm_release, #ifdef CONFIG_COMPAT .compat_ioctl = drm_compat_ioctl, #endif
@@ -97,6 +97,7 @@ static void udl_usb_disconnect(struct usb_interface *interface)drm_connector_unplug_all (dev);udl_fbdev_unplug (dev);udl_drop_usb (dev); +udl_device_set_unplugged (dev);drm_unplug_dev (dev); }
drivers/gpu/drm/udl/udl_drv.h +6 -0
@@ -65,6 +65,7 @@ struct udl_device {atomic_t bytes_identical;/* saved effort with backbuffer comparison */ atomic_t bytes_sent;/* to usb, after compression including overhead */ atomic_t cpu_kcycles_used;/* transpired during pixel processing */ +atomic_t unplugged;/* device has been unplugged or gone away */ };struct udl_gem_object {
@@ -133,6 +134,9 @@ int udl_gem_get_pages(struct udl_gem_object *obj);void udl_gem_put_pages (struct udl_gem_object *obj);int udl_gem_vmap (struct udl_gem_object *obj);void udl_gem_vunmap (struct udl_gem_object *obj); +int udl_drm_open (struct inode *inode,struct file *filp); +int udl_drm_release (struct inode *inode,struct file *filp); +int udl_drm_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);int udl_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma);int udl_gem_fault (struct vm_area_struct *vma,struct vm_fault *vmf);
@@ -140,6 +144,8 @@ int udl_handle_damage(struct udl_framebuffer *fb, int x, int y, int width, int height);int udl_drop_usb (struct drm_device *dev); +void udl_device_set_unplugged (struct drm_device *dev); +int udl_device_is_unplugged (struct drm_device *dev);#define CMD_WRITE_RAW8 "\xAF\x60"/**< 8 bit raw write command. */ #define CMD_WRITE_RL8 "\xAF\x61"/**< 8 bit run length command. */
drivers/gpu/drm/udl/udl_fb.c +1 -1
@@ -325,7 +325,7 @@ static int udl_fb_open(struct fb_info *info, int user)struct udl_device *udl = dev->dev_private;/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) +if (udl_device_is_unplugged (udl->ddev))return -ENODEV ; ufbdev->fb_count++;
drivers/gpu/drm/udl/udl_gem.c +5 -0
@@ -86,8 +86,13 @@ int udl_dumb_create(struct drm_file *file,int udl_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma) { +struct drm_file *priv = filp->private_data; +struct drm_device *dev = priv->minor->dev;int ret; +if (udl_device_is_unplugged (dev)) +return -ENODEV ; + ret =drm_gem_mmap (filp, vma);if (ret)return ret;
drivers/gpu/drm/udl/udl_main.c +61 -0
64 lines not on this page · raw message
include/drm/drmP.h +0 -14
@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */ struct inode *anon_inode;/**< inode for private address-space */ char *unique;/**< unique name of the device */ /*@} */
@@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,return ((dev->driver->driver_features & feature) ?1 :0 ); } -static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 ); -} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} -static inline bool drm_is_render_client (const struct drm_file *file_priv) {return file_priv->minor->type ==DRM_MINOR_RENDER ;
Signature · 6 lines
2.7.0.rc3.207.g0ac5344 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
Quoted 6 lines · Haixia Shi
Remove the general
drm_device_is_unplugged()checks, and move the unplugged flag handling logic into drm/udl. In general we want to keep driver-specific logic out of common drm code.Signed-off-by Haixia Shi <[email protected]>Reviewed-by Stéphane Marchesin <[email protected]>
Looks like this is v2 to address David's feedback, but doesn't mention that anywhere. Please resend with:
- v2 added, plus a small in-patch changelog of what you've changed in the commit message (see other patches on dri-devel).
- add David to the Cc: section of the patch to make sure he doesn't miss it.
Thanks, Daniel
Quoted 305 lines
--- drivers/gpu/drm/drm_drv.c | 6 ---- drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 -- drivers/gpu/drm/drm_ioctl.c | 3 -- drivers/gpu/drm/drm_vm.c | 3 -- drivers/gpu/drm/udl/udl_connector.c | 2 +- drivers/gpu/drm/udl/udl_drv.c | 7 +++-- drivers/gpu/drm/udl/udl_drv.h | 6 ++++ drivers/gpu/drm/udl/udl_fb.c | 2 +- drivers/gpu/drm/udl/udl_gem.c | 5 +++ drivers/gpu/drm/udl/udl_main.c | 61 +++++++++++++++++++++++++++++++++++++ include/drm/drmP.h | 14 --------- 12 files changed, 78 insertions(+), 36 deletions(-)drivers/gpu/drm/drm_drv.c +0
-6@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id)if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }return minor;@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -if (dev->open_count ==0 ) {drm_put_dev (dev); }drivers/gpu/drm/drm_fops.c +0
-2@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file *filp)if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev); }mutex_unlock (&drm_global_mutex);drivers/gpu/drm/drm_gem.c +0
-3@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -drm_vma_offset_lock_lookup (dev->vma_offset_manager); node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager, vma->vm_pgoff,drivers/gpu/drm/drm_ioctl.c +0
-3@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {drivers/gpu/drm/drm_vm.c +0
-3@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);drivers/gpu/drm/udl/udl_connector.c +1
-1@@ -96,7 +96,7 @@ static int udl_mode_valid(struct drm_connector *connector,static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) +if (udl_device_is_unplugged (connector->dev))return connector_status_disconnected;return connector_status_connected; }drivers/gpu/drm/udl/udl_drv.c +4
-3@@ -24,12 +24,12 @@ static const struct vm_operations_struct udl_gem_vm_ops = {static const struct file_operations udl_driver_fops = { .owner =THIS_MODULE , - .open = drm_open, + .open = udl_drm_open, .mmap = udl_drm_gem_mmap, .poll = drm_poll, .read = drm_read, - .unlocked_ioctl = drm_ioctl, - .release = drm_release, + .unlocked_ioctl = udl_drm_ioctl, + .release = udl_drm_release, #ifdef CONFIG_COMPAT .compat_ioctl = drm_compat_ioctl, #endif@@ -97,6 +97,7 @@ static void udl_usb_disconnect(struct usb_interface *interface)drm_connector_unplug_all (dev);udl_fbdev_unplug (dev);udl_drop_usb (dev); +udl_device_set_unplugged (dev);drm_unplug_dev (dev); }drivers/gpu/drm/udl/udl_drv.h +6
-0@@ -65,6 +65,7 @@ struct udl_device {atomic_t bytes_identical;/* saved effort with backbuffer comparison */ atomic_t bytes_sent;/* to usb, after compression including overhead */ atomic_t cpu_kcycles_used;/* transpired during pixel processing */ +atomic_t unplugged;/* device has been unplugged or gone away */ };struct udl_gem_object {@@ -133,6 +134,9 @@ int udl_gem_get_pages(struct udl_gem_object *obj);void udl_gem_put_pages (struct udl_gem_object *obj);int udl_gem_vmap (struct udl_gem_object *obj);void udl_gem_vunmap (struct udl_gem_object *obj); +int udl_drm_open (struct inode *inode,struct file *filp); +int udl_drm_release (struct inode *inode,struct file *filp); +int udl_drm_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);int udl_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma);int udl_gem_fault (struct vm_area_struct *vma,struct vm_fault *vmf);@@ -140,6 +144,8 @@ int udl_handle_damage(struct udl_framebuffer *fb, int x, int y, int width, int height);int udl_drop_usb (struct drm_device *dev); +void udl_device_set_unplugged (struct drm_device *dev); +int udl_device_is_unplugged (struct drm_device *dev);#define CMD_WRITE_RAW8 "\xAF\x60"/**< 8 bit raw write command. */ #define CMD_WRITE_RL8 "\xAF\x61"/**< 8 bit run length command. */ drivers/gpu/drm/udl/udl_fb.c +1
-1@@ -325,7 +325,7 @@ static int udl_fb_open(struct fb_info *info, int user)struct udl_device *udl = dev->dev_private;/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) +if (udl_device_is_unplugged (udl->ddev))return -ENODEV ; ufbdev->fb_count++;drivers/gpu/drm/udl/udl_gem.c +5
-0@@ -86,8 +86,13 @@ int udl_dumb_create(struct drm_file *file,int udl_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma) { +struct drm_file *priv = filp->private_data; +struct drm_device *dev = priv->minor->dev;int ret; +if (udl_device_is_unplugged (dev)) +return -ENODEV ; + ret =drm_gem_mmap (filp, vma);if (ret)return ret;drivers/gpu/drm/udl/udl_main.c +61
-0@@ -350,3 +350,64 @@ int udl_driver_unload(struct drm_device *dev)kfree (udl);return 0 ; } + +int udl_drm_open (struct inode *inode,struct file *filp) +{ +struct drm_file *file_priv; +struct drm_minor *minor; + +int ret =drm_open (inode, filp); +if (ret) +return ret; + + file_priv = filp->private_data; + minor = file_priv->minor; +if (udl_device_is_unplugged (minor->dev)) { +drm_dev_unref (minor->dev); +return -ENODEV ; + } + +return 0 ; +} + +int udl_drm_release (struct inode *inode,struct file *filp) +{ +struct drm_file *file_priv = filp->private_data; +struct drm_device *dev = file_priv->minor->dev; + +int ret =drm_release (inode, filp); +if (!dev->open_count &&udl_device_is_unplugged (dev)) +drm_put_dev (dev); + +return ret; +} + +int udl_drm_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) +{ +struct drm_file *file_priv = filp->private_data; +struct drm_device *dev = file_priv->minor->dev; +unsigned int nr =DRM_IOCTL_NR (cmd); + +if (udl_device_is_unplugged (dev) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_SETCRTC ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_RMFB ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_DESTROY_DUMB )) +return -ENODEV ; + +return drm_ioctl (filp, cmd, arg); +} + +void udl_device_set_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +smp_wmb (); +atomic_set (&udl->unplugged,1 ); +} + +int udl_device_is_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +int ret =atomic_read (&udl->unplugged); +smp_rmb (); +return ret; +}include/drm/drmP.h +0
-14@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */ struct inode *anon_inode;/**< inode for private address-space */ char *unique;/**< unique name of the device */ /*@} */ @@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,return ((dev->driver->driver_features & feature) ?1 :0 ); } -static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 ); -} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} -static inline bool drm_is_render_client (const struct drm_file *file_priv) {return file_priv->minor->type ==DRM_MINOR_RENDER ;Signature · 6 lines
2.7.0.rc3.207.g0ac5344 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
In reply to Haixia ShiHi
Quoted 217 lines · Haixia Shi
Remove the general
drm_device_is_unplugged()checks, and move the unplugged flag handling logic into drm/udl. In general we want to keep driver-specific logic out of common drm code.Signed-off-by Haixia Shi <[email protected]>Reviewed-by Stéphane Marchesin <[email protected]>--- drivers/gpu/drm/drm_drv.c | 6 ---- drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 -- drivers/gpu/drm/drm_ioctl.c | 3 -- drivers/gpu/drm/drm_vm.c | 3 -- drivers/gpu/drm/udl/udl_connector.c | 2 +- drivers/gpu/drm/udl/udl_drv.c | 7 +++-- drivers/gpu/drm/udl/udl_drv.h | 6 ++++ drivers/gpu/drm/udl/udl_fb.c | 2 +- drivers/gpu/drm/udl/udl_gem.c | 5 +++ drivers/gpu/drm/udl/udl_main.c | 61 +++++++++++++++++++++++++++++++++++++ include/drm/drmP.h | 14 --------- 12 files changed, 78 insertions(+), 36 deletions(-)drivers/gpu/drm/drm_drv.c +0
-6@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id)if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }return minor;@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -if (dev->open_count ==0 ) {drm_put_dev (dev); }drivers/gpu/drm/drm_fops.c +0
-2@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file *filp)if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev); }mutex_unlock (&drm_global_mutex);drivers/gpu/drm/drm_gem.c +0
-3@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -drm_vma_offset_lock_lookup (dev->vma_offset_manager); node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager, vma->vm_pgoff,drivers/gpu/drm/drm_ioctl.c +0
-3@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {drivers/gpu/drm/drm_vm.c +0
-3@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);drivers/gpu/drm/udl/udl_connector.c +1
-1@@ -96,7 +96,7 @@ static int udl_mode_valid(struct drm_connector *connector,static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) +if (udl_device_is_unplugged (connector->dev))return connector_status_disconnected;return connector_status_connected; }drivers/gpu/drm/udl/udl_drv.c +4
-3@@ -24,12 +24,12 @@ static const struct vm_operations_struct udl_gem_vm_ops = {static const struct file_operations udl_driver_fops = { .owner =THIS_MODULE , - .open = drm_open, + .open = udl_drm_open, .mmap = udl_drm_gem_mmap, .poll = drm_poll, .read = drm_read, - .unlocked_ioctl = drm_ioctl, - .release = drm_release, + .unlocked_ioctl = udl_drm_ioctl, + .release = udl_drm_release, #ifdef CONFIG_COMPAT .compat_ioctl = drm_compat_ioctl, #endif@@ -97,6 +97,7 @@ static void udl_usb_disconnect(struct usb_interface *interface)drm_connector_unplug_all (dev);udl_fbdev_unplug (dev);udl_drop_usb (dev); +udl_device_set_unplugged (dev);drm_unplug_dev (dev); }drivers/gpu/drm/udl/udl_drv.h +6
-0@@ -65,6 +65,7 @@ struct udl_device {atomic_t bytes_identical;/* saved effort with backbuffer comparison */ atomic_t bytes_sent;/* to usb, after compression including overhead */ atomic_t cpu_kcycles_used;/* transpired during pixel processing */ +atomic_t unplugged;/* device has been unplugged or gone away */ };struct udl_gem_object {@@ -133,6 +134,9 @@ int udl_gem_get_pages(struct udl_gem_object *obj);void udl_gem_put_pages (struct udl_gem_object *obj);int udl_gem_vmap (struct udl_gem_object *obj);void udl_gem_vunmap (struct udl_gem_object *obj); +int udl_drm_open (struct inode *inode,struct file *filp); +int udl_drm_release (struct inode *inode,struct file *filp); +int udl_drm_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);int udl_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma);int udl_gem_fault (struct vm_area_struct *vma,struct vm_fault *vmf);@@ -140,6 +144,8 @@ int udl_handle_damage(struct udl_framebuffer *fb, int x, int y, int width, int height);int udl_drop_usb (struct drm_device *dev); +void udl_device_set_unplugged (struct drm_device *dev); +int udl_device_is_unplugged (struct drm_device *dev);#define CMD_WRITE_RAW8 "\xAF\x60"/**< 8 bit raw write command. */ #define CMD_WRITE_RL8 "\xAF\x61"/**< 8 bit run length command. */ drivers/gpu/drm/udl/udl_fb.c +1
-1@@ -325,7 +325,7 @@ static int udl_fb_open(struct fb_info *info, int user)struct udl_device *udl = dev->dev_private;/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) +if (udl_device_is_unplugged (udl->ddev))return -ENODEV ; ufbdev->fb_count++;drivers/gpu/drm/udl/udl_gem.c +5
-0@@ -86,8 +86,13 @@ int udl_dumb_create(struct drm_file *file,int udl_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma) { +struct drm_file *priv = filp->private_data; +struct drm_device *dev = priv->minor->dev;int ret; +if (udl_device_is_unplugged (dev)) +return -ENODEV ; + ret =drm_gem_mmap (filp, vma);if (ret)return ret;drivers/gpu/drm/udl/udl_main.c +6
-0@@ -350,3 +350,64 @@ int udl_driver_unload(struct drm_device *dev)kfree (udl);return 0 ; } + +int udl_drm_open (struct inode *inode,struct file *filp) +{ +struct drm_file *file_priv; +struct drm_minor *minor; +
drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev) · line 368
Quoted 10 lines
drivers/gpu/drm/udl/udl_main.c +10
-0+int ret =drm_open (inode, filp); +if (ret) +return ret; + + file_priv = filp->private_data; + minor = file_priv->minor; +if (udl_device_is_unplugged (minor->dev)) { +drm_dev_unref (minor->dev); +return -ENODEV ; + }
This doesn't make sense to me. You're called here with global-mutex held, so you can just check udl_device_is_unplugged() before calling into drm_open().
drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev) · line 380
Quoted 12 lines
drivers/gpu/drm/udl/udl_main.c +12
-0+ +return 0 ; +} + +int udl_drm_release (struct inode *inode,struct file *filp) +{ +struct drm_file *file_priv = filp->private_data; +struct drm_device *dev = file_priv->minor->dev; + +int ret =drm_release (inode, filp); +if (!dev->open_count &&udl_device_is_unplugged (dev)) +drm_put_dev (dev);
This should rather be:
drm_release(inode, filp);
mutex_lock(&drm_global_mutex);
if (!dev->open_count && udl_device_is_unplugged(dev))
drm_put_dev(dev);
mutex_unlock(&drm_global_mutex);
return 0;There is no reason to look at the return code of drm_release(), ever.
Quoted 5 lines
drivers/gpu/drm/udl/udl_main.c +5
-0+ +return ret; +} + +int udl_drm_ioctl (struct file *filp,unsigned int cmd,unsigned long arg)
drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev) · line 395
Quoted 10 lines
drivers/gpu/drm/udl/udl_main.c +10
-0+{ +struct drm_file *file_priv = filp->private_data; +struct drm_device *dev = file_priv->minor->dev; +unsigned int nr =DRM_IOCTL_NR (cmd); + +if (udl_device_is_unplugged (dev) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_SETCRTC ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_RMFB ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_DESTROY_DUMB )) +return -ENODEV ;
Why?
Just do:
if (udl_device_is_unplugged(dev))
return -ENODEV;Why this complex logic here?
Thanks
David
Quoted 51 lines
drivers/gpu/drm/udl/udl_main.c +18
-0+ +return drm_ioctl (filp, cmd, arg); +} + +void udl_device_set_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +smp_wmb (); +atomic_set (&udl->unplugged,1 ); +} + +int udl_device_is_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +int ret =atomic_read (&udl->unplugged); +smp_rmb (); +return ret; +}include/drm/drmP.h +0
-15@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */ struct inode *anon_inode;/**< inode for private address-space */ char *unique;/**< unique name of the device */ /*@} */ @@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,return ((dev->driver->driver_features & feature) ?1 :0 ); } -static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 ); -} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} -static inline bool drm_is_render_client (const struct drm_file *file_priv) {return file_priv->minor->type ==DRM_MINOR_RENDER ; --
Quoted 2 lines
2.7.0.rc3.207.g0ac5344
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
Quoted 6 lines
drivers/gpu/drm/udl/udl_main.c +5
-0+if (udl_device_is_unplugged (dev) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_SETCRTC ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_RMFB ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_DESTROY_DUMB )) +return -ENODEV ;
Quoted 8 lines
Why?
Just do:
if (udl_device_is_unplugged(dev)) return -ENODEV;Why this complex logic here?
Because there are legitimate ioctl calls after UDL is unplugged. See crbug.com/583508 and crbug.com/583758 for some background.
The userspace (Chrome in this case) has allocated FBs and Dumb buffers on the drm device and needs to be given a chance to properly deallocate them (via RMFB and DESTROY_DUMB). In addition, it needs to call SETCRTC with fb_id = 0 to properly release the last refcount on the primary fb.
I initially proposed adding an "UNPLUG_DISALLOW" flag to ioctls so that we can whitelist them on a case-by-case basis but that proposal got shot down as being unnecessary, but you can see my original patch at
https://chromium-review.googlesource.com/#/c/326160/
Quoted 349 lines · David Herrmann
Hi
Quoted 1 line · Haixia Shi
Remove the general
drm_device_is_unplugged()checks, and move theunplugged
Quoted 1 line
flag handling logic into drm/udl. In general we want to keep
driver-specific
Quoted 4 lines
logic out of common drm code.
Signed-off-by Haixia Shi <[email protected]>Reviewed-by Stéphane Marchesin <[email protected]>Quoted 12 lines
--- drivers/gpu/drm/drm_drv.c | 6 ---- drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 -- drivers/gpu/drm/drm_ioctl.c | 3 -- drivers/gpu/drm/drm_vm.c | 3 -- drivers/gpu/drm/udl/udl_connector.c | 2 +- drivers/gpu/drm/udl/udl_drv.c | 7 +++-- drivers/gpu/drm/udl/udl_drv.h | 6 ++++ drivers/gpu/drm/udl/udl_fb.c | 2 +- drivers/gpu/drm/udl/udl_gem.c | 5 +++ drivers/gpu/drm/udl/udl_main.c | 61+++++++++++++++++++++++++++++++++++++
drivers/gpu/drm/drm_drv.c struct drm_minor *drm_minor_acquire(unsigned int
Quoted 8 lines
include/drm/drmP.h | 14 --------- 12 files changed, 78 insertions(+), 36 deletions(-)drivers/gpu/drm/drm_drv.c +0
-0@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int
minor_id)drivers/gpu/drm/drm_fops.c int drm_release(struct inode *inode, struct file
Quoted 24 lines
drivers/gpu/drm/drm_drv.c +0
-6if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }return minor;@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -if (dev->open_count ==0 ) {drm_put_dev (dev); }drivers/gpu/drm/drm_fops.c +0
-0@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file*filp)
drivers/gpu/drm/drm_gem.c int drm_gem_mmap(struct file *filp, struct
Quoted 13 lines
drivers/gpu/drm/drm_fops.c +0
-2if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev); }mutex_unlock (&drm_global_mutex);drivers/gpu/drm/drm_gem.c +0
-0@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct
vm_area_struct*vma)drivers/gpu/drm/drm_gem.c int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)
Quoted 8 lines
drivers/gpu/drm/drm_gem.c +0
-3struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -drm_vma_offset_lock_lookup (dev->vma_offset_manager); node =drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager,
drivers/gpu/drm/drm_vm.c int drm_legacy_mmap(struct file *filp, struct
Quoted 20 lines
drivers/gpu/drm/drm_gem.c +0
-0vma->vm_pgoff,drivers/gpu/drm/drm_ioctl.c +0
-3@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {drivers/gpu/drm/drm_vm.c +0
-0@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct
vm_area_struct*vma)Review
Quoted 10 lines
drivers/gpu/drm/drm_vm.c +0
-3struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_connector.cdrivers/gpu/drm/udl/udl_connector.c static int udl_mode_valid(struct drm_connector
Quoted 4 lines
index 4709b54..b168f2c 100644
drivers/gpu/drm/udl/udl_connector.c +0
-0@@ -96,7 +96,7 @@ static int udl_mode_valid(struct drm_connector*connector,
Review
Quoted 9 lines
drivers/gpu/drm/udl/udl_connector.c +1
-1static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) +if (udl_device_is_unplugged (connector->dev))return connector_status_disconnected;return connector_status_connected; }(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_drv.cdrivers/gpu/drm/udl/udl_drv.c static const struct vm_operations_struct
Quoted 4 lines
index d5728ec..f5c2a97 100644
drivers/gpu/drm/udl/udl_drv.c +0
-0@@ -24,12 +24,12 @@ static const struct vm_operations_struct
udl_gem_vm_ops= {drivers/gpu/drm/udl/udl_drv.c static void udl_usb_disconnect(struct usb_interface
Quoted 16 lines
drivers/gpu/drm/udl/udl_drv.c +3
-3static const struct file_operations udl_driver_fops = { .owner =THIS_MODULE , - .open = drm_open, + .open = udl_drm_open, .mmap = udl_drm_gem_mmap, .poll = drm_poll, .read = drm_read, - .unlocked_ioctl = drm_ioctl, - .release = drm_release, + .unlocked_ioctl = udl_drm_ioctl, + .release = udl_drm_release, #ifdef CONFIG_COMPAT .compat_ioctl = drm_compat_ioctl, #endif@@ -97,6 +97,7 @@ static void udl_usb_disconnect(struct usb_interface*interface)
Review
Quoted 8 lines
drivers/gpu/drm/udl/udl_drv.c +1
-0drm_connector_unplug_all (dev);udl_fbdev_unplug (dev);udl_drop_usb (dev); +udl_device_set_unplugged (dev);drm_unplug_dev (dev); }(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_drv.hdrivers/gpu/drm/udl/udl_drv.h struct udl_device { · line 65
Quoted 5 lines
index 4a064ef..75aa91c 100644
drivers/gpu/drm/udl/udl_drv.h +0
-0@@ -65,6 +65,7 @@ struct udl_device {atomic_t bytes_identical;/* saved effort with backbuffer comparison */
drivers/gpu/drm/udl/udl_drv.h struct udl_device { · line 66
Quoted 1 line
drivers/gpu/drm/udl/udl_drv.h +0
-0atomic_t bytes_sent;/* to usb, after compression including overhead */
drivers/gpu/drm/udl/udl_drv.h struct udl_device { · line 67
Quoted 1 line
drivers/gpu/drm/udl/udl_drv.h +0
-0atomic_t cpu_kcycles_used;/* transpired during pixel processing */
drivers/gpu/drm/udl/udl_drv.h int udl_gem_get_pages(struct udl_gem_object *obj); · line 139
Quoted 11 lines
drivers/gpu/drm/udl/udl_drv.h +4
-0+atomic_t unplugged;/* device has been unplugged or gone away */ };struct udl_gem_object {@@ -133,6 +134,9 @@ int udl_gem_get_pages(struct udl_gem_object *obj);void udl_gem_put_pages (struct udl_gem_object *obj);int udl_gem_vmap (struct udl_gem_object *obj);void udl_gem_vunmap (struct udl_gem_object *obj); +int udl_drm_open (struct inode *inode,struct file *filp); +int udl_drm_release (struct inode *inode,struct file *filp); +int udl_drm_ioctl(struct file *filp, unsigned int cmd, unsigned longarg);
drivers/gpu/drm/udl/udl_drv.h int udl_handle_damage(struct udl_framebuffer *fb,
Quoted 4 lines
drivers/gpu/drm/udl/udl_drv.h +0
-0int udl_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma);int udl_gem_fault (struct vm_area_struct *vma,struct vm_fault *vmf);@@ -140,6 +144,8 @@ int udl_handle_damage(struct udl_framebuffer *fb,int x, int y,
drivers/gpu/drm/udl/udl_fb.c static int udl_fb_open(struct fb_info *info, int
Quoted 13 lines
drivers/gpu/drm/udl/udl_drv.h +2
-0int width, int height);int udl_drop_usb (struct drm_device *dev); +void udl_device_set_unplugged (struct drm_device *dev); +int udl_device_is_unplugged (struct drm_device *dev);#define CMD_WRITE_RAW8 "\xAF\x60"/**< 8 bit raw write command. */ #define CMD_WRITE_RL8 "\xAF\x61"/**< 8 bit run length command. */ drivers/gpu/drm/udl/udl_fb.c +0
-0@@ -325,7 +325,7 @@ static int udl_fb_open(struct fb_info *info, intuser)
Review
Quoted 9 lines
drivers/gpu/drm/udl/udl_fb.c +1
-1struct udl_device *udl = dev->dev_private;/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) +if (udl_device_is_unplugged (udl->ddev))return -ENODEV ; ufbdev->fb_count++;(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_gem.cReview
Quoted 18 lines
index 2a0a784..33c302f 100644
drivers/gpu/drm/udl/udl_gem.c +5
-0@@ -86,8 +86,13 @@ int udl_dumb_create(struct drm_file *file,int udl_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma) { +struct drm_file *priv = filp->private_data; +struct drm_device *dev = priv->minor->dev;int ret; +if (udl_device_is_unplugged (dev)) +return -ENODEV ; + ret =drm_gem_mmap (filp, vma);if (ret)return ret;(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_main.cQuoted 13 lines
index 33dbfb2..2ba3ee3 100644
drivers/gpu/drm/udl/udl_main.c +6
-0@@ -350,3 +350,64 @@ int udl_driver_unload(struct drm_device *dev)kfree (udl);return 0 ; } + +int udl_drm_open (struct inode *inode,struct file *filp) +{ +struct drm_file *file_priv; +struct drm_minor *minor; +drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev) · line 368
Quoted 10 lines
drivers/gpu/drm/udl/udl_main.c +10
-0+int ret =drm_open (inode, filp); +if (ret) +return ret; + + file_priv = filp->private_data; + minor = file_priv->minor; +if (udl_device_is_unplugged (minor->dev)) { +drm_dev_unref (minor->dev); +return -ENODEV ; + }This doesn't make sense to me. You're called here with global-mutex held, so you can just check
udl_device_is_unplugged()before calling intodrm_open().drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev) · line 380
Quoted 12 lines
drivers/gpu/drm/udl/udl_main.c +12
-0+ +return 0 ; +} + +int udl_drm_release (struct inode *inode,struct file *filp) +{ +struct drm_file *file_priv = filp->private_data; +struct drm_device *dev = file_priv->minor->dev; + +int ret =drm_release (inode, filp); +if (!dev->open_count &&udl_device_is_unplugged (dev)) +drm_put_dev (dev);This should rather be:
drm_release(inode, filp); mutex_lock(&drm_global_mutex); if (!dev->open_count && udl_device_is_unplugged(dev)) drm_put_dev(dev); mutex_unlock(&drm_global_mutex); return 0;There is no reason to look at the return code of
drm_release(), ever.drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev)
Quoted 5 lines
drivers/gpu/drm/udl/udl_main.c +5
-0+ +return ret; +} + +int udl_drm_ioctl(struct file *filp, unsigned int cmd, unsigned longarg)
drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev) · line 395
Quoted 10 lines
drivers/gpu/drm/udl/udl_main.c +10
-0+{ +struct drm_file *file_priv = filp->private_data; +struct drm_device *dev = file_priv->minor->dev; +unsigned int nr =DRM_IOCTL_NR (cmd); + +if (udl_device_is_unplugged (dev) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_SETCRTC ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_RMFB ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_DESTROY_DUMB )) +return -ENODEV ;Why?
Just do:
if (udl_device_is_unplugged(dev)) return -ENODEV;Why this complex logic here?
Thanks
DavidQuoted 23 lines
drivers/gpu/drm/udl/udl_main.c +18
-0+ +return drm_ioctl (filp, cmd, arg); +} + +void udl_device_set_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +smp_wmb (); +atomic_set (&udl->unplugged,1 ); +} + +int udl_device_is_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +int ret =atomic_read (&udl->unplugged); +smp_rmb (); +return ret; +}include/drm/drmP.h +0
-0include/drm/drmP.h struct drm_device { · line 751
Quoted 4 lines
include/drm/drmP.h +0
-1@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */
include/drm/drmP.h struct drm_device { · line 751
Quoted 1 line
include/drm/drmP.h +0
-0struct inode *anon_inode;/**< inode for private address-space */
include/drm/drmP.h struct drm_device { · line 752
Quoted 1 line
include/drm/drmP.h +0
-0char *unique;/**< unique name of the device */
include/drm/drmP.h static __inline__ int drm_core_check_feature(struct
Quoted 2 lines
include/drm/drmP.h +0
-0/*@} */ @@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct
drm_device*dev,Quoted 3 lines
include/drm/drmP.h +0
-0return ((dev->driver->driver_features & feature) ?1 :0 ); }
Quoted 21 lines
Quoted 4 lines
include/drm/drmP.h +0
-4-static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 );include/drm/drmP.h static __inline__ int drm_core_check_feature(struct drm_device *dev,
Quoted 10 lines
include/drm/drmP.h +0
-9-} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} - static inline bool drm_is_render_client(const struct drm_file
*file_priv)Quoted 5 lines
include/drm/drmP.h +0
-1{return file_priv->minor->type ==DRM_MINOR_RENDER ; --2.7.0.rc3.207.g0ac5344
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
Hi
Quoted 24 lines · Haixia Shi
Quoted 7 lines
drivers/gpu/drm/udl/udl_main.c +5
-0+if (udl_device_is_unplugged (dev) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_SETCRTC ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_RMFB ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_DESTROY_DUMB )) +return -ENODEV ;Quoted 8 lines
Why?
Just do:
if (udl_device_is_unplugged(dev)) return -ENODEV;Why this complex logic here?
Because there are legitimate ioctl calls after UDL is unplugged. See crbug.com/583508 and crbug.com/583758 for some background.
The userspace (Chrome in this case) has allocated FBs and Dumb buffers on the drm device and needs to be given a chance to properly deallocate them (via RMFB and
DESTROY_DUMB). In addition, it needs to call SETCRTC withfb_id= 0 to properly release the last refcount on the primary fb.
Quoted 4 lines
I initially proposed adding an "
UNPLUG_DISALLOW" flag to ioctls so that we can whitelist them on a case-by-case basis but that proposal got shot down as being unnecessary, but you can see my original patch at
https://chromium-review.googlesource.com/#/c/326160/
If a device is unplugged, you should consider all your resources to be destroyed. There is no reason to release them manually. User-space *must* be able to deal with asynchronous unplugs.
If UDL does not release your resources, and you actually hit bugs due to this, then fix UDL to do this. But extending the already broken UNPLUG-hacks we have sounds wrong to me.
Anyway, this change is unrelated to your patch, so please drop it. Feel free to send a separate patch, if you want to continue the discussion.
Thanks
David
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
Quoted 27 lines · David Herrmann
Hi
Quoted 24 lines · Haixia Shi
Quoted 7 lines
drivers/gpu/drm/udl/udl_main.c +5
-0+if (udl_device_is_unplugged (dev) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_SETCRTC ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_RMFB ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_DESTROY_DUMB )) +return -ENODEV ;Quoted 8 lines
Why?
Just do:
if (udl_device_is_unplugged(dev)) return -ENODEV;Why this complex logic here?
Because there are legitimate ioctl calls after UDL is unplugged. See crbug.com/583508 and crbug.com/583758 for some background.
The userspace (Chrome in this case) has allocated FBs and Dumb buffers on the drm device and needs to be given a chance to properly deallocate them (via RMFB and
DESTROY_DUMB). In addition, it needs to call SETCRTC withfb_id= 0 to properly release the last refcount on the primary fb.
Quoted 8 lines
Quoted 4 lines
I initially proposed adding an "
UNPLUG_DISALLOW" flag to ioctls so that we can whitelist them on a case-by-case basis but that proposal got shot down as being unnecessary, but you can see my original patch at
https://chromium-review.googlesource.com/#/c/326160/If a device is unplugged, you should consider all your resources to be destroyed. There is no reason to release them manually. User-space *must* be able to deal with asynchronous unplugs.
So the problem if you do that is that things like a buffer's memory pages can disappear from under you. How would you deal with that case? User space certainly can't have a segfault handler catch that just in case :)
Stéphane
Quoted 9 lines
If UDL does not release your resources, and you actually hit bugs due to this, then fix UDL to do this. But extending the already broken UNPLUG-hacks we have sounds wrong to me.
Anyway, this change is unrelated to your patch, so please drop it. Feel free to send a separate patch, if you want to continue the discussion.
Quoted 6 lines
Thanks
David
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
Hi
Quoted 33 lines · Stéphane Marchesin
Quoted 32 lines · David Herrmann
Hi
Quoted 28 lines · Haixia Shi
Quoted 7 lines
drivers/gpu/drm/udl/udl_main.c +5
-0+if (udl_device_is_unplugged (dev) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_SETCRTC ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_RMFB ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_DESTROY_DUMB )) +return -ENODEV ;Quoted 8 lines
Why?
Just do:
if (udl_device_is_unplugged(dev)) return -ENODEV;Why this complex logic here?
Because there are legitimate ioctl calls after UDL is unplugged. See crbug.com/583508 and crbug.com/583758 for some background.
The userspace (Chrome in this case) has allocated FBs and Dumb buffers on the drm device and needs to be given a chance to properly deallocate them (via RMFB and
DESTROY_DUMB). In addition, it needs to call SETCRTC withfb_id= 0 to properly release the last refcount on the primary fb.I initially proposed adding an "
UNPLUG_DISALLOW" flag to ioctls so that we can whitelist them on a case-by-case basis but that proposal got shot down as being unnecessary, but you can see my original patch at
https://chromium-review.googlesource.com/#/c/326160/
Quoted 8 lines
Quoted 3 lines
If a device is unplugged, you should consider all your resources to be destroyed. There is no reason to release them manually. User-space *must* be able to deal with asynchronous unplugs.
So the problem if you do that is that things like a buffer's memory pages can disappear from under you. How would you deal with that case? User space certainly can't have a segfault handler catch that just in case :)
If you rip out hardware resources, then you better be able to deal with it. Sure, UDL is an exception as it doesn't have memory resources on the chip. But it sounds fishy to me, if you base your API on it. On a lot of other devices, the memory will simply not be there. So you cannot keep it around.
There are many ways to invalidate memory mappings. You either unmap the entire range (and user-space must deal with SIGBUS, which is completely feasible and a lot of code already does it), or you replace all with a zero page, or you duplicate all pages, ... IMO, user-space has to start dealing with hardware unplug properly and stop pretending it cannot happen.
If you mmap() your filesystem, and you rip out your block device, then you also will get SIGBUS if you access pages that are not in pagecache. Why are graphics buffers different?
Thanks
David
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
Quoted 46 lines · David Herrmann
Hi
Quoted 33 lines · Stéphane Marchesin
Quoted 32 lines · David Herrmann
Hi
Quoted 28 lines · Haixia Shi
Quoted 7 lines
drivers/gpu/drm/udl/udl_main.c +5
-0+if (udl_device_is_unplugged (dev) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_SETCRTC ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_RMFB ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_DESTROY_DUMB )) +return -ENODEV ;Quoted 8 lines
Why?
Just do:
if (udl_device_is_unplugged(dev)) return -ENODEV;Why this complex logic here?
Because there are legitimate ioctl calls after UDL is unplugged. See crbug.com/583508 and crbug.com/583758 for some background.
The userspace (Chrome in this case) has allocated FBs and Dumb buffers on the drm device and needs to be given a chance to properly deallocate them (via RMFB and
DESTROY_DUMB). In addition, it needs to call SETCRTC withfb_id= 0 to properly release the last refcount on the primary fb.I initially proposed adding an "
UNPLUG_DISALLOW" flag to ioctls so that we can whitelist them on a case-by-case basis but that proposal got shot down as being unnecessary, but you can see my original patch at
https://chromium-review.googlesource.com/#/c/326160/Quoted 8 lines
Quoted 3 lines
If a device is unplugged, you should consider all your resources to be destroyed. There is no reason to release them manually. User-space *must* be able to deal with asynchronous unplugs.
So the problem if you do that is that things like a buffer's memory pages can disappear from under you. How would you deal with that case? User space certainly can't have a segfault handler catch that just in case :)
Quoted 5 lines
If you rip out hardware resources, then you better be able to deal with it. Sure, UDL is an exception as it doesn't have memory resources on the chip. But it sounds fishy to me, if you base your API on it. On a lot of other devices, the memory will simply not be there. So you cannot keep it around.
The thing is, you are not unplugging a device here; you are unplugging a USB monitor. As a proof that this is just a monitor, I can plug another USB monitor with the same driver and pick up where I left off. I guess I am saying that the concept of unplugging a device is not applicable here (or to any driver that I know, for that matter).
Other drivers already handle all this by, for example, failing page flips if the monitor is gone. We basically want to do the same for UDL; I don't think we need to invent a new level of unplug here.
Quoted 7 lines
There are many ways to invalidate memory mappings. You either unmap the entire range (and user-space must deal with SIGBUS, which is completely feasible and a lot of code already does it), or you replace all with a zero page, or you duplicate all pages, ... IMO, user-space has to start dealing with hardware unplug properly and stop pretending it cannot happen.
What you are suggesting is much more complicated than you claim, for example if you destroy the dmabuf which is shared with another driver, what happens? User space definitely can't deal with that.
I think we should wait until we have unpluggable display hardware before inventing really complex support for it.
Stéphane
Quoted 7 lines
If you
mmap()your filesystem, and you rip out your block device, then you also will get SIGBUS if you access pages that are not in pagecache. Why are graphics buffers different?Thanks
David
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
Hi
Quoted 22 lines · Stéphane Marchesin
Quoted 9 lines · David Herrmann
Quoted 8 lines
Quoted 3 lines
If a device is unplugged, you should consider all your resources to be destroyed. There is no reason to release them manually. User-space *must* be able to deal with asynchronous unplugs.
So the problem if you do that is that things like a buffer's memory pages can disappear from under you. How would you deal with that case? User space certainly can't have a segfault handler catch that just in case :)
Quoted 5 lines
If you rip out hardware resources, then you better be able to deal with it. Sure, UDL is an exception as it doesn't have memory resources on the chip. But it sounds fishy to me, if you base your API on it. On a lot of other devices, the memory will simply not be there. So you cannot keep it around.
The thing is, you are not unplugging a device here; you are unplugging a USB monitor. As a proof that this is just a monitor, I can plug another USB monitor with the same driver and pick up where I left off. I guess I am saying that the concept of unplugging a device is not applicable here (or to any driver that I know, for that matter).
Quoted 3 lines
Other drivers already handle all this by, for example, failing page flips if the monitor is gone. We basically want to do the same for UDL; I don't think we need to invent a new level of unplug here.
No, you rip out a display controller. You don't just unplug a monitor, you remove the whole hardware. If UDL were treated on the same level as connector-hotplugging, then you should implement it that way. But currently it is not.
Btw., even if you do this, you still have to deal with devices going away, and new devices being plugged. DRM does not support CRTC/connector hotplugging, yet. Hence, making UDL a singleton driver will not work either.
Quoted 8 lines
Quoted 7 lines
There are many ways to invalidate memory mappings. You either unmap the entire range (and user-space must deal with SIGBUS, which is completely feasible and a lot of code already does it), or you replace all with a zero page, or you duplicate all pages, ... IMO, user-space has to start dealing with hardware unplug properly and stop pretending it cannot happen.
Quoted 6 lines
What you are suggesting is much more complicated than you claim, for example if you destroy the dmabuf which is shared with another driver, what happens? User space definitely can't deal with that.
I think we should wait until we have unpluggable display hardware before inventing really complex support for it.
PCI Hotplugging. Has been around since a decade. Intel just got lucky that they cannot be ripped out. The other drivers don't care (and break horribly if you do).
Feel free to come up with a better way to deal with UDL hotplugging. However, I for myself recommend doing it properly, on the bus level. Like all other subsystems do.
Thanks
David
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
In reply to Stéphane MarchesinQuoted 38 lines · Stéphane Marchesin
Quoted 37 lines · David Herrmann
Hi
Quoted 33 lines · Stéphane Marchesin
Quoted 32 lines · David Herrmann
Hi
Quoted 28 lines · Haixia Shi
Quoted 7 lines
(quoted diff) +5
-0+ if (udl_device_is_unplugged(dev) && + nr != DRM_IOCTL_NR(DRM_IOCTL_MODE_SETCRTC) && + nr != DRM_IOCTL_NR(DRM_IOCTL_MODE_RMFB) && + nr != DRM_IOCTL_NR(DRM_IOCTL_MODE_DESTROY_DUMB)) + return -ENODEV;Quoted 8 lines
Why?
Just do:
if (udl_device_is_unplugged(dev)) return -ENODEV;Why this complex logic here?
Because there are legitimate ioctl calls after UDL is unplugged. See crbug.com/583508 and crbug.com/583758 for some background.
The userspace (Chrome in this case) has allocated FBs and Dumb buffers on the drm device and needs to be given a chance to properly deallocate them (via RMFB and
DESTROY_DUMB). In addition, it needs to call SETCRTC withfb_id= 0 to properly release the last refcount on the primary fb.I initially proposed adding an "
UNPLUG_DISALLOW" flag to ioctls so that we can whitelist them on a case-by-case basis but that proposal got shot down as being unnecessary, but you can see my original patch at
https://chromium-review.googlesource.com/#/c/326160/
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
If a device is unplugged, you should consider all your resources to be destroyed. There is no reason to release them manually. User-space *must* be able to deal with asynchronous unplugs.
So the problem if you do that is that things like a buffer's memory pages can disappear from under you. How would you deal with that case? User space certainly can't have a segfault handler catch that just in case :)
Yeah, dma-buf and fence lifetime is entirely unsolved. I agree that they /should/ keep being alive. Of course the actual data in it might be toast, but that's not any different from a gpu hang. At least i915 only gives you asynchronous signalling for "bad stuff happened" in that case, buffer access to corrupted data continues to work. And must do so, because X/compositors/clients would just die if we don't do that, and that's Not Good(tm).
Quoted 12 lines
Quoted 5 lines
If you rip out hardware resources, then you better be able to deal with it. Sure, UDL is an exception as it doesn't have memory resources on the chip. But it sounds fishy to me, if you base your API on it. On a lot of other devices, the memory will simply not be there. So you cannot keep it around.
The thing is, you are not unplugging a device here; you are unplugging a USB monitor. As a proof that this is just a monitor, I can plug another USB monitor with the same driver and pick up where I left off. I guess I am saying that the concept of unplugging a device is not applicable here (or to any driver that I know, for that matter).
Quoted 3 lines
Other drivers already handle all this by, for example, failing page flips if the monitor is gone. We basically want to do the same for UDL; I don't think we need to invent a new level of unplug here.
Just an aside: Imo failing pageflips is really bad behaviour of some kernel drivers (yes mst does it by force-disabling sinks). Imo userspace should ask for things to get disabled explicitly, much less potential for races. For mst I think the right solution is to send out the uevent, stope enumerating the port, but keep it internally alive until it's all gone.
Something similar could make sense for uld.
Quoted 7 lines
Quoted 6 lines
There are many ways to invalidate memory mappings. You either unmap the entire range (and user-space must deal with SIGBUS, which is completely feasible and a lot of code already does it), or you replace all with a zero page, or you duplicate all pages, ... IMO, user-space has to start dealing with hardware unplug properly and stop pretending it cannot happen.
Quoted 6 lines
What you are suggesting is much more complicated than you claim, for example if you destroy the dmabuf which is shared with another driver, what happens? User space definitely can't deal with that.
I think we should wait until we have unpluggable display hardware before inventing really complex support for it.
I agree that for now we probably should just have hacks for udl (and yeah fixing up mst to no longer just go poof is on my todo list somewhere), and leave the larger issue of drivers disappearing unfixed. Atm module unload is the only real user for that (except udl ofc), and that's a developer feature.
Fixing all the dma-buf/fence/drm device lifetime issues properly is super hard I think. And tons of work.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
In reply to David HerrmannQuoted 11 lines
This should rather be:
drm_release(inode, filp); mutex_lock(&drm_global_mutex); if (!dev->open_count && udl_device_is_unplugged(dev)) drm_put_dev(dev); mutex_unlock(&drm_global_mutex); return 0;There is no reason to look at the return code of
drm_release(), ever.
But drm_release() does return a retcode. It would still make sense to return that as-is in case any existing code relies on it.
Quoted 349 lines · David Herrmann
Hi
Quoted 1 line · Haixia Shi
Remove the general
drm_device_is_unplugged()checks, and move theunplugged
Quoted 1 line
flag handling logic into drm/udl. In general we want to keep
driver-specific
Quoted 4 lines
logic out of common drm code.
Signed-off-by Haixia Shi <[email protected]>Reviewed-by Stéphane Marchesin <[email protected]>Quoted 12 lines
--- drivers/gpu/drm/drm_drv.c | 6 ---- drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 -- drivers/gpu/drm/drm_ioctl.c | 3 -- drivers/gpu/drm/drm_vm.c | 3 -- drivers/gpu/drm/udl/udl_connector.c | 2 +- drivers/gpu/drm/udl/udl_drv.c | 7 +++-- drivers/gpu/drm/udl/udl_drv.h | 6 ++++ drivers/gpu/drm/udl/udl_fb.c | 2 +- drivers/gpu/drm/udl/udl_gem.c | 5 +++ drivers/gpu/drm/udl/udl_main.c | 61+++++++++++++++++++++++++++++++++++++
drivers/gpu/drm/drm_drv.c struct drm_minor *drm_minor_acquire(unsigned int
Quoted 8 lines
include/drm/drmP.h | 14 --------- 12 files changed, 78 insertions(+), 36 deletions(-)drivers/gpu/drm/drm_drv.c +0
-0@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int
minor_id)drivers/gpu/drm/drm_fops.c int drm_release(struct inode *inode, struct file
Quoted 24 lines
drivers/gpu/drm/drm_drv.c +0
-6if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }return minor;@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -if (dev->open_count ==0 ) {drm_put_dev (dev); }drivers/gpu/drm/drm_fops.c +0
-0@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file*filp)
drivers/gpu/drm/drm_gem.c int drm_gem_mmap(struct file *filp, struct
Quoted 13 lines
drivers/gpu/drm/drm_fops.c +0
-2if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev); }mutex_unlock (&drm_global_mutex);drivers/gpu/drm/drm_gem.c +0
-0@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct
vm_area_struct*vma)drivers/gpu/drm/drm_gem.c int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)
Quoted 8 lines
drivers/gpu/drm/drm_gem.c +0
-3struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -drm_vma_offset_lock_lookup (dev->vma_offset_manager); node =drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager,
drivers/gpu/drm/drm_vm.c int drm_legacy_mmap(struct file *filp, struct
Quoted 20 lines
drivers/gpu/drm/drm_gem.c +0
-0vma->vm_pgoff,drivers/gpu/drm/drm_ioctl.c +0
-3@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {drivers/gpu/drm/drm_vm.c +0
-0@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct
vm_area_struct*vma)Review
Quoted 10 lines
drivers/gpu/drm/drm_vm.c +0
-3struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_connector.cdrivers/gpu/drm/udl/udl_connector.c static int udl_mode_valid(struct drm_connector
Quoted 4 lines
index 4709b54..b168f2c 100644
drivers/gpu/drm/udl/udl_connector.c +0
-0@@ -96,7 +96,7 @@ static int udl_mode_valid(struct drm_connector*connector,
Review
Quoted 9 lines
drivers/gpu/drm/udl/udl_connector.c +1
-1static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) +if (udl_device_is_unplugged (connector->dev))return connector_status_disconnected;return connector_status_connected; }(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_drv.cdrivers/gpu/drm/udl/udl_drv.c static const struct vm_operations_struct
Quoted 4 lines
index d5728ec..f5c2a97 100644
drivers/gpu/drm/udl/udl_drv.c +0
-0@@ -24,12 +24,12 @@ static const struct vm_operations_struct
udl_gem_vm_ops= {drivers/gpu/drm/udl/udl_drv.c static void udl_usb_disconnect(struct usb_interface
Quoted 16 lines
drivers/gpu/drm/udl/udl_drv.c +3
-3static const struct file_operations udl_driver_fops = { .owner =THIS_MODULE , - .open = drm_open, + .open = udl_drm_open, .mmap = udl_drm_gem_mmap, .poll = drm_poll, .read = drm_read, - .unlocked_ioctl = drm_ioctl, - .release = drm_release, + .unlocked_ioctl = udl_drm_ioctl, + .release = udl_drm_release, #ifdef CONFIG_COMPAT .compat_ioctl = drm_compat_ioctl, #endif@@ -97,6 +97,7 @@ static void udl_usb_disconnect(struct usb_interface*interface)
Review
Quoted 8 lines
drivers/gpu/drm/udl/udl_drv.c +1
-0drm_connector_unplug_all (dev);udl_fbdev_unplug (dev);udl_drop_usb (dev); +udl_device_set_unplugged (dev);drm_unplug_dev (dev); }(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_drv.hdrivers/gpu/drm/udl/udl_drv.h struct udl_device { · line 65
Quoted 5 lines
index 4a064ef..75aa91c 100644
drivers/gpu/drm/udl/udl_drv.h +0
-0@@ -65,6 +65,7 @@ struct udl_device {atomic_t bytes_identical;/* saved effort with backbuffer comparison */
drivers/gpu/drm/udl/udl_drv.h struct udl_device { · line 66
Quoted 1 line
drivers/gpu/drm/udl/udl_drv.h +0
-0atomic_t bytes_sent;/* to usb, after compression including overhead */
drivers/gpu/drm/udl/udl_drv.h struct udl_device { · line 67
Quoted 1 line
drivers/gpu/drm/udl/udl_drv.h +0
-0atomic_t cpu_kcycles_used;/* transpired during pixel processing */
drivers/gpu/drm/udl/udl_drv.h int udl_gem_get_pages(struct udl_gem_object *obj); · line 139
Quoted 11 lines
drivers/gpu/drm/udl/udl_drv.h +4
-0+atomic_t unplugged;/* device has been unplugged or gone away */ };struct udl_gem_object {@@ -133,6 +134,9 @@ int udl_gem_get_pages(struct udl_gem_object *obj);void udl_gem_put_pages (struct udl_gem_object *obj);int udl_gem_vmap (struct udl_gem_object *obj);void udl_gem_vunmap (struct udl_gem_object *obj); +int udl_drm_open (struct inode *inode,struct file *filp); +int udl_drm_release (struct inode *inode,struct file *filp); +int udl_drm_ioctl(struct file *filp, unsigned int cmd, unsigned longarg);
drivers/gpu/drm/udl/udl_drv.h int udl_handle_damage(struct udl_framebuffer *fb,
Quoted 4 lines
drivers/gpu/drm/udl/udl_drv.h +0
-0int udl_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma);int udl_gem_fault (struct vm_area_struct *vma,struct vm_fault *vmf);@@ -140,6 +144,8 @@ int udl_handle_damage(struct udl_framebuffer *fb,int x, int y,
drivers/gpu/drm/udl/udl_fb.c static int udl_fb_open(struct fb_info *info, int
Quoted 13 lines
drivers/gpu/drm/udl/udl_drv.h +2
-0int width, int height);int udl_drop_usb (struct drm_device *dev); +void udl_device_set_unplugged (struct drm_device *dev); +int udl_device_is_unplugged (struct drm_device *dev);#define CMD_WRITE_RAW8 "\xAF\x60"/**< 8 bit raw write command. */ #define CMD_WRITE_RL8 "\xAF\x61"/**< 8 bit run length command. */ drivers/gpu/drm/udl/udl_fb.c +0
-0@@ -325,7 +325,7 @@ static int udl_fb_open(struct fb_info *info, intuser)
Review
Quoted 9 lines
drivers/gpu/drm/udl/udl_fb.c +1
-1struct udl_device *udl = dev->dev_private;/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) +if (udl_device_is_unplugged (udl->ddev))return -ENODEV ; ufbdev->fb_count++;(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_gem.cReview
Quoted 18 lines
index 2a0a784..33c302f 100644
drivers/gpu/drm/udl/udl_gem.c +5
-0@@ -86,8 +86,13 @@ int udl_dumb_create(struct drm_file *file,int udl_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma) { +struct drm_file *priv = filp->private_data; +struct drm_device *dev = priv->minor->dev;int ret; +if (udl_device_is_unplugged (dev)) +return -ENODEV ; + ret =drm_gem_mmap (filp, vma);if (ret)return ret;(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_main.cQuoted 13 lines
index 33dbfb2..2ba3ee3 100644
drivers/gpu/drm/udl/udl_main.c +6
-0@@ -350,3 +350,64 @@ int udl_driver_unload(struct drm_device *dev)kfree (udl);return 0 ; } + +int udl_drm_open (struct inode *inode,struct file *filp) +{ +struct drm_file *file_priv; +struct drm_minor *minor; +drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev) · line 368
Quoted 10 lines
drivers/gpu/drm/udl/udl_main.c +10
-0+int ret =drm_open (inode, filp); +if (ret) +return ret; + + file_priv = filp->private_data; + minor = file_priv->minor; +if (udl_device_is_unplugged (minor->dev)) { +drm_dev_unref (minor->dev); +return -ENODEV ; + }This doesn't make sense to me. You're called here with global-mutex held, so you can just check
udl_device_is_unplugged()before calling intodrm_open().drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev) · line 380
Quoted 12 lines
drivers/gpu/drm/udl/udl_main.c +12
-0+ +return 0 ; +} + +int udl_drm_release (struct inode *inode,struct file *filp) +{ +struct drm_file *file_priv = filp->private_data; +struct drm_device *dev = file_priv->minor->dev; + +int ret =drm_release (inode, filp); +if (!dev->open_count &&udl_device_is_unplugged (dev)) +drm_put_dev (dev);This should rather be:
drm_release(inode, filp); mutex_lock(&drm_global_mutex); if (!dev->open_count && udl_device_is_unplugged(dev)) drm_put_dev(dev); mutex_unlock(&drm_global_mutex); return 0;There is no reason to look at the return code of
drm_release(), ever.drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev)
Quoted 5 lines
drivers/gpu/drm/udl/udl_main.c +5
-0+ +return ret; +} + +int udl_drm_ioctl(struct file *filp, unsigned int cmd, unsigned longarg)
drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev) · line 395
Quoted 10 lines
drivers/gpu/drm/udl/udl_main.c +10
-0+{ +struct drm_file *file_priv = filp->private_data; +struct drm_device *dev = file_priv->minor->dev; +unsigned int nr =DRM_IOCTL_NR (cmd); + +if (udl_device_is_unplugged (dev) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_SETCRTC ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_RMFB ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_DESTROY_DUMB )) +return -ENODEV ;Why?
Just do:
if (udl_device_is_unplugged(dev)) return -ENODEV;Why this complex logic here?
Thanks
DavidQuoted 23 lines
drivers/gpu/drm/udl/udl_main.c +18
-0+ +return drm_ioctl (filp, cmd, arg); +} + +void udl_device_set_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +smp_wmb (); +atomic_set (&udl->unplugged,1 ); +} + +int udl_device_is_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +int ret =atomic_read (&udl->unplugged); +smp_rmb (); +return ret; +}include/drm/drmP.h +0
-0include/drm/drmP.h struct drm_device { · line 751
Quoted 4 lines
include/drm/drmP.h +0
-1@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */
include/drm/drmP.h struct drm_device { · line 751
Quoted 1 line
include/drm/drmP.h +0
-0struct inode *anon_inode;/**< inode for private address-space */
include/drm/drmP.h struct drm_device { · line 752
Quoted 1 line
include/drm/drmP.h +0
-0char *unique;/**< unique name of the device */
include/drm/drmP.h static __inline__ int drm_core_check_feature(struct
Quoted 2 lines
include/drm/drmP.h +0
-0/*@} */ @@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct
drm_device*dev,Quoted 3 lines
include/drm/drmP.h +0
-0return ((dev->driver->driver_features & feature) ?1 :0 ); }
Quoted 21 lines
Quoted 4 lines
include/drm/drmP.h +0
-4-static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 );include/drm/drmP.h static __inline__ int drm_core_check_feature(struct drm_device *dev,
Quoted 10 lines
include/drm/drmP.h +0
-9-} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} - static inline bool drm_is_render_client(const struct drm_file
*file_priv)Quoted 5 lines
include/drm/drmP.h +0
-1{return file_priv->minor->type ==DRM_MINOR_RENDER ; --2.7.0.rc3.207.g0ac5344
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
Also note that it is not currently feasible for UDL code to access drm_global_mutex.
Please also refer to the similar comments ("FIXME: open_count is protected by drm_global_mutex but that would lead to locking inversion with the driver load path.") in nouveau, i915 and amdgpu.
Quoted 10 lines · Haixia Shi
Quoted 10 lines
This should rather be:
drm_release(inode, filp); mutex_lock(&drm_global_mutex); if (!dev->open_count && udl_device_is_unplugged(dev)) drm_put_dev(dev); mutex_unlock(&drm_global_mutex); return 0;
Quoted 381 lines
Quoted 1 line
There is no reason to look at the return code of
drm_release(), ever.But
drm_release()does return a retcode. It would still make sense to return that as-is in case any existing code relies on it.Quoted 371 lines · David Herrmann
Hi
Quoted 1 line · Haixia Shi
Remove the general
drm_device_is_unplugged()checks, and move theunplugged
Quoted 1 line
flag handling logic into drm/udl. In general we want to keep
driver-specific
Quoted 4 lines
logic out of common drm code.
Signed-off-by Haixia Shi <[email protected]>Reviewed-by Stéphane Marchesin <[email protected]>Quoted 12 lines
--- drivers/gpu/drm/drm_drv.c | 6 ---- drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 -- drivers/gpu/drm/drm_ioctl.c | 3 -- drivers/gpu/drm/drm_vm.c | 3 -- drivers/gpu/drm/udl/udl_connector.c | 2 +- drivers/gpu/drm/udl/udl_drv.c | 7 +++-- drivers/gpu/drm/udl/udl_drv.h | 6 ++++ drivers/gpu/drm/udl/udl_fb.c | 2 +- drivers/gpu/drm/udl/udl_gem.c | 5 +++ drivers/gpu/drm/udl/udl_main.c | 61+++++++++++++++++++++++++++++++++++++
drivers/gpu/drm/drm_drv.c struct drm_minor *drm_minor_acquire(unsigned int
Quoted 8 lines
include/drm/drmP.h | 14 --------- 12 files changed, 78 insertions(+), 36 deletions(-)drivers/gpu/drm/drm_drv.c +0
-0@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int
minor_id)drivers/gpu/drm/drm_fops.c int drm_release(struct inode *inode, struct file
Quoted 24 lines
drivers/gpu/drm/drm_drv.c +0
-6if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }return minor;@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -if (dev->open_count ==0 ) {drm_put_dev (dev); }drivers/gpu/drm/drm_fops.c +0
-0@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file*filp)
drivers/gpu/drm/drm_gem.c int drm_gem_mmap(struct file *filp, struct
Quoted 13 lines
drivers/gpu/drm/drm_fops.c +0
-2if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev); }mutex_unlock (&drm_global_mutex);drivers/gpu/drm/drm_gem.c +0
-0@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct
vm_area_struct*vma)drivers/gpu/drm/drm_gem.c int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)
Quoted 8 lines
drivers/gpu/drm/drm_gem.c +0
-3struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -drm_vma_offset_lock_lookup (dev->vma_offset_manager); node =drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager,
drivers/gpu/drm/drm_ioctl.c long drm_ioctl(struct file *filp, · line 698
Quoted 13 lines
drivers/gpu/drm/drm_gem.c +0
-0vma->vm_pgoff,drivers/gpu/drm/drm_ioctl.c +0
-3@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - is_driver_ioctl = nr >= DRM_COMMAND_BASE && nr <
DRM_COMMAND_END;drivers/gpu/drm/drm_vm.c int drm_legacy_mmap(struct file *filp, struct
Quoted 7 lines
drivers/gpu/drm/drm_ioctl.c +0
-0if (is_driver_ioctl) {drivers/gpu/drm/drm_vm.c +0
-0@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct
vm_area_struct*vma)Review
Quoted 10 lines
drivers/gpu/drm/drm_vm.c +0
-3struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_connector.cdrivers/gpu/drm/udl/udl_connector.c static int udl_mode_valid(struct drm_connector
Quoted 4 lines
index 4709b54..b168f2c 100644
drivers/gpu/drm/udl/udl_connector.c +0
-0@@ -96,7 +96,7 @@ static int udl_mode_valid(struct drm_connector*connector,
Review
Quoted 9 lines
drivers/gpu/drm/udl/udl_connector.c +1
-1static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) +if (udl_device_is_unplugged (connector->dev))return connector_status_disconnected;return connector_status_connected; }(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_drv.cdrivers/gpu/drm/udl/udl_drv.c static const struct vm_operations_struct
Quoted 4 lines
index d5728ec..f5c2a97 100644
drivers/gpu/drm/udl/udl_drv.c +0
-0@@ -24,12 +24,12 @@ static const struct vm_operations_struct
udl_gem_vm_ops= {drivers/gpu/drm/udl/udl_drv.c static void udl_usb_disconnect(struct usb_interface
Quoted 16 lines
drivers/gpu/drm/udl/udl_drv.c +3
-3static const struct file_operations udl_driver_fops = { .owner =THIS_MODULE , - .open = drm_open, + .open = udl_drm_open, .mmap = udl_drm_gem_mmap, .poll = drm_poll, .read = drm_read, - .unlocked_ioctl = drm_ioctl, - .release = drm_release, + .unlocked_ioctl = udl_drm_ioctl, + .release = udl_drm_release, #ifdef CONFIG_COMPAT .compat_ioctl = drm_compat_ioctl, #endif@@ -97,6 +97,7 @@ static void udl_usb_disconnect(struct usb_interface*interface)
Review
Quoted 8 lines
drivers/gpu/drm/udl/udl_drv.c +1
-0drm_connector_unplug_all (dev);udl_fbdev_unplug (dev);udl_drop_usb (dev); +udl_device_set_unplugged (dev);drm_unplug_dev (dev); }(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_drv.hdrivers/gpu/drm/udl/udl_drv.h struct udl_device { · line 65
Quoted 5 lines
index 4a064ef..75aa91c 100644
drivers/gpu/drm/udl/udl_drv.h +0
-0@@ -65,6 +65,7 @@ struct udl_device {atomic_t bytes_identical;/* saved effort with backbuffer comparison */
drivers/gpu/drm/udl/udl_drv.h struct udl_device { · line 66
Quoted 1 line
drivers/gpu/drm/udl/udl_drv.h +0
-0atomic_t bytes_sent;/* to usb, after compression including overhead */
drivers/gpu/drm/udl/udl_drv.h struct udl_device { · line 67
Quoted 1 line
drivers/gpu/drm/udl/udl_drv.h +0
-0atomic_t cpu_kcycles_used;/* transpired during pixel processing */
drivers/gpu/drm/udl/udl_drv.h int udl_gem_get_pages(struct udl_gem_object *obj); · line 139
Quoted 11 lines
drivers/gpu/drm/udl/udl_drv.h +4
-0+atomic_t unplugged;/* device has been unplugged or gone away */ };struct udl_gem_object {@@ -133,6 +134,9 @@ int udl_gem_get_pages(struct udl_gem_object *obj);void udl_gem_put_pages (struct udl_gem_object *obj);int udl_gem_vmap (struct udl_gem_object *obj);void udl_gem_vunmap (struct udl_gem_object *obj); +int udl_drm_open (struct inode *inode,struct file *filp); +int udl_drm_release (struct inode *inode,struct file *filp); +int udl_drm_ioctl(struct file *filp, unsigned int cmd, unsigned longarg);
drivers/gpu/drm/udl/udl_drv.h int udl_handle_damage(struct udl_framebuffer *fb,
Quoted 4 lines
drivers/gpu/drm/udl/udl_drv.h +0
-0int udl_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma);int udl_gem_fault (struct vm_area_struct *vma,struct vm_fault *vmf);@@ -140,6 +144,8 @@ int udl_handle_damage(struct udl_framebuffer *fb,int x, int y,
drivers/gpu/drm/udl/udl_fb.c static int udl_fb_open(struct fb_info *info, int
Quoted 13 lines
drivers/gpu/drm/udl/udl_drv.h +2
-0int width, int height);int udl_drop_usb (struct drm_device *dev); +void udl_device_set_unplugged (struct drm_device *dev); +int udl_device_is_unplugged (struct drm_device *dev);#define CMD_WRITE_RAW8 "\xAF\x60"/**< 8 bit raw write command. */ #define CMD_WRITE_RL8 "\xAF\x61"/**< 8 bit run length command. */ drivers/gpu/drm/udl/udl_fb.c +0
-0@@ -325,7 +325,7 @@ static int udl_fb_open(struct fb_info *info, intuser)
Review
Quoted 9 lines
drivers/gpu/drm/udl/udl_fb.c +1
-1struct udl_device *udl = dev->dev_private;/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) +if (udl_device_is_unplugged (udl->ddev))return -ENODEV ; ufbdev->fb_count++;(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_gem.cReview
Quoted 18 lines
index 2a0a784..33c302f 100644
drivers/gpu/drm/udl/udl_gem.c +5
-0@@ -86,8 +86,13 @@ int udl_dumb_create(struct drm_file *file,int udl_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma) { +struct drm_file *priv = filp->private_data; +struct drm_device *dev = priv->minor->dev;int ret; +if (udl_device_is_unplugged (dev)) +return -ENODEV ; + ret =drm_gem_mmap (filp, vma);if (ret)return ret;(quoted diff) +0
-0
b/drivers/gpu/drm/udl/udl_main.cQuoted 13 lines
index 33dbfb2..2ba3ee3 100644
drivers/gpu/drm/udl/udl_main.c +6
-0@@ -350,3 +350,64 @@ int udl_driver_unload(struct drm_device *dev)kfree (udl);return 0 ; } + +int udl_drm_open (struct inode *inode,struct file *filp) +{ +struct drm_file *file_priv; +struct drm_minor *minor; +drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev) · line 368
Quoted 10 lines
drivers/gpu/drm/udl/udl_main.c +10
-0+int ret =drm_open (inode, filp); +if (ret) +return ret; + + file_priv = filp->private_data; + minor = file_priv->minor; +if (udl_device_is_unplugged (minor->dev)) { +drm_dev_unref (minor->dev); +return -ENODEV ; + }This doesn't make sense to me. You're called here with global-mutex held, so you can just check
udl_device_is_unplugged()before calling intodrm_open().drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev) · line 380
Quoted 12 lines
drivers/gpu/drm/udl/udl_main.c +12
-0+ +return 0 ; +} + +int udl_drm_release (struct inode *inode,struct file *filp) +{ +struct drm_file *file_priv = filp->private_data; +struct drm_device *dev = file_priv->minor->dev; + +int ret =drm_release (inode, filp); +if (!dev->open_count &&udl_device_is_unplugged (dev)) +drm_put_dev (dev);This should rather be:
drm_release(inode, filp); mutex_lock(&drm_global_mutex); if (!dev->open_count && udl_device_is_unplugged(dev)) drm_put_dev(dev); mutex_unlock(&drm_global_mutex); return 0;There is no reason to look at the return code of
drm_release(), ever.drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev)
Quoted 5 lines
drivers/gpu/drm/udl/udl_main.c +5
-0+ +return ret; +} + +int udl_drm_ioctl(struct file *filp, unsigned int cmd, unsigned longarg)
drivers/gpu/drm/udl/udl_main.c int udl_driver_unload(struct drm_device *dev) · line 395
Quoted 10 lines
drivers/gpu/drm/udl/udl_main.c +10
-0+{ +struct drm_file *file_priv = filp->private_data; +struct drm_device *dev = file_priv->minor->dev; +unsigned int nr =DRM_IOCTL_NR (cmd); + +if (udl_device_is_unplugged (dev) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_SETCRTC ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_RMFB ) && + nr !=DRM_IOCTL_NR (DRM_IOCTL_MODE_DESTROY_DUMB )) +return -ENODEV ;Why?
Just do:
if (udl_device_is_unplugged(dev)) return -ENODEV;Why this complex logic here?
Thanks
DavidQuoted 23 lines
drivers/gpu/drm/udl/udl_main.c +18
-0+ +return drm_ioctl (filp, cmd, arg); +} + +void udl_device_set_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +smp_wmb (); +atomic_set (&udl->unplugged,1 ); +} + +int udl_device_is_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +int ret =atomic_read (&udl->unplugged); +smp_rmb (); +return ret; +}include/drm/drmP.h +0
-0include/drm/drmP.h struct drm_device { · line 751
Quoted 4 lines
include/drm/drmP.h +0
-1@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */
include/drm/drmP.h struct drm_device { · line 751
Quoted 1 line
include/drm/drmP.h +0
-0struct inode *anon_inode;/**< inode for private address-space */
include/drm/drmP.h struct drm_device { · line 752
Quoted 1 line
include/drm/drmP.h +0
-0char *unique;/**< unique name of the device */
include/drm/drmP.h static __inline__ int
Quoted 2 lines
include/drm/drmP.h +0
-0/*@} */ @@ -879,19 +878,6 @@ static __inline__ intdrm_core_check_feature(struct
drm_device*dev,Quoted 7 lines
include/drm/drmP.h +0
-4return ((dev->driver->driver_features & feature) ?1 :0 ); } -static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 );include/drm/drmP.h static __inline__ int drm_core_check_feature(struct drm_device *dev,
Quoted 10 lines
include/drm/drmP.h +0
-9-} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} - static inline bool drm_is_render_client(const struct drm_file
*file_priv)Quoted 5 lines
include/drm/drmP.h +0
-1{return file_priv->minor->type ==DRM_MINOR_RENDER ; --2.7.0.rc3.207.g0ac5344
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
Hi
Quoted 2 lines · Haixia Shi
Also note that it is not currently feasible for UDL code to access
drm_global_mutex.
Then change this.
Quoted 3 lines
Please also refer to the similar comments ("FIXME:
open_countis protected bydrm_global_mutexbut that would lead to locking inversion with the driver load path.") in nouveau, i915 and amdgpu.
This is unrelated to your change. I don't see any locking inversion in your patch.
Thanks
David
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
In reply to Haixia ShiHi
Quoted 8 lines · Haixia Shi
Quoted 8 lines
This should rather be:
drm_release(inode, filp); mutex_lock(&drm_global_mutex); if (!dev->open_count && udl_device_is_unplugged(dev)) drm_put_dev(dev); mutex_unlock(&drm_global_mutex);
Quoted 6 lines
Quoted 3 lines
return 0;There is no reason to look at the return code of
drm_release(), ever.But
drm_release()does return a retcode. It would still make sense to return that as-is in case any existing code relies on it.
Nobody should ever return error codes from fops.release(). It is completely bogus. You rather confuse generic user-space that calls close(), than getting any benefit out of it.
But TBH, I don't care. Feel free to forward the return value. But still, please change the order of the calls as I did.
Thanks
David
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
David
I am having trouble getting the reference to "drm_global_mutex" to link correctly in drm/udl. The error is
ERROR: "drm_global_mutex" [drivers/gpu/drm/udl/udl.ko] undefined! make[1]: *** [__modpost] Error 1
make: *** [modules] Error 2
This seems to be only accessed in the common drm code. Do you have a suggestion how to get around it?
Quoted 23 lines · David Herrmann
Hi
Quoted 8 lines · Haixia Shi
Quoted 8 lines
This should rather be:
drm_release(inode, filp); mutex_lock(&drm_global_mutex); if (!dev->open_count && udl_device_is_unplugged(dev)) drm_put_dev(dev); mutex_unlock(&drm_global_mutex);Quoted 5 lines
Quoted 3 lines
return 0;There is no reason to look at the return code of
drm_release(), ever.But
drm_release()does return a retcode. It would still make sense toreturn
Quoted 1 line
that as-is in case any existing code relies on it.
Nobody should ever return error codes from
fops.release(). It is completely bogus. You rather confuse generic user-space that callsclose(), than getting any benefit out of it.
Quoted 6 lines
But TBH, I don't care. Feel free to forward the return value. But still, please change the order of the calls as I did.
Thanks
David
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: make unplugged flag specific to udl driver
Hi
Quoted 11 lines · Haixia Shi
David
I am having trouble getting the reference to "
drm_global_mutex" to link correctly in drm/udl. The error isERROR: "
drm_global_mutex" [drivers/gpu/drm/udl/udl.ko] undefined! make[1]: *** [__modpost] Error 1
make: *** [modules] Error 2This seems to be only accessed in the common drm code. Do you have a suggestion how to get around it?
You need to add:
EXPORT_SYMBOL(drm_global_mutex);
Thanks
David
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 2/2 drm: remove drm_device_is_unplugged checks in common drm code.
In reply to Haixia ShiWhen USB cable is disconnected, we mark udl device as unplugged so that udl_detect reports connector status as disconnected, but still keep the drm device alive until user-space closes it.
--- drivers/gpu/drm/drm_drv.c | 6 ------ drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 --- drivers/gpu/drm/drm_ioctl.c | 3 --- drivers/gpu/drm/drm_vm.c | 3 --- drivers/gpu/drm/udl/udl_connector.c | 2 +- drivers/gpu/drm/udl/udl_drv.c | 1 + drivers/gpu/drm/udl/udl_drv.h | 3 +++ drivers/gpu/drm/udl/udl_fb.c | 2 +- drivers/gpu/drm/udl/udl_main.c | 15 +++++++++++++++ include/drm/drmP.h | 14 -------------- 11 files changed, 21 insertions(+), 33 deletions(-)
drivers/gpu/drm/drm_drv.c +0 -6
@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id)if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }return minor;
@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -if (dev->open_count ==0 ) {drm_put_dev (dev); }
drivers/gpu/drm/drm_fops.c +0 -2
@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file *filp)if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev); }mutex_unlock (&drm_global_mutex);
drivers/gpu/drm/drm_gem.c +0 -3
@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -drm_vma_offset_lock_lookup (dev->vma_offset_manager); node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager, vma->vm_pgoff,
drivers/gpu/drm/drm_ioctl.c +0 -3
@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {
drivers/gpu/drm/drm_vm.c +0 -3
@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);
drivers/gpu/drm/udl/udl_connector.c +1 -1
@@ -96,7 +96,7 @@ static int udl_mode_valid(struct drm_connector *connector,static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) +if (udl_device_is_unplugged (connector->dev))return connector_status_disconnected;return connector_status_connected; }
drivers/gpu/drm/udl/udl_drv.c +1 -0
@@ -97,6 +97,7 @@ static void udl_usb_disconnect(struct usb_interface *interface)drm_connector_unplug_all (dev);udl_fbdev_unplug (dev);udl_drop_usb (dev); +udl_device_set_unplugged (dev);drm_unplug_dev (dev); }
drivers/gpu/drm/udl/udl_drv.h +3 -0
@@ -65,6 +65,7 @@ struct udl_device {atomic_t bytes_identical;/* saved effort with backbuffer comparison */ atomic_t bytes_sent;/* to usb, after compression including overhead */ atomic_t cpu_kcycles_used;/* transpired during pixel processing */ +atomic_t unplugged;/* device has been unplugged or gone away */ };struct udl_gem_object {
@@ -140,6 +141,8 @@ int udl_handle_damage(struct udl_framebuffer *fb, int x, int y, int width, int height);int udl_drop_usb (struct drm_device *dev); +void udl_device_set_unplugged (struct drm_device *dev); +int udl_device_is_unplugged (struct drm_device *dev);#define CMD_WRITE_RAW8 "\xAF\x60"/**< 8 bit raw write command. */ #define CMD_WRITE_RL8 "\xAF\x61"/**< 8 bit run length command. */
drivers/gpu/drm/udl/udl_fb.c +1 -1
@@ -325,7 +325,7 @@ static int udl_fb_open(struct fb_info *info, int user)struct udl_device *udl = dev->dev_private;/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) +if (udl_device_is_unplugged (udl->ddev))return -ENODEV ; ufbdev->fb_count++;
drivers/gpu/drm/udl/udl_main.c +15 -0
@@ -350,3 +350,18 @@ int udl_driver_unload(struct drm_device *dev)kfree (udl);return 0 ; } + +void udl_device_set_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +smp_wmb (); +atomic_set (&udl->unplugged,1 ); +} + +int udl_device_is_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +int ret =atomic_read (&udl->unplugged); +smp_rmb (); +return ret; +}
include/drm/drmP.h +0 -14
@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */ struct inode *anon_inode;/**< inode for private address-space */ char *unique;/**< unique name of the device */ /*@} */
@@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,return ((dev->driver->driver_features & feature) ?1 :0 ); } -static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 ); -} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} -static inline bool drm_is_render_client (const struct drm_file *file_priv) {return file_priv->minor->type ==DRM_MINOR_RENDER ;
Signature · 6 lines
2.7.0.rc3.207.g0ac5344 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2 2/2] drm: remove drm_device_is_unplugged checks in common drm code.
Quoted 6 lines · Haixia Shi
When USB cable is disconnected, we mark udl device as unplugged so that
udl_detectreports connector status as disconnected, but still keep the drm device alive until user-space closes it.Signed-off-by Haixia Shi <[email protected]>Reviewed-by Stéphane Marchesin <[email protected]>
Please add more details capturing the discussion, i.e. why exactly this was done. Also, has Stephane really re-reviewed this new version already? And please Cc: everyone involved in the previous patch discussion, too.
Thanks, Daniel
Quoted 214 lines
--- drivers/gpu/drm/drm_drv.c | 6 ------ drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 --- drivers/gpu/drm/drm_ioctl.c | 3 --- drivers/gpu/drm/drm_vm.c | 3 --- drivers/gpu/drm/udl/udl_connector.c | 2 +- drivers/gpu/drm/udl/udl_drv.c | 1 + drivers/gpu/drm/udl/udl_drv.h | 3 +++ drivers/gpu/drm/udl/udl_fb.c | 2 +- drivers/gpu/drm/udl/udl_main.c | 15 +++++++++++++++ include/drm/drmP.h | 14 -------------- 11 files changed, 21 insertions(+), 33 deletions(-)drivers/gpu/drm/drm_drv.c +0
-6@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id)if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }return minor;@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -if (dev->open_count ==0 ) {drm_put_dev (dev); }drivers/gpu/drm/drm_fops.c +0
-2@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file *filp)if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev); }mutex_unlock (&drm_global_mutex);drivers/gpu/drm/drm_gem.c +0
-3@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -drm_vma_offset_lock_lookup (dev->vma_offset_manager); node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager, vma->vm_pgoff,drivers/gpu/drm/drm_ioctl.c +0
-3@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {drivers/gpu/drm/drm_vm.c +0
-3@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);drivers/gpu/drm/udl/udl_connector.c +1
-1@@ -96,7 +96,7 @@ static int udl_mode_valid(struct drm_connector *connector,static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) +if (udl_device_is_unplugged (connector->dev))return connector_status_disconnected;return connector_status_connected; }drivers/gpu/drm/udl/udl_drv.c +1
-0@@ -97,6 +97,7 @@ static void udl_usb_disconnect(struct usb_interface *interface)drm_connector_unplug_all (dev);udl_fbdev_unplug (dev);udl_drop_usb (dev); +udl_device_set_unplugged (dev);drm_unplug_dev (dev); }drivers/gpu/drm/udl/udl_drv.h +3
-0@@ -65,6 +65,7 @@ struct udl_device {atomic_t bytes_identical;/* saved effort with backbuffer comparison */ atomic_t bytes_sent;/* to usb, after compression including overhead */ atomic_t cpu_kcycles_used;/* transpired during pixel processing */ +atomic_t unplugged;/* device has been unplugged or gone away */ };struct udl_gem_object {@@ -140,6 +141,8 @@ int udl_handle_damage(struct udl_framebuffer *fb, int x, int y, int width, int height);int udl_drop_usb (struct drm_device *dev); +void udl_device_set_unplugged (struct drm_device *dev); +int udl_device_is_unplugged (struct drm_device *dev);#define CMD_WRITE_RAW8 "\xAF\x60"/**< 8 bit raw write command. */ #define CMD_WRITE_RL8 "\xAF\x61"/**< 8 bit run length command. */ drivers/gpu/drm/udl/udl_fb.c +1
-1@@ -325,7 +325,7 @@ static int udl_fb_open(struct fb_info *info, int user)struct udl_device *udl = dev->dev_private;/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) +if (udl_device_is_unplugged (udl->ddev))return -ENODEV ; ufbdev->fb_count++;drivers/gpu/drm/udl/udl_main.c +15
-0@@ -350,3 +350,18 @@ int udl_driver_unload(struct drm_device *dev)kfree (udl);return 0 ; } + +void udl_device_set_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +smp_wmb (); +atomic_set (&udl->unplugged,1 ); +} + +int udl_device_is_unplugged (struct drm_device *dev) +{ +struct udl_device *udl = dev->dev_private; +int ret =atomic_read (&udl->unplugged); +smp_rmb (); +return ret; +}include/drm/drmP.h +0
-14@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */ struct inode *anon_inode;/**< inode for private address-space */ char *unique;/**< unique name of the device */ /*@} */ @@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,return ((dev->driver->driver_features & feature) ?1 :0 ); } -static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 ); -} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} -static inline bool drm_is_render_client (const struct drm_file *file_priv) {return file_priv->minor->type ==DRM_MINOR_RENDER ;Signature · 6 lines
2.7.0.rc3.207.g0ac5344 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2 2/2] drm: remove drm_device_is_unplugged checks in common drm code.
In reply to Haixia ShiHi
Quoted 6 lines · Haixia Shi
When USB cable is disconnected, we mark udl device as unplugged so that
udl_detectreports connector status as disconnected, but still keep the drm device alive until user-space closes it.Signed-off-by Haixia Shi <[email protected]>Reviewed-by Stéphane Marchesin <[email protected]>
I assume this is based on the discussion I had with Stephane on IRC. I'm fine with going this way and keeping the device fully alive, and just treat the device removal as a connector-unplug. However, you really must document all this in your commit message.
Anyway, if you want to keep the device alive, then please change the code to entirely drop the "unplugged" flag and all related code. Then make sure you somehow reset "udl->udev" to NULL and make sure no code-path uses the usb-device after it was unplugged. I guess there should be appropriate locks already.
This way, you end up with a fully functional UDL device, which just happens to have to connector plugged. But you *really* have to be careful that no-one touches the usb device, as the interface might be re-used by some other device any time (or in case the usb-core provides protection against this, please document it).
Thanks
David
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2 2/2] drm: remove drm_device_is_unplugged checks in common drm code.
Well, in that case it would be even simpler. We don't even need the "unplugged" flag check in udl_detect because all connectors are already unplugged in udl_usb_disconnect (in drm_connector_unplug_all()).
It is not necessary to check the flag in udl_fb_open() either, if the intention is to keep the device alive.
As for code paths that uses udl->udev, I only see the following 3 places:
(1) udl_parse_vendor_description and udl_alloc_urb_list: both are only called at udl_driver_load(), so not a problem
(2) udl_usb_probe: won't happen after USB device is unplugged
(3) udl_get_edid: only called from udl_get_modes, won't be an issue because connectors are already unplugged
So, it seems that I *really* just need to drop the "unplugged" flag and update the commit message.
Quoted 21 lines · David Herrmann
Hi
Quoted 6 lines · Haixia Shi
When USB cable is disconnected, we mark udl device as unplugged so that
udl_detectreports connector status as disconnected, but still keep the drm device alive until user-space closes it.Signed-off-by Haixia Shi <[email protected]>Reviewed-by Stéphane Marchesin <[email protected]>I assume this is based on the discussion I had with Stephane on IRC. I'm fine with going this way and keeping the device fully alive, and just treat the device removal as a connector-unplug. However, you really must document all this in your commit message.
Anyway, if you want to keep the device alive, then please change the code to entirely drop the "unplugged" flag and all related code. Then make sure you somehow reset "
udl->udev" to NULL and make sure no code-path uses the usb-device after it was unplugged. I guess there should be appropriate locks already.
Quoted 9 lines
This way, you end up with a fully functional UDL device, which just happens to have to connector plugged. But you *really* have to be careful that no-one touches the usb device, as the interface might be re-used by some other device any time (or in case the usb-core provides protection against this, please document it).
Thanks
David
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 2/2 drm: remove drm_device_is_unplugged and related code
In reply to David HerrmannWhen a UDL monitor is unplugged, we need to still treat it as a fully functional device which just happens to have its connector unplugged. This allows user-space to properly deallocate fbs and dumb buffers before closing the device.
This drops the "unplugged" flag hack, which puts the device in a non-functional state after USB unplug and rejects most operations on the device such as ioctls with error -ENODEV.
--- drivers/gpu/drm/drm_drv.c | 6 ------ drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 --- drivers/gpu/drm/drm_ioctl.c | 3 --- drivers/gpu/drm/drm_vm.c | 3 --- drivers/gpu/drm/udl/udl_connector.c | 2 -- drivers/gpu/drm/udl/udl_fb.c | 6 ------ include/drm/drmP.h | 14 -------------- 8 files changed, 39 deletions(-)
drivers/gpu/drm/drm_drv.c +0 -6
@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id)if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }return minor;
@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -if (dev->open_count ==0 ) {drm_put_dev (dev); }
drivers/gpu/drm/drm_fops.c +0 -2
@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file *filp)if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev); }mutex_unlock (&drm_global_mutex);
drivers/gpu/drm/drm_gem.c +0 -3
@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -drm_vma_offset_lock_lookup (dev->vma_offset_manager); node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager, vma->vm_pgoff,
drivers/gpu/drm/drm_ioctl.c +0 -3
@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {
drivers/gpu/drm/drm_vm.c +0 -3
@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);
drivers/gpu/drm/udl/udl_connector.c +0 -2
@@ -96,8 +96,6 @@ static int udl_mode_valid(struct drm_connector *connector,static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) -return connector_status_disconnected;return connector_status_connected; }
drivers/gpu/drm/udl/udl_fb.c +0 -6
@@ -321,12 +321,6 @@ static void udl_fb_imageblit(struct fb_info *info, const struct fb_image *image)static int udl_fb_open (struct fb_info *info,int user) {struct udl_fbdev *ufbdev = info->par; -struct drm_device *dev = ufbdev->ufb.base.dev; -struct udl_device *udl = dev->dev_private; - -/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) -return -ENODEV ; ufbdev->fb_count++;
include/drm/drmP.h +0 -14
@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */ struct inode *anon_inode;/**< inode for private address-space */ char *unique;/**< unique name of the device */ /*@} */
@@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,return ((dev->driver->driver_features & feature) ?1 :0 ); } -static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 ); -} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} -static inline bool drm_is_render_client (const struct drm_file *file_priv) {return file_priv->minor->type ==DRM_MINOR_RENDER ;
Signature · 6 lines
2.7.0.rc3.207.g0ac5344 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 2/2] drm: remove drm_device_is_unplugged and related code
Quoted 5 lines · Haixia Shi
When a UDL monitor is unplugged, we need to still treat it as a fully functional device which just happens to have its connector unplugged. This allows user-space to properly deallocate fbs and dumb buffers before closing the device.
Quoted 7 lines
This drops the "unplugged" flag hack, which puts the device in a non-functional state after USB unplug and rejects most operations on the device such as ioctls with error
-ENODEV.Signed-off-by Haixia Shi <[email protected]>Reviewed-by Stéphane Marchesin <[email protected]>Cc David Herrmann <[email protected]>
Still missing the in-patch changelog. Please add something like
v2:
.... changes done for v2, and who suggested it
v3:
... changes done for v3.
Thanks, Daniel
Quoted 159 lines
--- drivers/gpu/drm/drm_drv.c | 6 ------ drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 --- drivers/gpu/drm/drm_ioctl.c | 3 --- drivers/gpu/drm/drm_vm.c | 3 --- drivers/gpu/drm/udl/udl_connector.c | 2 -- drivers/gpu/drm/udl/udl_fb.c | 6 ------ include/drm/drmP.h | 14 -------------- 8 files changed, 39 deletions(-)drivers/gpu/drm/drm_drv.c +0
-6@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id)if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }return minor;@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -if (dev->open_count ==0 ) {drm_put_dev (dev); }drivers/gpu/drm/drm_fops.c +0
-2@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file *filp)if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev); }mutex_unlock (&drm_global_mutex);drivers/gpu/drm/drm_gem.c +0
-3@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -drm_vma_offset_lock_lookup (dev->vma_offset_manager); node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager, vma->vm_pgoff,drivers/gpu/drm/drm_ioctl.c +0
-3@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {drivers/gpu/drm/drm_vm.c +0
-3@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);drivers/gpu/drm/udl/udl_connector.c +0
-2@@ -96,8 +96,6 @@ static int udl_mode_valid(struct drm_connector *connector,static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) -return connector_status_disconnected;return connector_status_connected; }drivers/gpu/drm/udl/udl_fb.c +0
-6@@ -321,12 +321,6 @@ static void udl_fb_imageblit(struct fb_info *info, const struct fb_image *image)static int udl_fb_open (struct fb_info *info,int user) {struct udl_fbdev *ufbdev = info->par; -struct drm_device *dev = ufbdev->ufb.base.dev; -struct udl_device *udl = dev->dev_private; - -/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) -return -ENODEV ; ufbdev->fb_count++;include/drm/drmP.h +0
-14@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */ struct inode *anon_inode;/**< inode for private address-space */ char *unique;/**< unique name of the device */ /*@} */ @@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,return ((dev->driver->driver_features & feature) ?1 :0 ); } -static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 ); -} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} -static inline bool drm_is_render_client (const struct drm_file *file_priv) {return file_priv->minor->type ==DRM_MINOR_RENDER ;Signature · 6 lines
2.7.0.rc3.207.g0ac5344 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 2/2 drm: remove drm_device_is_unplugged and related code
In reply to Haixia Shiv1: Remove the general drm_device_is_unplugged() checks, and move the unplugged flag handling logic into drm/udl. In general we want to keep driver-specific logic out of common drm code.
v2: Based on discussion with Stephane and David, drop most of the unplugged flag handling logic in drm/udl except for udl_detect() and udl_fb_open(). The intention is to treat the device removal as a connector-unplug, and kep the UDL device fully functional.
v3: Based on feedback from David, entirely drop the "unplugged" flag and all related code. There is no need to check for the unplugged flag as the existing udl_usb_disconnect() behavior already ensures the controller is removed, and all code paths that uses the usb-device are not reachable after unplug.
When a UDL monitor is unplugged, we need to still treat it as a fully functional device which just happens to have its connector unplugged. This allows user-space to properly deallocate fbs and dumb buffers before closing the device.
This drops the "unplugged" flag hack, which puts the device in a non-functional state after USB unplug and rejects most operations on the device such as ioctls with error -ENODEV.
--- drivers/gpu/drm/drm_drv.c | 6 ------ drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 --- drivers/gpu/drm/drm_ioctl.c | 3 --- drivers/gpu/drm/drm_vm.c | 3 --- drivers/gpu/drm/udl/udl_connector.c | 2 -- drivers/gpu/drm/udl/udl_fb.c | 6 ------ include/drm/drmP.h | 14 -------------- 8 files changed, 39 deletions(-)
drivers/gpu/drm/drm_drv.c +0 -6
@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id)if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }return minor;
@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -if (dev->open_count ==0 ) {drm_put_dev (dev); }
drivers/gpu/drm/drm_fops.c +0 -2
@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file *filp)if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev); }mutex_unlock (&drm_global_mutex);
drivers/gpu/drm/drm_gem.c +0 -3
@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -drm_vma_offset_lock_lookup (dev->vma_offset_manager); node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager, vma->vm_pgoff,
drivers/gpu/drm/drm_ioctl.c +0 -3
@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {
drivers/gpu/drm/drm_vm.c +0 -3
@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);
drivers/gpu/drm/udl/udl_connector.c +0 -2
@@ -96,8 +96,6 @@ static int udl_mode_valid(struct drm_connector *connector,static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) -return connector_status_disconnected;return connector_status_connected; }
drivers/gpu/drm/udl/udl_fb.c +0 -6
@@ -321,12 +321,6 @@ static void udl_fb_imageblit(struct fb_info *info, const struct fb_image *image)static int udl_fb_open (struct fb_info *info,int user) {struct udl_fbdev *ufbdev = info->par; -struct drm_device *dev = ufbdev->ufb.base.dev; -struct udl_device *udl = dev->dev_private; - -/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) -return -ENODEV ; ufbdev->fb_count++;
include/drm/drmP.h +0 -14
@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */ struct inode *anon_inode;/**< inode for private address-space */ char *unique;/**< unique name of the device */ /*@} */
@@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,return ((dev->driver->driver_features & feature) ?1 :0 ); } -static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 ); -} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} -static inline bool drm_is_render_client (const struct drm_file *file_priv) {return file_priv->minor->type ==DRM_MINOR_RENDER ;
Signature · 6 lines
2.7.0.rc3.207.g0ac5344 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 2/2] drm: remove drm_device_is_unplugged and related code
David - is the v3 patch acceptable to you? Thanks.
Quoted 194 lines · Haixia Shi
v1: Remove the general
drm_device_is_unplugged()checks, and move the unplugged
flag handling logic into drm/udl. In general we want to keep driver-specific
logic out of common drm code.v2: Based on discussion with Stephane and David, drop most of the unplugged flag handling logic in drm/udl except for
udl_detect()andudl_fb_open(). The intention is to treat the device removal as a connector-unplug, and kep the UDL device fully functional.v3: Based on feedback from David, entirely drop the "unplugged" flag and all
related code. There is no need to check for the unplugged flag as the existingudl_usb_disconnect()behavior already ensures the controller is removed, and
all code paths that uses the usb-device are not reachable after unplug.When a UDL monitor is unplugged, we need to still treat it as a fully functional device which just happens to have its connector unplugged. This allows user-space to properly deallocate fbs and dumb buffers before closing the device.
This drops the "unplugged" flag hack, which puts the device in a non-functional state after USB unplug and rejects most operations on the device such as ioctls with error
-ENODEV.Signed-off-by Haixia Shi <[email protected]>Reviewed-by Stéphane Marchesin <[email protected]>Cc David Herrmann <[email protected]>Cc Daniel Vetter <[email protected]>--- drivers/gpu/drm/drm_drv.c | 6 ------ drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 --- drivers/gpu/drm/drm_ioctl.c | 3 --- drivers/gpu/drm/drm_vm.c | 3 --- drivers/gpu/drm/udl/udl_connector.c | 2 -- drivers/gpu/drm/udl/udl_fb.c | 6 ------ include/drm/drmP.h | 14 -------------- 8 files changed, 39 deletions(-)drivers/gpu/drm/drm_drv.c +0
-3@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id)if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }return minor;drivers/gpu/drm/drm_drv.c +0
-3@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -if (dev->open_count ==0 ) {drm_put_dev (dev); }drivers/gpu/drm/drm_fops.c +0
-2@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file *filp)if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev); }mutex_unlock (&drm_global_mutex);drivers/gpu/drm/drm_gem.c +0
-3@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -drm_vma_offset_lock_lookup (dev->vma_offset_manager); node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager,vma->vm_pgoff,drivers/gpu/drm/drm_ioctl.c +0
-3@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {drivers/gpu/drm/drm_vm.c +0
-3@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock(&dev->struct_mutex);drivers/gpu/drm/udl/udl_connector.c +0
-2@@ -96,8 +96,6 @@ static int udl_mode_valid(struct drm_connector *connector, static enum drm_connector_statusudl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) -return connector_status_disconnected;return connector_status_connected; }drivers/gpu/drm/udl/udl_fb.c +0
-6@@ -321,12 +321,6 @@ static void udl_fb_imageblit(struct fb_info *info, const struct fb_image *image)static int udl_fb_open (struct fb_info *info,int user) {struct udl_fbdev *ufbdev = info->par; -struct drm_device *dev = ufbdev->ufb.base.dev; -struct udl_device *udl = dev->dev_private; - -/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) -return -ENODEV ; ufbdev->fb_count++;include/drm/drmP.h +0
-1@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */
struct inode*anon_inode; /**< inode for private
address-space */
char *unique; /**< unique name of the
device *//*@} */include/drm/drmP.h +0
-13@@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev, return ((dev->driver->driver_features & feature) ? 1 : 0); } -static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 ); -} - -static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} -static inline bool drm_is_render_client (const struct drm_file *file_priv) {return file_priv->minor->type == DRM_MINOR_RENDER;
Quoted 4 lines
--
2.7.0.rc3.207.g0ac5344
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 2/2] drm: remove drm_device_is_unplugged and related code
In reply to Haixia ShiHi
Quoted 67 lines · Haixia Shi
v1: Remove the general
drm_device_is_unplugged()checks, and move the unplugged flag handling logic into drm/udl. In general we want to keep driver-specific logic out of common drm code.v2: Based on discussion with Stephane and David, drop most of the unplugged flag handling logic in drm/udl except for
udl_detect()andudl_fb_open(). The intention is to treat the device removal as a connector-unplug, and kep the UDL device fully functional.v3: Based on feedback from David, entirely drop the "unplugged" flag and all related code. There is no need to check for the unplugged flag as the existing
udl_usb_disconnect()behavior already ensures the controller is removed, and all code paths that uses the usb-device are not reachable after unplug.When a UDL monitor is unplugged, we need to still treat it as a fully functional device which just happens to have its connector unplugged. This allows user-space to properly deallocate fbs and dumb buffers before closing the device.
This drops the "unplugged" flag hack, which puts the device in a non-functional state after USB unplug and rejects most operations on the device such as ioctls with error
-ENODEV.Signed-off-by Haixia Shi <[email protected]>Reviewed-by Stéphane Marchesin <[email protected]>Cc David Herrmann <[email protected]>Cc Daniel Vetter <[email protected]>--- drivers/gpu/drm/drm_drv.c | 6 ------ drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 --- drivers/gpu/drm/drm_ioctl.c | 3 --- drivers/gpu/drm/drm_vm.c | 3 --- drivers/gpu/drm/udl/udl_connector.c | 2 -- drivers/gpu/drm/udl/udl_fb.c | 6 ------ include/drm/drmP.h | 14 -------------- 8 files changed, 39 deletions(-)drivers/gpu/drm/drm_drv.c +0
-6@@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id)if (!minor) {return ERR_PTR (-ENODEV ); - }else if (drm_device_is_unplugged (minor->dev)) { -drm_dev_unref (minor->dev); -return ERR_PTR (-ENODEV ); }return minor;@@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev)drm_minor_unregister (dev,DRM_MINOR_CONTROL );mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); -if (dev->open_count ==0 ) {drm_put_dev (dev); }drivers/gpu/drm/drm_fops.c +0
-0
drivers/gpu/drm/drm_fops.c int drm_release(struct inode *inode, struct file *filp) · line 501
Quoted 5 lines
drivers/gpu/drm/drm_fops.c +0
-2@@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file *filp)if (!--dev->open_count) { retcode =drm_lastclose (dev); -if (drm_device_is_unplugged (dev)) -drm_put_dev (dev);
Who frees the udl device now? What code-path is responsible to call drm_dev_unregister() for udl devices? This hunk looks bogus to me. Please elaborate.
Quoted 50 lines
drivers/gpu/drm/drm_fops.c +0
-0}mutex_unlock (&drm_global_mutex);drivers/gpu/drm/drm_gem.c +0
-3@@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_vma_offset_node *node;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -drm_vma_offset_lock_lookup (dev->vma_offset_manager); node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager, vma->vm_pgoff,drivers/gpu/drm/drm_ioctl.c +0
-3@@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; - is_driver_ioctl = nr >=DRM_COMMAND_BASE && nr <DRM_COMMAND_END ;if (is_driver_ioctl) {drivers/gpu/drm/drm_vm.c +0
-3@@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma)struct drm_device *dev = priv->minor->dev;int ret; -if (drm_device_is_unplugged (dev)) -return -ENODEV ; -mutex_lock (&dev->struct_mutex); ret =drm_mmap_locked (filp, vma);mutex_unlock (&dev->struct_mutex);drivers/gpu/drm/udl/udl_connector.c +0
-0
drivers/gpu/drm/udl/udl_connector.c static int udl_mode_valid(struct drm_connector *connector, · line 99
Quoted 6 lines
drivers/gpu/drm/udl/udl_connector.c +0
-2@@ -96,8 +96,6 @@ static int udl_mode_valid(struct drm_connector *connector,static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) { -if (drm_device_is_unplugged (connector->dev)) -return connector_status_disconnected;return connector_status_connected;
Who marks a connector as "disconnect" once the device is removed?
Quoted 41 lines
drivers/gpu/drm/udl/udl_connector.c +0
-0}drivers/gpu/drm/udl/udl_fb.c +0
-6@@ -321,12 +321,6 @@ static void udl_fb_imageblit(struct fb_info *info, const struct fb_image *image)static int udl_fb_open (struct fb_info *info,int user) {struct udl_fbdev *ufbdev = info->par; -struct drm_device *dev = ufbdev->ufb.base.dev; -struct udl_device *udl = dev->dev_private; - -/* If the USB device is gone, we don't accept new opens */ -if (drm_device_is_unplugged (udl->ddev)) -return -ENODEV ; ufbdev->fb_count++;include/drm/drmP.h +0
-7@@ -748,7 +748,6 @@ struct drm_device {struct drm_minor *control;/**< Control node */ struct drm_minor *primary;/**< Primary node */ struct drm_minor *render;/**< Render node */ -atomic_t unplugged;/**< Flag whether dev is dead */ struct inode *anon_inode;/**< inode for private address-space */ char *unique;/**< unique name of the device */ /*@} */ @@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,return ((dev->driver->driver_features & feature) ?1 :0 ); } -static inline void drm_device_set_unplugged (struct drm_device *dev) -{ -smp_wmb (); -atomic_set (&dev->unplugged,1 ); -} -
include/drm/drmP.h static __inline__ int drm_core_check_feature(struct drm_device *dev, · line 883
Quoted 10 lines
include/drm/drmP.h +0
-7-static inline int drm_device_is_unplugged (struct drm_device *dev) -{ -int ret =atomic_read (&dev->unplugged); -smp_rmb (); -return ret; -} -static inline bool drm_is_render_client (const struct drm_file *file_priv) {return file_priv->minor->type ==DRM_MINOR_RENDER ;
Did you actually test this patch? How is it supposed to work? Please explain _exactly_ in your commit message what the new semantics are. I highly doubt that this patch does what you want. Also, please run kmemleak on your tests to verify that all memory is actually released.
Generally, I like the approach. However, I think you still need a state that marks a device as dropped. I'd do something like this:
1) In udl_usb_disconnect(), set udl->udev to NULL, locked by mode_config.mutex. This should be the _first_ thing you do there. This serves as barrier against ->get_modes(), which is the only path that uses "udl->udev".
2) In udl_detect(), return 'connector_status_disconnected' if "udl->udev" is NULL.
3) In udl_get_edid() add "if (WARN_ON(!udl->udev)) return NULL;"
4) Hook into f_ops.release() and call into drm_release(). But afterwards you have to call drm_put_dev() if open_count is 0 now.
Thanks
David
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel