Commit ba008404 authored by Mark Fasheh's avatar Mark Fasheh Committed by Linus Torvalds

[PATCH] Conditionally check expected_preempt_count in __resched_legal()

Commit 2d7d2535 ("fix cond_resched() fix")
introduced an 'expected_preempt_count' parameter to __resched_legal() to
fix a bug where it was returning a false negative when called from
cond_resched_lock() and preemption was enabled.

Unfortunately this broke things for when preemption is disabled.
preempt_count() will always return zero, thus failing the check against any
value of expected_preempt_count not equal to zero.  cond_resched_lock() for
example, passes an expected_preempt_count value of 1.

So fix the fix for the cond_resched() fix by skipping the check of
preempt_count() against expected_preempt_count when preemption is disabled.

Credit should go to Sunil Mushran for spotting the bug during testing.
Signed-off-by: default avatarMark Fasheh <mark.fasheh@oracle.com>
Acked-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 2aea4fb6
......@@ -4619,8 +4619,10 @@ asmlinkage long sys_sched_yield(void)
static inline int __resched_legal(int expected_preempt_count)
{
#ifdef CONFIG_PREEMPT
if (unlikely(preempt_count() != expected_preempt_count))
return 0;
#endif
if (unlikely(system_state != SYSTEM_RUNNING))
return 0;
return 1;
......
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