mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: Justin Forbes <jmforbes@linuxtx.org>,
	Zwane Mwaikambo <zwane@arm.linux.org.uk>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Randy Dunlap <rdunlap@xenotime.net>,
	Dave Jones <davej@redhat.com>,
	Chuck Wolber <chuckw@quantumlinux.com>,
	Chris Wedgwood <reviews@ml.cw.f00f.org>,
	torvalds@osdl.org, akpm@osdl.org, alan@lxorguk.ukuu.org.uk,
	Ingo Molnar <mingo@elte.hu>, Greg Kroah-Hartman <gregkh@suse.de>
Subject: [patch 18/23] cond_resched() fix
Date: Thu, 3 Aug 2006 22:40:24 -0700	[thread overview]
Message-ID: <20060804054024.GS769@kroah.com> (raw)
In-Reply-To: <20060804053807.GA769@kroah.com>

[-- Attachment #1: cond_resched-fix.patch --]
[-- Type: text/plain, Size: 3212 bytes --]


-stable review patch.  If anyone has any objections, please let us know.

------------------
From: Andrew Morton <akpm@osdl.org>

[PATCH] cond_resched() fix

Fix a bug identified by Zou Nan hai <nanhai.zou@intel.com>:

If the system is in state SYSTEM_BOOTING, and need_resched() is true,
cond_resched() returns true even though it didn't reschedule.  Consequently
need_resched() remains true and JBD locks up.

Fix that by teaching cond_resched() to only return true if it really did call
schedule().

cond_resched_lock() and cond_resched_softirq() have a problem too.  If we're
in SYSTEM_BOOTING state and need_resched() is true, these functions will drop
the lock and will then try to call schedule(), but the SYSTEM_BOOTING state
will prevent schedule() from being called.  So on return, need_resched() will
still be true, but cond_resched_lock() has to return 1 to tell the caller that
the lock was dropped.  The caller will probably lock up.

Bottom line: if these functions dropped the lock, they _must_ call schedule()
to clear need_resched().   Make it so.

Also, uninline __cond_resched().  It's largeish, and slowpath.

Acked-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 kernel/sched.c |   25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

--- linux-2.6.17.7.orig/kernel/sched.c
+++ linux-2.6.17.7/kernel/sched.c
@@ -4044,17 +4044,22 @@ asmlinkage long sys_sched_yield(void)
 	return 0;
 }
 
-static inline void __cond_resched(void)
+static inline int __resched_legal(int expected_preempt_count)
+{
+	if (unlikely(preempt_count() != expected_preempt_count))
+		return 0;
+	if (unlikely(system_state != SYSTEM_RUNNING))
+		return 0;
+	return 1;
+}
+
+static void __cond_resched(void)
 {
 	/*
 	 * The BKS might be reacquired before we have dropped
 	 * PREEMPT_ACTIVE, which could trigger a second
 	 * cond_resched() call.
 	 */
-	if (unlikely(preempt_count()))
-		return;
-	if (unlikely(system_state != SYSTEM_RUNNING))
-		return;
 	do {
 		add_preempt_count(PREEMPT_ACTIVE);
 		schedule();
@@ -4064,13 +4069,12 @@ static inline void __cond_resched(void)
 
 int __sched cond_resched(void)
 {
-	if (need_resched()) {
+	if (need_resched() && __resched_legal(0)) {
 		__cond_resched();
 		return 1;
 	}
 	return 0;
 }
-
 EXPORT_SYMBOL(cond_resched);
 
 /*
@@ -4091,7 +4095,7 @@ int cond_resched_lock(spinlock_t *lock)
 		ret = 1;
 		spin_lock(lock);
 	}
-	if (need_resched()) {
+	if (need_resched() && __resched_legal(1)) {
 		_raw_spin_unlock(lock);
 		preempt_enable_no_resched();
 		__cond_resched();
@@ -4100,14 +4104,13 @@ int cond_resched_lock(spinlock_t *lock)
 	}
 	return ret;
 }
-
 EXPORT_SYMBOL(cond_resched_lock);
 
 int __sched cond_resched_softirq(void)
 {
 	BUG_ON(!in_softirq());
 
-	if (need_resched()) {
+	if (need_resched() && __resched_legal(0)) {
 		__local_bh_enable();
 		__cond_resched();
 		local_bh_disable();
@@ -4115,10 +4118,8 @@ int __sched cond_resched_softirq(void)
 	}
 	return 0;
 }
-
 EXPORT_SYMBOL(cond_resched_softirq);
 
-
 /**
  * yield - yield the current processor to other threads.
  *

--

  parent reply	other threads:[~2006-08-04  5:45 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20060804053258.391158155@quad.kroah.org>
2006-08-04  5:38 ` [patch 00/23] -stable review Greg KH
2006-08-04  5:38   ` [patch 01/23] PCI: fix issues with extended conf space when MMCONFIG disabled because of e820 Greg KH
2006-08-04  5:38   ` [patch 02/23] Dont allow chmod() on the /proc/<pid>/ files Greg KH
2006-08-04  5:38   ` [patch 03/23] : H.323 helper: fix possible NULL-ptr dereference Greg KH
2006-08-04  5:38   ` [patch 04/23] scx200_acb: Fix the state machine Greg KH
2006-08-04  5:38   ` [patch 05/23] scx200_acb: Fix the block transactions Greg KH
2006-08-04  5:38   ` [patch 06/23] i2c: Fix ignore module parameter handling in i2c-core Greg KH
2006-08-04  5:39   ` [patch 07/23] sky2: NAPI bug Greg KH
2006-08-04  5:39   ` [patch 08/23] UHCI: Fix handling of short last packet Greg KH
2006-08-04  5:39   ` [patch 09/23] : Update frag_list in pskb_trim Greg KH
2006-08-04  5:39   ` [patch 10/23] VLAN state handling fix Greg KH
2006-08-04  5:39   ` [patch 11/23] Sparc64 quad-float emulation fix Greg KH
2006-08-04  5:39   ` [patch 12/23] invalidate_bdev() speedup Greg KH
2006-08-04  8:50     ` Christoph Hellwig
2006-08-04  9:04       ` Andrew Morton
2006-08-04 13:08         ` Arjan van de Ven
2006-08-04 13:25           ` Jes Sorensen
2006-08-04 15:18           ` Andrew Morton
2006-08-04  5:39   ` [patch 13/23] ieee1394: sbp2: enable auto spin-up for Maxtor disks Greg KH
2006-08-04  5:39   ` [patch 14/23] Fix race related problem when adding items to and svcrpc auth cache Greg KH
2006-08-04  5:40   ` [patch 15/23] ext3 -nobh option causes oops Greg KH
2006-08-04  5:40   ` [patch 16/23] ext3: avoid triggering ext3_error on bad NFS file handle Greg KH
2006-08-04 14:45     ` Eric Sandeen
2006-08-04 14:52       ` Christoph Hellwig
2006-08-04 15:35         ` Eric Sandeen
2006-08-05  1:28           ` Theodore Tso
2006-08-10  5:38           ` [stable] " Greg KH
2006-08-04  5:40   ` [patch 17/23] e1000: add forgotten PCI ID for supported device Greg KH
2006-08-04  5:40   ` Greg KH [this message]
2006-08-04  5:40   ` [patch 19/23] Fix budget-av compile failure Greg KH
2006-08-04  5:40   ` [patch 20/23] S390: fix futex_atomic_cmpxchg_inatomic Greg KH
2006-08-07  8:39     ` Martin Schwidefsky
2006-08-04  5:40   ` [patch 21/23] tty serialize flush_to_ldisc Greg KH
2006-08-04  5:40   ` [patch 22/23] Add stable branch to maintainers file Greg KH
2006-08-04  5:41   ` [patch 23/23] Have ext2 reject file handles with bad inode numbers early Greg KH
2006-08-04  7:18   ` [patch 00/23] -stable review Grant Coady
2006-08-04  7:20     ` Greg KH
2006-08-04  9:04   ` Jesper Juhl
2006-08-04  9:10     ` Patrick McHardy
2006-08-04  9:19       ` Jesper Juhl
2006-08-04  9:24         ` Patrick McHardy
2006-08-04  9:31           ` Jesper Juhl
2006-08-04  9:19     ` Andrew Morton
2006-08-04  9:22       ` Jesper Juhl
2006-08-04 13:50         ` Auke Kok

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060804054024.GS769@kroah.com \
    --to=gregkh@suse.de \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=chuckw@quantumlinux.com \
    --cc=davej@redhat.com \
    --cc=jmforbes@linuxtx.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rdunlap@xenotime.net \
    --cc=reviews@ml.cw.f00f.org \
    --cc=stable@kernel.org \
    --cc=torvalds@osdl.org \
    --cc=tytso@mit.edu \
    --cc=zwane@arm.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome