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

Commit f285144f authored by Martin Schwidefsky's avatar Martin Schwidefsky Committed by Ingo Molnar
Browse files

sched/x86: Do not clear PREEMPT_NEED_RESCHED on preempt count reset



The per-cpu preempt count of x86 contains two values, the actual preempt
count and the inverted PREEMPT_NEED_RESCHED bit. If a corrupted preempt
count is detected the preempt_count_set() function is used to reset the
preempt count.

In case the inverted PREEMPT_NEED_RESCHED bit is zero at the time of the
reset, the preemption indication is lost. Use raw_cpu_cmpxchg_4() to reset
only the count part and leave the PREEMPT_NEED_RESCHED bit as it is.

This improves the kernel's behavior when it runs into preempt count leaks
and tries to fix them up.

Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1478523660-733-1-git-send-email-schwidefsky@de.ibm.com


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 527b0a76
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -24,7 +24,13 @@ static __always_inline int preempt_count(void)

static __always_inline void preempt_count_set(int pc)
{
	raw_cpu_write_4(__preempt_count, pc);
	int old, new;

	do {
		old = raw_cpu_read_4(__preempt_count);
		new = (old & PREEMPT_NEED_RESCHED) |
			(pc & ~PREEMPT_NEED_RESCHED);
	} while (raw_cpu_cmpxchg_4(__preempt_count, old, new) != old);
}

/*