]> git.baikalelectronics.ru Git - kernel.git/commit
spinlocks and preemption points need to be at least compiler barriers
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 9 Apr 2013 17:48:33 +0000 (10:48 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 9 Apr 2013 17:48:33 +0000 (10:48 -0700)
commit18ea032c8c56cb3a2b326bb838dbfc9281cee2c4
tree1323fff10c28d7d802bb57d7e11e11907afe7cc0
parent2e7f1e2552a487bdb57f417efb268980aca1b3be
spinlocks and preemption points need to be at least compiler barriers

In UP and non-preempt respectively, the spinlocks and preemption
disable/enable points are stubbed out entirely, because there is no
regular code that can ever hit the kind of concurrency they are meant to
protect against.

However, while there is no regular code that can cause scheduling, we
_do_ end up having some exceptional (literally!) code that can do so,
and that we need to make sure does not ever get moved into the critical
region by the compiler.

In particular, get_user() and put_user() is generally implemented as
inline asm statements (even if the inline asm may then make a call
instruction to call out-of-line), and can obviously cause a page fault
and IO as a result.  If that inline asm has been scheduled into the
middle of a preemption-safe (or spinlock-protected) code region, we
obviously lose.

Now, admittedly this is *very* unlikely to actually ever happen, and
we've not seen examples of actual bugs related to this.  But partly
exactly because it's so hard to trigger and the resulting bug is so
subtle, we should be extra careful to get this right.

So make sure that even when preemption is disabled, and we don't have to
generate any actual *code* to explicitly tell the system that we are in
a preemption-disabled region, we need to at least tell the compiler not
to move things around the critical region.

This patch grew out of the same discussion that caused commits
c72f4e916a86 ("ARC: Add implicit compiler barrier to raw_local_irq*
functions") and 2e7f1e2552a4 ("tile: comment assumption about
__insn_mtspr for <asm/irqflags.h>") to come about.

Note for stable: use discretion when/if applying this.  As mentioned,
this bug may never have actually bitten anybody, and gcc may never have
done the required code motion for it to possibly ever trigger in
practice.

Cc: stable@vger.kernel.org
Cc: Steven Rostedt <srostedt@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/preempt.h
include/linux/spinlock_up.h