linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Andrew Morton <akpm@osdl.org>
Cc: Chandra Seetharaman <sekharan@us.ibm.com>,
	Kernel development list <linux-kernel@vger.kernel.org>
Subject: [PATCH] Register atomic_notifiers in atomic context
Date: Tue, 21 Feb 2006 10:54:44 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.44L0.0602211045490.5374-100000@iolanthe.rowland.org> (raw)

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 = {			\


             reply	other threads:[~2006-02-21 15:54 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-21 15:54 Alan Stern [this message]
2006-02-21 23:28 ` [PATCH] Register atomic_notifiers in atomic context 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

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=Pine.LNX.4.44L0.0602211045490.5374-100000@iolanthe.rowland.org \
    --to=stern@rowland.harvard.edu \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sekharan@us.ibm.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;
as well as URLs for NNTP newsgroup(s).