Commit c8a25005 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

lockdep: more robust lockdep_map init sequence

Steven Rostedt reported:

> OK, I think I figured this bug out. This is a lockdep issue with respect
> to tracepoints.
>
> The trace points in lockdep are called all the time. Outside the lockdep
> logic. But if lockdep were to trigger an error / warning (which this run
> did) we might be in trouble. For new locks, like the dentry->d_lock, that
> are created, they will not get a name:
>
> void lockdep_init_map(struct lockdep_map *lock, const char *name,
>                       struct lock_class_key *key, int subclass)
> {
>         if (unlikely(!debug_locks))
>                 return;
>
> When a problem is found by lockdep, debug_locks becomes false. Thus we
> stop allocating names for locks. This dentry->d_lock I had, now has no
> name. Worse yet, I have CONFIG_DEBUG_VM set, that scrambles non
> initialized memory. Thus, when the trace point was hit, it had junk for
> the lock->name, and the machine crashed.

Ah, nice catch. I think we should put at least the name in regardless.

Ensure we at least initialize the trivial entries of the depmap so that
they can be relied upon, even when lockdep itself decided to pack up and
go home.

[ Impact: fix lock tracing after lockdep warnings. ]
Reported-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <1239954049.23397.4156.camel@laptop>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 79d381c9
...@@ -2490,13 +2490,20 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this, ...@@ -2490,13 +2490,20 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this,
void lockdep_init_map(struct lockdep_map *lock, const char *name, void lockdep_init_map(struct lockdep_map *lock, const char *name,
struct lock_class_key *key, int subclass) struct lock_class_key *key, int subclass)
{ {
if (unlikely(!debug_locks)) lock->class_cache = NULL;
#ifdef CONFIG_LOCK_STAT
lock->cpu = raw_smp_processor_id();
#endif
if (DEBUG_LOCKS_WARN_ON(!name)) {
lock->name = "NULL";
return; return;
}
lock->name = name;
if (DEBUG_LOCKS_WARN_ON(!key)) if (DEBUG_LOCKS_WARN_ON(!key))
return; return;
if (DEBUG_LOCKS_WARN_ON(!name))
return;
/* /*
* Sanity check, the lock-class key must be persistent: * Sanity check, the lock-class key must be persistent:
*/ */
...@@ -2505,12 +2512,11 @@ void lockdep_init_map(struct lockdep_map *lock, const char *name, ...@@ -2505,12 +2512,11 @@ void lockdep_init_map(struct lockdep_map *lock, const char *name,
DEBUG_LOCKS_WARN_ON(1); DEBUG_LOCKS_WARN_ON(1);
return; return;
} }
lock->name = name;
lock->key = key; lock->key = key;
lock->class_cache = NULL;
#ifdef CONFIG_LOCK_STAT if (unlikely(!debug_locks))
lock->cpu = raw_smp_processor_id(); return;
#endif
if (subclass) if (subclass)
register_lock_class(lock, subclass, 1); register_lock_class(lock, subclass, 1);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment