[PATCH 5/5] remove pin_mutex try1, naively
Maarten Lankhorst
maarten.lankhorst at linux.intel.com
Wed Jun 9 13:23:57 UTC 2021
Signed-off-by: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
---
drivers/gpu/drm/i915/gt/intel_context.c | 49 +++++++++----------------
drivers/gpu/drm/i915/gt/intel_context.h | 13 +++++--
2 files changed, 27 insertions(+), 35 deletions(-)
diff --git a/drivers/gpu/drm/i915/gt/intel_context.c b/drivers/gpu/drm/i915/gt/intel_context.c
index 4033184f13b9..b1ccab2fad2e 100644
--- a/drivers/gpu/drm/i915/gt/intel_context.c
+++ b/drivers/gpu/drm/i915/gt/intel_context.c
@@ -53,24 +53,26 @@ int intel_context_alloc_state(struct intel_context *ce)
{
int err = 0;
- if (mutex_lock_interruptible(&ce->pin_mutex))
- return -EINTR;
-
- if (!test_bit(CONTEXT_ALLOC_BIT, &ce->flags)) {
- if (intel_context_is_banned(ce)) {
- err = -EIO;
- goto unlock;
- }
+ if (test_bit(CONTEXT_ALLOC_BIT, &ce->flags))
+ return 0;
- err = ce->ops->alloc(ce);
- if (unlikely(err))
- goto unlock;
+ err = i915_gem_object_lock_interruptible(ce->timeline->hwsp_ggtt->obj, NULL);
+ if (err)
+ return err;
- set_bit(CONTEXT_ALLOC_BIT, &ce->flags);
+ if (intel_context_is_banned(ce)) {
+ err = -EIO;
+ goto unlock;
}
+ err = ce->ops->alloc(ce);
+ if (unlikely(err))
+ goto unlock;
+
+ set_bit(CONTEXT_ALLOC_BIT, &ce->flags);
+
unlock:
- mutex_unlock(&ce->pin_mutex);
+ i915_gem_object_unlock(ce->timeline->hwsp_ggtt->obj);
return err;
}
@@ -213,12 +215,6 @@ int __intel_context_do_pin_ww(struct intel_context *ce,
return err;
}
- /*
- * We always pin the context/ring/timeline here, to ensure a pin
- * refcount for __intel_context_active(), which prevent a lock
- * inversion of ce->pin_mutex vs dma_resv_lock().
- */
-
err = i915_gem_object_lock(ce->timeline->hwsp_ggtt->obj, ww);
if (!err && ce->ring->vma->obj)
err = i915_gem_object_lock(ce->ring->vma->obj, ww);
@@ -237,24 +233,20 @@ int __intel_context_do_pin_ww(struct intel_context *ce,
if (err)
goto err_release;
- err = mutex_lock_interruptible(&ce->pin_mutex);
- if (err)
- goto err_post_unpin;
-
if (unlikely(intel_context_is_closed(ce))) {
err = -ENOENT;
- goto err_unlock;
+ goto err_post_unpin;
}
if (likely(!atomic_add_unless(&ce->pin_count, 1, 0))) {
err = intel_context_active_acquire(ce);
if (unlikely(err))
- goto err_unlock;
+ goto err_post_unpin;
err = ce->ops->pin(ce, vaddr);
if (err) {
intel_context_active_release(ce);
- goto err_unlock;
+ goto err_post_unpin;
}
CE_TRACE(ce, "pin ring:{start:%08x, head:%04x, tail:%04x}\n",
@@ -268,8 +260,6 @@ int __intel_context_do_pin_ww(struct intel_context *ce,
GEM_BUG_ON(!intel_context_is_pinned(ce)); /* no overflow! */
-err_unlock:
- mutex_unlock(&ce->pin_mutex);
err_post_unpin:
if (!handoff)
ce->ops->post_unpin(ce);
@@ -381,8 +371,6 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)
spin_lock_init(&ce->signal_lock);
INIT_LIST_HEAD(&ce->signals);
- mutex_init(&ce->pin_mutex);
-
i915_active_init(&ce->active,
__intel_context_active, __intel_context_retire, 0);
}
@@ -393,7 +381,6 @@ void intel_context_fini(struct intel_context *ce)
intel_timeline_put(ce->timeline);
i915_vm_put(ce->vm);
- mutex_destroy(&ce->pin_mutex);
i915_active_fini(&ce->active);
}
diff --git a/drivers/gpu/drm/i915/gt/intel_context.h b/drivers/gpu/drm/i915/gt/intel_context.h
index f83a73a2b39f..0de56c50e828 100644
--- a/drivers/gpu/drm/i915/gt/intel_context.h
+++ b/drivers/gpu/drm/i915/gt/intel_context.h
@@ -49,9 +49,14 @@ int intel_context_reconfigure_sseu(struct intel_context *ce,
* intel_context_is_pinned() remains stable.
*/
static inline int intel_context_lock_pinned(struct intel_context *ce)
- __acquires(ce->pin_mutex)
+ __acquires(&ce->state->obj->base.resv->lock)
{
- return mutex_lock_interruptible(&ce->pin_mutex);
+ int ret = intel_context_alloc_state(ce);
+
+ if (ret)
+ return ret;
+
+ return i915_gem_object_lock_interruptible(ce->state->obj, NULL);
}
/**
@@ -76,9 +81,9 @@ intel_context_is_pinned(struct intel_context *ce)
* Releases the lock earlier acquired by intel_context_unlock_pinned().
*/
static inline void intel_context_unlock_pinned(struct intel_context *ce)
- __releases(ce->pin_mutex)
+ __releases(&ce->state->obj->base.resv->lock)
{
- mutex_unlock(&ce->pin_mutex);
+ i915_gem_object_unlock(ce->state->obj);
}
int __intel_context_do_pin(struct intel_context *ce);
--
2.31.0
More information about the Intel-gfx-trybot
mailing list