public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Pavel Machek <pavel@ucw.cz>, Greg KH <greg@kroah.com>,
	Stephen Hemminger <shemminger@osdl.org>,
	Matthew Wilcox <matthew@wil.cx>, Adrian Bunk <bunk@stusta.de>,
	Linus Torvalds <torvalds@osdl.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-pci@atrey.karlin.mff.cuni.cz
Subject: [patch] drivers: wait for threaded probes between initcall levels
Date: Fri, 27 Oct 2006 11:42:37 -0700	[thread overview]
Message-ID: <20061027114237.d577c153.akpm@osdl.org> (raw)
In-Reply-To: <20061027114144.f8a5addc.akpm@osdl.org>

From: Andrew Morton <akpm@osdl.org>

The multithreaded-probing code has a problem: after one initcall level (eg,
core_initcall) has been processed, we will then start processing the next
level (postcore_initcall) while the kernel threads which are handling
core_initcall are still executing.  This breaks the guarantees which the
layered initcalls previously gave us.

IOW, we want to be multithreaded _within_ an initcall level, but not between
different levels.

Fix that up by causing the probing code to wait for all outstanding probes at
one level to complete before we start processing the next level.

Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 drivers/base/dd.c                 |   30 ++++++++++++++++++++++++++++
 include/asm-generic/vmlinux.lds.h |    9 +++++++-
 include/linux/init.h              |   28 +++++++++++++++++---------
 3 files changed, 57 insertions(+), 10 deletions(-)

diff -puN drivers/base/dd.c~drivers-wait-for-threaded-probes-between-initcall-levels drivers/base/dd.c
--- a/drivers/base/dd.c~drivers-wait-for-threaded-probes-between-initcall-levels
+++ a/drivers/base/dd.c
@@ -18,6 +18,7 @@
 #include <linux/device.h>
 #include <linux/module.h>
 #include <linux/kthread.h>
+#include <linux/wait.h>
 
 #include "base.h"
 #include "power/power.h"
@@ -70,6 +71,8 @@ struct stupid_thread_structure {
 };
 
 static atomic_t probe_count = ATOMIC_INIT(0);
+static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue);
+
 static int really_probe(void *void_data)
 {
 	struct stupid_thread_structure *data = void_data;
@@ -121,6 +124,7 @@ probe_failed:
 done:
 	kfree(data);
 	atomic_dec(&probe_count);
+	wake_up(&probe_waitqueue);
 	return ret;
 }
 
@@ -337,6 +341,32 @@ void driver_detach(struct device_driver 
 	}
 }
 
+#ifdef CONFIG_PCI_MULTITHREAD_PROBE
+static int __init wait_for_probes(void)
+{
+	DEFINE_WAIT(wait);
+
+	printk(KERN_INFO "%s: waiting for %d threads\n", __FUNCTION__,
+			atomic_read(&probe_count));
+	if (!atomic_read(&probe_count))
+		return 0;
+	while (atomic_read(&probe_count)) {
+		prepare_to_wait(&probe_waitqueue, &wait, TASK_UNINTERRUPTIBLE);
+		if (atomic_read(&probe_count))
+			schedule();
+	}
+	finish_wait(&probe_waitqueue, &wait);
+	return 0;
+}
+
+core_initcall_sync(wait_for_probes);
+postcore_initcall_sync(wait_for_probes);
+arch_initcall_sync(wait_for_probes);
+subsys_initcall_sync(wait_for_probes);
+fs_initcall_sync(wait_for_probes);
+device_initcall_sync(wait_for_probes);
+late_initcall_sync(wait_for_probes);
+#endif
 
 EXPORT_SYMBOL_GPL(device_bind_driver);
 EXPORT_SYMBOL_GPL(device_release_driver);
diff -puN include/asm-generic/vmlinux.lds.h~drivers-wait-for-threaded-probes-between-initcall-levels include/asm-generic/vmlinux.lds.h
--- a/include/asm-generic/vmlinux.lds.h~drivers-wait-for-threaded-probes-between-initcall-levels
+++ a/include/asm-generic/vmlinux.lds.h
@@ -216,10 +216,17 @@
 
 #define INITCALLS							\
   	*(.initcall1.init)						\
+  	*(.initcall1s.init)						\
   	*(.initcall2.init)						\
+  	*(.initcall2s.init)						\
   	*(.initcall3.init)						\
+  	*(.initcall3s.init)						\
   	*(.initcall4.init)						\
+  	*(.initcall4s.init)						\
   	*(.initcall5.init)						\
+  	*(.initcall5s.init)						\
   	*(.initcall6.init)						\
-  	*(.initcall7.init)
+  	*(.initcall6s.init)						\
+  	*(.initcall7.init)						\
+  	*(.initcall7s.init)
 
diff -puN include/linux/init.h~drivers-wait-for-threaded-probes-between-initcall-levels include/linux/init.h
--- a/include/linux/init.h~drivers-wait-for-threaded-probes-between-initcall-levels
+++ a/include/linux/init.h
@@ -84,19 +84,29 @@ extern void setup_arch(char **);
  * by link order. 
  * For backwards compatibility, initcall() puts the call in 
  * the device init subsection.
+ *
+ * The `id' arg to __define_initcall() is needed so that multiple initcalls
+ * can point at the same handler without causing duplicate-symbol build errors.
  */
 
-#define __define_initcall(level,fn) \
-	static initcall_t __initcall_##fn __attribute_used__ \
+#define __define_initcall(level,fn,id) \
+	static initcall_t __initcall_##fn##id __attribute_used__ \
 	__attribute__((__section__(".initcall" level ".init"))) = fn
 
-#define core_initcall(fn)		__define_initcall("1",fn)
-#define postcore_initcall(fn)		__define_initcall("2",fn)
-#define arch_initcall(fn)		__define_initcall("3",fn)
-#define subsys_initcall(fn)		__define_initcall("4",fn)
-#define fs_initcall(fn)			__define_initcall("5",fn)
-#define device_initcall(fn)		__define_initcall("6",fn)
-#define late_initcall(fn)		__define_initcall("7",fn)
+#define core_initcall(fn)		__define_initcall("1",fn,1)
+#define core_initcall_sync(fn)		__define_initcall("1s",fn,1s)
+#define postcore_initcall(fn)		__define_initcall("2",fn,2)
+#define postcore_initcall_sync(fn)	__define_initcall("2s",fn,2s)
+#define arch_initcall(fn)		__define_initcall("3",fn,3)
+#define arch_initcall_sync(fn)		__define_initcall("3s",fn,3s)
+#define subsys_initcall(fn)		__define_initcall("4",fn,4)
+#define subsys_initcall_sync(fn)	__define_initcall("4s",fn,4s)
+#define fs_initcall(fn)			__define_initcall("5",fn,5)
+#define fs_initcall_sync(fn)		__define_initcall("5s",fn,5s)
+#define device_initcall(fn)		__define_initcall("6",fn,6)
+#define device_initcall_sync(fn)	__define_initcall("6s",fn,6s)
+#define late_initcall(fn)		__define_initcall("7",fn,7)
+#define late_initcall_sync(fn)		__define_initcall("7s",fn,7s)
 
 #define __initcall(fn) device_initcall(fn)
 
_


  reply	other threads:[~2006-10-27 18:47 UTC|newest]

Thread overview: 139+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-23 23:22 Linux 2.6.19-rc3 Linus Torvalds
2006-10-24  2:24 ` Gene Heskett
2006-10-24  7:46 ` Muli Ben-Yehuda
2006-10-24 18:07   ` Badari Pulavarty
2006-10-24 20:21 ` 2.6.19-rc3: known unfixed regressions Adrian Bunk
2006-10-24 21:44   ` 2.6.19-rc3: known unfixed regressions: confirmations teunis
2006-10-26 15:31     ` Adrian Bunk
2006-10-26 15:54       ` teunis
2006-10-25  1:51 ` 2.6.19-rc3: known regressions with patches Adrian Bunk
2006-10-25 11:25 ` Linux 2.6.19-rc3 Jean Delvare
2006-10-25 12:01   ` Damien Wyart
2006-10-25 16:25     ` Auke Kok
2006-10-26  7:20       ` Jean Delvare
2006-10-25 20:13 ` Linux 2.6.19-rc3: !CONFIG_NET_ETHERNET unsets CONFIG_PHYLIB, but CONFIG_USB_USBNET also needs CONFIG_PHYLIB Athanasius
2006-10-25 22:17   ` [PATCH] " Randy Dunlap
2006-10-25 22:27     ` David Brownell
2006-10-25 23:58       ` [PATCH 2/2] usbnet: use MII hooks only if CONFIG_MII is enabled Randy Dunlap
2006-10-26  2:22         ` David Brownell
2006-11-02  7:15           ` Greg KH
2006-11-02 20:29             ` David Brownell
2006-11-03  2:27               ` Adrian Bunk
2006-11-03  2:47                 ` David Brownell
2006-11-03  2:58                   ` Randy.Dunlap
2006-11-04  2:51                   ` [2.6 patch] USB_RTL8150 must select MII Adrian Bunk
2006-10-26 15:46         ` [PATCH 2/2] usbnet: use MII hooks only if CONFIG_MII is enabled Adrian Bunk
2006-10-26 15:51           ` Randy.Dunlap
2006-10-28 11:21         ` Christoph Hellwig
2006-10-28 21:10           ` David Brownell
2006-10-28 21:13             ` Christoph Hellwig
2006-10-28 22:30               ` David Brownell
2006-10-28 21:39             ` Adrian Bunk
2006-10-31 17:40               ` [linux-usb-devel] " David Brownell
2006-10-31 18:07                 ` Adrian Bunk
2006-10-31 19:36                   ` David Brownell
2006-11-01  1:23                     ` Adrian Bunk
2006-11-02 20:19                       ` David Brownell
2006-10-25 23:59       ` [PATCH 1/2] !CONFIG_NET_ETHERNET unsets CONFIG_PHYLIB, but CONFIG_USB_USBNET also needs CONFIG_PHYLIB Randy Dunlap
2006-10-26  2:24         ` David Brownell
2006-10-26  5:05           ` Randy.Dunlap
2006-10-26  5:24             ` David Brownell
2006-10-26 22:45 ` 2.6.19-rc3: known unfixed regressions (v2) Adrian Bunk
2006-10-27  1:02   ` [RFC: 2.6.19 patch] let PCI_MULTITHREAD_PROBE depend on BROKEN Adrian Bunk
2006-10-27  1:20     ` Matthew Wilcox
2006-10-27  1:28       ` Andrew Morton
2006-10-27  2:11         ` Stephen Hemminger
2006-10-27 17:07           ` Greg KH
2006-10-27 17:22             ` Pavel Machek
2006-10-27 18:39               ` Andrew Morton
2006-10-27 18:41                 ` vmlinux.lds: consolidate initcall sections Andrew Morton
2006-10-27 18:42                   ` Andrew Morton [this message]
2006-10-27 18:47                     ` [patch] drivers: wait for threaded probes between initcall levels Stephen Hemminger
2006-10-27 20:15                       ` Andrew Morton
2006-10-27 20:42                         ` Linus Torvalds
2006-10-27 20:48                           ` Linus Torvalds
2006-10-28  1:11                             ` Greg KH
2006-10-28  1:50                               ` Linus Torvalds
2006-10-27 22:59                     ` Alan Cox
2006-10-27 23:06                       ` Andrew Morton
2006-10-28  5:09                         ` Grant Grundler
2006-10-28  5:19                           ` Andrew Morton
2006-10-28  5:32                             ` Andrew Morton
2006-10-28  6:08                             ` Grant Grundler
2006-10-28 20:48                               ` Stefan Richter
2006-10-28 23:34                                 ` Alan Cox
2006-10-29  2:01                                   ` Randy Dunlap
2006-10-30  9:44                         ` Cornelia Huck
2006-10-30 10:48                           ` Alan Cox
2006-10-30 12:29                             ` Matthew Wilcox
2006-10-27 23:12                       ` Olaf Hering
2006-10-27 19:31                   ` vmlinux.lds: consolidate initcall sections Haavard Skinnemoen
2006-10-29 10:21                     ` Geert Uytterhoeven
2006-10-27 19:44                   ` Matthew Wilcox
2006-10-27 20:17                     ` Andrew Morton
2006-10-27 20:27                       ` Matthew Wilcox
2006-10-27 22:23             ` [RFC: 2.6.19 patch] let PCI_MULTITHREAD_PROBE depend on BROKEN Adrian Bunk
2006-10-27 22:38               ` Andrew Morton
2006-10-28  1:08                 ` Greg KH
2006-10-27 23:03               ` Alan Cox
2006-10-27 22:57             ` Alan Cox
2006-10-27  8:27       ` Pavel Machek
2006-10-29 23:13 ` 2.6.19-rc3: known unfixed regressions (v3) Adrian Bunk
2006-10-30 13:56   ` Michael S. Tsirkin
2006-10-30 16:17     ` Jun'ichi Nomura
2006-10-30 16:32       ` Michael S. Tsirkin
2006-10-30 17:20         ` Jun'ichi Nomura
2006-10-30 17:54           ` Michael S. Tsirkin
2006-10-30 16:44       ` Linus Torvalds
2006-10-30 17:34         ` Jun'ichi Nomura
2006-10-30 18:16           ` Linus Torvalds
2006-10-30 18:35             ` Adrian Bunk
2006-10-30 19:00               ` Michael S. Tsirkin
2006-10-30 19:06               ` Hugh Dickins
2006-10-31 12:47               ` Martin Lorenz
2006-10-30 18:58             ` Michael S. Tsirkin
2006-10-31 21:15             ` Michael S. Tsirkin
2006-11-01  3:01     ` 2.6.19-rc <-> ThinkPads Adrian Bunk
2006-11-01  3:15       ` Len Brown
2006-11-01  5:11         ` Ernst Herzberg
2006-11-01  5:26           ` Linus Torvalds
2006-11-01  5:54             ` Michael S. Tsirkin
2006-11-01  6:16               ` Linus Torvalds
2006-11-01 17:25                 ` Andi Kleen
2006-11-01 18:12                   ` Michael S. Tsirkin
2006-11-01 18:25                   ` Linus Torvalds
2006-11-01 19:33                     ` Michael S. Tsirkin
2006-11-01 19:44                       ` Linus Torvalds
2006-11-01 19:34                     ` Andi Kleen
2006-11-01 19:52                       ` Linus Torvalds
2006-11-01 21:15                         ` Andi Kleen
2006-11-01 22:35                 ` Bill Davidsen
2006-11-01  6:18               ` Michael S. Tsirkin
2006-11-01  9:33                 ` Pavel Machek
2006-11-01 12:02                   ` Michael S. Tsirkin
2006-11-01 17:17                 ` Andi Kleen
2006-11-01 13:50             ` Stefan Seyfried
2006-11-01 16:36       ` Hugh Dickins
2006-11-04  3:49       ` 2.6.19-rc <-> ThinkPads, summary Adrian Bunk
2006-11-04 13:51         ` Hugh Dickins
2006-11-04 14:04         ` Russell King
2006-11-05  6:23           ` Adrian Bunk
2006-11-07 20:06             ` Russell King
2006-11-07 20:19               ` Ernst Herzberg
  -- strict thread matches above, loose matches on Subject: below --
2006-10-28  8:23 [patch] drivers: wait for threaded probes between initcall levels Adam J. Richter
2006-10-28  9:22 ` Russell King
2006-10-28 12:10   ` Russell King
2006-10-28 19:41 ` Linus Torvalds
2006-10-28 23:50 Adam J. Richter
2006-10-28 23:55 ` Linus Torvalds
2006-10-30 14:23   ` Kyle Moffett
2006-10-30 14:38     ` Arjan van de Ven
2006-10-30 15:00       ` Xavier Bestel
2006-10-30 15:05         ` Arjan van de Ven
2006-10-30 15:28           ` Xavier Bestel
2006-10-30 18:56       ` Kyle Moffett
2006-10-30 14:42     ` Matthew Wilcox
2006-10-30 18:47       ` Kyle Moffett
2006-10-30 19:13         ` Matthew Wilcox
2006-10-31  5:39           ` Grant Grundler
2006-10-29 20:38 Adam J. Richter

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=20061027114237.d577c153.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=bunk@stusta.de \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@atrey.karlin.mff.cuni.cz \
    --cc=matthew@wil.cx \
    --cc=pavel@ucw.cz \
    --cc=shemminger@osdl.org \
    --cc=torvalds@osdl.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