Skip to contentSkip to conversation

drm: rockchip: Fix rockchip drm unbind crash error

PATCH Superseded Jeffy Chen 2 participants 4 messages Apr 12, 2017 – Apr 13, 2017

Subsystems (3)

v9 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Jeffy Chen

author
#0 lore raw

v9 cover drm: rockchip: Fix rockchip drm unbind crash error

Verified on rk3399 chromebook kevin(with cros 4.4 kernel), no more crashes during unbind/bind drm with/out ui service running.

Changes in v9:
Move drm_device_set_plug_state into drm_drv.c .

Changes in v8:
Fix hang when unregistering drm dev with open_count 0.

Changes in v7:
Add drm_device_set_plug_state helper.

Changes in v6:
Reuse unplug status.

Changes in v5:
Fix wrong git account.

Changes in v2:
Fix some commit messages.

Jeffy Chen (1):
drm: Unplug drm device when unregistering it

 drivers/gpu/drm/drm_drv.c     | 26 ++++++++++----------------
 drivers/gpu/drm/udl/udl_drv.c |  2 +-
 include/drm/drmP.h            |  6 ------
 include/drm/drm_drv.h         |  1 -
 4 files changed, 11 insertions(+), 24 deletions(-)
Signature · 1 line
2.1.4
author
#1 lore raw

PATCH v9 1/1 drm: Unplug drm device when unregistering it

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.

Changes in v9:
Move drm_device_set_plug_state into drm_drv.c .

Changes in v8:
Fix hang when unregistering drm dev with open_count 0.

Changes in v7:
Add drm_device_set_plug_state helper.

Changes in v6:
Reuse unplug status.

Changes in v5:
Fix wrong git account.

Changes in v2:
Fix some commit messages.

---
 drivers/gpu/drm/drm_drv.c     | 26 ++++++++++----------------
 drivers/gpu/drm/udl/udl_drv.c |  2 +-
 include/drm/drmP.h            |  6 ------
 include/drm/drm_drv.h         |  1 -
 4 files changed, 11 insertions(+), 24 deletions(-)
drivers/gpu/drm/drm_drv.c +10 -16
index b5c6bb4..e1da4d1 100644
@@ -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 +1 -1
index cd8b017..5dbd916 100644
@@ -108,7 +108,7 @@ 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);
 }
 
 /*
include/drm/drmP.h +0 -6
index 3bfafcd..980a204 100644
@@ -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
index 0fefc3f..eb63078 100644
@@ -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
#2 lore raw

Re: [PATCH v9] drm: Unplug drm device when unregistering it

Quoted 19 lines · Jeffy Chen

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.

Changes in v9:
Move drm_device_set_plug_state into drm_drv.c .

Changes in v8:
Fix hang when unregistering drm dev with open_count 0.

Changes in v7:
Add drm_device_set_plug_state helper.

Quoted 9 lines

Changes in v6:
Reuse unplug status.

Changes in v5:
Fix wrong git account.

Changes in v2:
Fix some commit messages.

Hi Jeffy,
A couple bookkeeping notes:

- Please end the commit message with your Signed-off-by tag
- No need to send cover letters for one patch. All info should be in the commit message. Include superfluous information (such as tested on 4.4 kernel) after
---

Quoted 70 lines
---
 drivers/gpu/drm/drm_drv.c     | 26 ++++++++++----------------
 drivers/gpu/drm/udl/udl_drv.c |  2 +-
 include/drm/drmP.h            |  6 ------
 include/drm/drm_drv.h         |  1 -
 4 files changed, 11 insertions(+), 24 deletions(-)
drivers/gpu/drm/drm_drv.c +10 -16
index b5c6bb4..e1da4d1 100644
@@ -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 +0 -0
index cd8b017..5dbd916 100644

drivers/gpu/drm/udl/udl_drv.c static void udl_usb_disconnect(struct usb_interface *interface) · line 111

Quoted 5 lines
drivers/gpu/drm/udl/udl_drv.c +1 -1
@@ -108,7 +108,7 @@ 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);

I think you need drm_dev_unref here as well.

Sean

Quoted 35 lines
drivers/gpu/drm/udl/udl_drv.c +0 -0
 }
 
 /*
include/drm/drmP.h +0 -6
index 3bfafcd..980a204 100644
@@ -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
index 0fefc3f..eb63078 100644
@@ -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
Signature · 5 lines
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#3 lore raw

Re: [PATCH v9] drm: Unplug drm device when unregistering it

Hi Sean,

Quoted 30 lines · Sean Paul
Quoted 19 lines · Jeffy Chen

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.

Changes in v9:
Move drm_device_set_plug_state into drm_drv.c .

Changes in v8:
Fix hang when unregistering drm dev with open_count 0.

Changes in v7:
Add drm_device_set_plug_state helper.

Quoted 9 lines

Changes in v6:
Reuse unplug status.

Changes in v5:
Fix wrong git account.

Changes in v2:
Fix some commit messages.

Quoted 7 lines

Hi Jeffy,
A couple bookkeeping notes:

- Please end the commit message with your Signed-off-by tag
- No need to send cover letters for one patch. All info should be in the commit message. Include superfluous information (such as tested on 4.4 kernel) after
---

hmm...i'm using u-boot's patman tool to send patches. and the changelogs would be formated by the tool.

i'll switch changelogs to drm style.

Quoted 64 lines
Quoted 64 lines
---
  drivers/gpu/drm/drm_drv.c     | 26 ++++++++++----------------
  drivers/gpu/drm/udl/udl_drv.c |  2 +-
  include/drm/drmP.h            |  6 ------
  include/drm/drm_drv.h         |  1 -
  4 files changed, 11 insertions(+), 24 deletions(-)
drivers/gpu/drm/drm_drv.c +10 -16
index b5c6bb4..e1da4d1 100644
@@ -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);
 
Quoted 14 lines

drivers/gpu/drm/udl/udl_drv.c static void udl_usb_disconnect(struct usb_interface *interface) · line 111

Quoted 12 lines
drivers/gpu/drm/drm_drv.c +0 -0
  	if (drm_core_check_feature(dev, DRIVER_MODESET))
  		drm_modeset_unregister_all(dev);
drivers/gpu/drm/udl/udl_drv.c +1 -1
index cd8b017..5dbd916 100644
@@ -108,7 +108,7 @@ 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);

I think you need drm_dev_unref here as well.

right, will do.

Quoted 39 lines

Sean

Quoted 35 lines
drivers/gpu/drm/udl/udl_drv.c +0 -0
  }
 
  /*
include/drm/drmP.h +0 -6
index 3bfafcd..980a204 100644
@@ -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 -2
index 0fefc3f..eb63078 100644
@@ -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);
 
--

2.1.4