drm/i915: Check for rq->hwsp validity after acquiring RCU lock
commit 45db630e5f7ec83817c57c8ae387fe219bd42adf upstream.
Since we allow removing the timeline map at runtime, there is a risk
that rq->hwsp points into a stale page. To control that risk, we hold
the RCU read lock while reading *rq->hwsp, but we missed a couple of
important barriers. First, the unpinning / removal of the timeline map
must be after all RCU readers into that map are complete, i.e. after an
rcu barrier (in this case courtesy of call_rcu()). Secondly, we must
make sure that the rq->hwsp we are about to dereference under the RCU
lock is valid. In this case, we make the rq->hwsp pointer safe during
i915_request_retire() and so we know that rq->hwsp may become invalid
only after the request has been signaled. Therefore is the request is
not yet signaled when we acquire rq->hwsp under the RCU, we know that
rq->hwsp will remain valid for the duration of the RCU read lock.
This is a very small window that may lead to either considering the
request not completed (causing a delay until the request is checked
again, any wait for the request is not affected) or dereferencing an
invalid pointer.
Fixes: 3adac4689f
("drm/i915: Introduce concept of per-timeline (context) HWSP")
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: <stable@vger.kernel.org> # v5.1+
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20201218122421.18344-1-chris@chris-wilson.co.uk
(cherry picked from commit 9bb36cf66091ddf2d8840e5aa705ad3c93a6279b)
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210118101755.476744-1-chris@chris-wilson.co.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
bdab6bdaa0
commit
142c6a6040
@@ -434,7 +434,7 @@ static inline u32 hwsp_seqno(const struct i915_request *rq)
|
||||
|
||||
static inline bool __i915_request_has_started(const struct i915_request *rq)
|
||||
{
|
||||
return i915_seqno_passed(hwsp_seqno(rq), rq->fence.seqno - 1);
|
||||
return i915_seqno_passed(__hwsp_seqno(rq), rq->fence.seqno - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -465,11 +465,19 @@ static inline bool __i915_request_has_started(const struct i915_request *rq)
|
||||
*/
|
||||
static inline bool i915_request_started(const struct i915_request *rq)
|
||||
{
|
||||
bool result;
|
||||
|
||||
if (i915_request_signaled(rq))
|
||||
return true;
|
||||
|
||||
/* Remember: started but may have since been preempted! */
|
||||
return __i915_request_has_started(rq);
|
||||
result = true;
|
||||
rcu_read_lock(); /* the HWSP may be freed at runtime */
|
||||
if (likely(!i915_request_signaled(rq)))
|
||||
/* Remember: started but may have since been preempted! */
|
||||
result = __i915_request_has_started(rq);
|
||||
rcu_read_unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -482,10 +490,16 @@ static inline bool i915_request_started(const struct i915_request *rq)
|
||||
*/
|
||||
static inline bool i915_request_is_running(const struct i915_request *rq)
|
||||
{
|
||||
bool result;
|
||||
|
||||
if (!i915_request_is_active(rq))
|
||||
return false;
|
||||
|
||||
return __i915_request_has_started(rq);
|
||||
rcu_read_lock();
|
||||
result = __i915_request_has_started(rq) && i915_request_is_active(rq);
|
||||
rcu_read_unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -509,12 +523,25 @@ static inline bool i915_request_is_ready(const struct i915_request *rq)
|
||||
return !list_empty(&rq->sched.link);
|
||||
}
|
||||
|
||||
static inline bool __i915_request_is_complete(const struct i915_request *rq)
|
||||
{
|
||||
return i915_seqno_passed(__hwsp_seqno(rq), rq->fence.seqno);
|
||||
}
|
||||
|
||||
static inline bool i915_request_completed(const struct i915_request *rq)
|
||||
{
|
||||
bool result;
|
||||
|
||||
if (i915_request_signaled(rq))
|
||||
return true;
|
||||
|
||||
return i915_seqno_passed(hwsp_seqno(rq), rq->fence.seqno);
|
||||
result = true;
|
||||
rcu_read_lock(); /* the HWSP may be freed at runtime */
|
||||
if (likely(!i915_request_signaled(rq)))
|
||||
result = __i915_request_is_complete(rq);
|
||||
rcu_read_unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void i915_request_mark_complete(struct i915_request *rq)
|
||||
|
Reference in New Issue
Block a user