linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Register atomic_notifiers in atomic context
@ 2006-02-21 15:54 Alan Stern
  2006-02-21 23:28 ` Andrew Morton
  0 siblings, 1 reply; 26+ messages in thread
From: Alan Stern @ 2006-02-21 15:54 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Chandra Seetharaman, Kernel development list

Some atomic notifier chains require registrations to take place in atomic
context.  An example is the die_notifier, which on some architectures may
be accessed very early during the boot-up procedure, before task-switching
is legal.  To accomodate these chains, this patch (as655) replaces the
mutex in the atomic_notifier_head structure with a spinlock.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>

---

Andrew:

This ought to fix the problem you were seeing with the new notifier chains 
on your emt64 system.

Alan Stern



Index: usb-2.6/kernel/sys.c
===================================================================
--- usb-2.6.orig/kernel/sys.c
+++ usb-2.6/kernel/sys.c
@@ -155,7 +155,6 @@ static int __kprobes notifier_call_chain
  *	@n: New entry in notifier chain
  *
  *	Adds a notifier to an atomic notifier chain.
- *	Must be called in process context.
  *
  *	Currently always returns zero.
  */
@@ -163,11 +162,12 @@ static int __kprobes notifier_call_chain
 int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
 		struct notifier_block *n)
 {
+	unsigned long flags;
 	int ret;
 
-	mutex_lock(&nh->mutex);
+	spin_lock_irqsave(&nh->lock, flags);
 	ret = notifier_chain_register(&nh->head, n);
-	mutex_unlock(&nh->mutex);
+	spin_unlock_irqrestore(&nh->lock, flags);
 	return ret;
 }
 
@@ -179,18 +179,18 @@ EXPORT_SYMBOL(atomic_notifier_chain_regi
  *	@n: Entry to remove from notifier chain
  *
  *	Removes a notifier from an atomic notifier chain.
- *	Must be called from process context.
  *
  *	Returns zero on success or %-ENOENT on failure.
  */
 int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
 		struct notifier_block *n)
 {
+	unsigned long flags;
 	int ret;
 
-	mutex_lock(&nh->mutex);
+	spin_lock_irqsave(&nh->lock, flags);
 	ret = notifier_chain_unregister(&nh->head, n);
-	mutex_unlock(&nh->mutex);
+	spin_unlock_irqrestore(&nh->lock, flags);
 	synchronize_rcu();
 	return ret;
 }
Index: usb-2.6/include/linux/notifier.h
===================================================================
--- usb-2.6.orig/include/linux/notifier.h
+++ usb-2.6/include/linux/notifier.h
@@ -24,9 +24,9 @@
  *		registration, or unregistration.  All locking and protection
  *		must be provided by the caller.
  *
- * atomic_notifier_chain_register() and blocking_notifier_chain_register()
- * may be called only from process context, and likewise for the
- * corresponding _unregister() routines.
+ * atomic_notifier_chain_register() may be called from an atomic context,
+ * but blocking_notifier_chain_register() must be called from a process
+ * context.  Ditto for the corresponding _unregister() routines.
  *
  * atomic_notifier_chain_unregister() and blocking_notifier_chain_unregister()
  * _must not_ be called from within the call chain.
@@ -39,7 +39,7 @@ struct notifier_block {
 };
 
 struct atomic_notifier_head {
-	struct mutex mutex;
+	spinlock_t lock;
 	struct notifier_block *head;
 };
 
@@ -53,7 +53,7 @@ struct raw_notifier_head {
 };
 
 #define ATOMIC_INIT_NOTIFIER_HEAD(name) do {	\
-		mutex_init(&(name)->mutex);	\
+		spin_lock_init(&(name)->lock);	\
 		(name)->head = NULL;		\
 	} while (0)
 #define BLOCKING_INIT_NOTIFIER_HEAD(name) do {	\
@@ -66,7 +66,7 @@ struct raw_notifier_head {
 
 #define ATOMIC_NOTIFIER_HEAD(name)				\
 	struct atomic_notifier_head name = {			\
-		.mutex = __MUTEX_INITIALIZER((name).mutex),	\
+		.lock = SPIN_LOCK_UNLOCKED,			\
 		.head = NULL }
 #define BLOCKING_NOTIFIER_HEAD(name)				\
 	struct blocking_notifier_head name = {			\


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

end of thread, other threads:[~2006-02-24 20:21 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-21 15:54 [PATCH] Register atomic_notifiers in atomic context Alan Stern
2006-02-21 23:28 ` Andrew Morton
2006-02-22 16:08   ` Alan Stern
2006-02-22 16:12     ` Randy.Dunlap
2006-02-23  2:26     ` Andrew Morton
2006-02-23 17:15       ` Alan Stern
2006-02-23 19:03         ` Andrew Morton
2006-02-23 22:28           ` [PATCH] The idle notifier chain should be atomic Alan Stern
2006-02-23 23:49             ` Andi Kleen
2006-02-24  3:24               ` Alan Stern
2006-02-24  3:27                 ` Andi Kleen
2006-02-24  4:04                   ` Alan Stern
2006-02-23 22:36           ` [PATCH] Avoid calling down_read and down_write during startup Alan Stern
2006-02-23 22:37             ` Benjamin LaHaise
2006-02-24  0:16               ` Andrew Morton
2006-02-24  3:18                 ` Alan Stern
2006-02-24 14:40                   ` Benjamin LaHaise
2006-02-24 15:04                     ` Alan Stern
2006-02-24 15:15                       ` Benjamin LaHaise
2006-02-24 16:44                         ` Alan Stern
2006-02-24 16:44                           ` Benjamin LaHaise
2006-02-24 17:59                             ` Alan Stern
2006-02-24 18:37                               ` Benjamin LaHaise
2006-02-24 20:21                                 ` Alan Stern
2006-02-24 14:39                 ` Benjamin LaHaise
2006-02-24 15:03                   ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).