[PATCH 2/5] lockdep: check that no locks held at freeze time

From: Mandeep Singh Baines
Date: Thu Feb 14 2013 - 18:38:41 EST

We shouldn't try_to_freeze if locks are held. Verified that
I get no lockdep warnings after applying this patch and
"vfork: don't freezer_count() for in-kernel users of CLONE_VFORK".

Signed-off-by: Mandeep Singh Baines <msb@xxxxxxxxxxxx>
CC: Oleg Nesterov <oleg@xxxxxxxxxx>
CC: Tejun Heo <tj@xxxxxxxxxx>
CC: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
CC: Rafael J. Wysocki <rjw@xxxxxxx>
CC: Ingo Molnar <mingo@xxxxxxxxxx>
include/linux/freezer.h | 2 ++
kernel/lockdep.c | 6 +++---
2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/linux/freezer.h b/include/linux/freezer.h
index e4238ce..1538cfc 100644
--- a/include/linux/freezer.h
+++ b/include/linux/freezer.h
@@ -3,6 +3,7 @@

+#include <linux/debug_locks.h>
#include <linux/sched.h>
#include <linux/wait.h>
#include <linux/atomic.h>
@@ -43,6 +44,7 @@ extern void thaw_kernel_threads(void);

static inline bool try_to_freeze(void)
+ debug_check_no_locks_held(current);
if (likely(!freezing(current)))
return false;
diff --git a/kernel/lockdep.c b/kernel/lockdep.c
index 7981e5b..e3ee8af 100644
--- a/kernel/lockdep.c
+++ b/kernel/lockdep.c
@@ -4091,10 +4091,10 @@ static void print_held_locks_bug(struct task_struct *curr)

- printk("=====================================\n");
- printk("[ BUG: lock held at task exit time! ]\n");
+ printk("=======================================\n");
+ printk("[ BUG: lock held at exit/freeze time! ]\n");
- printk("-------------------------------------\n");
+ printk("---------------------------------------\n");
printk("%s/%d is exiting with locks still held!\n",
curr->comm, task_pid_nr(curr));

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/