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
90 if (current->lockdep_recursion) in lockdep_enabled()
101 * to use a raw spinlock - we really dont want the spinlock
180 #define KEYHASH_BITS (MAX_LOCKDEP_KEYS_BITS - 1)
193 unsigned int class_idx = hlock->class_idx; in hlock_class()
195 /* Don't re-read hlock->class_idx, can't use READ_ONCE() on bitfield */ in hlock_class()
207 * At this point, if the passed hlock->class_idx is still garbage, in hlock_class()
239 if (time > lt->max) in lock_time_inc()
240 lt->max = time; in lock_time_inc()
242 if (time < lt->min || !lt->nr) in lock_time_inc()
243 lt->min = time; in lock_time_inc()
245 lt->total += time; in lock_time_inc()
246 lt->nr++; in lock_time_inc()
251 if (!src->nr) in lock_time_add()
254 if (src->max > dst->max) in lock_time_add()
255 dst->max = src->max; in lock_time_add()
257 if (src->min < dst->min || !dst->nr) in lock_time_add()
258 dst->min = src->min; in lock_time_add()
260 dst->total += src->total; in lock_time_add()
261 dst->nr += src->nr; in lock_time_add()
272 &per_cpu(cpu_lock_stats, cpu)[class - lock_classes]; in lock_stats()
275 stats.contention_point[i] += pcs->contention_point[i]; in lock_stats()
278 stats.contending_point[i] += pcs->contending_point[i]; in lock_stats()
280 lock_time_add(&pcs->read_waittime, &stats.read_waittime); in lock_stats()
281 lock_time_add(&pcs->write_waittime, &stats.write_waittime); in lock_stats()
283 lock_time_add(&pcs->read_holdtime, &stats.read_holdtime); in lock_stats()
284 lock_time_add(&pcs->write_holdtime, &stats.write_holdtime); in lock_stats()
287 stats.bounces[i] += pcs->bounces[i]; in lock_stats()
299 &per_cpu(cpu_lock_stats, cpu)[class - lock_classes]; in clear_lock_stats()
303 memset(class->contention_point, 0, sizeof(class->contention_point)); in clear_lock_stats()
304 memset(class->contending_point, 0, sizeof(class->contending_point)); in clear_lock_stats()
309 return &this_cpu_ptr(cpu_lock_stats)[class - lock_classes]; in get_lock_stats()
320 holdtime = lockstat_clock() - hlock->holdtime_stamp; in lock_release_holdtime()
323 if (hlock->read) in lock_release_holdtime()
324 lock_time_inc(&stats->read_holdtime, holdtime); in lock_release_holdtime()
326 lock_time_inc(&stats->write_holdtime, holdtime); in lock_release_holdtime()
344 * struct pending_free - information about data structures about to be freed
355 * struct delayed_free - data structures used for delayed freeing
373 * The lockdep classes are in a hash-table as well, for fast lookup:
375 #define CLASSHASH_BITS (MAX_LOCKDEP_KEYS_BITS - 1)
383 * We put the lock dependency chains into a hash-table as well, to cache
386 #define CHAINHASH_BITS (MAX_LOCKDEP_CHAINS_BITS-1)
400 return (hlock->class_idx | (hlock->read << MAX_LOCKDEP_KEYS_BITS)); in hlock_id()
405 return hlock_id & (MAX_LOCKDEP_KEYS - 1); in chain_hlock_class_idx()
411 * It's a 64-bit hash, because it's important for the keys to be
425 task->lockdep_depth = 0; /* no locks held yet */ in lockdep_init_task()
426 task->curr_chain_key = INITIAL_CHAIN_KEY; in lockdep_init_task()
427 task->lockdep_recursion = 0; in lockdep_init_task()
469 if (class->name_version == 1 && in class_filter()
470 !strcmp(class->name, "lockname")) in class_filter()
472 if (class->name_version == 1 && in class_filter()
473 !strcmp(class->name, "&struct->lockfield")) in class_filter()
502 * struct lock_trace - single stack backtrace
517 * Stack-trace: sequence of lock_trace structures. Protected by the graph_lock.
524 return t1->hash == t2->hash && t1->nr_entries == t2->nr_entries && in traces_identical()
525 memcmp(t1->entries, t2->entries, in traces_identical()
526 t1->nr_entries * sizeof(t1->entries[0])) == 0; in traces_identical()
540 max_entries = MAX_STACK_TRACE_ENTRIES - nr_stack_trace_entries - in save_trace()
552 trace->nr_entries = stack_trace_save(trace->entries, max_entries, 3); in save_trace()
554 hash = jhash(trace->entries, trace->nr_entries * in save_trace()
555 sizeof(trace->entries[0]), 0); in save_trace()
556 trace->hash = hash; in save_trace()
557 hash_head = stack_trace_hash + (hash & (STACK_TRACE_HASH_SIZE - 1)); in save_trace()
562 nr_stack_trace_entries += LOCK_TRACE_SIZE_IN_LONGS + trace->nr_entries; in save_trace()
563 hlist_add_head(&trace->hash_entry, hash_head); in save_trace()
616 [LOCK_USED_IN_##__STATE] = "IN-"__stringify(__STATE)"-W", \
617 [LOCK_ENABLED_##__STATE] = __stringify(__STATE)"-ON-W", \
618 [LOCK_USED_IN_##__STATE##_READ] = "IN-"__stringify(__STATE)"-R",\
619 [LOCK_ENABLED_##__STATE##_READ] = __stringify(__STATE)"-ON-R",
629 [LOCK_USAGE_STATES] = "IN-NMI",
655 * - '+': irq is enabled and not in irq context in get_usage_char()
656 * - '-': in irq context and irq is disabled in get_usage_char()
657 * - '?': in irq context and irq is enabled in get_usage_char()
659 if (class->usage_mask & lock_flag(bit + LOCK_USAGE_DIR_MASK)) { in get_usage_char()
661 if (class->usage_mask & lock_flag(bit)) in get_usage_char()
663 } else if (class->usage_mask & lock_flag(bit)) in get_usage_char()
664 c = '-'; in get_usage_char()
687 name = class->name; in __print_lock_name()
689 name = __get_key_name(class->key, str); in __print_lock_name()
693 if (class->name_version > 1) in __print_lock_name()
694 printk(KERN_CONT "#%d", class->name_version); in __print_lock_name()
695 if (class->subclass) in __print_lock_name()
696 printk(KERN_CONT "/%d", class->subclass); in __print_lock_name()
708 printk(KERN_CONT "){%s}-{%hd:%hd}", usage, in print_lock_name()
709 class->wait_type_outer ?: class->wait_type_inner, in print_lock_name()
710 class->wait_type_inner); in print_lock_name()
718 name = lock->name; in print_lockdep_cache()
720 name = __get_key_name(lock->key->subkeys, str); in print_lockdep_cache()
744 printk(KERN_CONT "%px", hlock->instance); in print_lock()
746 printk(KERN_CONT ", at: %pS\n", (void *)hlock->acquire_ip); in print_lock()
751 int i, depth = READ_ONCE(p->lockdep_depth); in lockdep_print_held_locks()
754 printk("no locks held by %s/%d.\n", p->comm, task_pid_nr(p)); in lockdep_print_held_locks()
757 depth > 1 ? "s" : "", p->comm, task_pid_nr(p)); in lockdep_print_held_locks()
762 if (p->state == TASK_RUNNING && p != current) in lockdep_print_held_locks()
766 print_lock(p->held_locks + i); in lockdep_print_held_locks()
772 printk("%s %.*s %s\n", init_utsname()->release, in print_kernel_ident()
773 (int)strcspn(init_utsname()->version, " "), in print_kernel_ident()
774 init_utsname()->version, in print_kernel_ident()
809 * in-kernel percpu var? in static_obj()
823 * class->name_version generation counter. The caller must hold the graph
831 if (!new_class->name) in count_matching_names()
835 if (new_class->key - new_class->subclass == class->key) in count_matching_names()
836 return class->name_version; in count_matching_names()
837 if (class->name && !strcmp(class->name, new_class->name)) in count_matching_names()
838 count = max(count, class->name_version); in count_matching_names()
844 /* used from NMI context -- must be lockless */
866 if (unlikely(!lock->key)) in look_up_lock_class()
870 * NOTE: the class-key must be unique. For dynamic locks, a static in look_up_lock_class()
872 * (or spin_lock_init()) call - which acts as the key. For static in look_up_lock_class()
878 key = lock->key->subkeys + subclass; in look_up_lock_class()
889 if (class->key == key) { in look_up_lock_class()
894 WARN_ON_ONCE(class->name != lock->name && in look_up_lock_class()
895 lock->key != &__lockdep_no_validate__); in look_up_lock_class()
904 * Static locks do not have their class-keys yet - for them the key is
924 lock->key = (void *)can_addr; in assign_lock_key()
926 lock->key = (void *)can_addr; in assign_lock_key()
928 lock->key = (void *)lock; in assign_lock_key()
930 /* Debug-check: all keys must be persistent! */ in assign_lock_key()
932 pr_err("INFO: trying to register non-static key.\n"); in assign_lock_key()
968 if (in_list(e, &class->locks_after) || in in_any_class_list()
969 in_list(e, &class->locks_before)) in in_any_class_list()
980 if (e->links_to != c) { in class_lock_list_valid()
982 c->name ? : "(?)", in class_lock_list_valid()
983 (unsigned long)(e - list_entries), in class_lock_list_valid()
984 e->links_to && e->links_to->name ? in class_lock_list_valid()
985 e->links_to->name : "(?)", in class_lock_list_valid()
986 e->class && e->class->name ? e->class->name : in class_lock_list_valid()
1004 for (i = chain->base; i < chain->base + chain->depth; i++) in check_lock_chain_key()
1010 if (chain->chain_key != chain_key) { in check_lock_chain_key()
1012 (unsigned long long)(chain - lock_chains), in check_lock_chain_key()
1013 (unsigned long long)chain->chain_key, in check_lock_chain_key()
1027 if (in_list(&class->lock_entry, &pf->zapped)) in in_any_zapped_class_list()
1045 if (!in_list(&class->lock_entry, &all_lock_classes) && in __check_data_structures()
1046 !in_list(&class->lock_entry, &free_lock_classes) && in __check_data_structures()
1049 class, class->name ? : "(?)"); in __check_data_structures()
1057 if (!class_lock_list_valid(class, &class->locks_before)) in __check_data_structures()
1059 if (!class_lock_list_valid(class, &class->locks_after)) in __check_data_structures()
1078 if (!in_any_class_list(&e->entry)) { in __check_data_structures()
1080 (unsigned int)(e - list_entries), in __check_data_structures()
1081 e->class->name ? : "(?)", in __check_data_structures()
1082 e->links_to->name ? : "(?)"); in __check_data_structures()
1093 if (in_any_class_list(&e->entry)) { in __check_data_structures()
1095 (unsigned int)(e - list_entries), in __check_data_structures()
1096 e->class && e->class->name ? e->class->name : in __check_data_structures()
1098 e->links_to && e->links_to->name ? in __check_data_structures()
1099 e->links_to->name : "(?)"); in __check_data_structures()
1188 hlist_add_head_rcu(&key->hash_entry, hash_head); in lockdep_register_key()
1209 * a use-after-free in that case by returning early. in is_dynamic_key()
1229 * Register a lock's class in the hash-table, if the class is not present
1246 if (!lock->key) { in register_lock_class()
1249 } else if (!static_obj(lock->key) && !is_dynamic_key(lock->key)) { in register_lock_class()
1253 key = lock->key->subkeys + subclass; in register_lock_class()
1260 * We have to do the hash-walk again, to avoid races in register_lock_class()
1264 if (class->key == key) in register_lock_class()
1283 __set_bit(class - lock_classes, lock_classes_in_use); in register_lock_class()
1285 class->key = key; in register_lock_class()
1286 class->name = lock->name; in register_lock_class()
1287 class->subclass = subclass; in register_lock_class()
1288 WARN_ON_ONCE(!list_empty(&class->locks_before)); in register_lock_class()
1289 WARN_ON_ONCE(!list_empty(&class->locks_after)); in register_lock_class()
1290 class->name_version = count_matching_names(class); in register_lock_class()
1291 class->wait_type_inner = lock->wait_type_inner; in register_lock_class()
1292 class->wait_type_outer = lock->wait_type_outer; in register_lock_class()
1294 * We use RCU's safe list-add method to make in register_lock_class()
1295 * parallel walking of the hash-list safe: in register_lock_class()
1297 hlist_add_head_rcu(&class->hash_entry, hash_head); in register_lock_class()
1302 list_move_tail(&class->lock_entry, &all_lock_classes); in register_lock_class()
1307 printk("\nnew class %px: %s", class->key, class->name); in register_lock_class()
1308 if (class->name_version > 1) in register_lock_class()
1309 printk(KERN_CONT "#%d", class->name_version); in register_lock_class()
1322 lock->class_cache[0] = class; in register_lock_class()
1324 lock->class_cache[subclass] = class; in register_lock_class()
1328 * hash but the subclass -- which is hashed in -- didn't match. in register_lock_class()
1330 if (DEBUG_LOCKS_WARN_ON(class->subclass != subclass)) in register_lock_class()
1369 * Lock not present yet - get a new dependency struct and in add_lock_to_list()
1376 entry->class = this; in add_lock_to_list()
1377 entry->links_to = links_to; in add_lock_to_list()
1378 entry->dep = dep; in add_lock_to_list()
1379 entry->distance = distance; in add_lock_to_list()
1380 entry->trace = trace; in add_lock_to_list()
1383 * iteration is under RCU-sched; see look_up_lock_class() and in add_lock_to_list()
1386 list_add_tail_rcu(&entry->entry, head); in add_lock_to_list()
1392 * For good efficiency of modular, we use power of 2
1395 #define CQ_MASK (MAX_CIRCULAR_QUEUE_SIZE-1)
1399 * breadth-first search (BFS) algorithm, by which we can determine
1402 * indicates that adding the <prev> -> <next> lock dependency will
1403 * produce a circle in the graph. Breadth-first search instead of
1404 * depth-first search is used in order to find the shortest (circular)
1420 cq->front = cq->rear = 0; in __cq_init()
1426 return (cq->front == cq->rear); in __cq_empty()
1431 return ((cq->rear + 1) & CQ_MASK) == cq->front; in __cq_full()
1437 return -1; in __cq_enqueue()
1439 cq->element[cq->rear] = elem; in __cq_enqueue()
1440 cq->rear = (cq->rear + 1) & CQ_MASK; in __cq_enqueue()
1455 lock = cq->element[cq->front]; in __cq_dequeue()
1456 cq->front = (cq->front + 1) & CQ_MASK; in __cq_dequeue()
1463 return (cq->rear - cq->front) & CQ_MASK; in __cq_get_elem_count()
1468 lock->class->dep_gen_id = lockdep_dependency_gen_id; in mark_lock_accessed()
1474 lock->parent = parent; in visit_lock_entry()
1479 return lock->class->dep_gen_id == lockdep_dependency_gen_id; in lock_accessed()
1484 return child->parent; in get_lock_parent()
1508 void *lock_class = lock->class; in get_dep_list()
1529 BFS_EINVALIDNODE = -2,
1530 BFS_EQUEUEFULL = -1,
1546 * For dependency @prev -> @next:
1548 * SR: @prev is shared reader (->read != 0) and @next is recursive reader
1549 * (->read == 2)
1550 * ER: @prev is exclusive locker (->read == 0) and @next is recursive reader
1551 * SN: @prev is shared reader and @next is non-recursive locker (->read != 2)
1552 * EN: @prev is exclusive locker and @next is non-recursive locker
1555 * bit0 is prev->read == 0
1556 * bit1 is next->read != 2
1571 return (prev->read == 0) + ((next->read != 2) << 1); in __calc_dep_bit()
1586 return (next->read != 2) + ((prev->read == 0) << 1); in __calc_dep_bitb()
1601 lock->class = class; in __bfs_init_root()
1602 lock->parent = NULL; in __bfs_init_root()
1603 lock->only_xr = 0; in __bfs_init_root()
1610 * ->only_xr of the initial lock node is set to @hlock->read == 2, to make sure
1611 * that <prev> -> @hlock and @hlock -> <whatever __bfs() found> is not -(*R)->
1612 * and -(S*)->.
1618 lock->only_xr = (hlock->read == 2); in bfs_init_root()
1624 * ->only_xr of the initial lock node is set to @hlock->read != 0, to make sure
1625 * that <next> -> @hlock and @hlock -> <whatever backwards BFS found> is not
1626 * -(*S)-> and -(R*)-> (reverse order of -(*R)-> and -(S*)->).
1632 lock->only_xr = (hlock->read != 0); in bfs_init_rootb()
1637 if (!lock || !lock->parent) in __bfs_next()
1640 return list_next_or_null_rcu(get_dep_list(lock->parent, offset), in __bfs_next()
1641 &lock->entry, struct lock_list, entry); in __bfs_next()
1645 * Breadth-First Search to find a strong path in the dependency graph.
1658 * dependencies as -(*R)-> -(S*)->, please see:
1660 * Documentation/locking/lockdep-design.rst
1667 * has -(*R)-> in the search, and if it does (prev only has -(*R)->), we
1668 * filter out any -(S*)-> in the current dependency and after that, the
1669 * ->only_xr is set according to whether we only have -(*R)-> left.
1690 if (!lock->class) in __bfs()
1698 * @lock->class->locks_{after,before}) we skip, otherwise go in __bfs()
1711 if (lock->parent) { /* Parent exists, check prev dependency */ in __bfs()
1712 u8 dep = lock->dep; in __bfs()
1713 bool prev_only_xr = lock->parent->only_xr; in __bfs()
1716 * Mask out all -(S*)-> if we only have *R in previous in __bfs()
1717 * step, because -(*R)-> -(S*)-> don't make up a strong in __bfs()
1727 /* If there are only -(*R)-> left, set that for the next step */ in __bfs()
1728 lock->only_xr = !(dep & (DEP_SN_MASK | DEP_EN_MASK)); in __bfs()
1798 stack_trace_print(trace->entries, trace->nr_entries, spaces); in print_lock_trace()
1810 printk("\n-> #%u", depth); in print_circular_bug_entry()
1811 print_lock_name(target->class); in print_circular_bug_entry()
1813 print_lock_trace(target->trace, 6); in print_circular_bug_entry()
1823 struct lock_class *parent = prt->class; in print_circular_lock_scenario()
1841 printk(KERN_CONT " --> "); in print_circular_lock_scenario()
1843 printk(KERN_CONT " --> "); in print_circular_lock_scenario()
1850 printk(" ---- ----\n"); in print_circular_lock_scenario()
1884 pr_warn("------------------------------------------------------\n"); in print_circular_bug_header()
1886 curr->comm, task_pid_nr(curr)); in print_circular_bug_header()
1899 * We are about to add A -> B into the dependency graph, and in __bfs() a
1900 * strong dependency path A -> .. -> B is found: hlock_class equals
1901 * entry->class.
1903 * If A -> .. -> B can replace A -> B in any __bfs() search (means the former
1904 * is _stronger_ than or equal to the latter), we consider A -> B as redundant.
1905 * For example if A -> .. -> B is -(EN)-> (i.e. A -(E*)-> .. -(*N)-> B), and A
1906 * -> B is -(ER)-> or -(EN)->, then we don't need to add A -> B into the
1907 * dependency graph, as any strong path ..-> A -> B ->.. we can get with
1908 * having dependency A -> B, we could already get a equivalent path ..-> A ->
1909 * .. -> B -> .. with A -> .. -> B. Therefore A -> B is reduntant.
1911 * We need to make sure both the start and the end of A -> .. -> B is not
1912 * weaker than A -> B. For the start part, please see the comment in
1917 * a) A -> B is -(*R)-> (everything is not weaker than that)
1921 * b) A -> .. -> B is -(*N)-> (nothing is stronger than this)
1928 return hlock_class(hlock) == entry->class && /* Found A -> .. -> B */ in hlock_equal()
1929 (hlock->read == 2 || /* A -> B is -(*R)-> */ in hlock_equal()
1930 !entry->only_xr); /* A -> .. -> B is -(*N)-> */ in hlock_equal()
1934 * We are about to add B -> A into the dependency graph, and in __bfs() a
1935 * strong dependency path A -> .. -> B is found: hlock_class equals
1936 * entry->class.
1938 * We will have a deadlock case (conflict) if A -> .. -> B -> A is a strong
1943 * a) B -> A is -(E*)->
1947 * b) A -> .. -> B is -(*N)-> (i.e. A -> .. -(*N)-> B)
1949 * as then we don't have -(*R)-> -(S*)-> in the cycle.
1955 return hlock_class(hlock) == entry->class && /* Found A -> .. -> B */ in hlock_conflict()
1956 (hlock->read == 0 || /* B -> A is -(E*)-> */ in hlock_conflict()
1957 !entry->only_xr); /* A -> .. -> B is -(*N)-> */ in hlock_conflict()
1973 this->trace = save_trace(); in print_circular_bug()
1974 if (!this->trace) in print_circular_bug()
1985 print_circular_bug_entry(parent, --depth); in print_circular_bug()
2005 * Breadth-first-search failed, graph got corrupted? in print_bfs_bug()
2089 * <target> -> <src> dependency.
2126 * <target> or not. If it can, <src> -> <target> dependency is already
2144 * is equal to or stronger than <src> -> <target>. So if <src> is E, in check_redundant()
2145 * we need to let __bfs() only search for a path starting at a -(E*)->, in check_redundant()
2146 * we achieve this by setting the initial node's ->only_xr to true in in check_redundant()
2147 * that case. And if <prev> is S, we set initial ->only_xr to false in check_redundant()
2148 * because both -(S*)-> (equal) and -(E*)-> (stronger) are redundant. in check_redundant()
2150 src_entry.only_xr = src->read == 0; in check_redundant()
2168 * without creating any illegal irq-safe -> irq-unsafe lock dependency.
2170 * A irq safe->unsafe deadlock happens with the following conditions:
2172 * 1) We have a strong dependency path A -> ... -> B
2175 * irq can create a new dependency B -> A (consider the case that a holder
2178 * 3) the dependency circle A -> ... -> B -> A we get from 1) and 2) is a
2182 * a) if A -> B is -(*N)->, then B -> A could be any type, so any
2184 * b) if A -> B is -(*R)->, then B -> A must be -(E*)->, so only
2188 * c) if A -> B is -(E*)->, then B -> A could be any type, so any
2190 * d) if A -> B is -(S*)->, then B -> A must be -(*N)->, so only
2195 * There is a strong dependency path in the dependency graph: A -> B, and now
2197 * safe->unsafe bugs.
2199 * Note that usage_accumulate() is used in backwards search, so ->only_xr
2200 * stands for whether A -> B only has -(S*)-> (in this case ->only_xr is true).
2202 * As above, if only_xr is false, which means A -> B has -(E*)-> dependency
2208 if (!entry->only_xr) in usage_accumulate()
2209 *(unsigned long *)mask |= entry->class->usage_mask; in usage_accumulate()
2211 *(unsigned long *)mask |= (entry->class->usage_mask & LOCKF_IRQ); in usage_accumulate()
2217 * There is a strong dependency path in the dependency graph: A -> B, and now
2219 * i.e. which usage bit of B may introduce safe->unsafe deadlocks.
2221 * As above, if only_xr is false, which means A -> B has -(*N)-> dependency
2227 if (!entry->only_xr) in usage_match()
2228 return !!(entry->class->usage_mask & *(unsigned long *)mask); in usage_match()
2230 return !!((entry->class->usage_mask & LOCKF_IRQ) & *(unsigned long *)mask); in usage_match()
2234 * Find a node in the forwards-direction dependency sub-graph starting
2235 * at @root->class that matches @bit.
2254 * Find a node in the backwards-direction dependency sub-graph starting
2255 * at @root->class that matches @bit.
2274 printk("%*s->", depth, ""); in print_lock_class_header()
2282 if (class->usage_mask & (1 << bit)) { in print_lock_class_header()
2287 print_lock_trace(class->usage_traces[bit], len); in print_lock_class_header()
2293 depth, "", class->key, class->key); in print_lock_class_header()
2310 print_lock_class_header(entry->class, depth); in print_shortest_lock_dependencies()
2312 print_lock_trace(entry->trace, 2); in print_shortest_lock_dependencies()
2321 depth--; in print_shortest_lock_dependencies()
2331 struct lock_class *safe_class = safe_entry->class; in print_irq_lock_scenario()
2332 struct lock_class *unsafe_class = unsafe_entry->class; in print_irq_lock_scenario()
2354 printk(KERN_CONT " --> "); in print_irq_lock_scenario()
2356 printk(KERN_CONT " --> "); in print_irq_lock_scenario()
2363 printk(" ---- ----\n"); in print_irq_lock_scenario()
2398 pr_warn("WARNING: %s-safe -> %s-unsafe lock order detected\n", in print_bad_irq_dependency()
2401 pr_warn("-----------------------------------------------------\n"); in print_bad_irq_dependency()
2403 curr->comm, task_pid_nr(curr), in print_bad_irq_dependency()
2405 curr->softirq_context, softirq_count() >> SOFTIRQ_SHIFT, in print_bad_irq_dependency()
2407 curr->softirqs_enabled); in print_bad_irq_dependency()
2414 pr_cont(" ->"); in print_bad_irq_dependency()
2418 pr_warn("\nbut this new dependency connects a %s-irq-safe lock:\n", in print_bad_irq_dependency()
2420 print_lock_name(backwards_entry->class); in print_bad_irq_dependency()
2421 pr_warn("\n... which became %s-irq-safe at:\n", irqclass); in print_bad_irq_dependency()
2423 print_lock_trace(backwards_entry->class->usage_traces[bit1], 1); in print_bad_irq_dependency()
2425 pr_warn("\nto a %s-irq-unsafe lock:\n", irqclass); in print_bad_irq_dependency()
2426 print_lock_name(forwards_entry->class); in print_bad_irq_dependency()
2427 pr_warn("\n... which became %s-irq-unsafe at:\n", irqclass); in print_bad_irq_dependency()
2430 print_lock_trace(forwards_entry->class->usage_traces[bit2], 1); in print_bad_irq_dependency()
2438 pr_warn("\nthe dependencies between %s-irq-safe lock and the holding lock:\n", irqclass); in print_bad_irq_dependency()
2439 prev_root->trace = save_trace(); in print_bad_irq_dependency()
2440 if (!prev_root->trace) in print_bad_irq_dependency()
2445 pr_warn(" and %s-irq-unsafe lock:\n", irqclass); in print_bad_irq_dependency()
2446 next_root->trace = save_trace(); in print_bad_irq_dependency()
2447 if (!next_root->trace) in print_bad_irq_dependency()
2464 __stringify(__STATE)"-READ",
2482 * bit2-n: state
2497 * right shift of the mask transforms the individual bitnrs as -1 and
2538 * LOCK_USED_IN_IRQ_* -> LOCK_ENABLED_IRQ_*
2539 * LOCK_USED_IN_IRQ_*_READ -> LOCK_ENABLED_IRQ_*
2540 * LOCK_USED_IN_IRQ_* -> LOCK_ENABLED_IRQ_*_READ
2541 * LOCK_USED_IN_IRQ_*_READ -> LOCK_ENABLED_IRQ_*_READ
2605 return -1; in find_exclusive_match()
2609 * Prove that the new dependency does not connect a hardirq-safe(-read)
2610 * lock with a hardirq-unsafe lock - to achieve this we search
2611 * the backwards-subgraph starting at <prev>, and the
2612 * forwards-subgraph starting at <next>:
2661 backward_mask = original_mask(target_entry1->class->usage_mask); in check_irq_usage()
2675 ret = find_exclusive_match(target_entry->class->usage_mask, in check_irq_usage()
2676 target_entry1->class->usage_mask, in check_irq_usage()
2678 if (DEBUG_LOCKS_WARN_ON(ret == -1)) in check_irq_usage()
2712 nr_hardirq_chains--; in dec_chains()
2714 nr_softirq_chains--; in dec_chains()
2716 nr_process_chains--; in dec_chains()
2727 printk(" ----\n"); in print_deadlock_scenario()
2749 pr_warn("--------------------------------------------\n"); in print_deadlock_bug()
2751 curr->comm, task_pid_nr(curr)); in print_deadlock_bug()
2781 for (i = 0; i < curr->lockdep_depth; i++) { in check_deadlock()
2782 prev = curr->held_locks + i; in check_deadlock()
2784 if (prev->instance == next->nest_lock) in check_deadlock()
2791 * Allow read-after-read recursion of the same in check_deadlock()
2794 if ((next->read == 2) && prev->read) in check_deadlock()
2811 * There was a chain-cache miss, and we are about to add a new dependency
2814 * - would the adding of the <prev> -> <next> dependency create a
2817 * - does the new prev->next dependency connect any hardirq-safe lock
2818 * (in the full backwards-subgraph starting at <prev>) with any
2819 * hardirq-unsafe lock (in the full forwards-subgraph starting at
2822 * - does the new prev->next dependency connect any softirq-safe lock
2823 * (in the full backwards-subgraph starting at <prev>) with any
2824 * softirq-unsafe lock (in the full forwards-subgraph starting at
2840 if (!hlock_class(prev)->key || !hlock_class(next)->key) { in check_prev_add()
2842 * The warning statements below may trigger a use-after-free in check_prev_add()
2843 * of the class name. It is better to trigger a use-after free in check_prev_add()
2847 WARN_ONCE(!debug_locks_silent && !hlock_class(prev)->key, in check_prev_add()
2848 "Detected use-after-free of lock class %px/%s\n", in check_prev_add()
2850 hlock_class(prev)->name); in check_prev_add()
2851 WARN_ONCE(!debug_locks_silent && !hlock_class(next)->key, in check_prev_add()
2852 "Detected use-after-free of lock class %px/%s\n", in check_prev_add()
2854 hlock_class(next)->name); in check_prev_add()
2859 * Prove that the new <prev> -> <next> dependency would not in check_prev_add()
2861 * a breadth-first search into the graph starting at <next>, in check_prev_add()
2876 * Is the <prev> -> <next> dependency already present? in check_prev_add()
2879 * e.g. the L1 -> L2 -> L3 -> L4 and the L5 -> L1 -> L2 -> L3 in check_prev_add()
2880 * chains - the second one will be new, but L1 already has in check_prev_add()
2883 list_for_each_entry(entry, &hlock_class(prev)->locks_after, entry) { in check_prev_add()
2884 if (entry->class == hlock_class(next)) { in check_prev_add()
2886 entry->distance = 1; in check_prev_add()
2887 entry->dep |= calc_dep(prev, next); in check_prev_add()
2891 * ->locks_before list. in check_prev_add()
2905 list_for_each_entry(entry, &hlock_class(next)->locks_before, entry) { in check_prev_add()
2906 if (entry->class == hlock_class(prev)) { in check_prev_add()
2908 entry->distance = 1; in check_prev_add()
2909 entry->dep |= calc_depb(prev, next); in check_prev_add()
2921 * Is the <prev> -> <next> link redundant? in check_prev_add()
2941 &hlock_class(prev)->locks_after, in check_prev_add()
2942 next->acquire_ip, distance, in check_prev_add()
2950 &hlock_class(next)->locks_before, in check_prev_add()
2951 next->acquire_ip, distance, in check_prev_add()
2961 * Add the dependency to all directly-previous locks that are 'relevant'.
2963 * all consecutive trylock entries and the final non-trylock entry - or
2964 * the end of this context's lock-chain - whichever comes first.
2970 int depth = curr->lockdep_depth; in check_prevs_add()
2976 * Depth must not be zero for a non-head lock: in check_prevs_add()
2984 if (curr->held_locks[depth].irq_context != in check_prevs_add()
2985 curr->held_locks[depth-1].irq_context) in check_prevs_add()
2989 u16 distance = curr->lockdep_depth - depth + 1; in check_prevs_add()
2990 hlock = curr->held_locks + depth - 1; in check_prevs_add()
2992 if (hlock->check) { in check_prevs_add()
2998 * Stop after the first non-trylock entry, in check_prevs_add()
2999 * as non-trylock entries have added their in check_prevs_add()
3003 if (!hlock->trylock) in check_prevs_add()
3007 depth--; in check_prevs_add()
3009 * End of lock-stack? in check_prevs_add()
3016 if (curr->held_locks[depth].irq_context != in check_prevs_add()
3017 curr->held_locks[depth-1].irq_context) in check_prevs_add()
3048 * Bit 15 - always set to 1 (it is not a class index)
3049 * Bits 0-14 - upper 15 bits of the next block index
3050 * entry[1] - lower 16 bits of next block index
3054 * On the unsized bucket (bucket-0), the 3rd and 4th entries contain
3057 * entry[2] - upper 16 bits of the chain block size
3058 * entry[3] - lower 16 bits of the chain block size
3071 return size - 1; in size_to_bucket()
3078 for ((prev) = -1, (curr) = chain_block_buckets[bucket]; \
3083 * next block or -1
3092 return -1; in chain_block_next()
3102 * bucket-0 only
3132 * the block before it is re-added. in add_chain_block()
3177 nr_free_chain_hlocks -= size; in del_chain_block()
3181 nr_large_chain_blocks--; in del_chain_block()
3189 chain_block_buckets[i] = -1; in init_chain_block_buckets()
3195 * Return offset of a chain block of the right size or -1 if not found.
3197 * Fairly simple worst-fit allocator with the addition of a number of size
3200 static int alloc_chain_hlocks(int req) in alloc_chain_hlocks() argument
3208 BUILD_BUG_ON((MAX_LOCKDEP_KEYS-1) & CHAIN_BLK_FLAG); in alloc_chain_hlocks()
3212 if (nr_free_chain_hlocks < req) in alloc_chain_hlocks()
3213 return -1; in alloc_chain_hlocks()
3219 req = max(req, 2); in alloc_chain_hlocks()
3220 bucket = size_to_bucket(req); in alloc_chain_hlocks()
3225 del_chain_block(bucket, req, chain_block_next(curr)); in alloc_chain_hlocks()
3238 if (likely(size >= req)) { in alloc_chain_hlocks()
3240 add_chain_block(curr + req, size - req); in alloc_chain_hlocks()
3248 for (size = MAX_CHAIN_BUCKETS; size > req; size--) { in alloc_chain_hlocks()
3255 add_chain_block(curr + req, size - req); in alloc_chain_hlocks()
3259 return -1; in alloc_chain_hlocks()
3269 u16 chain_hlock = chain_hlocks[chain->base + i]; in lock_chain_get_class()
3272 return lock_classes + class_idx - 1; in lock_chain_get_class()
3284 for (i = curr->lockdep_depth - 1; i >= 0; i--) { in get_first_held_lock()
3285 hlock_curr = curr->held_locks + i; in get_first_held_lock()
3286 if (hlock_curr->irq_context != hlock->irq_context) in get_first_held_lock()
3302 printk(" hlock_id:%d -> chain_key:%016Lx", in print_chain_key_iteration()
3313 int depth = curr->lockdep_depth; in print_chain_keys_held_locks()
3316 printk("depth: %u (irq_context %u)\n", depth - i + 1, in print_chain_keys_held_locks()
3317 hlock_next->irq_context); in print_chain_keys_held_locks()
3319 hlock = curr->held_locks + i; in print_chain_keys_held_locks()
3335 printk("depth: %u\n", chain->depth); in print_chain_keys_chain()
3336 for (i = 0; i < chain->depth; i++) { in print_chain_keys_chain()
3337 hlock_id = chain_hlocks[chain->base + i]; in print_chain_keys_chain()
3340 print_lock_name(lock_classes + chain_hlock_class_idx(hlock_id) - 1); in print_chain_keys_chain()
3353 pr_warn("----------------------------\n"); in print_collision()
3354 pr_warn("%s/%d: ", current->comm, task_pid_nr(current)); in print_collision()
3383 if (DEBUG_LOCKS_WARN_ON(chain->depth != curr->lockdep_depth - (i - 1))) { in check_no_collision()
3388 for (j = 0; j < chain->depth - 1; j++, i++) { in check_no_collision()
3389 id = hlock_id(&curr->held_locks[i]); in check_no_collision()
3391 if (DEBUG_LOCKS_WARN_ON(chain_hlocks[chain->base + j] != id)) { in check_no_collision()
3401 * Given an index that is >= -1, return the index of the next lock chain.
3402 * Return -2 if there is no next lock chain.
3407 return i < ARRAY_SIZE(lock_chains) ? i : -2; in lockdep_next_lockchain()
3444 * disabled to make this an IRQ-safe lock.. for recursion reasons in add_chain_cache()
3459 chain->chain_key = chain_key; in add_chain_cache()
3460 chain->irq_context = hlock->irq_context; in add_chain_cache()
3462 chain->depth = curr->lockdep_depth + 1 - i; in add_chain_cache()
3465 BUILD_BUG_ON((1UL << 6) <= ARRAY_SIZE(curr->held_locks)); in add_chain_cache()
3468 j = alloc_chain_hlocks(chain->depth); in add_chain_cache()
3478 chain->base = j; in add_chain_cache()
3479 for (j = 0; j < chain->depth - 1; j++, i++) { in add_chain_cache()
3480 int lock_id = hlock_id(curr->held_locks + i); in add_chain_cache()
3482 chain_hlocks[chain->base + j] = lock_id; in add_chain_cache()
3484 chain_hlocks[chain->base + j] = hlock_id(hlock); in add_chain_cache()
3485 hlist_add_head_rcu(&chain->entry, hash_head); in add_chain_cache()
3487 inc_chains(chain->irq_context); in add_chain_cache()
3502 if (READ_ONCE(chain->chain_key) == chain_key) { in lookup_chain_cache()
3512 * add it and return 1 - in this case the new dependency chain is
3532 class->key, class->name); in lookup_chain_cache_add()
3540 (unsigned long long)chain_key, class->key, class->name); in lookup_chain_cache_add()
3547 * We have to walk the chain again locked - to avoid duplicates: in lookup_chain_cache_add()
3575 if (!hlock->trylock && hlock->check && in validate_chain()
3580 * - is irq-safe, if this lock is irq-unsafe in validate_chain()
3581 * - is softirq-safe, if this lock is hardirq-unsafe in validate_chain()
3586 * - within the current held-lock stack in validate_chain()
3587 * - across our accumulated lock dependency records in validate_chain()
3633 * We are building curr_chain_key incrementally, so double-check
3643 for (i = 0; i < curr->lockdep_depth; i++) { in check_chain_key()
3644 hlock = curr->held_locks + i; in check_chain_key()
3645 if (chain_key != hlock->prev_chain_key) { in check_chain_key()
3652 curr->lockdep_depth, i, in check_chain_key()
3654 (unsigned long long)hlock->prev_chain_key); in check_chain_key()
3659 * hlock->class_idx can't go beyond MAX_LOCKDEP_KEYS, but is in check_chain_key()
3662 if (DEBUG_LOCKS_WARN_ON(!test_bit(hlock->class_idx, lock_classes_in_use))) in check_chain_key()
3665 if (prev_hlock && (prev_hlock->irq_context != in check_chain_key()
3666 hlock->irq_context)) in check_chain_key()
3671 if (chain_key != curr->curr_chain_key) { in check_chain_key()
3678 curr->lockdep_depth, i, in check_chain_key()
3680 (unsigned long long)curr->curr_chain_key); in check_chain_key()
3695 printk(" ----\n"); in print_usage_bug_scenario()
3717 pr_warn("--------------------------------\n"); in print_usage_bug()
3719 pr_warn("inconsistent {%s} -> {%s} usage.\n", in print_usage_bug()
3723 curr->comm, task_pid_nr(curr), in print_usage_bug()
3731 print_lock_trace(hlock_class(this)->usage_traces[prev_bit], 1); in print_usage_bug()
3750 if (unlikely(hlock_class(this)->usage_mask & (1 << bad_bit))) { in valid_state()
3778 pr_warn("--------------------------------------------------------\n"); in print_irq_inversion_bug()
3780 curr->comm, task_pid_nr(curr)); in print_irq_inversion_bug()
3783 pr_warn("but this lock took another, %s-unsafe lock in the past:\n", irqclass); in print_irq_inversion_bug()
3785 pr_warn("but this lock was taken by another, %s-safe lock in the past:\n", irqclass); in print_irq_inversion_bug()
3786 print_lock_name(other->class); in print_irq_inversion_bug()
3800 depth--; in print_irq_inversion_bug()
3804 middle ? middle->class : root->class, other->class); in print_irq_inversion_bug()
3807 middle ? middle->class : other->class, root->class); in print_irq_inversion_bug()
3812 root->trace = save_trace(); in print_irq_inversion_bug()
3813 if (!root->trace) in print_irq_inversion_bug()
3822 * Prove that in the forwards-direction subgraph starting at <this>
3845 if (target_entry->class->usage_mask & lock_flag(bit)) { in check_usage_forwards()
3857 * Prove that in the backwards-direction subgraph starting at <this>
3880 if (target_entry->class->usage_mask & lock_flag(bit)) { in check_usage_backwards()
3893 const struct irqtrace_events *trace = &curr->irqtrace; in print_irqtrace_events()
3895 printk("irq event stamp: %u\n", trace->irq_events); in print_irqtrace_events()
3897 trace->hardirq_enable_event, (void *)trace->hardirq_enable_ip, in print_irqtrace_events()
3898 (void *)trace->hardirq_enable_ip); in print_irqtrace_events()
3900 trace->hardirq_disable_event, (void *)trace->hardirq_disable_ip, in print_irqtrace_events()
3901 (void *)trace->hardirq_disable_ip); in print_irqtrace_events()
3903 trace->softirq_enable_event, (void *)trace->softirq_enable_ip, in print_irqtrace_events()
3904 (void *)trace->softirq_enable_ip); in print_irqtrace_events()
3906 trace->softirq_disable_event, (void *)trace->softirq_disable_ip, in print_irqtrace_events()
3907 (void *)trace->softirq_disable_ip); in print_irqtrace_events()
3971 * mark ENABLED has to look backwards -- to ensure no dependee in mark_lock_irq()
3978 * mark USED_IN has to look forwards -- to ensure no dependency in mark_lock_irq()
4000 for (i = 0; i < curr->lockdep_depth; i++) { in mark_held_locks()
4002 hlock = curr->held_locks + i; in mark_held_locks()
4004 if (hlock->read) in mark_held_locks()
4009 if (!hlock->check) in mark_held_locks()
4037 if (curr->softirqs_enabled) in __trace_hardirqs_on_caller()
4042 * lockdep_hardirqs_on_prepare - Prepare for enabling interrupts
4095 current->hardirq_chain_key = current->curr_chain_key; in lockdep_hardirqs_on_prepare()
4105 struct irqtrace_events *trace = &current->irqtrace; in lockdep_hardirqs_on()
4123 * - recursion check, because NMI can hit lockdep; in lockdep_hardirqs_on()
4124 * - hardware state check, because above; in lockdep_hardirqs_on()
4125 * - chain_key check, see lockdep_hardirqs_on_prepare(). in lockdep_hardirqs_on()
4155 DEBUG_LOCKS_WARN_ON(current->hardirq_chain_key != in lockdep_hardirqs_on()
4156 current->curr_chain_key); in lockdep_hardirqs_on()
4159 /* we'll do an OFF -> ON transition: */ in lockdep_hardirqs_on()
4161 trace->hardirq_enable_ip = ip; in lockdep_hardirqs_on()
4162 trace->hardirq_enable_event = ++trace->irq_events; in lockdep_hardirqs_on()
4194 struct irqtrace_events *trace = &current->irqtrace; in lockdep_hardirqs_off()
4197 * We have done an ON -> OFF transition: in lockdep_hardirqs_off()
4200 trace->hardirq_disable_ip = ip; in lockdep_hardirqs_off()
4201 trace->hardirq_disable_event = ++trace->irq_events; in lockdep_hardirqs_off()
4214 struct irqtrace_events *trace = &current->irqtrace; in lockdep_softirqs_on()
4226 if (current->softirqs_enabled) { in lockdep_softirqs_on()
4233 * We'll do an OFF -> ON transition: in lockdep_softirqs_on()
4235 current->softirqs_enabled = 1; in lockdep_softirqs_on()
4236 trace->softirq_enable_ip = ip; in lockdep_softirqs_on()
4237 trace->softirq_enable_event = ++trace->irq_events; in lockdep_softirqs_on()
4263 if (current->softirqs_enabled) { in lockdep_softirqs_off()
4264 struct irqtrace_events *trace = &current->irqtrace; in lockdep_softirqs_off()
4267 * We have done an ON -> OFF transition: in lockdep_softirqs_off()
4269 current->softirqs_enabled = 0; in lockdep_softirqs_off()
4270 trace->softirq_disable_ip = ip; in lockdep_softirqs_off()
4271 trace->softirq_disable_event = ++trace->irq_events; in lockdep_softirqs_off()
4288 * If non-trylock use in a hardirq or softirq context, then in mark_usage()
4291 if (!hlock->trylock) { in mark_usage()
4292 if (hlock->read) { in mark_usage()
4297 if (curr->softirq_context) in mark_usage()
4305 if (curr->softirq_context) in mark_usage()
4310 if (!hlock->hardirqs_off) { in mark_usage()
4311 if (hlock->read) { in mark_usage()
4315 if (curr->softirqs_enabled) in mark_usage()
4323 if (curr->softirqs_enabled) in mark_usage()
4341 LOCK_CHAIN_SOFTIRQ_CONTEXT * !!task->softirq_context; in task_irq_context()
4347 unsigned int depth = curr->lockdep_depth; in separate_irq_context()
4355 prev_hlock = curr->held_locks + depth-1; in separate_irq_context()
4361 if (prev_hlock->irq_context != hlock->irq_context) in separate_irq_context()
4380 if (new_bit == LOCK_USED && this->read) in mark_lock()
4389 if (likely(hlock_class(this)->usage_mask & new_mask)) in mark_lock()
4397 if (unlikely(hlock_class(this)->usage_mask & new_mask)) in mark_lock()
4400 if (!hlock_class(this)->usage_mask) in mark_lock()
4403 hlock_class(this)->usage_mask |= new_mask; in mark_lock()
4406 if (!(hlock_class(this)->usage_traces[new_bit] = save_trace())) in mark_lock()
4442 if (curr->hardirq_threaded || curr->irq_config) in task_wait_context()
4446 } else if (curr->softirq_context) { in task_wait_context()
4471 pr_warn("-----------------------------\n"); in print_lock_invalid_wait_context()
4473 pr_warn("%s/%d is trying to lock:\n", curr->comm, task_pid_nr(curr)); in print_lock_invalid_wait_context()
4479 pr_warn("context-{%d:%d}\n", curr_inner, curr_inner); in print_lock_invalid_wait_context()
4492 * This check validates we takes locks in the right wait-type order; that is it
4506 short next_inner = hlock_class(next)->wait_type_inner; in check_wait_context()
4507 short next_outer = hlock_class(next)->wait_type_outer; in check_wait_context()
4511 if (!curr->lockdep_depth || !next_inner || next->trylock) in check_wait_context()
4520 for (depth = curr->lockdep_depth - 1; depth >= 0; depth--) { in check_wait_context()
4521 struct held_lock *prev = curr->held_locks + depth; in check_wait_context()
4522 if (prev->irq_context != next->irq_context) in check_wait_context()
4529 for (; depth < curr->lockdep_depth; depth++) { in check_wait_context()
4530 struct held_lock *prev = curr->held_locks + depth; in check_wait_context()
4531 short prev_inner = hlock_class(prev)->wait_type_inner; in check_wait_context()
4578 * Initialize a lock instance's lock-class mapping info:
4587 lock->class_cache[i] = NULL; in lockdep_init_map_waits()
4590 lock->cpu = raw_smp_processor_id(); in lockdep_init_map_waits()
4597 lock->name = "NULL"; in lockdep_init_map_waits()
4601 lock->name = name; in lockdep_init_map_waits()
4603 lock->wait_type_outer = outer; in lockdep_init_map_waits()
4604 lock->wait_type_inner = inner; in lockdep_init_map_waits()
4612 * Sanity check, the lock-class key must either have been allocated in lockdep_init_map_waits()
4621 lock->key = key; in lockdep_init_map_waits()
4658 pr_warn("----------------------------------\n"); in print_lock_nested_lock_not_held()
4660 pr_warn("%s/%d is trying to lock:\n", curr->comm, task_pid_nr(curr)); in print_lock_nested_lock_not_held()
4664 pr_warn("%s\n", hlock->nest_lock->name); in print_lock_nested_lock_not_held()
4702 if (!prove_locking || lock->key == &__lockdep_no_validate__) in __lock_acquire()
4706 class = lock->class_cache[subclass]; in __lock_acquire()
4719 printk("\nacquire class [%px] %s", class->key, class->name); in __lock_acquire()
4720 if (class->name_version > 1) in __lock_acquire()
4721 printk(KERN_CONT "#%d", class->name_version); in __lock_acquire()
4731 depth = curr->lockdep_depth; in __lock_acquire()
4733 * Ran out of static storage for our per-task lock stack again have we? in __lock_acquire()
4738 class_idx = class - lock_classes; in __lock_acquire()
4741 hlock = curr->held_locks + depth - 1; in __lock_acquire()
4742 if (hlock->class_idx == class_idx && nest_lock) { in __lock_acquire()
4746 if (!hlock->references) in __lock_acquire()
4747 hlock->references++; in __lock_acquire()
4749 hlock->references += references; in __lock_acquire()
4752 if (DEBUG_LOCKS_WARN_ON(hlock->references < references)) in __lock_acquire()
4759 hlock = curr->held_locks + depth; in __lock_acquire()
4766 hlock->class_idx = class_idx; in __lock_acquire()
4767 hlock->acquire_ip = ip; in __lock_acquire()
4768 hlock->instance = lock; in __lock_acquire()
4769 hlock->nest_lock = nest_lock; in __lock_acquire()
4770 hlock->irq_context = task_irq_context(curr); in __lock_acquire()
4771 hlock->trylock = trylock; in __lock_acquire()
4772 hlock->read = read; in __lock_acquire()
4773 hlock->check = check; in __lock_acquire()
4774 hlock->hardirqs_off = !!hardirqs_off; in __lock_acquire()
4775 hlock->references = references; in __lock_acquire()
4777 hlock->waittime_stamp = 0; in __lock_acquire()
4778 hlock->holdtime_stamp = lockstat_clock(); in __lock_acquire()
4780 hlock->pin_count = pin_count; in __lock_acquire()
4790 * Calculate the chain hash: it's the combined hash of all the in __lock_acquire()
4797 * the hash, not class->key. in __lock_acquire()
4805 chain_key = curr->curr_chain_key; in __lock_acquire()
4815 hlock->prev_chain_key = chain_key; in __lock_acquire()
4822 if (nest_lock && !__lock_is_held(nest_lock, -1)) { in __lock_acquire()
4828 WARN_ON_ONCE(depth && !hlock_class(hlock - 1)->key); in __lock_acquire()
4829 WARN_ON_ONCE(!hlock_class(hlock)->key); in __lock_acquire()
4835 curr->curr_chain_key = chain_key; in __lock_acquire()
4836 curr->lockdep_depth++; in __lock_acquire()
4842 if (unlikely(curr->lockdep_depth >= MAX_LOCK_DEPTH)) { in __lock_acquire()
4846 curr->lockdep_depth, MAX_LOCK_DEPTH); in __lock_acquire()
4855 if (unlikely(curr->lockdep_depth > max_lockdep_depth)) in __lock_acquire()
4856 max_lockdep_depth = curr->lockdep_depth; in __lock_acquire()
4874 pr_warn("-------------------------------------\n"); in print_unlock_imbalance_bug()
4876 curr->comm, task_pid_nr(curr)); in print_unlock_imbalance_bug()
4891 if (hlock->instance == lock) in match_held_lock()
4894 if (hlock->references) { in match_held_lock()
4895 const struct lock_class *class = lock->class_cache[0]; in match_held_lock()
4910 * References, but not a lock we're actually ref-counting? in match_held_lock()
4911 * State got messed up, follow the sites that change ->references in match_held_lock()
4914 if (DEBUG_LOCKS_WARN_ON(!hlock->nest_lock)) in match_held_lock()
4917 if (hlock->class_idx == class - lock_classes) in match_held_lock()
4932 i = depth - 1; in find_held_lock()
4933 hlock = curr->held_locks + i; in find_held_lock()
4939 for (i--, prev_hlock = hlock--; in find_held_lock()
4941 i--, prev_hlock = hlock--) { in find_held_lock()
4945 if (prev_hlock->irq_context != hlock->irq_context) { in find_held_lock()
4969 for (hlock = curr->held_locks + idx; idx < depth; idx++, hlock++) { in reacquire_held_locks()
4970 switch (__lock_acquire(hlock->instance, in reacquire_held_locks()
4971 hlock_class(hlock)->subclass, in reacquire_held_locks()
4972 hlock->trylock, in reacquire_held_locks()
4973 hlock->read, hlock->check, in reacquire_held_locks()
4974 hlock->hardirqs_off, in reacquire_held_locks()
4975 hlock->nest_lock, hlock->acquire_ip, in reacquire_held_locks()
4976 hlock->references, hlock->pin_count)) { in reacquire_held_locks()
5006 depth = curr->lockdep_depth; in __lock_set_class()
5021 lock->wait_type_inner, in __lock_set_class()
5022 lock->wait_type_outer); in __lock_set_class()
5024 hlock->class_idx = class - lock_classes; in __lock_set_class()
5026 curr->lockdep_depth = i; in __lock_set_class()
5027 curr->curr_chain_key = hlock->prev_chain_key; in __lock_set_class()
5036 if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth - merged)) in __lock_set_class()
5051 depth = curr->lockdep_depth; in __lock_downgrade()
5065 curr->lockdep_depth = i; in __lock_downgrade()
5066 curr->curr_chain_key = hlock->prev_chain_key; in __lock_downgrade()
5068 WARN(hlock->read, "downgrading a read lock"); in __lock_downgrade()
5069 hlock->read = 1; in __lock_downgrade()
5070 hlock->acquire_ip = ip; in __lock_downgrade()
5083 if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth)) in __lock_downgrade()
5090 * Remove the lock from the list of currently held locks - this gets
5105 depth = curr->lockdep_depth; in __lock_release()
5125 if (hlock->instance == lock) in __lock_release()
5128 WARN(hlock->pin_count, "releasing a pinned lock\n"); in __lock_release()
5130 if (hlock->references) { in __lock_release()
5131 hlock->references--; in __lock_release()
5132 if (hlock->references) { in __lock_release()
5148 curr->lockdep_depth = i; in __lock_release()
5149 curr->curr_chain_key = hlock->prev_chain_key; in __lock_release()
5155 if (i == depth-1) in __lock_release()
5163 * there's not N-1 bottles of beer left on the wall... in __lock_release()
5166 DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth - merged); in __lock_release()
5182 for (i = 0; i < curr->lockdep_depth; i++) { in __lock_is_held()
5183 struct held_lock *hlock = curr->held_locks + i; in __lock_is_held()
5186 if (read == -1 || hlock->read == read) in __lock_is_held()
5205 for (i = 0; i < curr->lockdep_depth; i++) { in __lock_pin_lock()
5206 struct held_lock *hlock = curr->held_locks + i; in __lock_pin_lock()
5215 hlock->pin_count += cookie.val; in __lock_pin_lock()
5232 for (i = 0; i < curr->lockdep_depth; i++) { in __lock_repin_lock()
5233 struct held_lock *hlock = curr->held_locks + i; in __lock_repin_lock()
5236 hlock->pin_count += cookie.val; in __lock_repin_lock()
5252 for (i = 0; i < curr->lockdep_depth; i++) { in __lock_unpin_lock()
5253 struct held_lock *hlock = curr->held_locks + i; in __lock_unpin_lock()
5256 if (WARN(!hlock->pin_count, "unpinning an unpinned lock\n")) in __lock_unpin_lock()
5259 hlock->pin_count -= cookie.val; in __lock_unpin_lock()
5261 if (WARN((int)hlock->pin_count < 0, "pin count corrupted\n")) in __lock_unpin_lock()
5262 hlock->pin_count = 0; in __lock_unpin_lock()
5272 * Check whether we follow the irq-flags state precisely:
5282 printk("possible reason: unannotated irqs-off.\n"); in check_flags()
5286 printk("possible reason: unannotated irqs-on.\n"); in check_flags()
5298 DEBUG_LOCKS_WARN_ON(current->softirqs_enabled); in check_flags()
5301 DEBUG_LOCKS_WARN_ON(!current->softirqs_enabled); in check_flags()
5359 * READ locks, there is no deadlock possible -- RCU. in verify_lock_unused()
5361 if (!hlock->read) in verify_lock_unused()
5364 if (!(class->usage_mask & mask)) in verify_lock_unused()
5367 hlock->class_idx = class - lock_classes; in verify_lock_unused()
5399 * We are not always called with irqs disabled - do that here,
5553 pr_warn("---------------------------------\n"); in print_lock_contention_bug()
5555 curr->comm, task_pid_nr(curr)); in print_lock_contention_bug()
5576 depth = curr->lockdep_depth; in __lock_contended()
5590 if (hlock->instance != lock) in __lock_contended()
5593 hlock->waittime_stamp = lockstat_clock(); in __lock_contended()
5595 contention_point = lock_point(hlock_class(hlock)->contention_point, ip); in __lock_contended()
5596 contending_point = lock_point(hlock_class(hlock)->contending_point, in __lock_contended()
5597 lock->ip); in __lock_contended()
5601 stats->contention_point[contention_point]++; in __lock_contended()
5603 stats->contending_point[contending_point]++; in __lock_contended()
5604 if (lock->cpu != smp_processor_id()) in __lock_contended()
5605 stats->bounces[bounce_contended + !!hlock->read]++; in __lock_contended()
5618 depth = curr->lockdep_depth; in __lock_acquired()
5632 if (hlock->instance != lock) in __lock_acquired()
5636 if (hlock->waittime_stamp) { in __lock_acquired()
5638 waittime = now - hlock->waittime_stamp; in __lock_acquired()
5639 hlock->holdtime_stamp = now; in __lock_acquired()
5644 if (hlock->read) in __lock_acquired()
5645 lock_time_inc(&stats->read_waittime, waittime); in __lock_acquired()
5647 lock_time_inc(&stats->write_waittime, waittime); in __lock_acquired()
5649 if (lock->cpu != cpu) in __lock_acquired()
5650 stats->bounces[bounce_acquired + !!hlock->read]++; in __lock_acquired()
5652 lock->cpu = cpu; in __lock_acquired()
5653 lock->ip = ip; in __lock_acquired()
5705 memset(current->held_locks, 0, MAX_LOCK_DEPTH*sizeof(struct held_lock)); in lockdep_reset()
5723 for (i = chain->base; i < chain->base + chain->depth; i++) { in remove_class_from_lock_chain()
5724 if (chain_hlock_class_idx(chain_hlocks[i]) != class - lock_classes) in remove_class_from_lock_chain()
5736 free_chain_hlocks(chain->base, chain->depth); in remove_class_from_lock_chain()
5738 WRITE_ONCE(chain->chain_key, INITIAL_CHAIN_KEY); in remove_class_from_lock_chain()
5739 dec_chains(chain->irq_context); in remove_class_from_lock_chain()
5745 hlist_del_rcu(&chain->entry); in remove_class_from_lock_chain()
5746 __set_bit(chain - lock_chains, pf->lock_chains_being_freed); in remove_class_from_lock_chain()
5775 WARN_ON_ONCE(!class->key); in zap_class()
5783 if (entry->class != class && entry->links_to != class) in zap_class()
5786 nr_list_entries--; in zap_class()
5787 list_del_rcu(&entry->entry); in zap_class()
5789 if (list_empty(&class->locks_after) && in zap_class()
5790 list_empty(&class->locks_before)) { in zap_class()
5791 list_move_tail(&class->lock_entry, &pf->zapped); in zap_class()
5792 hlist_del_rcu(&class->hash_entry); in zap_class()
5793 WRITE_ONCE(class->key, NULL); in zap_class()
5794 WRITE_ONCE(class->name, NULL); in zap_class()
5795 nr_lock_classes--; in zap_class()
5796 __clear_bit(class - lock_classes, lock_classes_in_use); in zap_class()
5799 class->name); in zap_class()
5811 WARN_ON_ONCE(!class->lock_entry.next); in reinit_class()
5812 WARN_ON_ONCE(!list_empty(&class->locks_after)); in reinit_class()
5813 WARN_ON_ONCE(!list_empty(&class->locks_before)); in reinit_class()
5814 memset(p + offset, 0, sizeof(*class) - offset); in reinit_class()
5815 WARN_ON_ONCE(!class->lock_entry.next); in reinit_class()
5816 WARN_ON_ONCE(!list_empty(&class->locks_after)); in reinit_class()
5817 WARN_ON_ONCE(!list_empty(&class->locks_before)); in reinit_class()
5846 if (list_empty(&pf->zapped)) in call_rcu_zapped()
5867 list_for_each_entry(class, &pf->zapped, lock_entry) in __free_zapped_classes()
5870 list_splice_init(&pf->zapped, &free_lock_classes); in __free_zapped_classes()
5874 pf->lock_chains_being_freed, ARRAY_SIZE(lock_chains)); in __free_zapped_classes()
5875 bitmap_clear(pf->lock_chains_being_freed, 0, ARRAY_SIZE(lock_chains)); in __free_zapped_classes()
5921 if (!within(class->key, start, size) && in __lockdep_free_key_range()
5922 !within(class->name, start, size)) in __lockdep_free_key_range()
5931 * freed; and possibly re-used by other modules.
5934 * guaranteed nobody will look up these exact classes -- they're properly dead
5989 * Check whether any element of the @lock->class_cache[] array refers to a
6003 if (lock->class_cache[j] == class) in lock_class_cache_is_registered()
6108 hlist_del_rcu(&k->hash_entry); in lockdep_unregister_key()
6120 /* Wait until is_dynamic_key() has finished accessing k->hash_entry. */ in lockdep_unregister_key()
6160 printk(" per task-struct memory footprint: %zu bytes\n", in lockdep_init()
6161 sizeof(((struct task_struct *)NULL)->held_locks)); in lockdep_init()
6177 pr_warn("-------------------------\n"); in print_freed_lock_bug()
6178 pr_warn("%s/%d is freeing memory %px-%px, with a lock still held there!\n", in print_freed_lock_bug()
6179 curr->comm, task_pid_nr(curr), mem_from, mem_to-1); in print_freed_lock_bug()
6196 * is destroyed or reinitialized - this code checks whether there is
6210 for (i = 0; i < curr->lockdep_depth; i++) { in debug_check_no_locks_freed()
6211 hlock = curr->held_locks + i; in debug_check_no_locks_freed()
6213 if (not_in_range(mem_from, mem_len, hlock->instance, in debug_check_no_locks_freed()
6214 sizeof(*hlock->instance))) in debug_check_no_locks_freed()
6234 current->comm, task_pid_nr(current)); in print_held_locks_bug()
6236 pr_warn("------------------------------------\n"); in print_held_locks_bug()
6244 if (unlikely(current->lockdep_depth > 0)) in debug_check_no_locks_held()
6262 if (!p->lockdep_depth) in debug_show_all_locks()
6294 if (unlikely(curr->lockdep_depth)) { in lockdep_sys_exit()
6301 pr_warn("------------------------------------------------\n"); in lockdep_sys_exit()
6303 curr->comm, curr->pid); in lockdep_sys_exit()
6323 pr_warn("-----------------------------\n"); in lockdep_rcu_suspicious()
6333 * If a CPU is in the RCU-free window in idle (ie: in the section in lockdep_rcu_suspicious()
6339 * such an RCU-idle CPU has called rcu_read_lock(), RCU might well in lockdep_rcu_suspicious()
6341 * choice here: we need to keep an RCU-free window in idle where in lockdep_rcu_suspicious()
6342 * the CPU may possibly enter into low power mode. This way we can in lockdep_rcu_suspicious()