Skip to contentSkip to conversation

drm/i915: Fix comparison bug

PATCH In review Rasmus Villemoes 3 participants 3 messages Sep 28, 2015 – Sep 29, 2015

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

PATCH 1/1 drm/i915: Fix comparison bug

->stolen->start has type u64 aka unsigned long long; relying on the difference (effectively cast to int) for sorting is wrong.

It wouldn't be a problem in practice if the values compared are always within INT_MAX of each other (so that the difference is actually representable in an int), but 440fd5283a87 ("drm/mm: Support 4 GiB and larger ranges") strongly suggests that's not the case.

---
 drivers/gpu/drm/i915/i915_debugfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_debugfs.c +5 -1
index e3ec9049081f..5207e681a987 100644
@@ -258,7 +258,11 @@ static int obj_rank_by_stolen(void *priv,
 	struct drm_i915_gem_object *b =
 		container_of(B, struct drm_i915_gem_object, obj_exec_link);
 
-	return a->stolen->start - b->stolen->start;
+	if (a->stolen->start < b->stolen->start)
+		return -1;
+	if (a->stolen->start > b->stolen->start)
+		return 1;
+	return 0;
 }
 
 static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
Signature · 1 line
2.1.3
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Rasmus Villemoes

->stolen->start has type u64 aka unsigned long long; relying on the difference (effectively cast to int) for sorting is wrong.

It wouldn't be a problem in practice if the values compared are always within INT_MAX of each other (so that the difference is actually representable in an int), but 440fd5283a87 ("drm/mm: Support 4 GiB and larger ranges") strongly suggests that's not the case.

Quoted 24 lines
---
 drivers/gpu/drm/i915/i915_debugfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_debugfs.c +5 -1
index e3ec9049081f..5207e681a987 100644
@@ -258,7 +258,11 @@ static int obj_rank_by_stolen(void *priv,
 	struct drm_i915_gem_object *b =
 		container_of(B, struct drm_i915_gem_object, obj_exec_link);
 
-	return a->stolen->start - b->stolen->start;
+	if (a->stolen->start < b->stolen->start)
+		return -1;
+	if (a->stolen->start > b->stolen->start)
+		return 1;
+	return 0;
 }
 
 static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
Signature · 1 line
2.1.3
Signature · 1 line
Jani Nikula, Intel Open Source Technology Center
#2 lore raw
Quoted 4 lines · Jani Nikula
Quoted 3 lines · Rasmus Villemoes

->stolen->start has type u64 aka unsigned long long; relying on the difference (effectively cast to int) for sorting is wrong.

Quoted 8 lines
Quoted 6 lines

It wouldn't be a problem in practice if the values compared are always within INT_MAX of each other (so that the difference is actually representable in an int), but 440fd5283a87 ("drm/mm: Support 4 GiB and larger ranges") strongly suggests that's not the case.

drm_mm is the shared gpu memmory manager, but stolen itself can only go to about 1.5G currently. So safe, but I merged your patch anyway with a small note added for 4.4.

Thanks, Daniel

Quoted 33 lines
Quoted 26 lines

---
 drivers/gpu/drm/i915/i915_debugfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_debugfs.c +5 -1
index e3ec9049081f..5207e681a987 100644
@@ -258,7 +258,11 @@ static int obj_rank_by_stolen(void *priv,
 	struct drm_i915_gem_object *b =
 		container_of(B, struct drm_i915_gem_object, obj_exec_link);
 
-	return a->stolen->start - b->stolen->start;
+	if (a->stolen->start < b->stolen->start)
+		return -1;
+	if (a->stolen->start > b->stolen->start)
+		return 1;
+	return 0;
 }
 
 static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
Signature · 1 line
2.1.3
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx