Skip to content

Commit 7d1c261

Browse files
mlankhorstdanvet
authored andcommitted
drm/i915: Take reservation lock around i915_vma_pin.
We previously complained when ww == NULL. This function is now only used in selftests to pin an object, and ww locking is now fixed. Signed-off-by: Maarten Lankhorst <[email protected]> Reviewed-by: Thomas Hellström <[email protected]> [danvet: Resolve conflict because we don't have a set-domain refactor, see https://lore.kernel.org/intel-gfx/[email protected]/ The really worrying thing here is that the above patch had a change in arguments for i915_gem_object_set_to_gtt_domain(), without any explanation. I decided to just faithfully apply Maarten's change but not the argument change which was in Maarten's context diff.] Signed-off-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 2a66596 commit 7d1c261

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,15 @@ static int gpu_set(struct context *ctx, unsigned long offset, u32 v)
200200
u32 *cs;
201201
int err;
202202

203+
vma = i915_gem_object_ggtt_pin(ctx->obj, NULL, 0, 0, 0);
204+
if (IS_ERR(vma))
205+
return PTR_ERR(vma);
206+
203207
i915_gem_object_lock(ctx->obj, NULL);
204208
err = i915_gem_object_set_to_gtt_domain(ctx->obj, true);
205209
if (err)
206210
goto out_unlock;
207211

208-
vma = i915_gem_object_ggtt_pin(ctx->obj, NULL, 0, 0, 0);
209-
if (IS_ERR(vma)) {
210-
err = PTR_ERR(vma);
211-
goto out_unlock;
212-
}
213-
214212
rq = intel_engine_create_kernel_request(ctx->engine);
215213
if (IS_ERR(rq)) {
216214
err = PTR_ERR(rq);

drivers/gpu/drm/i915/i915_gem.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,11 @@ i915_gem_object_ggtt_pin_ww(struct drm_i915_gem_object *obj,
928928
return ERR_PTR(ret);
929929
}
930930

931-
ret = i915_vma_pin_ww(vma, ww, size, alignment, flags | PIN_GLOBAL);
931+
if (ww)
932+
ret = i915_vma_pin_ww(vma, ww, size, alignment, flags | PIN_GLOBAL);
933+
else
934+
ret = i915_vma_pin(vma, size, alignment, flags | PIN_GLOBAL);
935+
932936
if (ret)
933937
return ERR_PTR(ret);
934938

drivers/gpu/drm/i915/i915_vma.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -863,9 +863,7 @@ int i915_vma_pin_ww(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
863863
int err;
864864

865865
#ifdef CONFIG_PROVE_LOCKING
866-
if (debug_locks && lockdep_is_held(&vma->vm->i915->drm.struct_mutex))
867-
WARN_ON(!ww);
868-
if (debug_locks && ww && vma->resv)
866+
if (debug_locks && !WARN_ON(!ww) && vma->resv)
869867
assert_vma_held(vma);
870868
#endif
871869

drivers/gpu/drm/i915/i915_vma.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,22 @@ i915_vma_pin_ww(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
246246
static inline int __must_check
247247
i915_vma_pin(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
248248
{
249-
#ifdef CONFIG_LOCKDEP
250-
WARN_ON_ONCE(vma->resv && dma_resv_held(vma->resv));
251-
#endif
252-
return i915_vma_pin_ww(vma, NULL, size, alignment, flags);
249+
struct i915_gem_ww_ctx ww;
250+
int err;
251+
252+
i915_gem_ww_ctx_init(&ww, true);
253+
retry:
254+
err = i915_gem_object_lock(vma->obj, &ww);
255+
if (!err)
256+
err = i915_vma_pin_ww(vma, &ww, size, alignment, flags);
257+
if (err == -EDEADLK) {
258+
err = i915_gem_ww_ctx_backoff(&ww);
259+
if (!err)
260+
goto retry;
261+
}
262+
i915_gem_ww_ctx_fini(&ww);
263+
264+
return err;
253265
}
254266

255267
int i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,

0 commit comments

Comments
 (0)