Re: [PATCH] timer: implement lockdep deadlock detection

From: Ingo Molnar
Date: Mon Jan 26 2009 - 18:07:55 EST



* Johannes Berg <johannes@xxxxxxxxxxxxxxxx> wrote:

> This modifies the timer code in a way to allow lockdep to detect
> deadlocks resulting from a lock being taken in the timer function as
> well as around the del_timer_sync() call.
>
> Validated with this module, otherwise bootup was clean.

That's a really neat trick ...

Curious: have you hit such a bug recently that motivated you to implement
it?

> +#ifdef CONFIG_LOCKDEP
> +#define init_timer(timer) \
> + do { \
> + static struct lock_class_key __key; \
> + init_timer_key((timer), #timer, &__key); \
> + } while (0)
> +#define init_timer_deferrable(timer) \
> + do { \

(Style detail: please put a newline after each macro block to make them
stand apart a bit more.)

> int del_timer_sync(struct timer_list *timer)
> {
> +#ifdef CONFIG_LOCKDEP
> + unsigned long flags;
> +
> + local_irq_save(flags);
> + lock_map_acquire(&timer->lockdep_map);
> + lock_map_release(&timer->lockdep_map);
> + local_irq_restore(flags);
> +#endif

yummie. We have repeat bugs in this area that are rather tricky to find.
This will trigger them in a debuggable way.

> @@ -861,10 +881,21 @@ static inline void __run_timers(struct t
>
> set_running_timer(base, timer);
> detach_timer(timer, 1);
> +
> spin_unlock_irq(&base->lock);

Yes, the newline is needed there :-) [seriously]

> int preempt_count = preempt_count();
> +
> + /* Couple the lock chain with the lock chain at
> + * del_timer_sync by acquiring the lock_map around
> + * the fn() call here and in del_timer_sync.
> + */

Please use the standard multi-line comment style:

/*
* Comment .....
* ...... goes here:
*/

Looks good otherwise,

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/