Lines Matching +full:combined +full:- +full:power +full:- +full:req
1 // SPDX-License-Identifier: GPL-2.0-only
15 * - lock inversion scenarios
16 * - circular lock dependencies
17 * - hardirq/softirq safe/unsafe locking bugs
91 if (current->lockdep_recursion) in lockdep_enabled()
102 * to use a raw spinlock - we really dont want the spinlock
181 #define KEYHASH_BITS (MAX_LOCKDEP_KEYS_BITS - 1)
194 unsigned int class_idx = hlock->class_idx; in hlock_class()
196 /* Don't re-read hlock->class_idx, can't use READ_ONCE() on bitfield */ in hlock_class()
208 * At this point, if the passed hlock->class_idx is still garbage, in hlock_class()
240 if (time > lt->max) in lock_time_inc()
241 lt->max = time; in lock_time_inc()
243 if (time < lt->min || !lt->nr) in lock_time_inc()
244 lt->min = time; in lock_time_inc()
246 lt->total += time; in lock_time_inc()
247 lt->nr++; in lock_time_inc()
252 if (!src->nr) in lock_time_add()
255 if (src->max > dst->max) in lock_time_add()
256 dst->max = src->max; in lock_time_add()
258 if (src->min < dst->min || !dst->nr) in lock_time_add()
259 dst->min = src->min; in lock_time_add()
261 dst->total += src->total; in lock_time_add()
262 dst->nr += src->nr; in lock_time_add()
273 &per_cpu(cpu_lock_stats, cpu)[class - lock_classes]; in lock_stats()
276 stats.contention_point[i] += pcs->contention_point[i]; in lock_stats()
279 stats.contending_point[i] += pcs->contending_point[i]; in lock_stats()
281 lock_time_add(&pcs->read_waittime, &stats.read_waittime); in lock_stats()
282 lock_time_add(&pcs->write_waittime, &stats.write_waittime); in lock_stats()
284 lock_time_add(&pcs->read_holdtime, &stats.read_holdtime); in lock_stats()
285 lock_time_add(&pcs->write_holdtime, &stats.write_holdtime); in lock_stats()
288 stats.bounces[i] += pcs->bounces[i]; in lock_stats()
300 &per_cpu(cpu_lock_stats, cpu)[class - lock_classes]; in clear_lock_stats()
304 memset(class->contention_point, 0, sizeof(class->contention_point)); in clear_lock_stats()
305 memset(class->contending_point, 0, sizeof(class->contending_point)); in clear_lock_stats()
310 return &this_cpu_ptr(cpu_lock_stats)[class - lock_classes]; in get_lock_stats()
321 holdtime = lockstat_clock() - hlock->holdtime_stamp; in lock_release_holdtime()
324 if (hlock->read) in lock_release_holdtime()
325 lock_time_inc(&stats->read_holdtime, holdtime); in lock_release_holdtime()
327 lock_time_inc(&stats->write_holdtime, holdtime); in lock_release_holdtime()
345 * struct pending_free - information about data structures about to be freed
356 * struct delayed_free - data structures used for delayed freeing
374 * The lockdep classes are in a hash-table as well, for fast lookup:
376 #define CLASSHASH_BITS (MAX_LOCKDEP_KEYS_BITS - 1)
384 * We put the lock dependency chains into a hash-table as well, to cache
387 #define CHAINHASH_BITS (MAX_LOCKDEP_CHAINS_BITS-1)
401 return (hlock->class_idx | (hlock->read << MAX_LOCKDEP_KEYS_BITS)); in hlock_id()
406 return hlock_id & (MAX_LOCKDEP_KEYS - 1); in chain_hlock_class_idx()
412 * It's a 64-bit hash, because it's important for the keys to be
426 task->lockdep_depth = 0; /* no locks held yet */ in lockdep_init_task()
427 task->curr_chain_key = INITIAL_CHAIN_KEY; in lockdep_init_task()
428 task->lockdep_recursion = 0; in lockdep_init_task()
470 if (class->name_version == 1 && in class_filter()
471 !strcmp(class->name, "lockname")) in class_filter()
473 if (class->name_version == 1 && in class_filter()
474 !strcmp(class->name, "&struct->lockfield")) in class_filter()
503 * struct lock_trace - single stack backtrace
518 * Stack-trace: sequence of lock_trace structures. Protected by the graph_lock.
525 return t1->hash == t2->hash && t1->nr_entries == t2->nr_entries && in traces_identical()
526 memcmp(t1->entries, t2->entries, in traces_identical()
527 t1->nr_entries * sizeof(t1->entries[0])) == 0; in traces_identical()
541 max_entries = MAX_STACK_TRACE_ENTRIES - nr_stack_trace_entries - in save_trace()
553 trace->nr_entries = stack_trace_save(trace->entries, max_entries, 3); in save_trace()
555 hash = jhash(trace->entries, trace->nr_entries * in save_trace()
556 sizeof(trace->entries[0]), 0); in save_trace()
557 trace->hash = hash; in save_trace()
558 hash_head = stack_trace_hash + (hash & (STACK_TRACE_HASH_SIZE - 1)); in save_trace()
563 nr_stack_trace_entries += LOCK_TRACE_SIZE_IN_LONGS + trace->nr_entries; in save_trace()
564 hlist_add_head(&trace->hash_entry, hash_head); in save_trace()
617 [LOCK_USED_IN_##__STATE] = "IN-"__stringify(__STATE)"-W", \
618 [LOCK_ENABLED_##__STATE] = __stringify(__STATE)"-ON-W", \
619 [LOCK_USED_IN_##__STATE##_READ] = "IN-"__stringify(__STATE)"-R",\
620 [LOCK_ENABLED_##__STATE##_READ] = __stringify(__STATE)"-ON-R",
630 [LOCK_USAGE_STATES] = "IN-NMI",
656 * - '+': irq is enabled and not in irq context in get_usage_char()
657 * - '-': in irq context and irq is disabled in get_usage_char()
658 * - '?': in irq context and irq is enabled in get_usage_char()
660 if (class->usage_mask & lock_flag(bit + LOCK_USAGE_DIR_MASK)) { in get_usage_char()
662 if (class->usage_mask & lock_flag(bit)) in get_usage_char()
664 } else if (class->usage_mask & lock_flag(bit)) in get_usage_char()
665 c = '-'; in get_usage_char()
688 name = class->name; in __print_lock_name()
690 name = __get_key_name(class->key, str); in __print_lock_name()
694 if (class->name_version > 1) in __print_lock_name()
695 printk(KERN_CONT "#%d", class->name_version); in __print_lock_name()
696 if (class->subclass) in __print_lock_name()
697 printk(KERN_CONT "/%d", class->subclass); in __print_lock_name()
709 printk(KERN_CONT "){%s}-{%d:%d}", usage, in print_lock_name()
710 class->wait_type_outer ?: class->wait_type_inner, in print_lock_name()
711 class->wait_type_inner); in print_lock_name()
719 name = lock->name; in print_lockdep_cache()
721 name = __get_key_name(lock->key->subkeys, str); in print_lockdep_cache()
745 printk(KERN_CONT "%px", hlock->instance); in print_lock()
747 printk(KERN_CONT ", at: %pS\n", (void *)hlock->acquire_ip); in print_lock()
752 int i, depth = READ_ONCE(p->lockdep_depth); in lockdep_print_held_locks()
755 printk("no locks held by %s/%d.\n", p->comm, task_pid_nr(p)); in lockdep_print_held_locks()
758 depth > 1 ? "s" : "", p->comm, task_pid_nr(p)); in lockdep_print_held_locks()
767 print_lock(p->held_locks + i); in lockdep_print_held_locks()
773 printk("%s %.*s %s\n", init_utsname()->release, in print_kernel_ident()
774 (int)strcspn(init_utsname()->version, " "), in print_kernel_ident()
775 init_utsname()->version, in print_kernel_ident()
810 * in-kernel percpu var? in static_obj()
824 * class->name_version generation counter. The caller must hold the graph
832 if (!new_class->name) in count_matching_names()
836 if (new_class->key - new_class->subclass == class->key) in count_matching_names()
837 return class->name_version; in count_matching_names()
838 if (class->name && !strcmp(class->name, new_class->name)) in count_matching_names()
839 count = max(count, class->name_version); in count_matching_names()
845 /* used from NMI context -- must be lockless */
869 if (unlikely(!lock->key)) in look_up_lock_class()
873 * NOTE: the class-key must be unique. For dynamic locks, a static in look_up_lock_class()
875 * (or spin_lock_init()) call - which acts as the key. For static in look_up_lock_class()
881 key = lock->key->subkeys + subclass; in look_up_lock_class()
892 if (class->key == key) { in look_up_lock_class()
897 WARN_ON_ONCE(class->name != lock->name && in look_up_lock_class()
898 lock->key != &__lockdep_no_validate__); in look_up_lock_class()
907 * Static locks do not have their class-keys yet - for them the key is
927 lock->key = (void *)can_addr; in assign_lock_key()
929 lock->key = (void *)can_addr; in assign_lock_key()
931 lock->key = (void *)lock; in assign_lock_key()
933 /* Debug-check: all keys must be persistent! */ in assign_lock_key()
935 pr_err("INFO: trying to register non-static key.\n"); in assign_lock_key()
972 if (in_list(e, &class->locks_after) || in in_any_class_list()
973 in_list(e, &class->locks_before)) in in_any_class_list()
984 if (e->links_to != c) { in class_lock_list_valid()
986 c->name ? : "(?)", in class_lock_list_valid()
987 (unsigned long)(e - list_entries), in class_lock_list_valid()
988 e->links_to && e->links_to->name ? in class_lock_list_valid()
989 e->links_to->name : "(?)", in class_lock_list_valid()
990 e->class && e->class->name ? e->class->name : in class_lock_list_valid()
1008 for (i = chain->base; i < chain->base + chain->depth; i++) in check_lock_chain_key()
1014 if (chain->chain_key != chain_key) { in check_lock_chain_key()
1016 (unsigned long long)(chain - lock_chains), in check_lock_chain_key()
1017 (unsigned long long)chain->chain_key, in check_lock_chain_key()
1031 if (in_list(&class->lock_entry, &pf->zapped)) in in_any_zapped_class_list()
1049 if (!in_list(&class->lock_entry, &all_lock_classes) && in __check_data_structures()
1050 !in_list(&class->lock_entry, &free_lock_classes) && in __check_data_structures()
1053 class, class->name ? : "(?)"); in __check_data_structures()
1061 if (!class_lock_list_valid(class, &class->locks_before)) in __check_data_structures()
1063 if (!class_lock_list_valid(class, &class->locks_after)) in __check_data_structures()
1082 if (!in_any_class_list(&e->entry)) { in __check_data_structures()
1084 (unsigned int)(e - list_entries), in __check_data_structures()
1085 e->class->name ? : "(?)", in __check_data_structures()
1086 e->links_to->name ? : "(?)"); in __check_data_structures()
1097 if (in_any_class_list(&e->entry)) { in __check_data_structures()
1099 (unsigned int)(e - list_entries), in __check_data_structures()
1100 e->class && e->class->name ? e->class->name : in __check_data_structures()
1102 e->links_to && e->links_to->name ? in __check_data_structures()
1103 e->links_to->name : "(?)"); in __check_data_structures()
1192 hlist_add_head_rcu(&key->hash_entry, hash_head); in lockdep_register_key()
1213 * a use-after-free in that case by returning early. in is_dynamic_key()
1233 * Register a lock's class in the hash-table, if the class is not present
1250 if (!lock->key) { in register_lock_class()
1253 } else if (!static_obj(lock->key) && !is_dynamic_key(lock->key)) { in register_lock_class()
1257 key = lock->key->subkeys + subclass; in register_lock_class()
1264 * We have to do the hash-walk again, to avoid races in register_lock_class()
1268 if (class->key == key) in register_lock_class()
1287 __set_bit(class - lock_classes, lock_classes_in_use); in register_lock_class()
1289 class->key = key; in register_lock_class()
1290 class->name = lock->name; in register_lock_class()
1291 class->subclass = subclass; in register_lock_class()
1292 WARN_ON_ONCE(!list_empty(&class->locks_before)); in register_lock_class()
1293 WARN_ON_ONCE(!list_empty(&class->locks_after)); in register_lock_class()
1294 class->name_version = count_matching_names(class); in register_lock_class()
1295 class->wait_type_inner = lock->wait_type_inner; in register_lock_class()
1296 class->wait_type_outer = lock->wait_type_outer; in register_lock_class()
1297 class->lock_type = lock->lock_type; in register_lock_class()
1299 * We use RCU's safe list-add method to make in register_lock_class()
1300 * parallel walking of the hash-list safe: in register_lock_class()
1302 hlist_add_head_rcu(&class->hash_entry, hash_head); in register_lock_class()
1307 list_move_tail(&class->lock_entry, &all_lock_classes); in register_lock_class()
1312 printk("\nnew class %px: %s", class->key, class->name); in register_lock_class()
1313 if (class->name_version > 1) in register_lock_class()
1314 printk(KERN_CONT "#%d", class->name_version); in register_lock_class()
1327 lock->class_cache[0] = class; in register_lock_class()
1329 lock->class_cache[subclass] = class; in register_lock_class()
1333 * hash but the subclass -- which is hashed in -- didn't match. in register_lock_class()
1335 if (DEBUG_LOCKS_WARN_ON(class->subclass != subclass)) in register_lock_class()
1374 * Lock not present yet - get a new dependency struct and in add_lock_to_list()
1381 entry->class = this; in add_lock_to_list()
1382 entry->links_to = links_to; in add_lock_to_list()
1383 entry->dep = dep; in add_lock_to_list()
1384 entry->distance = distance; in add_lock_to_list()
1385 entry->trace = trace; in add_lock_to_list()
1388 * iteration is under RCU-sched; see look_up_lock_class() and in add_lock_to_list()
1391 list_add_tail_rcu(&entry->entry, head); in add_lock_to_list()
1397 * For good efficiency of modular, we use power of 2
1400 #define CQ_MASK (MAX_CIRCULAR_QUEUE_SIZE-1)
1404 * breadth-first search (BFS) algorithm, by which we can determine
1407 * indicates that adding the <prev> -> <next> lock dependency will
1408 * produce a circle in the graph. Breadth-first search instead of
1409 * depth-first search is used in order to find the shortest (circular)
1425 cq->front = cq->rear = 0; in __cq_init()
1431 return (cq->front == cq->rear); in __cq_empty()
1436 return ((cq->rear + 1) & CQ_MASK) == cq->front; in __cq_full()
1442 return -1; in __cq_enqueue()
1444 cq->element[cq->rear] = elem; in __cq_enqueue()
1445 cq->rear = (cq->rear + 1) & CQ_MASK; in __cq_enqueue()
1460 lock = cq->element[cq->front]; in __cq_dequeue()
1461 cq->front = (cq->front + 1) & CQ_MASK; in __cq_dequeue()
1468 return (cq->rear - cq->front) & CQ_MASK; in __cq_get_elem_count()
1473 lock->class->dep_gen_id = lockdep_dependency_gen_id; in mark_lock_accessed()
1479 lock->parent = parent; in visit_lock_entry()
1484 return lock->class->dep_gen_id == lockdep_dependency_gen_id; in lock_accessed()
1489 return child->parent; in get_lock_parent()
1513 void *lock_class = lock->class; in get_dep_list()
1534 BFS_EINVALIDNODE = -2,
1535 BFS_EQUEUEFULL = -1,
1551 * For dependency @prev -> @next:
1553 * SR: @prev is shared reader (->read != 0) and @next is recursive reader
1554 * (->read == 2)
1555 * ER: @prev is exclusive locker (->read == 0) and @next is recursive reader
1556 * SN: @prev is shared reader and @next is non-recursive locker (->read != 2)
1557 * EN: @prev is exclusive locker and @next is non-recursive locker
1560 * bit0 is prev->read == 0
1561 * bit1 is next->read != 2
1576 return (prev->read == 0) + ((next->read != 2) << 1); in __calc_dep_bit()
1591 return (next->read != 2) + ((prev->read == 0) << 1); in __calc_dep_bitb()
1606 lock->class = class; in __bfs_init_root()
1607 lock->parent = NULL; in __bfs_init_root()
1608 lock->only_xr = 0; in __bfs_init_root()
1615 * ->only_xr of the initial lock node is set to @hlock->read == 2, to make sure
1616 * that <prev> -> @hlock and @hlock -> <whatever __bfs() found> is not -(*R)->
1617 * and -(S*)->.
1623 lock->only_xr = (hlock->read == 2); in bfs_init_root()
1629 * ->only_xr of the initial lock node is set to @hlock->read != 0, to make sure
1630 * that <next> -> @hlock and @hlock -> <whatever backwards BFS found> is not
1631 * -(*S)-> and -(R*)-> (reverse order of -(*R)-> and -(S*)->).
1637 lock->only_xr = (hlock->read != 0); in bfs_init_rootb()
1642 if (!lock || !lock->parent) in __bfs_next()
1645 return list_next_or_null_rcu(get_dep_list(lock->parent, offset), in __bfs_next()
1646 &lock->entry, struct lock_list, entry); in __bfs_next()
1650 * Breadth-First Search to find a strong path in the dependency graph.
1663 * dependencies as -(*R)-> -(S*)->, please see:
1665 * Documentation/locking/lockdep-design.rst
1672 * has -(*R)-> in the search, and if it does (prev only has -(*R)->), we
1673 * filter out any -(S*)-> in the current dependency and after that, the
1674 * ->only_xr is set according to whether we only have -(*R)-> left.
1696 if (!lock->class) in __bfs()
1704 * @lock->class->locks_{after,before}) we skip, otherwise go in __bfs()
1717 if (lock->parent) { /* Parent exists, check prev dependency */ in __bfs()
1718 u8 dep = lock->dep; in __bfs()
1719 bool prev_only_xr = lock->parent->only_xr; in __bfs()
1722 * Mask out all -(S*)-> if we only have *R in previous in __bfs()
1723 * step, because -(*R)-> -(S*)-> don't make up a strong in __bfs()
1733 /* If there are only -(*R)-> left, set that for the next step */ in __bfs()
1734 lock->only_xr = !(dep & (DEP_SN_MASK | DEP_EN_MASK)); in __bfs()
1811 stack_trace_print(trace->entries, trace->nr_entries, spaces); in print_lock_trace()
1823 printk("\n-> #%u", depth); in print_circular_bug_entry()
1824 print_lock_name(target->class); in print_circular_bug_entry()
1826 print_lock_trace(target->trace, 6); in print_circular_bug_entry()
1836 struct lock_class *parent = prt->class; in print_circular_lock_scenario()
1854 printk(KERN_CONT " --> "); in print_circular_lock_scenario()
1856 printk(KERN_CONT " --> "); in print_circular_lock_scenario()
1863 printk(" ---- ----\n"); in print_circular_lock_scenario()
1897 pr_warn("------------------------------------------------------\n"); in print_circular_bug_header()
1899 curr->comm, task_pid_nr(curr)); in print_circular_bug_header()
1912 * We are about to add A -> B into the dependency graph, and in __bfs() a
1913 * strong dependency path A -> .. -> B is found: hlock_class equals
1914 * entry->class.
1916 * If A -> .. -> B can replace A -> B in any __bfs() search (means the former
1917 * is _stronger_ than or equal to the latter), we consider A -> B as redundant.
1918 * For example if A -> .. -> B is -(EN)-> (i.e. A -(E*)-> .. -(*N)-> B), and A
1919 * -> B is -(ER)-> or -(EN)->, then we don't need to add A -> B into the
1920 * dependency graph, as any strong path ..-> A -> B ->.. we can get with
1921 * having dependency A -> B, we could already get a equivalent path ..-> A ->
1922 * .. -> B -> .. with A -> .. -> B. Therefore A -> B is redundant.
1924 * We need to make sure both the start and the end of A -> .. -> B is not
1925 * weaker than A -> B. For the start part, please see the comment in
1930 * a) A -> B is -(*R)-> (everything is not weaker than that)
1934 * b) A -> .. -> B is -(*N)-> (nothing is stronger than this)
1941 return hlock_class(hlock) == entry->class && /* Found A -> .. -> B */ in hlock_equal()
1942 (hlock->read == 2 || /* A -> B is -(*R)-> */ in hlock_equal()
1943 !entry->only_xr); /* A -> .. -> B is -(*N)-> */ in hlock_equal()
1947 * We are about to add B -> A into the dependency graph, and in __bfs() a
1948 * strong dependency path A -> .. -> B is found: hlock_class equals
1949 * entry->class.
1951 * We will have a deadlock case (conflict) if A -> .. -> B -> A is a strong
1956 * a) B -> A is -(E*)->
1960 * b) A -> .. -> B is -(*N)-> (i.e. A -> .. -(*N)-> B)
1962 * as then we don't have -(*R)-> -(S*)-> in the cycle.
1968 return hlock_class(hlock) == entry->class && /* Found A -> .. -> B */ in hlock_conflict()
1969 (hlock->read == 0 || /* B -> A is -(E*)-> */ in hlock_conflict()
1970 !entry->only_xr); /* A -> .. -> B is -(*N)-> */ in hlock_conflict()
1986 this->trace = save_trace(); in print_circular_bug()
1987 if (!this->trace) in print_circular_bug()
1998 print_circular_bug_entry(parent, --depth); in print_circular_bug()
2018 * Breadth-first-search failed, graph got corrupted? in print_bfs_bug()
2103 * <target> -> <src> dependency.
2142 * without creating any illegal irq-safe -> irq-unsafe lock dependency.
2144 * A irq safe->unsafe deadlock happens with the following conditions:
2146 * 1) We have a strong dependency path A -> ... -> B
2149 * irq can create a new dependency B -> A (consider the case that a holder
2152 * 3) the dependency circle A -> ... -> B -> A we get from 1) and 2) is a
2156 * a) if A -> B is -(*N)->, then B -> A could be any type, so any
2158 * b) if A -> B is -(*R)->, then B -> A must be -(E*)->, so only
2162 * c) if A -> B is -(E*)->, then B -> A could be any type, so any
2164 * d) if A -> B is -(S*)->, then B -> A must be -(*N)->, so only
2169 * There is a strong dependency path in the dependency graph: A -> B, and now
2171 * safe->unsafe bugs.
2173 * Note that usage_accumulate() is used in backwards search, so ->only_xr
2174 * stands for whether A -> B only has -(S*)-> (in this case ->only_xr is true).
2176 * As above, if only_xr is false, which means A -> B has -(E*)-> dependency
2182 if (!entry->only_xr) in usage_accumulate()
2183 *(unsigned long *)mask |= entry->class->usage_mask; in usage_accumulate()
2185 *(unsigned long *)mask |= (entry->class->usage_mask & LOCKF_IRQ); in usage_accumulate()
2191 * There is a strong dependency path in the dependency graph: A -> B, and now
2193 * i.e. which usage bit of B may introduce safe->unsafe deadlocks.
2195 * As above, if only_xr is false, which means A -> B has -(*N)-> dependency
2201 if (!entry->only_xr) in usage_match()
2202 return !!(entry->class->usage_mask & *(unsigned long *)mask); in usage_match()
2204 return !!((entry->class->usage_mask & LOCKF_IRQ) & *(unsigned long *)mask); in usage_match()
2222 * where lock(B) cannot sleep, and we have a dependency B -> ... -> A. in usage_skip()
2225 * have the observation for any lock chain L1 -> ... -> Ln, for any in usage_skip()
2230 * way the local_lock() exists in the dependency B -> ... -> A. in usage_skip()
2235 if (entry->class->lock_type == LD_LOCK_PERCPU) { in usage_skip()
2236 if (DEBUG_LOCKS_WARN_ON(entry->class->wait_type_inner < LD_WAIT_CONFIG)) in usage_skip()
2246 * Find a node in the forwards-direction dependency sub-graph starting
2247 * at @root->class that matches @bit.
2266 * Find a node in the backwards-direction dependency sub-graph starting
2267 * at @root->class that matches @bit.
2286 printk("%*s->", depth, ""); in print_lock_class_header()
2294 if (class->usage_mask & (1 << bit)) { in print_lock_class_header()
2299 print_lock_trace(class->usage_traces[bit], len); in print_lock_class_header()
2305 depth, "", class->key, class->key); in print_lock_class_header()
2311 * After BFS we get a lock dependency path (linked via ->parent of lock_list),
2317 * for a lock dependency A -> B, there are two lock_lists:
2319 * a) lock_list in the ->locks_after list of A, whose ->class is B and
2320 * ->links_to is A. In this case, we can say the lock_list is
2321 * "A -> B" (forwards case).
2323 * b) lock_list in the ->locks_before list of B, whose ->class is A
2324 * and ->links_to is B. In this case, we can say the lock_list is
2325 * "B <- A" (bacwards case).
2327 * The ->trace of both a) and b) point to the call trace where B was
2333 * ->class is A, as a result BFS will search all dependencies starting with
2334 * A, e.g. A -> B or A -> C.
2336 * The notation of a forwards helper lock_list is like "-> A", which means
2337 * we should search the forwards dependencies starting with "A", e.g A -> B
2338 * or A -> C.
2340 * The notation of a bacwards helper lock_list is like "<- B", which means
2342 * B <- A or B <- C.
2353 * ->parent ->parent
2354 * | lock_list | <--------- | lock_list | ... | lock_list | <--------- | lock_list |
2355 * | -> L1 | | L1 -> L2 | ... |Ln-2 -> Ln-1| | Ln-1 -> Ln|
2357 * , so it's natural that we start from @leaf and print every ->class and
2358 * ->trace until we reach the @root.
2371 print_lock_class_header(entry->class, depth); in print_shortest_lock_dependencies()
2373 print_lock_trace(entry->trace, 2); in print_shortest_lock_dependencies()
2382 depth--; in print_shortest_lock_dependencies()
2394 * ->parent ->parent
2395 * | lock_list | ---------> | lock_list | ... | lock_list | ---------> | lock_list |
2396 * | L2 <- L1 | | L3 <- L2 | ... | Ln <- Ln-1 | | <- Ln |
2399 * dependency path L1 -> L2 -> .. -> Ln in the non-reverse order.
2401 * Another thing to notice here is that ->class of L2 <- L1 is L1, while the
2402 * ->trace of L2 <- L1 is the call trace of L2, in fact we don't have the call
2418 print_lock_class_header(entry->class, depth); in print_shortest_lock_dependencies_backwards()
2429 trace = entry->trace; in print_shortest_lock_dependencies_backwards()
2437 depth--; in print_shortest_lock_dependencies_backwards()
2447 struct lock_class *safe_class = safe_entry->class; in print_irq_lock_scenario()
2448 struct lock_class *unsafe_class = unsafe_entry->class; in print_irq_lock_scenario()
2470 printk(KERN_CONT " --> "); in print_irq_lock_scenario()
2472 printk(KERN_CONT " --> "); in print_irq_lock_scenario()
2479 printk(" ---- ----\n"); in print_irq_lock_scenario()
2514 pr_warn("WARNING: %s-safe -> %s-unsafe lock order detected\n", in print_bad_irq_dependency()
2517 pr_warn("-----------------------------------------------------\n"); in print_bad_irq_dependency()
2519 curr->comm, task_pid_nr(curr), in print_bad_irq_dependency()
2521 curr->softirq_context, softirq_count() >> SOFTIRQ_SHIFT, in print_bad_irq_dependency()
2523 curr->softirqs_enabled); in print_bad_irq_dependency()
2530 pr_cont(" ->"); in print_bad_irq_dependency()
2534 pr_warn("\nbut this new dependency connects a %s-irq-safe lock:\n", in print_bad_irq_dependency()
2536 print_lock_name(backwards_entry->class); in print_bad_irq_dependency()
2537 pr_warn("\n... which became %s-irq-safe at:\n", irqclass); in print_bad_irq_dependency()
2539 print_lock_trace(backwards_entry->class->usage_traces[bit1], 1); in print_bad_irq_dependency()
2541 pr_warn("\nto a %s-irq-unsafe lock:\n", irqclass); in print_bad_irq_dependency()
2542 print_lock_name(forwards_entry->class); in print_bad_irq_dependency()
2543 pr_warn("\n... which became %s-irq-unsafe at:\n", irqclass); in print_bad_irq_dependency()
2546 print_lock_trace(forwards_entry->class->usage_traces[bit2], 1); in print_bad_irq_dependency()
2554 pr_warn("\nthe dependencies between %s-irq-safe lock and the holding lock:\n", irqclass); in print_bad_irq_dependency()
2558 pr_warn(" and %s-irq-unsafe lock:\n", irqclass); in print_bad_irq_dependency()
2559 next_root->trace = save_trace(); in print_bad_irq_dependency()
2560 if (!next_root->trace) in print_bad_irq_dependency()
2577 __stringify(__STATE)"-READ",
2595 * bit2-n: state
2610 * right shift of the mask transforms the individual bitnrs as -1 and
2651 * LOCK_USED_IN_IRQ_* -> LOCK_ENABLED_IRQ_*
2652 * LOCK_USED_IN_IRQ_*_READ -> LOCK_ENABLED_IRQ_*
2653 * LOCK_USED_IN_IRQ_* -> LOCK_ENABLED_IRQ_*_READ
2654 * LOCK_USED_IN_IRQ_*_READ -> LOCK_ENABLED_IRQ_*_READ
2718 return -1; in find_exclusive_match()
2722 * Prove that the new dependency does not connect a hardirq-safe(-read)
2723 * lock with a hardirq-unsafe lock - to achieve this we search
2724 * the backwards-subgraph starting at <prev>, and the
2725 * forwards-subgraph starting at <next>:
2777 * When trying to add A -> B to the graph, we find that there is a in check_irq_usage()
2778 * hardirq-safe L, that L -> ... -> A, and another hardirq-unsafe M, in check_irq_usage()
2779 * that B -> ... -> M. However M is **softirq-safe**, if we use exact in check_irq_usage()
2781 * **softirq-unsafe** and N -> ... -> A, however N -> .. -> M will not in check_irq_usage()
2784 backward_mask = original_mask(target_entry1->class->usage_mask & LOCKF_ENABLED_IRQ_ALL); in check_irq_usage()
2798 ret = find_exclusive_match(target_entry->class->usage_mask, in check_irq_usage()
2799 target_entry1->class->usage_mask, in check_irq_usage()
2801 if (DEBUG_LOCKS_WARN_ON(ret == -1)) in check_irq_usage()
2831 * <target> or not. If it can, <src> -> <target> dependency is already
2849 * is equal to or stronger than <src> -> <target>. So if <src> is E, in check_redundant()
2850 * we need to let __bfs() only search for a path starting at a -(E*)->, in check_redundant()
2851 * we achieve this by setting the initial node's ->only_xr to true in in check_redundant()
2852 * that case. And if <prev> is S, we set initial ->only_xr to false in check_redundant()
2853 * because both -(S*)-> (equal) and -(E*)-> (stronger) are redundant. in check_redundant()
2855 src_entry.only_xr = src->read == 0; in check_redundant()
2861 * comment in usage_skip(), A -> local_lock() -> B and A -> B are not in check_redundant()
2895 nr_hardirq_chains--; in dec_chains()
2897 nr_softirq_chains--; in dec_chains()
2899 nr_process_chains--; in dec_chains()
2910 printk(" ----\n"); in print_deadlock_scenario()
2932 pr_warn("--------------------------------------------\n"); in print_deadlock_bug()
2934 curr->comm, task_pid_nr(curr)); in print_deadlock_bug()
2964 for (i = 0; i < curr->lockdep_depth; i++) { in check_deadlock()
2965 prev = curr->held_locks + i; in check_deadlock()
2967 if (prev->instance == next->nest_lock) in check_deadlock()
2974 * Allow read-after-read recursion of the same in check_deadlock()
2977 if ((next->read == 2) && prev->read) in check_deadlock()
2994 * There was a chain-cache miss, and we are about to add a new dependency
2997 * - would the adding of the <prev> -> <next> dependency create a
3000 * - does the new prev->next dependency connect any hardirq-safe lock
3001 * (in the full backwards-subgraph starting at <prev>) with any
3002 * hardirq-unsafe lock (in the full forwards-subgraph starting at
3005 * - does the new prev->next dependency connect any softirq-safe lock
3006 * (in the full backwards-subgraph starting at <prev>) with any
3007 * softirq-unsafe lock (in the full forwards-subgraph starting at
3023 if (!hlock_class(prev)->key || !hlock_class(next)->key) { in check_prev_add()
3025 * The warning statements below may trigger a use-after-free in check_prev_add()
3026 * of the class name. It is better to trigger a use-after free in check_prev_add()
3030 WARN_ONCE(!debug_locks_silent && !hlock_class(prev)->key, in check_prev_add()
3031 "Detected use-after-free of lock class %px/%s\n", in check_prev_add()
3033 hlock_class(prev)->name); in check_prev_add()
3034 WARN_ONCE(!debug_locks_silent && !hlock_class(next)->key, in check_prev_add()
3035 "Detected use-after-free of lock class %px/%s\n", in check_prev_add()
3037 hlock_class(next)->name); in check_prev_add()
3042 * Prove that the new <prev> -> <next> dependency would not in check_prev_add()
3044 * a breadth-first search into the graph starting at <next>, in check_prev_add()
3059 * Is the <prev> -> <next> dependency already present? in check_prev_add()
3062 * e.g. the L1 -> L2 -> L3 -> L4 and the L5 -> L1 -> L2 -> L3 in check_prev_add()
3063 * chains - the second one will be new, but L1 already has in check_prev_add()
3066 list_for_each_entry(entry, &hlock_class(prev)->locks_after, entry) { in check_prev_add()
3067 if (entry->class == hlock_class(next)) { in check_prev_add()
3069 entry->distance = 1; in check_prev_add()
3070 entry->dep |= calc_dep(prev, next); in check_prev_add()
3074 * ->locks_before list. in check_prev_add()
3088 list_for_each_entry(entry, &hlock_class(next)->locks_before, entry) { in check_prev_add()
3089 if (entry->class == hlock_class(prev)) { in check_prev_add()
3091 entry->distance = 1; in check_prev_add()
3092 entry->dep |= calc_depb(prev, next); in check_prev_add()
3103 * Is the <prev> -> <next> link redundant? in check_prev_add()
3122 &hlock_class(prev)->locks_after, in check_prev_add()
3123 next->acquire_ip, distance, in check_prev_add()
3131 &hlock_class(next)->locks_before, in check_prev_add()
3132 next->acquire_ip, distance, in check_prev_add()
3142 * Add the dependency to all directly-previous locks that are 'relevant'.
3144 * all consecutive trylock entries and the final non-trylock entry - or
3145 * the end of this context's lock-chain - whichever comes first.
3151 int depth = curr->lockdep_depth; in check_prevs_add()
3157 * Depth must not be zero for a non-head lock: in check_prevs_add()
3165 if (curr->held_locks[depth].irq_context != in check_prevs_add()
3166 curr->held_locks[depth-1].irq_context) in check_prevs_add()
3170 u16 distance = curr->lockdep_depth - depth + 1; in check_prevs_add()
3171 hlock = curr->held_locks + depth - 1; in check_prevs_add()
3173 if (hlock->check) { in check_prevs_add()
3179 * Stop after the first non-trylock entry, in check_prevs_add()
3180 * as non-trylock entries have added their in check_prevs_add()
3184 if (!hlock->trylock) in check_prevs_add()
3188 depth--; in check_prevs_add()
3190 * End of lock-stack? in check_prevs_add()
3197 if (curr->held_locks[depth].irq_context != in check_prevs_add()
3198 curr->held_locks[depth-1].irq_context) in check_prevs_add()
3229 * Bit 15 - always set to 1 (it is not a class index)
3230 * Bits 0-14 - upper 15 bits of the next block index
3231 * entry[1] - lower 16 bits of next block index
3235 * On the unsized bucket (bucket-0), the 3rd and 4th entries contain
3238 * entry[2] - upper 16 bits of the chain block size
3239 * entry[3] - lower 16 bits of the chain block size
3252 return size - 1; in size_to_bucket()
3259 for ((prev) = -1, (curr) = chain_block_buckets[bucket]; \
3264 * next block or -1
3273 return -1; in chain_block_next()
3283 * bucket-0 only
3313 * the block before it is re-added. in add_chain_block()
3358 nr_free_chain_hlocks -= size; in del_chain_block()
3362 nr_large_chain_blocks--; in del_chain_block()
3370 chain_block_buckets[i] = -1; in init_chain_block_buckets()
3376 * Return offset of a chain block of the right size or -1 if not found.
3378 * Fairly simple worst-fit allocator with the addition of a number of size
3381 static int alloc_chain_hlocks(int req) in alloc_chain_hlocks() argument
3389 BUILD_BUG_ON((MAX_LOCKDEP_KEYS-1) & CHAIN_BLK_FLAG); in alloc_chain_hlocks()
3393 if (nr_free_chain_hlocks < req) in alloc_chain_hlocks()
3394 return -1; in alloc_chain_hlocks()
3400 req = max(req, 2); in alloc_chain_hlocks()
3401 bucket = size_to_bucket(req); in alloc_chain_hlocks()
3406 del_chain_block(bucket, req, chain_block_next(curr)); in alloc_chain_hlocks()
3419 if (likely(size >= req)) { in alloc_chain_hlocks()
3421 add_chain_block(curr + req, size - req); in alloc_chain_hlocks()
3429 for (size = MAX_CHAIN_BUCKETS; size > req; size--) { in alloc_chain_hlocks()
3436 add_chain_block(curr + req, size - req); in alloc_chain_hlocks()
3440 return -1; in alloc_chain_hlocks()
3450 u16 chain_hlock = chain_hlocks[chain->base + i]; in lock_chain_get_class()
3453 return lock_classes + class_idx - 1; in lock_chain_get_class()
3465 for (i = curr->lockdep_depth - 1; i >= 0; i--) { in get_first_held_lock()
3466 hlock_curr = curr->held_locks + i; in get_first_held_lock()
3467 if (hlock_curr->irq_context != hlock->irq_context) in get_first_held_lock()
3483 printk(" hlock_id:%d -> chain_key:%016Lx", in print_chain_key_iteration()
3494 int depth = curr->lockdep_depth; in print_chain_keys_held_locks()
3497 printk("depth: %u (irq_context %u)\n", depth - i + 1, in print_chain_keys_held_locks()
3498 hlock_next->irq_context); in print_chain_keys_held_locks()
3500 hlock = curr->held_locks + i; in print_chain_keys_held_locks()
3516 printk("depth: %u\n", chain->depth); in print_chain_keys_chain()
3517 for (i = 0; i < chain->depth; i++) { in print_chain_keys_chain()
3518 hlock_id = chain_hlocks[chain->base + i]; in print_chain_keys_chain()
3521 print_lock_name(lock_classes + chain_hlock_class_idx(hlock_id) - 1); in print_chain_keys_chain()
3534 pr_warn("----------------------------\n"); in print_collision()
3535 pr_warn("%s/%d: ", current->comm, task_pid_nr(current)); in print_collision()
3564 if (DEBUG_LOCKS_WARN_ON(chain->depth != curr->lockdep_depth - (i - 1))) { in check_no_collision()
3569 for (j = 0; j < chain->depth - 1; j++, i++) { in check_no_collision()
3570 id = hlock_id(&curr->held_locks[i]); in check_no_collision()
3572 if (DEBUG_LOCKS_WARN_ON(chain_hlocks[chain->base + j] != id)) { in check_no_collision()
3582 * Given an index that is >= -1, return the index of the next lock chain.
3583 * Return -2 if there is no next lock chain.
3588 return i < ARRAY_SIZE(lock_chains) ? i : -2; in lockdep_next_lockchain()
3625 * disabled to make this an IRQ-safe lock.. for recursion reasons in add_chain_cache()
3640 chain->chain_key = chain_key; in add_chain_cache()
3641 chain->irq_context = hlock->irq_context; in add_chain_cache()
3643 chain->depth = curr->lockdep_depth + 1 - i; in add_chain_cache()
3646 BUILD_BUG_ON((1UL << 6) <= ARRAY_SIZE(curr->held_locks)); in add_chain_cache()
3649 j = alloc_chain_hlocks(chain->depth); in add_chain_cache()
3659 chain->base = j; in add_chain_cache()
3660 for (j = 0; j < chain->depth - 1; j++, i++) { in add_chain_cache()
3661 int lock_id = hlock_id(curr->held_locks + i); in add_chain_cache()
3663 chain_hlocks[chain->base + j] = lock_id; in add_chain_cache()
3665 chain_hlocks[chain->base + j] = hlock_id(hlock); in add_chain_cache()
3666 hlist_add_head_rcu(&chain->entry, hash_head); in add_chain_cache()
3668 inc_chains(chain->irq_context); in add_chain_cache()
3683 if (READ_ONCE(chain->chain_key) == chain_key) { in lookup_chain_cache()
3693 * add it and return 1 - in this case the new dependency chain is
3713 class->key, class->name); in lookup_chain_cache_add()
3721 (unsigned long long)chain_key, class->key, class->name); in lookup_chain_cache_add()
3728 * We have to walk the chain again locked - to avoid duplicates: in lookup_chain_cache_add()
3756 if (!hlock->trylock && hlock->check && in validate_chain()
3761 * - is irq-safe, if this lock is irq-unsafe in validate_chain()
3762 * - is softirq-safe, if this lock is hardirq-unsafe in validate_chain()
3767 * - within the current held-lock stack in validate_chain()
3768 * - across our accumulated lock dependency records in validate_chain()
3814 * We are building curr_chain_key incrementally, so double-check
3824 for (i = 0; i < curr->lockdep_depth; i++) { in check_chain_key()
3825 hlock = curr->held_locks + i; in check_chain_key()
3826 if (chain_key != hlock->prev_chain_key) { in check_chain_key()
3833 curr->lockdep_depth, i, in check_chain_key()
3835 (unsigned long long)hlock->prev_chain_key); in check_chain_key()
3840 * hlock->class_idx can't go beyond MAX_LOCKDEP_KEYS, but is in check_chain_key()
3843 if (DEBUG_LOCKS_WARN_ON(!test_bit(hlock->class_idx, lock_classes_in_use))) in check_chain_key()
3846 if (prev_hlock && (prev_hlock->irq_context != in check_chain_key()
3847 hlock->irq_context)) in check_chain_key()
3852 if (chain_key != curr->curr_chain_key) { in check_chain_key()
3859 curr->lockdep_depth, i, in check_chain_key()
3861 (unsigned long long)curr->curr_chain_key); in check_chain_key()
3876 printk(" ----\n"); in print_usage_bug_scenario()
3898 pr_warn("--------------------------------\n"); in print_usage_bug()
3900 pr_warn("inconsistent {%s} -> {%s} usage.\n", in print_usage_bug()
3904 curr->comm, task_pid_nr(curr), in print_usage_bug()
3912 print_lock_trace(hlock_class(this)->usage_traces[prev_bit], 1); in print_usage_bug()
3931 if (unlikely(hlock_class(this)->usage_mask & (1 << bad_bit))) { in valid_state()
3960 pr_warn("--------------------------------------------------------\n"); in print_irq_inversion_bug()
3962 curr->comm, task_pid_nr(curr)); in print_irq_inversion_bug()
3965 pr_warn("but this lock took another, %s-unsafe lock in the past:\n", irqclass); in print_irq_inversion_bug()
3967 pr_warn("but this lock was taken by another, %s-safe lock in the past:\n", irqclass); in print_irq_inversion_bug()
3968 print_lock_name(other->class); in print_irq_inversion_bug()
3982 depth--; in print_irq_inversion_bug()
3986 middle ? middle->class : root->class, other->class); in print_irq_inversion_bug()
3989 middle ? middle->class : other->class, root->class); in print_irq_inversion_bug()
3994 root->trace = save_trace(); in print_irq_inversion_bug()
3995 if (!root->trace) in print_irq_inversion_bug()
4004 * Prove that in the forwards-direction subgraph starting at <this>
4027 if (target_entry->class->usage_mask & lock_flag(bit)) { in check_usage_forwards()
4039 * Prove that in the backwards-direction subgraph starting at <this>
4062 if (target_entry->class->usage_mask & lock_flag(bit)) { in check_usage_backwards()
4075 const struct irqtrace_events *trace = &curr->irqtrace; in print_irqtrace_events()
4077 printk("irq event stamp: %u\n", trace->irq_events); in print_irqtrace_events()
4079 trace->hardirq_enable_event, (void *)trace->hardirq_enable_ip, in print_irqtrace_events()
4080 (void *)trace->hardirq_enable_ip); in print_irqtrace_events()
4082 trace->hardirq_disable_event, (void *)trace->hardirq_disable_ip, in print_irqtrace_events()
4083 (void *)trace->hardirq_disable_ip); in print_irqtrace_events()
4085 trace->softirq_enable_event, (void *)trace->softirq_enable_ip, in print_irqtrace_events()
4086 (void *)trace->softirq_enable_ip); in print_irqtrace_events()
4088 trace->softirq_disable_event, (void *)trace->softirq_disable_ip, in print_irqtrace_events()
4089 (void *)trace->softirq_disable_ip); in print_irqtrace_events()
4153 * mark ENABLED has to look backwards -- to ensure no dependee in mark_lock_irq()
4160 * mark USED_IN has to look forwards -- to ensure no dependency in mark_lock_irq()
4182 for (i = 0; i < curr->lockdep_depth; i++) { in mark_held_locks()
4184 hlock = curr->held_locks + i; in mark_held_locks()
4186 if (hlock->read) in mark_held_locks()
4191 if (!hlock->check) in mark_held_locks()
4219 if (curr->softirqs_enabled) in __trace_hardirqs_on_caller()
4224 * lockdep_hardirqs_on_prepare - Prepare for enabling interrupts
4277 current->hardirq_chain_key = current->curr_chain_key; in lockdep_hardirqs_on_prepare()
4287 struct irqtrace_events *trace = ¤t->irqtrace; in lockdep_hardirqs_on()
4305 * - recursion check, because NMI can hit lockdep; in lockdep_hardirqs_on()
4306 * - hardware state check, because above; in lockdep_hardirqs_on()
4307 * - chain_key check, see lockdep_hardirqs_on_prepare(). in lockdep_hardirqs_on()
4337 DEBUG_LOCKS_WARN_ON(current->hardirq_chain_key != in lockdep_hardirqs_on()
4338 current->curr_chain_key); in lockdep_hardirqs_on()
4341 /* we'll do an OFF -> ON transition: */ in lockdep_hardirqs_on()
4343 trace->hardirq_enable_ip = ip; in lockdep_hardirqs_on()
4344 trace->hardirq_enable_event = ++trace->irq_events; in lockdep_hardirqs_on()
4376 struct irqtrace_events *trace = ¤t->irqtrace; in lockdep_hardirqs_off()
4379 * We have done an ON -> OFF transition: in lockdep_hardirqs_off()
4382 trace->hardirq_disable_ip = ip; in lockdep_hardirqs_off()
4383 trace->hardirq_disable_event = ++trace->irq_events; in lockdep_hardirqs_off()
4396 struct irqtrace_events *trace = ¤t->irqtrace; in lockdep_softirqs_on()
4408 if (current->softirqs_enabled) { in lockdep_softirqs_on()
4415 * We'll do an OFF -> ON transition: in lockdep_softirqs_on()
4417 current->softirqs_enabled = 1; in lockdep_softirqs_on()
4418 trace->softirq_enable_ip = ip; in lockdep_softirqs_on()
4419 trace->softirq_enable_event = ++trace->irq_events; in lockdep_softirqs_on()
4445 if (current->softirqs_enabled) { in lockdep_softirqs_off()
4446 struct irqtrace_events *trace = ¤t->irqtrace; in lockdep_softirqs_off()
4449 * We have done an ON -> OFF transition: in lockdep_softirqs_off()
4451 current->softirqs_enabled = 0; in lockdep_softirqs_off()
4452 trace->softirq_disable_ip = ip; in lockdep_softirqs_off()
4453 trace->softirq_disable_event = ++trace->irq_events; in lockdep_softirqs_off()
4470 * If non-trylock use in a hardirq or softirq context, then in mark_usage()
4473 if (!hlock->trylock) { in mark_usage()
4474 if (hlock->read) { in mark_usage()
4479 if (curr->softirq_context) in mark_usage()
4487 if (curr->softirq_context) in mark_usage()
4492 if (!hlock->hardirqs_off) { in mark_usage()
4493 if (hlock->read) { in mark_usage()
4497 if (curr->softirqs_enabled) in mark_usage()
4505 if (curr->softirqs_enabled) in mark_usage()
4523 LOCK_CHAIN_SOFTIRQ_CONTEXT * !!task->softirq_context; in task_irq_context()
4529 unsigned int depth = curr->lockdep_depth; in separate_irq_context()
4537 prev_hlock = curr->held_locks + depth-1; in separate_irq_context()
4543 if (prev_hlock->irq_context != hlock->irq_context) in separate_irq_context()
4562 if (new_bit == LOCK_USED && this->read) in mark_lock()
4571 if (likely(hlock_class(this)->usage_mask & new_mask)) in mark_lock()
4579 if (unlikely(hlock_class(this)->usage_mask & new_mask)) in mark_lock()
4582 if (!hlock_class(this)->usage_mask) in mark_lock()
4585 hlock_class(this)->usage_mask |= new_mask; in mark_lock()
4588 if (!(hlock_class(this)->usage_traces[new_bit] = save_trace())) in mark_lock()
4624 if (curr->hardirq_threaded || curr->irq_config) in task_wait_context()
4628 } else if (curr->softirq_context) { in task_wait_context()
4653 pr_warn("-----------------------------\n"); in print_lock_invalid_wait_context()
4655 pr_warn("%s/%d is trying to lock:\n", curr->comm, task_pid_nr(curr)); in print_lock_invalid_wait_context()
4661 pr_warn("context-{%d:%d}\n", curr_inner, curr_inner); in print_lock_invalid_wait_context()
4674 * This check validates we takes locks in the right wait-type order; that is it
4688 u8 next_inner = hlock_class(next)->wait_type_inner; in check_wait_context()
4689 u8 next_outer = hlock_class(next)->wait_type_outer; in check_wait_context()
4693 if (!next_inner || next->trylock) in check_wait_context()
4702 for (depth = curr->lockdep_depth - 1; depth >= 0; depth--) { in check_wait_context()
4703 struct held_lock *prev = curr->held_locks + depth; in check_wait_context()
4704 if (prev->irq_context != next->irq_context) in check_wait_context()
4711 for (; depth < curr->lockdep_depth; depth++) { in check_wait_context()
4712 struct held_lock *prev = curr->held_locks + depth; in check_wait_context()
4713 u8 prev_inner = hlock_class(prev)->wait_type_inner; in check_wait_context()
4760 * Initialize a lock instance's lock-class mapping info:
4769 lock->class_cache[i] = NULL; in lockdep_init_map_type()
4772 lock->cpu = raw_smp_processor_id(); in lockdep_init_map_type()
4779 lock->name = "NULL"; in lockdep_init_map_type()
4783 lock->name = name; in lockdep_init_map_type()
4785 lock->wait_type_outer = outer; in lockdep_init_map_type()
4786 lock->wait_type_inner = inner; in lockdep_init_map_type()
4787 lock->lock_type = lock_type; in lockdep_init_map_type()
4795 * Sanity check, the lock-class key must either have been allocated in lockdep_init_map_type()
4804 lock->key = key; in lockdep_init_map_type()
4841 pr_warn("----------------------------------\n"); in print_lock_nested_lock_not_held()
4843 pr_warn("%s/%d is trying to lock:\n", curr->comm, task_pid_nr(curr)); in print_lock_nested_lock_not_held()
4847 pr_warn("%s\n", hlock->nest_lock->name); in print_lock_nested_lock_not_held()
4885 if (!prove_locking || lock->key == &__lockdep_no_validate__) in __lock_acquire()
4889 class = lock->class_cache[subclass]; in __lock_acquire()
4902 printk("\nacquire class [%px] %s", class->key, class->name); in __lock_acquire()
4903 if (class->name_version > 1) in __lock_acquire()
4904 printk(KERN_CONT "#%d", class->name_version); in __lock_acquire()
4914 depth = curr->lockdep_depth; in __lock_acquire()
4916 * Ran out of static storage for our per-task lock stack again have we? in __lock_acquire()
4921 class_idx = class - lock_classes; in __lock_acquire()
4924 hlock = curr->held_locks + depth - 1; in __lock_acquire()
4925 if (hlock->class_idx == class_idx && nest_lock) { in __lock_acquire()
4929 if (!hlock->references) in __lock_acquire()
4930 hlock->references++; in __lock_acquire()
4932 hlock->references += references; in __lock_acquire()
4935 if (DEBUG_LOCKS_WARN_ON(hlock->references < references)) in __lock_acquire()
4942 hlock = curr->held_locks + depth; in __lock_acquire()
4949 hlock->class_idx = class_idx; in __lock_acquire()
4950 hlock->acquire_ip = ip; in __lock_acquire()
4951 hlock->instance = lock; in __lock_acquire()
4952 hlock->nest_lock = nest_lock; in __lock_acquire()
4953 hlock->irq_context = task_irq_context(curr); in __lock_acquire()
4954 hlock->trylock = trylock; in __lock_acquire()
4955 hlock->read = read; in __lock_acquire()
4956 hlock->check = check; in __lock_acquire()
4957 hlock->hardirqs_off = !!hardirqs_off; in __lock_acquire()
4958 hlock->references = references; in __lock_acquire()
4960 hlock->waittime_stamp = 0; in __lock_acquire()
4961 hlock->holdtime_stamp = lockstat_clock(); in __lock_acquire()
4963 hlock->pin_count = pin_count; in __lock_acquire()
4973 * Calculate the chain hash: it's the combined hash of all the in __lock_acquire()
4980 * the hash, not class->key. in __lock_acquire()
4988 chain_key = curr->curr_chain_key; in __lock_acquire()
4998 hlock->prev_chain_key = chain_key; in __lock_acquire()
5005 if (nest_lock && !__lock_is_held(nest_lock, -1)) { in __lock_acquire()
5011 WARN_ON_ONCE(depth && !hlock_class(hlock - 1)->key); in __lock_acquire()
5012 WARN_ON_ONCE(!hlock_class(hlock)->key); in __lock_acquire()
5018 curr->curr_chain_key = chain_key; in __lock_acquire()
5019 curr->lockdep_depth++; in __lock_acquire()
5025 if (unlikely(curr->lockdep_depth >= MAX_LOCK_DEPTH)) { in __lock_acquire()
5029 curr->lockdep_depth, MAX_LOCK_DEPTH); in __lock_acquire()
5038 if (unlikely(curr->lockdep_depth > max_lockdep_depth)) in __lock_acquire()
5039 max_lockdep_depth = curr->lockdep_depth; in __lock_acquire()
5057 pr_warn("-------------------------------------\n"); in print_unlock_imbalance_bug()
5059 curr->comm, task_pid_nr(curr)); in print_unlock_imbalance_bug()
5074 if (hlock->instance == lock) in match_held_lock()
5077 if (hlock->references) { in match_held_lock()
5078 const struct lock_class *class = lock->class_cache[0]; in match_held_lock()
5093 * References, but not a lock we're actually ref-counting? in match_held_lock()
5094 * State got messed up, follow the sites that change ->references in match_held_lock()
5097 if (DEBUG_LOCKS_WARN_ON(!hlock->nest_lock)) in match_held_lock()
5100 if (hlock->class_idx == class - lock_classes) in match_held_lock()
5115 i = depth - 1; in find_held_lock()
5116 hlock = curr->held_locks + i; in find_held_lock()
5122 for (i--, prev_hlock = hlock--; in find_held_lock()
5124 i--, prev_hlock = hlock--) { in find_held_lock()
5128 if (prev_hlock->irq_context != hlock->irq_context) { in find_held_lock()
5152 for (hlock = curr->held_locks + idx; idx < depth; idx++, hlock++) { in reacquire_held_locks()
5153 switch (__lock_acquire(hlock->instance, in reacquire_held_locks()
5154 hlock_class(hlock)->subclass, in reacquire_held_locks()
5155 hlock->trylock, in reacquire_held_locks()
5156 hlock->read, hlock->check, in reacquire_held_locks()
5157 hlock->hardirqs_off, in reacquire_held_locks()
5158 hlock->nest_lock, hlock->acquire_ip, in reacquire_held_locks()
5159 hlock->references, hlock->pin_count)) { in reacquire_held_locks()
5189 depth = curr->lockdep_depth; in __lock_set_class()
5204 lock->wait_type_inner, in __lock_set_class()
5205 lock->wait_type_outer); in __lock_set_class()
5207 hlock->class_idx = class - lock_classes; in __lock_set_class()
5209 curr->lockdep_depth = i; in __lock_set_class()
5210 curr->curr_chain_key = hlock->prev_chain_key; in __lock_set_class()
5219 if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth - merged)) in __lock_set_class()
5234 depth = curr->lockdep_depth; in __lock_downgrade()
5248 curr->lockdep_depth = i; in __lock_downgrade()
5249 curr->curr_chain_key = hlock->prev_chain_key; in __lock_downgrade()
5251 WARN(hlock->read, "downgrading a read lock"); in __lock_downgrade()
5252 hlock->read = 1; in __lock_downgrade()
5253 hlock->acquire_ip = ip; in __lock_downgrade()
5266 if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth)) in __lock_downgrade()
5273 * Remove the lock from the list of currently held locks - this gets
5288 depth = curr->lockdep_depth; in __lock_release()
5308 if (hlock->instance == lock) in __lock_release()
5311 WARN(hlock->pin_count, "releasing a pinned lock\n"); in __lock_release()
5313 if (hlock->references) { in __lock_release()
5314 hlock->references--; in __lock_release()
5315 if (hlock->references) { in __lock_release()
5331 curr->lockdep_depth = i; in __lock_release()
5332 curr->curr_chain_key = hlock->prev_chain_key; in __lock_release()
5338 if (i == depth-1) in __lock_release()
5346 * there's not N-1 bottles of beer left on the wall... in __lock_release()
5349 DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth - merged); in __lock_release()
5365 for (i = 0; i < curr->lockdep_depth; i++) { in __lock_is_held()
5366 struct held_lock *hlock = curr->held_locks + i; in __lock_is_held()
5369 if (read == -1 || hlock->read == read) in __lock_is_held()
5388 for (i = 0; i < curr->lockdep_depth; i++) { in __lock_pin_lock()
5389 struct held_lock *hlock = curr->held_locks + i; in __lock_pin_lock()
5398 hlock->pin_count += cookie.val; in __lock_pin_lock()
5415 for (i = 0; i < curr->lockdep_depth; i++) { in __lock_repin_lock()
5416 struct held_lock *hlock = curr->held_locks + i; in __lock_repin_lock()
5419 hlock->pin_count += cookie.val; in __lock_repin_lock()
5435 for (i = 0; i < curr->lockdep_depth; i++) { in __lock_unpin_lock()
5436 struct held_lock *hlock = curr->held_locks + i; in __lock_unpin_lock()
5439 if (WARN(!hlock->pin_count, "unpinning an unpinned lock\n")) in __lock_unpin_lock()
5442 hlock->pin_count -= cookie.val; in __lock_unpin_lock()
5444 if (WARN((int)hlock->pin_count < 0, "pin count corrupted\n")) in __lock_unpin_lock()
5445 hlock->pin_count = 0; in __lock_unpin_lock()
5455 * Check whether we follow the irq-flags state precisely:
5468 printk("possible reason: unannotated irqs-off.\n"); in check_flags()
5472 printk("possible reason: unannotated irqs-on.\n"); in check_flags()
5484 DEBUG_LOCKS_WARN_ON(current->softirqs_enabled); in check_flags()
5487 DEBUG_LOCKS_WARN_ON(!current->softirqs_enabled); in check_flags()
5547 * READ locks, there is no deadlock possible -- RCU. in verify_lock_unused()
5549 if (!hlock->read) in verify_lock_unused()
5552 if (!(class->usage_mask & mask)) in verify_lock_unused()
5555 hlock->class_idx = class - lock_classes; in verify_lock_unused()
5587 * We are not always called with irqs disabled - do that here,
5745 pr_warn("---------------------------------\n"); in print_lock_contention_bug()
5747 curr->comm, task_pid_nr(curr)); in print_lock_contention_bug()
5768 depth = curr->lockdep_depth; in __lock_contended()
5782 if (hlock->instance != lock) in __lock_contended()
5785 hlock->waittime_stamp = lockstat_clock(); in __lock_contended()
5787 contention_point = lock_point(hlock_class(hlock)->contention_point, ip); in __lock_contended()
5788 contending_point = lock_point(hlock_class(hlock)->contending_point, in __lock_contended()
5789 lock->ip); in __lock_contended()
5793 stats->contention_point[contention_point]++; in __lock_contended()
5795 stats->contending_point[contending_point]++; in __lock_contended()
5796 if (lock->cpu != smp_processor_id()) in __lock_contended()
5797 stats->bounces[bounce_contended + !!hlock->read]++; in __lock_contended()
5810 depth = curr->lockdep_depth; in __lock_acquired()
5824 if (hlock->instance != lock) in __lock_acquired()
5828 if (hlock->waittime_stamp) { in __lock_acquired()
5830 waittime = now - hlock->waittime_stamp; in __lock_acquired()
5831 hlock->holdtime_stamp = now; in __lock_acquired()
5836 if (hlock->read) in __lock_acquired()
5837 lock_time_inc(&stats->read_waittime, waittime); in __lock_acquired()
5839 lock_time_inc(&stats->write_waittime, waittime); in __lock_acquired()
5841 if (lock->cpu != cpu) in __lock_acquired()
5842 stats->bounces[bounce_acquired + !!hlock->read]++; in __lock_acquired()
5844 lock->cpu = cpu; in __lock_acquired()
5845 lock->ip = ip; in __lock_acquired()
5897 memset(current->held_locks, 0, MAX_LOCK_DEPTH*sizeof(struct held_lock)); in lockdep_reset()
5915 for (i = chain->base; i < chain->base + chain->depth; i++) { in remove_class_from_lock_chain()
5916 if (chain_hlock_class_idx(chain_hlocks[i]) != class - lock_classes) in remove_class_from_lock_chain()
5928 free_chain_hlocks(chain->base, chain->depth); in remove_class_from_lock_chain()
5930 WRITE_ONCE(chain->chain_key, INITIAL_CHAIN_KEY); in remove_class_from_lock_chain()
5931 dec_chains(chain->irq_context); in remove_class_from_lock_chain()
5937 hlist_del_rcu(&chain->entry); in remove_class_from_lock_chain()
5938 __set_bit(chain - lock_chains, pf->lock_chains_being_freed); in remove_class_from_lock_chain()
5967 WARN_ON_ONCE(!class->key); in zap_class()
5975 if (entry->class != class && entry->links_to != class) in zap_class()
5978 nr_list_entries--; in zap_class()
5979 list_del_rcu(&entry->entry); in zap_class()
5981 if (list_empty(&class->locks_after) && in zap_class()
5982 list_empty(&class->locks_before)) { in zap_class()
5983 list_move_tail(&class->lock_entry, &pf->zapped); in zap_class()
5984 hlist_del_rcu(&class->hash_entry); in zap_class()
5985 WRITE_ONCE(class->key, NULL); in zap_class()
5986 WRITE_ONCE(class->name, NULL); in zap_class()
5987 nr_lock_classes--; in zap_class()
5988 __clear_bit(class - lock_classes, lock_classes_in_use); in zap_class()
5991 class->name); in zap_class()
6003 WARN_ON_ONCE(!class->lock_entry.next); in reinit_class()
6004 WARN_ON_ONCE(!list_empty(&class->locks_after)); in reinit_class()
6005 WARN_ON_ONCE(!list_empty(&class->locks_before)); in reinit_class()
6006 memset(p + offset, 0, sizeof(*class) - offset); in reinit_class()
6007 WARN_ON_ONCE(!class->lock_entry.next); in reinit_class()
6008 WARN_ON_ONCE(!list_empty(&class->locks_after)); in reinit_class()
6009 WARN_ON_ONCE(!list_empty(&class->locks_before)); in reinit_class()
6038 if (list_empty(&pf->zapped)) in call_rcu_zapped()
6059 list_for_each_entry(class, &pf->zapped, lock_entry) in __free_zapped_classes()
6062 list_splice_init(&pf->zapped, &free_lock_classes); in __free_zapped_classes()
6066 pf->lock_chains_being_freed, ARRAY_SIZE(lock_chains)); in __free_zapped_classes()
6067 bitmap_clear(pf->lock_chains_being_freed, 0, ARRAY_SIZE(lock_chains)); in __free_zapped_classes()
6113 if (!within(class->key, start, size) && in __lockdep_free_key_range()
6114 !within(class->name, start, size)) in __lockdep_free_key_range()
6123 * freed; and possibly re-used by other modules.
6126 * guaranteed nobody will look up these exact classes -- they're properly dead
6181 * Check whether any element of the @lock->class_cache[] array refers to a
6195 if (lock->class_cache[j] == class) in lock_class_cache_is_registered()
6300 hlist_del_rcu(&k->hash_entry); in lockdep_unregister_key()
6312 /* Wait until is_dynamic_key() has finished accessing k->hash_entry. */ in lockdep_unregister_key()
6352 printk(" per task-struct memory footprint: %zu bytes\n", in lockdep_init()
6353 sizeof(((struct task_struct *)NULL)->held_locks)); in lockdep_init()
6369 pr_warn("-------------------------\n"); in print_freed_lock_bug()
6370 pr_warn("%s/%d is freeing memory %px-%px, with a lock still held there!\n", in print_freed_lock_bug()
6371 curr->comm, task_pid_nr(curr), mem_from, mem_to-1); in print_freed_lock_bug()
6388 * is destroyed or reinitialized - this code checks whether there is
6402 for (i = 0; i < curr->lockdep_depth; i++) { in debug_check_no_locks_freed()
6403 hlock = curr->held_locks + i; in debug_check_no_locks_freed()
6405 if (not_in_range(mem_from, mem_len, hlock->instance, in debug_check_no_locks_freed()
6406 sizeof(*hlock->instance))) in debug_check_no_locks_freed()
6426 current->comm, task_pid_nr(current)); in print_held_locks_bug()
6428 pr_warn("------------------------------------\n"); in print_held_locks_bug()
6436 if (unlikely(current->lockdep_depth > 0)) in debug_check_no_locks_held()
6454 if (!p->lockdep_depth) in debug_show_all_locks()
6486 if (unlikely(curr->lockdep_depth)) { in lockdep_sys_exit()
6493 pr_warn("------------------------------------------------\n"); in lockdep_sys_exit()
6495 curr->comm, curr->pid); in lockdep_sys_exit()
6516 pr_warn("-----------------------------\n"); in lockdep_rcu_suspicious()
6527 * If a CPU is in the RCU-free window in idle (ie: in the section in lockdep_rcu_suspicious()
6533 * such an RCU-idle CPU has called rcu_read_lock(), RCU might well in lockdep_rcu_suspicious()
6535 * choice here: we need to keep an RCU-free window in idle where in lockdep_rcu_suspicious()
6536 * the CPU may possibly enter into low power mode. This way we can in lockdep_rcu_suspicious()