Skip to content

Commit 6595b4a

Browse files
committed
Merge branch 'core-locking-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'core-locking-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: seqlock: Don't smp_rmb in seqlock reader spin loop watchdog, hung_task_timeout: Add Kconfig configurable default lockdep: Remove cmpxchg to update nr_chain_hlocks lockdep: Print a nicer description for simple irq lock inversions lockdep: Replace "Bad BFS generated tree" message with something less cryptic lockdep: Print a nicer description for irq inversion bugs lockdep: Print a nicer description for simple deadlocks lockdep: Print a nicer description for normal deadlocks lockdep: Print a nicer description for irq lock inversions
2 parents cbdad8d + 5db1256 commit 6595b4a

File tree

4 files changed

+213
-14
lines changed

4 files changed

+213
-14
lines changed

include/linux/seqlock.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ static __always_inline unsigned read_seqbegin(const seqlock_t *sl)
8888
unsigned ret;
8989

9090
repeat:
91-
ret = sl->sequence;
92-
smp_rmb();
91+
ret = ACCESS_ONCE(sl->sequence);
9392
if (unlikely(ret & 1)) {
9493
cpu_relax();
9594
goto repeat;
9695
}
96+
smp_rmb();
9797

9898
return ret;
9999
}

kernel/hung_task.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ unsigned long __read_mostly sysctl_hung_task_check_count = PID_MAX_LIMIT;
3333
/*
3434
* Zero means infinite timeout - no checking done:
3535
*/
36-
unsigned long __read_mostly sysctl_hung_task_timeout_secs = 120;
36+
unsigned long __read_mostly sysctl_hung_task_timeout_secs = CONFIG_DEFAULT_HUNG_TASK_TIMEOUT;
3737

3838
unsigned long __read_mostly sysctl_hung_task_warnings = 10;
3939

kernel/lockdep.c

+195-11
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,18 @@ void get_usage_chars(struct lock_class *class, char usage[LOCK_USAGE_CHARS])
490490
usage[i] = '\0';
491491
}
492492

493+
static int __print_lock_name(struct lock_class *class)
494+
{
495+
char str[KSYM_NAME_LEN];
496+
const char *name;
497+
498+
name = class->name;
499+
if (!name)
500+
name = __get_key_name(class->key, str);
501+
502+
return printk("%s", name);
503+
}
504+
493505
static void print_lock_name(struct lock_class *class)
494506
{
495507
char str[KSYM_NAME_LEN], usage[LOCK_USAGE_CHARS];
@@ -1053,6 +1065,56 @@ print_circular_bug_entry(struct lock_list *target, int depth)
10531065
return 0;
10541066
}
10551067

1068+
static void
1069+
print_circular_lock_scenario(struct held_lock *src,
1070+
struct held_lock *tgt,
1071+
struct lock_list *prt)
1072+
{
1073+
struct lock_class *source = hlock_class(src);
1074+
struct lock_class *target = hlock_class(tgt);
1075+
struct lock_class *parent = prt->class;
1076+
1077+
/*
1078+
* A direct locking problem where unsafe_class lock is taken
1079+
* directly by safe_class lock, then all we need to show
1080+
* is the deadlock scenario, as it is obvious that the
1081+
* unsafe lock is taken under the safe lock.
1082+
*
1083+
* But if there is a chain instead, where the safe lock takes
1084+
* an intermediate lock (middle_class) where this lock is
1085+
* not the same as the safe lock, then the lock chain is
1086+
* used to describe the problem. Otherwise we would need
1087+
* to show a different CPU case for each link in the chain
1088+
* from the safe_class lock to the unsafe_class lock.
1089+
*/
1090+
if (parent != source) {
1091+
printk("Chain exists of:\n ");
1092+
__print_lock_name(source);
1093+
printk(" --> ");
1094+
__print_lock_name(parent);
1095+
printk(" --> ");
1096+
__print_lock_name(target);
1097+
printk("\n\n");
1098+
}
1099+
1100+
printk(" Possible unsafe locking scenario:\n\n");
1101+
printk(" CPU0 CPU1\n");
1102+
printk(" ---- ----\n");
1103+
printk(" lock(");
1104+
__print_lock_name(target);
1105+
printk(");\n");
1106+
printk(" lock(");
1107+
__print_lock_name(parent);
1108+
printk(");\n");
1109+
printk(" lock(");
1110+
__print_lock_name(target);
1111+
printk(");\n");
1112+
printk(" lock(");
1113+
__print_lock_name(source);
1114+
printk(");\n");
1115+
printk("\n *** DEADLOCK ***\n\n");
1116+
}
1117+
10561118
/*
10571119
* When a circular dependency is detected, print the
10581120
* header first:
@@ -1096,6 +1158,7 @@ static noinline int print_circular_bug(struct lock_list *this,
10961158
{
10971159
struct task_struct *curr = current;
10981160
struct lock_list *parent;
1161+
struct lock_list *first_parent;
10991162
int depth;
11001163

11011164
if (!debug_locks_off_graph_unlock() || debug_locks_silent)
@@ -1109,13 +1172,17 @@ static noinline int print_circular_bug(struct lock_list *this,
11091172
print_circular_bug_header(target, depth, check_src, check_tgt);
11101173

11111174
parent = get_lock_parent(target);
1175+
first_parent = parent;
11121176

11131177
while (parent) {
11141178
print_circular_bug_entry(parent, --depth);
11151179
parent = get_lock_parent(parent);
11161180
}
11171181

11181182
printk("\nother info that might help us debug this:\n\n");
1183+
print_circular_lock_scenario(check_src, check_tgt,
1184+
first_parent);
1185+
11191186
lockdep_print_held_locks(curr);
11201187

11211188
printk("\nstack backtrace:\n");
@@ -1314,7 +1381,7 @@ print_shortest_lock_dependencies(struct lock_list *leaf,
13141381
printk("\n");
13151382

13161383
if (depth == 0 && (entry != root)) {
1317-
printk("lockdep:%s bad BFS generated tree\n", __func__);
1384+
printk("lockdep:%s bad path found in chain graph\n", __func__);
13181385
break;
13191386
}
13201387

@@ -1325,6 +1392,62 @@ print_shortest_lock_dependencies(struct lock_list *leaf,
13251392
return;
13261393
}
13271394

1395+
static void
1396+
print_irq_lock_scenario(struct lock_list *safe_entry,
1397+
struct lock_list *unsafe_entry,
1398+
struct lock_class *prev_class,
1399+
struct lock_class *next_class)
1400+
{
1401+
struct lock_class *safe_class = safe_entry->class;
1402+
struct lock_class *unsafe_class = unsafe_entry->class;
1403+
struct lock_class *middle_class = prev_class;
1404+
1405+
if (middle_class == safe_class)
1406+
middle_class = next_class;
1407+
1408+
/*
1409+
* A direct locking problem where unsafe_class lock is taken
1410+
* directly by safe_class lock, then all we need to show
1411+
* is the deadlock scenario, as it is obvious that the
1412+
* unsafe lock is taken under the safe lock.
1413+
*
1414+
* But if there is a chain instead, where the safe lock takes
1415+
* an intermediate lock (middle_class) where this lock is
1416+
* not the same as the safe lock, then the lock chain is
1417+
* used to describe the problem. Otherwise we would need
1418+
* to show a different CPU case for each link in the chain
1419+
* from the safe_class lock to the unsafe_class lock.
1420+
*/
1421+
if (middle_class != unsafe_class) {
1422+
printk("Chain exists of:\n ");
1423+
__print_lock_name(safe_class);
1424+
printk(" --> ");
1425+
__print_lock_name(middle_class);
1426+
printk(" --> ");
1427+
__print_lock_name(unsafe_class);
1428+
printk("\n\n");
1429+
}
1430+
1431+
printk(" Possible interrupt unsafe locking scenario:\n\n");
1432+
printk(" CPU0 CPU1\n");
1433+
printk(" ---- ----\n");
1434+
printk(" lock(");
1435+
__print_lock_name(unsafe_class);
1436+
printk(");\n");
1437+
printk(" local_irq_disable();\n");
1438+
printk(" lock(");
1439+
__print_lock_name(safe_class);
1440+
printk(");\n");
1441+
printk(" lock(");
1442+
__print_lock_name(middle_class);
1443+
printk(");\n");
1444+
printk(" <Interrupt>\n");
1445+
printk(" lock(");
1446+
__print_lock_name(safe_class);
1447+
printk(");\n");
1448+
printk("\n *** DEADLOCK ***\n\n");
1449+
}
1450+
13281451
static int
13291452
print_bad_irq_dependency(struct task_struct *curr,
13301453
struct lock_list *prev_root,
@@ -1376,6 +1499,9 @@ print_bad_irq_dependency(struct task_struct *curr,
13761499
print_stack_trace(forwards_entry->class->usage_traces + bit2, 1);
13771500

13781501
printk("\nother info that might help us debug this:\n\n");
1502+
print_irq_lock_scenario(backwards_entry, forwards_entry,
1503+
hlock_class(prev), hlock_class(next));
1504+
13791505
lockdep_print_held_locks(curr);
13801506

13811507
printk("\nthe dependencies between %s-irq-safe lock", irqclass);
@@ -1539,6 +1665,26 @@ static inline void inc_chains(void)
15391665

15401666
#endif
15411667

1668+
static void
1669+
print_deadlock_scenario(struct held_lock *nxt,
1670+
struct held_lock *prv)
1671+
{
1672+
struct lock_class *next = hlock_class(nxt);
1673+
struct lock_class *prev = hlock_class(prv);
1674+
1675+
printk(" Possible unsafe locking scenario:\n\n");
1676+
printk(" CPU0\n");
1677+
printk(" ----\n");
1678+
printk(" lock(");
1679+
__print_lock_name(prev);
1680+
printk(");\n");
1681+
printk(" lock(");
1682+
__print_lock_name(next);
1683+
printk(");\n");
1684+
printk("\n *** DEADLOCK ***\n\n");
1685+
printk(" May be due to missing lock nesting notation\n\n");
1686+
}
1687+
15421688
static int
15431689
print_deadlock_bug(struct task_struct *curr, struct held_lock *prev,
15441690
struct held_lock *next)
@@ -1557,6 +1703,7 @@ print_deadlock_bug(struct task_struct *curr, struct held_lock *prev,
15571703
print_lock(prev);
15581704

15591705
printk("\nother info that might help us debug this:\n");
1706+
print_deadlock_scenario(next, prev);
15601707
lockdep_print_held_locks(curr);
15611708

15621709
printk("\nstack backtrace:\n");
@@ -1826,7 +1973,7 @@ static inline int lookup_chain_cache(struct task_struct *curr,
18261973
struct list_head *hash_head = chainhashentry(chain_key);
18271974
struct lock_chain *chain;
18281975
struct held_lock *hlock_curr, *hlock_next;
1829-
int i, j, n, cn;
1976+
int i, j;
18301977

18311978
if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
18321979
return 0;
@@ -1886,15 +2033,9 @@ static inline int lookup_chain_cache(struct task_struct *curr,
18862033
}
18872034
i++;
18882035
chain->depth = curr->lockdep_depth + 1 - i;
1889-
cn = nr_chain_hlocks;
1890-
while (cn + chain->depth <= MAX_LOCKDEP_CHAIN_HLOCKS) {
1891-
n = cmpxchg(&nr_chain_hlocks, cn, cn + chain->depth);
1892-
if (n == cn)
1893-
break;
1894-
cn = n;
1895-
}
1896-
if (likely(cn + chain->depth <= MAX_LOCKDEP_CHAIN_HLOCKS)) {
1897-
chain->base = cn;
2036+
if (likely(nr_chain_hlocks + chain->depth <= MAX_LOCKDEP_CHAIN_HLOCKS)) {
2037+
chain->base = nr_chain_hlocks;
2038+
nr_chain_hlocks += chain->depth;
18982039
for (j = 0; j < chain->depth - 1; j++, i++) {
18992040
int lock_id = curr->held_locks[i].class_idx - 1;
19002041
chain_hlocks[chain->base + j] = lock_id;
@@ -2011,6 +2152,24 @@ static void check_chain_key(struct task_struct *curr)
20112152
#endif
20122153
}
20132154

2155+
static void
2156+
print_usage_bug_scenario(struct held_lock *lock)
2157+
{
2158+
struct lock_class *class = hlock_class(lock);
2159+
2160+
printk(" Possible unsafe locking scenario:\n\n");
2161+
printk(" CPU0\n");
2162+
printk(" ----\n");
2163+
printk(" lock(");
2164+
__print_lock_name(class);
2165+
printk(");\n");
2166+
printk(" <Interrupt>\n");
2167+
printk(" lock(");
2168+
__print_lock_name(class);
2169+
printk(");\n");
2170+
printk("\n *** DEADLOCK ***\n\n");
2171+
}
2172+
20142173
static int
20152174
print_usage_bug(struct task_struct *curr, struct held_lock *this,
20162175
enum lock_usage_bit prev_bit, enum lock_usage_bit new_bit)
@@ -2039,6 +2198,8 @@ print_usage_bug(struct task_struct *curr, struct held_lock *this,
20392198

20402199
print_irqtrace_events(curr);
20412200
printk("\nother info that might help us debug this:\n");
2201+
print_usage_bug_scenario(this);
2202+
20422203
lockdep_print_held_locks(curr);
20432204

20442205
printk("\nstack backtrace:\n");
@@ -2073,6 +2234,10 @@ print_irq_inversion_bug(struct task_struct *curr,
20732234
struct held_lock *this, int forwards,
20742235
const char *irqclass)
20752236
{
2237+
struct lock_list *entry = other;
2238+
struct lock_list *middle = NULL;
2239+
int depth;
2240+
20762241
if (!debug_locks_off_graph_unlock() || debug_locks_silent)
20772242
return 0;
20782243

@@ -2091,6 +2256,25 @@ print_irq_inversion_bug(struct task_struct *curr,
20912256
printk("\n\nand interrupts could create inverse lock ordering between them.\n\n");
20922257

20932258
printk("\nother info that might help us debug this:\n");
2259+
2260+
/* Find a middle lock (if one exists) */
2261+
depth = get_lock_depth(other);
2262+
do {
2263+
if (depth == 0 && (entry != root)) {
2264+
printk("lockdep:%s bad path found in chain graph\n", __func__);
2265+
break;
2266+
}
2267+
middle = entry;
2268+
entry = get_lock_parent(entry);
2269+
depth--;
2270+
} while (entry && entry != root && (depth >= 0));
2271+
if (forwards)
2272+
print_irq_lock_scenario(root, other,
2273+
middle ? middle->class : root->class, other->class);
2274+
else
2275+
print_irq_lock_scenario(other, root,
2276+
middle ? middle->class : other->class, root->class);
2277+
20942278
lockdep_print_held_locks(curr);
20952279

20962280
printk("\nthe shortest dependencies between 2nd lock and 1st lock:\n");

lib/Kconfig.debug

+15
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,21 @@ config DETECT_HUNG_TASK
238238
enabled then all held locks will also be reported. This
239239
feature has negligible overhead.
240240

241+
config DEFAULT_HUNG_TASK_TIMEOUT
242+
int "Default timeout for hung task detection (in seconds)"
243+
depends on DETECT_HUNG_TASK
244+
default 120
245+
help
246+
This option controls the default timeout (in seconds) used
247+
to determine when a task has become non-responsive and should
248+
be considered hung.
249+
250+
It can be adjusted at runtime via the kernel.hung_task_timeout
251+
sysctl or by writing a value to /proc/sys/kernel/hung_task_timeout.
252+
253+
A timeout of 0 disables the check. The default is two minutes.
254+
Keeping the default should be fine in most cases.
255+
241256
config BOOTPARAM_HUNG_TASK_PANIC
242257
bool "Panic (Reboot) On Hung Tasks"
243258
depends on DETECT_HUNG_TASK

0 commit comments

Comments
 (0)