* [PATCH 01/23] drm/i915: Drop vm.ref for duplicate vma on construction
@ 2020-07-02 8:32 Chris Wilson
2020-07-02 12:27 ` [Intel-gfx] " Tvrtko Ursulin
2020-07-02 20:25 ` Andi Shyti
0 siblings, 2 replies; 5+ messages in thread
From: Chris Wilson @ 2020-07-02 8:32 UTC (permalink / raw)
To: intel-gfx; +Cc: Chris Wilson, Tvrtko Ursulin, stable
As we allow for parallel threads to create vma instances in parallel,
and we only filter out the duplicates upon reacquiring the spinlock for
the rbtree, we have to free the loser of the constructors' race. When
freeing, we should also drop any resource references acquired for the
redundant vma.
Fixes: 2850748ef876 ("drm/i915: Pull i915_vma_pin under the vm->mutex")
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: <stable@vger.kernel.org> # v5.5+
---
drivers/gpu/drm/i915/i915_vma.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
index 1f63c4a1f055..7fe1f317cd2b 100644
--- a/drivers/gpu/drm/i915/i915_vma.c
+++ b/drivers/gpu/drm/i915/i915_vma.c
@@ -198,6 +198,7 @@ vma_create(struct drm_i915_gem_object *obj,
cmp = i915_vma_compare(pos, vm, view);
if (cmp == 0) {
spin_unlock(&obj->vma.lock);
+ i915_vm_put(vm);
i915_vma_free(vma);
return pos;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Intel-gfx] [PATCH 01/23] drm/i915: Drop vm.ref for duplicate vma on construction
2020-07-02 8:32 [PATCH 01/23] drm/i915: Drop vm.ref for duplicate vma on construction Chris Wilson
@ 2020-07-02 12:27 ` Tvrtko Ursulin
2020-07-02 20:25 ` Andi Shyti
1 sibling, 0 replies; 5+ messages in thread
From: Tvrtko Ursulin @ 2020-07-02 12:27 UTC (permalink / raw)
To: Chris Wilson, intel-gfx; +Cc: stable
On 02/07/2020 09:32, Chris Wilson wrote:
> As we allow for parallel threads to create vma instances in parallel,
> and we only filter out the duplicates upon reacquiring the spinlock for
> the rbtree, we have to free the loser of the constructors' race. When
> freeing, we should also drop any resource references acquired for the
> redundant vma.
>
> Fixes: 2850748ef876 ("drm/i915: Pull i915_vma_pin under the vm->mutex")
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Cc: <stable@vger.kernel.org> # v5.5+
> ---
> drivers/gpu/drm/i915/i915_vma.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
> index 1f63c4a1f055..7fe1f317cd2b 100644
> --- a/drivers/gpu/drm/i915/i915_vma.c
> +++ b/drivers/gpu/drm/i915/i915_vma.c
> @@ -198,6 +198,7 @@ vma_create(struct drm_i915_gem_object *obj,
> cmp = i915_vma_compare(pos, vm, view);
> if (cmp == 0) {
> spin_unlock(&obj->vma.lock);
> + i915_vm_put(vm);
> i915_vma_free(vma);
> return pos;
> }
>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Regards,
Tvrtko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Intel-gfx] [PATCH 01/23] drm/i915: Drop vm.ref for duplicate vma on construction
2020-07-02 8:32 [PATCH 01/23] drm/i915: Drop vm.ref for duplicate vma on construction Chris Wilson
2020-07-02 12:27 ` [Intel-gfx] " Tvrtko Ursulin
@ 2020-07-02 20:25 ` Andi Shyti
2020-07-02 20:38 ` Chris Wilson
1 sibling, 1 reply; 5+ messages in thread
From: Andi Shyti @ 2020-07-02 20:25 UTC (permalink / raw)
To: Chris Wilson; +Cc: intel-gfx, stable, andi, andi.shyti
Hi Chris,
> diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
> index 1f63c4a1f055..7fe1f317cd2b 100644
> --- a/drivers/gpu/drm/i915/i915_vma.c
> +++ b/drivers/gpu/drm/i915/i915_vma.c
> @@ -198,6 +198,7 @@ vma_create(struct drm_i915_gem_object *obj,
> cmp = i915_vma_compare(pos, vm, view);
> if (cmp == 0) {
> spin_unlock(&obj->vma.lock);
> + i915_vm_put(vm);
> i915_vma_free(vma);
You are forgettin one return without dereferencing it.
would this be a solution:
@@ -106,6 +106,7 @@ vma_create(struct drm_i915_gem_object *obj,
{
struct i915_vma *vma;
struct rb_node *rb, **p;
+ struct i915_vma *pos = ERR_PTR(-E2BIG);
/* The aliasing_ppgtt should never be used directly! */
GEM_BUG_ON(vm == &vm->gt->ggtt->alias->vm);
@@ -185,7 +186,6 @@ vma_create(struct drm_i915_gem_object *obj,
rb = NULL;
p = &obj->vma.tree.rb_node;
while (*p) {
- struct i915_vma *pos;
long cmp;
rb = *p;
@@ -197,12 +197,8 @@ vma_create(struct drm_i915_gem_object *obj,
* and dispose of ours.
*/
cmp = i915_vma_compare(pos, vm, view);
- if (cmp == 0) {
- spin_unlock(&obj->vma.lock);
- i915_vm_put(vm);
- i915_vma_free(vma);
- return pos;
- }
+ if (!cmp)
+ goto err_unlock;
if (cmp < 0)
p = &rb->rb_right;
@@ -230,8 +226,9 @@ vma_create(struct drm_i915_gem_object *obj,
err_unlock:
spin_unlock(&obj->vma.lock);
err_vma:
+ i915_vm_put(vm);
i915_vma_free(vma);
- return ERR_PTR(-E2BIG);
+ return pos;
}
Andi
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Intel-gfx] [PATCH 01/23] drm/i915: Drop vm.ref for duplicate vma on construction
2020-07-02 20:25 ` Andi Shyti
@ 2020-07-02 20:38 ` Chris Wilson
2020-07-02 20:56 ` Andi Shyti
0 siblings, 1 reply; 5+ messages in thread
From: Chris Wilson @ 2020-07-02 20:38 UTC (permalink / raw)
To: Andi Shyti; +Cc: intel-gfx, stable, andi, andi.shyti
Quoting Andi Shyti (2020-07-02 21:25:45)
> Hi Chris,
>
> > diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
> > index 1f63c4a1f055..7fe1f317cd2b 100644
> > --- a/drivers/gpu/drm/i915/i915_vma.c
> > +++ b/drivers/gpu/drm/i915/i915_vma.c
> > @@ -198,6 +198,7 @@ vma_create(struct drm_i915_gem_object *obj,
> > cmp = i915_vma_compare(pos, vm, view);
> > if (cmp == 0) {
> > spin_unlock(&obj->vma.lock);
> > + i915_vm_put(vm);
> > i915_vma_free(vma);
>
> You are forgettin one return without dereferencing it.
>
> would this be a solution:
>
> @@ -106,6 +106,7 @@ vma_create(struct drm_i915_gem_object *obj,
> {
> struct i915_vma *vma;
> struct rb_node *rb, **p;
> + struct i915_vma *pos = ERR_PTR(-E2BIG);
>
> /* The aliasing_ppgtt should never be used directly! */
> GEM_BUG_ON(vm == &vm->gt->ggtt->alias->vm);
> @@ -185,7 +186,6 @@ vma_create(struct drm_i915_gem_object *obj,
> rb = NULL;
> p = &obj->vma.tree.rb_node;
> while (*p) {
> - struct i915_vma *pos;
> long cmp;
>
> rb = *p;
> @@ -197,12 +197,8 @@ vma_create(struct drm_i915_gem_object *obj,
> * and dispose of ours.
> */
> cmp = i915_vma_compare(pos, vm, view);
> - if (cmp == 0) {
> - spin_unlock(&obj->vma.lock);
> - i915_vm_put(vm);
> - i915_vma_free(vma);
> - return pos;
> - }
> + if (!cmp)
> + goto err_unlock;
Yeah, but you might as well do
if (cmp < 0)
p = right;
else if (cmp > 0)
p = left;
else
goto err_unlock;
> if (cmp < 0)
> p = &rb->rb_right;
> @@ -230,8 +226,9 @@ vma_create(struct drm_i915_gem_object *obj,
> err_unlock:
> spin_unlock(&obj->vma.lock);
> err_vma:
> + i915_vm_put(vm);
> i915_vma_free(vma);
> - return ERR_PTR(-E2BIG);
> + return pos;
> }
>
> Andi
Ta, going to send that as a patch?
-Chris
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Intel-gfx] [PATCH 01/23] drm/i915: Drop vm.ref for duplicate vma on construction
2020-07-02 20:38 ` Chris Wilson
@ 2020-07-02 20:56 ` Andi Shyti
0 siblings, 0 replies; 5+ messages in thread
From: Andi Shyti @ 2020-07-02 20:56 UTC (permalink / raw)
To: Chris Wilson; +Cc: Andi Shyti, intel-gfx, stable, andi.shyti
Hi Chris,
> Ta, going to send that as a patch?
mine was a suggestion, it was easier to build the diff than
explain myself :)
If you want I can send it, though.
Andi
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-07-02 21:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-02 8:32 [PATCH 01/23] drm/i915: Drop vm.ref for duplicate vma on construction Chris Wilson
2020-07-02 12:27 ` [Intel-gfx] " Tvrtko Ursulin
2020-07-02 20:25 ` Andi Shyti
2020-07-02 20:38 ` Chris Wilson
2020-07-02 20:56 ` Andi Shyti
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).