History

lockdep: Mark emergency sections in lockdep splats

Mark emergency sections wherever multiple lines of lock debugging output are generated. In an emergency section, every printk() call will attempt to directly flush to the consoles using the EMERGENCY priority. Note that debug_show_all_locks() and lockdep_print_held_locks() rely on their callers to enter the emergency section. This is because these functions can also be called in non-emergency situations (such as sysrq).

John Ogness committed 2 years ago

Commit 59cd94e1 parent 8c032731 file · +81 −2Browse files

Showing the changes to kernel/locking (1 of 1 file). Show all

Unified · Split

kernel/locking/lockdep.c+81−2
@@ -56,6 +56,7 @@ · 55 unmodified lines
5656 #include <linux/kprobes.h>
5757 #include <linux/lockdep.h>
5858 #include <linux/context_tracking.h>
59+#include <linux/console.h>
5960
6061 #include <asm/sections.h>
6162
@@ -573,8 +574,10 @@ static struct lock_trace *save_trace(void) · 511 unmodified lines
573574 if (!debug_locks_off_graph_unlock())
574575 return NULL;
575576
577+ nbcon_cpu_emergency_enter();
576578 print_lockdep_off("BUG: MAX_STACK_TRACE_ENTRIES too low!");
577579 dump_stack();
580+ nbcon_cpu_emergency_exit();
578581
579582 return NULL;
580583 }
@@ -887,11 +890,13 @@ look_up_lock_class(const struct lockdep_map *lock, unsigned int subclass) · 306 unmodified lines
887890 if (unlikely(subclass >= MAX_LOCKDEP_SUBCLASSES)) {
888891 instrumentation_begin();
889892 debug_locks_off();
893+ nbcon_cpu_emergency_enter();
890894 printk(KERN_ERR
891895 "BUG: looking up invalid subclass: %u\n", subclass);
892896 printk(KERN_ERR
893897 "turning off the locking correctness validator.\n");
894898 dump_stack();
899+ nbcon_cpu_emergency_exit();
895900 instrumentation_end();
896901 return NULL;
897902 }
@@ -968,11 +973,13 @@ static bool assign_lock_key(struct lockdep_map *lock) · 70 unmodified lines
968973 else {
969974 /* Debug-check: all keys must be persistent! */
970975 debug_locks_off();
976+ nbcon_cpu_emergency_enter();
971977 pr_err("INFO: trying to register non-static key.\n");
972978 pr_err("The code is fine but needs lockdep annotation, or maybe\n");
973979 pr_err("you didn't initialize this object before use?\n");
974980 pr_err("turning off the locking correctness validator.\n");
975981 dump_stack();
982+ nbcon_cpu_emergency_exit();
976983 return false;
977984 }
978985
@@ -1316,8 +1323,10 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force) · 337 unmodified lines
13161323 return NULL;
13171324 }
13181325
1326+ nbcon_cpu_emergency_enter();
13191327 print_lockdep_off("BUG: MAX_LOCKDEP_KEYS too low!");
13201328 dump_stack();
1329+ nbcon_cpu_emergency_exit();
13211330 return NULL;
13221331 }
13231332 nr_lock_classes++;
@@ -1349,11 +1358,13 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force) · 25 unmodified lines
13491358 if (verbose(class)) {
13501359 graph_unlock();
13511360
1361+ nbcon_cpu_emergency_enter();
13521362 printk("\nnew class %px: %s", class->key, class->name);
13531363 if (class->name_version > 1)
13541364 printk(KERN_CONT "#%d", class->name_version);
13551365 printk(KERN_CONT "\n");
13561366 dump_stack();
1367+ nbcon_cpu_emergency_exit();
13571368
13581369 if (!graph_lock()) {
13591370 return NULL;
@@ -1392,8 +1403,10 @@ static struct lock_list *alloc_list_entry(void) · 32 unmodified lines
13921403 if (!debug_locks_off_graph_unlock())
13931404 return NULL;
13941405
1406+ nbcon_cpu_emergency_enter();
13951407 print_lockdep_off("BUG: MAX_LOCKDEP_ENTRIES too low!");
13961408 dump_stack();
1409+ nbcon_cpu_emergency_exit();
13971410 return NULL;
13981411 }
13991412 nr_list_entries++;
@@ -2039,6 +2052,8 @@ static noinline void print_circular_bug(struct lock_list *this, · 639 unmodified lines
20392052
20402053 depth = get_lock_depth(target);
20412054
2055+ nbcon_cpu_emergency_enter();
2056+
20422057 print_circular_bug_header(target, depth, check_src, check_tgt);
20432058
20442059 parent = get_lock_parent(target);
@@ -2057,6 +2072,8 @@ static noinline void print_circular_bug(struct lock_list *this, · 12 unmodified lines
20572072
20582073 printk("\nstack backtrace:\n");
20592074 dump_stack();
2075+
2076+ nbcon_cpu_emergency_exit();
20602077 }
20612078
20622079 static noinline void print_bfs_bug(int ret)
@@ -2569,6 +2586,8 @@ print_bad_irq_dependency(struct task_struct *curr, · 506 unmodified lines
25692586 if (!debug_locks_off_graph_unlock() || debug_locks_silent)
25702587 return;
25712588
2589+ nbcon_cpu_emergency_enter();
2590+
25722591 pr_warn("\n");
25732592 pr_warn("=====================================================\n");
25742593 pr_warn("WARNING: %s-safe -> %s-unsafe lock order detected\n",
@@ -2618,11 +2637,13 @@ print_bad_irq_dependency(struct task_struct *curr, · 43 unmodified lines
26182637 pr_warn(" and %s-irq-unsafe lock:\n", irqclass);
26192638 next_root->trace = save_trace();
26202639 if (!next_root->trace)
2621− return;
2640+ goto out;
26222641 print_shortest_lock_dependencies(forwards_entry, next_root);
26232642
26242643 pr_warn("\nstack backtrace:\n");
26252644 dump_stack();
2645+out:
2646+ nbcon_cpu_emergency_exit();
26262647 }
26272648
26282649 static const char *state_names[] = {
@@ -2987,6 +3008,8 @@ print_deadlock_bug(struct task_struct *curr, struct held_lock *prev, · 358 unmodified lines
29873008 if (!debug_locks_off_graph_unlock() || debug_locks_silent)
29883009 return;
29893010
3011+ nbcon_cpu_emergency_enter();
3012+
29903013 pr_warn("\n");
29913014 pr_warn("============================================\n");
29923015 pr_warn("WARNING: possible recursive locking detected\n");
@@ -3009,6 +3032,8 @@ print_deadlock_bug(struct task_struct *curr, struct held_lock *prev, · 16 unmodified lines
30093032
30103033 pr_warn("\nstack backtrace:\n");
30113034 dump_stack();
3035+
3036+ nbcon_cpu_emergency_exit();
30123037 }
30133038
30143039 /*
@@ -3606,6 +3631,8 @@ static void print_collision(struct task_struct *curr, · 591 unmodified lines
36063631 struct held_lock *hlock_next,
36073632 struct lock_chain *chain)
36083633 {
3634+ nbcon_cpu_emergency_enter();
3635+
36093636 pr_warn("\n");
36103637 pr_warn("============================\n");
36113638 pr_warn("WARNING: chain_key collision\n");
@@ -3622,6 +3649,8 @@ static void print_collision(struct task_struct *curr, · 10 unmodified lines
36223649
36233650 pr_warn("\nstack backtrace:\n");
36243651 dump_stack();
3652+
3653+ nbcon_cpu_emergency_exit();
36253654 }
36263655 #endif
36273656
@@ -3712,8 +3741,10 @@ static inline int add_chain_cache(struct task_struct *curr, · 84 unmodified lines
37123741 if (!debug_locks_off_graph_unlock())
37133742 return 0;
37143743
3744+ nbcon_cpu_emergency_enter();
37153745 print_lockdep_off("BUG: MAX_LOCKDEP_CHAINS too low!");
37163746 dump_stack();
3747+ nbcon_cpu_emergency_exit();
37173748 return 0;
37183749 }
37193750 chain->chain_key = chain_key;
@@ -3730,8 +3761,10 @@ static inline int add_chain_cache(struct task_struct *curr, · 10 unmodified lines
37303761 if (!debug_locks_off_graph_unlock())
37313762 return 0;
37323763
3764+ nbcon_cpu_emergency_enter();
37333765 print_lockdep_off("BUG: MAX_LOCKDEP_CHAIN_HLOCKS too low!");
37343766 dump_stack();
3767+ nbcon_cpu_emergency_exit();
37353768 return 0;
37363769 }
37373770
@@ -3970,6 +4003,8 @@ print_usage_bug(struct task_struct *curr, struct held_lock *this, · 232 unmodified lines
39704003 if (!debug_locks_off() || debug_locks_silent)
39714004 return;
39724005
4006+ nbcon_cpu_emergency_enter();
4007+
39734008 pr_warn("\n");
39744009 pr_warn("================================\n");
39754010 pr_warn("WARNING: inconsistent lock state\n");
@@ -3998,6 +4033,8 @@ print_usage_bug(struct task_struct *curr, struct held_lock *this, · 22 unmodified lines
39984033
39994034 pr_warn("\nstack backtrace:\n");
40004035 dump_stack();
4036+
4037+ nbcon_cpu_emergency_exit();
40014038 }
40024039
40034040 /*
@@ -4032,6 +4069,8 @@ print_irq_inversion_bug(struct task_struct *curr, · 28 unmodified lines
40324069 if (!debug_locks_off_graph_unlock() || debug_locks_silent)
40334070 return;
40344071
4072+ nbcon_cpu_emergency_enter();
4073+
40354074 pr_warn("\n");
40364075 pr_warn("========================================================\n");
40374076 pr_warn("WARNING: possible irq lock inversion dependency detected\n");
@@ -4072,11 +4111,13 @@ print_irq_inversion_bug(struct task_struct *curr, · 34 unmodified lines
40724111 pr_warn("\nthe shortest dependencies between 2nd lock and 1st lock:\n");
40734112 root->trace = save_trace();
40744113 if (!root->trace)
4075− return;
4114+ goto out;
40764115 print_shortest_lock_dependencies(other, root);
40774116
40784117 pr_warn("\nstack backtrace:\n");
40794118 dump_stack();
4119+out:
4120+ nbcon_cpu_emergency_exit();
40804121 }
40814122
40824123 /*
@@ -4153,6 +4194,8 @@ void print_irqtrace_events(struct task_struct *curr) · 70 unmodified lines
41534194 {
41544195 const struct irqtrace_events *trace = &curr->irqtrace;
41554196
4197+ nbcon_cpu_emergency_enter();
4198+
41564199 printk("irq event stamp: %u\n", trace->irq_events);
41574200 printk("hardirqs last enabled at (%u): [<%px>] %pS\n",
41584201 trace->hardirq_enable_event, (void *)trace->hardirq_enable_ip,
@@ -4166,6 +4209,8 @@ void print_irqtrace_events(struct task_struct *curr) · 7 unmodified lines
41664209 printk("softirqs last disabled at (%u): [<%px>] %pS\n",
41674210 trace->softirq_disable_event, (void *)trace->softirq_disable_ip,
41684211 (void *)trace->softirq_disable_ip);
4212+
4213+ nbcon_cpu_emergency_exit();
41694214 }
41704215
41714216 static int HARDIRQ_verbose(struct lock_class *class)
@@ -4686,10 +4731,12 @@ unlock: · 514 unmodified lines
46864731 * We must printk outside of the graph_lock:
46874732 */
46884733 if (ret == 2) {
4734+ nbcon_cpu_emergency_enter();
46894735 printk("\nmarked lock as {%s}:\n", usage_str[new_bit]);
46904736 print_lock(this);
46914737 print_irqtrace_events(curr);
46924738 dump_stack();
4739+ nbcon_cpu_emergency_exit();
46934740 }
46944741
46954742 return ret;
@@ -4730,6 +4777,8 @@ print_lock_invalid_wait_context(struct task_struct *curr, · 34 unmodified lines
47304777 if (debug_locks_silent)
47314778 return 0;
47324779
4780+ nbcon_cpu_emergency_enter();
4781+
47334782 pr_warn("\n");
47344783 pr_warn("=============================\n");
47354784 pr_warn("[ BUG: Invalid wait context ]\n");
@@ -4749,6 +4798,8 @@ print_lock_invalid_wait_context(struct task_struct *curr, · 13 unmodified lines
47494798 pr_warn("stack backtrace:\n");
47504799 dump_stack();
47514800
4801+ nbcon_cpu_emergency_exit();
4802+
47524803 return 0;
47534804 }
47544805
@@ -4956,6 +5007,8 @@ print_lock_nested_lock_not_held(struct task_struct *curr, · 201 unmodified lines
49565007 if (debug_locks_silent)
49575008 return;
49585009
5010+ nbcon_cpu_emergency_enter();
5011+
49595012 pr_warn("\n");
49605013 pr_warn("==================================\n");
49615014 pr_warn("WARNING: Nested lock was not taken\n");
@@ -4976,6 +5029,8 @@ print_lock_nested_lock_not_held(struct task_struct *curr, · 14 unmodified lines
49765029
49775030 pr_warn("\nstack backtrace:\n");
49785031 dump_stack();
5032+
5033+ nbcon_cpu_emergency_exit();
49795034 }
49805035
49815036 static int __lock_is_held(const struct lockdep_map *lock, int read);
@@ -5024,11 +5079,13 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, · 42 unmodified lines
50245079 debug_class_ops_inc(class);
50255080
50265081 if (very_verbose(class)) {
5082+ nbcon_cpu_emergency_enter();
50275083 printk("\nacquire class [%px] %s", class->key, class->name);
50285084 if (class->name_version > 1)
50295085 printk(KERN_CONT "#%d", class->name_version);
50305086 printk(KERN_CONT "\n");
50315087 dump_stack();
5088+ nbcon_cpu_emergency_exit();
50325089 }
50335090
50345091 /*
@@ -5155,6 +5212,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, · 120 unmodified lines
51555212 #endif
51565213 if (unlikely(curr->lockdep_depth >= MAX_LOCK_DEPTH)) {
51575214 debug_locks_off();
5215+ nbcon_cpu_emergency_enter();
51585216 print_lockdep_off("BUG: MAX_LOCK_DEPTH too low!");
51595217 printk(KERN_DEBUG "depth: %i max: %lu!\n",
51605218 curr->lockdep_depth, MAX_LOCK_DEPTH);
@@ -5162,6 +5220,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, · 1 unmodified line
51625220 lockdep_print_held_locks(current);
51635221 debug_show_all_locks();
51645222 dump_stack();
5223+ nbcon_cpu_emergency_exit();
51655224
51665225 return 0;
51675226 }
@@ -5181,6 +5240,8 @@ static void print_unlock_imbalance_bug(struct task_struct *curr, · 13 unmodified lines
51815240 if (debug_locks_silent)
51825241 return;
51835242
5243+ nbcon_cpu_emergency_enter();
5244+
51845245 pr_warn("\n");
51855246 pr_warn("=====================================\n");
51865247 pr_warn("WARNING: bad unlock balance detected!\n");
@@ -5197,6 +5258,8 @@ static void print_unlock_imbalance_bug(struct task_struct *curr, · 10 unmodified lines
51975258
51985259 pr_warn("\nstack backtrace:\n");
51995260 dump_stack();
5261+
5262+ nbcon_cpu_emergency_exit();
52005263 }
52015264
52025265 static noinstr int match_held_lock(const struct held_lock *hlock,
@@ -5901,6 +5964,8 @@ static void print_lock_contention_bug(struct task_struct *curr, · 698 unmodified lines
59015964 if (debug_locks_silent)
59025965 return;
59035966
5967+ nbcon_cpu_emergency_enter();
5968+
59045969 pr_warn("\n");
59055970 pr_warn("=================================\n");
59065971 pr_warn("WARNING: bad contention detected!\n");
@@ -5917,6 +5982,8 @@ static void print_lock_contention_bug(struct task_struct *curr, · 10 unmodified lines
59175982
59185983 pr_warn("\nstack backtrace:\n");
59195984 dump_stack();
5985+
5986+ nbcon_cpu_emergency_exit();
59205987 }
59215988
59225989 static void
@@ -6536,6 +6603,8 @@ print_freed_lock_bug(struct task_struct *curr, const void *mem_from, · 613 unmodified lines
65366603 if (debug_locks_silent)
65376604 return;
65386605
6606+ nbcon_cpu_emergency_enter();
6607+
65396608 pr_warn("\n");
65406609 pr_warn("=========================\n");
65416610 pr_warn("WARNING: held lock freed!\n");
@@ -6548,6 +6617,8 @@ print_freed_lock_bug(struct task_struct *curr, const void *mem_from, · 6 unmodified lines
65486617
65496618 pr_warn("\nstack backtrace:\n");
65506619 dump_stack();
6620+
6621+ nbcon_cpu_emergency_exit();
65516622 }
65526623
65536624 static inline int not_in_range(const void* mem_from, unsigned long mem_len,
@@ -6594,6 +6665,8 @@ static void print_held_locks_bug(void) · 40 unmodified lines
65946665 if (debug_locks_silent)
65956666 return;
65966667
6668+ nbcon_cpu_emergency_enter();
6669+
65976670 pr_warn("\n");
65986671 pr_warn("====================================\n");
65996672 pr_warn("WARNING: %s/%d still has locks held!\n",
@@ -6603,6 +6676,8 @@ static void print_held_locks_bug(void) · 3 unmodified lines
66036676 lockdep_print_held_locks(current);
66046677 pr_warn("\nstack backtrace:\n");
66056678 dump_stack();
6679+
6680+ nbcon_cpu_emergency_exit();
66066681 }
66076682
66086683 void debug_check_no_locks_held(void)
@@ -6660,6 +6735,7 @@ asmlinkage __visible void lockdep_sys_exit(void) · 51 unmodified lines
66606735 if (unlikely(curr->lockdep_depth)) {
66616736 if (!debug_locks_off())
66626737 return;
6738+ nbcon_cpu_emergency_enter();
66636739 pr_warn("\n");
66646740 pr_warn("================================================\n");
66656741 pr_warn("WARNING: lock held when returning to user space!\n");
@@ -6668,6 +6744,7 @@ asmlinkage __visible void lockdep_sys_exit(void) · 2 unmodified lines
66686744 pr_warn("%s/%d is leaving the kernel with locks still held!\n",
66696745 curr->comm, curr->pid);
66706746 lockdep_print_held_locks(curr);
6747+ nbcon_cpu_emergency_exit();
66716748 }
66726749
66736750 /*
@@ -6684,6 +6761,7 @@ void lockdep_rcu_suspicious(const char *file, const int line, const char *s) · 10 unmodified lines
66846761 bool rcu = warn_rcu_enter();
66856762
66866763 /* Note: the following can be executed concurrently, so be careful. */
6764+ nbcon_cpu_emergency_enter();
66876765 pr_warn("\n");
66886766 pr_warn("=============================\n");
66896767 pr_warn("WARNING: suspicious RCU usage\n");
@@ -6722,6 +6800,7 @@ void lockdep_rcu_suspicious(const char *file, const int line, const char *s) · 32 unmodified lines
67226800 lockdep_print_held_locks(curr);
67236801 pr_warn("\nstack backtrace:\n");
67246802 dump_stack();
6803+ nbcon_cpu_emergency_exit();
67256804 warn_rcu_exit(rcu);
67266805 }
67276806 EXPORT_SYMBOL_GPL(lockdep_rcu_suspicious);