dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/i915: Fix comparison bug
@ 2015-09-28 21:08 Rasmus Villemoes
  2015-09-29  7:37 ` Jani Nikula
  0 siblings, 1 reply; 4+ messages in thread
From: Rasmus Villemoes @ 2015-09-28 21:08 UTC (permalink / raw)
  To: Daniel Vetter, Jani Nikula, David Airlie
  Cc: Rasmus Villemoes, intel-gfx, dri-devel, linux-kernel

->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.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 drivers/gpu/drm/i915/i915_debugfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index e3ec9049081f..5207e681a987 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -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)
-- 
2.1.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/i915: Fix comparison bug
  2015-09-28 21:08 [PATCH] drm/i915: Fix comparison bug Rasmus Villemoes
@ 2015-09-29  7:37 ` Jani Nikula
  2015-09-29  7:43   ` Daniel Vetter
  0 siblings, 1 reply; 4+ messages in thread
From: Jani Nikula @ 2015-09-29  7:37 UTC (permalink / raw)
  To: Daniel Vetter, David Airlie
  Cc: intel-gfx, Rasmus Villemoes, linux-kernel, dri-devel

On Tue, 29 Sep 2015, Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
> ->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.
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>

Reviewed-by: Jani Nikula <jani.nikula@intel.com>


> ---
>  drivers/gpu/drm/i915/i915_debugfs.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> index e3ec9049081f..5207e681a987 100644
> --- a/drivers/gpu/drm/i915/i915_debugfs.c
> +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> @@ -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)
> -- 
> 2.1.3
>

-- 
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/i915: Fix comparison bug
  2015-09-29  7:37 ` Jani Nikula
@ 2015-09-29  7:43   ` Daniel Vetter
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Vetter @ 2015-09-29  7:43 UTC (permalink / raw)
  To: Jani Nikula
  Cc: David Airlie, intel-gfx, Rasmus Villemoes, linux-kernel,
	dri-devel, Daniel Vetter

On Tue, Sep 29, 2015 at 10:37:30AM +0300, Jani Nikula wrote:
> On Tue, 29 Sep 2015, Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
> > ->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.
> >
> > Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> 
> Reviewed-by: Jani Nikula <jani.nikula@intel.com>

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
> 
> 
> > ---
> >  drivers/gpu/drm/i915/i915_debugfs.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> > index e3ec9049081f..5207e681a987 100644
> > --- a/drivers/gpu/drm/i915/i915_debugfs.c
> > +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> > @@ -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)
> > -- 
> > 2.1.3
> >
> 
> -- 
> Jani Nikula, Intel Open Source Technology Center
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] drm/i915: Fix comparison bug
@ 2014-12-07 21:26 Rasmus Villemoes
  0 siblings, 0 replies; 4+ messages in thread
From: Rasmus Villemoes @ 2014-12-07 21:26 UTC (permalink / raw)
  To: Daniel Vetter, Jani Nikula, David Airlie
  Cc: Rasmus Villemoes, intel-gfx, dri-devel, linux-kernel

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

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 drivers/gpu/drm/i915/i915_debugfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 063b44817e08..adfb863bb580 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -236,7 +236,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)
-- 
2.1.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-29  7:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-28 21:08 [PATCH] drm/i915: Fix comparison bug Rasmus Villemoes
2015-09-29  7:37 ` Jani Nikula
2015-09-29  7:43   ` Daniel Vetter
  -- strict thread matches above, loose matches on Subject: below --
2014-12-07 21:26 Rasmus Villemoes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).