sched: Fix cond_resched_lock() in !CONFIG_PREEMPT
authorFrederic Weisbecker <fweisbec@gmail.com>
Fri, 24 Jul 2009 18:05:23 +0000 (20:05 +0200)
committerIngo Molnar <mingo@elte.hu>
Sun, 2 Aug 2009 12:03:57 +0000 (14:03 +0200)
The might_sleep() test inside cond_resched_lock() assumes the
spinlock is held and then preemption is disabled. This is true
with CONFIG_PREEMPT but the preempt_count() doesn't change
otherwise.

Check by starting from the appropriate preempt offset depending
on the config.

Reported-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1248458723-12146-1-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
include/linux/sched.h

index cbbfca69aa4adaee053e29a9ad4f998093fc0769..c472414953bfc9d4133cadd48e19cca234e8be6e 100644 (file)
@@ -2293,8 +2293,14 @@ extern int _cond_resched(void);
 
 extern int __cond_resched_lock(spinlock_t *lock);
 
+#ifdef CONFIG_PREEMPT
+#define PREEMPT_LOCK_OFFSET    PREEMPT_OFFSET
+#else
+#define PREEMPT_LOCK_OFFSET    0
+#endif
+
 #define cond_resched_lock(lock) ({                             \
-       __might_sleep(__FILE__, __LINE__, PREEMPT_OFFSET);      \
+       __might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET); \
        __cond_resched_lock(lock);                              \
 })