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

Commit b654f7de authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar
Browse files

sched: Make sure to not re-read variables after validation



We could re-read rq->rt_avg after we validated it was smaller than
total, invalidating the check and resulting in an unintended negative.

Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Cc: David Rientjes <rientjes@google.com>
Link: http://lkml.kernel.org/r/1337688268.9698.29.camel@twins


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 74a5ce20
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -3503,15 +3503,22 @@ unsigned long __weak arch_scale_smt_power(struct sched_domain *sd, int cpu)
unsigned long scale_rt_power(int cpu)
{
	struct rq *rq = cpu_rq(cpu);
	u64 total, available;
	u64 total, available, age_stamp, avg;

	total = sched_avg_period() + (rq->clock - rq->age_stamp);
	/*
	 * Since we're reading these variables without serialization make sure
	 * we read them once before doing sanity checks on them.
	 */
	age_stamp = ACCESS_ONCE(rq->age_stamp);
	avg = ACCESS_ONCE(rq->rt_avg);

	total = sched_avg_period() + (rq->clock - age_stamp);

	if (unlikely(total < rq->rt_avg)) {
	if (unlikely(total < avg)) {
		/* Ensures that power won't end up being negative */
		available = 0;
	} else {
		available = total - rq->rt_avg;
		available = total - avg;
	}

	if (unlikely((s64)total < SCHED_POWER_SCALE))