drm/i915: Gracefully handle obj not bound to GGTT in is_pin_display
Subsystems (2)
PATCH 1/1 drm/i915: Gracefully handle obj not bound to GGTT in is_pin_display
From: Oscar Mateo <[email protected]>
Otherwise, we do a NULL pointer dereference.
I've seen this happen while handling an error ini915_gem_object_pin_to_display_plane():
If i915_gem_object_set_cache_level() fails, we call is_pin_display() to handle the error. At this point, the object is still not pinned to GGTT and maybe not even bound, so we have to check before we dereference its GGTT vma.
Issue: VIZ-3772
--- drivers/gpu/drm/i915/i915_gem.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem.c +5 -1
@@ -3619,6 +3619,10 @@ unlock:static bool is_pin_display (struct drm_i915_gem_object *obj) { +struct i915_vma *vma =i915_gem_obj_to_ggtt (obj); +if (!vma) +return false; +/* There are 3 sources that pin objects: * 1. The display engine (scanouts, sprites, cursors); * 2. Reservations for execbuffer;
@@ -3630,7 +3634,7 @@ static bool is_pin_display(struct drm_i915_gem_object *obj)* subtracting the potential reference by the user, any pin_count * remains, it must be due to another use by the display engine. */ -return i915_gem_obj_to_ggtt (obj)->pin_count - !!obj->user_pin_count; +return vma->pin_count - !!obj->user_pin_count; }/*
Signature · 1 line
1.9.0
Quoted 3 lines · On Wed, Apr 02, 2014 at 07:21:01PM +0100, [email protected] wrote:
From: Oscar Mateo <[email protected]>
Otherwise, we do a NULL pointer dereference.
Or we could just dowas_pin_display = obj->pin_display;obj->pin_display = true;
err_unpin_display:obj->pin_display = was_pin_display;
And then we wouldn't even need the essay... However, it is almost a theory of operation and quite useful...
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Quoted 7 lines · On Wed, Apr 02, 2014 at 07:21:01PM +0100, [email protected] wrote:
From: Oscar Mateo <[email protected]>
Otherwise, we do a NULL pointer dereference.
I've seen this happen while handling an error in
i915_gem_object_pin_to_display_plane():
Quoted 7 lines
If
i915_gem_object_set_cache_level()fails, we callis_pin_display()to handle the error. At this point, the object is still not pinned to GGTT and maybe not even bound, so we have to check before we dereference its GGTT vma.Issue: VIZ-3772
Signed-off-by Oscar Mateo <[email protected]>
Have you looked into provoking this with an igt testcase? On a hunch a busy load (to extend the race window) plus the usual interruptor trick to jump out of wait_seqno calls should be able to make this go kaboom on command. But I haven't analyzed the bug in detail.
Thanks, Daniel
Quoted 35 lines
--- drivers/gpu/drm/i915/i915_gem.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/i915_gem.c +5
-1@@ -3619,6 +3619,10 @@ unlock:static bool is_pin_display (struct drm_i915_gem_object *obj) { +struct i915_vma *vma =i915_gem_obj_to_ggtt (obj); +if (!vma) +return false; +/* There are 3 sources that pin objects: * 1. The display engine (scanouts, sprites, cursors); * 2. Reservations for execbuffer; @@ -3630,7 +3634,7 @@ static bool is_pin_display(struct drm_i915_gem_object *obj)* subtracting the potential reference by the user, any pin_count * remains, it must be due to another use by the display engine. */ -return i915_gem_obj_to_ggtt (obj)->pin_count - !!obj->user_pin_count; +return vma->pin_count - !!obj->user_pin_count; }/* Signature · 6 lines
1.9.0 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Hi Daniel,
Sorry, this fell through the cracks:
Quoted 16 lines
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Gracefully handle obj not bound to GGTT in
is_pin_displayQuoted 12 lines · On Wed, Apr 02, 2014 at 07:21:01PM +0100, [email protected] wrote:
From: Oscar Mateo <[email protected]>
Otherwise, we do a NULL pointer dereference.
I've seen this happen while handling an error in
i915_gem_object_pin_to_display_plane():If
i915_gem_object_set_cache_level()fails, we callis_pin_display()to handle the error. At this point, the object is still not pinned to GGTT and maybe not even bound, so we have to check before we dereference its GGTT vma.
Quoted 7 lines
Quoted 2 lines
Issue: VIZ-3772
Signed-off-by Oscar Mateo <[email protected]>Have you looked into provoking this with an igt testcase? On a hunch a busy load (to extend the race window) plus the usual interruptor trick to jump out of
wait_seqnocalls should be able to make this go kaboom on command. But I haven't analyzed the bug in detail.
AFAICT, the only sequence where this likely to happen (because we are handling a recently created object) is:
intelfb_alloc -> intel_pin_and_fence_fb_obj -> i915_gem_object_pin_to_display_plane -> i915_gem_object_set_cache_level -> is_pin_display
Now, I think intelfb_alloc only happens during bootup, so reproducing it on IGT would be difficult. I still feel the fix is valid though :)
-- Oscar
Quoted 28 lines · Oscar
Hi Daniel,
Sorry, this fell through the cracks:
Quoted 16 lines
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Gracefully handle obj not bound to GGTT in
is_pin_displayQuoted 12 lines · On Wed, Apr 02, 2014 at 07:21:01PM +0100, [email protected] wrote:
From: Oscar Mateo <[email protected]>
Otherwise, we do a NULL pointer dereference.
I've seen this happen while handling an error in
i915_gem_object_pin_to_display_plane():If
i915_gem_object_set_cache_level()fails, we callis_pin_display()to handle the error. At this point, the object is still not pinned to GGTT and maybe not even bound, so we have to check before we dereference its GGTT vma.Quoted 7 lines
Quoted 2 lines
Issue: VIZ-3772
Signed-off-by Oscar Mateo <[email protected]>Have you looked into provoking this with an igt testcase? On a hunch a busy load (to extend the race window) plus the usual interruptor trick to jump out of
wait_seqnocalls should be able to make this go kaboom on command. But I haven't analyzed the bug in detail.
Quoted 6 lines
AFAICT, the only sequence where this likely to happen (because we are handling a recently created object) is:
intelfb_alloc->intel_pin_and_fence_fb_obj->i915_gem_object_pin_to_display_plane->i915_gem_object_set_cache_level->is_pin_displayNow, I think
intelfb_alloconly happens during bootup, so reproducing it on IGT would be difficult. I still feel the fix is valid though :)
Did you consider my alternative fix of restoring the old value in the error path?
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47
Quoted 45 lines
-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Monday, May 12, 2014 11:09 AM
To: Mateo Lozano, Oscar
Cc: Daniel Vetter; [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Gracefully handle obj not bound to GGTT inis_pin_displayQuoted 8 lines · Oscar
Hi Daniel,
Sorry, this fell through the cracks:
Quoted 4 lines
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Gracefully handle obj not bound to GGTT in
is_pin_displayOn Wed, Apr 02, 2014 at 07:21:01PM +0100, [email protected]
Quoted 15 lines · wrote:
Quoted 15 lines
Quoted 14 lines
From: Oscar Mateo <[email protected]>
Otherwise, we do a NULL pointer dereference.
I've seen this happen while handling an error in
i915_gem_object_pin_to_display_plane():If
i915_gem_object_set_cache_level()fails, we callis_pin_display()to handle the error. At this point, the object is still not pinned to GGTT and maybe not even bound, so we have to check before we dereference its GGTT vma.Issue: VIZ-3772
Signed-off-by Oscar Mateo <[email protected]>Quoted 6 lines
Quoted 4 lines
Have you looked into provoking this with an igt testcase? On a hunch a busy load (to extend the race window) plus the usual interruptor trick to jump out of
wait_seqnocalls should be able to make this go kaboom on command. But I haven't analyzed the bug in detail.AFAICT, the only sequence where this likely to happen (because we are
handling a recently created object) is:
Quoted 5 lines
intelfb_alloc->intel_pin_and_fence_fb_obj->i915_gem_object_pin_to_display_plane->i915_gem_object_set_cache_level->is_pin_display
Quoted 6 lines
Quoted 1 line
Now, I think
intelfb_alloconly happens during bootup, so reproducing it onIGT would be difficult.
Quoted 1 line
I still feel the fix is valid though :)
Did you consider my alternative fix of restoring the old value in the error path? -Chris
Is that directed to Daniel or me? Restoring the old value is way easier, but I thought you wanted to keep is_pin_display as a theory of operation? And Daniel might still want an IGT test, I suppose...
Quoted 4 lines · Oscar
Quoted 1 line
Did you consider my alternative fix of restoring the old value in the error path?
Is that directed to Daniel or me? Restoring the old value is way easier, but I thought you wanted to keep
is_pin_displayas a theory of operation? And Daniel might still want an IGT test, I suppose...
I'd like to be able to kill is_pin_display(), it's very fragile but I don't have a better alternative yet.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Quoted 23 lines · Oscar
Hi Daniel,
Sorry, this fell through the cracks:
Quoted 19 lines
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Gracefully handle obj not bound to GGTT in
is_pin_displayQuoted 14 lines · On Wed, Apr 02, 2014 at 07:21:01PM +0100, [email protected] wrote:
From: Oscar Mateo <[email protected]>
Otherwise, we do a NULL pointer dereference.
I've seen this happen while handling an error in
i915_gem_object_pin_to_display_plane():If
i915_gem_object_set_cache_level()fails, we callis_pin_display()to handle the error. At this point, the object is still not pinned to GGTT and maybe not even bound, so we have to check before we dereference its GGTT vma.Issue: VIZ-3772
Signed-off-by Oscar Mateo <[email protected]>
Quoted 8 lines
Quoted 4 lines
Have you looked into provoking this with an igt testcase? On a hunch a busy load (to extend the race window) plus the usual interruptor trick to jump out of
wait_seqnocalls should be able to make this go kaboom on command. But I haven't analyzed the bug in detail.AFAICT, the only sequence where this likely to happen (because we are handling a recently created object) is:
intelfb_alloc->intel_pin_and_fence_fb_obj->i915_gem_object_pin_to_display_plane->i915_gem_object_set_cache_level->is_pin_display
Pageflipping to a freshly allocated BO without ever touching it beforehand should be able to achive the same. If this is really all that's needed.
But looking at the code a better way should be:
1. Create new bo, wrap it in a kms fb.
2. Slap busy load onto that bo, e.g. reapeatedly fill it with the blitter.
3. Enable evil interruptor (igt_fork_signal_helper).
4. Submit pageflip
-> Boom since the set_cache_level will block, get interrupted and exit early with -EINTR.
Given sufficient overkill in 2. this should be 100% reliable to reproduce.
Cheers, Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 42 lines · Daniel Vetter
Quoted 23 lines · Oscar
Hi Daniel,
Sorry, this fell through the cracks:
Quoted 19 lines
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Gracefully handle obj not bound to GGTT in
is_pin_displayQuoted 14 lines · On Wed, Apr 02, 2014 at 07:21:01PM +0100, [email protected] wrote:
From: Oscar Mateo <[email protected]>
Otherwise, we do a NULL pointer dereference.
I've seen this happen while handling an error in
i915_gem_object_pin_to_display_plane():If
i915_gem_object_set_cache_level()fails, we callis_pin_display()to handle the error. At this point, the object is still not pinned to GGTT and maybe not even bound, so we have to check before we dereference its GGTT vma.Issue: VIZ-3772
Signed-off-by Oscar Mateo <[email protected]>Quoted 8 lines
Quoted 4 lines
Have you looked into provoking this with an igt testcase? On a hunch a busy load (to extend the race window) plus the usual interruptor trick to jump out of
wait_seqnocalls should be able to make this go kaboom on command. But I haven't analyzed the bug in detail.AFAICT, the only sequence where this likely to happen (because we are handling a recently created object) is:
intelfb_alloc->intel_pin_and_fence_fb_obj->i915_gem_object_pin_to_display_plane->i915_gem_object_set_cache_level->is_pin_displayPageflipping to a freshly allocated BO without ever touching it beforehand should be able to achive the same. If this is really all that's needed.
But looking at the code a better way should be:
1. Create new bo, wrap it in a kms fb.
2. Slap busy load onto that bo, e.g. reapeatedly fill it with the blitter.
3. Enable evil interruptor (igt_fork_signal_helper).
4. Submit pageflip
Quoted 4 lines
-> Boom since the
set_cache_levelwill block, get interrupted and exit early with-EINTR.Given sufficient overkill in 2. this should be 100% reliable to reproduce.
Aside: Those kinds of tricks are a big reason why I think igts aren't just useful as testcases, but also to really understand how a bug comes about. At least ime finally figuring out the last ingredient to make an igt fully reliably often resulted in a suddenly much clearer understanding of the bug at hand.
I call this "review by asking for an igt" ;-)
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 1 line
I call this "review by asking for an igt" ;-) -Daniel
Ok, I´ll give it a try. At least I will learn something about the kms code, a.k.a. "learning by igt" :D
Quoted 10 lines
Quoted 10 lines
But looking at the code a better way should be:
1. Create new bo, wrap it in a kms fb.
2. Slap busy load onto that bo, e.g. reapeatedly fill it with the blitter.
3. Enable evil interruptor (igt_fork_signal_helper).
4. Submit pageflip-> Boom since the
set_cache_levelwill block, get interrupted and exit early with-EINTR.Given sufficient overkill in 2. this should be 100% reliable to reproduce.
As soon as I execbuffer to the bo, it gets a vma for the GGTT vm:
vm = ctx->vm; if (!USES_FULL_PPGTT(dev)) vm = &dev_priv->gtt.base; ... /* Look up object handles */ ret = eb_lookup_vmas(eb, exec, args, vm, file); if (ret) goto err;
And then it becomes impossible to reproduce the problem :( Is there any other trick to make set_cache_level fail?
-- Oscar
Quoted 24 lines · Oscar
Quoted 10 lines
Quoted 10 lines
But looking at the code a better way should be:
1. Create new bo, wrap it in a kms fb.
2. Slap busy load onto that bo, e.g. reapeatedly fill it with the blitter.
3. Enable evil interruptor (igt_fork_signal_helper).
4. Submit pageflip-> Boom since the
set_cache_levelwill block, get interrupted and exit early with-EINTR.Given sufficient overkill in 2. this should be 100% reliable to reproduce.
As soon as I execbuffer to the bo, it gets a vma for the GGTT vm:
vm = ctx->vm; if (!USES_FULL_PPGTT(dev)) vm = &dev_priv->gtt.base; ... /* Look up object handles */ ret = eb_lookup_vmas(eb, exec, args, vm, file); if (ret) goto err;
Quoted 2 lines
And then it becomes impossible to reproduce the problem :( Is there any other trick to make
set_cache_levelfail?
What if you make the pin_to_ggtt fail instead? Can you create an object that's too big for the ggtt?
Signature · 2 lines
Ville Syrjälä Intel OTC
Quoted 34 lines
-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Thursday, May 15, 2014 2:34 PM
To: Mateo Lozano, Oscar
Cc: Daniel Vetter; [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Gracefully handle obj not bound to GGTT inis_pin_displayQuoted 25 lines · Oscar
Quoted 11 lines
Quoted 11 lines
But looking at the code a better way should be:
1. Create new bo, wrap it in a kms fb.
2. Slap busy load onto that bo, e.g. reapeatedly fill it with the blitter.
3. Enable evil interruptor (igt_fork_signal_helper).
4. Submit pageflip-> Boom since the
set_cache_levelwill block, get interrupted and -> exit
early with-EINTR.Given sufficient overkill in 2. this should be 100% reliable to reproduce.
As soon as I execbuffer to the bo, it gets a vma for the GGTT vm:
vm = ctx->vm; if (!USES_FULL_PPGTT(dev)) vm = &dev_priv->gtt.base; ... /* Look up object handles */ ret = eb_lookup_vmas(eb, exec, args, vm, file); if (ret) goto err;
Quoted 5 lines
Quoted 2 lines
And then it becomes impossible to reproduce the problem :( Is there any other trick to make
set_cache_levelfail?What if you make the
pin_to_ggttfail instead? Can you create an object that's too big for the ggtt?
Thanks Ville: that worked like a charm ;)
Quoted 24 lines · Oscar
Quoted 10 lines
Quoted 10 lines
But looking at the code a better way should be:
1. Create new bo, wrap it in a kms fb.
2. Slap busy load onto that bo, e.g. reapeatedly fill it with the blitter.
3. Enable evil interruptor (igt_fork_signal_helper).
4. Submit pageflip-> Boom since the
set_cache_levelwill block, get interrupted and exit early with-EINTR.Given sufficient overkill in 2. this should be 100% reliable to reproduce.
As soon as I execbuffer to the bo, it gets a vma for the GGTT vm:
vm = ctx->vm; if (!USES_FULL_PPGTT(dev)) vm = &dev_priv->gtt.base; ... /* Look up object handles */ ret = eb_lookup_vmas(eb, exec, args, vm, file); if (ret) goto err;
Quoted 2 lines
And then it becomes impossible to reproduce the problem :( Is there any other trick to make
set_cache_levelfail?
i915.ppgtt=2 should still make this blow up. The bug kinda doesn't exist without full ppgtt I think ...
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
PATCH v2 1/1 drm/i915: Gracefully handle obj not bound to GGTT in is_pin_display
In reply to [email protected]From: Oscar Mateo <[email protected]>
Otherwise, we do a NULL pointer dereference.
I've seen this happen while handling an error ini915_gem_object_pin_to_display_plane():
If i915_gem_object_set_cache_level() fails, we call is_pin_display() to handle the error. At this point, the object is still not pinned to GGTT and maybe not even bound, so we have to check before we dereference its GGTT vma.
v2: Chris Wilson says restoring the old value is easier, but that is_pin_display is useful as a theory of operation. Take the solomonic
decision: at least this way is_pin_display is a little more robust (until Chris can kill it off).
Issue: VIZ-3772
--- drivers/gpu/drm/i915/i915_gem.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +14 -2
@@ -3641,6 +3641,15 @@ unlock:static bool is_pin_display (struct drm_i915_gem_object *obj) { +struct i915_vma *vma; + +if (list_empty (&obj->vma_list)) +return false; + + vma =i915_gem_obj_to_ggtt (obj); +if (!vma) +return false; +/* There are 3 sources that pin objects: * 1. The display engine (scanouts, sprites, cursors); * 2. Reservations for execbuffer;
@@ -3652,7 +3661,7 @@ static bool is_pin_display(struct drm_i915_gem_object *obj)* subtracting the potential reference by the user, any pin_count * remains, it must be due to another use by the display engine. */ -return i915_gem_obj_to_ggtt (obj)->pin_count - !!obj->user_pin_count; +return vma->pin_count - !!obj->user_pin_count; }/*
@@ -3666,6 +3675,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj, struct intel_ring_buffer *pipelined) {u32 old_read_domains, old_write_domain; +bool was_pin_display;int ret;if (pipelined != obj->ring) {
@@ -3677,6 +3687,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,/* Mark the pin_display early so that we account for the * display coherency whilst setting up the cache domains. */ + was_pin_display = obj->pin_display; obj->pin_display = true;/* The display engine is not coherent with the LLC cache on gen6. As
@@ -3719,7 +3730,8 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,return 0 ; err_unpin_display: - obj->pin_display =is_pin_display (obj); +WARN_ON (was_pin_display !=is_pin_display (obj)); + obj->pin_display = was_pin_display;return ret; }
Signature · 1 line
1.9.0
Quoted 12 lines · On Fri, May 16, 2014 at 12:08:22PM +0100, [email protected] wrote:
From: Oscar Mateo <[email protected]>
Otherwise, we do a NULL pointer dereference.
I've seen this happen while handling an error in
i915_gem_object_pin_to_display_plane():If
i915_gem_object_set_cache_level()fails, we callis_pin_display()to handle the error. At this point, the object is still not pinned to GGTT and maybe not even bound, so we have to check before we dereference its GGTT vma.
Quoted 6 lines
v2: Chris Wilson says restoring the old value is easier, but that
is_pin_displayis useful as a theory of operation. Take the solomonic
decision: at least this wayis_pin_displayis a little more robust (until Chris can kill it off).Issue: VIZ-3772
I heard you wrote a testcase?
Quoted 10 lines
Signed-off-by Oscar Mateo <[email protected]>--- drivers/gpu/drm/i915/i915_gem.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/i915_gem.c +0
-0
drivers/gpu/drm/i915/i915_gem.c unlock: · line 3647
Quoted 7 lines
drivers/gpu/drm/i915/i915_gem.c +4
-0@@ -3641,6 +3641,15 @@ unlock:static bool is_pin_display (struct drm_i915_gem_object *obj) { +struct i915_vma *vma; + +if (list_empty (&obj->vma_list)) +return false;
Hmm, this is so that we don't trigger the WARN from inside i915_gem_obj_to_ggtt(). I would say that means the WARN in the callee has outlived its usefulness. Other callers WARN if they fail to find the ggtt_vma they expect, so I think we can just drop the WARN and save the duplication here.
Quoted 34 lines
drivers/gpu/drm/i915/i915_gem.c +8
-1+ + vma =i915_gem_obj_to_ggtt (obj); +if (!vma) +return false; +/* There are 3 sources that pin objects: * 1. The display engine (scanouts, sprites, cursors); * 2. Reservations for execbuffer; @@ -3652,7 +3661,7 @@ static bool is_pin_display(struct drm_i915_gem_object *obj)* subtracting the potential reference by the user, any pin_count * remains, it must be due to another use by the display engine. */ -return i915_gem_obj_to_ggtt (obj)->pin_count - !!obj->user_pin_count; +return vma->pin_count - !!obj->user_pin_count; }/* @@ -3666,6 +3675,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj, struct intel_ring_buffer *pipelined) {u32 old_read_domains, old_write_domain; +bool was_pin_display;int ret;if (pipelined != obj->ring) {@@ -3677,6 +3687,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,/* Mark the pin_display early so that we account for the * display coherency whilst setting up the cache domains. */ + was_pin_display = obj->pin_display; obj->pin_display = true;/* The display engine is not coherent with the LLC cache on gen6. As
drivers/gpu/drm/i915/i915_gem.c i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj, · line 3736
Quoted 8 lines
drivers/gpu/drm/i915/i915_gem.c +2
-1@@ -3719,7 +3730,8 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,return 0 ; err_unpin_display: - obj->pin_display =is_pin_display (obj); +WARN_ON (was_pin_display !=is_pin_display (obj)); + obj->pin_display = was_pin_display;return ret; }
Ok, this looks like a useful check.
Other than the debate over the placement of the WARN() in i915_gem_obj_to_ggtt() (maybe leave a comment here to remind us to drop the WARN and the check later?),
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
PATCH v3 1/1 drm/i915: Gracefully handle obj not bound to GGTT in is_pin_display
In reply to [email protected]From: Oscar Mateo <[email protected]>
Otherwise, we do a NULL pointer dereference.
I've seen this happen while handling an error ini915_gem_object_pin_to_display_plane():
If i915_gem_object_set_cache_level() fails, we call is_pin_display() to handle the error. At this point, the object is still not pinned to GGTT and maybe not even bound, so we have to check before we dereference its GGTT vma.
The IGT kms_flip/bo-too-big tests for this bug.
v2: Chris Wilson says restoring the old value is easier, but that is_pin_display is useful as a theory of operation. Take the solomonic
decision: at least this way is_pin_display is a little more robust (until Chris can kill it off).
v3: Chris suggests the WARN in i915_gem_obj_to_ggtt has outlived its
usefulness: add a reminder to remove it.
Issue: VIZ-3772
--- drivers/gpu/drm/i915/i915_gem.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +17 -2
@@ -3641,6 +3641,15 @@ unlock:static bool is_pin_display (struct drm_i915_gem_object *obj) { +struct i915_vma *vma; + +if (list_empty (&obj->vma_list)) +return false; + + vma =i915_gem_obj_to_ggtt (obj); +if (!vma) +return false; +/* There are 3 sources that pin objects: * 1. The display engine (scanouts, sprites, cursors); * 2. Reservations for execbuffer;
@@ -3652,7 +3661,7 @@ static bool is_pin_display(struct drm_i915_gem_object *obj)* subtracting the potential reference by the user, any pin_count * remains, it must be due to another use by the display engine. */ -return i915_gem_obj_to_ggtt (obj)->pin_count - !!obj->user_pin_count; +return vma->pin_count - !!obj->user_pin_count; }/*
@@ -3666,6 +3675,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj, struct intel_ring_buffer *pipelined) {u32 old_read_domains, old_write_domain; +bool was_pin_display;int ret;if (pipelined != obj->ring) {
@@ -3677,6 +3687,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,/* Mark the pin_display early so that we account for the * display coherency whilst setting up the cache domains. */ + was_pin_display = obj->pin_display; obj->pin_display = true;/* The display engine is not coherent with the LLC cache on gen6. As
@@ -3719,7 +3730,8 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,return 0 ; err_unpin_display: - obj->pin_display =is_pin_display (obj); +WARN_ON (was_pin_display !=is_pin_display (obj)); + obj->pin_display = was_pin_display;return ret; }
@@ -5115,6 +5127,9 @@ struct i915_vma *i915_gem_obj_to_ggtt(struct drm_i915_gem_object *obj) {struct i915_vma *vma; +/* This WARN has probably outlived its usefulness (callers already +* WARN if they don't find the GGTT vma they expect). When removing, +* remember to remove the pre-check in is_pin_display() as well */ if (WARN_ON (list_empty (&obj->vma_list)))return NULL ;
Signature · 1 line
1.9.0
Daniel Vetter
AppliedQuoted 19 lines · On Fri, May 16, 2014 at 02:20:43PM +0100, [email protected] wrote:
From: Oscar Mateo <[email protected]>
Otherwise, we do a NULL pointer dereference.
I've seen this happen while handling an error in
i915_gem_object_pin_to_display_plane():If
i915_gem_object_set_cache_level()fails, we callis_pin_display()to handle the error. At this point, the object is still not pinned to GGTT and maybe not even bound, so we have to check before we dereference its GGTT vma.The IGT kms_flip/bo-too-big tests for this bug.
v2: Chris Wilson says restoring the old value is easier, but that
is_pin_displayis useful as a theory of operation. Take the solomonic
decision: at least this wayis_pin_displayis a little more robust (until Chris can kill it off).
Quoted 5 lines
v3: Chris suggests the WARN in
i915_gem_obj_to_ggtthas outlived its
usefulness: add a reminder to remove it.Issue: VIZ-3772
Signed-off-by Oscar Mateo <[email protected]>
Queued for -next, thanks for the patch.
-Daniel
Quoted 76 lines
--- drivers/gpu/drm/i915/i915_gem.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/i915_gem.c +17
-2@@ -3641,6 +3641,15 @@ unlock:static bool is_pin_display (struct drm_i915_gem_object *obj) { +struct i915_vma *vma; + +if (list_empty (&obj->vma_list)) +return false; + + vma =i915_gem_obj_to_ggtt (obj); +if (!vma) +return false; +/* There are 3 sources that pin objects: * 1. The display engine (scanouts, sprites, cursors); * 2. Reservations for execbuffer; @@ -3652,7 +3661,7 @@ static bool is_pin_display(struct drm_i915_gem_object *obj)* subtracting the potential reference by the user, any pin_count * remains, it must be due to another use by the display engine. */ -return i915_gem_obj_to_ggtt (obj)->pin_count - !!obj->user_pin_count; +return vma->pin_count - !!obj->user_pin_count; }/* @@ -3666,6 +3675,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj, struct intel_ring_buffer *pipelined) {u32 old_read_domains, old_write_domain; +bool was_pin_display;int ret;if (pipelined != obj->ring) {@@ -3677,6 +3687,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,/* Mark the pin_display early so that we account for the * display coherency whilst setting up the cache domains. */ + was_pin_display = obj->pin_display; obj->pin_display = true;/* The display engine is not coherent with the LLC cache on gen6. As @@ -3719,7 +3730,8 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,return 0 ; err_unpin_display: - obj->pin_display =is_pin_display (obj); +WARN_ON (was_pin_display !=is_pin_display (obj)); + obj->pin_display = was_pin_display;return ret; }@@ -5115,6 +5127,9 @@ struct i915_vma *i915_gem_obj_to_ggtt(struct drm_i915_gem_object *obj) {struct i915_vma *vma; +/* This WARN has probably outlived its usefulness (callers already +* WARN if they don't find the GGTT vma they expect). When removing, +* remember to remove the pre-check in is_pin_display() as well */ if (WARN_ON (list_empty (&obj->vma_list)))return NULL ;Signature · 6 lines
1.9.0 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch