diff options
author | Peter Zijlstra <peterz@infradead.org> | 2016-05-16 09:01:11 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2016-05-17 06:24:21 -0400 |
commit | 2e636d5e66c35dfcbaf617aa8fa963f6847478fe (patch) | |
tree | 5a3d291d3856121b07f32655ddc8552c752c69c3 | |
parent | bc231d9ede99518b67a77544d9084f15b898fe2e (diff) |
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.
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>
-rw-r--r-- | include/asm-generic/preempt.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/include/asm-generic/preempt.h b/include/asm-generic/preempt.h index 5d8ffa3e6f8c..c1cde3577551 100644 --- a/include/asm-generic/preempt.h +++ b/include/asm-generic/preempt.h | |||
@@ -7,10 +7,10 @@ | |||
7 | 7 | ||
8 | static __always_inline int preempt_count(void) | 8 | static __always_inline int preempt_count(void) |
9 | { | 9 | { |
10 | return current_thread_info()->preempt_count; | 10 | return READ_ONCE(current_thread_info()->preempt_count); |
11 | } | 11 | } |
12 | 12 | ||
13 | static __always_inline int *preempt_count_ptr(void) | 13 | static __always_inline volatile int *preempt_count_ptr(void) |
14 | { | 14 | { |
15 | return ¤t_thread_info()->preempt_count; | 15 | return ¤t_thread_info()->preempt_count; |
16 | } | 16 | } |