drm/i915: fix up error cleanup in i915_gem_object_bind_to_gtt
Subsystems (2)
PATCH 1/1 drm/i915: fix up error cleanup in i915_gem_object_bind_to_gtt
This has been broken in
commit 2f63315692b1d3c055972ad33fc7168ae908b97b
Author: Ben Widawsky <[email protected]> Date: Wed Jul 17 12:19:03 2013 -0700
drm/i915: Create VMAs
which resulted in an OOPS the first time around we've hit -ENOSPC.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=67156
--- drivers/gpu/drm/i915/i915_gem.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +8 -6
@@ -3121,8 +3121,8 @@ i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj, vma =i915_gem_vma_create (obj, &dev_priv->gtt.base);if (IS_ERR (vma)) { -i915_gem_object_unpin_pages (obj); -return PTR_ERR (vma); + ret =PTR_ERR (vma); + goto err_unpin; } search_free:
@@ -3138,17 +3138,17 @@ search_free:if (ret ==0 ) goto search_free; - goto err_out; + goto err_free_vma; }if (WARN_ON (!i915_gem_valid_gtt_space (dev, &vma->node, obj->cache_level))) { ret = -EINVAL ; - goto err_out; + goto err_remove_node; } ret =i915_gem_gtt_prepare_object (obj);if (ret) - goto err_out; + goto err_remove_node;list_move_tail (&obj->global_list, &dev_priv->mm.bound_list);list_add_tail (&obj->mm_list, &vm->inactive_list);
@@ -3167,9 +3167,11 @@ search_free:i915_gem_verify_gtt (dev);return 0 ; -err_out: +err_remove_node:drm_mm_remove_node (&vma->node); +err_free_vma:i915_gem_vma_destroy (vma); +err_unpin:i915_gem_object_unpin_pages (obj);return ret; }
Signature · 1 line
1.8.3.2
Quoted 8 lines · Daniel Vetter
This has been broken in
commit
2f63315692b1d3c055972ad33fc7168ae908b97bAuthor: Ben Widawsky <[email protected]> Date: Wed Jul 17 12:19:03 2013 -0700drm/i915: Create VMAs
Quoted 7 lines
which resulted in an OOPS the first time around we've hit
-ENOSPC.Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=67156
Cc Imre Deak <[email protected]>Cc Ben Widawsky <[email protected]>Tested-by meng <[email protected]>Signed-off-by Daniel Vetter <[email protected]>
I tried and failed to demonstrate that this was overkill.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Quoted 24 lines · Daniel Vetter
This has been broken in
commit
2f63315692b1d3c055972ad33fc7168ae908b97bAuthor: Ben Widawsky <[email protected]> Date: Wed Jul 17 12:19:03 2013 -0700drm/i915: Create VMAs
which resulted in an OOPS the first time around we've hit
-ENOSPC.Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=67156
Cc Imre Deak <[email protected]>Cc Ben Widawsky <[email protected]>Tested-by meng <[email protected]>Signed-off-by Daniel Vetter <[email protected]>--- drivers/gpu/drm/i915/i915_gem.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)drivers/gpu/drm/i915/i915_gem.c +0
-0
drivers/gpu/drm/i915/i915_gem.c i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj, · line 3126
Quoted 8 lines
drivers/gpu/drm/i915/i915_gem.c +2
-2@@ -3121,8 +3121,8 @@ i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj, vma =i915_gem_vma_create (obj, &dev_priv->gtt.base);if (IS_ERR (vma)) { -i915_gem_object_unpin_pages (obj); -return PTR_ERR (vma); + ret =PTR_ERR (vma); + goto err_unpin; }
Adding the extra goto here seems pointless to me.
drivers/gpu/drm/i915/i915_gem.c search_free: · line 3142
Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c +1
-1search_free:@@ -3138,17 +3138,17 @@ search_free:if (ret ==0 ) goto search_free; - goto err_out; + goto err_free_vma; }
My preference would be to exit early in drm_mm_remove_node() if the node isn't allocated. I think at least we should add a WARN to drm_mm_remove_node if the node->allocated == 0.
Quoted 17 lines
drivers/gpu/drm/i915/i915_gem.c +2
-2if (WARN_ON (!i915_gem_valid_gtt_space (dev, &vma->node, obj->cache_level))) { ret = -EINVAL ; - goto err_out; + goto err_remove_node; } ret =i915_gem_gtt_prepare_object (obj);if (ret) - goto err_out; + goto err_remove_node;list_move_tail (&obj->global_list, &dev_priv->mm.bound_list);list_add_tail (&obj->mm_list, &vm->inactive_list);@@ -3167,9 +3167,11 @@ search_free:i915_gem_verify_gtt (dev);return 0 ;
drivers/gpu/drm/i915/i915_gem.c search_free: · line 3177
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +3
-1-err_out: +err_remove_node:drm_mm_remove_node (&vma->node); +err_free_vma:i915_gem_vma_destroy (vma); +err_unpin:i915_gem_object_unpin_pages (obj);return ret; }
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
Daniel Vetter
AppliedQuoted 26 lines · Ben Widawsky
Quoted 25 lines · Daniel Vetter
This has been broken in
commit
2f63315692b1d3c055972ad33fc7168ae908b97bAuthor: Ben Widawsky <[email protected]> Date: Wed Jul 17 12:19:03 2013 -0700drm/i915: Create VMAs
which resulted in an OOPS the first time around we've hit
-ENOSPC.Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=67156
Cc Imre Deak <[email protected]>Cc Ben Widawsky <[email protected]>Tested-by meng <[email protected]>Signed-off-by Daniel Vetter <[email protected]>--- drivers/gpu/drm/i915/i915_gem.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)drivers/gpu/drm/i915/i915_gem.c +0
-0@@ -3121,8 +3121,8 @@ i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj,
Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj, · line 3126
Quoted 7 lines
drivers/gpu/drm/i915/i915_gem.c +2
-2vma =i915_gem_vma_create (obj, &dev_priv->gtt.base);if (IS_ERR (vma)) { -i915_gem_object_unpin_pages (obj); -return PTR_ERR (vma); + ret =PTR_ERR (vma); + goto err_unpin; }Adding the extra goto here seems pointless to me.
Like explained on irc, that's just to have a nice OCD reverse err_foo:
label stacking at the end of the function.
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/i915/i915_gem.c +0
-0search_free:@@ -3138,17 +3138,17 @@ search_free:if (ret ==0 ) goto search_free;
Quoted 7 lines
drivers/gpu/drm/i915/i915_gem.c search_free: · line 3142
Quoted 3 lines
drivers/gpu/drm/i915/i915_gem.c +1
-1- goto err_out; + goto err_free_vma; }My preference would be to exit early in
drm_mm_remove_node()if the node isn't allocated. I think at least we should add a WARN todrm_mm_remove_nodeif thenode->allocated== 0.
Hm, good idea. I'll create a quick patch.
Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/i915/i915_gem.c +2
-2if (WARN_ON (!i915_gem_valid_gtt_space (dev, &vma->node, obj->cache_level))) { ret = -EINVAL ; - goto err_out; + goto err_remove_node; } ret =i915_gem_gtt_prepare_object (obj);if (ret) - goto err_out; + goto err_remove_node;list_move_tail (&obj->global_list, &dev_priv->mm.bound_list);list_add_tail (&obj->mm_list, &vm->inactive_list);@@ -3167,9 +3167,11 @@ search_free:i915_gem_verify_gtt (dev);return 0 ;
Quoted 11 lines
drivers/gpu/drm/i915/i915_gem.c search_free: · line 3177
Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c +3
-1-err_out: +err_remove_node:drm_mm_remove_node (&vma->node); +err_free_vma:i915_gem_vma_destroy (vma); +err_unpin:i915_gem_object_unpin_pages (obj);return ret; }Reviewed-by Ben Widawsky <[email protected]>
Queued for -next, thanks for the review.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 87 lines · Daniel Vetter
Quoted 26 lines · Ben Widawsky
Quoted 25 lines · Daniel Vetter
This has been broken in
commit
2f63315692b1d3c055972ad33fc7168ae908b97bAuthor: Ben Widawsky <[email protected]> Date: Wed Jul 17 12:19:03 2013 -0700drm/i915: Create VMAs
which resulted in an OOPS the first time around we've hit
-ENOSPC.Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=67156
Cc Imre Deak <[email protected]>Cc Ben Widawsky <[email protected]>Tested-by meng <[email protected]>Signed-off-by Daniel Vetter <[email protected]>--- drivers/gpu/drm/i915/i915_gem.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)drivers/gpu/drm/i915/i915_gem.c +0
-0@@ -3121,8 +3121,8 @@ i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj,Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj, · line 3126
Quoted 7 lines
drivers/gpu/drm/i915/i915_gem.c +2
-2vma =i915_gem_vma_create (obj, &dev_priv->gtt.base);if (IS_ERR (vma)) { -i915_gem_object_unpin_pages (obj); -return PTR_ERR (vma); + ret =PTR_ERR (vma); + goto err_unpin; }Adding the extra goto here seems pointless to me.
Like explained on irc, that's just to have a nice OCD reverse
err_foo:
label stacking at the end of the function.Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/i915/i915_gem.c +0
-0search_free:@@ -3138,17 +3138,17 @@ search_free:if (ret ==0 ) goto search_free;Quoted 7 lines
drivers/gpu/drm/i915/i915_gem.c search_free: · line 3142
Quoted 3 lines
drivers/gpu/drm/i915/i915_gem.c +1
-1- goto err_out; + goto err_free_vma; }My preference would be to exit early in
drm_mm_remove_node()if the node isn't allocated. I think at least we should add a WARN todrm_mm_remove_nodeif thenode->allocated== 0.Hm, good idea. I'll create a quick patch.
Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/i915/i915_gem.c +2
-2if (WARN_ON (!i915_gem_valid_gtt_space (dev, &vma->node, obj->cache_level))) { ret = -EINVAL ; - goto err_out; + goto err_remove_node; } ret =i915_gem_gtt_prepare_object (obj);if (ret) - goto err_out; + goto err_remove_node;list_move_tail (&obj->global_list, &dev_priv->mm.bound_list);list_add_tail (&obj->mm_list, &vm->inactive_list);@@ -3167,9 +3167,11 @@ search_free:i915_gem_verify_gtt (dev);return 0 ;Quoted 11 lines
drivers/gpu/drm/i915/i915_gem.c search_free: · line 3177
Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c +3
-1-err_out: +err_remove_node:drm_mm_remove_node (&vma->node); +err_free_vma:i915_gem_vma_destroy (vma); +err_unpin:i915_gem_object_unpin_pages (obj);return ret; }Reviewed-by Ben Widawsky <[email protected]>
Quoted 1 line
Queued for -next, thanks for the review.
So I think this bug here warrants a testcase in igt. I've expected gem_tiled_blits/interruptible to hit this, but apparently it does not. So what we want is to fail the drm_mm_insert_node_in_range_generic call (with -ENOSPC) and then again fail the i915_gem_evict_something call with an error. That should be simplest to achieve (and indeed does happen as the bug indicates) when a blocking wait for the gpu to evict a buffer it's still using.
Hence why I've thought that gem_tiled_blits/interruptible should hit this, since it thrashes the gtt (so plenty of -ENOSPC) and has the 2nd thread interrupting us running in parallel (so we should see the occasional -ERESTARTSYS). But apparently the tuning is wrong for this case. I guess cranking up the signal rate (we might need a real interface for that anyway since the current value is the most the wait ioctl test can stomach before failing). Or using much bigger objects to have more gtt contention going on. I'd still only use the first fixed part to do blits, but add a variable part at then end to mix up the gtt drm_mm as much as possible.
Ofc this should be a new subtest so that we don't reduce existing test coverage.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch