Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

debugobjects: add timer specific object debugging code

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.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Ingo Molnar <mingo@elte.hu>
Cc: Greg KH <greg@kroah.com>
Cc: Randy Dunlap <randy.dunlap@oracle.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Thomas Gleixner and committed by
Linus Torvalds
c6f3a97f 691cc54c

+187 -13
+3 -1
drivers/parport/ieee1284.c
··· 76 76 semaphore. */ 77 77 return 1; 78 78 79 - init_timer (&timer); 79 + init_timer_on_stack(&timer); 80 80 timer.expires = jiffies + timeout; 81 81 timer.function = timeout_waiting_on_port; 82 82 port_from_cookie[port->number % PARPORT_MAX] = port; ··· 87 87 if (!del_timer (&timer) && !ret) 88 88 /* Timed out. */ 89 89 ret = 1; 90 + 91 + destroy_timer_on_stack(&timer); 90 92 91 93 return ret; 92 94 }
+2 -3
fs/aio.c
··· 1078 1078 1079 1079 static inline void init_timeout(struct aio_timeout *to) 1080 1080 { 1081 - init_timer(&to->timer); 1082 - to->timer.data = (unsigned long)to; 1083 - to->timer.function = timeout_func; 1081 + setup_timer_on_stack(&to->timer, timeout_func, (unsigned long) to); 1084 1082 to->timed_out = 0; 1085 1083 to->p = current; 1086 1084 } ··· 1211 1213 if (timeout) 1212 1214 clear_timeout(&to); 1213 1215 out: 1216 + destroy_timer_on_stack(&to.timer); 1214 1217 return i ? i : ret; 1215 1218 } 1216 1219
+7
include/linux/poison.h
··· 10 10 #define LIST_POISON1 ((void *) 0x00100100) 11 11 #define LIST_POISON2 ((void *) 0x00200200) 12 12 13 + /********** include/linux/timer.h **********/ 14 + /* 15 + * Magic number "tsta" to indicate a static timer initializer 16 + * for the object debugging code. 17 + */ 18 + #define TIMER_ENTRY_STATIC ((void *) 0x74737461) 19 + 13 20 /********** mm/slab.c **********/ 14 21 /* 15 22 * Magic nums for obj red zoning.
+22 -1
include/linux/timer.h
··· 4 4 #include <linux/list.h> 5 5 #include <linux/ktime.h> 6 6 #include <linux/stddef.h> 7 + #include <linux/debugobjects.h> 7 8 8 9 struct tvec_base; 9 10 ··· 26 25 extern struct tvec_base boot_tvec_bases; 27 26 28 27 #define TIMER_INITIALIZER(_function, _expires, _data) { \ 28 + .entry = { .prev = TIMER_ENTRY_STATIC }, \ 29 29 .function = (_function), \ 30 30 .expires = (_expires), \ 31 31 .data = (_data), \ ··· 40 38 void init_timer(struct timer_list *timer); 41 39 void init_timer_deferrable(struct timer_list *timer); 42 40 41 + #ifdef CONFIG_DEBUG_OBJECTS_TIMERS 42 + extern void init_timer_on_stack(struct timer_list *timer); 43 + extern void destroy_timer_on_stack(struct timer_list *timer); 44 + #else 45 + static inline void destroy_timer_on_stack(struct timer_list *timer) { } 46 + static inline void init_timer_on_stack(struct timer_list *timer) 47 + { 48 + init_timer(timer); 49 + } 50 + #endif 51 + 43 52 static inline void setup_timer(struct timer_list * timer, 44 53 void (*function)(unsigned long), 45 54 unsigned long data) ··· 58 45 timer->function = function; 59 46 timer->data = data; 60 47 init_timer(timer); 48 + } 49 + 50 + static inline void setup_timer_on_stack(struct timer_list *timer, 51 + void (*function)(unsigned long), 52 + unsigned long data) 53 + { 54 + timer->function = function; 55 + timer->data = data; 56 + init_timer_on_stack(timer); 61 57 } 62 58 63 59 /** ··· 185 163 unsigned long __round_jiffies_relative(unsigned long j, int cpu); 186 164 unsigned long round_jiffies(unsigned long j); 187 165 unsigned long round_jiffies_relative(unsigned long j); 188 - 189 166 190 167 #endif
+145 -8
kernel/timer.c
··· 320 320 static void timer_stats_account_timer(struct timer_list *timer) {} 321 321 #endif 322 322 323 + #ifdef CONFIG_DEBUG_OBJECTS_TIMERS 324 + 325 + static struct debug_obj_descr timer_debug_descr; 326 + 327 + /* 328 + * fixup_init is called when: 329 + * - an active object is initialized 330 + */ 331 + static int timer_fixup_init(void *addr, enum debug_obj_state state) 332 + { 333 + struct timer_list *timer = addr; 334 + 335 + switch (state) { 336 + case ODEBUG_STATE_ACTIVE: 337 + del_timer_sync(timer); 338 + debug_object_init(timer, &timer_debug_descr); 339 + return 1; 340 + default: 341 + return 0; 342 + } 343 + } 344 + 345 + /* 346 + * fixup_activate is called when: 347 + * - an active object is activated 348 + * - an unknown object is activated (might be a statically initialized object) 349 + */ 350 + static int timer_fixup_activate(void *addr, enum debug_obj_state state) 351 + { 352 + struct timer_list *timer = addr; 353 + 354 + switch (state) { 355 + 356 + case ODEBUG_STATE_NOTAVAILABLE: 357 + /* 358 + * This is not really a fixup. The timer was 359 + * statically initialized. We just make sure that it 360 + * is tracked in the object tracker. 361 + */ 362 + if (timer->entry.next == NULL && 363 + timer->entry.prev == TIMER_ENTRY_STATIC) { 364 + debug_object_init(timer, &timer_debug_descr); 365 + debug_object_activate(timer, &timer_debug_descr); 366 + return 0; 367 + } else { 368 + WARN_ON_ONCE(1); 369 + } 370 + return 0; 371 + 372 + case ODEBUG_STATE_ACTIVE: 373 + WARN_ON(1); 374 + 375 + default: 376 + return 0; 377 + } 378 + } 379 + 380 + /* 381 + * fixup_free is called when: 382 + * - an active object is freed 383 + */ 384 + static int timer_fixup_free(void *addr, enum debug_obj_state state) 385 + { 386 + struct timer_list *timer = addr; 387 + 388 + switch (state) { 389 + case ODEBUG_STATE_ACTIVE: 390 + del_timer_sync(timer); 391 + debug_object_free(timer, &timer_debug_descr); 392 + return 1; 393 + default: 394 + return 0; 395 + } 396 + } 397 + 398 + static struct debug_obj_descr timer_debug_descr = { 399 + .name = "timer_list", 400 + .fixup_init = timer_fixup_init, 401 + .fixup_activate = timer_fixup_activate, 402 + .fixup_free = timer_fixup_free, 403 + }; 404 + 405 + static inline void debug_timer_init(struct timer_list *timer) 406 + { 407 + debug_object_init(timer, &timer_debug_descr); 408 + } 409 + 410 + static inline void debug_timer_activate(struct timer_list *timer) 411 + { 412 + debug_object_activate(timer, &timer_debug_descr); 413 + } 414 + 415 + static inline void debug_timer_deactivate(struct timer_list *timer) 416 + { 417 + debug_object_deactivate(timer, &timer_debug_descr); 418 + } 419 + 420 + static inline void debug_timer_free(struct timer_list *timer) 421 + { 422 + debug_object_free(timer, &timer_debug_descr); 423 + } 424 + 425 + static void __init_timer(struct timer_list *timer); 426 + 427 + void init_timer_on_stack(struct timer_list *timer) 428 + { 429 + debug_object_init_on_stack(timer, &timer_debug_descr); 430 + __init_timer(timer); 431 + } 432 + EXPORT_SYMBOL_GPL(init_timer_on_stack); 433 + 434 + void destroy_timer_on_stack(struct timer_list *timer) 435 + { 436 + debug_object_free(timer, &timer_debug_descr); 437 + } 438 + EXPORT_SYMBOL_GPL(destroy_timer_on_stack); 439 + 440 + #else 441 + static inline void debug_timer_init(struct timer_list *timer) { } 442 + static inline void debug_timer_activate(struct timer_list *timer) { } 443 + static inline void debug_timer_deactivate(struct timer_list *timer) { } 444 + #endif 445 + 446 + static void __init_timer(struct timer_list *timer) 447 + { 448 + timer->entry.next = NULL; 449 + timer->base = __raw_get_cpu_var(tvec_bases); 450 + #ifdef CONFIG_TIMER_STATS 451 + timer->start_site = NULL; 452 + timer->start_pid = -1; 453 + memset(timer->start_comm, 0, TASK_COMM_LEN); 454 + #endif 455 + } 456 + 323 457 /** 324 458 * init_timer - initialize a timer. 325 459 * @timer: the timer to be initialized ··· 463 329 */ 464 330 void init_timer(struct timer_list *timer) 465 331 { 466 - timer->entry.next = NULL; 467 - timer->base = __raw_get_cpu_var(tvec_bases); 468 - #ifdef CONFIG_TIMER_STATS 469 - timer->start_site = NULL; 470 - timer->start_pid = -1; 471 - memset(timer->start_comm, 0, TASK_COMM_LEN); 472 - #endif 332 + debug_timer_init(timer); 333 + __init_timer(timer); 473 334 } 474 335 EXPORT_SYMBOL(init_timer); 475 336 ··· 479 350 int clear_pending) 480 351 { 481 352 struct list_head *entry = &timer->entry; 353 + 354 + debug_timer_deactivate(timer); 482 355 483 356 __list_del(entry->prev, entry->next); 484 357 if (clear_pending) ··· 536 405 ret = 1; 537 406 } 538 407 408 + debug_timer_activate(timer); 409 + 539 410 new_base = __get_cpu_var(tvec_bases); 540 411 541 412 if (base != new_base) { ··· 583 450 BUG_ON(timer_pending(timer) || !timer->function); 584 451 spin_lock_irqsave(&base->lock, flags); 585 452 timer_set_base(timer, base); 453 + debug_timer_activate(timer); 586 454 internal_add_timer(base, timer); 587 455 /* 588 456 * Check whether the other CPU is idle and needs to be ··· 1220 1086 1221 1087 expire = timeout + jiffies; 1222 1088 1223 - setup_timer(&timer, process_timeout, (unsigned long)current); 1089 + setup_timer_on_stack(&timer, process_timeout, (unsigned long)current); 1224 1090 __mod_timer(&timer, expire); 1225 1091 schedule(); 1226 1092 del_singleshot_timer_sync(&timer); 1093 + 1094 + /* Remove the timer from the object tracker */ 1095 + destroy_timer_on_stack(&timer); 1227 1096 1228 1097 timeout = expire - jiffies; 1229 1098
+8
lib/Kconfig.debug
··· 217 217 properly. This can make kmalloc/kfree-intensive workloads 218 218 much slower. 219 219 220 + config DEBUG_OBJECTS_TIMERS 221 + bool "Debug timer objects" 222 + depends on DEBUG_OBJECTS 223 + help 224 + If you say Y here, additional code will be inserted into the 225 + timer routines to track the life time of timer objects and 226 + validate the timer operations. 227 + 220 228 config DEBUG_SLAB 221 229 bool "Debug slab memory allocations" 222 230 depends on DEBUG_KERNEL && SLAB