Skip to contentSkip to conversation

drm: Don't pass negative delta to ktime_sub_ns()

PATCH In review Michel Dänzer 4 participants 7 messages Jun 12, 2013 – Aug 7, 2013

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

PATCH 1/1 drm: Don't pass negative delta to ktime_sub_ns()

From: Michel Dänzer <[email protected]>

It takes an unsigned value. This happens not to blow up on 64-bit architectures, but it does on 32-bit, causing drm_calc_vbltimestamp_from_scanoutpos() to calculate totally bogus timestamps for vblank events. Which in turn causes e.g. gnome-shell to hang after a DPMS off cycle with current xf86-video-ati Git.

---
 drivers/gpu/drm/drm_irq.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_irq.c +4 -1
index a6a8643..39665f8 100644
@@ -708,7 +708,10 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, int crtc,
 	/* Subtract time delta from raw timestamp to get final
 	 * vblank_time timestamp for end of vblank.
 	 */
-	etime = ktime_sub_ns(etime, delta_ns);
+	if (delta_ns < 0)
+		etime = ktime_add_ns(etime, -delta_ns);
+	else
+		etime = ktime_sub_ns(etime, delta_ns);
 	*vblank_time = ktime_to_timeval(etime);
 
 	DRM_DEBUG("crtc %d : v %d p(%d,%d)@ %ld.%ld -> %ld.%ld [e %d us, %d rep]\n",
Signature · 6 lines
1.8.3

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 10 lines · Michel Dänzer

From: Michel Dänzer <[email protected]>

It takes an unsigned value. This happens not to blow up on 64-bit architectures, but it does on 32-bit, causing drm_calc_vbltimestamp_from_scanoutpos() to calculate totally bogus timestamps for vblank events. Which in turn causes e.g. gnome-shell to hang after a DPMS off cycle with current xf86-video-ati Git.

iiuc, this occurs when compensating for the early vblank interrupt. However,

#define ktime_sub_ns(kt, nsval) \
    ({ (ktime_t){ .tv64 = (kt).tv64 - (nsval) }; })

so both tv64 and delta_ns are s64. I am not seeing the unsigned promotion bug here.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#2 lore raw
Quoted 12 lines · Chris Wilson
Quoted 10 lines · Michel Dänzer

From: Michel Dänzer <[email protected]>

It takes an unsigned value. This happens not to blow up on 64-bit architectures, but it does on 32-bit, causing drm_calc_vbltimestamp_from_scanoutpos() to calculate totally bogus timestamps for vblank events. Which in turn causes e.g. gnome-shell to hang after a DPMS off cycle with current xf86-video-ati Git.

Quoted 8 lines

iiuc, this occurs when compensating for the early vblank interrupt. However,

#define ktime_sub_ns(kt, nsval) \
    ({ (ktime_t){ .tv64 = (kt).tv64 - (nsval) }; })

so both tv64 and delta_ns are s64. I am not seeing the unsigned promotion bug here.

Ok, Imre pointed out to me that there is a separate definition for 32-bit machines that does seem limited to only handling unsigned ns values. And so currently blows up big time for the early vblank case.

If we knew the values were guaranteed to be less that a second we could just use ktime_add() by keeping delta_ns as a ktime_t instead. Since we are dealing with fractions of a frame...
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Reviewed-by on v1 1/1
#3 lore raw
In reply to Michel Dänzer
Quoted 10 lines · Michel Dänzer

From: Michel Dänzer <[email protected]>

It takes an unsigned value. This happens not to blow up on 64-bit architectures, but it does on 32-bit, causing drm_calc_vbltimestamp_from_scanoutpos() to calculate totally bogus timestamps for vblank events. Which in turn causes e.g. gnome-shell to hang after a DPMS off cycle with current xf86-video-ati Git.

Yes, I introduced this regression in:

drm: use monotonic time in drm_calc_vbltimestamp_from_scanoutpos

The fix seems to be ok, perhaps you should also mention the regressing commit in the commit message.

Quoted 10 lines
---
 drivers/gpu/drm/drm_irq.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_irq.c +0 -0
index a6a8643..39665f8 100644
@@ -708,7 +708,10 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, int crtc,
 	/* Subtract time delta from raw timestamp to get final

drivers/gpu/drm/drm_irq.c int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, int crtc, · line 717

Quoted 10 lines
drivers/gpu/drm/drm_irq.c +4 -1
 	 * vblank_time timestamp for end of vblank.
 	 */
-	etime = ktime_sub_ns(etime, delta_ns);
+	if (delta_ns < 0)
+		etime = ktime_add_ns(etime, -delta_ns);
+	else
+		etime = ktime_sub_ns(etime, delta_ns);
 	*vblank_time = ktime_to_timeval(etime);
 
 	DRM_DEBUG("crtc %d : v %d p(%d,%d)@ %ld.%ld -> %ld.%ld [e %d us, %d rep]\n",

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

Tested-by shui yangwei on v1 1/1
#4 lore raw
In reply to Michel Dänzer
Quoted 10 lines · Michel Dänzer

From: Michel Dänzer <[email protected]>

It takes an unsigned value. This happens not to blow up on 64-bit architectures, but it does on 32-bit, causing drm_calc_vbltimestamp_from_scanoutpos() to calculate totally bogus timestamps for vblank events. Which in turn causes e.g. gnome-shell to hang after a DPMS off cycle with current xf86-video-ati Git.

Our paranoid flip tester apparently hit this:

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=59339
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=59836

Cheers, Daniel

Quoted 27 lines
---
 drivers/gpu/drm/drm_irq.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_irq.c +4 -1
index a6a8643..39665f8 100644
@@ -708,7 +708,10 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, int crtc,
 	/* Subtract time delta from raw timestamp to get final
 	 * vblank_time timestamp for end of vblank.
 	 */
-	etime = ktime_sub_ns(etime, delta_ns);
+	if (delta_ns < 0)
+		etime = ktime_add_ns(etime, -delta_ns);
+	else
+		etime = ktime_sub_ns(etime, delta_ns);
 	*vblank_time = ktime_to_timeval(etime);
 
 	DRM_DEBUG("crtc %d : v %d p(%d,%d)@ %ld.%ld -> %ld.%ld [e %d us, %d rep]\n",
Signature · 6 lines
1.8.3

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#5 lore raw
In reply to Michel Dänzer
Quoted 10 lines · Michel Dänzer

From: Michel Dänzer <[email protected]>

It takes an unsigned value. This happens not to blow up on 64-bit architectures, but it does on 32-bit, causing drm_calc_vbltimestamp_from_scanoutpos() to calculate totally bogus timestamps for vblank events. Which in turn causes e.g. gnome-shell to hang after a DPMS off cycle with current xf86-video-ati Git.

Dave, it looks like you missed this patch.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#6 lore raw
               vimOn Mit, 2013-07-17 at 12:58 +0100, Chris Wilson wrote:
Quoted 9 lines · Michel Dänzer
Quoted 8 lines

From: Michel Dänzer <[email protected]>

It takes an unsigned value. This happens not to blow up on 64-bit architectures, but it does on 32-bit, causing drm_calc_vbltimestamp_from_scanoutpos() to calculate totally bogus timestamps for vblank events. Which in turn causes e.g. gnome-shell to hang after a DPMS off cycle with current xf86-video-ati Git.

Quoted 4 lines
Quoted 2 lines

Dave, it looks like you missed this patch.

Dave, any particular reason why this fix still isn't merged? It's approaching its two-month anniversary...

Signature · 7 lines
Earthling Michel Dänzer           |                   http://www.amd.com
Libre software enthusiast         |          Debian, X and DRI developer

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