Blob Blame History Raw
From 6976e74b5fa12430b36c3b0f8afd7e8e695be0ab Mon Sep 17 00:00:00 2001
From: Michal Wajdeczko <michal.wajdeczko@intel.com>
Date: Mon, 10 Apr 2017 12:17:47 +0000
Subject: [PATCH] drm/i915: Don't allow overuse of __intel_wait_for_register_fw()
Git-commit: 6976e74b5fa12430b36c3b0f8afd7e8e695be0ab
Patch-mainline: v4.13-rc1
References: FATE#322643 bsc#1055900

This function should not be called with long timeouts in atomic context.
Annotate it as might_sleep if timeout is longer than 10us.

V2: fix comment (Michal)

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Suggested-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Link: http://patchwork.freedesktop.org/patch/msgid/20170410121747.209200-1-michal.wajdeczko@intel.com
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Acked-by: Takashi Iwai <tiwai@suse.de>

---
 drivers/gpu/drm/i915/intel_uncore.c |    5 +++++
 1 file changed, 5 insertions(+)

--- a/drivers/gpu/drm/i915/intel_uncore.c
+++ b/drivers/gpu/drm/i915/intel_uncore.c
@@ -1600,6 +1600,8 @@ static int gen6_reset_engines(struct drm
  *     (I915_READ_FW(reg) & mask) == value
  *
  * Otherwise, the wait will timeout after @slow_timeout_ms milliseconds.
+ * For atomic context @slow_timeout_ms must be zero and @fast_timeout_us
+ * must be not larger than 10 microseconds.
  *
  * Note that this routine assumes the caller holds forcewake asserted, it is
  * not suitable for very long waits. See intel_wait_for_register() if you
@@ -1620,6 +1622,9 @@ int __intel_wait_for_register_fw(struct
 #define done (((reg_value = I915_READ_FW(reg)) & mask) == value)
 	int ret;
 
+	/* Catch any overuse of this function */
+	might_sleep_if(fast_timeout_us > 10 || slow_timeout_ms);
+
 	if (fast_timeout_us > 10)
 		ret = _wait_for(done, fast_timeout_us, 10);
 	else