drm/i915: Fix comparison bug
Subsystems (2)
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
@@ -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
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_MAXof each other (so that the difference is actually representable in an int), but440fd5283a87("drm/mm: Support 4 GiB and larger ranges") strongly suggests that's not the case.Signed-off-by Rasmus Villemoes <[email protected]>
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@@ -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
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_MAXof each other (so that the difference is actually representable in an int), but440fd5283a87("drm/mm: Support 4 GiB and larger ranges") strongly suggests that's not the case.Signed-off-by Rasmus Villemoes <[email protected]>Reviewed-by Jani Nikula <[email protected]>
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@@ -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.3Signature · 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