All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/i915: Mark runtime_pm as a special class of lock
@ 2018-07-20 11:10 Chris Wilson
  2018-07-20 11:11 ` Chris Wilson
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Chris Wilson @ 2018-07-20 11:10 UTC (permalink / raw)
  To: intel-gfx; +Cc: Daniel Vetter

Runtime power management acts as a type of "wakelock" that code must
hold in order to access the device. Such a lock has all the ordering
issues of a regular lock, and so it would be convenient to use lockdep
to catch violations and cyclic deadlocks.

In the long run, it will be interesting to use cross-release tracking so
that we could mark the runtime wakelock as held for as long as the
device was suspended, so that we catch whenever we might be trying to
access the device having forgotten about acquiring the wakelock.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_drv.c         | 16 ++++++++++++++++
 drivers/gpu/drm/i915/i915_drv.h         |  1 +
 drivers/gpu/drm/i915/intel_drv.h        |  1 +
 drivers/gpu/drm/i915/intel_runtime_pm.c | 20 ++++++++++++++++++++
 4 files changed, 38 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index ef482f817ad6..c70f1f950c9f 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -921,6 +921,7 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv,
 	/* This must be called before any calls to HAS_PCH_* */
 	intel_detect_pch(dev_priv);
 
+	intel_runtime_pm_init_early(dev_priv);
 	intel_wopcm_init_early(&dev_priv->wopcm);
 	intel_uc_init_early(dev_priv);
 	intel_pm_setup(dev_priv);
@@ -2403,6 +2404,7 @@ static int intel_runtime_suspend(struct device *kdev)
 	DRM_DEBUG_KMS("Suspending device\n");
 
 	disable_rpm_wakeref_asserts(dev_priv);
+	lock_map_acquire(&dev_priv->runtime_pm.lock);
 
 	/*
 	 * We are safe here against re-faults, since the fault handler takes
@@ -2437,11 +2439,23 @@ static int intel_runtime_suspend(struct device *kdev)
 		i915_gem_init_swizzling(dev_priv);
 		i915_gem_restore_fences(dev_priv);
 
+		lock_map_release(&dev_priv->runtime_pm.lock);
 		enable_rpm_wakeref_asserts(dev_priv);
 
 		return ret;
 	}
 
+	/*
+	 * XXX We want to keep the runtime_pm.lock held across suspend.
+	 *
+	 * We want to treat the whole runtime sleep period as a locked state
+	 * and catch any lock ordering problems that may arise from trying
+	 * to access the device without first acquiring the runtime reference.
+	 * However, this will need lockdep cross-release support as the lock
+	 * will no longer be tied to a process. Once we have that working, we
+	 * should endeavour on moving this lockdep_map to the PM core.
+	 */
+	lock_map_release(&dev_priv->runtime_pm.lock);
 	enable_rpm_wakeref_asserts(dev_priv);
 	WARN_ON_ONCE(atomic_read(&dev_priv->runtime_pm.wakeref_count));
 
@@ -2496,6 +2510,7 @@ static int intel_runtime_resume(struct device *kdev)
 
 	WARN_ON_ONCE(atomic_read(&dev_priv->runtime_pm.wakeref_count));
 	disable_rpm_wakeref_asserts(dev_priv);
+	lock_map_acquire(&dev_priv->runtime_pm.lock);
 
 	intel_opregion_notify_adapter(dev_priv, PCI_D0);
 	dev_priv->runtime_pm.suspended = false;
@@ -2537,6 +2552,7 @@ static int intel_runtime_resume(struct device *kdev)
 
 	intel_enable_ipc(dev_priv);
 
+	lock_map_release(&dev_priv->runtime_pm.lock);
 	enable_rpm_wakeref_asserts(dev_priv);
 
 	if (ret)
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 493e31fba3f5..dda4078b981a 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1168,6 +1168,7 @@ struct skl_wm_params {
  * For more, read the Documentation/power/runtime_pm.txt.
  */
 struct i915_runtime_pm {
+	struct lockdep_map lock;
 	atomic_t wakeref_count;
 	bool suspended;
 	bool irqs_enabled;
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index c6d90058d0a9..42b8bdb81d80 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -1944,6 +1944,7 @@ void intel_power_domains_suspend(struct drm_i915_private *dev_priv);
 void intel_power_domains_verify_state(struct drm_i915_private *dev_priv);
 void bxt_display_core_init(struct drm_i915_private *dev_priv, bool resume);
 void bxt_display_core_uninit(struct drm_i915_private *dev_priv);
+void intel_runtime_pm_init_early(struct drm_i915_private *dev_priv);
 void intel_runtime_pm_enable(struct drm_i915_private *dev_priv);
 const char *
 intel_display_power_domain_str(enum intel_display_power_domain domain);
diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c b/drivers/gpu/drm/i915/intel_runtime_pm.c
index 30f6c9d23a9a..e4220a147cde 100644
--- a/drivers/gpu/drm/i915/intel_runtime_pm.c
+++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
@@ -3698,6 +3698,8 @@ void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
 	ret = pm_runtime_get_sync(kdev);
 	WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
 
+	lock_map_acquire_read(&dev_priv->runtime_pm.lock);
+
 	atomic_inc(&dev_priv->runtime_pm.wakeref_count);
 	assert_rpm_wakelock_held(dev_priv);
 }
@@ -3731,6 +3733,8 @@ bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
 			return false;
 	}
 
+	lock_map_acquire_read(&dev_priv->runtime_pm.lock);
+
 	atomic_inc(&dev_priv->runtime_pm.wakeref_count);
 	assert_rpm_wakelock_held(dev_priv);
 
@@ -3759,9 +3763,15 @@ void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
 	struct pci_dev *pdev = dev_priv->drm.pdev;
 	struct device *kdev = &pdev->dev;
 
+#if IS_ENABLED(CONFIG_LOCKDEP)
+	WARN_ON_ONCE(!lock_is_held_type(&dev_priv->runtime_pm.lock, 1));
+#endif
+
 	assert_rpm_wakelock_held(dev_priv);
 	pm_runtime_get_noresume(kdev);
 
+	lock_map_acquire_read(&dev_priv->runtime_pm.lock);
+
 	atomic_inc(&dev_priv->runtime_pm.wakeref_count);
 }
 
@@ -3781,6 +3791,8 @@ void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
 	assert_rpm_wakelock_held(dev_priv);
 	atomic_dec(&dev_priv->runtime_pm.wakeref_count);
 
+	lock_map_release(&dev_priv->runtime_pm.lock);
+
 	pm_runtime_mark_last_busy(kdev);
 	pm_runtime_put_autosuspend(kdev);
 }
@@ -3826,3 +3838,11 @@ void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
 	 */
 	pm_runtime_put_autosuspend(kdev);
 }
+
+void intel_runtime_pm_init_early(struct drm_i915_private *dev_priv)
+{
+	static struct lock_class_key lock_key;
+
+	lockdep_init_map(&dev_priv->runtime_pm.lock,
+			 "i915->runtime_pm", &lock_key, 0);
+}
-- 
2.18.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/i915: Mark runtime_pm as a special class of lock
  2018-07-20 11:10 [PATCH] drm/i915: Mark runtime_pm as a special class of lock Chris Wilson
@ 2018-07-20 11:11 ` Chris Wilson
  2018-07-20 11:41 ` ✗ Fi.CI.SPARSE: warning for " Patchwork
  2018-07-20 12:09 ` ✗ Fi.CI.BAT: failure " Patchwork
  2 siblings, 0 replies; 4+ messages in thread
From: Chris Wilson @ 2018-07-20 11:11 UTC (permalink / raw)
  To: intel-gfx; +Cc: Daniel Vetter

Quoting Chris Wilson (2018-07-20 12:10:16)
> Runtime power management acts as a type of "wakelock" that code must
> hold in order to access the device. Such a lock has all the ordering
> issues of a regular lock, and so it would be convenient to use lockdep
> to catch violations and cyclic deadlocks.
> 
> In the long run, it will be interesting to use cross-release tracking so
> that we could mark the runtime wakelock as held for as long as the
> device was suspended, so that we catch whenever we might be trying to
> access the device having forgotten about acquiring the wakelock.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>

Wrong branch, ignore this for the moment. We'll be back with this later
after cross-release.
-Chris
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* ✗ Fi.CI.SPARSE: warning for drm/i915: Mark runtime_pm as a special class of lock
  2018-07-20 11:10 [PATCH] drm/i915: Mark runtime_pm as a special class of lock Chris Wilson
  2018-07-20 11:11 ` Chris Wilson
@ 2018-07-20 11:41 ` Patchwork
  2018-07-20 12:09 ` ✗ Fi.CI.BAT: failure " Patchwork
  2 siblings, 0 replies; 4+ messages in thread
From: Patchwork @ 2018-07-20 11:41 UTC (permalink / raw)
  To: Chris Wilson; +Cc: intel-gfx

== Series Details ==

Series: drm/i915: Mark runtime_pm as a special class of lock
URL   : https://patchwork.freedesktop.org/series/46938/
State : warning

== Summary ==

$ dim sparse origin/drm-tip
Commit: drm/i915: Mark runtime_pm as a special class of lock
-drivers/gpu/drm/i915/selftests/../i915_drv.h:3645:16: warning: expression using sizeof(void)
+drivers/gpu/drm/i915/selftests/../i915_drv.h:3646:16: warning: expression using sizeof(void)

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* ✗ Fi.CI.BAT: failure for drm/i915: Mark runtime_pm as a special class of lock
  2018-07-20 11:10 [PATCH] drm/i915: Mark runtime_pm as a special class of lock Chris Wilson
  2018-07-20 11:11 ` Chris Wilson
  2018-07-20 11:41 ` ✗ Fi.CI.SPARSE: warning for " Patchwork
@ 2018-07-20 12:09 ` Patchwork
  2 siblings, 0 replies; 4+ messages in thread
From: Patchwork @ 2018-07-20 12:09 UTC (permalink / raw)
  To: Chris Wilson; +Cc: intel-gfx

== Series Details ==

Series: drm/i915: Mark runtime_pm as a special class of lock
URL   : https://patchwork.freedesktop.org/series/46938/
State : failure

== Summary ==

= CI Bug Log - changes from CI_DRM_4518 -> Patchwork_9731 =

== Summary - FAILURE ==

  Serious unknown changes coming with Patchwork_9731 absolutely need to be
  verified manually.
  
  If you think the reported changes have nothing to do with the changes
  introduced in Patchwork_9731, please notify your bug team to allow them
  to document this new failure mode, which will reduce false positives in CI.

  External URL: https://patchwork.freedesktop.org/api/1.0/series/46938/revisions/1/mbox/

== Possible new issues ==

  Here are the unknown changes that may have been introduced in Patchwork_9731:

  === IGT changes ===

    ==== Possible regressions ====

    igt@drv_module_reload@basic-no-display:
      {fi-skl-iommu}:     PASS -> DMESG-WARN +3
      fi-elk-e7500:       PASS -> DMESG-WARN +16

    igt@drv_module_reload@basic-reload:
      fi-skl-guc:         PASS -> DMESG-WARN +2
      fi-kbl-x1275:       PASS -> DMESG-WARN +16

    igt@drv_module_reload@basic-reload-inject:
      fi-skl-6260u:       PASS -> DMESG-WARN +3
      fi-kbl-7560u:       PASS -> DMESG-WARN +16
      fi-skl-6770hq:      PASS -> DMESG-WARN +3

    igt@drv_selftest@live_contexts:
      fi-cfl-s3:          PASS -> DMESG-WARN +16

    igt@drv_selftest@live_dmabuf:
      fi-byt-n2820:       PASS -> DMESG-WARN +16
      fi-hsw-4770r:       PASS -> DMESG-WARN +16

    igt@drv_selftest@live_gtt:
      {fi-kbl-8809g}:     PASS -> DMESG-WARN +16
      fi-kbl-guc:         PASS -> DMESG-WARN +14
      fi-gdg-551:         PASS -> DMESG-WARN +16
      fi-kbl-7500u:       PASS -> DMESG-WARN +16

    igt@drv_selftest@live_guc:
      fi-hsw-peppy:       PASS -> DMESG-WARN +16

    igt@drv_selftest@live_hangcheck:
      fi-snb-2520m:       PASS -> DMESG-WARN +16
      fi-skl-6700hq:      PASS -> DMESG-WARN +3
      fi-skl-6700k2:      PASS -> DMESG-WARN +3
      fi-cfl-guc:         PASS -> DMESG-FAIL
      fi-skl-6600u:       PASS -> DMESG-WARN +3

    igt@drv_selftest@live_hugepages:
      fi-glk-dsi:         PASS -> DMESG-WARN +16
      {fi-cfl-8109u}:     PASS -> DMESG-WARN +15

    igt@drv_selftest@live_objects:
      fi-bwr-2160:        PASS -> DMESG-WARN +16
      fi-bdw-5557u:       PASS -> DMESG-WARN +16
      fi-snb-2600:        PASS -> DMESG-WARN +16
      fi-hsw-4770:        PASS -> DMESG-WARN +16
      fi-bxt-dsi:         PASS -> DMESG-WARN +16

    igt@drv_selftest@live_requests:
      fi-whl-u:           PASS -> DMESG-WARN +16
      fi-skl-gvtdvm:      PASS -> DMESG-WARN +16
      fi-ivb-3520m:       PASS -> DMESG-WARN +16
      fi-bxt-j4205:       PASS -> DMESG-WARN +16
      fi-cfl-guc:         PASS -> DMESG-WARN +14

    igt@drv_selftest@live_sanitycheck:
      fi-bdw-gvtdvm:      PASS -> DMESG-WARN +16
      fi-ilk-650:         PASS -> DMESG-WARN +16
      fi-bsw-n3050:       PASS -> DMESG-WARN +15
      fi-kbl-7567u:       PASS -> DMESG-WARN +16
      fi-glk-j4005:       PASS -> DMESG-WARN +16
      fi-ivb-3770:        PASS -> DMESG-WARN +16

    igt@drv_selftest@live_uncore:
      fi-pnv-d510:        PASS -> DMESG-WARN +16

    igt@drv_selftest@live_workarounds:
      fi-cfl-8700k:       PASS -> DMESG-WARN +16
      fi-kbl-r:           PASS -> DMESG-WARN +16
      fi-byt-j1900:       PASS -> DMESG-WARN +16
      fi-blb-e6850:       PASS -> DMESG-WARN +16

    
    ==== Warnings ====

    igt@drv_selftest@live_workarounds:
      {fi-cfl-8109u}:     DMESG-FAIL (fdo#107292) -> DMESG-WARN

    
== Known issues ==

  Here are the changes found in Patchwork_9731 that come from known issues:

  === IGT changes ===

    ==== Issues hit ====

    igt@drv_selftest@live_hangcheck:
      fi-kbl-guc:         PASS -> DMESG-FAIL (fdo#106947)

    igt@drv_selftest@live_objects:
      fi-skl-6770hq:      PASS -> DMESG-WARN (fdo#107175) +12
      fi-skl-6700k2:      PASS -> DMESG-WARN (fdo#107175) +12
      fi-skl-6260u:       PASS -> DMESG-WARN (fdo#107175) +12

    igt@drv_selftest@live_requests:
      fi-skl-6700hq:      PASS -> DMESG-WARN (fdo#107175) +12
      fi-skl-guc:         PASS -> DMESG-WARN (fdo#107175) +11

    igt@drv_selftest@live_sanitycheck:
      {fi-skl-iommu}:     PASS -> DMESG-WARN (fdo#107175) +12

    igt@drv_selftest@live_uncore:
      fi-skl-6600u:       PASS -> DMESG-WARN (fdo#107175) +12

    igt@drv_selftest@live_workarounds:
      fi-bsw-n3050:       PASS -> DMESG-FAIL (fdo#107292)

    
    ==== Possible fixes ====

    igt@drv_selftest@live_hangcheck:
      fi-skl-guc:         DMESG-FAIL (fdo#107174) -> PASS

    
  {name}: This element is suppressed. This means it is ignored when computing
          the status of the difference (SUCCESS, WARNING, or FAILURE).

  fdo#106947 https://bugs.freedesktop.org/show_bug.cgi?id=106947
  fdo#107174 https://bugs.freedesktop.org/show_bug.cgi?id=107174
  fdo#107175 https://bugs.freedesktop.org/show_bug.cgi?id=107175
  fdo#107292 https://bugs.freedesktop.org/show_bug.cgi?id=107292


== Participating hosts (47 -> 42) ==

  Missing    (5): fi-ctg-p8600 fi-ilk-m540 fi-byt-squawks fi-bsw-cyan fi-hsw-4200u 


== Build changes ==

    * Linux: CI_DRM_4518 -> Patchwork_9731

  CI_DRM_4518: 85bdcb875339b30f7beecbc7cba6bc2041cdd28b @ git://anongit.freedesktop.org/gfx-ci/linux
  IGT_4569: bf70728a951cd3c08dd9bbc9310e16aaa252164f @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
  Patchwork_9731: 4f29c85b4ee47576c4c42c9240a69b3b8fda1529 @ git://anongit.freedesktop.org/gfx-ci/linux


== Linux commits ==

4f29c85b4ee4 drm/i915: Mark runtime_pm as a special class of lock

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_9731/issues.html
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-07-20 12:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-20 11:10 [PATCH] drm/i915: Mark runtime_pm as a special class of lock Chris Wilson
2018-07-20 11:11 ` Chris Wilson
2018-07-20 11:41 ` ✗ Fi.CI.SPARSE: warning for " Patchwork
2018-07-20 12:09 ` ✗ Fi.CI.BAT: failure " Patchwork

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.