Skip to content

Commit f943fe0

Browse files
dvyukovIngo Molnar
authored and
Ingo Molnar
committed
lockdep: Fix report formatting
Since commit: 4bcc595 ("printk: reinstate KERN_CONT for printing continuation lines") printk() requires KERN_CONT to continue log messages. Lots of printk() in lockdep.c and print_ip_sym() don't have it. As the result lockdep reports are completely messed up. Add missing KERN_CONT and inline print_ip_sym() where necessary. Example of a messed up report: 0-rc5+ torvalds#41 Not tainted ------------------------------------------------------- syz-executor0/5036 is trying to acquire lock: ( rtnl_mutex ){+.+.+.} , at: [<ffffffff86b3d6ac>] rtnl_lock+0x1c/0x20 but task is already holding lock: ( &net->packet.sklist_lock ){+.+...} , at: [<ffffffff873541a6>] packet_diag_dump+0x1a6/0x1920 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #3 ( &net->packet.sklist_lock +.+...} ... Without this patch all scripts that parse kernel bug reports are broken. Signed-off-by: Dmitry Vyukov <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 1be5d4f commit f943fe0

File tree

1 file changed

+57
-54
lines changed

1 file changed

+57
-54
lines changed

kernel/locking/lockdep.c

+57-54
Original file line numberDiff line numberDiff line change
@@ -506,13 +506,13 @@ static void __print_lock_name(struct lock_class *class)
506506
name = class->name;
507507
if (!name) {
508508
name = __get_key_name(class->key, str);
509-
printk("%s", name);
509+
printk(KERN_CONT "%s", name);
510510
} else {
511-
printk("%s", name);
511+
printk(KERN_CONT "%s", name);
512512
if (class->name_version > 1)
513-
printk("#%d", class->name_version);
513+
printk(KERN_CONT "#%d", class->name_version);
514514
if (class->subclass)
515-
printk("/%d", class->subclass);
515+
printk(KERN_CONT "/%d", class->subclass);
516516
}
517517
}
518518

@@ -522,9 +522,9 @@ static void print_lock_name(struct lock_class *class)
522522

523523
get_usage_chars(class, usage);
524524

525-
printk(" (");
525+
printk(KERN_CONT " (");
526526
__print_lock_name(class);
527-
printk("){%s}", usage);
527+
printk(KERN_CONT "){%s}", usage);
528528
}
529529

530530
static void print_lockdep_cache(struct lockdep_map *lock)
@@ -536,7 +536,7 @@ static void print_lockdep_cache(struct lockdep_map *lock)
536536
if (!name)
537537
name = __get_key_name(lock->key->subkeys, str);
538538

539-
printk("%s", name);
539+
printk(KERN_CONT "%s", name);
540540
}
541541

542542
static void print_lock(struct held_lock *hlock)
@@ -551,13 +551,13 @@ static void print_lock(struct held_lock *hlock)
551551
barrier();
552552

553553
if (!class_idx || (class_idx - 1) >= MAX_LOCKDEP_KEYS) {
554-
printk("<RELEASED>\n");
554+
printk(KERN_CONT "<RELEASED>\n");
555555
return;
556556
}
557557

558558
print_lock_name(lock_classes + class_idx - 1);
559-
printk(", at: ");
560-
print_ip_sym(hlock->acquire_ip);
559+
printk(KERN_CONT ", at: [<%p>] %pS\n",
560+
(void *)hlock->acquire_ip, (void *)hlock->acquire_ip);
561561
}
562562

563563
static void lockdep_print_held_locks(struct task_struct *curr)
@@ -792,8 +792,8 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
792792

793793
printk("\nnew class %p: %s", class->key, class->name);
794794
if (class->name_version > 1)
795-
printk("#%d", class->name_version);
796-
printk("\n");
795+
printk(KERN_CONT "#%d", class->name_version);
796+
printk(KERN_CONT "\n");
797797
dump_stack();
798798

799799
if (!graph_lock()) {
@@ -1071,7 +1071,7 @@ print_circular_bug_entry(struct lock_list *target, int depth)
10711071
return 0;
10721072
printk("\n-> #%u", depth);
10731073
print_lock_name(target->class);
1074-
printk(":\n");
1074+
printk(KERN_CONT ":\n");
10751075
print_stack_trace(&target->trace, 6);
10761076

10771077
return 0;
@@ -1102,28 +1102,28 @@ print_circular_lock_scenario(struct held_lock *src,
11021102
if (parent != source) {
11031103
printk("Chain exists of:\n ");
11041104
__print_lock_name(source);
1105-
printk(" --> ");
1105+
printk(KERN_CONT " --> ");
11061106
__print_lock_name(parent);
1107-
printk(" --> ");
1107+
printk(KERN_CONT " --> ");
11081108
__print_lock_name(target);
1109-
printk("\n\n");
1109+
printk(KERN_CONT "\n\n");
11101110
}
11111111

11121112
printk(" Possible unsafe locking scenario:\n\n");
11131113
printk(" CPU0 CPU1\n");
11141114
printk(" ---- ----\n");
11151115
printk(" lock(");
11161116
__print_lock_name(target);
1117-
printk(");\n");
1117+
printk(KERN_CONT ");\n");
11181118
printk(" lock(");
11191119
__print_lock_name(parent);
1120-
printk(");\n");
1120+
printk(KERN_CONT ");\n");
11211121
printk(" lock(");
11221122
__print_lock_name(target);
1123-
printk(");\n");
1123+
printk(KERN_CONT ");\n");
11241124
printk(" lock(");
11251125
__print_lock_name(source);
1126-
printk(");\n");
1126+
printk(KERN_CONT ");\n");
11271127
printk("\n *** DEADLOCK ***\n\n");
11281128
}
11291129

@@ -1359,22 +1359,22 @@ static void print_lock_class_header(struct lock_class *class, int depth)
13591359

13601360
printk("%*s->", depth, "");
13611361
print_lock_name(class);
1362-
printk(" ops: %lu", class->ops);
1363-
printk(" {\n");
1362+
printk(KERN_CONT " ops: %lu", class->ops);
1363+
printk(KERN_CONT " {\n");
13641364

13651365
for (bit = 0; bit < LOCK_USAGE_STATES; bit++) {
13661366
if (class->usage_mask & (1 << bit)) {
13671367
int len = depth;
13681368

13691369
len += printk("%*s %s", depth, "", usage_str[bit]);
1370-
len += printk(" at:\n");
1370+
len += printk(KERN_CONT " at:\n");
13711371
print_stack_trace(class->usage_traces + bit, len);
13721372
}
13731373
}
13741374
printk("%*s }\n", depth, "");
13751375

1376-
printk("%*s ... key at: ",depth,"");
1377-
print_ip_sym((unsigned long)class->key);
1376+
printk("%*s ... key at: [<%p>] %pS\n",
1377+
depth, "", class->key, class->key);
13781378
}
13791379

13801380
/*
@@ -1437,30 +1437,30 @@ print_irq_lock_scenario(struct lock_list *safe_entry,
14371437
if (middle_class != unsafe_class) {
14381438
printk("Chain exists of:\n ");
14391439
__print_lock_name(safe_class);
1440-
printk(" --> ");
1440+
printk(KERN_CONT " --> ");
14411441
__print_lock_name(middle_class);
1442-
printk(" --> ");
1442+
printk(KERN_CONT " --> ");
14431443
__print_lock_name(unsafe_class);
1444-
printk("\n\n");
1444+
printk(KERN_CONT "\n\n");
14451445
}
14461446

14471447
printk(" Possible interrupt unsafe locking scenario:\n\n");
14481448
printk(" CPU0 CPU1\n");
14491449
printk(" ---- ----\n");
14501450
printk(" lock(");
14511451
__print_lock_name(unsafe_class);
1452-
printk(");\n");
1452+
printk(KERN_CONT ");\n");
14531453
printk(" local_irq_disable();\n");
14541454
printk(" lock(");
14551455
__print_lock_name(safe_class);
1456-
printk(");\n");
1456+
printk(KERN_CONT ");\n");
14571457
printk(" lock(");
14581458
__print_lock_name(middle_class);
1459-
printk(");\n");
1459+
printk(KERN_CONT ");\n");
14601460
printk(" <Interrupt>\n");
14611461
printk(" lock(");
14621462
__print_lock_name(safe_class);
1463-
printk(");\n");
1463+
printk(KERN_CONT ");\n");
14641464
printk("\n *** DEADLOCK ***\n\n");
14651465
}
14661466

@@ -1497,9 +1497,9 @@ print_bad_irq_dependency(struct task_struct *curr,
14971497
print_lock(prev);
14981498
printk("which would create a new lock dependency:\n");
14991499
print_lock_name(hlock_class(prev));
1500-
printk(" ->");
1500+
printk(KERN_CONT " ->");
15011501
print_lock_name(hlock_class(next));
1502-
printk("\n");
1502+
printk(KERN_CONT "\n");
15031503

15041504
printk("\nbut this new dependency connects a %s-irq-safe lock:\n",
15051505
irqclass);
@@ -1521,8 +1521,7 @@ print_bad_irq_dependency(struct task_struct *curr,
15211521

15221522
lockdep_print_held_locks(curr);
15231523

1524-
printk("\nthe dependencies between %s-irq-safe lock", irqclass);
1525-
printk(" and the holding lock:\n");
1524+
printk("\nthe dependencies between %s-irq-safe lock and the holding lock:\n", irqclass);
15261525
if (!save_trace(&prev_root->trace))
15271526
return 0;
15281527
print_shortest_lock_dependencies(backwards_entry, prev_root);
@@ -1694,10 +1693,10 @@ print_deadlock_scenario(struct held_lock *nxt,
16941693
printk(" ----\n");
16951694
printk(" lock(");
16961695
__print_lock_name(prev);
1697-
printk(");\n");
1696+
printk(KERN_CONT ");\n");
16981697
printk(" lock(");
16991698
__print_lock_name(next);
1700-
printk(");\n");
1699+
printk(KERN_CONT ");\n");
17011700
printk("\n *** DEADLOCK ***\n\n");
17021701
printk(" May be due to missing lock nesting notation\n\n");
17031702
}
@@ -1891,9 +1890,9 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev,
18911890
graph_unlock();
18921891
printk("\n new dependency: ");
18931892
print_lock_name(hlock_class(prev));
1894-
printk(" => ");
1893+
printk(KERN_CONT " => ");
18951894
print_lock_name(hlock_class(next));
1896-
printk("\n");
1895+
printk(KERN_CONT "\n");
18971896
dump_stack();
18981897
return graph_lock();
18991898
}
@@ -2343,11 +2342,11 @@ print_usage_bug_scenario(struct held_lock *lock)
23432342
printk(" ----\n");
23442343
printk(" lock(");
23452344
__print_lock_name(class);
2346-
printk(");\n");
2345+
printk(KERN_CONT ");\n");
23472346
printk(" <Interrupt>\n");
23482347
printk(" lock(");
23492348
__print_lock_name(class);
2350-
printk(");\n");
2349+
printk(KERN_CONT ");\n");
23512350
printk("\n *** DEADLOCK ***\n\n");
23522351
}
23532352

@@ -2522,14 +2521,18 @@ check_usage_backwards(struct task_struct *curr, struct held_lock *this,
25222521
void print_irqtrace_events(struct task_struct *curr)
25232522
{
25242523
printk("irq event stamp: %u\n", curr->irq_events);
2525-
printk("hardirqs last enabled at (%u): ", curr->hardirq_enable_event);
2526-
print_ip_sym(curr->hardirq_enable_ip);
2527-
printk("hardirqs last disabled at (%u): ", curr->hardirq_disable_event);
2528-
print_ip_sym(curr->hardirq_disable_ip);
2529-
printk("softirqs last enabled at (%u): ", curr->softirq_enable_event);
2530-
print_ip_sym(curr->softirq_enable_ip);
2531-
printk("softirqs last disabled at (%u): ", curr->softirq_disable_event);
2532-
print_ip_sym(curr->softirq_disable_ip);
2524+
printk("hardirqs last enabled at (%u): [<%p>] %pS\n",
2525+
curr->hardirq_enable_event, (void *)curr->hardirq_enable_ip,
2526+
(void *)curr->hardirq_enable_ip);
2527+
printk("hardirqs last disabled at (%u): [<%p>] %pS\n",
2528+
curr->hardirq_disable_event, (void *)curr->hardirq_disable_ip,
2529+
(void *)curr->hardirq_disable_ip);
2530+
printk("softirqs last enabled at (%u): [<%p>] %pS\n",
2531+
curr->softirq_enable_event, (void *)curr->softirq_enable_ip,
2532+
(void *)curr->softirq_enable_ip);
2533+
printk("softirqs last disabled at (%u): [<%p>] %pS\n",
2534+
curr->softirq_disable_event, (void *)curr->softirq_disable_ip,
2535+
(void *)curr->softirq_disable_ip);
25332536
}
25342537

25352538
static int HARDIRQ_verbose(struct lock_class *class)
@@ -3235,8 +3238,8 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
32353238
if (very_verbose(class)) {
32363239
printk("\nacquire class [%p] %s", class->key, class->name);
32373240
if (class->name_version > 1)
3238-
printk("#%d", class->name_version);
3239-
printk("\n");
3241+
printk(KERN_CONT "#%d", class->name_version);
3242+
printk(KERN_CONT "\n");
32403243
dump_stack();
32413244
}
32423245

@@ -3378,7 +3381,7 @@ print_unlock_imbalance_bug(struct task_struct *curr, struct lockdep_map *lock,
33783381
printk("%s/%d is trying to release lock (",
33793382
curr->comm, task_pid_nr(curr));
33803383
print_lockdep_cache(lock);
3381-
printk(") at:\n");
3384+
printk(KERN_CONT ") at:\n");
33823385
print_ip_sym(ip);
33833386
printk("but there are no more locks to release!\n");
33843387
printk("\nother info that might help us debug this:\n");
@@ -3871,7 +3874,7 @@ print_lock_contention_bug(struct task_struct *curr, struct lockdep_map *lock,
38713874
printk("%s/%d is trying to contend lock (",
38723875
curr->comm, task_pid_nr(curr));
38733876
print_lockdep_cache(lock);
3874-
printk(") at:\n");
3877+
printk(KERN_CONT ") at:\n");
38753878
print_ip_sym(ip);
38763879
printk("but there are no locks held!\n");
38773880
printk("\nother info that might help us debug this:\n");

0 commit comments

Comments
 (0)