aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/lockdep.c38
-rw-r--r--kernel/lockdep_internals.h6
-rw-r--r--kernel/lockdep_proc.c91
3 files changed, 132 insertions, 3 deletions
diff --git a/kernel/lockdep.c b/kernel/lockdep.c
index 81a4e4a3f087..a796f1f38ac5 100644
--- a/kernel/lockdep.c
+++ b/kernel/lockdep.c
@@ -1458,7 +1458,14 @@ out_bug:
1458} 1458}
1459 1459
1460unsigned long nr_lock_chains; 1460unsigned long nr_lock_chains;
1461static struct lock_chain lock_chains[MAX_LOCKDEP_CHAINS]; 1461struct lock_chain lock_chains[MAX_LOCKDEP_CHAINS];
1462atomic_t nr_chain_hlocks;
1463static u16 chain_hlocks[MAX_LOCKDEP_CHAIN_HLOCKS];
1464
1465struct lock_class *lock_chain_get_class(struct lock_chain *chain, int i)
1466{
1467 return lock_classes + chain_hlocks[chain->base + i];
1468}
1462 1469
1463/* 1470/*
1464 * Look up a dependency chain. If the key is not present yet then 1471 * Look up a dependency chain. If the key is not present yet then
@@ -1466,10 +1473,15 @@ static struct lock_chain lock_chains[MAX_LOCKDEP_CHAINS];
1466 * validated. If the key is already hashed, return 0. 1473 * validated. If the key is already hashed, return 0.
1467 * (On return with 1 graph_lock is held.) 1474 * (On return with 1 graph_lock is held.)
1468 */ 1475 */
1469static inline int lookup_chain_cache(u64 chain_key, struct lock_class *class) 1476static inline int lookup_chain_cache(struct task_struct *curr,
1477 struct held_lock *hlock,
1478 u64 chain_key)
1470{ 1479{
1480 struct lock_class *class = hlock->class;
1471 struct list_head *hash_head = chainhashentry(chain_key); 1481 struct list_head *hash_head = chainhashentry(chain_key);
1472 struct lock_chain *chain; 1482 struct lock_chain *chain;
1483 struct held_lock *hlock_curr, *hlock_next;
1484 int i, j, n;
1473 1485
1474 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) 1486 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
1475 return 0; 1487 return 0;
@@ -1517,6 +1529,26 @@ cache_hit:
1517 } 1529 }
1518 chain = lock_chains + nr_lock_chains++; 1530 chain = lock_chains + nr_lock_chains++;
1519 chain->chain_key = chain_key; 1531 chain->chain_key = chain_key;
1532 chain->irq_context = hlock->irq_context;
1533 /* Find the first held_lock of current chain */
1534 hlock_next = hlock;
1535 for (i = curr->lockdep_depth - 1; i >= 0; i--) {
1536 hlock_curr = curr->held_locks + i;
1537 if (hlock_curr->irq_context != hlock_next->irq_context)
1538 break;
1539 hlock_next = hlock;
1540 }
1541 i++;
1542 chain->depth = curr->lockdep_depth + 1 - i;
1543 n = atomic_add_return(chain->depth, &nr_chain_hlocks);
1544 if (unlikely(n < MAX_LOCKDEP_CHAIN_HLOCKS)) {
1545 chain->base = n - chain->depth;
1546 for (j = 0; j < chain->depth - 1; j++, i++) {
1547 int lock_id = curr->held_locks[i].class - lock_classes;
1548 chain_hlocks[chain->base + j] = lock_id;
1549 }
1550 chain_hlocks[chain->base + j] = class - lock_classes;
1551 }
1520 list_add_tail_rcu(&chain->entry, hash_head); 1552 list_add_tail_rcu(&chain->entry, hash_head);
1521 debug_atomic_inc(&chain_lookup_misses); 1553 debug_atomic_inc(&chain_lookup_misses);
1522 inc_chains(); 1554 inc_chains();
@@ -1538,7 +1570,7 @@ static int validate_chain(struct task_struct *curr, struct lockdep_map *lock,
1538 * graph_lock for us) 1570 * graph_lock for us)
1539 */ 1571 */
1540 if (!hlock->trylock && (hlock->check == 2) && 1572 if (!hlock->trylock && (hlock->check == 2) &&
1541 lookup_chain_cache(chain_key, hlock->class)) { 1573 lookup_chain_cache(curr, hlock, chain_key)) {
1542 /* 1574 /*
1543 * Check whether last held lock: 1575 * Check whether last held lock:
1544 * 1576 *
diff --git a/kernel/lockdep_internals.h b/kernel/lockdep_internals.h
index 8ce09bc4613d..db09b176dd34 100644
--- a/kernel/lockdep_internals.h
+++ b/kernel/lockdep_internals.h
@@ -23,6 +23,8 @@
23#define MAX_LOCKDEP_CHAINS_BITS 14 23#define MAX_LOCKDEP_CHAINS_BITS 14
24#define MAX_LOCKDEP_CHAINS (1UL << MAX_LOCKDEP_CHAINS_BITS) 24#define MAX_LOCKDEP_CHAINS (1UL << MAX_LOCKDEP_CHAINS_BITS)
25 25
26#define MAX_LOCKDEP_CHAIN_HLOCKS (MAX_LOCKDEP_CHAINS*5)
27
26/* 28/*
27 * Stack-trace: tightly packed array of stack backtrace 29 * Stack-trace: tightly packed array of stack backtrace
28 * addresses. Protected by the hash_lock. 30 * addresses. Protected by the hash_lock.
@@ -30,15 +32,19 @@
30#define MAX_STACK_TRACE_ENTRIES 262144UL 32#define MAX_STACK_TRACE_ENTRIES 262144UL
31 33
32extern struct list_head all_lock_classes; 34extern struct list_head all_lock_classes;
35extern struct lock_chain lock_chains[];
33 36
34extern void 37extern void
35get_usage_chars(struct lock_class *class, char *c1, char *c2, char *c3, char *c4); 38get_usage_chars(struct lock_class *class, char *c1, char *c2, char *c3, char *c4);
36 39
37extern const char * __get_key_name(struct lockdep_subclass_key *key, char *str); 40extern const char * __get_key_name(struct lockdep_subclass_key *key, char *str);
38 41
42struct lock_class *lock_chain_get_class(struct lock_chain *chain, int i);
43
39extern unsigned long nr_lock_classes; 44extern unsigned long nr_lock_classes;
40extern unsigned long nr_list_entries; 45extern unsigned long nr_list_entries;
41extern unsigned long nr_lock_chains; 46extern unsigned long nr_lock_chains;
47extern atomic_t nr_chain_hlocks;
42extern unsigned long nr_stack_trace_entries; 48extern unsigned long nr_stack_trace_entries;
43 49
44extern unsigned int nr_hardirq_chains; 50extern unsigned int nr_hardirq_chains;
diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
index 688c5f1940bd..14d052c8a835 100644
--- a/kernel/lockdep_proc.c
+++ b/kernel/lockdep_proc.c
@@ -178,6 +178,93 @@ static const struct file_operations proc_lockdep_operations = {
178 .release = seq_release, 178 .release = seq_release,
179}; 179};
180 180
181static void *lc_next(struct seq_file *m, void *v, loff_t *pos)
182{
183 struct lock_chain *chain;
184
185 (*pos)++;
186
187 if (v == SEQ_START_TOKEN)
188 chain = m->private;
189 else {
190 chain = v;
191
192 if (*pos < nr_lock_chains)
193 chain = lock_chains + *pos;
194 else
195 chain = NULL;
196 }
197
198 return chain;
199}
200
201static void *lc_start(struct seq_file *m, loff_t *pos)
202{
203 if (*pos == 0)
204 return SEQ_START_TOKEN;
205
206 if (*pos < nr_lock_chains)
207 return lock_chains + *pos;
208
209 return NULL;
210}
211
212static void lc_stop(struct seq_file *m, void *v)
213{
214}
215
216static int lc_show(struct seq_file *m, void *v)
217{
218 struct lock_chain *chain = v;
219 struct lock_class *class;
220 int i;
221
222 if (v == SEQ_START_TOKEN) {
223 seq_printf(m, "all lock chains:\n");
224 return 0;
225 }
226
227 seq_printf(m, "irq_context: %d\n", chain->irq_context);
228
229 for (i = 0; i < chain->depth; i++) {
230 class = lock_chain_get_class(chain, i);
231 seq_printf(m, "[%p] ", class->key);
232 print_name(m, class);
233 seq_puts(m, "\n");
234 }
235 seq_puts(m, "\n");
236
237 return 0;
238}
239
240static const struct seq_operations lockdep_chains_ops = {
241 .start = lc_start,
242 .next = lc_next,
243 .stop = lc_stop,
244 .show = lc_show,
245};
246
247static int lockdep_chains_open(struct inode *inode, struct file *file)
248{
249 int res = seq_open(file, &lockdep_chains_ops);
250 if (!res) {
251 struct seq_file *m = file->private_data;
252
253 if (nr_lock_chains)
254 m->private = lock_chains;
255 else
256 m->private = NULL;
257 }
258 return res;
259}
260
261static const struct file_operations proc_lockdep_chains_operations = {
262 .open = lockdep_chains_open,
263 .read = seq_read,
264 .llseek = seq_lseek,
265 .release = seq_release,
266};
267
181static void lockdep_stats_debug_show(struct seq_file *m) 268static void lockdep_stats_debug_show(struct seq_file *m)
182{ 269{
183#ifdef CONFIG_DEBUG_LOCKDEP 270#ifdef CONFIG_DEBUG_LOCKDEP
@@ -294,6 +381,8 @@ static int lockdep_stats_show(struct seq_file *m, void *v)
294#ifdef CONFIG_PROVE_LOCKING 381#ifdef CONFIG_PROVE_LOCKING
295 seq_printf(m, " dependency chains: %11lu [max: %lu]\n", 382 seq_printf(m, " dependency chains: %11lu [max: %lu]\n",
296 nr_lock_chains, MAX_LOCKDEP_CHAINS); 383 nr_lock_chains, MAX_LOCKDEP_CHAINS);
384 seq_printf(m, " dependency chain hlocks: %11d [max: %lu]\n",
385 atomic_read(&nr_chain_hlocks), MAX_LOCKDEP_CHAIN_HLOCKS);
297#endif 386#endif
298 387
299#ifdef CONFIG_TRACE_IRQFLAGS 388#ifdef CONFIG_TRACE_IRQFLAGS
@@ -661,6 +750,8 @@ static const struct file_operations proc_lock_stat_operations = {
661static int __init lockdep_proc_init(void) 750static int __init lockdep_proc_init(void)
662{ 751{
663 proc_create("lockdep", S_IRUSR, NULL, &proc_lockdep_operations); 752 proc_create("lockdep", S_IRUSR, NULL, &proc_lockdep_operations);
753 proc_create("lockdep_chains", S_IRUSR, NULL,
754 &proc_lockdep_chains_operations);
664 proc_create("lockdep_stats", S_IRUSR, NULL, 755 proc_create("lockdep_stats", S_IRUSR, NULL,
665 &proc_lockdep_stats_operations); 756 &proc_lockdep_stats_operations);
666 757