UPSTREAM: sched/preempt: Fix preempt_count manipulations
authorPeter Zijlstra <peterz@infradead.org>
Mon, 16 May 2016 13:01:11 +0000 (15:01 +0200)
committerHuang, Tao <huangtao@rock-chips.com>
Tue, 8 Nov 2016 02:21:07 +0000 (10:21 +0800)
commit9b4f68fbb4eb6be48cd1d6453a76a1f96cc7852c
tree2d5d25c8d8479c5bdf4ff269d8377397859108de
parent3b316acdc4924e3fb847bc8b7eb4ae76bf6ddfa7
UPSTREAM: sched/preempt: Fix preempt_count manipulations

Vikram reported that his ARM64 compiler managed to 'optimize' away the
preempt_count manipulations in code like:

preempt_enable_no_resched();
put_user();
preempt_disable();

Irrespective of that fact that that is horrible code that should be
fixed for many reasons, it does highlight a deficiency in the generic
preempt_count manipulators. As it is never right to combine/elide
preempt_count manipulations like this.

Therefore sprinkle some volatile in the two generic accessors to
ensure the compiler is aware of the fact that the preempt_count is
observed outside of the regular program-order view and thus cannot be
optimized away like this.

x86; the only arch not using the generic code is not affected as we
do all this in asm in order to use the segment base per-cpu stuff.

Change-Id: I13da06ddb17c533b8150f008514a4c74723b1742
Reported-by: Vikram Mulukutla <markivx@codeaurora.org>
Tested-by: Vikram Mulukutla <markivx@codeaurora.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: a787870924db ("sched, arch: Create asm/preempt.h")
Link: http://lkml.kernel.org/r/20160516131751.GH3205@twins.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 2e636d5e66c35dfcbaf617aa8fa963f6847478fe)
include/asm-generic/preempt.h