Lines Matching +full:dont +full:- +full:validate

1 // SPDX-License-Identifier: GPL-2.0-only
15 * - lock inversion scenarios
16 * - circular lock dependencies
17 * - hardirq/softirq safe/unsafe locking bugs
122 if (current->lockdep_recursion) in lockdep_enabled()
133 * to use a raw spinlock - we really dont want the spinlock
173 * walking the graph we dont change it (while the other in graph_lock()
212 #define KEYHASH_BITS (MAX_LOCKDEP_KEYS_BITS - 1)
223 unsigned int class_idx = hlock->class_idx; in hlock_class()
225 /* Don't re-read hlock->class_idx, can't use READ_ONCE() on bitfield */ in hlock_class()
237 * At this point, if the passed hlock->class_idx is still garbage, in hlock_class()
269 if (time > lt->max) in lock_time_inc()
270 lt->max = time; in lock_time_inc()
272 if (time < lt->min || !lt->nr) in lock_time_inc()
273 lt->min = time; in lock_time_inc()
275 lt->total += time; in lock_time_inc()
276 lt->nr++; in lock_time_inc()
281 if (!src->nr) in lock_time_add()
284 if (src->max > dst->max) in lock_time_add()
285 dst->max = src->max; in lock_time_add()
287 if (src->min < dst->min || !dst->nr) in lock_time_add()
288 dst->min = src->min; in lock_time_add()
290 dst->total += src->total; in lock_time_add()
291 dst->nr += src->nr; in lock_time_add()
302 &per_cpu(cpu_lock_stats, cpu)[class - lock_classes]; in lock_stats()
305 stats.contention_point[i] += pcs->contention_point[i]; in lock_stats()
308 stats.contending_point[i] += pcs->contending_point[i]; in lock_stats()
310 lock_time_add(&pcs->read_waittime, &stats.read_waittime); in lock_stats()
311 lock_time_add(&pcs->write_waittime, &stats.write_waittime); in lock_stats()
313 lock_time_add(&pcs->read_holdtime, &stats.read_holdtime); in lock_stats()
314 lock_time_add(&pcs->write_holdtime, &stats.write_holdtime); in lock_stats()
317 stats.bounces[i] += pcs->bounces[i]; in lock_stats()
329 &per_cpu(cpu_lock_stats, cpu)[class - lock_classes]; in clear_lock_stats()
333 memset(class->contention_point, 0, sizeof(class->contention_point)); in clear_lock_stats()
334 memset(class->contending_point, 0, sizeof(class->contending_point)); in clear_lock_stats()
339 return &this_cpu_ptr(cpu_lock_stats)[class - lock_classes]; in get_lock_stats()
350 holdtime = lockstat_clock() - hlock->holdtime_stamp; in lock_release_holdtime()
353 if (hlock->read) in lock_release_holdtime()
354 lock_time_inc(&stats->read_holdtime, holdtime); in lock_release_holdtime()
356 lock_time_inc(&stats->write_holdtime, holdtime); in lock_release_holdtime()
374 * struct pending_free - information about data structures about to be freed
385 * struct delayed_free - data structures used for delayed freeing
403 * The lockdep classes are in a hash-table as well, for fast lookup:
405 #define CLASSHASH_BITS (MAX_LOCKDEP_KEYS_BITS - 1)
413 * We put the lock dependency chains into a hash-table as well, to cache
416 #define CHAINHASH_BITS (MAX_LOCKDEP_CHAINS_BITS-1)
430 return (hlock->class_idx | (hlock->read << MAX_LOCKDEP_KEYS_BITS)); in hlock_id()
435 return hlock_id & (MAX_LOCKDEP_KEYS - 1); in chain_hlock_class_idx()
441 * It's a 64-bit hash, because it's important for the keys to be
455 task->lockdep_depth = 0; /* no locks held yet */ in lockdep_init_task()
456 task->curr_chain_key = INITIAL_CHAIN_KEY; in lockdep_init_task()
457 task->lockdep_recursion = 0; in lockdep_init_task()
499 if (class->name_version == 1 && in class_filter()
500 !strcmp(class->name, "lockname")) in class_filter()
502 if (class->name_version == 1 && in class_filter()
503 !strcmp(class->name, "&struct->lockfield")) in class_filter()
532 * struct lock_trace - single stack backtrace
547 * Stack-trace: sequence of lock_trace structures. Protected by the graph_lock.
554 return t1->hash == t2->hash && t1->nr_entries == t2->nr_entries && in traces_identical()
555 memcmp(t1->entries, t2->entries, in traces_identical()
556 t1->nr_entries * sizeof(t1->entries[0])) == 0; in traces_identical()
570 max_entries = MAX_STACK_TRACE_ENTRIES - nr_stack_trace_entries - in save_trace()
582 trace->nr_entries = stack_trace_save(trace->entries, max_entries, 3); in save_trace()
584 hash = jhash(trace->entries, trace->nr_entries * in save_trace()
585 sizeof(trace->entries[0]), 0); in save_trace()
586 trace->hash = hash; in save_trace()
587 hash_head = stack_trace_hash + (hash & (STACK_TRACE_HASH_SIZE - 1)); in save_trace()
592 nr_stack_trace_entries += LOCK_TRACE_SIZE_IN_LONGS + trace->nr_entries; in save_trace()
593 hlist_add_head(&trace->hash_entry, hash_head); in save_trace()
646 [LOCK_USED_IN_##__STATE] = "IN-"__stringify(__STATE)"-W", \
647 [LOCK_ENABLED_##__STATE] = __stringify(__STATE)"-ON-W", \
648 [LOCK_USED_IN_##__STATE##_READ] = "IN-"__stringify(__STATE)"-R",\
649 [LOCK_ENABLED_##__STATE##_READ] = __stringify(__STATE)"-ON-R",
659 [LOCK_USAGE_STATES] = "IN-NMI",
685 * - '+': irq is enabled and not in irq context in get_usage_char()
686 * - '-': in irq context and irq is disabled in get_usage_char()
687 * - '?': in irq context and irq is enabled in get_usage_char()
689 if (class->usage_mask & lock_flag(bit + LOCK_USAGE_DIR_MASK)) { in get_usage_char()
691 if (class->usage_mask & lock_flag(bit)) in get_usage_char()
693 } else if (class->usage_mask & lock_flag(bit)) in get_usage_char()
694 c = '-'; in get_usage_char()
717 name = class->name; in __print_lock_name()
719 name = __get_key_name(class->key, str); in __print_lock_name()
723 if (class->name_version > 1) in __print_lock_name()
724 printk(KERN_CONT "#%d", class->name_version); in __print_lock_name()
725 if (class->subclass) in __print_lock_name()
726 printk(KERN_CONT "/%d", class->subclass); in __print_lock_name()
727 if (hlock && class->print_fn) in __print_lock_name()
728 class->print_fn(hlock->instance); in __print_lock_name()
740 printk(KERN_CONT "){%s}-{%d:%d}", usage, in print_lock_name()
741 class->wait_type_outer ?: class->wait_type_inner, in print_lock_name()
742 class->wait_type_inner); in print_lock_name()
750 name = lock->name; in print_lockdep_cache()
752 name = __get_key_name(lock->key->subkeys, str); in print_lockdep_cache()
776 printk(KERN_CONT "%px", hlock->instance); in print_lock()
778 printk(KERN_CONT ", at: %pS\n", (void *)hlock->acquire_ip); in print_lock()
783 int i, depth = READ_ONCE(p->lockdep_depth); in lockdep_print_held_locks()
786 printk("no locks held by %s/%d.\n", p->comm, task_pid_nr(p)); in lockdep_print_held_locks()
789 depth > 1 ? "s" : "", p->comm, task_pid_nr(p)); in lockdep_print_held_locks()
798 print_lock(p->held_locks + i); in lockdep_print_held_locks()
804 printk("%s %.*s %s\n", init_utsname()->release, in print_kernel_ident()
805 (int)strcspn(init_utsname()->version, " "), in print_kernel_ident()
806 init_utsname()->version, in print_kernel_ident()
845 * in-kernel percpu var? in static_obj()
859 * class->name_version generation counter. The caller must hold the graph
867 if (!new_class->name) in count_matching_names()
871 if (new_class->key - new_class->subclass == class->key) in count_matching_names()
872 return class->name_version; in count_matching_names()
873 if (class->name && !strcmp(class->name, new_class->name)) in count_matching_names()
874 count = max(count, class->name_version); in count_matching_names()
880 /* used from NMI context -- must be lockless */
904 if (unlikely(!lock->key)) in look_up_lock_class()
908 * NOTE: the class-key must be unique. For dynamic locks, a static in look_up_lock_class()
910 * (or spin_lock_init()) call - which acts as the key. For static in look_up_lock_class()
916 key = lock->key->subkeys + subclass; in look_up_lock_class()
927 if (class->key == key) { in look_up_lock_class()
932 WARN_ONCE(class->name != lock->name && in look_up_lock_class()
933 lock->key != &__lockdep_no_validate__, in look_up_lock_class()
935 lock->name, lock->key, class->name); in look_up_lock_class()
944 * Static locks do not have their class-keys yet - for them the key is
964 lock->key = (void *)can_addr; in assign_lock_key()
966 lock->key = (void *)can_addr; in assign_lock_key()
968 lock->key = (void *)lock; in assign_lock_key()
970 /* Debug-check: all keys must be persistent! */ in assign_lock_key()
972 pr_err("INFO: trying to register non-static key.\n"); in assign_lock_key()
1009 if (in_list(e, &class->locks_after) || in in_any_class_list()
1010 in_list(e, &class->locks_before)) in in_any_class_list()
1021 if (e->links_to != c) { in class_lock_list_valid()
1023 c->name ? : "(?)", in class_lock_list_valid()
1024 (unsigned long)(e - list_entries), in class_lock_list_valid()
1025 e->links_to && e->links_to->name ? in class_lock_list_valid()
1026 e->links_to->name : "(?)", in class_lock_list_valid()
1027 e->class && e->class->name ? e->class->name : in class_lock_list_valid()
1045 for (i = chain->base; i < chain->base + chain->depth; i++) in check_lock_chain_key()
1051 if (chain->chain_key != chain_key) { in check_lock_chain_key()
1053 (unsigned long long)(chain - lock_chains), in check_lock_chain_key()
1054 (unsigned long long)chain->chain_key, in check_lock_chain_key()
1068 if (in_list(&class->lock_entry, &pf->zapped)) in in_any_zapped_class_list()
1086 if (!in_list(&class->lock_entry, &all_lock_classes) && in __check_data_structures()
1087 !in_list(&class->lock_entry, &free_lock_classes) && in __check_data_structures()
1090 class, class->name ? : "(?)"); in __check_data_structures()
1098 if (!class_lock_list_valid(class, &class->locks_before)) in __check_data_structures()
1100 if (!class_lock_list_valid(class, &class->locks_after)) in __check_data_structures()
1119 if (!in_any_class_list(&e->entry)) { in __check_data_structures()
1121 (unsigned int)(e - list_entries), in __check_data_structures()
1122 e->class->name ? : "(?)", in __check_data_structures()
1123 e->links_to->name ? : "(?)"); in __check_data_structures()
1134 if (in_any_class_list(&e->entry)) { in __check_data_structures()
1136 (unsigned int)(e - list_entries), in __check_data_structures()
1137 e->class && e->class->name ? e->class->name : in __check_data_structures()
1139 e->links_to && e->links_to->name ? in __check_data_structures()
1140 e->links_to->name : "(?)"); in __check_data_structures()
1229 hlist_add_head_rcu(&key->hash_entry, hash_head); in lockdep_register_key()
1250 * a use-after-free in that case by returning early. in is_dynamic_key()
1270 * Register a lock's class in the hash-table, if the class is not present
1288 if (!lock->key) { in register_lock_class()
1291 } else if (!static_obj(lock->key) && !is_dynamic_key(lock->key)) { in register_lock_class()
1295 key = lock->key->subkeys + subclass; in register_lock_class()
1302 * We have to do the hash-walk again, to avoid races in register_lock_class()
1306 if (class->key == key) in register_lock_class()
1325 __set_bit(class - lock_classes, lock_classes_in_use); in register_lock_class()
1327 class->key = key; in register_lock_class()
1328 class->name = lock->name; in register_lock_class()
1329 class->subclass = subclass; in register_lock_class()
1330 WARN_ON_ONCE(!list_empty(&class->locks_before)); in register_lock_class()
1331 WARN_ON_ONCE(!list_empty(&class->locks_after)); in register_lock_class()
1332 class->name_version = count_matching_names(class); in register_lock_class()
1333 class->wait_type_inner = lock->wait_type_inner; in register_lock_class()
1334 class->wait_type_outer = lock->wait_type_outer; in register_lock_class()
1335 class->lock_type = lock->lock_type; in register_lock_class()
1337 * We use RCU's safe list-add method to make in register_lock_class()
1338 * parallel walking of the hash-list safe: in register_lock_class()
1340 hlist_add_head_rcu(&class->hash_entry, hash_head); in register_lock_class()
1345 list_move_tail(&class->lock_entry, &all_lock_classes); in register_lock_class()
1346 idx = class - lock_classes; in register_lock_class()
1353 printk("\nnew class %px: %s", class->key, class->name); in register_lock_class()
1354 if (class->name_version > 1) in register_lock_class()
1355 printk(KERN_CONT "#%d", class->name_version); in register_lock_class()
1368 lock->class_cache[0] = class; in register_lock_class()
1370 lock->class_cache[subclass] = class; in register_lock_class()
1374 * hash but the subclass -- which is hashed in -- didn't match. in register_lock_class()
1376 if (DEBUG_LOCKS_WARN_ON(class->subclass != subclass)) in register_lock_class()
1415 * Lock not present yet - get a new dependency struct and in add_lock_to_list()
1422 entry->class = this; in add_lock_to_list()
1423 entry->links_to = links_to; in add_lock_to_list()
1424 entry->dep = dep; in add_lock_to_list()
1425 entry->distance = distance; in add_lock_to_list()
1426 entry->trace = trace; in add_lock_to_list()
1429 * iteration is under RCU-sched; see look_up_lock_class() and in add_lock_to_list()
1432 list_add_tail_rcu(&entry->entry, head); in add_lock_to_list()
1441 #define CQ_MASK (MAX_CIRCULAR_QUEUE_SIZE-1)
1445 * breadth-first search (BFS) algorithm, by which we can determine
1448 * indicates that adding the <prev> -> <next> lock dependency will
1449 * produce a circle in the graph. Breadth-first search instead of
1450 * depth-first search is used in order to find the shortest (circular)
1466 cq->front = cq->rear = 0; in __cq_init()
1472 return (cq->front == cq->rear); in __cq_empty()
1477 return ((cq->rear + 1) & CQ_MASK) == cq->front; in __cq_full()
1483 return -1; in __cq_enqueue()
1485 cq->element[cq->rear] = elem; in __cq_enqueue()
1486 cq->rear = (cq->rear + 1) & CQ_MASK; in __cq_enqueue()
1501 lock = cq->element[cq->front]; in __cq_dequeue()
1502 cq->front = (cq->front + 1) & CQ_MASK; in __cq_dequeue()
1509 return (cq->rear - cq->front) & CQ_MASK; in __cq_get_elem_count()
1514 lock->class->dep_gen_id = lockdep_dependency_gen_id; in mark_lock_accessed()
1520 lock->parent = parent; in visit_lock_entry()
1525 return lock->class->dep_gen_id == lockdep_dependency_gen_id; in lock_accessed()
1530 return child->parent; in get_lock_parent()
1554 void *lock_class = lock->class; in get_dep_list()
1575 BFS_EINVALIDNODE = -2,
1576 BFS_EQUEUEFULL = -1,
1592 * For dependency @prev -> @next:
1594 * SR: @prev is shared reader (->read != 0) and @next is recursive reader
1595 * (->read == 2)
1596 * ER: @prev is exclusive locker (->read == 0) and @next is recursive reader
1597 * SN: @prev is shared reader and @next is non-recursive locker (->read != 2)
1598 * EN: @prev is exclusive locker and @next is non-recursive locker
1601 * bit0 is prev->read == 0
1602 * bit1 is next->read != 2
1617 return (prev->read == 0) + ((next->read != 2) << 1); in __calc_dep_bit()
1632 return (next->read != 2) + ((prev->read == 0) << 1); in __calc_dep_bitb()
1647 lock->class = class; in __bfs_init_root()
1648 lock->parent = NULL; in __bfs_init_root()
1649 lock->only_xr = 0; in __bfs_init_root()
1656 * ->only_xr of the initial lock node is set to @hlock->read == 2, to make sure
1657 * that <prev> -> @hlock and @hlock -> <whatever __bfs() found> is not -(*R)->
1658 * and -(S*)->.
1664 lock->only_xr = (hlock->read == 2); in bfs_init_root()
1670 * ->only_xr of the initial lock node is set to @hlock->read != 0, to make sure
1671 * that <next> -> @hlock and @hlock -> <whatever backwards BFS found> is not
1672 * -(*S)-> and -(R*)-> (reverse order of -(*R)-> and -(S*)->).
1678 lock->only_xr = (hlock->read != 0); in bfs_init_rootb()
1683 if (!lock || !lock->parent) in __bfs_next()
1686 return list_next_or_null_rcu(get_dep_list(lock->parent, offset), in __bfs_next()
1687 &lock->entry, struct lock_list, entry); in __bfs_next()
1691 * Breadth-First Search to find a strong path in the dependency graph.
1704 * dependencies as -(*R)-> -(S*)->, please see:
1706 * Documentation/locking/lockdep-design.rst
1713 * has -(*R)-> in the search, and if it does (prev only has -(*R)->), we
1714 * filter out any -(S*)-> in the current dependency and after that, the
1715 * ->only_xr is set according to whether we only have -(*R)-> left.
1737 if (!lock->class) in __bfs()
1745 * @lock->class->locks_{after,before}) we skip, otherwise go in __bfs()
1758 if (lock->parent) { /* Parent exists, check prev dependency */ in __bfs()
1759 u8 dep = lock->dep; in __bfs()
1760 bool prev_only_xr = lock->parent->only_xr; in __bfs()
1763 * Mask out all -(S*)-> if we only have *R in previous in __bfs()
1764 * step, because -(*R)-> -(S*)-> don't make up a strong in __bfs()
1774 /* If there are only -(*R)-> left, set that for the next step */ in __bfs()
1775 lock->only_xr = !(dep & (DEP_SN_MASK | DEP_EN_MASK)); in __bfs()
1852 stack_trace_print(trace->entries, trace->nr_entries, spaces); in print_lock_trace()
1864 printk("\n-> #%u", depth); in print_circular_bug_entry()
1865 print_lock_name(NULL, target->class); in print_circular_bug_entry()
1867 print_lock_trace(target->trace, 6); in print_circular_bug_entry()
1877 struct lock_class *parent = prt->class; in print_circular_lock_scenario()
1878 int src_read = src->read; in print_circular_lock_scenario()
1879 int tgt_read = tgt->read; in print_circular_lock_scenario()
1897 printk(KERN_CONT " --> "); in print_circular_lock_scenario()
1899 printk(KERN_CONT " --> "); in print_circular_lock_scenario()
1906 printk(" ---- ----\n"); in print_circular_lock_scenario()
1921 else if (src->sync) in print_circular_lock_scenario()
1948 pr_warn("------------------------------------------------------\n"); in print_circular_bug_header()
1950 curr->comm, task_pid_nr(curr)); in print_circular_bug_header()
1963 * We are about to add A -> B into the dependency graph, and in __bfs() a
1964 * strong dependency path A -> .. -> B is found: hlock_class equals
1965 * entry->class.
1967 * If A -> .. -> B can replace A -> B in any __bfs() search (means the former
1968 * is _stronger_ than or equal to the latter), we consider A -> B as redundant.
1969 * For example if A -> .. -> B is -(EN)-> (i.e. A -(E*)-> .. -(*N)-> B), and A
1970 * -> B is -(ER)-> or -(EN)->, then we don't need to add A -> B into the
1971 * dependency graph, as any strong path ..-> A -> B ->.. we can get with
1972 * having dependency A -> B, we could already get a equivalent path ..-> A ->
1973 * .. -> B -> .. with A -> .. -> B. Therefore A -> B is redundant.
1975 * We need to make sure both the start and the end of A -> .. -> B is not
1976 * weaker than A -> B. For the start part, please see the comment in
1981 * a) A -> B is -(*R)-> (everything is not weaker than that)
1985 * b) A -> .. -> B is -(*N)-> (nothing is stronger than this)
1992 return hlock_class(hlock) == entry->class && /* Found A -> .. -> B */ in hlock_equal()
1993 (hlock->read == 2 || /* A -> B is -(*R)-> */ in hlock_equal()
1994 !entry->only_xr); /* A -> .. -> B is -(*N)-> */ in hlock_equal()
1998 * We are about to add B -> A into the dependency graph, and in __bfs() a
1999 * strong dependency path A -> .. -> B is found: hlock_class equals
2000 * entry->class.
2002 * We will have a deadlock case (conflict) if A -> .. -> B -> A is a strong
2007 * a) B -> A is -(E*)->
2011 * b) A -> .. -> B is -(*N)-> (i.e. A -> .. -(*N)-> B)
2013 * as then we don't have -(*R)-> -(S*)-> in the cycle.
2019 return hlock_class(hlock) == entry->class && /* Found A -> .. -> B */ in hlock_conflict()
2020 (hlock->read == 0 || /* B -> A is -(E*)-> */ in hlock_conflict()
2021 !entry->only_xr); /* A -> .. -> B is -(*N)-> */ in hlock_conflict()
2037 this->trace = save_trace(); in print_circular_bug()
2038 if (!this->trace) in print_circular_bug()
2049 print_circular_bug_entry(parent, --depth); in print_circular_bug()
2069 * Breadth-first-search failed, graph got corrupted? in print_bfs_bug()
2156 * <target> -> <src> dependency.
2184 if (src->class_idx == target->class_idx) in check_noncircular()
2198 * without creating any illegal irq-safe -> irq-unsafe lock dependency.
2200 * A irq safe->unsafe deadlock happens with the following conditions:
2202 * 1) We have a strong dependency path A -> ... -> B
2205 * irq can create a new dependency B -> A (consider the case that a holder
2208 * 3) the dependency circle A -> ... -> B -> A we get from 1) and 2) is a
2212 * a) if A -> B is -(*N)->, then B -> A could be any type, so any
2214 * b) if A -> B is -(*R)->, then B -> A must be -(E*)->, so only
2218 * c) if A -> B is -(E*)->, then B -> A could be any type, so any
2220 * d) if A -> B is -(S*)->, then B -> A must be -(*N)->, so only
2225 * There is a strong dependency path in the dependency graph: A -> B, and now
2227 * safe->unsafe bugs.
2229 * Note that usage_accumulate() is used in backwards search, so ->only_xr
2230 * stands for whether A -> B only has -(S*)-> (in this case ->only_xr is true).
2232 * As above, if only_xr is false, which means A -> B has -(E*)-> dependency
2238 if (!entry->only_xr) in usage_accumulate()
2239 *(unsigned long *)mask |= entry->class->usage_mask; in usage_accumulate()
2241 *(unsigned long *)mask |= (entry->class->usage_mask & LOCKF_IRQ); in usage_accumulate()
2247 * There is a strong dependency path in the dependency graph: A -> B, and now
2249 * i.e. which usage bit of B may introduce safe->unsafe deadlocks.
2251 * As above, if only_xr is false, which means A -> B has -(*N)-> dependency
2257 if (!entry->only_xr) in usage_match()
2258 return !!(entry->class->usage_mask & *(unsigned long *)mask); in usage_match()
2260 return !!((entry->class->usage_mask & LOCKF_IRQ) & *(unsigned long *)mask); in usage_match()
2265 if (entry->class->lock_type == LD_LOCK_NORMAL) in usage_skip()
2281 * where lock(B) cannot sleep, and we have a dependency B -> ... -> A. in usage_skip()
2284 * have the observation for any lock chain L1 -> ... -> Ln, for any in usage_skip()
2289 * way the local_lock() exists in the dependency B -> ... -> A. in usage_skip()
2294 if (entry->class->lock_type == LD_LOCK_PERCPU && in usage_skip()
2295 DEBUG_LOCKS_WARN_ON(entry->class->wait_type_inner < LD_WAIT_CONFIG)) in usage_skip()
2299 * Skip WAIT_OVERRIDE for irq inversion detection -- it's not actually in usage_skip()
2307 * Find a node in the forwards-direction dependency sub-graph starting
2308 * at @root->class that matches @bit.
2327 * Find a node in the backwards-direction dependency sub-graph starting
2328 * at @root->class that matches @bit.
2347 printk("%*s->", depth, ""); in print_lock_class_header()
2355 if (class->usage_mask & (1 << bit)) { in print_lock_class_header()
2360 print_lock_trace(class->usage_traces[bit], len); in print_lock_class_header()
2366 depth, "", class->key, class->key); in print_lock_class_header()
2372 * After BFS we get a lock dependency path (linked via ->parent of lock_list),
2378 * for a lock dependency A -> B, there are two lock_lists:
2380 * a) lock_list in the ->locks_after list of A, whose ->class is B and
2381 * ->links_to is A. In this case, we can say the lock_list is
2382 * "A -> B" (forwards case).
2384 * b) lock_list in the ->locks_before list of B, whose ->class is A
2385 * and ->links_to is B. In this case, we can say the lock_list is
2386 * "B <- A" (bacwards case).
2388 * The ->trace of both a) and b) point to the call trace where B was
2394 * ->class is A, as a result BFS will search all dependencies starting with
2395 * A, e.g. A -> B or A -> C.
2397 * The notation of a forwards helper lock_list is like "-> A", which means
2398 * we should search the forwards dependencies starting with "A", e.g A -> B
2399 * or A -> C.
2401 * The notation of a bacwards helper lock_list is like "<- B", which means
2403 * B <- A or B <- C.
2414 * ->parent ->parent
2415 * | lock_list | <--------- | lock_list | ... | lock_list | <--------- | lock_list |
2416 * | -> L1 | | L1 -> L2 | ... |Ln-2 -> Ln-1| | Ln-1 -> Ln|
2418 * , so it's natural that we start from @leaf and print every ->class and
2419 * ->trace until we reach the @root.
2432 print_lock_class_header(entry->class, depth); in print_shortest_lock_dependencies()
2434 print_lock_trace(entry->trace, 2); in print_shortest_lock_dependencies()
2443 depth--; in print_shortest_lock_dependencies()
2455 * ->parent ->parent
2456 * | lock_list | ---------> | lock_list | ... | lock_list | ---------> | lock_list |
2457 * | L2 <- L1 | | L3 <- L2 | ... | Ln <- Ln-1 | | <- Ln |
2460 * dependency path L1 -> L2 -> .. -> Ln in the non-reverse order.
2462 * Another thing to notice here is that ->class of L2 <- L1 is L1, while the
2463 * ->trace of L2 <- L1 is the call trace of L2, in fact we don't have the call
2479 print_lock_class_header(entry->class, depth); in print_shortest_lock_dependencies_backwards()
2490 trace = entry->trace; in print_shortest_lock_dependencies_backwards()
2498 depth--; in print_shortest_lock_dependencies_backwards()
2508 struct lock_class *safe_class = safe_entry->class; in print_irq_lock_scenario()
2509 struct lock_class *unsafe_class = unsafe_entry->class; in print_irq_lock_scenario()
2531 printk(KERN_CONT " --> "); in print_irq_lock_scenario()
2533 printk(KERN_CONT " --> "); in print_irq_lock_scenario()
2540 printk(" ---- ----\n"); in print_irq_lock_scenario()
2575 pr_warn("WARNING: %s-safe -> %s-unsafe lock order detected\n", in print_bad_irq_dependency()
2578 pr_warn("-----------------------------------------------------\n"); in print_bad_irq_dependency()
2580 curr->comm, task_pid_nr(curr), in print_bad_irq_dependency()
2582 curr->softirq_context, softirq_count() >> SOFTIRQ_SHIFT, in print_bad_irq_dependency()
2584 curr->softirqs_enabled); in print_bad_irq_dependency()
2591 pr_cont(" ->"); in print_bad_irq_dependency()
2595 pr_warn("\nbut this new dependency connects a %s-irq-safe lock:\n", in print_bad_irq_dependency()
2597 print_lock_name(NULL, backwards_entry->class); in print_bad_irq_dependency()
2598 pr_warn("\n... which became %s-irq-safe at:\n", irqclass); in print_bad_irq_dependency()
2600 print_lock_trace(backwards_entry->class->usage_traces[bit1], 1); in print_bad_irq_dependency()
2602 pr_warn("\nto a %s-irq-unsafe lock:\n", irqclass); in print_bad_irq_dependency()
2603 print_lock_name(NULL, forwards_entry->class); in print_bad_irq_dependency()
2604 pr_warn("\n... which became %s-irq-unsafe at:\n", irqclass); in print_bad_irq_dependency()
2607 print_lock_trace(forwards_entry->class->usage_traces[bit2], 1); in print_bad_irq_dependency()
2615 pr_warn("\nthe dependencies between %s-irq-safe lock and the holding lock:\n", irqclass); in print_bad_irq_dependency()
2619 pr_warn(" and %s-irq-unsafe lock:\n", irqclass); in print_bad_irq_dependency()
2620 next_root->trace = save_trace(); in print_bad_irq_dependency()
2621 if (!next_root->trace) in print_bad_irq_dependency()
2638 __stringify(__STATE)"-READ",
2656 * bit2-n: state
2671 * right shift of the mask transforms the individual bitnrs as -1 and
2712 * LOCK_USED_IN_IRQ_* -> LOCK_ENABLED_IRQ_*
2713 * LOCK_USED_IN_IRQ_*_READ -> LOCK_ENABLED_IRQ_*
2714 * LOCK_USED_IN_IRQ_* -> LOCK_ENABLED_IRQ_*_READ
2715 * LOCK_USED_IN_IRQ_*_READ -> LOCK_ENABLED_IRQ_*_READ
2779 return -1; in find_exclusive_match()
2783 * Prove that the new dependency does not connect a hardirq-safe(-read)
2784 * lock with a hardirq-unsafe lock - to achieve this we search
2785 * the backwards-subgraph starting at <prev>, and the
2786 * forwards-subgraph starting at <next>:
2838 * When trying to add A -> B to the graph, we find that there is a in check_irq_usage()
2839 * hardirq-safe L, that L -> ... -> A, and another hardirq-unsafe M, in check_irq_usage()
2840 * that B -> ... -> M. However M is **softirq-safe**, if we use exact in check_irq_usage()
2842 * **softirq-unsafe** and N -> ... -> A, however N -> .. -> M will not in check_irq_usage()
2845 backward_mask = original_mask(target_entry1->class->usage_mask & LOCKF_ENABLED_IRQ_ALL); in check_irq_usage()
2859 ret = find_exclusive_match(target_entry->class->usage_mask, in check_irq_usage()
2860 target_entry1->class->usage_mask, in check_irq_usage()
2862 if (DEBUG_LOCKS_WARN_ON(ret == -1)) in check_irq_usage()
2892 * <target> or not. If it can, <src> -> <target> dependency is already
2910 * is equal to or stronger than <src> -> <target>. So if <src> is E, in check_redundant()
2911 * we need to let __bfs() only search for a path starting at a -(E*)->, in check_redundant()
2912 * we achieve this by setting the initial node's ->only_xr to true in in check_redundant()
2913 * that case. And if <prev> is S, we set initial ->only_xr to false in check_redundant()
2914 * because both -(S*)-> (equal) and -(E*)-> (stronger) are redundant. in check_redundant()
2916 src_entry.only_xr = src->read == 0; in check_redundant()
2922 * comment in usage_skip(), A -> local_lock() -> B and A -> B are not in check_redundant()
2956 nr_hardirq_chains--; in dec_chains()
2958 nr_softirq_chains--; in dec_chains()
2960 nr_process_chains--; in dec_chains()
2971 printk(" ----\n"); in print_deadlock_scenario()
2995 pr_warn("--------------------------------------------\n"); in print_deadlock_bug()
2997 curr->comm, task_pid_nr(curr)); in print_deadlock_bug()
3002 if (class->cmp_fn) { in print_deadlock_bug()
3004 class->cmp_fn(prev->instance, next->instance)); in print_deadlock_bug()
3033 for (i = 0; i < curr->lockdep_depth; i++) { in check_deadlock()
3034 prev = curr->held_locks + i; in check_deadlock()
3036 if (prev->instance == next->nest_lock) in check_deadlock()
3043 * Allow read-after-read recursion of the same in check_deadlock()
3046 if ((next->read == 2) && prev->read) in check_deadlock()
3051 if (class->cmp_fn && in check_deadlock()
3052 class->cmp_fn(prev->instance, next->instance) < 0) in check_deadlock()
3069 * There was a chain-cache miss, and we are about to add a new dependency
3070 * to a previous lock. We validate the following rules:
3072 * - would the adding of the <prev> -> <next> dependency create a
3075 * - does the new prev->next dependency connect any hardirq-safe lock
3076 * (in the full backwards-subgraph starting at <prev>) with any
3077 * hardirq-unsafe lock (in the full forwards-subgraph starting at
3080 * - does the new prev->next dependency connect any softirq-safe lock
3081 * (in the full backwards-subgraph starting at <prev>) with any
3082 * softirq-unsafe lock (in the full forwards-subgraph starting at
3098 if (!hlock_class(prev)->key || !hlock_class(next)->key) { in check_prev_add()
3100 * The warning statements below may trigger a use-after-free in check_prev_add()
3101 * of the class name. It is better to trigger a use-after free in check_prev_add()
3105 WARN_ONCE(!debug_locks_silent && !hlock_class(prev)->key, in check_prev_add()
3106 "Detected use-after-free of lock class %px/%s\n", in check_prev_add()
3108 hlock_class(prev)->name); in check_prev_add()
3109 WARN_ONCE(!debug_locks_silent && !hlock_class(next)->key, in check_prev_add()
3110 "Detected use-after-free of lock class %px/%s\n", in check_prev_add()
3112 hlock_class(next)->name); in check_prev_add()
3116 if (prev->class_idx == next->class_idx) { in check_prev_add()
3119 if (class->cmp_fn && in check_prev_add()
3120 class->cmp_fn(prev->instance, next->instance) < 0) in check_prev_add()
3125 * Prove that the new <prev> -> <next> dependency would not in check_prev_add()
3127 * a breadth-first search into the graph starting at <next>, in check_prev_add()
3142 * Is the <prev> -> <next> dependency already present? in check_prev_add()
3145 * e.g. the L1 -> L2 -> L3 -> L4 and the L5 -> L1 -> L2 -> L3 in check_prev_add()
3146 * chains - the second one will be new, but L1 already has in check_prev_add()
3149 list_for_each_entry(entry, &hlock_class(prev)->locks_after, entry) { in check_prev_add()
3150 if (entry->class == hlock_class(next)) { in check_prev_add()
3152 entry->distance = 1; in check_prev_add()
3153 entry->dep |= calc_dep(prev, next); in check_prev_add()
3157 * ->locks_before list. in check_prev_add()
3171 list_for_each_entry(entry, &hlock_class(next)->locks_before, entry) { in check_prev_add()
3172 if (entry->class == hlock_class(prev)) { in check_prev_add()
3174 entry->distance = 1; in check_prev_add()
3175 entry->dep |= calc_depb(prev, next); in check_prev_add()
3186 * Is the <prev> -> <next> link redundant? in check_prev_add()
3205 &hlock_class(prev)->locks_after, distance, in check_prev_add()
3212 &hlock_class(next)->locks_before, distance, in check_prev_add()
3221 * Add the dependency to all directly-previous locks that are 'relevant'.
3223 * all consecutive trylock entries and the final non-trylock entry - or
3224 * the end of this context's lock-chain - whichever comes first.
3230 int depth = curr->lockdep_depth; in check_prevs_add()
3236 * Depth must not be zero for a non-head lock: in check_prevs_add()
3244 if (curr->held_locks[depth].irq_context != in check_prevs_add()
3245 curr->held_locks[depth-1].irq_context) in check_prevs_add()
3249 u16 distance = curr->lockdep_depth - depth + 1; in check_prevs_add()
3250 hlock = curr->held_locks + depth - 1; in check_prevs_add()
3252 if (hlock->check) { in check_prevs_add()
3258 * Stop after the first non-trylock entry, in check_prevs_add()
3259 * as non-trylock entries have added their in check_prevs_add()
3263 if (!hlock->trylock) in check_prevs_add()
3267 depth--; in check_prevs_add()
3269 * End of lock-stack? in check_prevs_add()
3276 if (curr->held_locks[depth].irq_context != in check_prevs_add()
3277 curr->held_locks[depth-1].irq_context) in check_prevs_add()
3308 * Bit 15 - always set to 1 (it is not a class index)
3309 * Bits 0-14 - upper 15 bits of the next block index
3310 * entry[1] - lower 16 bits of next block index
3314 * On the unsized bucket (bucket-0), the 3rd and 4th entries contain
3317 * entry[2] - upper 16 bits of the chain block size
3318 * entry[3] - lower 16 bits of the chain block size
3331 return size - 1; in size_to_bucket()
3338 for ((prev) = -1, (curr) = chain_block_buckets[bucket]; \
3343 * next block or -1
3352 return -1; in chain_block_next()
3362 * bucket-0 only
3392 * the block before it is re-added. in add_chain_block()
3437 nr_free_chain_hlocks -= size; in del_chain_block()
3441 nr_large_chain_blocks--; in del_chain_block()
3449 chain_block_buckets[i] = -1; in init_chain_block_buckets()
3455 * Return offset of a chain block of the right size or -1 if not found.
3457 * Fairly simple worst-fit allocator with the addition of a number of size
3468 BUILD_BUG_ON((MAX_LOCKDEP_KEYS-1) & CHAIN_BLK_FLAG); in alloc_chain_hlocks()
3473 return -1; in alloc_chain_hlocks()
3501 add_chain_block(curr + req, size - req); in alloc_chain_hlocks()
3509 for (size = MAX_CHAIN_BUCKETS; size > req; size--) { in alloc_chain_hlocks()
3516 add_chain_block(curr + req, size - req); in alloc_chain_hlocks()
3520 return -1; in alloc_chain_hlocks()
3530 u16 chain_hlock = chain_hlocks[chain->base + i]; in lock_chain_get_class()
3545 for (i = curr->lockdep_depth - 1; i >= 0; i--) { in get_first_held_lock()
3546 hlock_curr = curr->held_locks + i; in get_first_held_lock()
3547 if (hlock_curr->irq_context != hlock->irq_context) in get_first_held_lock()
3563 printk(" hlock_id:%d -> chain_key:%016Lx", in print_chain_key_iteration()
3574 int depth = curr->lockdep_depth; in print_chain_keys_held_locks()
3577 printk("depth: %u (irq_context %u)\n", depth - i + 1, in print_chain_keys_held_locks()
3578 hlock_next->irq_context); in print_chain_keys_held_locks()
3580 hlock = curr->held_locks + i; in print_chain_keys_held_locks()
3596 printk("depth: %u\n", chain->depth); in print_chain_keys_chain()
3597 for (i = 0; i < chain->depth; i++) { in print_chain_keys_chain()
3598 hlock_id = chain_hlocks[chain->base + i]; in print_chain_keys_chain()
3614 pr_warn("----------------------------\n"); in print_collision()
3615 pr_warn("%s/%d: ", current->comm, task_pid_nr(current)); in print_collision()
3644 if (DEBUG_LOCKS_WARN_ON(chain->depth != curr->lockdep_depth - (i - 1))) { in check_no_collision()
3649 for (j = 0; j < chain->depth - 1; j++, i++) { in check_no_collision()
3650 id = hlock_id(&curr->held_locks[i]); in check_no_collision()
3652 if (DEBUG_LOCKS_WARN_ON(chain_hlocks[chain->base + j] != id)) { in check_no_collision()
3662 * Given an index that is >= -1, return the index of the next lock chain.
3663 * Return -2 if there is no next lock chain.
3668 return i < ARRAY_SIZE(lock_chains) ? i : -2; in lockdep_next_lockchain()
3705 * disabled to make this an IRQ-safe lock.. for recursion reasons in add_chain_cache()
3720 chain->chain_key = chain_key; in add_chain_cache()
3721 chain->irq_context = hlock->irq_context; in add_chain_cache()
3723 chain->depth = curr->lockdep_depth + 1 - i; in add_chain_cache()
3726 BUILD_BUG_ON((1UL << 6) <= ARRAY_SIZE(curr->held_locks)); in add_chain_cache()
3729 j = alloc_chain_hlocks(chain->depth); in add_chain_cache()
3739 chain->base = j; in add_chain_cache()
3740 for (j = 0; j < chain->depth - 1; j++, i++) { in add_chain_cache()
3741 int lock_id = hlock_id(curr->held_locks + i); in add_chain_cache()
3743 chain_hlocks[chain->base + j] = lock_id; in add_chain_cache()
3745 chain_hlocks[chain->base + j] = hlock_id(hlock); in add_chain_cache()
3746 hlist_add_head_rcu(&chain->entry, hash_head); in add_chain_cache()
3748 inc_chains(chain->irq_context); in add_chain_cache()
3763 if (READ_ONCE(chain->chain_key) == chain_key) { in lookup_chain_cache()
3773 * add it and return 1 - in this case the new dependency chain is
3793 class->key, class->name); in lookup_chain_cache_add()
3801 (unsigned long long)chain_key, class->key, class->name); in lookup_chain_cache_add()
3808 * We have to walk the chain again locked - to avoid duplicates: in lookup_chain_cache_add()
3836 if (!hlock->trylock && hlock->check && in validate_chain()
3841 * - is irq-safe, if this lock is irq-unsafe in validate_chain()
3842 * - is softirq-safe, if this lock is hardirq-unsafe in validate_chain()
3847 * - within the current held-lock stack in validate_chain()
3848 * - across our accumulated lock dependency records in validate_chain()
3894 * We are building curr_chain_key incrementally, so double-check
3904 for (i = 0; i < curr->lockdep_depth; i++) { in check_chain_key()
3905 hlock = curr->held_locks + i; in check_chain_key()
3906 if (chain_key != hlock->prev_chain_key) { in check_chain_key()
3913 curr->lockdep_depth, i, in check_chain_key()
3915 (unsigned long long)hlock->prev_chain_key); in check_chain_key()
3920 * hlock->class_idx can't go beyond MAX_LOCKDEP_KEYS, but is in check_chain_key()
3923 if (DEBUG_LOCKS_WARN_ON(!test_bit(hlock->class_idx, lock_classes_in_use))) in check_chain_key()
3926 if (prev_hlock && (prev_hlock->irq_context != in check_chain_key()
3927 hlock->irq_context)) in check_chain_key()
3932 if (chain_key != curr->curr_chain_key) { in check_chain_key()
3939 curr->lockdep_depth, i, in check_chain_key()
3941 (unsigned long long)curr->curr_chain_key); in check_chain_key()
3956 printk(" ----\n"); in print_usage_bug_scenario()
3978 pr_warn("--------------------------------\n"); in print_usage_bug()
3980 pr_warn("inconsistent {%s} -> {%s} usage.\n", in print_usage_bug()
3984 curr->comm, task_pid_nr(curr), in print_usage_bug()
3992 print_lock_trace(hlock_class(this)->usage_traces[prev_bit], 1); in print_usage_bug()
4011 if (unlikely(hlock_class(this)->usage_mask & (1 << bad_bit))) { in valid_state()
4040 pr_warn("--------------------------------------------------------\n"); in print_irq_inversion_bug()
4042 curr->comm, task_pid_nr(curr)); in print_irq_inversion_bug()
4045 pr_warn("but this lock took another, %s-unsafe lock in the past:\n", irqclass); in print_irq_inversion_bug()
4047 pr_warn("but this lock was taken by another, %s-safe lock in the past:\n", irqclass); in print_irq_inversion_bug()
4048 print_lock_name(NULL, other->class); in print_irq_inversion_bug()
4062 depth--; in print_irq_inversion_bug()
4066 middle ? middle->class : root->class, other->class); in print_irq_inversion_bug()
4069 middle ? middle->class : other->class, root->class); in print_irq_inversion_bug()
4074 root->trace = save_trace(); in print_irq_inversion_bug()
4075 if (!root->trace) in print_irq_inversion_bug()
4084 * Prove that in the forwards-direction subgraph starting at <this>
4107 if (target_entry->class->usage_mask & lock_flag(bit)) { in check_usage_forwards()
4119 * Prove that in the backwards-direction subgraph starting at <this>
4142 if (target_entry->class->usage_mask & lock_flag(bit)) { in check_usage_backwards()
4155 const struct irqtrace_events *trace = &curr->irqtrace; in print_irqtrace_events()
4157 printk("irq event stamp: %u\n", trace->irq_events); in print_irqtrace_events()
4159 trace->hardirq_enable_event, (void *)trace->hardirq_enable_ip, in print_irqtrace_events()
4160 (void *)trace->hardirq_enable_ip); in print_irqtrace_events()
4162 trace->hardirq_disable_event, (void *)trace->hardirq_disable_ip, in print_irqtrace_events()
4163 (void *)trace->hardirq_disable_ip); in print_irqtrace_events()
4165 trace->softirq_enable_event, (void *)trace->softirq_enable_ip, in print_irqtrace_events()
4166 (void *)trace->softirq_enable_ip); in print_irqtrace_events()
4168 trace->softirq_disable_event, (void *)trace->softirq_disable_ip, in print_irqtrace_events()
4169 (void *)trace->softirq_disable_ip); in print_irqtrace_events()
4213 * Validate that this particular lock does not have conflicting in mark_lock_irq()
4228 * Validate that the lock dependencies don't have conflicting usage in mark_lock_irq()
4233 * mark ENABLED has to look backwards -- to ensure no dependee in mark_lock_irq()
4240 * mark USED_IN has to look forwards -- to ensure no dependency in mark_lock_irq()
4262 for (i = 0; i < curr->lockdep_depth; i++) { in mark_held_locks()
4264 hlock = curr->held_locks + i; in mark_held_locks()
4266 if (hlock->read) in mark_held_locks()
4271 if (!hlock->check) in mark_held_locks()
4299 if (curr->softirqs_enabled) in __trace_hardirqs_on_caller()
4304 * lockdep_hardirqs_on_prepare - Prepare for enabling interrupts
4356 current->hardirq_chain_key = current->curr_chain_key; in lockdep_hardirqs_on_prepare()
4366 struct irqtrace_events *trace = &current->irqtrace; in lockdep_hardirqs_on()
4384 * - recursion check, because NMI can hit lockdep; in lockdep_hardirqs_on()
4385 * - hardware state check, because above; in lockdep_hardirqs_on()
4386 * - chain_key check, see lockdep_hardirqs_on_prepare(). in lockdep_hardirqs_on()
4416 DEBUG_LOCKS_WARN_ON(current->hardirq_chain_key != in lockdep_hardirqs_on()
4417 current->curr_chain_key); in lockdep_hardirqs_on()
4420 /* we'll do an OFF -> ON transition: */ in lockdep_hardirqs_on()
4422 trace->hardirq_enable_ip = ip; in lockdep_hardirqs_on()
4423 trace->hardirq_enable_event = ++trace->irq_events; in lockdep_hardirqs_on()
4455 struct irqtrace_events *trace = &current->irqtrace; in lockdep_hardirqs_off()
4458 * We have done an ON -> OFF transition: in lockdep_hardirqs_off()
4461 trace->hardirq_disable_ip = ip; in lockdep_hardirqs_off()
4462 trace->hardirq_disable_event = ++trace->irq_events; in lockdep_hardirqs_off()
4475 struct irqtrace_events *trace = &current->irqtrace; in lockdep_softirqs_on()
4487 if (current->softirqs_enabled) { in lockdep_softirqs_on()
4494 * We'll do an OFF -> ON transition: in lockdep_softirqs_on()
4496 current->softirqs_enabled = 1; in lockdep_softirqs_on()
4497 trace->softirq_enable_ip = ip; in lockdep_softirqs_on()
4498 trace->softirq_enable_event = ++trace->irq_events; in lockdep_softirqs_on()
4524 if (current->softirqs_enabled) { in lockdep_softirqs_off()
4525 struct irqtrace_events *trace = &current->irqtrace; in lockdep_softirqs_off()
4528 * We have done an ON -> OFF transition: in lockdep_softirqs_off()
4530 current->softirqs_enabled = 0; in lockdep_softirqs_off()
4531 trace->softirq_disable_ip = ip; in lockdep_softirqs_off()
4532 trace->softirq_disable_event = ++trace->irq_events; in lockdep_softirqs_off()
4549 * If non-trylock use in a hardirq or softirq context, then in mark_usage()
4552 if (!hlock->trylock) { in mark_usage()
4553 if (hlock->read) { in mark_usage()
4558 if (curr->softirq_context) in mark_usage()
4566 if (curr->softirq_context) in mark_usage()
4577 if (!hlock->hardirqs_off && !hlock->sync) { in mark_usage()
4578 if (hlock->read) { in mark_usage()
4582 if (curr->softirqs_enabled) in mark_usage()
4590 if (curr->softirqs_enabled) in mark_usage()
4608 LOCK_CHAIN_SOFTIRQ_CONTEXT * !!task->softirq_context; in task_irq_context()
4614 unsigned int depth = curr->lockdep_depth; in separate_irq_context()
4622 prev_hlock = curr->held_locks + depth-1; in separate_irq_context()
4628 if (prev_hlock->irq_context != hlock->irq_context) in separate_irq_context()
4635 * Mark a lock with a usage bit, and validate the state transition:
4647 if (new_bit == LOCK_USED && this->read) in mark_lock()
4656 if (likely(hlock_class(this)->usage_mask & new_mask)) in mark_lock()
4664 if (unlikely(hlock_class(this)->usage_mask & new_mask)) in mark_lock()
4667 if (!hlock_class(this)->usage_mask) in mark_lock()
4670 hlock_class(this)->usage_mask |= new_mask; in mark_lock()
4673 if (!(hlock_class(this)->usage_traces[new_bit] = save_trace())) in mark_lock()
4709 if (curr->hardirq_threaded || curr->irq_config) in task_wait_context()
4713 } else if (curr->softirq_context) { in task_wait_context()
4738 pr_warn("-----------------------------\n"); in print_lock_invalid_wait_context()
4740 pr_warn("%s/%d is trying to lock:\n", curr->comm, task_pid_nr(curr)); in print_lock_invalid_wait_context()
4746 pr_warn("context-{%d:%d}\n", curr_inner, curr_inner); in print_lock_invalid_wait_context()
4759 * This check validates we take locks in the right wait-type order; that is it
4773 u8 next_inner = hlock_class(next)->wait_type_inner; in check_wait_context()
4774 u8 next_outer = hlock_class(next)->wait_type_outer; in check_wait_context()
4778 if (!next_inner || next->trylock) in check_wait_context()
4787 for (depth = curr->lockdep_depth - 1; depth >= 0; depth--) { in check_wait_context()
4788 struct held_lock *prev = curr->held_locks + depth; in check_wait_context()
4789 if (prev->irq_context != next->irq_context) in check_wait_context()
4796 for (; depth < curr->lockdep_depth; depth++) { in check_wait_context()
4797 struct held_lock *prev = curr->held_locks + depth; in check_wait_context()
4799 u8 prev_inner = class->wait_type_inner; in check_wait_context()
4811 * Allow override for annotations -- this is typically in check_wait_context()
4815 if (unlikely(class->lock_type == LD_LOCK_WAIT_OVERRIDE)) in check_wait_context()
4854 * Initialize a lock instance's lock-class mapping info:
4863 lock->class_cache[i] = NULL; in lockdep_init_map_type()
4866 lock->cpu = raw_smp_processor_id(); in lockdep_init_map_type()
4873 lock->name = "NULL"; in lockdep_init_map_type()
4877 lock->name = name; in lockdep_init_map_type()
4879 lock->wait_type_outer = outer; in lockdep_init_map_type()
4880 lock->wait_type_inner = inner; in lockdep_init_map_type()
4881 lock->lock_type = lock_type; in lockdep_init_map_type()
4889 * Sanity check, the lock-class key must either have been allocated in lockdep_init_map_type()
4898 lock->key = key; in lockdep_init_map_type()
4925 struct lock_class *class = lock->class_cache[0]; in lockdep_set_lock_cmp_fn()
4935 WARN_ON(class->cmp_fn && class->cmp_fn != cmp_fn); in lockdep_set_lock_cmp_fn()
4936 WARN_ON(class->print_fn && class->print_fn != print_fn); in lockdep_set_lock_cmp_fn()
4938 class->cmp_fn = cmp_fn; in lockdep_set_lock_cmp_fn()
4939 class->print_fn = print_fn; in lockdep_set_lock_cmp_fn()
4961 pr_warn("----------------------------------\n"); in print_lock_nested_lock_not_held()
4963 pr_warn("%s/%d is trying to lock:\n", curr->comm, task_pid_nr(curr)); in print_lock_nested_lock_not_held()
4967 pr_warn("%s\n", hlock->nest_lock->name); in print_lock_nested_lock_not_held()
4983 * We maintain the dependency maps and validate the locking attempt:
5005 if (!prove_locking || lock->key == &__lockdep_no_validate__) in __lock_acquire()
5009 class = lock->class_cache[subclass]; in __lock_acquire()
5022 printk("\nacquire class [%px] %s", class->key, class->name); in __lock_acquire()
5023 if (class->name_version > 1) in __lock_acquire()
5024 printk(KERN_CONT "#%d", class->name_version); in __lock_acquire()
5031 * (we dont increase the depth just yet, up until the in __lock_acquire()
5034 depth = curr->lockdep_depth; in __lock_acquire()
5036 * Ran out of static storage for our per-task lock stack again have we? in __lock_acquire()
5041 class_idx = class - lock_classes; in __lock_acquire()
5045 hlock = curr->held_locks + depth - 1; in __lock_acquire()
5046 if (hlock->class_idx == class_idx && nest_lock) { in __lock_acquire()
5050 if (!hlock->references) in __lock_acquire()
5051 hlock->references++; in __lock_acquire()
5053 hlock->references += references; in __lock_acquire()
5056 if (DEBUG_LOCKS_WARN_ON(hlock->references < references)) in __lock_acquire()
5063 hlock = curr->held_locks + depth; in __lock_acquire()
5070 hlock->class_idx = class_idx; in __lock_acquire()
5071 hlock->acquire_ip = ip; in __lock_acquire()
5072 hlock->instance = lock; in __lock_acquire()
5073 hlock->nest_lock = nest_lock; in __lock_acquire()
5074 hlock->irq_context = task_irq_context(curr); in __lock_acquire()
5075 hlock->trylock = trylock; in __lock_acquire()
5076 hlock->read = read; in __lock_acquire()
5077 hlock->check = check; in __lock_acquire()
5078 hlock->sync = !!sync; in __lock_acquire()
5079 hlock->hardirqs_off = !!hardirqs_off; in __lock_acquire()
5080 hlock->references = references; in __lock_acquire()
5082 hlock->waittime_stamp = 0; in __lock_acquire()
5083 hlock->holdtime_stamp = lockstat_clock(); in __lock_acquire()
5085 hlock->pin_count = pin_count; in __lock_acquire()
5102 * the hash, not class->key. in __lock_acquire()
5110 chain_key = curr->curr_chain_key; in __lock_acquire()
5120 hlock->prev_chain_key = chain_key; in __lock_acquire()
5127 if (nest_lock && !__lock_is_held(nest_lock, -1)) { in __lock_acquire()
5133 WARN_ON_ONCE(depth && !hlock_class(hlock - 1)->key); in __lock_acquire()
5134 WARN_ON_ONCE(!hlock_class(hlock)->key); in __lock_acquire()
5141 if (hlock->sync) in __lock_acquire()
5144 curr->curr_chain_key = chain_key; in __lock_acquire()
5145 curr->lockdep_depth++; in __lock_acquire()
5151 if (unlikely(curr->lockdep_depth >= MAX_LOCK_DEPTH)) { in __lock_acquire()
5155 curr->lockdep_depth, MAX_LOCK_DEPTH); in __lock_acquire()
5164 if (unlikely(curr->lockdep_depth > max_lockdep_depth)) in __lock_acquire()
5165 max_lockdep_depth = curr->lockdep_depth; in __lock_acquire()
5183 pr_warn("-------------------------------------\n"); in print_unlock_imbalance_bug()
5185 curr->comm, task_pid_nr(curr)); in print_unlock_imbalance_bug()
5200 if (hlock->instance == lock) in match_held_lock()
5203 if (hlock->references) { in match_held_lock()
5204 const struct lock_class *class = lock->class_cache[0]; in match_held_lock()
5219 * References, but not a lock we're actually ref-counting? in match_held_lock()
5220 * State got messed up, follow the sites that change ->references in match_held_lock()
5223 if (DEBUG_LOCKS_WARN_ON(!hlock->nest_lock)) in match_held_lock()
5226 if (hlock->class_idx == class - lock_classes) in match_held_lock()
5241 i = depth - 1; in find_held_lock()
5242 hlock = curr->held_locks + i; in find_held_lock()
5248 for (i--, prev_hlock = hlock--; in find_held_lock()
5250 i--, prev_hlock = hlock--) { in find_held_lock()
5254 if (prev_hlock->irq_context != hlock->irq_context) { in find_held_lock()
5278 for (hlock = curr->held_locks + idx; idx < depth; idx++, hlock++) { in reacquire_held_locks()
5279 switch (__lock_acquire(hlock->instance, in reacquire_held_locks()
5280 hlock_class(hlock)->subclass, in reacquire_held_locks()
5281 hlock->trylock, in reacquire_held_locks()
5282 hlock->read, hlock->check, in reacquire_held_locks()
5283 hlock->hardirqs_off, in reacquire_held_locks()
5284 hlock->nest_lock, hlock->acquire_ip, in reacquire_held_locks()
5285 hlock->references, hlock->pin_count, 0)) { in reacquire_held_locks()
5315 depth = curr->lockdep_depth; in __lock_set_class()
5330 lock->wait_type_inner, in __lock_set_class()
5331 lock->wait_type_outer, in __lock_set_class()
5332 lock->lock_type); in __lock_set_class()
5334 hlock->class_idx = class - lock_classes; in __lock_set_class()
5336 curr->lockdep_depth = i; in __lock_set_class()
5337 curr->curr_chain_key = hlock->prev_chain_key; in __lock_set_class()
5346 if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth - merged)) in __lock_set_class()
5361 depth = curr->lockdep_depth; in __lock_downgrade()
5375 curr->lockdep_depth = i; in __lock_downgrade()
5376 curr->curr_chain_key = hlock->prev_chain_key; in __lock_downgrade()
5378 WARN(hlock->read, "downgrading a read lock"); in __lock_downgrade()
5379 hlock->read = 1; in __lock_downgrade()
5380 hlock->acquire_ip = ip; in __lock_downgrade()
5393 if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth)) in __lock_downgrade()
5400 * Remove the lock from the list of currently held locks - this gets
5415 depth = curr->lockdep_depth; in __lock_release()
5435 if (hlock->instance == lock) in __lock_release()
5438 WARN(hlock->pin_count, "releasing a pinned lock\n"); in __lock_release()
5440 if (hlock->references) { in __lock_release()
5441 hlock->references--; in __lock_release()
5442 if (hlock->references) { in __lock_release()
5458 curr->lockdep_depth = i; in __lock_release()
5459 curr->curr_chain_key = hlock->prev_chain_key; in __lock_release()
5465 if (i == depth-1) in __lock_release()
5473 * there's not N-1 bottles of beer left on the wall... in __lock_release()
5476 DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth - merged); in __lock_release()
5492 for (i = 0; i < curr->lockdep_depth; i++) { in __lock_is_held()
5493 struct held_lock *hlock = curr->held_locks + i; in __lock_is_held()
5496 if (read == -1 || !!hlock->read == read) in __lock_is_held()
5515 for (i = 0; i < curr->lockdep_depth; i++) { in __lock_pin_lock()
5516 struct held_lock *hlock = curr->held_locks + i; in __lock_pin_lock()
5525 hlock->pin_count += cookie.val; in __lock_pin_lock()
5542 for (i = 0; i < curr->lockdep_depth; i++) { in __lock_repin_lock()
5543 struct held_lock *hlock = curr->held_locks + i; in __lock_repin_lock()
5546 hlock->pin_count += cookie.val; in __lock_repin_lock()
5562 for (i = 0; i < curr->lockdep_depth; i++) { in __lock_unpin_lock()
5563 struct held_lock *hlock = curr->held_locks + i; in __lock_unpin_lock()
5566 if (WARN(!hlock->pin_count, "unpinning an unpinned lock\n")) in __lock_unpin_lock()
5569 hlock->pin_count -= cookie.val; in __lock_unpin_lock()
5571 if (WARN((int)hlock->pin_count < 0, "pin count corrupted\n")) in __lock_unpin_lock()
5572 hlock->pin_count = 0; in __lock_unpin_lock()
5582 * Check whether we follow the irq-flags state precisely:
5595 printk("possible reason: unannotated irqs-off.\n"); in check_flags()
5599 printk("possible reason: unannotated irqs-on.\n"); in check_flags()
5605 * We dont accurately track softirq state in e.g. in check_flags()
5612 DEBUG_LOCKS_WARN_ON(current->softirqs_enabled); in check_flags()
5615 DEBUG_LOCKS_WARN_ON(!current->softirqs_enabled); in check_flags()
5676 * READ locks, there is no deadlock possible -- RCU. in verify_lock_unused()
5678 if (!hlock->read) in verify_lock_unused()
5681 if (!(class->usage_mask & mask)) in verify_lock_unused()
5684 hlock->class_idx = class - lock_classes; in verify_lock_unused()
5716 * We are not always called with irqs disabled - do that here,
5782 * lock_sync() - A special annotation for synchronize_{s,}rcu()-like API.
5902 pr_warn("---------------------------------\n"); in print_lock_contention_bug()
5904 curr->comm, task_pid_nr(curr)); in print_lock_contention_bug()
5925 depth = curr->lockdep_depth; in __lock_contended()
5939 if (hlock->instance != lock) in __lock_contended()
5942 hlock->waittime_stamp = lockstat_clock(); in __lock_contended()
5944 contention_point = lock_point(hlock_class(hlock)->contention_point, ip); in __lock_contended()
5945 contending_point = lock_point(hlock_class(hlock)->contending_point, in __lock_contended()
5946 lock->ip); in __lock_contended()
5950 stats->contention_point[contention_point]++; in __lock_contended()
5952 stats->contending_point[contending_point]++; in __lock_contended()
5953 if (lock->cpu != smp_processor_id()) in __lock_contended()
5954 stats->bounces[bounce_contended + !!hlock->read]++; in __lock_contended()
5967 depth = curr->lockdep_depth; in __lock_acquired()
5981 if (hlock->instance != lock) in __lock_acquired()
5985 if (hlock->waittime_stamp) { in __lock_acquired()
5987 waittime = now - hlock->waittime_stamp; in __lock_acquired()
5988 hlock->holdtime_stamp = now; in __lock_acquired()
5993 if (hlock->read) in __lock_acquired()
5994 lock_time_inc(&stats->read_waittime, waittime); in __lock_acquired()
5996 lock_time_inc(&stats->write_waittime, waittime); in __lock_acquired()
5998 if (lock->cpu != cpu) in __lock_acquired()
5999 stats->bounces[bounce_acquired + !!hlock->read]++; in __lock_acquired()
6001 lock->cpu = cpu; in __lock_acquired()
6002 lock->ip = ip; in __lock_acquired()
6054 memset(current->held_locks, 0, MAX_LOCK_DEPTH*sizeof(struct held_lock)); in lockdep_reset()
6072 for (i = chain->base; i < chain->base + chain->depth; i++) { in remove_class_from_lock_chain()
6073 if (chain_hlock_class_idx(chain_hlocks[i]) != class - lock_classes) in remove_class_from_lock_chain()
6085 free_chain_hlocks(chain->base, chain->depth); in remove_class_from_lock_chain()
6087 WRITE_ONCE(chain->chain_key, INITIAL_CHAIN_KEY); in remove_class_from_lock_chain()
6088 dec_chains(chain->irq_context); in remove_class_from_lock_chain()
6094 hlist_del_rcu(&chain->entry); in remove_class_from_lock_chain()
6095 __set_bit(chain - lock_chains, pf->lock_chains_being_freed); in remove_class_from_lock_chain()
6124 WARN_ON_ONCE(!class->key); in zap_class()
6132 if (entry->class != class && entry->links_to != class) in zap_class()
6135 nr_list_entries--; in zap_class()
6136 list_del_rcu(&entry->entry); in zap_class()
6138 if (list_empty(&class->locks_after) && in zap_class()
6139 list_empty(&class->locks_before)) { in zap_class()
6140 list_move_tail(&class->lock_entry, &pf->zapped); in zap_class()
6141 hlist_del_rcu(&class->hash_entry); in zap_class()
6142 WRITE_ONCE(class->key, NULL); in zap_class()
6143 WRITE_ONCE(class->name, NULL); in zap_class()
6144 nr_lock_classes--; in zap_class()
6145 __clear_bit(class - lock_classes, lock_classes_in_use); in zap_class()
6146 if (class - lock_classes == max_lock_class_idx) in zap_class()
6147 max_lock_class_idx--; in zap_class()
6150 class->name); in zap_class()
6159 WARN_ON_ONCE(!class->lock_entry.next); in reinit_class()
6160 WARN_ON_ONCE(!list_empty(&class->locks_after)); in reinit_class()
6161 WARN_ON_ONCE(!list_empty(&class->locks_before)); in reinit_class()
6163 WARN_ON_ONCE(!class->lock_entry.next); in reinit_class()
6164 WARN_ON_ONCE(!list_empty(&class->locks_after)); in reinit_class()
6165 WARN_ON_ONCE(!list_empty(&class->locks_before)); in reinit_class()
6194 if (list_empty(&pf->zapped)) in call_rcu_zapped()
6215 list_for_each_entry(class, &pf->zapped, lock_entry) in __free_zapped_classes()
6218 list_splice_init(&pf->zapped, &free_lock_classes); in __free_zapped_classes()
6222 pf->lock_chains_being_freed, ARRAY_SIZE(lock_chains)); in __free_zapped_classes()
6223 bitmap_clear(pf->lock_chains_being_freed, 0, ARRAY_SIZE(lock_chains)); in __free_zapped_classes()
6269 if (!within(class->key, start, size) && in __lockdep_free_key_range()
6270 !within(class->name, start, size)) in __lockdep_free_key_range()
6279 * freed; and possibly re-used by other modules.
6282 * guaranteed nobody will look up these exact classes -- they're properly dead
6337 * Check whether any element of the @lock->class_cache[] array refers to a
6351 if (lock->class_cache[j] == class) in lock_class_cache_is_registered()
6460 hlist_del_rcu(&k->hash_entry); in lockdep_unregister_key()
6474 /* Wait until is_dynamic_key() has finished accessing k->hash_entry. */ in lockdep_unregister_key()
6514 printk(" per task-struct memory footprint: %zu bytes\n", in lockdep_init()
6515 sizeof(((struct task_struct *)NULL)->held_locks)); in lockdep_init()
6531 pr_warn("-------------------------\n"); in print_freed_lock_bug()
6532 pr_warn("%s/%d is freeing memory %px-%px, with a lock still held there!\n", in print_freed_lock_bug()
6533 curr->comm, task_pid_nr(curr), mem_from, mem_to-1); in print_freed_lock_bug()
6550 * is destroyed or reinitialized - this code checks whether there is
6564 for (i = 0; i < curr->lockdep_depth; i++) { in debug_check_no_locks_freed()
6565 hlock = curr->held_locks + i; in debug_check_no_locks_freed()
6567 if (not_in_range(mem_from, mem_len, hlock->instance, in debug_check_no_locks_freed()
6568 sizeof(*hlock->instance))) in debug_check_no_locks_freed()
6588 current->comm, task_pid_nr(current)); in print_held_locks_bug()
6590 pr_warn("------------------------------------\n"); in print_held_locks_bug()
6598 if (unlikely(current->lockdep_depth > 0)) in debug_check_no_locks_held()
6616 if (!p->lockdep_depth) in debug_show_all_locks()
6648 if (unlikely(curr->lockdep_depth)) { in lockdep_sys_exit()
6655 pr_warn("------------------------------------------------\n"); in lockdep_sys_exit()
6657 curr->comm, curr->pid); in lockdep_sys_exit()
6679 pr_warn("-----------------------------\n"); in lockdep_rcu_suspicious()
6690 * If a CPU is in the RCU-free window in idle (ie: in the section in lockdep_rcu_suspicious()
6696 * such an RCU-idle CPU has called rcu_read_lock(), RCU might well in lockdep_rcu_suspicious()
6698 * choice here: we need to keep an RCU-free window in idle where in lockdep_rcu_suspicious()