Lines Matching refs:object
283 struct kmemleak_object *object) in hex_dump_object() argument
285 const u8 *ptr = (const u8 *)object->pointer; in hex_dump_object()
289 len = min_t(size_t, object->size, HEX_MAX_LINES * HEX_ROW_SIZE); in hex_dump_object()
308 static bool color_white(const struct kmemleak_object *object) in color_white() argument
310 return object->count != KMEMLEAK_BLACK && in color_white()
311 object->count < object->min_count; in color_white()
314 static bool color_gray(const struct kmemleak_object *object) in color_gray() argument
316 return object->min_count != KMEMLEAK_BLACK && in color_gray()
317 object->count >= object->min_count; in color_gray()
325 static bool unreferenced_object(struct kmemleak_object *object) in unreferenced_object() argument
327 return (color_white(object) && object->flags & OBJECT_ALLOCATED) && in unreferenced_object()
328 time_before_eq(object->jiffies + jiffies_min_age, in unreferenced_object()
337 struct kmemleak_object *object) in print_unreferenced() argument
340 unsigned int msecs_age = jiffies_to_msecs(jiffies - object->jiffies); in print_unreferenced()
343 object->pointer, object->size); in print_unreferenced()
345 object->comm, object->pid, object->jiffies, in print_unreferenced()
347 hex_dump_object(seq, object); in print_unreferenced()
350 for (i = 0; i < object->trace_len; i++) { in print_unreferenced()
351 void *ptr = (void *)object->trace[i]; in print_unreferenced()
361 static void dump_object_info(struct kmemleak_object *object) in dump_object_info() argument
364 object->pointer, object->size); in dump_object_info()
366 object->comm, object->pid, object->jiffies); in dump_object_info()
367 pr_notice(" min_count = %d\n", object->min_count); in dump_object_info()
368 pr_notice(" count = %d\n", object->count); in dump_object_info()
369 pr_notice(" flags = 0x%x\n", object->flags); in dump_object_info()
370 pr_notice(" checksum = %u\n", object->checksum); in dump_object_info()
372 stack_trace_print(object->trace, object->trace_len, 4); in dump_object_info()
387 struct kmemleak_object *object; in lookup_object() local
390 object = rb_entry(rb, struct kmemleak_object, rb_node); in lookup_object()
391 untagged_objp = (unsigned long)kasan_reset_tag((void *)object->pointer); in lookup_object()
394 rb = object->rb_node.rb_left; in lookup_object()
395 else if (untagged_objp + object->size <= untagged_ptr) in lookup_object()
396 rb = object->rb_node.rb_right; in lookup_object()
398 return object; in lookup_object()
402 dump_object_info(object); in lookup_object()
415 static int get_object(struct kmemleak_object *object) in get_object() argument
417 return atomic_inc_not_zero(&object->use_count); in get_object()
426 struct kmemleak_object *object; in mem_pool_alloc() local
430 object = kmem_cache_alloc(object_cache, gfp_kmemleak_mask(gfp)); in mem_pool_alloc()
431 if (object) in mem_pool_alloc()
432 return object; in mem_pool_alloc()
437 object = list_first_entry_or_null(&mem_pool_free_list, in mem_pool_alloc()
438 typeof(*object), object_list); in mem_pool_alloc()
439 if (object) in mem_pool_alloc()
440 list_del(&object->object_list); in mem_pool_alloc()
442 object = &mem_pool[--mem_pool_free_count]; in mem_pool_alloc()
447 return object; in mem_pool_alloc()
453 static void mem_pool_free(struct kmemleak_object *object) in mem_pool_free() argument
457 if (object < mem_pool || object >= mem_pool + ARRAY_SIZE(mem_pool)) { in mem_pool_free()
458 kmem_cache_free(object_cache, object); in mem_pool_free()
464 list_add(&object->object_list, &mem_pool_free_list); in mem_pool_free()
475 struct kmemleak_object *object = in free_object_rcu() local
482 hlist_for_each_entry_safe(area, tmp, &object->area_list, node) { in free_object_rcu()
486 mem_pool_free(object); in free_object_rcu()
496 static void put_object(struct kmemleak_object *object) in put_object() argument
498 if (!atomic_dec_and_test(&object->use_count)) in put_object()
502 WARN_ON(object->flags & OBJECT_ALLOCATED); in put_object()
510 call_rcu(&object->rcu, free_object_rcu); in put_object()
512 free_object_rcu(&object->rcu); in put_object()
521 struct kmemleak_object *object; in find_and_get_object() local
525 object = lookup_object(ptr, alias); in find_and_get_object()
529 if (object && !get_object(object)) in find_and_get_object()
530 object = NULL; in find_and_get_object()
533 return object; in find_and_get_object()
540 static void __remove_object(struct kmemleak_object *object) in __remove_object() argument
542 rb_erase(&object->rb_node, &object_tree_root); in __remove_object()
543 list_del_rcu(&object->object_list); in __remove_object()
554 struct kmemleak_object *object; in find_and_remove_object() local
557 object = lookup_object(ptr, alias); in find_and_remove_object()
558 if (object) in find_and_remove_object()
559 __remove_object(object); in find_and_remove_object()
562 return object; in find_and_remove_object()
581 struct kmemleak_object *object, *parent; in create_object() local
586 object = mem_pool_alloc(gfp); in create_object()
587 if (!object) { in create_object()
593 INIT_LIST_HEAD(&object->object_list); in create_object()
594 INIT_LIST_HEAD(&object->gray_list); in create_object()
595 INIT_HLIST_HEAD(&object->area_list); in create_object()
596 raw_spin_lock_init(&object->lock); in create_object()
597 atomic_set(&object->use_count, 1); in create_object()
598 object->flags = OBJECT_ALLOCATED; in create_object()
599 object->pointer = ptr; in create_object()
600 object->size = kfence_ksize((void *)ptr) ?: size; in create_object()
601 object->excess_ref = 0; in create_object()
602 object->min_count = min_count; in create_object()
603 object->count = 0; /* white color initially */ in create_object()
604 object->jiffies = jiffies; in create_object()
605 object->checksum = 0; in create_object()
609 object->pid = 0; in create_object()
610 strncpy(object->comm, "hardirq", sizeof(object->comm)); in create_object()
612 object->pid = 0; in create_object()
613 strncpy(object->comm, "softirq", sizeof(object->comm)); in create_object()
615 object->pid = current->pid; in create_object()
622 strncpy(object->comm, current->comm, sizeof(object->comm)); in create_object()
626 object->trace_len = __save_stack_trace(object->trace); in create_object()
651 kmem_cache_free(object_cache, object); in create_object()
652 object = NULL; in create_object()
656 rb_link_node(&object->rb_node, rb_parent, link); in create_object()
657 rb_insert_color(&object->rb_node, &object_tree_root); in create_object()
659 list_add_tail_rcu(&object->object_list, &object_list); in create_object()
662 return object; in create_object()
668 static void __delete_object(struct kmemleak_object *object) in __delete_object() argument
672 WARN_ON(!(object->flags & OBJECT_ALLOCATED)); in __delete_object()
673 WARN_ON(atomic_read(&object->use_count) < 1); in __delete_object()
679 raw_spin_lock_irqsave(&object->lock, flags); in __delete_object()
680 object->flags &= ~OBJECT_ALLOCATED; in __delete_object()
681 raw_spin_unlock_irqrestore(&object->lock, flags); in __delete_object()
682 put_object(object); in __delete_object()
691 struct kmemleak_object *object; in delete_object_full() local
693 object = find_and_remove_object(ptr, 0); in delete_object_full()
694 if (!object) { in delete_object_full()
701 __delete_object(object); in delete_object_full()
711 struct kmemleak_object *object; in delete_object_part() local
714 object = find_and_remove_object(ptr, 1); in delete_object_part()
715 if (!object) { in delete_object_part()
728 start = object->pointer; in delete_object_part()
729 end = object->pointer + object->size; in delete_object_part()
731 create_object(start, ptr - start, object->min_count, in delete_object_part()
734 create_object(ptr + size, end - ptr - size, object->min_count, in delete_object_part()
737 __delete_object(object); in delete_object_part()
740 static void __paint_it(struct kmemleak_object *object, int color) in __paint_it() argument
742 object->min_count = color; in __paint_it()
744 object->flags |= OBJECT_NO_SCAN; in __paint_it()
747 static void paint_it(struct kmemleak_object *object, int color) in paint_it() argument
751 raw_spin_lock_irqsave(&object->lock, flags); in paint_it()
752 __paint_it(object, color); in paint_it()
753 raw_spin_unlock_irqrestore(&object->lock, flags); in paint_it()
758 struct kmemleak_object *object; in paint_ptr() local
760 object = find_and_get_object(ptr, 0); in paint_ptr()
761 if (!object) { in paint_ptr()
768 paint_it(object, color); in paint_ptr()
769 put_object(object); in paint_ptr()
797 struct kmemleak_object *object; in add_scan_area() local
802 object = find_and_get_object(ptr, 1); in add_scan_area()
803 if (!object) { in add_scan_area()
810 untagged_objp = (unsigned long)kasan_reset_tag((void *)object->pointer); in add_scan_area()
815 raw_spin_lock_irqsave(&object->lock, flags); in add_scan_area()
819 object->flags |= OBJECT_FULL_SCAN; in add_scan_area()
823 size = untagged_objp + object->size - untagged_ptr; in add_scan_area()
824 } else if (untagged_ptr + size > untagged_objp + object->size) { in add_scan_area()
826 dump_object_info(object); in add_scan_area()
835 hlist_add_head(&area->node, &object->area_list); in add_scan_area()
837 raw_spin_unlock_irqrestore(&object->lock, flags); in add_scan_area()
838 put_object(object); in add_scan_area()
850 struct kmemleak_object *object; in object_set_excess_ref() local
852 object = find_and_get_object(ptr, 0); in object_set_excess_ref()
853 if (!object) { in object_set_excess_ref()
859 raw_spin_lock_irqsave(&object->lock, flags); in object_set_excess_ref()
860 object->excess_ref = excess_ref; in object_set_excess_ref()
861 raw_spin_unlock_irqrestore(&object->lock, flags); in object_set_excess_ref()
862 put_object(object); in object_set_excess_ref()
873 struct kmemleak_object *object; in object_no_scan() local
875 object = find_and_get_object(ptr, 0); in object_no_scan()
876 if (!object) { in object_no_scan()
881 raw_spin_lock_irqsave(&object->lock, flags); in object_no_scan()
882 object->flags |= OBJECT_NO_SCAN; in object_no_scan()
883 raw_spin_unlock_irqrestore(&object->lock, flags); in object_no_scan()
884 put_object(object); in object_no_scan()
1026 struct kmemleak_object *object; in kmemleak_update_trace() local
1034 object = find_and_get_object((unsigned long)ptr, 1); in kmemleak_update_trace()
1035 if (!object) { in kmemleak_update_trace()
1043 raw_spin_lock_irqsave(&object->lock, flags); in kmemleak_update_trace()
1044 object->trace_len = __save_stack_trace(object->trace); in kmemleak_update_trace()
1045 raw_spin_unlock_irqrestore(&object->lock, flags); in kmemleak_update_trace()
1047 put_object(object); in kmemleak_update_trace()
1181 static bool update_checksum(struct kmemleak_object *object) in update_checksum() argument
1183 u32 old_csum = object->checksum; in update_checksum()
1187 object->checksum = crc32(0, kasan_reset_tag((void *)object->pointer), object->size); in update_checksum()
1191 return object->checksum != old_csum; in update_checksum()
1197 static void update_refs(struct kmemleak_object *object) in update_refs() argument
1199 if (!color_white(object)) { in update_refs()
1210 object->count++; in update_refs()
1211 if (color_gray(object)) { in update_refs()
1213 WARN_ON(!get_object(object)); in update_refs()
1214 list_add_tail(&object->gray_list, &gray_list); in update_refs()
1254 struct kmemleak_object *object; in scan_block() local
1275 object = lookup_object(pointer, 1); in scan_block()
1276 if (!object) in scan_block()
1278 if (object == scanned) in scan_block()
1287 raw_spin_lock_nested(&object->lock, SINGLE_DEPTH_NESTING); in scan_block()
1289 if (color_gray(object)) { in scan_block()
1290 excess_ref = object->excess_ref; in scan_block()
1294 update_refs(object); in scan_block()
1296 raw_spin_unlock(&object->lock); in scan_block()
1299 object = lookup_object(excess_ref, 0); in scan_block()
1300 if (!object) in scan_block()
1302 if (object == scanned) in scan_block()
1305 raw_spin_lock_nested(&object->lock, SINGLE_DEPTH_NESTING); in scan_block()
1306 update_refs(object); in scan_block()
1307 raw_spin_unlock(&object->lock); in scan_block()
1334 static void scan_object(struct kmemleak_object *object) in scan_object() argument
1343 raw_spin_lock_irqsave(&object->lock, flags); in scan_object()
1344 if (object->flags & OBJECT_NO_SCAN) in scan_object()
1346 if (!(object->flags & OBJECT_ALLOCATED)) in scan_object()
1349 if (hlist_empty(&object->area_list) || in scan_object()
1350 object->flags & OBJECT_FULL_SCAN) { in scan_object()
1351 void *start = (void *)object->pointer; in scan_object()
1352 void *end = (void *)(object->pointer + object->size); in scan_object()
1357 scan_block(start, next, object); in scan_object()
1363 raw_spin_unlock_irqrestore(&object->lock, flags); in scan_object()
1365 raw_spin_lock_irqsave(&object->lock, flags); in scan_object()
1366 } while (object->flags & OBJECT_ALLOCATED); in scan_object()
1368 hlist_for_each_entry(area, &object->area_list, node) in scan_object()
1371 object); in scan_object()
1373 raw_spin_unlock_irqrestore(&object->lock, flags); in scan_object()
1382 struct kmemleak_object *object, *tmp; in scan_gray_list() local
1389 object = list_entry(gray_list.next, typeof(*object), gray_list); in scan_gray_list()
1390 while (&object->gray_list != &gray_list) { in scan_gray_list()
1395 scan_object(object); in scan_gray_list()
1397 tmp = list_entry(object->gray_list.next, typeof(*object), in scan_gray_list()
1401 list_del(&object->gray_list); in scan_gray_list()
1402 put_object(object); in scan_gray_list()
1404 object = tmp; in scan_gray_list()
1417 struct kmemleak_object *object; in kmemleak_scan() local
1426 list_for_each_entry_rcu(object, &object_list, object_list) { in kmemleak_scan()
1427 raw_spin_lock_irqsave(&object->lock, flags); in kmemleak_scan()
1433 if (atomic_read(&object->use_count) > 1) { in kmemleak_scan()
1435 atomic_read(&object->use_count)); in kmemleak_scan()
1436 dump_object_info(object); in kmemleak_scan()
1440 object->count = 0; in kmemleak_scan()
1441 if (color_gray(object) && get_object(object)) in kmemleak_scan()
1442 list_add_tail(&object->gray_list, &gray_list); in kmemleak_scan()
1444 raw_spin_unlock_irqrestore(&object->lock, flags); in kmemleak_scan()
1511 list_for_each_entry_rcu(object, &object_list, object_list) { in kmemleak_scan()
1512 raw_spin_lock_irqsave(&object->lock, flags); in kmemleak_scan()
1513 if (color_white(object) && (object->flags & OBJECT_ALLOCATED) in kmemleak_scan()
1514 && update_checksum(object) && get_object(object)) { in kmemleak_scan()
1516 object->count = object->min_count; in kmemleak_scan()
1517 list_add_tail(&object->gray_list, &gray_list); in kmemleak_scan()
1519 raw_spin_unlock_irqrestore(&object->lock, flags); in kmemleak_scan()
1538 list_for_each_entry_rcu(object, &object_list, object_list) { in kmemleak_scan()
1539 raw_spin_lock_irqsave(&object->lock, flags); in kmemleak_scan()
1540 if (unreferenced_object(object) && in kmemleak_scan()
1541 !(object->flags & OBJECT_REPORTED)) { in kmemleak_scan()
1542 object->flags |= OBJECT_REPORTED; in kmemleak_scan()
1545 print_unreferenced(NULL, object); in kmemleak_scan()
1549 raw_spin_unlock_irqrestore(&object->lock, flags); in kmemleak_scan()
1633 struct kmemleak_object *object; in kmemleak_seq_start() local
1642 list_for_each_entry_rcu(object, &object_list, object_list) { in kmemleak_seq_start()
1645 if (get_object(object)) in kmemleak_seq_start()
1648 object = NULL; in kmemleak_seq_start()
1650 return object; in kmemleak_seq_start()
1698 struct kmemleak_object *object = v; in kmemleak_seq_show() local
1701 raw_spin_lock_irqsave(&object->lock, flags); in kmemleak_seq_show()
1702 if ((object->flags & OBJECT_REPORTED) && unreferenced_object(object)) in kmemleak_seq_show()
1703 print_unreferenced(seq, object); in kmemleak_seq_show()
1704 raw_spin_unlock_irqrestore(&object->lock, flags); in kmemleak_seq_show()
1723 struct kmemleak_object *object; in dump_str_object_info() local
1728 object = find_and_get_object(addr, 0); in dump_str_object_info()
1729 if (!object) { in dump_str_object_info()
1734 raw_spin_lock_irqsave(&object->lock, flags); in dump_str_object_info()
1735 dump_object_info(object); in dump_str_object_info()
1736 raw_spin_unlock_irqrestore(&object->lock, flags); in dump_str_object_info()
1738 put_object(object); in dump_str_object_info()
1750 struct kmemleak_object *object; in kmemleak_clear() local
1754 list_for_each_entry_rcu(object, &object_list, object_list) { in kmemleak_clear()
1755 raw_spin_lock_irqsave(&object->lock, flags); in kmemleak_clear()
1756 if ((object->flags & OBJECT_REPORTED) && in kmemleak_clear()
1757 unreferenced_object(object)) in kmemleak_clear()
1758 __paint_it(object, KMEMLEAK_GREY); in kmemleak_clear()
1759 raw_spin_unlock_irqrestore(&object->lock, flags); in kmemleak_clear()
1868 struct kmemleak_object *object, *tmp; in __kmemleak_do_cleanup() local
1874 list_for_each_entry_safe(object, tmp, &object_list, object_list) { in __kmemleak_do_cleanup()
1875 __remove_object(object); in __kmemleak_do_cleanup()
1876 __delete_object(object); in __kmemleak_do_cleanup()