drm: Unplug drm device when unregistering it (v7)
Subsystems (3)
PATCH v10 1/1 drm: Unplug drm device when unregistering it (v7)
After unbinding drm, the user space may still owns the drm dev fd, and may still be able to call drm ioctl.
We're using an unplugged state to prevent something like that, so let's reuse it here.
Also drop drm_unplug_dev, because it would be unused after other changes.
Verified on rk3399 chromebook kevin(with cros 4.4 kernel), no more crashes when unbinding drm with ui service still running.
v2: Fix some commit messages.
v3: Reuse unplug status.
v4: Add drm_device_set_plug_state helper.
v5: Fix hang when unregistering drm dev with open_count 0.
v6: Move drm_device_set_plug_state into drm_drv.
v7: Add missing drm_dev_unref in udl_drv.
---
drivers/gpu/drm/drm_drv.c | 26 ++++++++++---------------- drivers/gpu/drm/udl/udl_drv.c | 3 ++- include/drm/drmP.h | 6 ------ include/drm/drm_drv.h | 1 - 4 files changed, 12 insertions(+), 24 deletions(-)
drivers/gpu/drm/drm_drv.c +10 -16
@@ -355,22 +355,6 @@ void drm_put_dev(struct drm_device *dev) }EXPORT_SYMBOL (drm_put_dev); -void drm_unplug_dev (struct drm_device *dev) -{ -/* for a USB device */ -drm_dev_unregister (dev); - -mutex_lock (&drm_global_mutex); - -drm_device_set_unplugged (dev); - -if (dev->open_count ==0 ) { -drm_put_dev (dev); - } -mutex_unlock (&drm_global_mutex); -} -EXPORT_SYMBOL (drm_unplug_dev); -/* * DRM internal mount * We want to be able to allocate our own "struct address_space" to control
@@ -733,6 +717,13 @@ static void remove_compat_control_link(struct drm_device *dev)kfree (name); } +static inline void drm_device_set_plug_state (struct drm_device *dev, +bool plugged) +{ +smp_wmb (); +atomic_set (&dev->unplugged, !plugged); +} +/** * drm_dev_register - Register DRM device * @dev: Device to register
@@ -787,6 +778,8 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)if (drm_core_check_feature (dev,DRIVER_MODESET ))drm_modeset_register_all (dev); +drm_device_set_plug_state (dev, true); + ret =0 ; DRM_INFO("Initialized %s %d.%d.%d %s for %s on minor %d\n",
@@ -826,6 +819,7 @@ void drm_dev_unregister(struct drm_device *dev)drm_lastclose (dev); dev->registered = false; +drm_device_set_plug_state (dev, false);if (drm_core_check_feature (dev,DRIVER_MODESET ))drm_modeset_unregister_all (dev);
drivers/gpu/drm/udl/udl_drv.c +2 -1
@@ -108,7 +108,8 @@ static void udl_usb_disconnect(struct usb_interface *interface)drm_kms_helper_poll_disable (dev);udl_fbdev_unplug (dev);udl_drop_usb (dev); -drm_unplug_dev (dev); +drm_dev_unregister (dev); +drm_dev_unref (drm_dev); }/*
include/drm/drmP.h +0 -6
@@ -488,12 +488,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);
include/drm/drm_drv.h +0 -1
@@ -544,7 +544,6 @@ void drm_dev_unregister(struct drm_device *dev);void drm_dev_ref (struct drm_device *dev);void drm_dev_unref (struct drm_device *dev);void drm_put_dev (struct drm_device *dev); -void drm_unplug_dev (struct drm_device *dev);int drm_dev_set_unique (struct drm_device *dev,const char *name);
Signature · 1 line
2.1.4
kbuild test robot
build botreproduce:
Hi Jeffy,
[auto build test ERROR on drm/drm-next]
[also build test ERROR on v4.11-rc6 next-20170413]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Jeffy-Chen/drm-Unplug-drm-device-when-unregistering-it-v7/20170413-130045 base: git://people.freedesktop.org/~airlied/linux.git drm-next config: x86_64-randconfig-x012-201715 (attached as .config) compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce: # save the attached .config to linux build tree make ARCH=x86_64
All errors (new ones prefixed by >>):
drivers/gpu//drm/udl/udl_drv.c: In function 'udl_usb_disconnect':
>> drivers/gpu//drm/udl/udl_drv.c:112:16: error: 'drm_dev' undeclared (first use in this function)
drm_dev_unref(drm_dev);
^~~~~~~drivers/gpu//drm/udl/udl_drv.c:112:16: note: each undeclared identifier is reported only once for each function it appears in
vim +/drm_dev +112 drivers/gpu//drm/udl/udl_drv.c
106 struct drm_device *dev = usb_get_intfdata(interface);
107
108 drm_kms_helper_poll_disable(dev);
109 udl_fbdev_unplug(dev);
110 udl_drop_usb(dev);
111 drm_dev_unregister(dev);
> 112 drm_dev_unref(drm_dev);
113 }
114
115 /*
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation