mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-20 05:31:15 +00:00
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 commits79e5f05edc
("ARC: Add implicit compiler barrier to raw_local_irq* functions") and3e2e0d2c22
("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>
This commit is contained in:
parent
3e2e0d2c22
commit
386afc9114
2 changed files with 31 additions and 18 deletions
|
@ -93,14 +93,20 @@ do { \
|
|||
|
||||
#else /* !CONFIG_PREEMPT_COUNT */
|
||||
|
||||
#define preempt_disable() do { } while (0)
|
||||
#define sched_preempt_enable_no_resched() do { } while (0)
|
||||
#define preempt_enable_no_resched() do { } while (0)
|
||||
#define preempt_enable() do { } while (0)
|
||||
/*
|
||||
* Even if we don't have any preemption, we need preempt disable/enable
|
||||
* to be barriers, so that we don't have things like get_user/put_user
|
||||
* that can cause faults and scheduling migrate into our preempt-protected
|
||||
* region.
|
||||
*/
|
||||
#define preempt_disable() barrier()
|
||||
#define sched_preempt_enable_no_resched() barrier()
|
||||
#define preempt_enable_no_resched() barrier()
|
||||
#define preempt_enable() barrier()
|
||||
|
||||
#define preempt_disable_notrace() do { } while (0)
|
||||
#define preempt_enable_no_resched_notrace() do { } while (0)
|
||||
#define preempt_enable_notrace() do { } while (0)
|
||||
#define preempt_disable_notrace() barrier()
|
||||
#define preempt_enable_no_resched_notrace() barrier()
|
||||
#define preempt_enable_notrace() barrier()
|
||||
|
||||
#endif /* CONFIG_PREEMPT_COUNT */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue