Protect the access to driver and timeline name which otherwise could be
freed as dma-fence exported is signalling fences.

This prepares the code for incoming dma-fence API changes which will start
asserting these accesses are done from a RCU locked section.

Now that the safe access is handled in the dma-fence API, the external
callers such as sync_file, and our internal code paths, we can drop the
similar protection from i915_fence_get_timeline_name().

This prepares the code for incoming dma-fence API changes which will start
asserting these accesses are done from a RCU locked section.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursu...@igalia.com>
Reviewed-by: Andi Shyti <andi.sh...@linux.intel.com> # v1
---
v2:
 * Rebased for dma-fence API change.
---
 drivers/gpu/drm/i915/gt/intel_gt_requests.c | 10 ++++++++--
 drivers/gpu/drm/i915/i915_request.c         |  7 +++++--
 drivers/gpu/drm/i915/i915_sw_fence.c        | 10 ++++++++--
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/intel_gt_requests.c 
b/drivers/gpu/drm/i915/gt/intel_gt_requests.c
index ae3557ed6c1e..93298820bee2 100644
--- a/drivers/gpu/drm/i915/gt/intel_gt_requests.c
+++ b/drivers/gpu/drm/i915/gt/intel_gt_requests.c
@@ -250,11 +250,17 @@ void intel_gt_watchdog_work(struct work_struct *work)
        llist_for_each_entry_safe(rq, rn, first, watchdog.link) {
                if (!i915_request_completed(rq)) {
                        struct dma_fence *f = &rq->fence;
+                       const char __rcu *timeline;
+                       const char __rcu *driver;
 
+                       rcu_read_lock();
+                       driver = dma_fence_driver_name(f);
+                       timeline = dma_fence_timeline_name(f);
                        pr_notice("Fence expiration time out 
i915-%s:%s:%llx!\n",
-                                 dma_fence_driver_name(f),
-                                 dma_fence_timeline_name(f),
+                                 rcu_dereference(driver),
+                                 rcu_dereference(timeline),
                                  f->seqno);
+                       rcu_read_unlock();
                        i915_request_cancel(rq, -EINTR);
                }
                i915_request_put(rq);
diff --git a/drivers/gpu/drm/i915/i915_request.c 
b/drivers/gpu/drm/i915/i915_request.c
index 4874c4f1e4ab..b9a2b2194c8f 100644
--- a/drivers/gpu/drm/i915/i915_request.c
+++ b/drivers/gpu/drm/i915/i915_request.c
@@ -2184,7 +2184,7 @@ void i915_request_show(struct drm_printer *m,
                       const char *prefix,
                       int indent)
 {
-       const char *name = dma_fence_timeline_name((struct dma_fence 
*)&rq->fence);
+       const char __rcu *timeline;
        char buf[80] = "";
        int x = 0;
 
@@ -2220,6 +2220,8 @@ void i915_request_show(struct drm_printer *m,
 
        x = print_sched_attr(&rq->sched.attr, buf, x, sizeof(buf));
 
+       rcu_read_lock();
+       timeline = dma_fence_timeline_name((struct dma_fence *)&rq->fence);
        drm_printf(m, "%s%.*s%c %llx:%lld%s%s %s @ %dms: %s\n",
                   prefix, indent, "                ",
                   queue_status(rq),
@@ -2228,7 +2230,8 @@ void i915_request_show(struct drm_printer *m,
                   fence_status(rq),
                   buf,
                   jiffies_to_msecs(jiffies - rq->emitted_jiffies),
-                  name);
+                  rcu_dereference(timeline));
+       rcu_read_unlock();
 }
 
 static bool engine_match_ring(struct intel_engine_cs *engine, struct 
i915_request *rq)
diff --git a/drivers/gpu/drm/i915/i915_sw_fence.c 
b/drivers/gpu/drm/i915/i915_sw_fence.c
index 9edf659d18db..73e89b168fc3 100644
--- a/drivers/gpu/drm/i915/i915_sw_fence.c
+++ b/drivers/gpu/drm/i915/i915_sw_fence.c
@@ -430,16 +430,22 @@ static void timer_i915_sw_fence_wake(struct timer_list *t)
        struct i915_sw_dma_fence_cb_timer *cb = timer_container_of(cb, t,
                                                                   timer);
        struct i915_sw_fence *fence;
+       const char __rcu *timeline;
+       const char __rcu *driver;
 
        fence = xchg(&cb->base.fence, NULL);
        if (!fence)
                return;
 
+       rcu_read_lock();
+       driver = dma_fence_driver_name(cb->dma);
+       timeline = dma_fence_timeline_name(cb->dma);
        pr_notice("Asynchronous wait on fence %s:%s:%llx timed out 
(hint:%ps)\n",
-                 dma_fence_driver_name(cb->dma),
-                 dma_fence_timeline_name(cb->dma),
+                 rcu_dereference(driver),
+                 rcu_dereference(timeline),
                  cb->dma->seqno,
                  i915_sw_fence_debug_hint(fence));
+       rcu_read_unlock();
 
        i915_sw_fence_set_error_once(fence, -ETIMEDOUT);
        i915_sw_fence_complete(fence);
-- 
2.48.0

Reply via email to