mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bjorn Helgaas <bjorn.helgaas@hp.com>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@osdl.org>
Subject: [PATCH] fix init_idle() locking problem
Date: Mon, 10 May 2004 10:32:18 -0600	[thread overview]
Message-ID: <200405101032.18508.bjorn.helgaas@hp.com> (raw)

When starting up secondary CPUs, most architectures do something
like this:

	do_boot_cpu(int cpu)
	{
		idle = fork_by_hand();
		wake_up_forked_process(idle);
		init_idle(idle, cpu);

init_idle() removes "idle" from its runqueue, but there's a window
between looking up the runqueue and locking it, where another CPU
can move "idle" to a different runqueue, i.e., via load_balance().

This is based on 2.6.6.

===== kernel/sched.c 1.261 vs edited =====
--- 1.261/kernel/sched.c	Mon Apr 26 23:07:43 2004
+++ edited/kernel/sched.c	Mon May 10 09:59:54 2004
@@ -2660,11 +2660,18 @@
 
 void __init init_idle(task_t *idle, int cpu)
 {
-	runqueue_t *idle_rq = cpu_rq(cpu), *rq = cpu_rq(task_cpu(idle));
+	runqueue_t *idle_rq = cpu_rq(cpu), *rq;
 	unsigned long flags;
 
+repeat_lock_runqueues:
+	rq = task_rq(idle);
 	local_irq_save(flags);
 	double_rq_lock(idle_rq, rq);
+	if (rq != task_rq(idle)) {
+		double_rq_unlock(idle_rq, rq);
+		local_irq_restore(flags);
+		goto repeat_lock_runqueues;
+	}
 
 	idle_rq->curr = idle_rq->idle = idle;
 	deactivate_task(idle, rq);

             reply	other threads:[~2004-05-10 16:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-10 16:32 Bjorn Helgaas [this message]
2004-05-11  9:39 ` Ingo Molnar
2004-05-11 16:13   ` Bjorn Helgaas

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=200405101032.18508.bjorn.helgaas@hp.com \
    --to=bjorn.helgaas@hp.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®