Skip to contentSkip to conversation

drm/i915: Fix module unloading with DRM_I915_UMS=n

PATCH In review Daniel Vetter 4 participants 7 messages Nov 15, 2013 – Nov 25, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915: Fix module unloading with DRM_I915_UMS=n

Oops, makes testing early boot failures in i915.ko a bit more pain, so let's fix it.

---
 drivers/gpu/drm/i915/i915_drv.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/i915/i915_drv.c +6 -0
index c2e00ed23195..d9e5c6fc52ea 100644
@@ -982,6 +982,8 @@ static struct pci_driver i915_pci_driver = {
 	.driver.pm = &i915_pm_ops,
 };
 
+bool i915_no_driver_loaded;
+
 static int __init i915_init(void)
 {
 	driver.num_ioctls = i915_max_ioctl;
@@ -1011,6 +1013,7 @@ static int __init i915_init(void)
 		driver.get_vblank_timestamp = NULL;
 #ifndef CONFIG_DRM_I915_UMS
 		/* Silently fail loading to not upset userspace. */
+		i915_no_driver_loaded = true;
 		return 0;
 #endif
 	}
@@ -1020,6 +1023,9 @@ static int __init i915_init(void)
 
 static void __exit i915_exit(void)
 {
+	if (i915_no_driver_loaded)
+		return;
+
 	drm_pci_exit(&driver, &i915_pci_driver);
 }
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 2 lines · Daniel Vetter

Oops, makes testing early boot failures in i915.ko a bit more pain, so let's fix it.

You already have a static driver structure, why not take advantage of that here?
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#2 lore raw

PATCH 1/1 drm/i915: Fix module unloading with DRM_I915_UMS=n

Oops, makes testing early boot failures in i915.ko a bit more pain, so let's fix it.

v2: We already have a bit of static storage to track this (Chris).

---
 drivers/gpu/drm/i915/i915_drv.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/i915/i915_drv.c +5 -0
index c2e00ed23195..72fc9e33c78c 100644
@@ -1020,6 +1020,11 @@ static int __init i915_init(void)
 
 static void __exit i915_exit(void)
 {
+#ifndef CONFIG_DRM_I915_UMS
+	if (!(driver.driver_features & DRIVER_MODESET))
+		return; /* Never loaded a driver. */
+#endif
+
 	drm_pci_exit(&driver, &i915_pci_driver);
 }
 
Signature · 1 line
1.8.3.1
#3 lore raw
Quoted 7 lines · Daniel Vetter

Oops, makes testing early boot failures in i915.ko a bit more pain, so let's fix it.

v2: We already have a bit of static storage to track this (Chris).

How about just fixing the core not to die?

drivers/gpu/drm/drm_pci.c +8 -3
index f00d7a9..3b9c7ce 100644
@@ -375,13 +375,13 @@ int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver)
 
        DRM_DEBUG("\n");
 
+       if (driver->driver_features & DRIVER_MODESET)
+               return pci_register_driver(pdriver);
+
        INIT_LIST_HEAD(&driver->device_list);
        driver->kdriver.pci = pdriver;
        driver->bus = &drm_pci_bus;
 
-       if (driver->driver_features & DRIVER_MODESET)
-               return pci_register_driver(pdriver);
-
        /* If not using KMS, fall back to stealth mode manual scanning. */
        for (i = 0; pdriver->id_table[i].vendor != 0; i++) {
                pid = &pdriver->id_table[i];
@@ -462,6 +462,11 @@ void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver)
        struct drm_device *dev, *tmp;
        DRM_DEBUG("\n");
 
+       if (!driver->kdriver.pci)
+               return;
+
+       WARN_ON(driver->kdriver.pci != pdriver);
+
        if (driver->driver_features & DRIVER_MODESET) {
                pci_unregister_driver(pdriver);
        } else {

We can drop the redundant pdriver later.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#4 lore raw
Quoted 10 lines · Chris Wilson
Quoted 7 lines · Daniel Vetter

Oops, makes testing early boot failures in i915.ko a bit more pain, so let's fix it.

v2: We already have a bit of static storage to track this (Chris).

How about just fixing the core not to die?

This is for the disabled UMS code where we silently don't register anything. So there's also nothing to clean up, i.e. we've called drm_pci_exit without drm_pci_init. I don't think this is something we should allow in the core.
-Daniel

Quoted 40 lines
drivers/gpu/drm/drm_pci.c +8 -3
index f00d7a9..3b9c7ce 100644
@@ -375,13 +375,13 @@ int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver)
 
        DRM_DEBUG("\n");
 
+       if (driver->driver_features & DRIVER_MODESET)
+               return pci_register_driver(pdriver);
+
        INIT_LIST_HEAD(&driver->device_list);
        driver->kdriver.pci = pdriver;
        driver->bus = &drm_pci_bus;
 
-       if (driver->driver_features & DRIVER_MODESET)
-               return pci_register_driver(pdriver);
-
        /* If not using KMS, fall back to stealth mode manual scanning. */
        for (i = 0; pdriver->id_table[i].vendor != 0; i++) {
                pid = &pdriver->id_table[i];
@@ -462,6 +462,11 @@ void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver)
        struct drm_device *dev, *tmp;
        DRM_DEBUG("\n");
 
+       if (!driver->kdriver.pci)
+               return;
+
+       WARN_ON(driver->kdriver.pci != pdriver);
+
        if (driver->driver_features & DRIVER_MODESET) {
                pci_unregister_driver(pdriver);
        } else {

We can drop the redundant pdriver later.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Reviewed-by Tested-by on v1 1/1
#5 lore raw
In reply to Daniel Vetter

2013/11/15 Daniel Vetter <[email protected]>:

Quoted 7 lines

Oops, makes testing early boot failures in i915.ko a bit more pain, so let's fix it.

v2: We already have a bit of static storage to track this (Chris).

I can reproduce the failure by booting with i915.modeset=0, then get the oops when "rmmod i915".

I also looked at Chris' patch. I think that since we take the early "return 0" inside i915_init, we never call drm_pci_init, so it doesn't make too much sense to fix the problem inside drm_pci_exit.

Quoted 27 lines
---
 drivers/gpu/drm/i915/i915_drv.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/i915/i915_drv.c +5 -1
index c2e00ed23195..72fc9e33c78c 100644
@@ -1020,6 +1020,11 @@ static int __init i915_init(void)
 
 static void __exit i915_exit(void)
 {
+#ifndef CONFIG_DRM_I915_UMS
+       if (!(driver.driver_features & DRIVER_MODESET))
+               return; /* Never loaded a driver. */
+#endif
+
        drm_pci_exit(&driver, &i915_pci_driver);
 }
 
--

1.8.3.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 1 line
Paulo Zanoni
#6 lore raw
Quoted 12 lines · Paulo Zanoni

2013/11/15 Daniel Vetter <[email protected]>:

Quoted 7 lines

Oops, makes testing early boot failures in i915.ko a bit more pain, so let's fix it.

v2: We already have a bit of static storage to track this (Chris).

I can reproduce the failure by booting with i915.modeset=0, then get the oops when "rmmod i915".

Quoted 6 lines

I also looked at Chris' patch. I think that since we take the early "return 0" inside i915_init, we never call drm_pci_init, so it doesn't make too much sense to fix the problem inside drm_pci_exit.

Thanks for review&testing, patch merged.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch