Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cd82f37a authored by Chris Wilson's avatar Chris Wilson Committed by Jani Nikula
Browse files

drm/i915/shrinker: Wrap need_resched() inside preempt-disable



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: default avatarJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
Reported-by: default avatarTomi Sarvela <tomi.p.sarvela@intel.com>
Fixes: 290271de ("drm/i915: Spin for struct_mutex inside shrinker")
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: <drm-intel-fixes@lists.freedesktop.org> # v4.13-rc1+
Link: https://patchwork.freedesktop.org/patch/msgid/20170804104135.26805-1-chris@chris-wilson.co.uk


Tested-by: default avatarJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
Reviewed-by: default avatarJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
(cherry picked from commit 6cb0c6ad)
Signed-off-by: default avatarJani Nikula <jani.nikula@intel.com>
parent b5fa57dd
Loading
Loading
Loading
Loading
+8 −3
Original line number Original line Diff line number Diff line
@@ -43,16 +43,21 @@ static bool shrinker_lock(struct drm_i915_private *dev_priv, bool *unlock)
		return true;
		return true;


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


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


	BUG();
	BUG();