diff options
author | Tony Breeds <tony@bakeyournoodle.com> | 2010-05-19 01:46:36 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-05-19 02:18:44 -0400 |
commit | fd6be105b883244127a734ac9f14ae94a022dcc0 (patch) | |
tree | 9fc86c2827813379274522bdc92dd71538d207e5 | |
parent | 537b60d17894b7c19a6060feae40299d7109d6e7 (diff) |
mutex: Fix optimistic spinning vs. BKL
Currently, we can hit a nasty case with optimistic
spinning on mutexes:
CPU A tries to take a mutex, while holding the BKL
CPU B tried to take the BLK while holding the mutex
This looks like a AB-BA scenario but in practice, is
allowed and happens due to the auto-release on
schedule() nature of the BKL.
In that case, the optimistic spinning code can get us
into a situation where instead of going to sleep, A
will spin waiting for B who is spinning waiting for
A, and the only way out of that loop is the
need_resched() test in mutex_spin_on_owner().
This patch fixes it by completely disabling spinning
if we own the BKL. This adds one more detail to the
extensive list of reasons why it's a bad idea for
kernel code to be holding the BKL.
Signed-off-by: Tony Breeds <tony@bakeyournoodle.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: <stable@kernel.org>
LKML-Reference: <20100519054636.GC12389@ozlabs.org>
[ added an unlikely() attribute to the branch ]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | kernel/mutex.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/kernel/mutex.c b/kernel/mutex.c index 632f04c57d82..4c0b7b3e6d2e 100644 --- a/kernel/mutex.c +++ b/kernel/mutex.c | |||
@@ -172,6 +172,13 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, | |||
172 | struct thread_info *owner; | 172 | struct thread_info *owner; |
173 | 173 | ||
174 | /* | 174 | /* |
175 | * If we own the BKL, then don't spin. The owner of | ||
176 | * the mutex might be waiting on us to release the BKL. | ||
177 | */ | ||
178 | if (unlikely(current->lock_depth >= 0)) | ||
179 | break; | ||
180 | |||
181 | /* | ||
175 | * If there's an owner, wait for it to either | 182 | * If there's an owner, wait for it to either |
176 | * release the lock or go to sleep. | 183 | * release the lock or go to sleep. |
177 | */ | 184 | */ |