debugobject infrastructure V3
Subsystems (11)
cover debugobject infrastructure V3
Changes since V2:
- dropped the VM_USER check
- hash algorithm fixed
- processed Randy's documentation review
- added hrtimers (hrtimers have dynamic users now in the network code)
Thanks,
tglx
PATCH 1/5 slab: add a flag to prevent debug_free checks on a kmem_cache
This is a preperatory patch for the debugobjects infrastructure. The flag prevents debug_free checks on kmem_caches. This is necessary to avoid resursive calls into a debug mechanism which uses a kmem_cache itself.
--- include/linux/slab.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/linux/slab.h +7 -0
@@ -29,6 +29,13 @@#define SLAB_MEM_SPREAD 0x00100000UL/* Spread some memory over cpuset */ #define SLAB_TRACE 0x00200000UL/* Trace allocations and frees */ +/* Flag to prevent checks on free */ +#ifdef CONFIG_DEBUG_OBJECTS +# define SLAB_DEBUG_OBJECTS 0x00400000UL +#else +# define SLAB_DEBUG_OBJECTS 0x00000000UL +#endif +/* The following flags affect the page allocator grouping pages by mobility */ #define SLAB_RECLAIM_ACCOUNT 0x00020000UL/* Objects are reclaimable */ #define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT/* Objects are short-lived */
PATCH 2/5 infrastructure to debug (dynamic) objects
In reply to Thomas GleixnerWe can see an ever repeating problem pattern with objects of any kind in the kernel:
1) freeing of active objects
2) reinitialization of active objects
Both problems can be hard to debug because the crash happens at a point where we have no chance to decode the root cause anymore. One problem spot are kernel timers, where the detection of the problem often happens in interrupt context and usually causes the machine to panic.
While working on a timer related bug report I had to hack specialized code into the timer subsystem to get a reasonable hint for the root cause. This debug hack was fine for temporary use, but far from a mergeable solution due to the intrusiveness into the timer code.
The code further lacked the ability to detect and report the root cause instantly and keep the system operational.
Keeping the system operational is important to get hold of the debug information without special debugging aids like serial consoles and special knowledge of the bug reporter.
The problems described above are not restricted to timers, but timers tend to expose it usually in a full system crash. Other objects are less explosive, but the symptoms caused by such mistakes can be even harder to debug.
Instead of creating specialized debugging code for the timer subsystem a generic infrastructure is created which allows developers to verify their code and provides an easy to enable debug facility for users in case of trouble.
The debugobjects core code keeps track of operations on static and dynamic objects by inserting them into a hashed list and sanity checking them on object operations and provides additional checks whenever kernel memory is freed.
The tracked object operations are:
- initializing an object
- adding an object to a subsystem list
- deleting an object from a subsystem list
Each operation is sanity checked before the operation is executed and the subsystem specific code can provide a fixup function which allows to prevent the damage of the operation. When the sanity check triggers a warning message and a stack trace is printed.
The list of operations can be extended if the need arises. For now it's limited to the requirements of the first user (timers).
The core code enqueues the objects into hash buckets. The hash index is generated from the address of the object to simplify the lookup for the check on kfree/vfree. Each bucket has it's own spinlock to avoid contention on a global lock.
The debug code can be compiled in without being active. The runtime overhead is minimal and could be optimized by asm alternatives. A kernel command line option enables the debugging code.
Thanks to Ingo Molnar for review, suggestions and cleanup patches.
--- Documentation/kernel-parameters.txt | 2 include/linux/debugobjects.h | 90 +++ init/main.c | 3 lib/Kconfig.debug | 23 lib/Makefile | 1 lib/debugobjects.c | 890 ++++++++++++++++++++++++++++++++++++ mm/page_alloc.c | 10 mm/slab.c | 10 mm/slub.c | 3 mm/vmalloc.c | 2 10 files changed, 1030 insertions(+), 4 deletions(-)
Documentation/kernel-parameters.txt +2 -0
@@ -551,6 +551,8 @@ and is between 256 and 4096 characters. 1 will print _a lot_ more information - normally only useful to kernel developers. + debug_objects [KNL] Enable object debugging + decnet.addr= [HW,NET] Format: <area>[,<node>] See also Documentation/networking/decnet.txt.
include/linux/debugobjects.h new file +90 -0
90 lines not on this page · raw message
init/main.c +3 -0
@@ -52,6 +52,7 @@#include <linux/unwind.h> #include <linux/buffer_head.h> #include <linux/debug_locks.h> +#include <linux/debugobjects.h> #include <linux/lockdep.h> #include <linux/pid_namespace.h> #include <linux/device.h>
@@ -517,6 +518,7 @@ asmlinkage void __init start_kernel(void*/ unwind_init ();lockdep_init (); +debug_objects_early_init ();cgroup_init_early ();local_irq_disable ();
@@ -610,6 +612,7 @@ asmlinkage void __init start_kernel(voidenable_debug_pagealloc ();cpu_hotplug_init ();kmem_cache_init (); +debug_objects_mem_init ();setup_per_cpu_pageset ();numa_policy_init ();if (late_time_init)
lib/Kconfig.debug +23 -0
@@ -183,6 +183,29 @@ config TIMER_STATS (it defaults to deactivated on bootup and will only be activated if some application like powertop activates it explicitly). +config DEBUG_OBJECTS + bool "Debug object operations" + depends on DEBUG_KERNEL + help + If you say Y here, additional code will be inserted into the + kernel to track the life time of various objects and validate + the operations on those objects. + +config DEBUG_OBJECTS_SELFTEST + bool "Debug objects selftest" + depends on DEBUG_OBJECTS + help + This enables the selftest of the object debug code. + +config DEBUG_OBJECTS_FREE + bool "Debug objects in freed memory" + depends on DEBUG_OBJECTS + help + This enables checks whether a k/v free operation frees an area + which contains an object which has not been deactivated + properly. This can make kmalloc/kfree-intensive workloads + much slower. + config DEBUG_SLAB bool "Debug slab memory allocations" depends on DEBUG_KERNEL && SLAB
lib/Makefile +1 -0
@@ -36,6 +36,7 @@ obj-$(CONFIG_LOCK_KERNEL) += kernel_lock obj-$(CONFIG_PLIST) += plist.o obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o obj-$(CONFIG_DEBUG_LIST) += list_debug.o +obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o ifneq ($(CONFIG_HAVE_DEC_LOCK),y) lib-y += dec_and_lock.o
lib/debugobjects.c new file +890 -0
890 lines not on this page · raw message
mm/page_alloc.c +8 -2
@@ -45,6 +45,7 @@#include <linux/fault-inject.h> #include <linux/page-isolation.h> #include <linux/memcontrol.h> +#include <linux/debugobjects.h> #include <asm/tlbflush.h> #include <asm/div64.h>
@@ -532,8 +533,11 @@ static void __free_pages_ok(struct pageif (reserved)return ; -if (!PageHighMem (page)) +if (!PageHighMem (page)) {debug_check_no_locks_freed (page_address (page),PAGE_SIZE <<order); +debug_check_no_obj_freed (page_address (page), +PAGE_SIZE << order); + }arch_free_page (page, order);kernel_map_pages (page,1 << order,0 );
@@ -995,8 +999,10 @@ static void free_hot_cold_page(struct paif (free_pages_check (page))return ; -if (!PageHighMem (page)) +if (!PageHighMem (page)) {debug_check_no_locks_freed (page_address (page),PAGE_SIZE ); +debug_check_no_obj_freed (page_address (page),PAGE_SIZE ); + }arch_free_page (page,0 );kernel_map_pages (page,1 ,0 );
mm/slab.c +8 -2
@@ -110,6 +110,7 @@#include <linux/fault-inject.h> #include <linux/rtmutex.h> #include <linux/reciprocal_div.h> +#include <linux/debugobjects.h> #include <asm/cacheflush.h> #include <asm/tlbflush.h>
@@ -178,12 +179,14 @@ SLAB_CACHE_DMA | \ SLAB_STORE_USER | \ SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \ - SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD) + SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \ + SLAB_DEBUG_OBJECTS)#else # define CREATE_MASK (SLAB_HWCACHE_ALIGN | \ SLAB_CACHE_DMA | \ SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \ - SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD) + SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \ + SLAB_DEBUG_OBJECTS)#endif /*
@@ -3764,6 +3767,8 @@ void kmem_cache_free(struct kmem_cache *local_irq_save (flags);debug_check_no_locks_freed (objp,obj_size (cachep)); +if (!(cachep->flags &SLAB_DEBUG_OBJECTS )) +debug_check_no_obj_freed (objp,obj_size (cachep));__cache_free (cachep, objp);local_irq_restore (flags); }
@@ -3789,6 +3794,7 @@ void kfree(const void *objp)kfree_debugcheck (objp); c =virt_to_cache (objp);debug_check_no_locks_freed (objp,obj_size (c)); +debug_check_no_obj_freed (objp,obj_size (c));__cache_free (c, (void *)objp);local_irq_restore (flags); }
mm/slub.c +3 -0
@@ -21,6 +21,7 @@#include <linux/ctype.h> #include <linux/kallsyms.h> #include <linux/memory.h> +#include <linux/debugobjects.h> /* * Lock order:
@@ -1694,6 +1695,8 @@ static __always_inline void slab_free(stlocal_irq_save (flags); c =get_cpu_slab (s,smp_processor_id ());debug_check_no_locks_freed (object, c->objsize); +if (!(s->flags &SLAB_DEBUG_OBJECTS )) +debug_check_no_obj_freed (object, s->objsize);if (likely (page == c->page && c->node >=0 )) { object[c->offset] = c->freelist; c->freelist = object;
mm/vmalloc.c +2 -0
@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/spinlock.h> #include <linux/interrupt.h> +#include <linux/debugobjects.h> #include <linux/vmalloc.h>
@@ -383,6 +384,7 @@ static void __vunmap(const void *addr, i }debug_check_no_locks_freed (addr, area->size); +debug_check_no_obj_freed (addr, area->size);if (deallocate_pages) {int i;
Re: [patch 2/5] infrastructure to debug (dynamic) objects
Quoted 17 lines · On Fri, 21 Mar 2008 20:26:18 -0000 Thomas Gleixner wrote:
Documentation/kernel-parameters.txt | 2 include/linux/debugobjects.h | 90 +++ init/main.c | 3 lib/Kconfig.debug | 23 lib/Makefile | 1 lib/debugobjects.c | 890 ++++++++++++++++++++++++++++++++++++ mm/page_alloc.c | 10 mm/slab.c | 10 mm/slub.c | 3 mm/vmalloc.c | 2 10 files changed, 1030 insertions(+), 4 deletions(-)Index: linux-2.6/lib/Kconfig.debug
===================================================================
lib/Kconfig.debug config TIMER_STATS · line 191
Quoted 9 lines
lib/Kconfig.debug +6
-0@@ -183,6 +183,29 @@ config TIMER_STATS (it defaults to deactivated on bootup and will only be activated if some application like powertop activates it explicitly). +config DEBUG_OBJECTS + bool "Debug object operations" + depends on DEBUG_KERNEL + help + If you say Y here, additional code will be inserted into the + kernel to track the life time of various objects and validate
lifetime
lib/Kconfig.debug config TIMER_STATS · line 204
Quoted 13 lines
lib/Kconfig.debug +13
-0+ the operations on those objects. + +config DEBUG_OBJECTS_SELFTEST + bool "Debug objects selftest" + depends on DEBUG_OBJECTS + help + This enables the selftest of the object debug code. + +config DEBUG_OBJECTS_FREE + bool "Debug objects in freed memory" + depends on DEBUG_OBJECTS + help + This enables checks whether a k/v free operation frees an area
Please say "kfree/vfree" so that we (I, others) don't have to think "what the heck is a k/v free operation?".
Quoted 13 lines
lib/Kconfig.debug +4
-0+ which contains an object which has not been deactivated + properly. This can make kmalloc/kfree-intensive workloads + much slower. + config DEBUG_SLAB bool "Debug slab memory allocations" depends on DEBUG_KERNEL && SLABIndex:
linux-2.6/lib/debugobjects.c
===================================================================lib/debugobjects.c new file +0
-0@@ -0,0 +1,890 @@
...
Quoted 2 lines
+/*
+ * We run out of memory. That means we probably have tons of objects
ran
Quoted 15 lines
+ * allocated.
+ */lib/debugobjects.c new file +13
-0+static void debug_objects_oom (void ) +{ +struct debug_bucket *db = obj_hash; +struct hlist_node *node, *tmp; +struct debug_obj *obj; +unsigned long flags; +int i; + +printk (KERN_WARNING "ODEBUG: Out of memory. ODEBUG disabled\n" ); + +for (i =0 ; i <ODEBUG_HASH_SIZE ; i++, db++) { +spin_lock_irqsave (&db->lock, flags); +hlist_for_each_entry_safe (obj, node, tmp, &db->list, node) {
lib/debugobjects.c
Quoted 10 lines
lib/debugobjects.c new file +9
-0+hlist_del (&obj->node); +free_object (obj); + } +spin_unlock_irqrestore (&db->lock, flags); + } +} +/** +* debug_object_init_on_stack - debug checks when an object on stack is +* initialized
Unfortunately the first line of kernel-doc notation ("short description") is limited to one line. Even if it exceeds 80 columns. :(
lib/debugobjects.c line 329
Quoted 10 lines
+ * @addr: address of the object
+ * @descr: pointer to an object specific debug description structure
+ */lib/debugobjects.c new file +7
-0+void debug_object_init_on_stack (void *addr,struct debug_obj_descr *descr) +{ +if (!debug_objects_enabled) +return ; + +__debug_object_init (addr, descr,1 ); +}
---
~Randy
Re: [patch 2/5] infrastructure to debug (dynamic) objects
Quoted 4 lines · Randy Dunlap
lib/Kconfig.debug config TIMER_STATS · line 191
Quoted 2 lines
lib/Kconfig.debug +2
-0+ If you say Y here, additional code will be inserted into the + kernel to track the life time of various objects and validatelifetime
Fixed.
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ help + This enables checks whether a k/v free operation frees an areaPlease say "kfree/vfree" so that we (I, others) don't have to think "what the heck is a k/v free operation?".
Ooops. Missed that one. Fixed it in the docs already.
Quoted 4 lines
Quoted 2 lines
+/*
+ * We run out of memory. That means we probably have tons of objectsran
Sigh. This is one of the words which hunt me since school.
Quoted 6 lines
Quoted 3 lines
+/**
+ *debug_object_init_on_stack- debug checks when an object on stack is
+ * initializedUnfortunately the first line of kernel-doc notation ("short description") is limited to one line. Even if it exceeds 80 columns. :(
Fixed
Thanks,
tglx
Andrew Morton
maintainerRe: [patch 2/5] infrastructure to debug (dynamic) objects
In reply to Thomas GleixnerQuoted 4 lines · On Fri, 21 Mar 2008 20:26:18 -0000 Thomas Gleixner <[email protected]> wrote:
The debugobjects core code keeps track of operations on static and dynamic objects by inserting them into a hashed list and sanity checking them on object operations and provides additional checks whenever kernel memory is freed.
Prime candidates for conversion to this interface are locks: spinlocks, rwlocks, mutexes, etc.
a) it'd be interesting to get that done, as a proof-of-usefulness thing.
b) but this code internally uses spinlocks. Will it explode?
also list_heads and hlists. But
a) that might be a bit redundant against the custome debugging which lists already have and
b) this code uses lists and hlists internally?
Re: [patch 2/5] infrastructure to debug (dynamic) objects
Quoted 8 lines · Andrew Morton
Quoted 4 lines · On Fri, 21 Mar 2008 20:26:18 -0000 Thomas Gleixner <[email protected]> wrote:
The debugobjects core code keeps track of operations on static and dynamic objects by inserting them into a hashed list and sanity checking them on object operations and provides additional checks whenever kernel memory is freed.
Quoted 4 lines
Prime candidates for conversion to this interface are locks: spinlocks, rwlocks, mutexes, etc.
a) it'd be interesting to get that done, as a proof-of-usefulness thing.
/me looks for volunteers :)
Quoted 1 line
b) but this code internally uses spinlocks. Will it explode?
It should not, but we can use untracked spinlocks for the internals.
Quoted 4 lines
also
list_headsand hlists. Buta) that might be a bit redundant against the custome debugging which lists already have and
Yup.
Quoted 1 line
b) this code uses lists and hlists internally?
Yes, it uses hlists.
Thanks,
tglx
Re: [patch 2/5] infrastructure to debug (dynamic) objects
Quoted 9 lines · Thomas Gleixner
Quoted 8 lines · Andrew Morton
Quoted 4 lines · On Fri, 21 Mar 2008 20:26:18 -0000 Thomas Gleixner <[email protected]> wrote:
The debugobjects core code keeps track of operations on static and dynamic objects by inserting them into a hashed list and sanity checking them on object operations and provides additional checks whenever kernel memory is freed.
Quoted 6 lines
Quoted 4 lines
Prime candidates for conversion to this interface are locks: spinlocks, rwlocks, mutexes, etc.
a) it'd be interesting to get that done, as a proof-of-usefulness thing.
/me looks for volunteers :)
I had a look into that and it's not a friday afternoon project as it needs some major distangling of lockdep, which seems to be on Peter's todo list for quite a while.
vs. the proof-of-usefulness I just want to point out that having an infrastructure which allows us to retrieve valuable debug information with an exact pointer to the offending code from a live system is useful by definition and it has proven it already in several cases.
I was able to fix two of those problems (use after free) myself, but I'm unable to get this one resolved w/o twisting my brain:
http://bugzilla.kernel.org/show_bug.cgi?id=10068
But .... having such precise info:
ODEBUG: init active object: db112e94 timer_list
WARNING: at lib/debugobjects.c:63 debug_print_object() Pid: 2023, comm: softmac Not tainted 2.6.24.2 #10 [<c01c5181>] debug_object_op+0x89/0xe0 [<c0120168>] init_timer+0x18/0x40 [<e098f813>] ieee80211softmac_auth_req+0x6b/0x9c [ieee80211softmac] [<e0991543>] ieee80211softmac_assoc_work+0x292/0x392 [ieee80211softmac] [<e0991643>] ieee80211softmac_assoc_notify_scan+0x0/0x10 [ieee80211softmac] [<e0991ab6>] ieee80211softmac_notify_callback+0x40/0x48 [ieee80211softmac] [<e0991a76>] ieee80211softmac_notify_callback+0x0/0x48 [ieee80211softmac] [<e0991978>] ieee80211softmac_call_events_locked+0xdc/0xee [ieee80211softmac] [<e0991643>] ieee80211softmac_assoc_notify_scan+0x0/0x10 [ieee80211softmac] [<e0991a76>] ieee80211softmac_notify_callback+0x0/0x48 [ieee80211softmac] [<c01250bf>] run_workqueue+0x6b/0xdf [<c0335f0f>] schedule+0x1f0/0x20a [<c01256b2>] worker_thread+0x0/0xc2 [<c0125766>] worker_thread+0xb4/0xc2 [<c0127baa>] autoremove_wake_function+0x0/0x33 [<c01256b2>] worker_thread+0x0/0xc2 [<c0127a4a>] kthread+0x36/0x5c [<c0127a14>] kthread+0x0/0x5c [<c0104757>] kernel_thread_helper+0x7/0x10
instead of:
kernel BUG at kernel/timer.c: 607!
Invalid opcode: 0000 [#1]
Modules linked in: cpufreq_stats nls_cp437 sbp2 scsi_mod loop zd1211rw
ieee80211softmac parport_pc parport ohci1394 snd_intel8x0 ieee1394 sis900 ehci_hcd ide_cd cdrom fan asus_acpi backlight battery ac
Pid 3239, comm: firefox-bin Not tainted (2.6.24.2 #1) EIP:0060 :[<c011e54b>] EFLAGS:00210007 CPU:0 EIP is at cascade+0x3b/0x57
EAX:0 EBX:0 ECX:5 EDX:d9eb3ca4
ESI:5 EDI:c0485640 EBP:d9ecdf30 ESP:d9ecdf30 DS:007b ES:007b FS:0000 GS:0033 SS:0068
...
Call trace
[<c011e6ad>] run_timer_softirq+0x55/0x141 [<c012b8e3>] tick_handle_periodic+0xf/0x54 [<c011bdcc>] __do_softirq+0x35/0x75 [<c011be2e>] do_softirq+022/0x26 [<c01055b0>] do_IRQ+0x58/0x6b [<c033b1a7>] schedule+0x1f0/0x20a [<c01045e7>] common_interrupt+0x23/0x28
Kernel Panic - not syncing: Fatal exception in interrupt
makes it useful enough - at least for me.
The fact, that this information has not been used by the knowledgable developers of the offending code to fix the root cause within 14 days is a totaly different problem.
Thanks,
tglx
PATCH 3/5 debugobjects: add documentation
In reply to Thomas GleixnerAdd a DocBook for debugobjects.
--- Documentation/DocBook/Makefile | 3 Documentation/DocBook/debugobjects.tmpl | 391 ++++++++++++++++++++++++++++++++ 2 files changed, 393 insertions(+), 1 deletion(-)
Documentation/DocBook/Makefile +2 -1
@@ -11,7 +11,8 @@ DOCBOOKS := wanbook.xml z8530book.xml mc procfs-guide.xml writing_usb_driver.xml networking.xml \ kernel-api.xml filesystems.xml lsm.xml usb.xml \ gadget.xml libata.xml mtdnand.xml librs.xml rapidio.xml \ - genericirq.xml s390-drivers.xml uio-howto.xml scsi.xml + genericirq.xml s390-drivers.xml uio-howto.xml scsi.xml \ + debugobjects.xml ### # The build process is as follows (targets):
Documentation/DocBook/debugobjects.tmpl new file +391 -0
391 lines not on this page · raw message
PATCH 4/5 debugobjects: add timer specific object debugging code
In reply to Thomas GleixnerAdd calls to the generic object debugging infrastructure and provide fixup functions which allow to keep the system alive when recoverable problems have been detected by the object debugging core code.
--- drivers/parport/ieee1284.c | 4 - fs/aio.c | 5 - include/linux/poison.h | 7 ++ include/linux/timer.h | 23 ++++++ kernel/timer.c | 153 ++++++++++++++++++++++++++++++++++++++++++--- lib/Kconfig.debug | 8 ++ 6 files changed, 187 insertions(+), 13 deletions(-)
drivers/parport/ieee1284.c +3 -1
@@ -76,7 +76,7 @@ int parport_wait_event (struct parport *semaphore. */ return 1 ; -init_timer (&timer); +init_timer_on_stack (&timer); timer.expires = jiffies + timeout; timer.function = timeout_waiting_on_port; port_from_cookie[port->number %PARPORT_MAX ] = port;
@@ -88,6 +88,8 @@ int parport_wait_event (struct parport */* Timed out. */ ret =1 ; +destroy_timer_on_stack (&timer); +return ret; }
fs/aio.c +2 -3
@@ -1069,9 +1069,7 @@ static void timeout_func(unsigned long dstatic inline void init_timeout (struct aio_timeout *to) { -init_timer (&to->timer); - to->timer.data = (unsigned long )to; - to->timer.function = timeout_func; +setup_timer_on_stack (&to->timer, timeout_func, (unsigned long ) to); to->timed_out =0 ; to->p = current; }
@@ -1201,6 +1199,7 @@ retry:if (timeout)clear_timeout (&to); out: +destroy_timer_on_stack (&to.timer);return i ? i : ret; }
include/linux/poison.h +7 -0
@@ -10,6 +10,13 @@#define LIST_POISON1 ((void *) 0x00100100)#define LIST_POISON2 ((void *) 0x00200200) +/********** include/linux/timer.h **********/ +/* +* Magic number "tsta" to indicate a static timer initializer +* for the object debugging code. +*/ +#define TIMER_ENTRY_STATIC ((void *) 0x74737461) +/********** mm/slab.c **********/ /* * Magic nums for obj red zoning.
include/linux/timer.h +22 -1
@@ -4,6 +4,7 @@#include <linux/list.h> #include <linux/ktime.h> #include <linux/stddef.h> +#include <linux/debugobjects.h> struct tvec_base ;
@@ -25,6 +26,7 @@ struct timer_list {extern struct tvec_base boot_tvec_bases;#define TIMER_INITIALIZER (_function, _expires, _data) { \ + .entry = { .prev = TIMER_ENTRY_STATIC }, \ .function = (_function), \ .expires = (_expires), \ .data = (_data), \
@@ -38,6 +40,17 @@ extern struct tvec_base boot_tvec_bases;void init_timer (struct timer_list *timer);void init_timer_deferrable (struct timer_list *timer); +#ifdef CONFIG_DEBUG_OBJECTS_TIMERS +extern void init_timer_on_stack (struct timer_list *timer); +extern void destroy_timer_on_stack (struct timer_list *timer); +#else +static inline void destroy_timer_on_stack (struct timer_list *timer) { } +static inline void init_timer_on_stack (struct timer_list *timer) +{ +init_timer (timer); +} +#endif +static inline void setup_timer (struct timer_list * timer,void (*function)(unsigned long ),unsigned long data)
@@ -47,6 +60,15 @@ static inline void setup_timer(struct tiinit_timer (timer); } +static inline void setup_timer_on_stack (struct timer_list *timer, +void (*function)(unsigned long ), +unsigned long data) +{ + timer->function = function; + timer->data = data; +init_timer_on_stack (timer); +} +/** * timer_pending - is a timer pending? * @timer: the timer in question
@@ -164,5 +186,4 @@ unsigned long __round_jiffies_relative(uunsigned long round_jiffies (unsigned long j);unsigned long round_jiffies_relative (unsigned long j); -#endif
kernel/timer.c +145 -8
194 lines not on this page · raw message
lib/Kconfig.debug +8 -0
@@ -206,6 +206,14 @@ config DEBUG_OBJECTS_FREE properly. This can make kmalloc/kfree-intensive workloads much slower. +config DEBUG_OBJECTS_TIMERS + bool "Debug timer objects" + depends on DEBUG_OBJECTS + help + If you say Y here, additional code will be inserted into the + timer routines to track the life time of timer objects and + validate the timer operations. + config DEBUG_SLAB bool "Debug slab memory allocations" depends on DEBUG_KERNEL && SLAB
Andrew Morton
maintainerRe: [patch 4/5] debugobjects: add timer specific object debugging code
Quoted 4 lines · On Fri, 21 Mar 2008 20:26:28 -0000 Thomas Gleixner <[email protected]> wrote:
Add calls to the generic object debugging infrastructure and provide fixup functions which allow to keep the system alive when recoverable problems have been detected by the object debugging core code.
This has run afoul of the new
http://ozlabs.org/~rusty/kernel/rr-latest/misc:timer-typesafe.patch
I don't know if Rusty intends that for 2.6.26. Probably not, given its infancy. So I'll locally revert that change from Rusty's tree to clear the way for a clean merge of debugobjects-add-timer-specific-object-debugging-code.patch.
PATCH 5/5 add hrtimer specific debugobjects code
In reply to Thomas Gleixnerhrtimers have now dynamic users in the network code. Put them under debugobjects surveillance as well.
Add calls to the generic object debugging infrastructure and provide fixup functions which allow to keep the system alive when recoverable problems have been detected by the object debugging core code.
--- include/linux/hrtimer.h | 15 ++++ kernel/futex.c | 13 +++ kernel/hrtimer.c | 176 ++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 182 insertions(+), 22 deletions(-)
include/linux/hrtimer.h +15 -0
@@ -268,6 +268,21 @@ extern ktime_t ktime_get_real(void);extern void hrtimer_init (struct hrtimer *timer,clockid_t which_clock,enum hrtimer_mode mode); +#ifdef CONFIG_DEBUG_OBJECTS_TIMERS +extern void hrtimer_init_on_stack (struct hrtimer *timer,clockid_t which_clock, +enum hrtimer_mode mode); + +extern void destroy_hrtimer_on_stack (struct hrtimer *timer); +#else +static inline void hrtimer_init_on_stack (struct hrtimer *timer, +clockid_t which_clock, +enum hrtimer_mode mode) +{ +hrtimer_init (timer, which_clock, mode); +} +static inline void destroy_hrtimer_on_stack (struct hrtimer *timer) { } +#endif +/* Basic timer operations: */ extern int hrtimer_start (struct hrtimer *timer,ktime_t tim,const enum hrtimer_mode mode);
kernel/futex.c +11 -2
@@ -1266,7 +1266,7 @@ static int futex_wait(u32 __user *uaddr,if (!abs_time)schedule ();else { -hrtimer_init (&t.timer,CLOCK_MONOTONIC ,HRTIMER_MODE_ABS ); +hrtimer_init_on_stack (&t.timer,CLOCK_MONOTONIC ,HRTIMER_MODE_ABS );hrtimer_init_sleeper (&t, current); t.timer.expires = *abs_time;
@@ -1286,6 +1286,8 @@ static int futex_wait(u32 __user *uaddr,/* Flag if a timeout occured */ rem = (t.task ==NULL ); + +destroy_hrtimer_on_stack (&t.timer); } }__set_current_state (TASK_RUNNING );
@@ -1367,7 +1369,8 @@ static int futex_lock_pi(u32 __user *uadif (time) { to = &timeout; -hrtimer_init (&to->timer,CLOCK_REALTIME ,HRTIMER_MODE_ABS ); +hrtimer_init_on_stack (&to->timer,CLOCK_REALTIME , +HRTIMER_MODE_ABS );hrtimer_init_sleeper (to, current); to->timer.expires = *time; }
@@ -1581,6 +1584,8 @@ static int futex_lock_pi(u32 __user *uadunqueue_me_pi (&q);futex_unlock_mm (fshared); +if (to) +destroy_hrtimer_on_stack (&to->timer);return ret != -EINTR ? ret : -ERESTARTNOINTR ; out_unlock_release_sem:
@@ -1588,6 +1593,8 @@ static int futex_lock_pi(u32 __user *uad out_release_sem:futex_unlock_mm (fshared); +if (to) +destroy_hrtimer_on_stack (&to->timer);return ret; uaddr_faulted:
@@ -1615,6 +1622,8 @@ static int futex_lock_pi(u32 __user *uadif (!ret && (uval != -EFAULT )) goto retry; +if (to) +destroy_hrtimer_on_stack (&to->timer);return ret; }
kernel/hrtimer.c +156 -20
285 lines not on this page · raw message