diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2006-03-27 04:16:30 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-27 11:44:50 -0500 |
commit | e041c683412d5bf44dc2b109053e3b837b71742d (patch) | |
tree | 9d271066ef379da0c0fb3b8cb4137abd5d2ebba0 /drivers/macintosh | |
parent | 76b81e2b0e2241accebcc68e126bc5ab958661b9 (diff) |
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/macintosh')
-rw-r--r-- | drivers/macintosh/adb.c | 11 | ||||
-rw-r--r-- | drivers/macintosh/adbhid.c | 3 | ||||
-rw-r--r-- | drivers/macintosh/via-pmu.c | 2 | ||||
-rw-r--r-- | drivers/macintosh/via-pmu68k.c | 7 | ||||
-rw-r--r-- | drivers/macintosh/windfarm_core.c | 8 |
5 files changed, 18 insertions, 13 deletions
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c index d2ead1776c1..34fcabac5fd 100644 --- a/drivers/macintosh/adb.c +++ b/drivers/macintosh/adb.c | |||
@@ -80,7 +80,7 @@ static struct adb_driver *adb_driver_list[] = { | |||
80 | static struct class *adb_dev_class; | 80 | static struct class *adb_dev_class; |
81 | 81 | ||
82 | struct adb_driver *adb_controller; | 82 | struct adb_driver *adb_controller; |
83 | struct notifier_block *adb_client_list = NULL; | 83 | BLOCKING_NOTIFIER_HEAD(adb_client_list); |
84 | static int adb_got_sleep; | 84 | static int adb_got_sleep; |
85 | static int adb_inited; | 85 | static int adb_inited; |
86 | static pid_t adb_probe_task_pid; | 86 | static pid_t adb_probe_task_pid; |
@@ -354,7 +354,8 @@ adb_notify_sleep(struct pmu_sleep_notifier *self, int when) | |||
354 | /* Stop autopoll */ | 354 | /* Stop autopoll */ |
355 | if (adb_controller->autopoll) | 355 | if (adb_controller->autopoll) |
356 | adb_controller->autopoll(0); | 356 | adb_controller->autopoll(0); |
357 | ret = notifier_call_chain(&adb_client_list, ADB_MSG_POWERDOWN, NULL); | 357 | ret = blocking_notifier_call_chain(&adb_client_list, |
358 | ADB_MSG_POWERDOWN, NULL); | ||
358 | if (ret & NOTIFY_STOP_MASK) { | 359 | if (ret & NOTIFY_STOP_MASK) { |
359 | up(&adb_probe_mutex); | 360 | up(&adb_probe_mutex); |
360 | return PBOOK_SLEEP_REFUSE; | 361 | return PBOOK_SLEEP_REFUSE; |
@@ -391,7 +392,8 @@ do_adb_reset_bus(void) | |||
391 | if (adb_controller->autopoll) | 392 | if (adb_controller->autopoll) |
392 | adb_controller->autopoll(0); | 393 | adb_controller->autopoll(0); |
393 | 394 | ||
394 | nret = notifier_call_chain(&adb_client_list, ADB_MSG_PRE_RESET, NULL); | 395 | nret = blocking_notifier_call_chain(&adb_client_list, |
396 | ADB_MSG_PRE_RESET, NULL); | ||
395 | if (nret & NOTIFY_STOP_MASK) { | 397 | if (nret & NOTIFY_STOP_MASK) { |
396 | if (adb_controller->autopoll) | 398 | if (adb_controller->autopoll) |
397 | adb_controller->autopoll(autopoll_devs); | 399 | adb_controller->autopoll(autopoll_devs); |
@@ -426,7 +428,8 @@ do_adb_reset_bus(void) | |||
426 | } | 428 | } |
427 | up(&adb_handler_sem); | 429 | up(&adb_handler_sem); |
428 | 430 | ||
429 | nret = notifier_call_chain(&adb_client_list, ADB_MSG_POST_RESET, NULL); | 431 | nret = blocking_notifier_call_chain(&adb_client_list, |
432 | ADB_MSG_POST_RESET, NULL); | ||
430 | if (nret & NOTIFY_STOP_MASK) | 433 | if (nret & NOTIFY_STOP_MASK) |
431 | return -EBUSY; | 434 | return -EBUSY; |
432 | 435 | ||
diff --git a/drivers/macintosh/adbhid.c b/drivers/macintosh/adbhid.c index c0b46bceb5d..f5779a73184 100644 --- a/drivers/macintosh/adbhid.c +++ b/drivers/macintosh/adbhid.c | |||
@@ -1214,7 +1214,8 @@ static int __init adbhid_init(void) | |||
1214 | 1214 | ||
1215 | adbhid_probe(); | 1215 | adbhid_probe(); |
1216 | 1216 | ||
1217 | notifier_chain_register(&adb_client_list, &adbhid_adb_notifier); | 1217 | blocking_notifier_chain_register(&adb_client_list, |
1218 | &adbhid_adb_notifier); | ||
1218 | 1219 | ||
1219 | return 0; | 1220 | return 0; |
1220 | } | 1221 | } |
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c index 4f5f3abc9cb..0b5ff553e39 100644 --- a/drivers/macintosh/via-pmu.c +++ b/drivers/macintosh/via-pmu.c | |||
@@ -187,7 +187,7 @@ extern int disable_kernel_backlight; | |||
187 | 187 | ||
188 | int __fake_sleep; | 188 | int __fake_sleep; |
189 | int asleep; | 189 | int asleep; |
190 | struct notifier_block *sleep_notifier_list; | 190 | BLOCKING_NOTIFIER_HEAD(sleep_notifier_list); |
191 | 191 | ||
192 | #ifdef CONFIG_ADB | 192 | #ifdef CONFIG_ADB |
193 | static int adb_dev_map = 0; | 193 | static int adb_dev_map = 0; |
diff --git a/drivers/macintosh/via-pmu68k.c b/drivers/macintosh/via-pmu68k.c index f08e52f2107..35b70323e7e 100644 --- a/drivers/macintosh/via-pmu68k.c +++ b/drivers/macintosh/via-pmu68k.c | |||
@@ -102,7 +102,7 @@ static int pmu_kind = PMU_UNKNOWN; | |||
102 | static int pmu_fully_inited = 0; | 102 | static int pmu_fully_inited = 0; |
103 | 103 | ||
104 | int asleep; | 104 | int asleep; |
105 | struct notifier_block *sleep_notifier_list; | 105 | BLOCKING_NOTIFIER_HEAD(sleep_notifier_list); |
106 | 106 | ||
107 | static int pmu_probe(void); | 107 | static int pmu_probe(void); |
108 | static int pmu_init(void); | 108 | static int pmu_init(void); |
@@ -913,7 +913,8 @@ int powerbook_sleep(void) | |||
913 | struct adb_request sleep_req; | 913 | struct adb_request sleep_req; |
914 | 914 | ||
915 | /* Notify device drivers */ | 915 | /* Notify device drivers */ |
916 | ret = notifier_call_chain(&sleep_notifier_list, PBOOK_SLEEP, NULL); | 916 | ret = blocking_notifier_call_chain(&sleep_notifier_list, |
917 | PBOOK_SLEEP, NULL); | ||
917 | if (ret & NOTIFY_STOP_MASK) | 918 | if (ret & NOTIFY_STOP_MASK) |
918 | return -EBUSY; | 919 | return -EBUSY; |
919 | 920 | ||
@@ -984,7 +985,7 @@ int powerbook_sleep(void) | |||
984 | enable_irq(i); | 985 | enable_irq(i); |
985 | 986 | ||
986 | /* Notify drivers */ | 987 | /* Notify drivers */ |
987 | notifier_call_chain(&sleep_notifier_list, PBOOK_WAKE, NULL); | 988 | blocking_notifier_call_chain(&sleep_notifier_list, PBOOK_WAKE, NULL); |
988 | 989 | ||
989 | /* reenable ADB autopoll */ | 990 | /* reenable ADB autopoll */ |
990 | pmu_adb_autopoll(adb_dev_map); | 991 | pmu_adb_autopoll(adb_dev_map); |
diff --git a/drivers/macintosh/windfarm_core.c b/drivers/macintosh/windfarm_core.c index 6c0ba04bc57..ab3faa702d5 100644 --- a/drivers/macintosh/windfarm_core.c +++ b/drivers/macintosh/windfarm_core.c | |||
@@ -52,7 +52,7 @@ | |||
52 | static LIST_HEAD(wf_controls); | 52 | static LIST_HEAD(wf_controls); |
53 | static LIST_HEAD(wf_sensors); | 53 | static LIST_HEAD(wf_sensors); |
54 | static DEFINE_MUTEX(wf_lock); | 54 | static DEFINE_MUTEX(wf_lock); |
55 | static struct notifier_block *wf_client_list; | 55 | static BLOCKING_NOTIFIER_HEAD(wf_client_list); |
56 | static int wf_client_count; | 56 | static int wf_client_count; |
57 | static unsigned int wf_overtemp; | 57 | static unsigned int wf_overtemp; |
58 | static unsigned int wf_overtemp_counter; | 58 | static unsigned int wf_overtemp_counter; |
@@ -68,7 +68,7 @@ static struct platform_device wf_platform_device = { | |||
68 | 68 | ||
69 | static inline void wf_notify(int event, void *param) | 69 | static inline void wf_notify(int event, void *param) |
70 | { | 70 | { |
71 | notifier_call_chain(&wf_client_list, event, param); | 71 | blocking_notifier_call_chain(&wf_client_list, event, param); |
72 | } | 72 | } |
73 | 73 | ||
74 | int wf_critical_overtemp(void) | 74 | int wf_critical_overtemp(void) |
@@ -398,7 +398,7 @@ int wf_register_client(struct notifier_block *nb) | |||
398 | struct wf_sensor *sr; | 398 | struct wf_sensor *sr; |
399 | 399 | ||
400 | mutex_lock(&wf_lock); | 400 | mutex_lock(&wf_lock); |
401 | rc = notifier_chain_register(&wf_client_list, nb); | 401 | rc = blocking_notifier_chain_register(&wf_client_list, nb); |
402 | if (rc != 0) | 402 | if (rc != 0) |
403 | goto bail; | 403 | goto bail; |
404 | wf_client_count++; | 404 | wf_client_count++; |
@@ -417,7 +417,7 @@ EXPORT_SYMBOL_GPL(wf_register_client); | |||
417 | int wf_unregister_client(struct notifier_block *nb) | 417 | int wf_unregister_client(struct notifier_block *nb) |
418 | { | 418 | { |
419 | mutex_lock(&wf_lock); | 419 | mutex_lock(&wf_lock); |
420 | notifier_chain_unregister(&wf_client_list, nb); | 420 | blocking_notifier_chain_unregister(&wf_client_list, nb); |
421 | wf_client_count++; | 421 | wf_client_count++; |
422 | if (wf_client_count == 0) | 422 | if (wf_client_count == 0) |
423 | wf_stop_thread(); | 423 | wf_stop_thread(); |