From 9d1d79acf251b04b22ff76e89fb8dea034c2f865 Mon Sep 17 00:00:00 2001
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date: Fri, 11 Oct 2013 17:14:31 +0200
Subject: [PATCH 301/414] drm: remove preempt_disable() from
 drm_calc_vbltimestamp_from_scanoutpos()

Luis captured the following:

| BUG: sleeping function called from invalid context at kernel/rtmutex.c:659
| in_atomic(): 1, irqs_disabled(): 0, pid: 517, name: Xorg
| 2 locks held by Xorg/517:
|  #0:
|  (
| &dev->vbl_lock
| ){......}
| , at:
| [<ffffffffa0024c60>] drm_vblank_get+0x30/0x2b0 [drm]
|  #1:
|  (
| &dev->vblank_time_lock
| ){......}
| , at:
| [<ffffffffa0024ce1>] drm_vblank_get+0xb1/0x2b0 [drm]
| Preemption disabled at:
| [<ffffffffa008bc95>] i915_get_vblank_timestamp+0x45/0xa0 [i915]
| CPU: 3 PID: 517 Comm: Xorg Not tainted 3.10.10-rt7+ #5
| Call Trace:
|  [<ffffffff8164b790>] dump_stack+0x19/0x1b
|  [<ffffffff8107e62f>] __might_sleep+0xff/0x170
|  [<ffffffff81651ac4>] rt_spin_lock+0x24/0x60
|  [<ffffffffa0084e67>] i915_read32+0x27/0x170 [i915]
|  [<ffffffffa008a591>] i915_pipe_enabled+0x31/0x40 [i915]
|  [<ffffffffa008a6be>] i915_get_crtc_scanoutpos+0x3e/0x1b0 [i915]
|  [<ffffffffa00245d4>] drm_calc_vbltimestamp_from_scanoutpos+0xf4/0x430 [drm]
|  [<ffffffffa008bc95>] i915_get_vblank_timestamp+0x45/0xa0 [i915]
|  [<ffffffffa0024998>] drm_get_last_vbltimestamp+0x48/0x70 [drm]
|  [<ffffffffa0024db5>] drm_vblank_get+0x185/0x2b0 [drm]
|  [<ffffffffa0025d03>] drm_wait_vblank+0x83/0x5d0 [drm]
|  [<ffffffffa00212a2>] drm_ioctl+0x552/0x6a0 [drm]
|  [<ffffffff811a0095>] do_vfs_ioctl+0x325/0x5b0
|  [<ffffffff811a03a1>] SyS_ioctl+0x81/0xa0
|  [<ffffffff8165a342>] tracesys+0xdd/0xe2

After a longer thread it was decided to drop the preempt_disable()/
enable() invocations which were meant for -RT and Mario Kleiner looks
for a replacement.

Cc: stable-rt@vger.kernel.org
Reported-By: Luis Claudio R. Goncalves <lclaudio@uudg.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 drivers/gpu/drm/drm_irq.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index f92da0a32f0d..434ea848c097 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -628,11 +628,6 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, int crtc,
 	 * code gets preempted or delayed for some reason.
 	 */
 	for (i = 0; i < DRM_TIMESTAMP_MAXRETRIES; i++) {
-		/* Disable preemption to make it very likely to
-		 * succeed in the first iteration even on PREEMPT_RT kernel.
-		 */
-		preempt_disable();
-
 		/* Get system timestamp before query. */
 		stime = ktime_get();
 
@@ -644,8 +639,6 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, int crtc,
 		if (!drm_timestamp_monotonic)
 			mono_time_offset = ktime_get_monotonic_offset();
 
-		preempt_enable();
-
 		/* Return as no-op if scanout query unsupported or failed. */
 		if (!(vbl_status & DRM_SCANOUTPOS_VALID)) {
 			DRM_DEBUG("crtc %d : scanoutpos query failed [%d].\n",
-- 
2.10.2

