public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Kernel Testers List <kernel-testers@vger.kernel.org>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Vegard Nossum <vegard.nossum@gmail.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Oleg Nesterov <oleg@redhat.com>,
	Dmitry Adamushko <dmitry.adamushko@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [Bug #11989] Suspend failure on NForce4-based boards due to chanes in stop_machine
Date: Tue, 11 Nov 2008 11:52:14 +0100	[thread overview]
Message-ID: <20081111105214.GA15645@elte.hu> (raw)
In-Reply-To: <200811102355.42389.rjw@sisk.pl>


* Rafael J. Wysocki <rjw@sisk.pl> wrote:

> However, it is reproducible by doing
> 
> # echo core > /sys/power/pm_test
> 
> and repeating
> 
> # echo disk > /sys/power/state
> 
> for a couple of times, in which case the last two lines printed to the console
> before a (solid) hang are:
> 
> SMP alternatives: switching to SMP code
> Booting processor 1 APIC 0x1 ip 0x6000
> 
> So, it evidently fails while re-enabling the non-boot CPU and not 
> during disabling it as I thought before.
> 
> With commit c9583e55fa2b08a230c549bd1e3c0bde6c50d9cc reverted the 
> issue is not reproducible any more.

[ Cc:-ed workqueue/locking/suspend-race-condition experts. ]

Seems like the new kernel/stop_machine.c logic has a race for the test 
sequence above. (Below is the bisected commit again, maybe the race is 
visible via email review as well.)

	Ingo

-------------->
>From c9583e55fa2b08a230c549bd1e3c0bde6c50d9cc Mon Sep 17 00:00:00 2001
From: Heiko Carstens <heiko.carstens@de.ibm.com>
Date: Mon, 13 Oct 2008 23:50:10 +0200
Subject: [PATCH] stop_machine: use workqueues instead of kernel threads

Convert stop_machine to a workqueue based approach. Instead of using kernel
threads for stop_machine we now use a an rt workqueue to synchronize all
cpus.
This has the advantage that all needed per cpu threads are already created
when stop_machine gets called. And therefore a call to stop_machine won't
fail anymore. This is needed for s390 which needs a mechanism to synchronize
all cpus without allocating any memory.
As Rusty pointed out free_module() needs a non-failing stop_machine interface
as well.

As a side effect the stop_machine code gets simplified.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 kernel/stop_machine.c |  111 ++++++++++++++++++-------------------------------
 1 files changed, 41 insertions(+), 70 deletions(-)

diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
index af3c7ce..0e688c6 100644
--- a/kernel/stop_machine.c
+++ b/kernel/stop_machine.c
@@ -37,9 +37,13 @@ struct stop_machine_data {
 /* Like num_online_cpus(), but hotplug cpu uses us, so we need this. */
 static unsigned int num_threads;
 static atomic_t thread_ack;
-static struct completion finished;
 static DEFINE_MUTEX(lock);
 
+static struct workqueue_struct *stop_machine_wq;
+static struct stop_machine_data active, idle;
+static const cpumask_t *active_cpus;
+static void *stop_machine_work;
+
 static void set_state(enum stopmachine_state newstate)
 {
 	/* Reset ack counter. */
@@ -51,21 +55,25 @@ static void set_state(enum stopmachine_state newstate)
 /* Last one to ack a state moves to the next state. */
 static void ack_state(void)
 {
-	if (atomic_dec_and_test(&thread_ack)) {
-		/* If we're the last one to ack the EXIT, we're finished. */
-		if (state == STOPMACHINE_EXIT)
-			complete(&finished);
-		else
-			set_state(state + 1);
-	}
+	if (atomic_dec_and_test(&thread_ack))
+		set_state(state + 1);
 }
 
-/* This is the actual thread which stops the CPU.  It exits by itself rather
- * than waiting for kthread_stop(), because it's easier for hotplug CPU. */
-static int stop_cpu(struct stop_machine_data *smdata)
+/* This is the actual function which stops the CPU. It runs
+ * in the context of a dedicated stopmachine workqueue. */
+static void stop_cpu(struct work_struct *unused)
 {
 	enum stopmachine_state curstate = STOPMACHINE_NONE;
-
+	struct stop_machine_data *smdata = &idle;
+	int cpu = smp_processor_id();
+
+	if (!active_cpus) {
+		if (cpu == first_cpu(cpu_online_map))
+			smdata = &active;
+	} else {
+		if (cpu_isset(cpu, *active_cpus))
+			smdata = &active;
+	}
 	/* Simple state machine */
 	do {
 		/* Chill out and ensure we re-read stopmachine_state. */
@@ -90,7 +98,6 @@ static int stop_cpu(struct stop_machine_data *smdata)
 	} while (curstate != STOPMACHINE_EXIT);
 
 	local_irq_enable();
-	do_exit(0);
 }
 
 /* Callback for CPUs which aren't supposed to do anything. */
@@ -101,78 +108,34 @@ static int chill(void *unused)
 
 int __stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus)
 {
-	int i, err;
-	struct stop_machine_data active, idle;
-	struct task_struct **threads;
+	struct work_struct *sm_work;
+	int i;
 
+	/* Set up initial state. */
+	mutex_lock(&lock);
+	num_threads = num_online_cpus();
+	active_cpus = cpus;
 	active.fn = fn;
 	active.data = data;
 	active.fnret = 0;
 	idle.fn = chill;
 	idle.data = NULL;
 
-	/* This could be too big for stack on large machines. */
-	threads = kcalloc(NR_CPUS, sizeof(threads[0]), GFP_KERNEL);
-	if (!threads)
-		return -ENOMEM;
-
-	/* Set up initial state. */
-	mutex_lock(&lock);
-	init_completion(&finished);
-	num_threads = num_online_cpus();
 	set_state(STOPMACHINE_PREPARE);
 
-	for_each_online_cpu(i) {
-		struct stop_machine_data *smdata = &idle;
-		struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
-
-		if (!cpus) {
-			if (i == first_cpu(cpu_online_map))
-				smdata = &active;
-		} else {
-			if (cpu_isset(i, *cpus))
-				smdata = &active;
-		}
-
-		threads[i] = kthread_create((void *)stop_cpu, smdata, "kstop%u",
-					    i);
-		if (IS_ERR(threads[i])) {
-			err = PTR_ERR(threads[i]);
-			threads[i] = NULL;
-			goto kill_threads;
-		}
-
-		/* Place it onto correct cpu. */
-		kthread_bind(threads[i], i);
-
-		/* Make it highest prio. */
-		if (sched_setscheduler_nocheck(threads[i], SCHED_FIFO, &param))
-			BUG();
-	}
-
-	/* We've created all the threads.  Wake them all: hold this CPU so one
+	/* Schedule the stop_cpu work on all cpus: hold this CPU so one
 	 * doesn't hit this CPU until we're ready. */
 	get_cpu();
-	for_each_online_cpu(i)
-		wake_up_process(threads[i]);
-
+	for_each_online_cpu(i) {
+		sm_work = percpu_ptr(stop_machine_work, i);
+		INIT_WORK(sm_work, stop_cpu);
+		queue_work_on(i, stop_machine_wq, sm_work);
+	}
 	/* This will release the thread on our CPU. */
 	put_cpu();
-	wait_for_completion(&finished);
+	flush_workqueue(stop_machine_wq);
 	mutex_unlock(&lock);
-
-	kfree(threads);
-
 	return active.fnret;
-
-kill_threads:
-	for_each_online_cpu(i)
-		if (threads[i])
-			kthread_stop(threads[i]);
-	mutex_unlock(&lock);
-
-	kfree(threads);
-	return err;
 }
 
 int stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus)
@@ -187,3 +150,11 @@ int stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus)
 	return ret;
 }
 EXPORT_SYMBOL_GPL(stop_machine);
+
+static int __init stop_machine_init(void)
+{
+	stop_machine_wq = create_rt_workqueue("kstop");
+	stop_machine_work = alloc_percpu(struct work_struct);
+	return 0;
+}
+early_initcall(stop_machine_init);

  reply	other threads:[~2008-11-11 10:53 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-09 17:53 2.6.28-rc3-git6: Reported regressions from 2.6.27 Rafael J. Wysocki
2008-11-09 17:53 ` [Bug #11799] xorg can not start up with stolen memory Rafael J. Wysocki
2008-11-09 17:54 ` [Bug #11806] iwl3945 fails with microcode error Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11822] ACPI Warning (nspredef-0858): _SB_.PCI0.LPC_.EC__.BAT0._BIF: Return Package type mismatch at index 9 - found Buffer, expected String [20080926] Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11849] default IRQ affinity change in v2.6.27 (breaking several SMP PPC based systems) Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11834] iwl3945: if I leave my machine running overnight, wifi will not work in the morning Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11826] extreme slowness of IO stuff using 2.6.28-rc1 Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11841] plenty of line "ACPI: EC: non-query interrupt received, switching to interrupt mode" in dmesg and system not powering down Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11875] radeonfb lockup in .28-rc (bisected) Rafael J. Wysocki
2008-11-09 21:15   ` Benjamin Herrenschmidt
2008-11-10  5:46   ` Benjamin Herrenschmidt
2008-11-10  7:13     ` Paul Collins
2008-11-10  9:05       ` Benjamin Herrenschmidt
2008-11-10  9:06     ` David Miller
2008-11-10 20:39     ` Andreas Schwab
2008-11-10 21:52       ` Benjamin Herrenschmidt
2008-11-10 23:20         ` Andreas Schwab
2008-11-10 23:34           ` Benjamin Herrenschmidt
2008-11-10 23:54             ` Andreas Schwab
2008-11-11  1:49               ` Benjamin Herrenschmidt
2008-11-11  2:47                 ` Linus Torvalds
2008-11-11  3:21                   ` Benjamin Herrenschmidt
2008-11-11  9:31                 ` Andreas Schwab
2008-11-11 11:30                   ` Benjamin Herrenschmidt
2008-11-21  2:55                   ` Benjamin Herrenschmidt
2008-11-21  3:02                   ` Benjamin Herrenschmidt
2008-11-13 23:11     ` David Miller
2008-11-14  0:54       ` Benjamin Herrenschmidt
2008-11-14  2:50         ` David Miller
2008-11-14  3:04           ` David Miller
2008-11-14  3:29             ` Benjamin Herrenschmidt
2008-11-14  4:28               ` David Miller
2008-11-14  8:51                 ` Benjamin Herrenschmidt
2008-11-09 17:59 ` [Bug #11873] unable to mount ext3 root filesystem due to htree_dirblock_to_tree Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11858] Timeout regression introduced by 242f9dcb8ba6f68fcd217a119a7648a4f69290e9 Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11891] resume from disk broken on hp/compaq nx7000 (DRM problem) Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11898] mke2fs hang on AIC79 device Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11895] 2.6.28-rc2 regression: keyboard dead after reboot on Toshiba Portege 4000 Rafael J. Wysocki
2008-11-10 16:53   ` Andrey Borzenkov
2008-11-10 18:06     ` Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11899] sometime boot failed on T61 laptop Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11896] [2.6.28-rc2] EeePC ACPI errors &amp; exceptions Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11903] regression: vmalloc easily fail Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11905] lots of extra timer interrupts costing 2W Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11906] 2.6.28-rc2 seems to fail at powering down the monitor when it should Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11908] linux-2.6.28-rc2 regression : oprofile doesnt work anymore Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11913] USB/INPUT: slab error in cache_alloc_debugcheck_after(): double free? Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11917] Asus Eee PC hotkeys stop working after prolonged usage Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11911] new PCMCIA device instance after resume - orinoco can't download firmware Rafael J. Wysocki
2008-11-10  3:55   ` Andrey Borzenkov
2008-11-09 17:59 ` [Bug #11928] ath5k gets lost with eeepc-laptop removal Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11937] ext3 __log_wait_for_space: no transactions Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11925] cdrom: missing compat ioctls Rafael J. Wysocki
2008-11-09 23:00   ` Andreas Schwab
2008-11-09 23:29     ` Rafael J. Wysocki
2008-11-09 23:39       ` Andreas Schwab
2008-11-09 17:59 ` [Bug #11942] AMD64 reboot regression Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11958] [2.6.27.x =&gt; 2.6.28-rc3] Xorg crash with xf86MapVidMem error Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11947] 2.6.28-rc VC switching with Intel graphics broken Rafael J. Wysocki
2008-11-11  9:28   ` Romano Giannetti
2008-11-09 17:59 ` [Bug #11965] regression introduced by - timers: fix itimer/many thread hang Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11970] gettimeofday return a old time in mmbench Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11982] Fan level 7 after resume wit 2.6.28-rc3 Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11985] 2.6.28-rc3 truncates nfsd results Rafael J. Wysocki
2008-11-09 21:05   ` J. Bruce Fields
2008-11-09 17:59 ` [Bug #11984] regression when switching TTY-&gt;X, input related? Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11986] 2.6.28-rc2-git1: spitz still won't boot Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11987] Bootup time regression from 2.6.27 to 2.6.28-rc3+ Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11989] Suspend failure on NForce4-based boards due to chanes in stop_machine Rafael J. Wysocki
2008-11-10 12:04   ` Heiko Carstens
2008-11-10 14:47     ` Rafael J. Wysocki
2008-11-10 22:55       ` Rafael J. Wysocki
2008-11-11 10:52         ` Ingo Molnar [this message]
2008-11-11 11:31           ` Heiko Carstens
2008-11-11 12:42             ` Heiko Carstens
2008-11-11 13:13               ` Ingo Molnar
2008-11-11 14:35               ` Paul E. McKenney
2008-11-11 15:01                 ` Heiko Carstens
2008-11-11 16:17                   ` Paul E. McKenney
2008-11-11 15:02                 ` Paul E. McKenney
2008-11-11 16:14                   ` Heiko Carstens
2008-11-11 16:45                     ` Paul E. McKenney
2008-11-11 17:34                       ` Paul E. McKenney
2008-11-12  9:05                         ` Heiko Carstens
2008-11-12 16:03                           ` Paul E. McKenney
2008-11-12 16:51                             ` Heiko Carstens
2008-11-12 19:43                               ` Paul E. McKenney
2008-11-11 17:03                   ` Q: force_quiescent_state && cpu_online_map Oleg Nesterov
2008-11-11 17:25                     ` Paul E. McKenney
2008-11-11 13:36           ` [Bug #11989] Suspend failure on NForce4-based boards due to chanes in stop_machine Vegard Nossum
2008-11-11 13:46             ` Vegard Nossum
2008-11-11 13:49             ` Peter Zijlstra
2008-11-11 14:47           ` Vegard Nossum
2008-11-11 15:11             ` Dmitry Adamushko
2008-11-11 16:31             ` Oleg Nesterov
2008-11-12  3:30               ` Rusty Russell
2008-11-12  3:39           ` Rusty Russell
2008-11-15 13:37             ` Rafael J. Wysocki
2008-11-11 21:28         ` Dmitry Adamushko
2008-11-11 23:43           ` Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11994] Computer doesn't power down after commit CPI: EC: do transaction from interrupt context Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11988] Eliminate recursive mutex in compat fb ioctl path Rafael J. Wysocki
2008-11-14 14:51   ` Geert Uytterhoeven
2008-11-15 11:51     ` Rafael J. Wysocki
2008-11-09 17:59 ` [Bug #11996] Tracing framework regression in 2.6.28-rc3 Rafael J. Wysocki
  -- strict thread matches above, loose matches on Subject: below --
2008-11-16 16:24 2.6.28-rc5: Reported regressions from 2.6.27 Rafael J. Wysocki
2008-11-16 16:35 ` [Bug #11989] Suspend failure on NForce4-based boards due to chanes in stop_machine Rafael J. Wysocki

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=20081111105214.GA15645@elte.hu \
    --to=mingo@elte.hu \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=dmitry.adamushko@gmail.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=kernel-testers@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=rjw@sisk.pl \
    --cc=rusty@rustcorp.com.au \
    --cc=vegard.nossum@gmail.com \
    /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