diff options
author | Tejun Heo <tj@kernel.org> | 2010-10-26 17:23:05 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-26 19:52:18 -0400 |
commit | e2852ae825dba5ebc159788720baec1a28a57125 (patch) | |
tree | 9d7ed7731505ca02a0f35e8003ebe1cceefe7ecb /lib/percpu_counter.c | |
parent | 066a9be6c0124edc9527088231f03c6236be375d (diff) |
percpu_counter: add debugobj support
All percpu counters are linked to a global list on initialization and
removed from it on destruction. The list is walked during CPU up/down.
If a percpu counter is freed without being properly destroyed, the system
will oops only on the next CPU up/down making it pretty nasty to track
down. This patch adds debugobj support for percpu counters so that such
problems can be found easily.
As percpu counters don't make sense on stack and can't be statically
initialized, debugobj support is pretty simple. It's initialized and
activated on counter initialization, and deactivatd and destroyed on
counter destruction. With this patch applied, the bug fixed by commit
602586a83b719df0fbd94196a1359ed35aeb2df3 (shmem: put_super must
percpu_counter_destroy) triggers the following warning on tmpfs unmount
and the system won't oops on the next cpu up/down operation.
------------[ cut here ]------------
WARNING: at lib/debugobjects.c:259 debug_print_object+0x5c/0x70()
Hardware name: Bochs
ODEBUG: free active (active state 0) object type: percpu_counter
Modules linked in:
Pid: 3999, comm: umount Not tainted 2.6.36-rc2-work+ #5
Call Trace:
[<ffffffff81083f7f>] warn_slowpath_common+0x7f/0xc0
[<ffffffff81084076>] warn_slowpath_fmt+0x46/0x50
[<ffffffff813b45cc>] debug_print_object+0x5c/0x70
[<ffffffff813b50e5>] debug_check_no_obj_freed+0x125/0x210
[<ffffffff811577d3>] kfree+0xb3/0x2f0
[<ffffffff81132edd>] shmem_put_super+0x1d/0x30
[<ffffffff81162e96>] generic_shutdown_super+0x56/0xe0
[<ffffffff81162f86>] kill_anon_super+0x16/0x60
[<ffffffff81162ff7>] kill_litter_super+0x27/0x30
[<ffffffff81163295>] deactivate_locked_super+0x45/0x60
[<ffffffff81163cfa>] deactivate_super+0x4a/0x70
[<ffffffff8117d446>] mntput_no_expire+0x86/0xe0
[<ffffffff8117df7f>] sys_umount+0x6f/0x360
[<ffffffff8103f01b>] system_call_fastpath+0x16/0x1b
---[ end trace cce2a341ba3611a7 ]---
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Thomas Gleixner <tglxlinutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/percpu_counter.c')
-rw-r--r-- | lib/percpu_counter.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c index 209448e1d2b9..1d954ea72331 100644 --- a/lib/percpu_counter.c +++ b/lib/percpu_counter.c | |||
@@ -8,10 +8,53 @@ | |||
8 | #include <linux/init.h> | 8 | #include <linux/init.h> |
9 | #include <linux/cpu.h> | 9 | #include <linux/cpu.h> |
10 | #include <linux/module.h> | 10 | #include <linux/module.h> |
11 | #include <linux/debugobjects.h> | ||
11 | 12 | ||
12 | static LIST_HEAD(percpu_counters); | 13 | static LIST_HEAD(percpu_counters); |
13 | static DEFINE_MUTEX(percpu_counters_lock); | 14 | static DEFINE_MUTEX(percpu_counters_lock); |
14 | 15 | ||
16 | #ifdef CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER | ||
17 | |||
18 | static struct debug_obj_descr percpu_counter_debug_descr; | ||
19 | |||
20 | static int percpu_counter_fixup_free(void *addr, enum debug_obj_state state) | ||
21 | { | ||
22 | struct percpu_counter *fbc = addr; | ||
23 | |||
24 | switch (state) { | ||
25 | case ODEBUG_STATE_ACTIVE: | ||
26 | percpu_counter_destroy(fbc); | ||
27 | debug_object_free(fbc, &percpu_counter_debug_descr); | ||
28 | return 1; | ||
29 | default: | ||
30 | return 0; | ||
31 | } | ||
32 | } | ||
33 | |||
34 | static struct debug_obj_descr percpu_counter_debug_descr = { | ||
35 | .name = "percpu_counter", | ||
36 | .fixup_free = percpu_counter_fixup_free, | ||
37 | }; | ||
38 | |||
39 | static inline void debug_percpu_counter_activate(struct percpu_counter *fbc) | ||
40 | { | ||
41 | debug_object_init(fbc, &percpu_counter_debug_descr); | ||
42 | debug_object_activate(fbc, &percpu_counter_debug_descr); | ||
43 | } | ||
44 | |||
45 | static inline void debug_percpu_counter_deactivate(struct percpu_counter *fbc) | ||
46 | { | ||
47 | debug_object_deactivate(fbc, &percpu_counter_debug_descr); | ||
48 | debug_object_free(fbc, &percpu_counter_debug_descr); | ||
49 | } | ||
50 | |||
51 | #else /* CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER */ | ||
52 | static inline void debug_percpu_counter_activate(struct percpu_counter *fbc) | ||
53 | { } | ||
54 | static inline void debug_percpu_counter_deactivate(struct percpu_counter *fbc) | ||
55 | { } | ||
56 | #endif /* CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER */ | ||
57 | |||
15 | void percpu_counter_set(struct percpu_counter *fbc, s64 amount) | 58 | void percpu_counter_set(struct percpu_counter *fbc, s64 amount) |
16 | { | 59 | { |
17 | int cpu; | 60 | int cpu; |
@@ -75,6 +118,9 @@ int __percpu_counter_init(struct percpu_counter *fbc, s64 amount, | |||
75 | fbc->counters = alloc_percpu(s32); | 118 | fbc->counters = alloc_percpu(s32); |
76 | if (!fbc->counters) | 119 | if (!fbc->counters) |
77 | return -ENOMEM; | 120 | return -ENOMEM; |
121 | |||
122 | debug_percpu_counter_activate(fbc); | ||
123 | |||
78 | #ifdef CONFIG_HOTPLUG_CPU | 124 | #ifdef CONFIG_HOTPLUG_CPU |
79 | INIT_LIST_HEAD(&fbc->list); | 125 | INIT_LIST_HEAD(&fbc->list); |
80 | mutex_lock(&percpu_counters_lock); | 126 | mutex_lock(&percpu_counters_lock); |
@@ -90,6 +136,8 @@ void percpu_counter_destroy(struct percpu_counter *fbc) | |||
90 | if (!fbc->counters) | 136 | if (!fbc->counters) |
91 | return; | 137 | return; |
92 | 138 | ||
139 | debug_percpu_counter_deactivate(fbc); | ||
140 | |||
93 | #ifdef CONFIG_HOTPLUG_CPU | 141 | #ifdef CONFIG_HOTPLUG_CPU |
94 | mutex_lock(&percpu_counters_lock); | 142 | mutex_lock(&percpu_counters_lock); |
95 | list_del(&fbc->list); | 143 | list_del(&fbc->list); |