Skip to content

Commit

Permalink
drm/i915/shrinker: Wrap need_resched() inside preempt-disable
Browse files Browse the repository at this point in the history
In order for us to successfully detect the end of a timeslice,
preemption must be disabled. Otherwise, inside the loop we may be
preempted many times without our noticing, and each time our timeslice
will be reset, invalidating need_resched()

Reported-by: Joonas Lahtinen <[email protected]>
Reported-by: Tomi Sarvela <[email protected]>
Fixes: 290271d ("drm/i915: Spin for struct_mutex inside shrinker")
Signed-off-by: Chris Wilson <[email protected]>
Cc: Mika Kuoppala <[email protected]>
Cc: Joonas Lahtinen <[email protected]>
Cc: <[email protected]> # v4.13-rc1+
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
Tested-by: Joonas Lahtinen <[email protected]>
Reviewed-by: Joonas Lahtinen <[email protected]>
  • Loading branch information
ickle committed Aug 4, 2017
1 parent 28152a2 commit 6cb0c6a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions drivers/gpu/drm/i915/i915_gem_shrinker.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,21 @@ static bool shrinker_lock(struct drm_i915_private *dev_priv, bool *unlock)
return true;

case MUTEX_TRYLOCK_FAILED:
*unlock = false;
preempt_disable();
do {
cpu_relax();
if (mutex_trylock(&dev_priv->drm.struct_mutex)) {
case MUTEX_TRYLOCK_SUCCESS:
*unlock = true;
return true;
break;
}
} while (!need_resched());
preempt_enable();
return *unlock;

return false;
case MUTEX_TRYLOCK_SUCCESS:
*unlock = true;
return true;
}

BUG();
Expand Down

0 comments on commit 6cb0c6a

Please sign in to comment.