]>
Commit | Line | Data |
---|---|---|
9f934a63 GKH |
1 | From de5e2ddf9bb3ce7b643223b9b0718062254f302f Mon Sep 17 00:00:00 2001 |
2 | From: Eric Dumazet <eric.dumazet@gmail.com> | |
3 | Date: Tue, 26 Oct 2010 14:21:17 -0700 | |
4 | Subject: ipmi: proper spinlock initialization | |
5 | ||
6 | From: Eric Dumazet <eric.dumazet@gmail.com> | |
7 | ||
8 | commit de5e2ddf9bb3ce7b643223b9b0718062254f302f upstream. | |
9 | ||
10 | Unloading ipmi module can trigger following error. (if | |
11 | CONFIG_DEBUG_SPINLOCK=y) | |
12 | ||
13 | [ 9633.779590] BUG: spinlock bad magic on CPU#1, rmmod/7170 | |
14 | [ 9633.779606] lock: f41f5414, .magic: 00000000, .owner: | |
15 | <none>/-1, .owner_cpu: 0 | |
16 | [ 9633.779626] Pid: 7170, comm: rmmod Not tainted | |
17 | 2.6.36-rc7-11474-gb71eb1e-dirty #328 | |
18 | [ 9633.779644] Call Trace: | |
19 | [ 9633.779657] [<c13921cc>] ? printk+0x18/0x1c | |
20 | [ 9633.779672] [<c11a1f33>] spin_bug+0xa3/0xf0 | |
21 | [ 9633.779685] [<c11a1ffd>] do_raw_spin_lock+0x7d/0x160 | |
22 | [ 9633.779702] [<c1131537>] ? release_sysfs_dirent+0x47/0xb0 | |
23 | [ 9633.779718] [<c1131b78>] ? sysfs_addrm_finish+0xa8/0xd0 | |
24 | [ 9633.779734] [<c1394bac>] _raw_spin_lock_irqsave+0xc/0x20 | |
25 | [ 9633.779752] [<f99d93da>] cleanup_one_si+0x6a/0x200 [ipmi_si] | |
26 | [ 9633.779768] [<c11305b2>] ? sysfs_hash_and_remove+0x72/0x80 | |
27 | [ 9633.779786] [<f99dcf26>] ipmi_pnp_remove+0xd/0xf [ipmi_si] | |
28 | [ 9633.779802] [<c11f622b>] pnp_device_remove+0x1b/0x40 | |
29 | ||
30 | Fix this by initializing spinlocks in a smi_info_alloc() helper function, | |
31 | right after memory allocation and clearing. | |
32 | ||
33 | Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> | |
34 | Acked-by: David Miller <davem@davemloft.net> | |
35 | Cc: Yinghai Lu <yinghai@kernel.org> | |
36 | Acked-by: Corey Minyard <cminyard@mvista.com> | |
37 | Signed-off-by: Andrew Morton <akpm@linux-foundation.org> | |
38 | Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> | |
39 | Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> | |
40 | ||
41 | --- | |
42 | drivers/char/ipmi/ipmi_si_intf.c | 30 +++++++++++++++++++----------- | |
43 | 1 file changed, 19 insertions(+), 11 deletions(-) | |
44 | ||
45 | --- a/drivers/char/ipmi/ipmi_si_intf.c | |
46 | +++ b/drivers/char/ipmi/ipmi_si_intf.c | |
47 | @@ -1665,6 +1665,17 @@ static int check_hotmod_int_op(const cha | |
48 | return 0; | |
49 | } | |
50 | ||
51 | +static struct smi_info *smi_info_alloc(void) | |
52 | +{ | |
53 | + struct smi_info *info = kzalloc(sizeof(*info), GFP_KERNEL); | |
54 | + | |
55 | + if (info) { | |
56 | + spin_lock_init(&info->si_lock); | |
57 | + spin_lock_init(&info->msg_lock); | |
58 | + } | |
59 | + return info; | |
60 | +} | |
61 | + | |
62 | static int hotmod_handler(const char *val, struct kernel_param *kp) | |
63 | { | |
64 | char *str = kstrdup(val, GFP_KERNEL); | |
65 | @@ -1779,7 +1790,7 @@ static int hotmod_handler(const char *va | |
66 | } | |
67 | ||
68 | if (op == HM_ADD) { | |
69 | - info = kzalloc(sizeof(*info), GFP_KERNEL); | |
70 | + info = smi_info_alloc(); | |
71 | if (!info) { | |
72 | rv = -ENOMEM; | |
73 | goto out; | |
74 | @@ -1844,7 +1855,7 @@ static __devinit void hardcode_find_bmc( | |
75 | if (!ports[i] && !addrs[i]) | |
76 | continue; | |
77 | ||
78 | - info = kzalloc(sizeof(*info), GFP_KERNEL); | |
79 | + info = smi_info_alloc(); | |
80 | if (!info) | |
81 | return; | |
82 | ||
83 | @@ -2028,7 +2039,7 @@ static __devinit int try_init_spmi(struc | |
84 | return -ENODEV; | |
85 | } | |
86 | ||
87 | - info = kzalloc(sizeof(*info), GFP_KERNEL); | |
88 | + info = smi_info_alloc(); | |
89 | if (!info) { | |
90 | printk(KERN_ERR PFX "Could not allocate SI data (3)\n"); | |
91 | return -ENOMEM; | |
92 | @@ -2138,7 +2149,7 @@ static int __devinit ipmi_pnp_probe(stru | |
93 | if (!acpi_dev) | |
94 | return -ENODEV; | |
95 | ||
96 | - info = kzalloc(sizeof(*info), GFP_KERNEL); | |
97 | + info = smi_info_alloc(); | |
98 | if (!info) | |
99 | return -ENOMEM; | |
100 | ||
101 | @@ -2319,7 +2330,7 @@ static __devinit void try_init_dmi(struc | |
102 | { | |
103 | struct smi_info *info; | |
104 | ||
105 | - info = kzalloc(sizeof(*info), GFP_KERNEL); | |
106 | + info = smi_info_alloc(); | |
107 | if (!info) { | |
108 | printk(KERN_ERR PFX "Could not allocate SI data\n"); | |
109 | return; | |
110 | @@ -2426,7 +2437,7 @@ static int __devinit ipmi_pci_probe(stru | |
111 | int class_type = pdev->class & PCI_ERMC_CLASSCODE_TYPE_MASK; | |
112 | struct smi_info *info; | |
113 | ||
114 | - info = kzalloc(sizeof(*info), GFP_KERNEL); | |
115 | + info = smi_info_alloc(); | |
116 | if (!info) | |
117 | return -ENOMEM; | |
118 | ||
119 | @@ -2567,7 +2578,7 @@ static int __devinit ipmi_of_probe(struc | |
120 | return -EINVAL; | |
121 | } | |
122 | ||
123 | - info = kzalloc(sizeof(*info), GFP_KERNEL); | |
124 | + info = smi_info_alloc(); | |
125 | ||
126 | if (!info) { | |
127 | dev_err(&dev->dev, | |
128 | @@ -3014,7 +3025,7 @@ static __devinit void default_find_bmc(v | |
129 | if (check_legacy_ioport(ipmi_defaults[i].port)) | |
130 | continue; | |
131 | #endif | |
132 | - info = kzalloc(sizeof(*info), GFP_KERNEL); | |
133 | + info = smi_info_alloc(); | |
134 | if (!info) | |
135 | return; | |
136 | ||
137 | @@ -3139,9 +3150,6 @@ static int try_smi_init(struct smi_info | |
138 | goto out_err; | |
139 | } | |
140 | ||
141 | - spin_lock_init(&(new_smi->si_lock)); | |
142 | - spin_lock_init(&(new_smi->msg_lock)); | |
143 | - | |
144 | /* Do low-level detection first. */ | |
145 | if (new_smi->handlers->detect(new_smi->si_sm)) { | |
146 | if (new_smi->addr_source) |