Commit 2d7d2535 authored by Jim Houston's avatar Jim Houston Committed by Linus Torvalds

[PATCH] fix cond_resched() fix

In cond_resched_lock() it calls __resched_legal() before dropping the spin
lock.  __resched_legal() will always finds the preempt_count non-zero and
will prevent the call to __cond_resched().

The attached patch adds a parameter to __resched_legal() with the expected
preempt_count value.

Cc: Ingo Molnar <mingo@elte.hu>
Cc: <stable@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 6ea24f9a
...@@ -4456,9 +4456,9 @@ asmlinkage long sys_sched_yield(void) ...@@ -4456,9 +4456,9 @@ asmlinkage long sys_sched_yield(void)
return 0; return 0;
} }
static inline int __resched_legal(void) static inline int __resched_legal(int expected_preempt_count)
{ {
if (unlikely(preempt_count())) if (unlikely(preempt_count() != expected_preempt_count))
return 0; return 0;
if (unlikely(system_state != SYSTEM_RUNNING)) if (unlikely(system_state != SYSTEM_RUNNING))
return 0; return 0;
...@@ -4484,7 +4484,7 @@ static void __cond_resched(void) ...@@ -4484,7 +4484,7 @@ static void __cond_resched(void)
int __sched cond_resched(void) int __sched cond_resched(void)
{ {
if (need_resched() && __resched_legal()) { if (need_resched() && __resched_legal(0)) {
__cond_resched(); __cond_resched();
return 1; return 1;
} }
...@@ -4510,7 +4510,7 @@ int cond_resched_lock(spinlock_t *lock) ...@@ -4510,7 +4510,7 @@ int cond_resched_lock(spinlock_t *lock)
ret = 1; ret = 1;
spin_lock(lock); spin_lock(lock);
} }
if (need_resched() && __resched_legal()) { if (need_resched() && __resched_legal(1)) {
spin_release(&lock->dep_map, 1, _THIS_IP_); spin_release(&lock->dep_map, 1, _THIS_IP_);
_raw_spin_unlock(lock); _raw_spin_unlock(lock);
preempt_enable_no_resched(); preempt_enable_no_resched();
...@@ -4526,7 +4526,7 @@ int __sched cond_resched_softirq(void) ...@@ -4526,7 +4526,7 @@ int __sched cond_resched_softirq(void)
{ {
BUG_ON(!in_softirq()); BUG_ON(!in_softirq());
if (need_resched() && __resched_legal()) { if (need_resched() && __resched_legal(0)) {
raw_local_irq_disable(); raw_local_irq_disable();
_local_bh_enable(); _local_bh_enable();
raw_local_irq_enable(); raw_local_irq_enable();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment