[Intel-gfx] [PATCH] drm/i915: Ensure that the wait ioctl return timeout is valid

Chris Wilson chris at chris-wilson.co.uk
Wed Nov 14 20:11:24 CET 2012


Due to a discrepancy between the sleep time and the amount of time we
spend waiting inside the wait_event_timeout, it is possible that we end
up computing that negative time remains in the wait_ioctl. This is
obviously a bogus result to return to userspace, and triggers a WARN, so
we need to fix up the value before propagating it back.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Ben Widawsky <ben at bwidawsk.net>
---
 drivers/gpu/drm/i915/i915_gem.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index cdcf19d..8e43a4f 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1050,6 +1050,8 @@ static int __wait_seqno(struct intel_ring_buffer *ring, u32 seqno,
 	if (timeout) {
 		struct timespec sleep_time = timespec_sub(now, before);
 		*timeout = timespec_sub(*timeout, sleep_time);
+		if (end == 0 || !timespec_valid(timeout))
+			set_normalized_timespec(timeout, 0, 0);
 	}
 
 	switch (end) {
@@ -1058,8 +1060,6 @@ static int __wait_seqno(struct intel_ring_buffer *ring, u32 seqno,
 	case -ERESTARTSYS: /* Signal */
 		return (int)end;
 	case 0: /* Timeout */
-		if (timeout)
-			set_normalized_timespec(timeout, 0, 0);
 		return -ETIME;
 	default: /* Completed */
 		WARN_ON(end < 0); /* We're not aware of other errors */
@@ -2335,10 +2335,9 @@ i915_gem_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	mutex_unlock(&dev->struct_mutex);
 
 	ret = __wait_seqno(ring, seqno, true, timeout);
-	if (timeout) {
-		WARN_ON(!timespec_valid(timeout));
+	if (timeout)
 		args->timeout_ns = timespec_to_ns(timeout);
-	}
+
 	return ret;
 
 out:
-- 
1.7.10.4




More information about the Intel-gfx mailing list