locking/mutex: Don't assume TASK_RUNNING
authorPeter Zijlstra <[email protected]>
Wed, 24 Sep 2014 08:18:46 +0000 (10:18 +0200)
committerIngo Molnar <[email protected]>
Tue, 28 Oct 2014 09:55:08 +0000 (10:55 +0100)
We're going to make might_sleep() test for TASK_RUNNING, because
blocking without TASK_RUNNING will destroy the task state by setting
it to TASK_RUNNING.

There are a few occasions where its 'valid' to call blocking
primitives (and mutex_lock in particular) and not have TASK_RUNNING,
typically such cases are right before we set TASK_RUNNING anyhow.

Robustify the code by not assuming this; this has the beneficial side
effect of allowing optional code emission for fixing the above
might_sleep() false positives.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: Oleg Nesterov <[email protected]>
Cc: Linus Torvalds <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
kernel/locking/mutex.c

index dadbf88c22c48cea044aac4e34fda9deec78636a..454195194d4a133f2d600d0d3659b2ee5306b7ad 100644 (file)
@@ -378,8 +378,14 @@ done:
         * reschedule now, before we try-lock the mutex. This avoids getting
         * scheduled out right after we obtained the mutex.
         */
-       if (need_resched())
+       if (need_resched()) {
+               /*
+                * We _should_ have TASK_RUNNING here, but just in case
+                * we do not, make it so, otherwise we might get stuck.
+                */
+               __set_current_state(TASK_RUNNING);
                schedule_preempt_disabled();
+       }
 
        return false;
 }