[RFC PATCH 4/4] lockdep: fix race condition in __lock_set_class()

From: Yong Zhang
Date: Fri Nov 04 2011 - 05:29:03 EST


When someone call lock_set_class() with valid key, nothing
protect the initializing of 'lockdep_map'; thus could lead
to flase positive warning from lockdep (such as "key not in
.data!"). This patch cure that potential issue.

Signed-off-by: Yong Zhang <yong.zhang0@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
---
kernel/lockdep.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/lockdep.c b/kernel/lockdep.c
index 3af87ad..fd4d816 100644
--- a/kernel/lockdep.c
+++ b/kernel/lockdep.c
@@ -3290,8 +3290,12 @@ __lock_set_class(struct lockdep_map *lock, const char *name,
found_it:
/* optimizing for lock_set_subclass() */
if (key) {
- lockdep_init_map(lock, name, key, 0);
- register_lock_class(lock, subclass, 0, 0);
+ if (!graph_lock())
+ return 0;
+
+ __lockdep_init_map(lock, name, key, 0);
+ /* will release graph_lock() there */
+ register_lock_class(lock, subclass, 0, 1);
}

curr->lockdep_depth = i;
--
1.7.5.4

--
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/