All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Conditionally check expected_preempt_count in __resched_legal()
@ 2006-12-13 19:55 Mark Fasheh
  2006-12-13 20:04 ` Ingo Molnar
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Fasheh @ 2006-12-13 19:55 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm, jim.houston, sunil.mushran

Commit 2d7d253548cffdce80f4e03664686e9ccb1b0ed7 ("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: Mark Fasheh <mark.fasheh@oracle.com>
---
 kernel/sched.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/kernel/sched.c b/kernel/sched.c
index 8a0afb9..82b971f 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -4616,8 +4616,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;
-- 
1.4.2.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Conditionally check expected_preempt_count in __resched_legal()
  2006-12-13 19:55 [PATCH] Conditionally check expected_preempt_count in __resched_legal() Mark Fasheh
@ 2006-12-13 20:04 ` Ingo Molnar
  0 siblings, 0 replies; 2+ messages in thread
From: Ingo Molnar @ 2006-12-13 20:04 UTC (permalink / raw)
  To: Mark Fasheh; +Cc: linux-kernel, akpm, jim.houston, sunil.mushran


* Mark Fasheh <mark.fasheh@oracle.com> wrote:

> Commit 2d7d253548cffdce80f4e03664686e9ccb1b0ed7 ("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: Mark Fasheh <mark.fasheh@oracle.com>

well spotted. I'm wondering whether this piece of code has the highest 
amount of fixes per line of code ratio in the whole kernel ...

Acked-by: Ingo Molnar <mingo@elte.hu>

	Ingo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-12-13 20:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-13 19:55 [PATCH] Conditionally check expected_preempt_count in __resched_legal() Mark Fasheh
2006-12-13 20:04 ` Ingo Molnar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.