Skip to contentSkip to conversation

Runtime pm ref leak bonanza

PATCH In review Lukas Wunner 6 participants 24 messages Jun 8, 2016 – Jun 22, 2016 6 messages not in the archive

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

v2 cover Runtime pm ref leak bonanza

Second iteration of my endeavour to rid nouveau, radeon and amdgpu of runtime pm ref leaks.

Patches 1 to 8 are identical to v1.

Patch 9 of v1 modified the DRM core to turn off all CRTCs on driver unload. Based on feedback by Daniel Vetter, I've replaced this with a helper to turn off all CRTCs, which is called by nouveau, radeon and amdgpu on unload. In other words, this is now opt-in. So patch 9 of v1 is replaced with new patches 9 to 12.

A by-product of patch 9 is a helper which turns off a *single* CRTC. This is open coded in three other places in the DRM tree and patches 13 to 15 refactor those to use the new helper.

To ease reviewing, I've pushed this series to GitHub:
https://github.com/l1k/linux/commits/drm_runpm_fixes_v2

The discussion on v1 is archived here:
https://lists.freedesktop.org/archives/dri-devel/2016-May/thread.html#108278

Thanks,

Lukas

Lukas Wunner (15):
drm/nouveau: Don't leak runtime pm ref on driver unload drm/nouveau: Forbid runtime pm on driver unload drm/radeon: Don't leak runtime pm ref on driver unload drm/radeon: Don't leak runtime pm ref on driver load drm/radeon: Forbid runtime pm on driver unload drm/amdgpu: Don't leak runtime pm ref on driver unload drm/amdgpu: Don't leak runtime pm ref on driver load drm/amdgpu: Forbid runtime pm on driver unload
drm: Add helpers to turn off CRTCs drm/nouveau: Turn off CRTCs on driver unload drm/radeon: Turn off CRTCs on driver unload drm/amdgpu: Turn off CRTCs on driver unload
drm: Use helper to turn off CRTC drm/i2c/ch7006: Use helper to turn off CRTC drm/nouveau/dispnv04: Use helper to turn off CRTC

 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    | 12 +++++--
 drivers/gpu/drm/drm_crtc.c                 | 53 ++++++++++++++++++++++++++----
 drivers/gpu/drm/i2c/ch7006_drv.c           |  9 ++---
 drivers/gpu/drm/nouveau/dispnv04/disp.c    | 10 ------
 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c  |  9 ++---
 drivers/gpu/drm/nouveau/nouveau_display.c  |  1 +
 drivers/gpu/drm/nouveau/nouveau_drm.c      |  6 +++-
 drivers/gpu/drm/radeon/radeon_device.c     |  4 +++
 drivers/gpu/drm/radeon/radeon_display.c    |  1 +
 drivers/gpu/drm/radeon/radeon_kms.c        |  5 ++-
 include/drm/drm_crtc.h                     |  2 ++
 12 files changed, 77 insertions(+), 36 deletions(-)
Signature · 6 lines
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH v2 1/15 drm/nouveau: Don't leak runtime pm ref on driver unload

nouveau_drm_load() calls pm_runtime_put() if nouveau_runtime_pm != 0, but nouveau_drm_unload() calls pm_runtime_get_sync() unconditionally. We therefore leak a runtime pm ref whenever nouveau is loaded with runpm=0 and then unloaded. The GPU will subsequently never runtime suspend even if nouveau is loaded again with runpm=1.

Fix by taking the runtime pm ref under the same condition that it was released on driver load.

Fixes 5addcf0a5f0f ("nouveau: add runtime PM support (v0.9)")
Cc Dave Airlie <[email protected]>
Cc Ben Skeggs <[email protected]>
---
 drivers/gpu/drm/nouveau/nouveau_drm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +4 -1
index 5c4d4df..2b0f441 100644
@@ -490,7 +490,10 @@ nouveau_drm_unload(struct drm_device *dev)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
 
-	pm_runtime_get_sync(dev->dev);
+	if (nouveau_runtime_pm != 0) {
+		pm_runtime_get_sync(dev->dev);
+	}
+
 	nouveau_fbcon_fini(dev);
 	nouveau_accel_fini(drm);
 	nouveau_hwmon_fini(dev);
Signature · 6 lines
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

PATCH v2 3/15 drm/radeon: Don't leak runtime pm ref on driver unload

In reply to Lukas Wunner

radeon_driver_load_kms() calls pm_runtime_put_autosuspend() if radeon_is_px(dev), but radeon_driver_unload_kms() calls pm_runtime_get_sync() unconditionally. We therefore leak a runtime pm ref whenever radeon is unloaded on a non-PX machine or if runpm=0. The GPU will subsequently never runtime suspend after loading radeon again.

Fix by taking the runtime pm ref under the same condition that it was released on driver load.

Fixes 10ebc0bc0934 ("drm/radeon: add runtime PM support (v2)")
Cc Dave Airlie <[email protected]>
Cc Alex Deucher <[email protected]>
---
 drivers/gpu/drm/radeon/radeon_kms.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_kms.c +3 -1
index 414953c..51998a4 100644
@@ -63,7 +63,9 @@ int radeon_driver_unload_kms(struct drm_device *dev)
 	if (rdev->rmmio == NULL)
 		goto done_free;
 
-	pm_runtime_get_sync(dev->dev);
+	if (radeon_is_px(dev)) {
+		pm_runtime_get_sync(dev->dev);
+	}
 
 	radeon_kfd_device_fini(rdev);
 
Signature · 6 lines
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

PATCH v2 4/15 drm/radeon: Don't leak runtime pm ref on driver load

In reply to Lukas Wunner

radeon_device_init() returns an error if either of the two calls to radeon_init() fail. One level up in the call stack, radeon_driver_load_kms() will then skip runtime pm initialization and call radeon_driver_unload_kms(), which acquires a runtime pm ref that is leaked.

Balance by releasing a runtime pm ref in the error path of radeon_device_init().

Fixes 10ebc0bc0934 ("drm/radeon: add runtime PM support (v2)")
Cc Dave Airlie <[email protected]>
Cc Alex Deucher <[email protected]>
---
 drivers/gpu/drm/radeon/radeon_device.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/radeon/radeon_device.c +4 -0
index e721e6b..e0bf778 100644
@@ -30,6 +30,7 @@
 #include <drm/drmP.h>
 #include <drm/drm_crtc_helper.h>
 #include <drm/radeon_drm.h>
+#include <linux/pm_runtime.h>
 #include <linux/vgaarb.h>
 #include <linux/vga_switcheroo.h>
 #include <linux/efi.h>
@@ -1505,6 +1506,9 @@ int radeon_device_init(struct radeon_device *rdev,
 	return 0;
 
 failed:
+	/* balance pm_runtime_get_sync() in radeon_driver_unload_kms() */
+	if (radeon_is_px(ddev))
+		pm_runtime_put_noidle(ddev->dev);
 	if (runtime)
 		vga_switcheroo_fini_domain_pm_ops(rdev->dev);
 	return r;
Signature · 6 lines
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

PATCH v2 5/15 drm/radeon: Forbid runtime pm on driver unload

In reply to Lukas Wunner

The PCI core calls pm_runtime_forbid() on device probe in pci_pm_init(), making this the default state when radeon is loaded. radeon_driver_load_kms() therefore calls pm_runtime_allow(), but there's no pm_runtime_forbid() in radeon_driver_unload_kms() to balance it. Add it so that we leave the device in the same state that we found it.

This isn't a bug, it's just good housekeeping. When radeon is first loaded with runpm=1, then unloaded and loaded again with runpm=0, pm_runtime_forbid() will be called from radeon_pmops_runtime_idle() or radeon_pmops_runtime_suspend(), so the behaviour is correct. If there ever is a third party driver for AMD cards, this commit avoids that it has to clean up behind radeon.

---
 drivers/gpu/drm/radeon/radeon_kms.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/radeon/radeon_kms.c +1 -0
index 51998a4..835563c 100644
@@ -65,6 +65,7 @@ int radeon_driver_unload_kms(struct drm_device *dev)
 
 	if (radeon_is_px(dev)) {
 		pm_runtime_get_sync(dev->dev);
+		pm_runtime_forbid(dev->dev);
 	}
 
 	radeon_kfd_device_fini(rdev);
Signature · 6 lines
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

PATCH v2 6/15 drm/amdgpu: Don't leak runtime pm ref on driver unload

In reply to Lukas Wunner

amdgpu_driver_load_kms() calls pm_runtime_put_autosuspend() if amdgpu_device_is_px(dev), but amdgpu_driver_unload_kms() calls pm_runtime_get_sync() unconditionally. We therefore leak a runtime pm ref whenever amdgpu is unloaded on a non-PX machine or if runpm=0. The GPU will subsequently never runtime suspend after loading amdgpu again.

Fix by taking the runtime pm ref under the same condition that it was released on driver load.

Fixes d38ceaf99ed0 ("drm/amdgpu: add core driver (v4)")
Cc Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3 -1
index 40a2370..9b1f979 100644
@@ -60,7 +60,9 @@ int amdgpu_driver_unload_kms(struct drm_device *dev)
 	if (adev->rmmio == NULL)
 		goto done_free;
 
-	pm_runtime_get_sync(dev->dev);
+	if (amdgpu_device_is_px(dev)) {
+		pm_runtime_get_sync(dev->dev);
+	}
 
 	amdgpu_amdkfd_device_fini(adev);
 
Signature · 6 lines
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw

PATCH v2 7/15 drm/amdgpu: Don't leak runtime pm ref on driver load

In reply to Lukas Wunner

If an error occurs in amdgpu_device_init() after adev->rmmio has been set, its caller amdgpu_driver_load_kms() will skip runtime pm initialization and call amdgpu_driver_unload_kms(), which acquires a runtime pm ref that is leaked.

Balance by releasing a runtime pm ref in the error path of amdgpu_driver_load_kms().

Fixes d38ceaf99ed0 ("drm/amdgpu: add core driver (v4)")
Cc Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -2
index 9b1f979..0db692e 100644
@@ -137,9 +137,12 @@ int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags)
 	}
 
 out:
-	if (r)
+	if (r) {
+		/* balance pm_runtime_get_sync in amdgpu_driver_unload_kms */
+		if (adev->rmmio && amdgpu_device_is_px(dev))
+			pm_runtime_put_noidle(dev->dev);
 		amdgpu_driver_unload_kms(dev);
-
+	}
 
 	return r;
 }
Signature · 6 lines
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw

PATCH v2 8/15 drm/amdgpu: Forbid runtime pm on driver unload

In reply to Lukas Wunner

The PCI core calls pm_runtime_forbid() on device probe in pci_pm_init(), making this the default state when amdgpu is loaded. amdgpu_driver_load_kms() therefore calls pm_runtime_allow(), but there's no pm_runtime_forbid() in amdgpu_driver_unload_kms() to balance it. Add it so that we leave the device in the same state that we found it.

This isn't a bug, it's just good housekeeping. When amdgpu is first loaded with runpm=1, then unloaded and loaded again with runpm=0, pm_runtime_forbid() will be called from amdgpu_pmops_runtime_idle() or amdgpu_pmops_runtime_suspend(), so the behaviour is correct. If there ever is a third party driver for AMD cards, this commit avoids that it has to clean up behind amdgpu.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -0
index 0db692e..38a28d1 100644
@@ -62,6 +62,7 @@ int amdgpu_driver_unload_kms(struct drm_device *dev)
 
 	if (amdgpu_device_is_px(dev)) {
 		pm_runtime_get_sync(dev->dev);
+		pm_runtime_forbid(dev->dev);
 	}
 
 	amdgpu_amdkfd_device_fini(adev);
Signature · 6 lines
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#8 lore raw

PATCH v2 9/15 drm: Add helpers to turn off CRTCs

In reply to Lukas Wunner

Turning off a single CRTC or all active CRTCs of a DRM device is a fairly common pattern. Add helpers to avoid open coding this everywhere.

The name was chosen to be consistent with drm_plane_force_disable().

---
 drivers/gpu/drm/drm_crtc.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 include/drm/drm_crtc.h     |  2 ++
 2 files changed, 47 insertions(+)
drivers/gpu/drm/drm_crtc.c +45 -0
index 37427b2..1edc1f4 100644
@@ -426,6 +426,51 @@ void drm_mode_object_reference(struct drm_mode_object *obj)
 }
 EXPORT_SYMBOL(drm_mode_object_reference);
 
+/**
+ * drm_crtc_force_disable - Forcibly turn off a CRTC
+ * @crtc: CRTC to turn off
+ *
+ * Returns:
+ * Zero on success, error code on failure.
+ */
+int drm_crtc_force_disable(struct drm_crtc *crtc)
+{
+	struct drm_mode_set set = {
+		.crtc = crtc,
+	};
+
+	return drm_mode_set_config_internal(&set);
+}
+EXPORT_SYMBOL(drm_crtc_force_disable);
+
+/**
+ * drm_crtc_force_disable_all - Forcibly turn off all enabled CRTCs
+ * @dev: DRM device whose CRTCs to turn off
+ *
+ * Drivers may want to call this on unload to ensure that all displays are
+ * unlit and the GPU is in a consistent, low power state. Takes modeset locks.
+ *
+ * Returns:
+ * Zero on success, error code on failure.
+ */
+int drm_crtc_force_disable_all(struct drm_device *dev)
+{
+	struct drm_crtc *crtc;
+	int ret = 0;
+
+	drm_modeset_lock_all(dev);
+	drm_for_each_crtc(crtc, dev)
+		if (crtc->enabled) {
+			ret = drm_crtc_force_disable(crtc);
+			if (ret)
+				goto out;
+		}
+out:
+	drm_modeset_unlock_all(dev);
+	return ret;
+}
+EXPORT_SYMBOL(drm_crtc_force_disable_all);
+
 static void drm_framebuffer_free(struct kref *kref)
 {
 	struct drm_framebuffer *fb =
include/drm/drm_crtc.h +2 -0
index d1559cd..c192f2c 100644
@@ -2326,6 +2326,8 @@ extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
 				   int x, int y,
 				   const struct drm_display_mode *mode,
 				   const struct drm_framebuffer *fb);
+extern int drm_crtc_force_disable(struct drm_crtc *crtc);
+extern int drm_crtc_force_disable_all(struct drm_device *dev);
 
 extern void drm_encoder_cleanup(struct drm_encoder *encoder);
 
Signature · 6 lines
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#9 lore raw

PATCH v2 11/15 drm/radeon: Turn off CRTCs on driver unload

In reply to Lukas Wunner

radeon leaks a runtime pm ref if at least one CRTC is enabled on unload. The ref is taken by radeon_crtc_set_config() and held as long as a CRTC is in use. Fix by turning off all CRTCs on unload.

---
 drivers/gpu/drm/radeon/radeon_display.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/radeon/radeon_display.c +1 -0
index 6a41b49..1922c96 100644
@@ -1708,6 +1708,7 @@ void radeon_modeset_fini(struct radeon_device *rdev)
 		radeon_afmt_fini(rdev);
 		drm_kms_helper_poll_fini(rdev->ddev);
 		radeon_hpd_fini(rdev);
+		drm_crtc_force_disable_all(rdev->ddev);
 		drm_mode_config_cleanup(rdev->ddev);
 		rdev->mode_info.mode_config_initialized = false;
 	}
Signature · 6 lines
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#10 lore raw

PATCH v2 12/15 drm/amdgpu: Turn off CRTCs on driver unload

In reply to Lukas Wunner

amdgpu leaks a runtime pm ref if at least one CRTC is enabled on unload. The ref is taken by amdgpu_crtc_set_config() and held as long as a CRTC is in use. Fix by turning off all CRTCs on unload.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
index bb8b149..2ab5e0b 100644
@@ -1624,6 +1624,7 @@ void amdgpu_device_fini(struct amdgpu_device *adev)
 	amdgpu_bo_evict_vram(adev);
 	amdgpu_ib_pool_fini(adev);
 	amdgpu_fence_driver_fini(adev);
+	drm_crtc_force_disable_all(adev->ddev);
 	amdgpu_fbdev_fini(adev);
 	r = amdgpu_fini(adev);
 	kfree(adev->ip_block_status);
Signature · 6 lines
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#11 lore raw

PATCH v2 13/15 drm: Use helper to turn off CRTC

In reply to Lukas Wunner

Use shiny new drm_crtc_force_disable() instead of open coding the same. No functional change intended.

---
 drivers/gpu/drm/drm_crtc.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/gpu/drm/drm_crtc.c +1 -7
index 1edc1f4..3bd32a1 100644
@@ -619,8 +619,6 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb)
 	struct drm_device *dev;
 	struct drm_crtc *crtc;
 	struct drm_plane *plane;
-	struct drm_mode_set set;
-	int ret;
 
 	if (!fb)
 		return;
@@ -650,11 +648,7 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb)
 		drm_for_each_crtc(crtc, dev) {
 			if (crtc->primary->fb == fb) {
 				/* should turn off the crtc */
-				memset(&set, 0, sizeof(struct drm_mode_set));
-				set.crtc = crtc;
-				set.fb = NULL;
-				ret = drm_mode_set_config_internal(&set);
-				if (ret)
+				if (drm_crtc_force_disable(crtc))
 					DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc);
 			}
 		}
Signature · 6 lines
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#12 lore raw

PATCH v2 14/15 drm/i2c/ch7006: Use helper to turn off CRTC

In reply to Lukas Wunner

Use shiny new drm_crtc_force_disable() instead of open coding the same. No functional change intended.

Cc Francisco Jerez <[email protected]>
---
 drivers/gpu/drm/i2c/ch7006_drv.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/gpu/drm/i2c/ch7006_drv.c +2 -7
index 0594c45..e9e8ae2 100644
@@ -361,13 +361,8 @@ static int ch7006_encoder_set_property(struct drm_encoder *encoder,
 
 		/* Disable the crtc to ensure a full modeset is
 		 * performed whenever it's turned on again. */
-		if (crtc) {
-			struct drm_mode_set modeset = {
-				.crtc = crtc,
-			};
-
-			drm_mode_set_config_internal(&modeset);
-		}
+		if (crtc)
+			drm_crtc_force_disable(crtc);
 	}
 
 	return 0;
Signature · 6 lines
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v2 14/15
#13 lore raw

Re: [PATCH v2 14/15] drm/i2c/ch7006: Use helper to turn off CRTC

Quoted 5 lines · Lukas Wunner

Use shiny new drm_crtc_force_disable() instead of open coding the same. No functional change intended.

Cc Francisco Jerez <[email protected]>
Quoted 26 lines
---
 drivers/gpu/drm/i2c/ch7006_drv.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/gpu/drm/i2c/ch7006_drv.c +2 -7
index 0594c45..e9e8ae2 100644
@@ -361,13 +361,8 @@ static int ch7006_encoder_set_property(struct drm_encoder *encoder,
 
 		/* Disable the crtc to ensure a full modeset is
 		 * performed whenever it's turned on again. */
-		if (crtc) {
-			struct drm_mode_set modeset = {
-				.crtc = crtc,
-			};
-
-			drm_mode_set_config_internal(&modeset);
-		}
+		if (crtc)
+			drm_crtc_force_disable(crtc);
 	}
 
 	return 0;
Signature · 1 line
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): cover.1465392124.git.lukas-JFq808J9C/[email protected]

#15 lore raw

PATCH v2 2/15 drm/nouveau: Forbid runtime pm on driver unload

The PCI core calls pm_runtime_forbid() on device probe in pci_pm_init(), making this the default state when nouveau is loaded. nouveau_drm_load() therefore calls pm_runtime_allow(), but there's no pm_runtime_forbid() in nouveau_drm_unload() to balance it. Add it so that we leave the device in the same state that we found it.

This isn't a bug, it's just good housekeeping. When nouveau is first loaded with runpm=1, then unloaded and loaded again with runpm=0, pm_runtime_forbid() will be called from nouveau_pmops_runtime_idle() or nouveau_pmops_runtime_suspend(), so the behaviour is correct. The nvidia blob doesn't use runtime pm, but if it ever does, this commit avoids that it has to clean up behind nouveau.

---
 drivers/gpu/drm/nouveau/nouveau_drm.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -0
index 2b0f441..e1d1d9c 100644
@@ -492,6 +492,7 @@ nouveau_drm_unload(struct drm_device *dev)
 
 	if (nouveau_runtime_pm != 0) {
 		pm_runtime_get_sync(dev->dev);
+		pm_runtime_forbid(dev->dev);
 	}
 
 	nouveau_fbcon_fini(dev);
Signature · 6 lines
2.8.1

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau
#16 lore raw

PATCH v2 10/15 drm/nouveau: Turn off CRTCs on driver unload

In reply to a message not in the archive

nouveau leaks a runtime pm ref if at least one CRTC is enabled on unload. The ref is taken by nouveau_crtc_set_config() and held as long as a CRTC is in use.

nv04_display_destroy() should solve this by turning off all CRTCs, but

(1) nv50_display_destroy() doesn't do the same and

(2) it's broken since commit d6bf2f370703 ("drm/nouveau: run mode_config destructor before destroying internal display state") because the crtc structs are torn down by drm_mode_config_cleanup() before being turned off. Also, there's no locking.

Move the code to turn off all CRTCs from nv04_display_destroy() to nouveau_display_destroy() so that it's called for both nv04 and nv50 and before drm_mode_config_cleanup(). Use drm_crtc_force_disable_all() helper to save on code and have proper locking.

---
 drivers/gpu/drm/nouveau/dispnv04/disp.c   | 10 ----------
 drivers/gpu/drm/nouveau/nouveau_display.c |  1 +
 2 files changed, 1 insertion(+), 10 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/disp.c +0 -10
index aea81a5..34c0f2f6 100644
@@ -125,18 +125,8 @@ nv04_display_destroy(struct drm_device *dev)
 	struct nv04_display *disp = nv04_display(dev);
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nouveau_encoder *encoder;
-	struct drm_crtc *crtc;
 	struct nouveau_crtc *nv_crtc;
 
-	/* Turn every CRTC off. */
-	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
-		struct drm_mode_set modeset = {
-			.crtc = crtc,
-		};
-
-		drm_mode_set_config_internal(&modeset);
-	}
-
 	/* Restore state */
 	list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.base.head)
 		encoder->enc_restore(&encoder->base.base);
drivers/gpu/drm/nouveau/nouveau_display.c +1 -0
index 7c77f96..cbdb3d4 100644
@@ -554,6 +554,7 @@ nouveau_display_destroy(struct drm_device *dev)
 	nouveau_display_vblank_fini(dev);
 
 	drm_kms_helper_poll_fini(dev);
+	drm_crtc_force_disable_all(dev);
 	drm_mode_config_cleanup(dev);
 
 	if (disp->dtor)
Signature · 6 lines
2.8.1

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau
#17 lore raw

PATCH v2 15/15 drm/nouveau/dispnv04: Use helper to turn off CRTC

In reply to a message not in the archive

Use shiny new drm_crtc_force_disable() instead of open coding the same. No functional change intended.

---
 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/tvnv17.c +2 -7
index a665b78..434d1e2 100644
@@ -749,13 +749,8 @@ static int nv17_tv_set_property(struct drm_encoder *encoder,
 
 		/* Disable the crtc to ensure a full modeset is
 		 * performed whenever it's turned on again. */
-		if (crtc) {
-			struct drm_mode_set modeset = {
-				.crtc = crtc,
-			};
-
-			drm_mode_set_config_internal(&modeset);
-		}
+		if (crtc)
+			drm_crtc_force_disable(crtc);
 	}
 
 	return 0;
Signature · 6 lines
2.8.1

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau
#18 lore raw
In reply to a message not in the archive
Quoted 11 lines · Lukas Wunner

Second iteration of my endeavour to rid nouveau, radeon and amdgpu of runtime pm ref leaks.

Patches 1 to 8 are identical to v1.

Patch 9 of v1 modified the DRM core to turn off all CRTCs on driver unload. Based on feedback by Daniel Vetter, I've replaced this with a helper to turn off all CRTCs, which is called by nouveau, radeon and amdgpu on unload. In other words, this is now opt-in. So patch 9 of v1 is replaced with new patches 9 to 12.

Quoted 3 lines

A by-product of patch 9 is a helper which turns off a *single* CRTC. This is open coded in three other places in the DRM tree and patches 13 to 15 refactor those to use the new helper.

Yeah I think this makes much more sense. Please poke amd/nouveau folks for reviews/acks, then I can merge.
-Daniel

Quoted 45 lines

To ease reviewing, I've pushed this series to GitHub:
https://github.com/l1k/linux/commits/drm_runpm_fixes_v2

The discussion on v1 is archived here:
https://lists.freedesktop.org/archives/dri-devel/2016-May/thread.html#108278

Thanks,

Lukas

Lukas Wunner (15):
drm/nouveau: Don't leak runtime pm ref on driver unload drm/nouveau: Forbid runtime pm on driver unload drm/radeon: Don't leak runtime pm ref on driver unload drm/radeon: Don't leak runtime pm ref on driver load drm/radeon: Forbid runtime pm on driver unload drm/amdgpu: Don't leak runtime pm ref on driver unload drm/amdgpu: Don't leak runtime pm ref on driver load drm/amdgpu: Forbid runtime pm on driver unload
drm: Add helpers to turn off CRTCs drm/nouveau: Turn off CRTCs on driver unload drm/radeon: Turn off CRTCs on driver unload drm/amdgpu: Turn off CRTCs on driver unload
drm: Use helper to turn off CRTC drm/i2c/ch7006: Use helper to turn off CRTC drm/nouveau/dispnv04: Use helper to turn off CRTC

 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    | 12 +++++--
 drivers/gpu/drm/drm_crtc.c                 | 53 ++++++++++++++++++++++++++----
 drivers/gpu/drm/i2c/ch7006_drv.c           |  9 ++---
 drivers/gpu/drm/nouveau/dispnv04/disp.c    | 10 ------
 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c  |  9 ++---
 drivers/gpu/drm/nouveau/nouveau_display.c  |  1 +
 drivers/gpu/drm/nouveau/nouveau_drm.c      |  6 +++-
 drivers/gpu/drm/radeon/radeon_device.c     |  4 +++
 drivers/gpu/drm/radeon/radeon_display.c    |  1 +
 drivers/gpu/drm/radeon/radeon_kms.c        |  5 ++-
 include/drm/drm_crtc.h                     |  2 ++
 12 files changed, 77 insertions(+), 36 deletions(-)
Signature · 1 line
2.8.1
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): 20160609065032.GI3363-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org

#20 lore raw
Quoted 12 lines · Daniel Vetter
Quoted 11 lines · Lukas Wunner

Second iteration of my endeavour to rid nouveau, radeon and amdgpu of runtime pm ref leaks.

Patches 1 to 8 are identical to v1.

Patch 9 of v1 modified the DRM core to turn off all CRTCs on driver unload. Based on feedback by Daniel Vetter, I've replaced this with a helper to turn off all CRTCs, which is called by nouveau, radeon and amdgpu on unload. In other words, this is now opt-in. So patch 9 of v1 is replaced with new patches 9 to 12.

Quoted 6 lines
Quoted 3 lines

A by-product of patch 9 is a helper which turns off a *single* CRTC. This is open coded in three other places in the DRM tree and patches 13 to 15 refactor those to use the new helper.

Yeah I think this makes much more sense. Please poke amd/nouveau folks for reviews/acks, then I can merge.

Looks fine to me.

Ben.

Quoted 48 lines

-Daniel

Quoted 45 lines

To ease reviewing, I've pushed this series to GitHub:
https://github.com/l1k/linux/commits/drm_runpm_fixes_v2

The discussion on v1 is archived here:
https://lists.freedesktop.org/archives/dri-devel/2016-May/thread.html#108278

Thanks,

Lukas

Lukas Wunner (15):
drm/nouveau: Don't leak runtime pm ref on driver unload drm/nouveau: Forbid runtime pm on driver unload drm/radeon: Don't leak runtime pm ref on driver unload drm/radeon: Don't leak runtime pm ref on driver load drm/radeon: Forbid runtime pm on driver unload drm/amdgpu: Don't leak runtime pm ref on driver unload drm/amdgpu: Don't leak runtime pm ref on driver load drm/amdgpu: Forbid runtime pm on driver unload
drm: Add helpers to turn off CRTCs drm/nouveau: Turn off CRTCs on driver unload drm/radeon: Turn off CRTCs on driver unload drm/amdgpu: Turn off CRTCs on driver unload
drm: Use helper to turn off CRTC drm/i2c/ch7006: Use helper to turn off CRTC drm/nouveau/dispnv04: Use helper to turn off CRTC

 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    | 12 +++++--
 drivers/gpu/drm/drm_crtc.c                 | 53 ++++++++++++++++++++++++++----
 drivers/gpu/drm/i2c/ch7006_drv.c           |  9 ++---
 drivers/gpu/drm/nouveau/dispnv04/disp.c    | 10 ------
 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c  |  9 ++---
 drivers/gpu/drm/nouveau/nouveau_display.c  |  1 +
 drivers/gpu/drm/nouveau/nouveau_drm.c      |  6 +++-
 drivers/gpu/drm/radeon/radeon_device.c     |  4 +++
 drivers/gpu/drm/radeon/radeon_display.c    |  1 +
 drivers/gpu/drm/radeon/radeon_kms.c        |  5 ++-
 include/drm/drm_crtc.h                     |  2 ++
 12 files changed, 77 insertions(+), 36 deletions(-)
Signature · 1 line
2.8.1

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

Acked-by
#21 lore raw
In reply to a message not in the archive
Quoted 12 lines · Daniel Vetter
Quoted 11 lines · Lukas Wunner

Second iteration of my endeavour to rid nouveau, radeon and amdgpu of runtime pm ref leaks.

Patches 1 to 8 are identical to v1.

Patch 9 of v1 modified the DRM core to turn off all CRTCs on driver unload. Based on feedback by Daniel Vetter, I've replaced this with a helper to turn off all CRTCs, which is called by nouveau, radeon and amdgpu on unload. In other words, this is now opt-in. So patch 9 of v1 is replaced with new patches 9 to 12.

Quoted 6 lines
Quoted 3 lines

A by-product of patch 9 is a helper which turns off a *single* CRTC. This is open coded in three other places in the DRM tree and patches 13 to 15 refactor those to use the new helper.

Yeah I think this makes much more sense. Please poke amd/nouveau folks for reviews/acks, then I can merge.

The amdgpu, radeon, and drm patches are:

Quoted 48 lines

-Daniel

Quoted 42 lines

To ease reviewing, I've pushed this series to GitHub:
https://github.com/l1k/linux/commits/drm_runpm_fixes_v2

The discussion on v1 is archived here:
https://lists.freedesktop.org/archives/dri-devel/2016-May/thread.html#108278

Thanks,

Lukas

Lukas Wunner (15):
drm/nouveau: Don't leak runtime pm ref on driver unload drm/nouveau: Forbid runtime pm on driver unload drm/radeon: Don't leak runtime pm ref on driver unload drm/radeon: Don't leak runtime pm ref on driver load drm/radeon: Forbid runtime pm on driver unload drm/amdgpu: Don't leak runtime pm ref on driver unload drm/amdgpu: Don't leak runtime pm ref on driver load drm/amdgpu: Forbid runtime pm on driver unload
drm: Add helpers to turn off CRTCs drm/nouveau: Turn off CRTCs on driver unload drm/radeon: Turn off CRTCs on driver unload drm/amdgpu: Turn off CRTCs on driver unload
drm: Use helper to turn off CRTC drm/i2c/ch7006: Use helper to turn off CRTC drm/nouveau/dispnv04: Use helper to turn off CRTC

 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    | 12 +++++--
 drivers/gpu/drm/drm_crtc.c                 | 53 ++++++++++++++++++++++++++----
 drivers/gpu/drm/i2c/ch7006_drv.c           |  9 ++---
 drivers/gpu/drm/nouveau/dispnv04/disp.c    | 10 ------
 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c  |  9 ++---
 drivers/gpu/drm/nouveau/nouveau_display.c  |  1 +
 drivers/gpu/drm/nouveau/nouveau_drm.c      |  6 +++-
 drivers/gpu/drm/radeon/radeon_device.c     |  4 +++
 drivers/gpu/drm/radeon/radeon_display.c    |  1 +
 drivers/gpu/drm/radeon/radeon_kms.c        |  5 ++-
 include/drm/drm_crtc.h                     |  2 ++
 12 files changed, 77 insertions(+), 36 deletions(-)
Quoted 3 lines

--
2.8.1

Quoted 8 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

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): CADnq5_NENZukwJg-CACQ-djWsP4e299gnr4aWrEJkdcVMeaZWA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

Acked-by Ben Skeggs Acked-by Alex Deucher Reviewed-by Francisco Jerez
#23 lore raw
Quoted 17 lines · Alex Deucher
Quoted 16 lines · Daniel Vetter
Quoted 14 lines · Lukas Wunner

Second iteration of my endeavour to rid nouveau, radeon and amdgpu of runtime pm ref leaks.

Patches 1 to 8 are identical to v1.

Patch 9 of v1 modified the DRM core to turn off all CRTCs on driver unload. Based on feedback by Daniel Vetter, I've replaced this with a helper to turn off all CRTCs, which is called by nouveau, radeon and amdgpu on unload. In other words, this is now opt-in. So patch 9 of v1 is replaced with new patches 9 to 12.

A by-product of patch 9 is a helper which turns off a *single* CRTC. This is open coded in three other places in the DRM tree and patches 13 to 15 refactor those to use the new helper.

Quoted 5 lines
Quoted 2 lines

Yeah I think this makes much more sense. Please poke amd/nouveau folks for reviews/acks, then I can merge.

The amdgpu, radeon, and drm patches are:

Great, thank you. That means all patches are either acked or reviewed:

* Patches 1, 2, 10 and 15 are

Message-ID: <[email protected]>

* Patches 3 - 9 and 11 - 13 are

Message-ID: <CADnq5_NENZukwJg-CACQ-djWsP4e299gnr4aWrEJkdcVMeaZWA@mail.gmail.com>

* Patch 14 is

Message-ID: <[email protected]>

Dave, Daniel, could one of you pick this up?

I've pushed another branch to GitHub which is amended with all the Acked-by and Reviewed-by tags. It's also rebased on latest drm-next. Otherwise this is identical to what I've posted. So in case you don't want to apply all tags manually, you can cherry-pick from or merge this branch (barring any objections of course):
https://github.com/l1k/linux/commits/drm_runpm_fixes_v2_acked

Thanks everyone!

Lukas
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): 20160615113735.GA562-JFq808J9C/[email protected]

#25 lore raw
Quoted 44 lines · Lukas Wunner
Quoted 17 lines · Alex Deucher
Quoted 16 lines · Daniel Vetter
Quoted 14 lines · Lukas Wunner

Second iteration of my endeavour to rid nouveau, radeon and amdgpu of runtime pm ref leaks.

Patches 1 to 8 are identical to v1.

Patch 9 of v1 modified the DRM core to turn off all CRTCs on driver unload. Based on feedback by Daniel Vetter, I've replaced this with a helper to turn off all CRTCs, which is called by nouveau, radeon and amdgpu on unload. In other words, this is now opt-in. So patch 9 of v1 is replaced with new patches 9 to 12.

A by-product of patch 9 is a helper which turns off a *single* CRTC. This is open coded in three other places in the DRM tree and patches 13 to 15 refactor those to use the new helper.

Quoted 5 lines
Quoted 2 lines

Yeah I think this makes much more sense. Please poke amd/nouveau folks for reviews/acks, then I can merge.

The amdgpu, radeon, and drm patches are:

Great, thank you. That means all patches are either acked or reviewed:

* Patches 1, 2, 10 and 15 are

Message-ID: <[email protected]>

* Patches 3 - 9 and 11 - 13 are

Message-ID: <CADnq5_NENZukwJg-CACQ-djWsP4e299gnr4aWrEJkdcVMeaZWA@mail.gmail.com>

* Patch 14 is

Message-ID: <[email protected]>

Dave, Daniel, could one of you pick this up?

Quoted 8 lines

I've pushed another branch to GitHub which is amended with all the Acked-by and Reviewed-by tags. It's also rebased on latest drm-next. Otherwise this is identical to what I've posted. So in case you don't want to apply all tags manually, you can cherry-pick from or merge this branch (barring any objections of course):
https://github.com/l1k/linux/commits/drm_runpm_fixes_v2_acked

Thanks everyone!

Yeah will pick up later this week, right now I have a big drm-misc pull that's pending. Would like to get that landed first. Please ping me if your patches haven't landed in drm-misc by next week.

Cheers, Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): 20160615151154.GF1338-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org

#27 lore raw
Quoted 52 lines · Daniel Vetter
Quoted 51 lines · Lukas Wunner
Quoted 17 lines · Alex Deucher
Quoted 16 lines · Daniel Vetter
Quoted 14 lines · Lukas Wunner

Second iteration of my endeavour to rid nouveau, radeon and amdgpu of runtime pm ref leaks.

Patches 1 to 8 are identical to v1.

Patch 9 of v1 modified the DRM core to turn off all CRTCs on driver unload. Based on feedback by Daniel Vetter, I've replaced this with a helper to turn off all CRTCs, which is called by nouveau, radeon and amdgpu on unload. In other words, this is now opt-in. So patch 9 of v1 is replaced with new patches 9 to 12.

A by-product of patch 9 is a helper which turns off a *single* CRTC. This is open coded in three other places in the DRM tree and patches 13 to 15 refactor those to use the new helper.

Quoted 5 lines
Quoted 2 lines

Yeah I think this makes much more sense. Please poke amd/nouveau folks for reviews/acks, then I can merge.

The amdgpu, radeon, and drm patches are:

Great, thank you. That means all patches are either acked or reviewed:

* Patches 1, 2, 10 and 15 are

Message-ID: <[email protected]>

* Patches 3 - 9 and 11 - 13 are

Message-ID: <CADnq5_NENZukwJg-CACQ-djWsP4e299gnr4aWrEJkdcVMeaZWA@mail.gmail.com>

* Patch 14 is

Message-ID: <[email protected]>

Dave, Daniel, could one of you pick this up?

I've pushed another branch to GitHub which is amended with all the Acked-by and Reviewed-by tags. It's also rebased on latest drm-next. Otherwise this is identical to what I've posted. So in case you don't want to apply all tags manually, you can cherry-pick from or merge this branch (barring any objections of course):
https://github.com/l1k/linux/commits/drm_runpm_fixes_v2_acked

Quoted 5 lines
Quoted 1 line

Thanks everyone!

Yeah will pick up later this week, right now I have a big drm-misc pull that's pending. Would like to get that landed first. Please ping me if your patches haven't landed in drm-misc by next week.

If you can be bothered to update your drm-misc pull: Ping! (Otherwise I think Dave or Thierry/Sumit could pick it up instead.)

Thanks and have a pleasant vacation,

Lukas
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): 20160622124447.GA3267-JFq808J9C/[email protected]

#29 lore raw
Quoted 6 lines · Lukas Wunner
Quoted 3 lines

Yeah will pick up later this week, right now I have a big drm-misc pull that's pending. Would like to get that landed first. Please ping me if your patches haven't landed in drm-misc by next week.

If you can be bothered to update your drm-misc pull: Ping! (Otherwise I think Dave or Thierry/Sumit could pick it up instead.)

So much for my 5 second attention span :( I'll merge them right now, but I think it's better to let them soak a bit more. Maybe Thierry can send a pull request next week (if more patches show up). Note I'll wait with pushing out until Dave merged the previous pull, to avoid a mess in case another fixup is needed.

Thanks for reminding me.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau