Skip to contentSkip to conversation

taint on lockdep warning with new TAINT_LOCKDEP

PATCH In review Slava Pestov 3 participants 3 messages Jan 29, 2015 – Feb 18, 2015 Locking primitives

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 taint on lockdep warning with new TAINT_LOCKDEP

This helps when writing automated tests, since they can fail the test if the kernel was tainted instead of manually scraping dmesg for interesting strings.

---
 include/linux/kernel.h   |  1 +
 kernel/locking/lockdep.c | 31 +++++++++++++++++++++++++++++++
 kernel/panic.c           |  2 ++
 3 files changed, 34 insertions(+)
include/linux/kernel.h +1 -0
index 5449d2f..c46e24e 100644
@@ -471,6 +471,7 @@ extern enum system_states {
 #define TAINT_OOT_MODULE		12
 #define TAINT_UNSIGNED_MODULE		13
 #define TAINT_SOFTLOCKUP		14
+#define TAINT_LOCKDEP			15
 
 extern const char hex_asc[];
 #define hex_asc_lo(x)	hex_asc[((x) & 0x0f)]
kernel/locking/lockdep.c +31 -0
index 88d0d44..4916a32 100644
@@ -382,6 +382,8 @@ static unsigned long stack_trace[MAX_STACK_TRACE_ENTRIES];
 
 static void print_lockdep_off(const char *bug_msg)
 {
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
+
 	printk(KERN_DEBUG "%s\n", bug_msg);
 	printk(KERN_DEBUG "turning off the locking correctness validator.\n");
 #ifdef CONFIG_LOCK_STAT
@@ -739,6 +741,9 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
  	 */
 	if (!static_obj(lock->key)) {
 		debug_locks_off();
+
+		add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
+
 		printk("INFO: trying to register non-static key.\n");
 		printk("the code is fine but needs lockdep annotation.\n");
 		printk("turning off the locking correctness validator.\n");
@@ -1190,6 +1195,8 @@ static noinline int print_circular_bug(struct lock_list *this,
 	if (!debug_locks_off_graph_unlock() || debug_locks_silent)
 		return 0;
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
+
 	if (!save_trace(&this->trace))
 		return 0;
 
@@ -1492,6 +1499,8 @@ print_bad_irq_dependency(struct task_struct *curr,
 	if (!debug_locks_off_graph_unlock() || debug_locks_silent)
 		return 0;
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
+
 	printk("\n");
 	printk("======================================================\n");
 	printk("[ INFO: %s-safe -> %s-unsafe lock order detected ]\n",
@@ -1722,6 +1731,8 @@ print_deadlock_bug(struct task_struct *curr, struct held_lock *prev,
 	if (!debug_locks_off_graph_unlock() || debug_locks_silent)
 		return 0;
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
+
 	printk("\n");
 	printk("=============================================\n");
 	printk("[ INFO: possible recursive locking detected ]\n");
@@ -2226,6 +2237,8 @@ print_usage_bug(struct task_struct *curr, struct held_lock *this,
 	if (!debug_locks_off_graph_unlock() || debug_locks_silent)
 		return 0;
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
+
 	printk("\n");
 	printk("=================================\n");
 	printk("[ INFO: inconsistent lock state ]\n");
@@ -2291,6 +2304,8 @@ print_irq_inversion_bug(struct task_struct *curr,
 	if (!debug_locks_off_graph_unlock() || debug_locks_silent)
 		return 0;
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
+
 	printk("\n");
 	printk("=========================================================\n");
 	printk("[ INFO: possible irq lock inversion dependency detected ]\n");
@@ -3014,6 +3029,8 @@ print_lock_nested_lock_not_held(struct task_struct *curr,
 	if (debug_locks_silent)
 		return 0;
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
+
 	printk("\n");
 	printk("==================================\n");
 	printk("[ BUG: Nested lock was not taken ]\n");
@@ -3219,6 +3236,8 @@ print_unlock_imbalance_bug(struct task_struct *curr, struct lockdep_map *lock,
 	if (debug_locks_silent)
 		return 0;
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
+
 	printk("\n");
 	printk("=====================================\n");
 	printk("[ BUG: bad unlock balance detected! ]\n");
@@ -3664,6 +3683,8 @@ print_lock_contention_bug(struct task_struct *curr, struct lockdep_map *lock,
 	if (debug_locks_silent)
 		return 0;
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
+
 	printk("\n");
 	printk("=================================\n");
 	printk("[ BUG: bad contention detected! ]\n");
@@ -4040,6 +4061,8 @@ print_freed_lock_bug(struct task_struct *curr, const void *mem_from,
 	if (debug_locks_silent)
 		return;
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
+
 	printk("\n");
 	printk("=========================\n");
 	printk("[ BUG: held lock freed! ]\n");
@@ -4098,6 +4121,8 @@ static void print_held_locks_bug(void)
 	if (debug_locks_silent)
 		return;
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
+
 	printk("\n");
 	printk("=====================================\n");
 	printk("[ BUG: %s/%d still has locks held! ]\n",
@@ -4197,6 +4222,9 @@ asmlinkage __visible void lockdep_sys_exit(void)
 	if (unlikely(curr->lockdep_depth)) {
 		if (!debug_locks_off())
 			return;
+
+		add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
+
 		printk("\n");
 		printk("================================================\n");
 		printk("[ BUG: lock held when returning to user space! ]\n");
@@ -4216,6 +4244,9 @@ void lockdep_rcu_suspicious(const char *file, const int line, const char *s)
 	if (!debug_locks_off())
 		return;
 #endif /* #ifdef CONFIG_PROVE_RCU_REPEATEDLY */
+
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
+
 	/* Note: the following can be executed concurrently, so be careful. */
 	printk("\n");
 	printk("===============================\n");
kernel/panic.c +2 -0
index 4d8d6f9..7bd42ba 100644
@@ -226,6 +226,7 @@ static const struct tnt tnts[] = {
 	{ TAINT_OOT_MODULE,		'O', ' ' },
 	{ TAINT_UNSIGNED_MODULE,	'E', ' ' },
 	{ TAINT_SOFTLOCKUP,		'L', ' ' },
+	{ TAINT_LOCKDEP,		'K', ' ' },
 };
 
 /**
@@ -246,6 +247,7 @@ static const struct tnt tnts[] = {
  *  'O' - Out-of-tree module has been loaded.
  *  'E' - Unsigned module has been loaded.
  *  'L' - A soft lockup has previously occurred.
+ *  'K' - Lockdep warning was generated.
  *
  *	The string is overwritten by the next call to print_tainted().
  */
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 3 lines · On Thu, 29 Jan 2015 13:50:26 -0800 Slava Pestov <[email protected]> wrote:

This helps when writing automated tests, since they can fail the test if the kernel was tainted instead of manually scraping dmesg for interesting strings.

Seems sane. It wouldn't hurt to mention this in
Documentation/locking/lockdep-design.txt

#2 lore raw
In reply to Slava Pestov
Quoted 48 lines · Slava Pestov

This helps when writing automated tests, since they can fail the test if the kernel was tainted instead of manually scraping dmesg for interesting strings.

---
 include/linux/kernel.h   |  1 +
 kernel/locking/lockdep.c | 31 +++++++++++++++++++++++++++++++
 kernel/panic.c           |  2 ++
 3 files changed, 34 insertions(+)
include/linux/kernel.h +1 -0
index 5449d2f..c46e24e 100644
@@ -471,6 +471,7 @@ extern enum system_states {
 #define TAINT_OOT_MODULE		12
 #define TAINT_UNSIGNED_MODULE		13
 #define TAINT_SOFTLOCKUP		14
+#define TAINT_LOCKDEP			15
 
 extern const char hex_asc[];
 #define hex_asc_lo(x)	hex_asc[((x) & 0x0f)]
kernel/locking/lockdep.c +9 -0
index 88d0d44..4916a32 100644
@@ -382,6 +382,8 @@ static unsigned long stack_trace[MAX_STACK_TRACE_ENTRIES];
 
 static void print_lockdep_off(const char *bug_msg)
 {
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
 
+		add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);

kernel/locking/lockdep.c static unsigned long stack_trace[MAX_STACK_TRACE_ENTRIES];

Quoted 10 lines
kernel/locking/lockdep.c +5 -0
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
 
+		add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);
 
+	add_taint(TAINT_LOCKDEP, LOCKDEP_NOW_UNRELIABLE);

If only we had a function that turns lockdep off in a single place, instead of having to crap all over lockdep.c? ;-)

Thanks,

Ingo