19e4a51adSThomas Gleixner // SPDX-License-Identifier: GPL-2.0 23ac7fe5aSThomas Gleixner /* 33ac7fe5aSThomas Gleixner * Generic infrastructure for lifetime debugging of objects. 43ac7fe5aSThomas Gleixner * 53ac7fe5aSThomas Gleixner * Copyright (C) 2008, Thomas Gleixner <[email protected]> 63ac7fe5aSThomas Gleixner */ 7719e4843SFabian Frederick 8719e4843SFabian Frederick #define pr_fmt(fmt) "ODEBUG: " fmt 9719e4843SFabian Frederick 103ac7fe5aSThomas Gleixner #include <linux/debugobjects.h> 113ac7fe5aSThomas Gleixner #include <linux/interrupt.h> 12d43c36dcSAlexey Dobriyan #include <linux/sched.h> 1368db0cf1SIngo Molnar #include <linux/sched/task_stack.h> 143ac7fe5aSThomas Gleixner #include <linux/seq_file.h> 153ac7fe5aSThomas Gleixner #include <linux/debugfs.h> 165a0e3ad6STejun Heo #include <linux/slab.h> 173ac7fe5aSThomas Gleixner #include <linux/hash.h> 18caba4cbbSWaiman Long #include <linux/kmemleak.h> 1988451f2cSZqiang #include <linux/cpu.h> 203ac7fe5aSThomas Gleixner 213ac7fe5aSThomas Gleixner #define ODEBUG_HASH_BITS 14 223ac7fe5aSThomas Gleixner #define ODEBUG_HASH_SIZE (1 << ODEBUG_HASH_BITS) 233ac7fe5aSThomas Gleixner 240b6ec8c0SChristian Borntraeger #define ODEBUG_POOL_SIZE 1024 253ac7fe5aSThomas Gleixner #define ODEBUG_POOL_MIN_LEVEL 256 26d86998b1SWaiman Long #define ODEBUG_POOL_PERCPU_SIZE 64 27634d61f4SWaiman Long #define ODEBUG_BATCH_SIZE 16 283ac7fe5aSThomas Gleixner 293ac7fe5aSThomas Gleixner #define ODEBUG_CHUNK_SHIFT PAGE_SHIFT 303ac7fe5aSThomas Gleixner #define ODEBUG_CHUNK_SIZE (1 << ODEBUG_CHUNK_SHIFT) 313ac7fe5aSThomas Gleixner #define ODEBUG_CHUNK_MASK (~(ODEBUG_CHUNK_SIZE - 1)) 323ac7fe5aSThomas Gleixner 33a7344a68SWaiman Long /* 34a7344a68SWaiman Long * We limit the freeing of debug objects via workqueue at a maximum 35a7344a68SWaiman Long * frequency of 10Hz and about 1024 objects for each freeing operation. 36a7344a68SWaiman Long * So it is freeing at most 10k debug objects per second. 37a7344a68SWaiman Long */ 38a7344a68SWaiman Long #define ODEBUG_FREE_WORK_MAX 1024 39a7344a68SWaiman Long #define ODEBUG_FREE_WORK_DELAY DIV_ROUND_UP(HZ, 10) 40a7344a68SWaiman Long 413ac7fe5aSThomas Gleixner struct debug_bucket { 423ac7fe5aSThomas Gleixner struct hlist_head list; 43aef9cb05SThomas Gleixner raw_spinlock_t lock; 443ac7fe5aSThomas Gleixner }; 453ac7fe5aSThomas Gleixner 46e18328ffSThomas Gleixner struct obj_pool { 47e18328ffSThomas Gleixner struct hlist_head objects; 48e18328ffSThomas Gleixner unsigned int cnt; 49e18328ffSThomas Gleixner } ____cacheline_aligned; 50e18328ffSThomas Gleixner 51*18b8afcbSThomas Gleixner static DEFINE_PER_CPU(struct obj_pool, pool_pcpu); 52d86998b1SWaiman Long 533ac7fe5aSThomas Gleixner static struct debug_bucket obj_hash[ODEBUG_HASH_SIZE]; 543ac7fe5aSThomas Gleixner 551be1cb7bSThomas Gleixner static struct debug_obj obj_static_pool[ODEBUG_POOL_SIZE] __initdata; 563ac7fe5aSThomas Gleixner 57aef9cb05SThomas Gleixner static DEFINE_RAW_SPINLOCK(pool_lock); 583ac7fe5aSThomas Gleixner 59e18328ffSThomas Gleixner static struct obj_pool pool_global; 60e18328ffSThomas Gleixner static struct obj_pool pool_to_free; 613ac7fe5aSThomas Gleixner 62cb58d190SThomas Gleixner static HLIST_HEAD(pool_boot); 63cb58d190SThomas Gleixner 64d86998b1SWaiman Long /* 65d86998b1SWaiman Long * Because of the presence of percpu free pools, obj_pool_free will 66d86998b1SWaiman Long * under-count those in the percpu free pools. Similarly, obj_pool_used 67d86998b1SWaiman Long * will over-count those in the percpu free pools. Adjustments will be 68d86998b1SWaiman Long * made at debug_stats_show(). Both obj_pool_min_free and obj_pool_max_used 69d86998b1SWaiman Long * can be off. 70d86998b1SWaiman Long */ 71e4757c71SZhen Lei static int __data_racy obj_pool_min_free = ODEBUG_POOL_SIZE; 723ac7fe5aSThomas Gleixner static int obj_pool_used; 73e4757c71SZhen Lei static int __data_racy obj_pool_max_used; 74a7344a68SWaiman Long static bool obj_freeing; 753ac7fe5aSThomas Gleixner 765b5baba6SBreno Leitao static int __data_racy debug_objects_maxchain __read_mostly; 775b5baba6SBreno Leitao static int __data_racy __maybe_unused debug_objects_maxchecked __read_mostly; 785b5baba6SBreno Leitao static int __data_racy debug_objects_fixups __read_mostly; 795b5baba6SBreno Leitao static int __data_racy debug_objects_warnings __read_mostly; 80661cc28bSThomas Gleixner static bool __data_racy debug_objects_enabled __read_mostly 813ae70205SIngo Molnar = CONFIG_DEBUG_OBJECTS_ENABLE_DEFAULT; 82e4757c71SZhen Lei static int debug_objects_pool_size __ro_after_init 8397dd552eSWaiman Long = ODEBUG_POOL_SIZE; 84e4757c71SZhen Lei static int debug_objects_pool_min_level __ro_after_init 8597dd552eSWaiman Long = ODEBUG_POOL_MIN_LEVEL; 865b5baba6SBreno Leitao 87aedcade6SStephen Boyd static const struct debug_obj_descr *descr_test __read_mostly; 8868279f9cSAlexey Dobriyan static struct kmem_cache *obj_cache __ro_after_init; 893ac7fe5aSThomas Gleixner 90c4b73aabSWaiman Long /* 910cad93c3SWaiman Long * Track numbers of kmem_cache_alloc()/free() calls done. 92c4b73aabSWaiman Long */ 93e4757c71SZhen Lei static int __data_racy debug_objects_allocated; 94e4757c71SZhen Lei static int __data_racy debug_objects_freed; 95c4b73aabSWaiman Long 96337fff8bSThomas Gleixner static void free_obj_work(struct work_struct *work); 97a7344a68SWaiman Long static DECLARE_DELAYED_WORK(debug_obj_work, free_obj_work); 98337fff8bSThomas Gleixner 993ac7fe5aSThomas Gleixner static int __init enable_object_debug(char *str) 1003ac7fe5aSThomas Gleixner { 101661cc28bSThomas Gleixner debug_objects_enabled = true; 1023ac7fe5aSThomas Gleixner return 0; 1033ac7fe5aSThomas Gleixner } 104661cc28bSThomas Gleixner early_param("debug_objects", enable_object_debug); 1053e8ebb5cSKyle McMartin 1063e8ebb5cSKyle McMartin static int __init disable_object_debug(char *str) 1073e8ebb5cSKyle McMartin { 108661cc28bSThomas Gleixner debug_objects_enabled = false; 1093e8ebb5cSKyle McMartin return 0; 1103e8ebb5cSKyle McMartin } 1113e8ebb5cSKyle McMartin early_param("no_debug_objects", disable_object_debug); 1123ac7fe5aSThomas Gleixner 1133ac7fe5aSThomas Gleixner static const char *obj_states[ODEBUG_STATE_MAX] = { 1143ac7fe5aSThomas Gleixner [ODEBUG_STATE_NONE] = "none", 1153ac7fe5aSThomas Gleixner [ODEBUG_STATE_INIT] = "initialized", 1163ac7fe5aSThomas Gleixner [ODEBUG_STATE_INACTIVE] = "inactive", 1173ac7fe5aSThomas Gleixner [ODEBUG_STATE_ACTIVE] = "active", 1183ac7fe5aSThomas Gleixner [ODEBUG_STATE_DESTROYED] = "destroyed", 1193ac7fe5aSThomas Gleixner [ODEBUG_STATE_NOTAVAILABLE] = "not available", 1203ac7fe5aSThomas Gleixner }; 1213ac7fe5aSThomas Gleixner 122e18328ffSThomas Gleixner static __always_inline unsigned int pool_count(struct obj_pool *pool) 123e18328ffSThomas Gleixner { 124e18328ffSThomas Gleixner return READ_ONCE(pool->cnt); 125e18328ffSThomas Gleixner } 126e18328ffSThomas Gleixner 127e18328ffSThomas Gleixner static inline bool pool_global_should_refill(void) 128e18328ffSThomas Gleixner { 129e18328ffSThomas Gleixner return READ_ONCE(pool_global.cnt) < debug_objects_pool_min_level; 130e18328ffSThomas Gleixner } 131e18328ffSThomas Gleixner 132e18328ffSThomas Gleixner static inline bool pool_global_must_refill(void) 133e18328ffSThomas Gleixner { 134e18328ffSThomas Gleixner return READ_ONCE(pool_global.cnt) < (debug_objects_pool_min_level / 2); 135e18328ffSThomas Gleixner } 136e18328ffSThomas Gleixner 13749a5cb82SThomas Gleixner static void free_object_list(struct hlist_head *head) 13849a5cb82SThomas Gleixner { 13949a5cb82SThomas Gleixner struct hlist_node *tmp; 14049a5cb82SThomas Gleixner struct debug_obj *obj; 14149a5cb82SThomas Gleixner int cnt = 0; 14249a5cb82SThomas Gleixner 14349a5cb82SThomas Gleixner hlist_for_each_entry_safe(obj, tmp, head, node) { 14449a5cb82SThomas Gleixner hlist_del(&obj->node); 14549a5cb82SThomas Gleixner kmem_cache_free(obj_cache, obj); 14649a5cb82SThomas Gleixner cnt++; 14749a5cb82SThomas Gleixner } 14849a5cb82SThomas Gleixner debug_objects_freed += cnt; 14949a5cb82SThomas Gleixner } 15049a5cb82SThomas Gleixner 151d8c6cd3aSZhen Lei static void fill_pool_from_freelist(void) 1523ac7fe5aSThomas Gleixner { 153d8c6cd3aSZhen Lei static unsigned long state; 154d26bf505SWaiman Long struct debug_obj *obj; 1553ac7fe5aSThomas Gleixner 15636c4ead6SYang Shi /* 15763a4a9b5SZhen Lei * Reuse objs from the global obj_to_free list; they will be 15863a4a9b5SZhen Lei * reinitialized when allocating. 15936c4ead6SYang Shi */ 160e18328ffSThomas Gleixner if (!pool_count(&pool_to_free)) 161d8c6cd3aSZhen Lei return; 162d8c6cd3aSZhen Lei 163d8c6cd3aSZhen Lei /* 164d8c6cd3aSZhen Lei * Prevent the context from being scheduled or interrupted after 165d8c6cd3aSZhen Lei * setting the state flag; 166d8c6cd3aSZhen Lei */ 167d8c6cd3aSZhen Lei guard(irqsave)(); 168d8c6cd3aSZhen Lei 169d8c6cd3aSZhen Lei /* 170d8c6cd3aSZhen Lei * Avoid lock contention on &pool_lock and avoid making the cache 171d8c6cd3aSZhen Lei * line exclusive by testing the bit before attempting to set it. 172d8c6cd3aSZhen Lei */ 173d8c6cd3aSZhen Lei if (test_bit(0, &state) || test_and_set_bit(0, &state)) 174d8c6cd3aSZhen Lei return; 175d8c6cd3aSZhen Lei 176d8c6cd3aSZhen Lei guard(raw_spinlock)(&pool_lock); 17736c4ead6SYang Shi /* 17836c4ead6SYang Shi * Recheck with the lock held as the worker thread might have 17936c4ead6SYang Shi * won the race and freed the global free list already. 18036c4ead6SYang Shi */ 181e18328ffSThomas Gleixner while (pool_to_free.cnt && (pool_global.cnt < debug_objects_pool_min_level)) { 182e18328ffSThomas Gleixner obj = hlist_entry(pool_to_free.objects.first, typeof(*obj), node); 18336c4ead6SYang Shi hlist_del(&obj->node); 184e18328ffSThomas Gleixner WRITE_ONCE(pool_to_free.cnt, pool_to_free.cnt - 1); 185e18328ffSThomas Gleixner hlist_add_head(&obj->node, &pool_global.objects); 186e18328ffSThomas Gleixner WRITE_ONCE(pool_global.cnt, pool_global.cnt + 1); 18736c4ead6SYang Shi } 188d8c6cd3aSZhen Lei clear_bit(0, &state); 18936c4ead6SYang Shi } 19036c4ead6SYang Shi 191d8c6cd3aSZhen Lei static void fill_pool(void) 192d8c6cd3aSZhen Lei { 193d8c6cd3aSZhen Lei static atomic_t cpus_allocating; 194d8c6cd3aSZhen Lei 195d8c6cd3aSZhen Lei /* 196d8c6cd3aSZhen Lei * Avoid allocation and lock contention when: 197d8c6cd3aSZhen Lei * - One other CPU is already allocating 198d8c6cd3aSZhen Lei * - the global pool has not reached the critical level yet 199d8c6cd3aSZhen Lei */ 200e18328ffSThomas Gleixner if (!pool_global_must_refill() && atomic_read(&cpus_allocating)) 2011fda107dSThomas Gleixner return; 2023ac7fe5aSThomas Gleixner 203d8c6cd3aSZhen Lei atomic_inc(&cpus_allocating); 204e18328ffSThomas Gleixner while (pool_global_should_refill()) { 205813fd078SZhen Lei struct debug_obj *new, *last = NULL; 206813fd078SZhen Lei HLIST_HEAD(head); 207d26bf505SWaiman Long int cnt; 2083ac7fe5aSThomas Gleixner 209d26bf505SWaiman Long for (cnt = 0; cnt < ODEBUG_BATCH_SIZE; cnt++) { 210d8c6cd3aSZhen Lei new = kmem_cache_zalloc(obj_cache, __GFP_HIGH | __GFP_NOWARN); 211813fd078SZhen Lei if (!new) 212d26bf505SWaiman Long break; 213813fd078SZhen Lei hlist_add_head(&new->node, &head); 214813fd078SZhen Lei if (!last) 215813fd078SZhen Lei last = new; 216d26bf505SWaiman Long } 217d26bf505SWaiman Long if (!cnt) 218d8c6cd3aSZhen Lei break; 2193ac7fe5aSThomas Gleixner 220d8c6cd3aSZhen Lei guard(raw_spinlock_irqsave)(&pool_lock); 221e18328ffSThomas Gleixner hlist_splice_init(&head, &last->node, &pool_global.objects); 222813fd078SZhen Lei debug_objects_allocated += cnt; 223e18328ffSThomas Gleixner WRITE_ONCE(pool_global.cnt, pool_global.cnt + cnt); 2243ac7fe5aSThomas Gleixner } 225d8c6cd3aSZhen Lei atomic_dec(&cpus_allocating); 2263ac7fe5aSThomas Gleixner } 2273ac7fe5aSThomas Gleixner 2283ac7fe5aSThomas Gleixner /* 2293ac7fe5aSThomas Gleixner * Lookup an object in the hash bucket. 2303ac7fe5aSThomas Gleixner */ 2313ac7fe5aSThomas Gleixner static struct debug_obj *lookup_object(void *addr, struct debug_bucket *b) 2323ac7fe5aSThomas Gleixner { 2333ac7fe5aSThomas Gleixner struct debug_obj *obj; 2343ac7fe5aSThomas Gleixner int cnt = 0; 2353ac7fe5aSThomas Gleixner 236b67bfe0dSSasha Levin hlist_for_each_entry(obj, &b->list, node) { 2373ac7fe5aSThomas Gleixner cnt++; 2383ac7fe5aSThomas Gleixner if (obj->object == addr) 2393ac7fe5aSThomas Gleixner return obj; 2403ac7fe5aSThomas Gleixner } 2413ac7fe5aSThomas Gleixner if (cnt > debug_objects_maxchain) 2423ac7fe5aSThomas Gleixner debug_objects_maxchain = cnt; 2433ac7fe5aSThomas Gleixner 2443ac7fe5aSThomas Gleixner return NULL; 2453ac7fe5aSThomas Gleixner } 2463ac7fe5aSThomas Gleixner 2473ac7fe5aSThomas Gleixner /* 248d86998b1SWaiman Long * Allocate a new object from the hlist 249d86998b1SWaiman Long */ 250d86998b1SWaiman Long static struct debug_obj *__alloc_object(struct hlist_head *list) 251d86998b1SWaiman Long { 252d86998b1SWaiman Long struct debug_obj *obj = NULL; 253d86998b1SWaiman Long 254d86998b1SWaiman Long if (list->first) { 255d86998b1SWaiman Long obj = hlist_entry(list->first, typeof(*obj), node); 256d86998b1SWaiman Long hlist_del(&obj->node); 257d86998b1SWaiman Long } 258d86998b1SWaiman Long 259d86998b1SWaiman Long return obj; 260d86998b1SWaiman Long } 261d86998b1SWaiman Long 2623ac7fe5aSThomas Gleixner static struct debug_obj * 263aedcade6SStephen Boyd alloc_object(void *addr, struct debug_bucket *b, const struct debug_obj_descr *descr) 2643ac7fe5aSThomas Gleixner { 265*18b8afcbSThomas Gleixner struct obj_pool *percpu_pool = this_cpu_ptr(&pool_pcpu); 266d86998b1SWaiman Long struct debug_obj *obj; 267d86998b1SWaiman Long 268d86998b1SWaiman Long if (likely(obj_cache)) { 269*18b8afcbSThomas Gleixner obj = __alloc_object(&percpu_pool->objects); 270d86998b1SWaiman Long if (obj) { 271*18b8afcbSThomas Gleixner percpu_pool->cnt--; 272d86998b1SWaiman Long goto init_obj; 273d86998b1SWaiman Long } 274cb58d190SThomas Gleixner } else { 275cb58d190SThomas Gleixner obj = __alloc_object(&pool_boot); 276cb58d190SThomas Gleixner goto init_obj; 277d86998b1SWaiman Long } 2783ac7fe5aSThomas Gleixner 279aef9cb05SThomas Gleixner raw_spin_lock(&pool_lock); 280e18328ffSThomas Gleixner obj = __alloc_object(&pool_global.objects); 281d86998b1SWaiman Long if (obj) { 2823ac7fe5aSThomas Gleixner obj_pool_used++; 283e18328ffSThomas Gleixner WRITE_ONCE(pool_global.cnt, pool_global.cnt - 1); 284634d61f4SWaiman Long 285634d61f4SWaiman Long /* 286634d61f4SWaiman Long * Looking ahead, allocate one batch of debug objects and 287634d61f4SWaiman Long * put them into the percpu free pool. 288634d61f4SWaiman Long */ 289634d61f4SWaiman Long if (likely(obj_cache)) { 290634d61f4SWaiman Long int i; 291634d61f4SWaiman Long 292634d61f4SWaiman Long for (i = 0; i < ODEBUG_BATCH_SIZE; i++) { 293634d61f4SWaiman Long struct debug_obj *obj2; 294634d61f4SWaiman Long 295e18328ffSThomas Gleixner obj2 = __alloc_object(&pool_global.objects); 296634d61f4SWaiman Long if (!obj2) 297634d61f4SWaiman Long break; 298*18b8afcbSThomas Gleixner hlist_add_head(&obj2->node, &percpu_pool->objects); 299*18b8afcbSThomas Gleixner percpu_pool->cnt++; 300634d61f4SWaiman Long obj_pool_used++; 301e18328ffSThomas Gleixner WRITE_ONCE(pool_global.cnt, pool_global.cnt - 1); 302634d61f4SWaiman Long } 303634d61f4SWaiman Long } 304634d61f4SWaiman Long 3053ac7fe5aSThomas Gleixner if (obj_pool_used > obj_pool_max_used) 3063ac7fe5aSThomas Gleixner obj_pool_max_used = obj_pool_used; 3073ac7fe5aSThomas Gleixner 308e18328ffSThomas Gleixner if (pool_global.cnt < obj_pool_min_free) 309e18328ffSThomas Gleixner obj_pool_min_free = pool_global.cnt; 3103ac7fe5aSThomas Gleixner } 311aef9cb05SThomas Gleixner raw_spin_unlock(&pool_lock); 3123ac7fe5aSThomas Gleixner 313d86998b1SWaiman Long init_obj: 314d86998b1SWaiman Long if (obj) { 315d86998b1SWaiman Long obj->object = addr; 316d86998b1SWaiman Long obj->descr = descr; 317d86998b1SWaiman Long obj->state = ODEBUG_STATE_NONE; 318d86998b1SWaiman Long obj->astate = 0; 319d86998b1SWaiman Long hlist_add_head(&obj->node, &b->list); 320d86998b1SWaiman Long } 3213ac7fe5aSThomas Gleixner return obj; 3223ac7fe5aSThomas Gleixner } 3233ac7fe5aSThomas Gleixner 3243ac7fe5aSThomas Gleixner /* 325337fff8bSThomas Gleixner * workqueue function to free objects. 326858274b6SWaiman Long * 327858274b6SWaiman Long * To reduce contention on the global pool_lock, the actual freeing of 328636e1970SYang Shi * debug objects will be delayed if the pool_lock is busy. 329337fff8bSThomas Gleixner */ 330337fff8bSThomas Gleixner static void free_obj_work(struct work_struct *work) 331337fff8bSThomas Gleixner { 33236c4ead6SYang Shi struct debug_obj *obj; 333337fff8bSThomas Gleixner unsigned long flags; 33436c4ead6SYang Shi HLIST_HEAD(tofree); 335337fff8bSThomas Gleixner 336a7344a68SWaiman Long WRITE_ONCE(obj_freeing, false); 337858274b6SWaiman Long if (!raw_spin_trylock_irqsave(&pool_lock, flags)) 338858274b6SWaiman Long return; 33936c4ead6SYang Shi 340e18328ffSThomas Gleixner if (pool_global.cnt >= debug_objects_pool_size) 341a7344a68SWaiman Long goto free_objs; 342a7344a68SWaiman Long 34336c4ead6SYang Shi /* 34436c4ead6SYang Shi * The objs on the pool list might be allocated before the work is 34536c4ead6SYang Shi * run, so recheck if pool list it full or not, if not fill pool 346a7344a68SWaiman Long * list from the global free list. As it is likely that a workload 347a7344a68SWaiman Long * may be gearing up to use more and more objects, don't free any 348a7344a68SWaiman Long * of them until the next round. 34936c4ead6SYang Shi */ 350e18328ffSThomas Gleixner while (pool_to_free.cnt && pool_global.cnt < debug_objects_pool_size) { 351e18328ffSThomas Gleixner obj = hlist_entry(pool_to_free.objects.first, typeof(*obj), node); 35236c4ead6SYang Shi hlist_del(&obj->node); 353e18328ffSThomas Gleixner hlist_add_head(&obj->node, &pool_global.objects); 354e18328ffSThomas Gleixner WRITE_ONCE(pool_to_free.cnt, pool_to_free.cnt - 1); 355e18328ffSThomas Gleixner WRITE_ONCE(pool_global.cnt, pool_global.cnt + 1); 35636c4ead6SYang Shi } 357a7344a68SWaiman Long raw_spin_unlock_irqrestore(&pool_lock, flags); 358a7344a68SWaiman Long return; 35936c4ead6SYang Shi 360a7344a68SWaiman Long free_objs: 36136c4ead6SYang Shi /* 36236c4ead6SYang Shi * Pool list is already full and there are still objs on the free 36336c4ead6SYang Shi * list. Move remaining free objs to a temporary list to free the 36436c4ead6SYang Shi * memory outside the pool_lock held region. 36536c4ead6SYang Shi */ 366e18328ffSThomas Gleixner if (pool_to_free.cnt) { 367e18328ffSThomas Gleixner hlist_move_list(&pool_to_free.objects, &tofree); 368e18328ffSThomas Gleixner WRITE_ONCE(pool_to_free.cnt, 0); 36936c4ead6SYang Shi } 370aef9cb05SThomas Gleixner raw_spin_unlock_irqrestore(&pool_lock, flags); 37136c4ead6SYang Shi 37249a5cb82SThomas Gleixner free_object_list(&tofree); 373337fff8bSThomas Gleixner } 374337fff8bSThomas Gleixner 375a7344a68SWaiman Long static void __free_object(struct debug_obj *obj) 376636e1970SYang Shi { 377634d61f4SWaiman Long struct debug_obj *objs[ODEBUG_BATCH_SIZE]; 378*18b8afcbSThomas Gleixner struct obj_pool *percpu_pool; 379634d61f4SWaiman Long int lookahead_count = 0; 380636e1970SYang Shi bool work; 381636e1970SYang Shi 382cb58d190SThomas Gleixner guard(irqsave)(); 383cb58d190SThomas Gleixner 384cb58d190SThomas Gleixner if (unlikely(!obj_cache)) { 385cb58d190SThomas Gleixner hlist_add_head(&obj->node, &pool_boot); 386cb58d190SThomas Gleixner return; 387cb58d190SThomas Gleixner } 388634d61f4SWaiman Long 389d86998b1SWaiman Long /* 390d86998b1SWaiman Long * Try to free it into the percpu pool first. 391d86998b1SWaiman Long */ 392*18b8afcbSThomas Gleixner percpu_pool = this_cpu_ptr(&pool_pcpu); 393*18b8afcbSThomas Gleixner if (percpu_pool->cnt < ODEBUG_POOL_PERCPU_SIZE) { 394*18b8afcbSThomas Gleixner hlist_add_head(&obj->node, &percpu_pool->objects); 395*18b8afcbSThomas Gleixner percpu_pool->cnt++; 396a7344a68SWaiman Long return; 397d86998b1SWaiman Long } 398d86998b1SWaiman Long 399634d61f4SWaiman Long /* 400634d61f4SWaiman Long * As the percpu pool is full, look ahead and pull out a batch 401634d61f4SWaiman Long * of objects from the percpu pool and free them as well. 402634d61f4SWaiman Long */ 403634d61f4SWaiman Long for (; lookahead_count < ODEBUG_BATCH_SIZE; lookahead_count++) { 404*18b8afcbSThomas Gleixner objs[lookahead_count] = __alloc_object(&percpu_pool->objects); 405634d61f4SWaiman Long if (!objs[lookahead_count]) 406634d61f4SWaiman Long break; 407*18b8afcbSThomas Gleixner percpu_pool->cnt--; 408634d61f4SWaiman Long } 409634d61f4SWaiman Long 410d86998b1SWaiman Long raw_spin_lock(&pool_lock); 411e18328ffSThomas Gleixner work = (pool_global.cnt > debug_objects_pool_size) && obj_cache && 412e18328ffSThomas Gleixner (pool_to_free.cnt < ODEBUG_FREE_WORK_MAX); 413636e1970SYang Shi obj_pool_used--; 414636e1970SYang Shi 415636e1970SYang Shi if (work) { 416e18328ffSThomas Gleixner WRITE_ONCE(pool_to_free.cnt, pool_to_free.cnt + 1); 417e18328ffSThomas Gleixner hlist_add_head(&obj->node, &pool_to_free.objects); 418634d61f4SWaiman Long if (lookahead_count) { 419e18328ffSThomas Gleixner WRITE_ONCE(pool_to_free.cnt, pool_to_free.cnt + lookahead_count); 420634d61f4SWaiman Long obj_pool_used -= lookahead_count; 421634d61f4SWaiman Long while (lookahead_count) { 422634d61f4SWaiman Long hlist_add_head(&objs[--lookahead_count]->node, 423e18328ffSThomas Gleixner &pool_to_free.objects); 424634d61f4SWaiman Long } 425634d61f4SWaiman Long } 426a7344a68SWaiman Long 427e18328ffSThomas Gleixner if ((pool_global.cnt > debug_objects_pool_size) && 428e18328ffSThomas Gleixner (pool_to_free.cnt < ODEBUG_FREE_WORK_MAX)) { 429a7344a68SWaiman Long int i; 430a7344a68SWaiman Long 431a7344a68SWaiman Long /* 432a7344a68SWaiman Long * Free one more batch of objects from obj_pool. 433a7344a68SWaiman Long */ 434a7344a68SWaiman Long for (i = 0; i < ODEBUG_BATCH_SIZE; i++) { 435e18328ffSThomas Gleixner obj = __alloc_object(&pool_global.objects); 436e18328ffSThomas Gleixner hlist_add_head(&obj->node, &pool_to_free.objects); 437e18328ffSThomas Gleixner WRITE_ONCE(pool_global.cnt, pool_global.cnt - 1); 438e18328ffSThomas Gleixner WRITE_ONCE(pool_to_free.cnt, pool_to_free.cnt + 1); 439a7344a68SWaiman Long } 440a7344a68SWaiman Long } 441636e1970SYang Shi } else { 442e18328ffSThomas Gleixner WRITE_ONCE(pool_global.cnt, pool_global.cnt + 1); 443e18328ffSThomas Gleixner hlist_add_head(&obj->node, &pool_global.objects); 444634d61f4SWaiman Long if (lookahead_count) { 445e18328ffSThomas Gleixner WRITE_ONCE(pool_global.cnt, pool_global.cnt + lookahead_count); 446634d61f4SWaiman Long obj_pool_used -= lookahead_count; 447634d61f4SWaiman Long while (lookahead_count) { 448634d61f4SWaiman Long hlist_add_head(&objs[--lookahead_count]->node, 449e18328ffSThomas Gleixner &pool_global.objects); 450634d61f4SWaiman Long } 451634d61f4SWaiman Long } 452636e1970SYang Shi } 453d86998b1SWaiman Long raw_spin_unlock(&pool_lock); 454636e1970SYang Shi } 455636e1970SYang Shi 456337fff8bSThomas Gleixner /* 457337fff8bSThomas Gleixner * Put the object back into the pool and schedule work to free objects 458337fff8bSThomas Gleixner * if necessary. 4593ac7fe5aSThomas Gleixner */ 4603ac7fe5aSThomas Gleixner static void free_object(struct debug_obj *obj) 4613ac7fe5aSThomas Gleixner { 462a7344a68SWaiman Long __free_object(obj); 463e18328ffSThomas Gleixner if (!READ_ONCE(obj_freeing) && pool_count(&pool_to_free)) { 464a7344a68SWaiman Long WRITE_ONCE(obj_freeing, true); 465a7344a68SWaiman Long schedule_delayed_work(&debug_obj_work, ODEBUG_FREE_WORK_DELAY); 466a7344a68SWaiman Long } 4673ac7fe5aSThomas Gleixner } 4683ac7fe5aSThomas Gleixner 469a2a70238SThomas Gleixner static void put_objects(struct hlist_head *list) 47088451f2cSZqiang { 47188451f2cSZqiang struct hlist_node *tmp; 47288451f2cSZqiang struct debug_obj *obj; 47388451f2cSZqiang 474a2a70238SThomas Gleixner /* 475a2a70238SThomas Gleixner * Using free_object() puts the objects into reuse or schedules 476a2a70238SThomas Gleixner * them for freeing and it get's all the accounting correct. 477a2a70238SThomas Gleixner */ 478a2a70238SThomas Gleixner hlist_for_each_entry_safe(obj, tmp, list, node) { 47988451f2cSZqiang hlist_del(&obj->node); 480a2a70238SThomas Gleixner free_object(obj); 481a2a70238SThomas Gleixner } 48288451f2cSZqiang } 483eabb7f1aSwuchi 48449968cf1SThomas Gleixner #ifdef CONFIG_HOTPLUG_CPU 485a2a70238SThomas Gleixner static int object_cpu_offline(unsigned int cpu) 486a2a70238SThomas Gleixner { 487a2a70238SThomas Gleixner /* Remote access is safe as the CPU is dead already */ 488*18b8afcbSThomas Gleixner struct obj_pool *pcp = per_cpu_ptr(&pool_pcpu, cpu); 489eabb7f1aSwuchi 490*18b8afcbSThomas Gleixner put_objects(&pcp->objects); 491*18b8afcbSThomas Gleixner pcp->cnt = 0; 49288451f2cSZqiang return 0; 49388451f2cSZqiang } 49488451f2cSZqiang #endif 49588451f2cSZqiang 49649968cf1SThomas Gleixner /* Out of memory. Free all objects from hash */ 4973ac7fe5aSThomas Gleixner static void debug_objects_oom(void) 4983ac7fe5aSThomas Gleixner { 4993ac7fe5aSThomas Gleixner struct debug_bucket *db = obj_hash; 500673d62ccSVegard Nossum HLIST_HEAD(freelist); 5013ac7fe5aSThomas Gleixner 502719e4843SFabian Frederick pr_warn("Out of memory. ODEBUG disabled\n"); 5033ac7fe5aSThomas Gleixner 50449968cf1SThomas Gleixner for (int i = 0; i < ODEBUG_HASH_SIZE; i++, db++) { 50549968cf1SThomas Gleixner scoped_guard(raw_spinlock_irqsave, &db->lock) 506673d62ccSVegard Nossum hlist_move_list(&db->list, &freelist); 507673d62ccSVegard Nossum 50849968cf1SThomas Gleixner put_objects(&freelist); 5093ac7fe5aSThomas Gleixner } 5103ac7fe5aSThomas Gleixner } 5113ac7fe5aSThomas Gleixner 5123ac7fe5aSThomas Gleixner /* 5133ac7fe5aSThomas Gleixner * We use the pfn of the address for the hash. That way we can check 5143ac7fe5aSThomas Gleixner * for freed objects simply by checking the affected bucket. 5153ac7fe5aSThomas Gleixner */ 5163ac7fe5aSThomas Gleixner static struct debug_bucket *get_bucket(unsigned long addr) 5173ac7fe5aSThomas Gleixner { 5183ac7fe5aSThomas Gleixner unsigned long hash; 5193ac7fe5aSThomas Gleixner 5203ac7fe5aSThomas Gleixner hash = hash_long((addr >> ODEBUG_CHUNK_SHIFT), ODEBUG_HASH_BITS); 5213ac7fe5aSThomas Gleixner return &obj_hash[hash]; 5223ac7fe5aSThomas Gleixner } 5233ac7fe5aSThomas Gleixner 5243ac7fe5aSThomas Gleixner static void debug_print_object(struct debug_obj *obj, char *msg) 5253ac7fe5aSThomas Gleixner { 526aedcade6SStephen Boyd const struct debug_obj_descr *descr = obj->descr; 5273ac7fe5aSThomas Gleixner static int limit; 5283ac7fe5aSThomas Gleixner 5298b64d420STetsuo Handa /* 5308b64d420STetsuo Handa * Don't report if lookup_object_or_alloc() by the current thread 5318b64d420STetsuo Handa * failed because lookup_object_or_alloc()/debug_objects_oom() by a 5328b64d420STetsuo Handa * concurrent thread turned off debug_objects_enabled and cleared 5338b64d420STetsuo Handa * the hash buckets. 5348b64d420STetsuo Handa */ 5358b64d420STetsuo Handa if (!debug_objects_enabled) 5368b64d420STetsuo Handa return; 5378b64d420STetsuo Handa 53899777288SStanislaw Gruszka if (limit < 5 && descr != descr_test) { 53999777288SStanislaw Gruszka void *hint = descr->debug_hint ? 54099777288SStanislaw Gruszka descr->debug_hint(obj->object) : NULL; 5413ac7fe5aSThomas Gleixner limit++; 542a5d8e467SMathieu Desnoyers WARN(1, KERN_ERR "ODEBUG: %s %s (active state %u) " 543c4db2d3bSStephen Boyd "object: %p object type: %s hint: %pS\n", 544a5d8e467SMathieu Desnoyers msg, obj_states[obj->state], obj->astate, 545c4db2d3bSStephen Boyd obj->object, descr->name, hint); 5463ac7fe5aSThomas Gleixner } 5473ac7fe5aSThomas Gleixner debug_objects_warnings++; 5483ac7fe5aSThomas Gleixner } 5493ac7fe5aSThomas Gleixner 5503ac7fe5aSThomas Gleixner /* 5513ac7fe5aSThomas Gleixner * Try to repair the damage, so we have a better chance to get useful 5523ac7fe5aSThomas Gleixner * debug output. 5533ac7fe5aSThomas Gleixner */ 554b1e4d9d8SDu, Changbin static bool 555b1e4d9d8SDu, Changbin debug_object_fixup(bool (*fixup)(void *addr, enum debug_obj_state state), 5563ac7fe5aSThomas Gleixner void * addr, enum debug_obj_state state) 5573ac7fe5aSThomas Gleixner { 558b1e4d9d8SDu, Changbin if (fixup && fixup(addr, state)) { 559b1e4d9d8SDu, Changbin debug_objects_fixups++; 560b1e4d9d8SDu, Changbin return true; 561b1e4d9d8SDu, Changbin } 562b1e4d9d8SDu, Changbin return false; 5633ac7fe5aSThomas Gleixner } 5643ac7fe5aSThomas Gleixner 5653ac7fe5aSThomas Gleixner static void debug_object_is_on_stack(void *addr, int onstack) 5663ac7fe5aSThomas Gleixner { 5673ac7fe5aSThomas Gleixner int is_on_stack; 5683ac7fe5aSThomas Gleixner static int limit; 5693ac7fe5aSThomas Gleixner 5703ac7fe5aSThomas Gleixner if (limit > 4) 5713ac7fe5aSThomas Gleixner return; 5723ac7fe5aSThomas Gleixner 5738b05c7e6SFUJITA Tomonori is_on_stack = object_is_on_stack(addr); 5743ac7fe5aSThomas Gleixner if (is_on_stack == onstack) 5753ac7fe5aSThomas Gleixner return; 5763ac7fe5aSThomas Gleixner 5773ac7fe5aSThomas Gleixner limit++; 5783ac7fe5aSThomas Gleixner if (is_on_stack) 579fc91a3c4SJoel Fernandes (Google) pr_warn("object %p is on stack %p, but NOT annotated.\n", addr, 580fc91a3c4SJoel Fernandes (Google) task_stack_page(current)); 5813ac7fe5aSThomas Gleixner else 582fc91a3c4SJoel Fernandes (Google) pr_warn("object %p is NOT on stack %p, but annotated.\n", addr, 583fc91a3c4SJoel Fernandes (Google) task_stack_page(current)); 584fc91a3c4SJoel Fernandes (Google) 5853ac7fe5aSThomas Gleixner WARN_ON(1); 5863ac7fe5aSThomas Gleixner } 5873ac7fe5aSThomas Gleixner 58863a75969SThomas Gleixner static struct debug_obj *lookup_object_or_alloc(void *addr, struct debug_bucket *b, 58963a75969SThomas Gleixner const struct debug_obj_descr *descr, 59063a75969SThomas Gleixner bool onstack, bool alloc_ifstatic) 59163a75969SThomas Gleixner { 59263a75969SThomas Gleixner struct debug_obj *obj = lookup_object(addr, b); 59363a75969SThomas Gleixner enum debug_obj_state state = ODEBUG_STATE_NONE; 59463a75969SThomas Gleixner 59563a75969SThomas Gleixner if (likely(obj)) 59663a75969SThomas Gleixner return obj; 59763a75969SThomas Gleixner 59863a75969SThomas Gleixner /* 59963a75969SThomas Gleixner * debug_object_init() unconditionally allocates untracked 60063a75969SThomas Gleixner * objects. It does not matter whether it is a static object or 60163a75969SThomas Gleixner * not. 60263a75969SThomas Gleixner * 60363a75969SThomas Gleixner * debug_object_assert_init() and debug_object_activate() allow 60463a75969SThomas Gleixner * allocation only if the descriptor callback confirms that the 60563a75969SThomas Gleixner * object is static and considered initialized. For non-static 60663a75969SThomas Gleixner * objects the allocation needs to be done from the fixup callback. 60763a75969SThomas Gleixner */ 60863a75969SThomas Gleixner if (unlikely(alloc_ifstatic)) { 60963a75969SThomas Gleixner if (!descr->is_static_object || !descr->is_static_object(addr)) 61063a75969SThomas Gleixner return ERR_PTR(-ENOENT); 61163a75969SThomas Gleixner /* Statically allocated objects are considered initialized */ 61263a75969SThomas Gleixner state = ODEBUG_STATE_INIT; 61363a75969SThomas Gleixner } 61463a75969SThomas Gleixner 61563a75969SThomas Gleixner obj = alloc_object(addr, b, descr); 61663a75969SThomas Gleixner if (likely(obj)) { 61763a75969SThomas Gleixner obj->state = state; 61863a75969SThomas Gleixner debug_object_is_on_stack(addr, onstack); 61963a75969SThomas Gleixner return obj; 62063a75969SThomas Gleixner } 62163a75969SThomas Gleixner 62263a75969SThomas Gleixner /* Out of memory. Do the cleanup outside of the locked region */ 623661cc28bSThomas Gleixner debug_objects_enabled = false; 62463a75969SThomas Gleixner return NULL; 62563a75969SThomas Gleixner } 62663a75969SThomas Gleixner 6270af462f1SThomas Gleixner static void debug_objects_fill_pool(void) 6280af462f1SThomas Gleixner { 629d8c6cd3aSZhen Lei if (unlikely(!obj_cache)) 630d8c6cd3aSZhen Lei return; 631d8c6cd3aSZhen Lei 632e18328ffSThomas Gleixner if (likely(!pool_global_should_refill())) 633d8c6cd3aSZhen Lei return; 634d8c6cd3aSZhen Lei 635d8c6cd3aSZhen Lei /* Try reusing objects from obj_to_free_list */ 636d8c6cd3aSZhen Lei fill_pool_from_freelist(); 637d8c6cd3aSZhen Lei 638e18328ffSThomas Gleixner if (likely(!pool_global_should_refill())) 639d8c6cd3aSZhen Lei return; 640d8c6cd3aSZhen Lei 6410af462f1SThomas Gleixner /* 6420af462f1SThomas Gleixner * On RT enabled kernels the pool refill must happen in preemptible 6430cce06baSPeter Zijlstra * context -- for !RT kernels we rely on the fact that spinlock_t and 6440cce06baSPeter Zijlstra * raw_spinlock_t are basically the same type and this lock-type 6450cce06baSPeter Zijlstra * inversion works just fine. 6460af462f1SThomas Gleixner */ 6470cce06baSPeter Zijlstra if (!IS_ENABLED(CONFIG_PREEMPT_RT) || preemptible()) { 6480cce06baSPeter Zijlstra /* 6490cce06baSPeter Zijlstra * Annotate away the spinlock_t inside raw_spinlock_t warning 6500cce06baSPeter Zijlstra * by temporarily raising the wait-type to WAIT_SLEEP, matching 6510cce06baSPeter Zijlstra * the preemptible() condition above. 6520cce06baSPeter Zijlstra */ 6530cce06baSPeter Zijlstra static DEFINE_WAIT_OVERRIDE_MAP(fill_pool_map, LD_WAIT_SLEEP); 6540cce06baSPeter Zijlstra lock_map_acquire_try(&fill_pool_map); 6550af462f1SThomas Gleixner fill_pool(); 6560cce06baSPeter Zijlstra lock_map_release(&fill_pool_map); 6570cce06baSPeter Zijlstra } 6580af462f1SThomas Gleixner } 6590af462f1SThomas Gleixner 6603ac7fe5aSThomas Gleixner static void 661aedcade6SStephen Boyd __debug_object_init(void *addr, const struct debug_obj_descr *descr, int onstack) 6623ac7fe5aSThomas Gleixner { 6639bb63626SAndrzej Hajda struct debug_obj *obj, o; 6643ac7fe5aSThomas Gleixner struct debug_bucket *db; 6653ac7fe5aSThomas Gleixner unsigned long flags; 6663ac7fe5aSThomas Gleixner 6670af462f1SThomas Gleixner debug_objects_fill_pool(); 66850db04ddSVegard Nossum 6693ac7fe5aSThomas Gleixner db = get_bucket((unsigned long) addr); 6703ac7fe5aSThomas Gleixner 671aef9cb05SThomas Gleixner raw_spin_lock_irqsave(&db->lock, flags); 6723ac7fe5aSThomas Gleixner 67363a75969SThomas Gleixner obj = lookup_object_or_alloc(addr, db, descr, onstack, false); 67463a75969SThomas Gleixner if (unlikely(!obj)) { 675aef9cb05SThomas Gleixner raw_spin_unlock_irqrestore(&db->lock, flags); 6763ac7fe5aSThomas Gleixner debug_objects_oom(); 6773ac7fe5aSThomas Gleixner return; 6783ac7fe5aSThomas Gleixner } 6793ac7fe5aSThomas Gleixner 6803ac7fe5aSThomas Gleixner switch (obj->state) { 6813ac7fe5aSThomas Gleixner case ODEBUG_STATE_NONE: 6823ac7fe5aSThomas Gleixner case ODEBUG_STATE_INIT: 6833ac7fe5aSThomas Gleixner case ODEBUG_STATE_INACTIVE: 6843ac7fe5aSThomas Gleixner obj->state = ODEBUG_STATE_INIT; 685aef9cb05SThomas Gleixner raw_spin_unlock_irqrestore(&db->lock, flags); 686d5f34153SWaiman Long return; 6873ac7fe5aSThomas Gleixner default: 6883ac7fe5aSThomas Gleixner break; 6893ac7fe5aSThomas Gleixner } 6903ac7fe5aSThomas Gleixner 6919bb63626SAndrzej Hajda o = *obj; 692aef9cb05SThomas Gleixner raw_spin_unlock_irqrestore(&db->lock, flags); 6939bb63626SAndrzej Hajda debug_print_object(&o, "init"); 6949bb63626SAndrzej Hajda 6959bb63626SAndrzej Hajda if (o.state == ODEBUG_STATE_ACTIVE) 6969bb63626SAndrzej Hajda debug_object_fixup(descr->fixup_init, addr, o.state); 6973ac7fe5aSThomas Gleixner } 6983ac7fe5aSThomas Gleixner 6993ac7fe5aSThomas Gleixner /** 7003ac7fe5aSThomas Gleixner * debug_object_init - debug checks when an object is initialized 7013ac7fe5aSThomas Gleixner * @addr: address of the object 7023ac7fe5aSThomas Gleixner * @descr: pointer to an object specific debug description structure 7033ac7fe5aSThomas Gleixner */ 704aedcade6SStephen Boyd void debug_object_init(void *addr, const struct debug_obj_descr *descr) 7053ac7fe5aSThomas Gleixner { 7063ac7fe5aSThomas Gleixner if (!debug_objects_enabled) 7073ac7fe5aSThomas Gleixner return; 7083ac7fe5aSThomas Gleixner 7093ac7fe5aSThomas Gleixner __debug_object_init(addr, descr, 0); 7103ac7fe5aSThomas Gleixner } 711f8ff04e2SChris Wilson EXPORT_SYMBOL_GPL(debug_object_init); 7123ac7fe5aSThomas Gleixner 7133ac7fe5aSThomas Gleixner /** 7143ac7fe5aSThomas Gleixner * debug_object_init_on_stack - debug checks when an object on stack is 7153ac7fe5aSThomas Gleixner * initialized 7163ac7fe5aSThomas Gleixner * @addr: address of the object 7173ac7fe5aSThomas Gleixner * @descr: pointer to an object specific debug description structure 7183ac7fe5aSThomas Gleixner */ 719aedcade6SStephen Boyd void debug_object_init_on_stack(void *addr, const struct debug_obj_descr *descr) 7203ac7fe5aSThomas Gleixner { 7213ac7fe5aSThomas Gleixner if (!debug_objects_enabled) 7223ac7fe5aSThomas Gleixner return; 7233ac7fe5aSThomas Gleixner 7243ac7fe5aSThomas Gleixner __debug_object_init(addr, descr, 1); 7253ac7fe5aSThomas Gleixner } 726f8ff04e2SChris Wilson EXPORT_SYMBOL_GPL(debug_object_init_on_stack); 7273ac7fe5aSThomas Gleixner 7283ac7fe5aSThomas Gleixner /** 7293ac7fe5aSThomas Gleixner * debug_object_activate - debug checks when an object is activated 7303ac7fe5aSThomas Gleixner * @addr: address of the object 7313ac7fe5aSThomas Gleixner * @descr: pointer to an object specific debug description structure 732b778ae25SPaul E. McKenney * Returns 0 for success, -EINVAL for check failed. 7333ac7fe5aSThomas Gleixner */ 734aedcade6SStephen Boyd int debug_object_activate(void *addr, const struct debug_obj_descr *descr) 7353ac7fe5aSThomas Gleixner { 73663a75969SThomas Gleixner struct debug_obj o = { .object = addr, .state = ODEBUG_STATE_NOTAVAILABLE, .descr = descr }; 7373ac7fe5aSThomas Gleixner struct debug_bucket *db; 7383ac7fe5aSThomas Gleixner struct debug_obj *obj; 7393ac7fe5aSThomas Gleixner unsigned long flags; 7403ac7fe5aSThomas Gleixner 7413ac7fe5aSThomas Gleixner if (!debug_objects_enabled) 742b778ae25SPaul E. McKenney return 0; 7433ac7fe5aSThomas Gleixner 7440af462f1SThomas Gleixner debug_objects_fill_pool(); 7450af462f1SThomas Gleixner 7463ac7fe5aSThomas Gleixner db = get_bucket((unsigned long) addr); 7473ac7fe5aSThomas Gleixner 748aef9cb05SThomas Gleixner raw_spin_lock_irqsave(&db->lock, flags); 7493ac7fe5aSThomas Gleixner 75063a75969SThomas Gleixner obj = lookup_object_or_alloc(addr, db, descr, false, true); 7519bb63626SAndrzej Hajda if (unlikely(!obj)) { 7529bb63626SAndrzej Hajda raw_spin_unlock_irqrestore(&db->lock, flags); 7539bb63626SAndrzej Hajda debug_objects_oom(); 7549bb63626SAndrzej Hajda return 0; 7559bb63626SAndrzej Hajda } else if (likely(!IS_ERR(obj))) { 7563ac7fe5aSThomas Gleixner switch (obj->state) { 7579bb63626SAndrzej Hajda case ODEBUG_STATE_ACTIVE: 7589bb63626SAndrzej Hajda case ODEBUG_STATE_DESTROYED: 7599bb63626SAndrzej Hajda o = *obj; 7609bb63626SAndrzej Hajda break; 7613ac7fe5aSThomas Gleixner case ODEBUG_STATE_INIT: 7623ac7fe5aSThomas Gleixner case ODEBUG_STATE_INACTIVE: 7633ac7fe5aSThomas Gleixner obj->state = ODEBUG_STATE_ACTIVE; 7649bb63626SAndrzej Hajda fallthrough; 7653ac7fe5aSThomas Gleixner default: 766aef9cb05SThomas Gleixner raw_spin_unlock_irqrestore(&db->lock, flags); 767b778ae25SPaul E. McKenney return 0; 7683ac7fe5aSThomas Gleixner } 7699bb63626SAndrzej Hajda } 77063a75969SThomas Gleixner 7719bb63626SAndrzej Hajda raw_spin_unlock_irqrestore(&db->lock, flags); 77263a75969SThomas Gleixner debug_print_object(&o, "activate"); 7739bb63626SAndrzej Hajda 7749bb63626SAndrzej Hajda switch (o.state) { 7759bb63626SAndrzej Hajda case ODEBUG_STATE_ACTIVE: 7769bb63626SAndrzej Hajda case ODEBUG_STATE_NOTAVAILABLE: 7779bb63626SAndrzej Hajda if (debug_object_fixup(descr->fixup_activate, addr, o.state)) 7789bb63626SAndrzej Hajda return 0; 7799bb63626SAndrzej Hajda fallthrough; 7809bb63626SAndrzej Hajda default: 7819bb63626SAndrzej Hajda return -EINVAL; 7829bb63626SAndrzej Hajda } 78363a75969SThomas Gleixner } 784f8ff04e2SChris Wilson EXPORT_SYMBOL_GPL(debug_object_activate); 7853ac7fe5aSThomas Gleixner 7863ac7fe5aSThomas Gleixner /** 7873ac7fe5aSThomas Gleixner * debug_object_deactivate - debug checks when an object is deactivated 7883ac7fe5aSThomas Gleixner * @addr: address of the object 7893ac7fe5aSThomas Gleixner * @descr: pointer to an object specific debug description structure 7903ac7fe5aSThomas Gleixner */ 791aedcade6SStephen Boyd void debug_object_deactivate(void *addr, const struct debug_obj_descr *descr) 7923ac7fe5aSThomas Gleixner { 7939bb63626SAndrzej Hajda struct debug_obj o = { .object = addr, .state = ODEBUG_STATE_NOTAVAILABLE, .descr = descr }; 7943ac7fe5aSThomas Gleixner struct debug_bucket *db; 7953ac7fe5aSThomas Gleixner struct debug_obj *obj; 7963ac7fe5aSThomas Gleixner unsigned long flags; 7973ac7fe5aSThomas Gleixner 7983ac7fe5aSThomas Gleixner if (!debug_objects_enabled) 7993ac7fe5aSThomas Gleixner return; 8003ac7fe5aSThomas Gleixner 8013ac7fe5aSThomas Gleixner db = get_bucket((unsigned long) addr); 8023ac7fe5aSThomas Gleixner 803aef9cb05SThomas Gleixner raw_spin_lock_irqsave(&db->lock, flags); 8043ac7fe5aSThomas Gleixner 8053ac7fe5aSThomas Gleixner obj = lookup_object(addr, db); 8063ac7fe5aSThomas Gleixner if (obj) { 8073ac7fe5aSThomas Gleixner switch (obj->state) { 8089bb63626SAndrzej Hajda case ODEBUG_STATE_DESTROYED: 8099bb63626SAndrzej Hajda break; 8103ac7fe5aSThomas Gleixner case ODEBUG_STATE_INIT: 8113ac7fe5aSThomas Gleixner case ODEBUG_STATE_INACTIVE: 8123ac7fe5aSThomas Gleixner case ODEBUG_STATE_ACTIVE: 8139bb63626SAndrzej Hajda if (obj->astate) 8149bb63626SAndrzej Hajda break; 8153ac7fe5aSThomas Gleixner obj->state = ODEBUG_STATE_INACTIVE; 8169bb63626SAndrzej Hajda fallthrough; 8173ac7fe5aSThomas Gleixner default: 8189bb63626SAndrzej Hajda raw_spin_unlock_irqrestore(&db->lock, flags); 8199bb63626SAndrzej Hajda return; 8203ac7fe5aSThomas Gleixner } 8219bb63626SAndrzej Hajda o = *obj; 822d5f34153SWaiman Long } 823d5f34153SWaiman Long 824d5f34153SWaiman Long raw_spin_unlock_irqrestore(&db->lock, flags); 8253ac7fe5aSThomas Gleixner debug_print_object(&o, "deactivate"); 8263ac7fe5aSThomas Gleixner } 827f8ff04e2SChris Wilson EXPORT_SYMBOL_GPL(debug_object_deactivate); 8283ac7fe5aSThomas Gleixner 8293ac7fe5aSThomas Gleixner /** 8303ac7fe5aSThomas Gleixner * debug_object_destroy - debug checks when an object is destroyed 8313ac7fe5aSThomas Gleixner * @addr: address of the object 8323ac7fe5aSThomas Gleixner * @descr: pointer to an object specific debug description structure 8333ac7fe5aSThomas Gleixner */ 834aedcade6SStephen Boyd void debug_object_destroy(void *addr, const struct debug_obj_descr *descr) 8353ac7fe5aSThomas Gleixner { 8369bb63626SAndrzej Hajda struct debug_obj *obj, o; 8373ac7fe5aSThomas Gleixner struct debug_bucket *db; 8383ac7fe5aSThomas Gleixner unsigned long flags; 8393ac7fe5aSThomas Gleixner 8403ac7fe5aSThomas Gleixner if (!debug_objects_enabled) 8413ac7fe5aSThomas Gleixner return; 8423ac7fe5aSThomas Gleixner 8433ac7fe5aSThomas Gleixner db = get_bucket((unsigned long) addr); 8443ac7fe5aSThomas Gleixner 845aef9cb05SThomas Gleixner raw_spin_lock_irqsave(&db->lock, flags); 8463ac7fe5aSThomas Gleixner 8473ac7fe5aSThomas Gleixner obj = lookup_object(addr, db); 8489bb63626SAndrzej Hajda if (!obj) { 8499bb63626SAndrzej Hajda raw_spin_unlock_irqrestore(&db->lock, flags); 8509bb63626SAndrzej Hajda return; 8519bb63626SAndrzej Hajda } 8523ac7fe5aSThomas Gleixner 8533ac7fe5aSThomas Gleixner switch (obj->state) { 8549bb63626SAndrzej Hajda case ODEBUG_STATE_ACTIVE: 8559bb63626SAndrzej Hajda case ODEBUG_STATE_DESTROYED: 8569bb63626SAndrzej Hajda break; 8573ac7fe5aSThomas Gleixner case ODEBUG_STATE_NONE: 8583ac7fe5aSThomas Gleixner case ODEBUG_STATE_INIT: 8593ac7fe5aSThomas Gleixner case ODEBUG_STATE_INACTIVE: 8603ac7fe5aSThomas Gleixner obj->state = ODEBUG_STATE_DESTROYED; 8619bb63626SAndrzej Hajda fallthrough; 8623ac7fe5aSThomas Gleixner default: 863aef9cb05SThomas Gleixner raw_spin_unlock_irqrestore(&db->lock, flags); 8649bb63626SAndrzej Hajda return; 8659bb63626SAndrzej Hajda } 8669bb63626SAndrzej Hajda 8679bb63626SAndrzej Hajda o = *obj; 8689bb63626SAndrzej Hajda raw_spin_unlock_irqrestore(&db->lock, flags); 8699bb63626SAndrzej Hajda debug_print_object(&o, "destroy"); 8709bb63626SAndrzej Hajda 8719bb63626SAndrzej Hajda if (o.state == ODEBUG_STATE_ACTIVE) 8729bb63626SAndrzej Hajda debug_object_fixup(descr->fixup_destroy, addr, o.state); 8733ac7fe5aSThomas Gleixner } 874f8ff04e2SChris Wilson EXPORT_SYMBOL_GPL(debug_object_destroy); 8753ac7fe5aSThomas Gleixner 8763ac7fe5aSThomas Gleixner /** 8773ac7fe5aSThomas Gleixner * debug_object_free - debug checks when an object is freed 8783ac7fe5aSThomas Gleixner * @addr: address of the object 8793ac7fe5aSThomas Gleixner * @descr: pointer to an object specific debug description structure 8803ac7fe5aSThomas Gleixner */ 881aedcade6SStephen Boyd void debug_object_free(void *addr, const struct debug_obj_descr *descr) 8823ac7fe5aSThomas Gleixner { 8839bb63626SAndrzej Hajda struct debug_obj *obj, o; 8843ac7fe5aSThomas Gleixner struct debug_bucket *db; 8853ac7fe5aSThomas Gleixner unsigned long flags; 8863ac7fe5aSThomas Gleixner 8873ac7fe5aSThomas Gleixner if (!debug_objects_enabled) 8883ac7fe5aSThomas Gleixner return; 8893ac7fe5aSThomas Gleixner 8903ac7fe5aSThomas Gleixner db = get_bucket((unsigned long) addr); 8913ac7fe5aSThomas Gleixner 892aef9cb05SThomas Gleixner raw_spin_lock_irqsave(&db->lock, flags); 8933ac7fe5aSThomas Gleixner 8943ac7fe5aSThomas Gleixner obj = lookup_object(addr, db); 8959bb63626SAndrzej Hajda if (!obj) { 8969bb63626SAndrzej Hajda raw_spin_unlock_irqrestore(&db->lock, flags); 8979bb63626SAndrzej Hajda return; 8989bb63626SAndrzej Hajda } 8993ac7fe5aSThomas Gleixner 9003ac7fe5aSThomas Gleixner switch (obj->state) { 9013ac7fe5aSThomas Gleixner case ODEBUG_STATE_ACTIVE: 9029bb63626SAndrzej Hajda break; 9033ac7fe5aSThomas Gleixner default: 9043ac7fe5aSThomas Gleixner hlist_del(&obj->node); 905aef9cb05SThomas Gleixner raw_spin_unlock_irqrestore(&db->lock, flags); 9063ac7fe5aSThomas Gleixner free_object(obj); 907673d62ccSVegard Nossum return; 9083ac7fe5aSThomas Gleixner } 9099bb63626SAndrzej Hajda 9109bb63626SAndrzej Hajda o = *obj; 911aef9cb05SThomas Gleixner raw_spin_unlock_irqrestore(&db->lock, flags); 9129bb63626SAndrzej Hajda debug_print_object(&o, "free"); 9139bb63626SAndrzej Hajda 9149bb63626SAndrzej Hajda debug_object_fixup(descr->fixup_free, addr, o.state); 9153ac7fe5aSThomas Gleixner } 916f8ff04e2SChris Wilson EXPORT_SYMBOL_GPL(debug_object_free); 9173ac7fe5aSThomas Gleixner 918a5d8e467SMathieu Desnoyers /** 919b84d435cSChristine Chan * debug_object_assert_init - debug checks when object should be init-ed 920b84d435cSChristine Chan * @addr: address of the object 921b84d435cSChristine Chan * @descr: pointer to an object specific debug description structure 922b84d435cSChristine Chan */ 923aedcade6SStephen Boyd void debug_object_assert_init(void *addr, const struct debug_obj_descr *descr) 924b84d435cSChristine Chan { 92563a75969SThomas Gleixner struct debug_obj o = { .object = addr, .state = ODEBUG_STATE_NOTAVAILABLE, .descr = descr }; 926b84d435cSChristine Chan struct debug_bucket *db; 927b84d435cSChristine Chan struct debug_obj *obj; 928b84d435cSChristine Chan unsigned long flags; 929b84d435cSChristine Chan 930b84d435cSChristine Chan if (!debug_objects_enabled) 931b84d435cSChristine Chan return; 932b84d435cSChristine Chan 9330af462f1SThomas Gleixner debug_objects_fill_pool(); 9340af462f1SThomas Gleixner 935b84d435cSChristine Chan db = get_bucket((unsigned long) addr); 936b84d435cSChristine Chan 937b84d435cSChristine Chan raw_spin_lock_irqsave(&db->lock, flags); 93863a75969SThomas Gleixner obj = lookup_object_or_alloc(addr, db, descr, false, true); 939b84d435cSChristine Chan raw_spin_unlock_irqrestore(&db->lock, flags); 94063a75969SThomas Gleixner if (likely(!IS_ERR_OR_NULL(obj))) 94163a75969SThomas Gleixner return; 94263a75969SThomas Gleixner 94363a75969SThomas Gleixner /* If NULL the allocation has hit OOM */ 94463a75969SThomas Gleixner if (!obj) { 94563a75969SThomas Gleixner debug_objects_oom(); 946b84d435cSChristine Chan return; 947b84d435cSChristine Chan } 948b84d435cSChristine Chan 94963a75969SThomas Gleixner /* Object is neither tracked nor static. It's not initialized. */ 95063a75969SThomas Gleixner debug_print_object(&o, "assert_init"); 95163a75969SThomas Gleixner debug_object_fixup(descr->fixup_assert_init, addr, ODEBUG_STATE_NOTAVAILABLE); 952b84d435cSChristine Chan } 953f8ff04e2SChris Wilson EXPORT_SYMBOL_GPL(debug_object_assert_init); 954b84d435cSChristine Chan 955b84d435cSChristine Chan /** 956a5d8e467SMathieu Desnoyers * debug_object_active_state - debug checks object usage state machine 957a5d8e467SMathieu Desnoyers * @addr: address of the object 958a5d8e467SMathieu Desnoyers * @descr: pointer to an object specific debug description structure 959a5d8e467SMathieu Desnoyers * @expect: expected state 960a5d8e467SMathieu Desnoyers * @next: state to move to if expected state is found 961a5d8e467SMathieu Desnoyers */ 962a5d8e467SMathieu Desnoyers void 963aedcade6SStephen Boyd debug_object_active_state(void *addr, const struct debug_obj_descr *descr, 964a5d8e467SMathieu Desnoyers unsigned int expect, unsigned int next) 965a5d8e467SMathieu Desnoyers { 9669bb63626SAndrzej Hajda struct debug_obj o = { .object = addr, .state = ODEBUG_STATE_NOTAVAILABLE, .descr = descr }; 967a5d8e467SMathieu Desnoyers struct debug_bucket *db; 968a5d8e467SMathieu Desnoyers struct debug_obj *obj; 969a5d8e467SMathieu Desnoyers unsigned long flags; 970a5d8e467SMathieu Desnoyers 971a5d8e467SMathieu Desnoyers if (!debug_objects_enabled) 972a5d8e467SMathieu Desnoyers return; 973a5d8e467SMathieu Desnoyers 974a5d8e467SMathieu Desnoyers db = get_bucket((unsigned long) addr); 975a5d8e467SMathieu Desnoyers 976a5d8e467SMathieu Desnoyers raw_spin_lock_irqsave(&db->lock, flags); 977a5d8e467SMathieu Desnoyers 978a5d8e467SMathieu Desnoyers obj = lookup_object(addr, db); 979a5d8e467SMathieu Desnoyers if (obj) { 980a5d8e467SMathieu Desnoyers switch (obj->state) { 981a5d8e467SMathieu Desnoyers case ODEBUG_STATE_ACTIVE: 9829bb63626SAndrzej Hajda if (obj->astate != expect) 983a5d8e467SMathieu Desnoyers break; 9849bb63626SAndrzej Hajda obj->astate = next; 9859bb63626SAndrzej Hajda raw_spin_unlock_irqrestore(&db->lock, flags); 9869bb63626SAndrzej Hajda return; 987a5d8e467SMathieu Desnoyers default: 988a5d8e467SMathieu Desnoyers break; 989a5d8e467SMathieu Desnoyers } 9909bb63626SAndrzej Hajda o = *obj; 991d5f34153SWaiman Long } 992d5f34153SWaiman Long 993d5f34153SWaiman Long raw_spin_unlock_irqrestore(&db->lock, flags); 994a5d8e467SMathieu Desnoyers debug_print_object(&o, "active_state"); 995a5d8e467SMathieu Desnoyers } 996f8ff04e2SChris Wilson EXPORT_SYMBOL_GPL(debug_object_active_state); 997a5d8e467SMathieu Desnoyers 9983ac7fe5aSThomas Gleixner #ifdef CONFIG_DEBUG_OBJECTS_FREE 9993ac7fe5aSThomas Gleixner static void __debug_check_no_obj_freed(const void *address, unsigned long size) 10003ac7fe5aSThomas Gleixner { 10013ac7fe5aSThomas Gleixner unsigned long flags, oaddr, saddr, eaddr, paddr, chunks; 10029bb63626SAndrzej Hajda int cnt, objs_checked = 0; 10039bb63626SAndrzej Hajda struct debug_obj *obj, o; 10043ac7fe5aSThomas Gleixner struct debug_bucket *db; 10051ea9b98bSYang Shi struct hlist_node *tmp; 10063ac7fe5aSThomas Gleixner 10073ac7fe5aSThomas Gleixner saddr = (unsigned long) address; 10083ac7fe5aSThomas Gleixner eaddr = saddr + size; 10093ac7fe5aSThomas Gleixner paddr = saddr & ODEBUG_CHUNK_MASK; 10103ac7fe5aSThomas Gleixner chunks = ((eaddr - paddr) + (ODEBUG_CHUNK_SIZE - 1)); 10113ac7fe5aSThomas Gleixner chunks >>= ODEBUG_CHUNK_SHIFT; 10123ac7fe5aSThomas Gleixner 10133ac7fe5aSThomas Gleixner for (;chunks > 0; chunks--, paddr += ODEBUG_CHUNK_SIZE) { 10143ac7fe5aSThomas Gleixner db = get_bucket(paddr); 10153ac7fe5aSThomas Gleixner 10163ac7fe5aSThomas Gleixner repeat: 10173ac7fe5aSThomas Gleixner cnt = 0; 1018aef9cb05SThomas Gleixner raw_spin_lock_irqsave(&db->lock, flags); 1019b67bfe0dSSasha Levin hlist_for_each_entry_safe(obj, tmp, &db->list, node) { 10203ac7fe5aSThomas Gleixner cnt++; 10213ac7fe5aSThomas Gleixner oaddr = (unsigned long) obj->object; 10223ac7fe5aSThomas Gleixner if (oaddr < saddr || oaddr >= eaddr) 10233ac7fe5aSThomas Gleixner continue; 10243ac7fe5aSThomas Gleixner 10253ac7fe5aSThomas Gleixner switch (obj->state) { 10263ac7fe5aSThomas Gleixner case ODEBUG_STATE_ACTIVE: 10279bb63626SAndrzej Hajda o = *obj; 1028aef9cb05SThomas Gleixner raw_spin_unlock_irqrestore(&db->lock, flags); 10299bb63626SAndrzej Hajda debug_print_object(&o, "free"); 10309bb63626SAndrzej Hajda debug_object_fixup(o.descr->fixup_free, (void *)oaddr, o.state); 10313ac7fe5aSThomas Gleixner goto repeat; 10323ac7fe5aSThomas Gleixner default: 10333ac7fe5aSThomas Gleixner hlist_del(&obj->node); 1034a7344a68SWaiman Long __free_object(obj); 10353ac7fe5aSThomas Gleixner break; 10363ac7fe5aSThomas Gleixner } 10373ac7fe5aSThomas Gleixner } 1038aef9cb05SThomas Gleixner raw_spin_unlock_irqrestore(&db->lock, flags); 1039673d62ccSVegard Nossum 10403ac7fe5aSThomas Gleixner if (cnt > debug_objects_maxchain) 10413ac7fe5aSThomas Gleixner debug_objects_maxchain = cnt; 1042bd9dcd04SYang Shi 1043bd9dcd04SYang Shi objs_checked += cnt; 10443ac7fe5aSThomas Gleixner } 1045bd9dcd04SYang Shi 1046bd9dcd04SYang Shi if (objs_checked > debug_objects_maxchecked) 1047bd9dcd04SYang Shi debug_objects_maxchecked = objs_checked; 10481ea9b98bSYang Shi 10491ea9b98bSYang Shi /* Schedule work to actually kmem_cache_free() objects */ 1050e18328ffSThomas Gleixner if (!READ_ONCE(obj_freeing) && pool_count(&pool_to_free)) { 1051a7344a68SWaiman Long WRITE_ONCE(obj_freeing, true); 1052a7344a68SWaiman Long schedule_delayed_work(&debug_obj_work, ODEBUG_FREE_WORK_DELAY); 1053a7344a68SWaiman Long } 10543ac7fe5aSThomas Gleixner } 10553ac7fe5aSThomas Gleixner 10563ac7fe5aSThomas Gleixner void debug_check_no_obj_freed(const void *address, unsigned long size) 10573ac7fe5aSThomas Gleixner { 10583ac7fe5aSThomas Gleixner if (debug_objects_enabled) 10593ac7fe5aSThomas Gleixner __debug_check_no_obj_freed(address, size); 10603ac7fe5aSThomas Gleixner } 10613ac7fe5aSThomas Gleixner #endif 10623ac7fe5aSThomas Gleixner 10633ac7fe5aSThomas Gleixner #ifdef CONFIG_DEBUG_FS 10643ac7fe5aSThomas Gleixner 10653ac7fe5aSThomas Gleixner static int debug_stats_show(struct seq_file *m, void *v) 10663ac7fe5aSThomas Gleixner { 1067d86998b1SWaiman Long int cpu, obj_percpu_free = 0; 1068d86998b1SWaiman Long 1069d86998b1SWaiman Long for_each_possible_cpu(cpu) 1070*18b8afcbSThomas Gleixner obj_percpu_free += per_cpu(pool_pcpu.cnt, cpu); 1071d86998b1SWaiman Long 10723ac7fe5aSThomas Gleixner seq_printf(m, "max_chain :%d\n", debug_objects_maxchain); 1073bd9dcd04SYang Shi seq_printf(m, "max_checked :%d\n", debug_objects_maxchecked); 10743ac7fe5aSThomas Gleixner seq_printf(m, "warnings :%d\n", debug_objects_warnings); 10753ac7fe5aSThomas Gleixner seq_printf(m, "fixups :%d\n", debug_objects_fixups); 1076e18328ffSThomas Gleixner seq_printf(m, "pool_free :%d\n", pool_count(&pool_global) + obj_percpu_free); 1077d86998b1SWaiman Long seq_printf(m, "pool_pcp_free :%d\n", obj_percpu_free); 10783ac7fe5aSThomas Gleixner seq_printf(m, "pool_min_free :%d\n", obj_pool_min_free); 1079d86998b1SWaiman Long seq_printf(m, "pool_used :%d\n", obj_pool_used - obj_percpu_free); 10803ac7fe5aSThomas Gleixner seq_printf(m, "pool_max_used :%d\n", obj_pool_max_used); 1081e18328ffSThomas Gleixner seq_printf(m, "on_free_list :%d\n", pool_count(&pool_to_free)); 10820cad93c3SWaiman Long seq_printf(m, "objs_allocated:%d\n", debug_objects_allocated); 10830cad93c3SWaiman Long seq_printf(m, "objs_freed :%d\n", debug_objects_freed); 10843ac7fe5aSThomas Gleixner return 0; 10853ac7fe5aSThomas Gleixner } 10860f85c480SQinglang Miao DEFINE_SHOW_ATTRIBUTE(debug_stats); 10873ac7fe5aSThomas Gleixner 10883ac7fe5aSThomas Gleixner static int __init debug_objects_init_debugfs(void) 10893ac7fe5aSThomas Gleixner { 1090fecb0d95SGreg Kroah-Hartman struct dentry *dbgdir; 10913ac7fe5aSThomas Gleixner 10923ac7fe5aSThomas Gleixner if (!debug_objects_enabled) 10933ac7fe5aSThomas Gleixner return 0; 10943ac7fe5aSThomas Gleixner 10953ac7fe5aSThomas Gleixner dbgdir = debugfs_create_dir("debug_objects", NULL); 10963ac7fe5aSThomas Gleixner 1097fecb0d95SGreg Kroah-Hartman debugfs_create_file("stats", 0444, dbgdir, NULL, &debug_stats_fops); 10983ac7fe5aSThomas Gleixner 10993ac7fe5aSThomas Gleixner return 0; 11003ac7fe5aSThomas Gleixner } 11013ac7fe5aSThomas Gleixner __initcall(debug_objects_init_debugfs); 11023ac7fe5aSThomas Gleixner 11033ac7fe5aSThomas Gleixner #else 11043ac7fe5aSThomas Gleixner static inline void debug_objects_init_debugfs(void) { } 11053ac7fe5aSThomas Gleixner #endif 11063ac7fe5aSThomas Gleixner 11073ac7fe5aSThomas Gleixner #ifdef CONFIG_DEBUG_OBJECTS_SELFTEST 11083ac7fe5aSThomas Gleixner 11093ac7fe5aSThomas Gleixner /* Random data structure for the self test */ 11103ac7fe5aSThomas Gleixner struct self_test { 11113ac7fe5aSThomas Gleixner unsigned long dummy1[6]; 11123ac7fe5aSThomas Gleixner int static_init; 11133ac7fe5aSThomas Gleixner unsigned long dummy2[3]; 11143ac7fe5aSThomas Gleixner }; 11153ac7fe5aSThomas Gleixner 1116aedcade6SStephen Boyd static __initconst const struct debug_obj_descr descr_type_test; 11173ac7fe5aSThomas Gleixner 1118b9fdac7fSDu, Changbin static bool __init is_static_object(void *addr) 1119b9fdac7fSDu, Changbin { 1120b9fdac7fSDu, Changbin struct self_test *obj = addr; 1121b9fdac7fSDu, Changbin 1122b9fdac7fSDu, Changbin return obj->static_init; 1123b9fdac7fSDu, Changbin } 1124b9fdac7fSDu, Changbin 11253ac7fe5aSThomas Gleixner /* 11263ac7fe5aSThomas Gleixner * fixup_init is called when: 11273ac7fe5aSThomas Gleixner * - an active object is initialized 11283ac7fe5aSThomas Gleixner */ 1129b1e4d9d8SDu, Changbin static bool __init fixup_init(void *addr, enum debug_obj_state state) 11303ac7fe5aSThomas Gleixner { 11313ac7fe5aSThomas Gleixner struct self_test *obj = addr; 11323ac7fe5aSThomas Gleixner 11333ac7fe5aSThomas Gleixner switch (state) { 11343ac7fe5aSThomas Gleixner case ODEBUG_STATE_ACTIVE: 11353ac7fe5aSThomas Gleixner debug_object_deactivate(obj, &descr_type_test); 11363ac7fe5aSThomas Gleixner debug_object_init(obj, &descr_type_test); 1137b1e4d9d8SDu, Changbin return true; 11383ac7fe5aSThomas Gleixner default: 1139b1e4d9d8SDu, Changbin return false; 11403ac7fe5aSThomas Gleixner } 11413ac7fe5aSThomas Gleixner } 11423ac7fe5aSThomas Gleixner 11433ac7fe5aSThomas Gleixner /* 11443ac7fe5aSThomas Gleixner * fixup_activate is called when: 11453ac7fe5aSThomas Gleixner * - an active object is activated 1146b9fdac7fSDu, Changbin * - an unknown non-static object is activated 11473ac7fe5aSThomas Gleixner */ 1148b1e4d9d8SDu, Changbin static bool __init fixup_activate(void *addr, enum debug_obj_state state) 11493ac7fe5aSThomas Gleixner { 11503ac7fe5aSThomas Gleixner struct self_test *obj = addr; 11513ac7fe5aSThomas Gleixner 11523ac7fe5aSThomas Gleixner switch (state) { 11533ac7fe5aSThomas Gleixner case ODEBUG_STATE_NOTAVAILABLE: 1154b1e4d9d8SDu, Changbin return true; 11553ac7fe5aSThomas Gleixner case ODEBUG_STATE_ACTIVE: 11563ac7fe5aSThomas Gleixner debug_object_deactivate(obj, &descr_type_test); 11573ac7fe5aSThomas Gleixner debug_object_activate(obj, &descr_type_test); 1158b1e4d9d8SDu, Changbin return true; 11593ac7fe5aSThomas Gleixner 11603ac7fe5aSThomas Gleixner default: 1161b1e4d9d8SDu, Changbin return false; 11623ac7fe5aSThomas Gleixner } 11633ac7fe5aSThomas Gleixner } 11643ac7fe5aSThomas Gleixner 11653ac7fe5aSThomas Gleixner /* 11663ac7fe5aSThomas Gleixner * fixup_destroy is called when: 11673ac7fe5aSThomas Gleixner * - an active object is destroyed 11683ac7fe5aSThomas Gleixner */ 1169b1e4d9d8SDu, Changbin static bool __init fixup_destroy(void *addr, enum debug_obj_state state) 11703ac7fe5aSThomas Gleixner { 11713ac7fe5aSThomas Gleixner struct self_test *obj = addr; 11723ac7fe5aSThomas Gleixner 11733ac7fe5aSThomas Gleixner switch (state) { 11743ac7fe5aSThomas Gleixner case ODEBUG_STATE_ACTIVE: 11753ac7fe5aSThomas Gleixner debug_object_deactivate(obj, &descr_type_test); 11763ac7fe5aSThomas Gleixner debug_object_destroy(obj, &descr_type_test); 1177b1e4d9d8SDu, Changbin return true; 11783ac7fe5aSThomas Gleixner default: 1179b1e4d9d8SDu, Changbin return false; 11803ac7fe5aSThomas Gleixner } 11813ac7fe5aSThomas Gleixner } 11823ac7fe5aSThomas Gleixner 11833ac7fe5aSThomas Gleixner /* 11843ac7fe5aSThomas Gleixner * fixup_free is called when: 11853ac7fe5aSThomas Gleixner * - an active object is freed 11863ac7fe5aSThomas Gleixner */ 1187b1e4d9d8SDu, Changbin static bool __init fixup_free(void *addr, enum debug_obj_state state) 11883ac7fe5aSThomas Gleixner { 11893ac7fe5aSThomas Gleixner struct self_test *obj = addr; 11903ac7fe5aSThomas Gleixner 11913ac7fe5aSThomas Gleixner switch (state) { 11923ac7fe5aSThomas Gleixner case ODEBUG_STATE_ACTIVE: 11933ac7fe5aSThomas Gleixner debug_object_deactivate(obj, &descr_type_test); 11943ac7fe5aSThomas Gleixner debug_object_free(obj, &descr_type_test); 1195b1e4d9d8SDu, Changbin return true; 11963ac7fe5aSThomas Gleixner default: 1197b1e4d9d8SDu, Changbin return false; 11983ac7fe5aSThomas Gleixner } 11993ac7fe5aSThomas Gleixner } 12003ac7fe5aSThomas Gleixner 12011fb2f77cSHenrik Kretzschmar static int __init 12023ac7fe5aSThomas Gleixner check_results(void *addr, enum debug_obj_state state, int fixups, int warnings) 12033ac7fe5aSThomas Gleixner { 12043ac7fe5aSThomas Gleixner struct debug_bucket *db; 12053ac7fe5aSThomas Gleixner struct debug_obj *obj; 12063ac7fe5aSThomas Gleixner unsigned long flags; 12073ac7fe5aSThomas Gleixner int res = -EINVAL; 12083ac7fe5aSThomas Gleixner 12093ac7fe5aSThomas Gleixner db = get_bucket((unsigned long) addr); 12103ac7fe5aSThomas Gleixner 1211aef9cb05SThomas Gleixner raw_spin_lock_irqsave(&db->lock, flags); 12123ac7fe5aSThomas Gleixner 12133ac7fe5aSThomas Gleixner obj = lookup_object(addr, db); 12143ac7fe5aSThomas Gleixner if (!obj && state != ODEBUG_STATE_NONE) { 12155cd2b459SArjan van de Ven WARN(1, KERN_ERR "ODEBUG: selftest object not found\n"); 12163ac7fe5aSThomas Gleixner goto out; 12173ac7fe5aSThomas Gleixner } 12183ac7fe5aSThomas Gleixner if (obj && obj->state != state) { 12195cd2b459SArjan van de Ven WARN(1, KERN_ERR "ODEBUG: selftest wrong state: %d != %d\n", 12203ac7fe5aSThomas Gleixner obj->state, state); 12213ac7fe5aSThomas Gleixner goto out; 12223ac7fe5aSThomas Gleixner } 12233ac7fe5aSThomas Gleixner if (fixups != debug_objects_fixups) { 12245cd2b459SArjan van de Ven WARN(1, KERN_ERR "ODEBUG: selftest fixups failed %d != %d\n", 12253ac7fe5aSThomas Gleixner fixups, debug_objects_fixups); 12263ac7fe5aSThomas Gleixner goto out; 12273ac7fe5aSThomas Gleixner } 12283ac7fe5aSThomas Gleixner if (warnings != debug_objects_warnings) { 12295cd2b459SArjan van de Ven WARN(1, KERN_ERR "ODEBUG: selftest warnings failed %d != %d\n", 12303ac7fe5aSThomas Gleixner warnings, debug_objects_warnings); 12313ac7fe5aSThomas Gleixner goto out; 12323ac7fe5aSThomas Gleixner } 12333ac7fe5aSThomas Gleixner res = 0; 12343ac7fe5aSThomas Gleixner out: 1235aef9cb05SThomas Gleixner raw_spin_unlock_irqrestore(&db->lock, flags); 12363ac7fe5aSThomas Gleixner if (res) 1237661cc28bSThomas Gleixner debug_objects_enabled = false; 12383ac7fe5aSThomas Gleixner return res; 12393ac7fe5aSThomas Gleixner } 12403ac7fe5aSThomas Gleixner 1241aedcade6SStephen Boyd static __initconst const struct debug_obj_descr descr_type_test = { 12423ac7fe5aSThomas Gleixner .name = "selftest", 1243b9fdac7fSDu, Changbin .is_static_object = is_static_object, 12443ac7fe5aSThomas Gleixner .fixup_init = fixup_init, 12453ac7fe5aSThomas Gleixner .fixup_activate = fixup_activate, 12463ac7fe5aSThomas Gleixner .fixup_destroy = fixup_destroy, 12473ac7fe5aSThomas Gleixner .fixup_free = fixup_free, 12483ac7fe5aSThomas Gleixner }; 12493ac7fe5aSThomas Gleixner 12503ac7fe5aSThomas Gleixner static __initdata struct self_test obj = { .static_init = 0 }; 12513ac7fe5aSThomas Gleixner 125255fb412eSThomas Gleixner static bool __init debug_objects_selftest(void) 12533ac7fe5aSThomas Gleixner { 12543ac7fe5aSThomas Gleixner int fixups, oldfixups, warnings, oldwarnings; 12553ac7fe5aSThomas Gleixner unsigned long flags; 12563ac7fe5aSThomas Gleixner 12573ac7fe5aSThomas Gleixner local_irq_save(flags); 12583ac7fe5aSThomas Gleixner 12593ac7fe5aSThomas Gleixner fixups = oldfixups = debug_objects_fixups; 12603ac7fe5aSThomas Gleixner warnings = oldwarnings = debug_objects_warnings; 12613ac7fe5aSThomas Gleixner descr_test = &descr_type_test; 12623ac7fe5aSThomas Gleixner 12633ac7fe5aSThomas Gleixner debug_object_init(&obj, &descr_type_test); 12643ac7fe5aSThomas Gleixner if (check_results(&obj, ODEBUG_STATE_INIT, fixups, warnings)) 12653ac7fe5aSThomas Gleixner goto out; 12663ac7fe5aSThomas Gleixner debug_object_activate(&obj, &descr_type_test); 12673ac7fe5aSThomas Gleixner if (check_results(&obj, ODEBUG_STATE_ACTIVE, fixups, warnings)) 12683ac7fe5aSThomas Gleixner goto out; 12693ac7fe5aSThomas Gleixner debug_object_activate(&obj, &descr_type_test); 12703ac7fe5aSThomas Gleixner if (check_results(&obj, ODEBUG_STATE_ACTIVE, ++fixups, ++warnings)) 12713ac7fe5aSThomas Gleixner goto out; 12723ac7fe5aSThomas Gleixner debug_object_deactivate(&obj, &descr_type_test); 12733ac7fe5aSThomas Gleixner if (check_results(&obj, ODEBUG_STATE_INACTIVE, fixups, warnings)) 12743ac7fe5aSThomas Gleixner goto out; 12753ac7fe5aSThomas Gleixner debug_object_destroy(&obj, &descr_type_test); 12763ac7fe5aSThomas Gleixner if (check_results(&obj, ODEBUG_STATE_DESTROYED, fixups, warnings)) 12773ac7fe5aSThomas Gleixner goto out; 12783ac7fe5aSThomas Gleixner debug_object_init(&obj, &descr_type_test); 12793ac7fe5aSThomas Gleixner if (check_results(&obj, ODEBUG_STATE_DESTROYED, fixups, ++warnings)) 12803ac7fe5aSThomas Gleixner goto out; 12813ac7fe5aSThomas Gleixner debug_object_activate(&obj, &descr_type_test); 12823ac7fe5aSThomas Gleixner if (check_results(&obj, ODEBUG_STATE_DESTROYED, fixups, ++warnings)) 12833ac7fe5aSThomas Gleixner goto out; 12843ac7fe5aSThomas Gleixner debug_object_deactivate(&obj, &descr_type_test); 12853ac7fe5aSThomas Gleixner if (check_results(&obj, ODEBUG_STATE_DESTROYED, fixups, ++warnings)) 12863ac7fe5aSThomas Gleixner goto out; 12873ac7fe5aSThomas Gleixner debug_object_free(&obj, &descr_type_test); 12883ac7fe5aSThomas Gleixner if (check_results(&obj, ODEBUG_STATE_NONE, fixups, warnings)) 12893ac7fe5aSThomas Gleixner goto out; 12903ac7fe5aSThomas Gleixner 12913ac7fe5aSThomas Gleixner obj.static_init = 1; 12923ac7fe5aSThomas Gleixner debug_object_activate(&obj, &descr_type_test); 12939f78ff00SStephen Boyd if (check_results(&obj, ODEBUG_STATE_ACTIVE, fixups, warnings)) 12943ac7fe5aSThomas Gleixner goto out; 12953ac7fe5aSThomas Gleixner debug_object_init(&obj, &descr_type_test); 12963ac7fe5aSThomas Gleixner if (check_results(&obj, ODEBUG_STATE_INIT, ++fixups, ++warnings)) 12973ac7fe5aSThomas Gleixner goto out; 12983ac7fe5aSThomas Gleixner debug_object_free(&obj, &descr_type_test); 12993ac7fe5aSThomas Gleixner if (check_results(&obj, ODEBUG_STATE_NONE, fixups, warnings)) 13003ac7fe5aSThomas Gleixner goto out; 13013ac7fe5aSThomas Gleixner 13023ac7fe5aSThomas Gleixner #ifdef CONFIG_DEBUG_OBJECTS_FREE 13033ac7fe5aSThomas Gleixner debug_object_init(&obj, &descr_type_test); 13043ac7fe5aSThomas Gleixner if (check_results(&obj, ODEBUG_STATE_INIT, fixups, warnings)) 13053ac7fe5aSThomas Gleixner goto out; 13063ac7fe5aSThomas Gleixner debug_object_activate(&obj, &descr_type_test); 13073ac7fe5aSThomas Gleixner if (check_results(&obj, ODEBUG_STATE_ACTIVE, fixups, warnings)) 13083ac7fe5aSThomas Gleixner goto out; 13093ac7fe5aSThomas Gleixner __debug_check_no_obj_freed(&obj, sizeof(obj)); 13103ac7fe5aSThomas Gleixner if (check_results(&obj, ODEBUG_STATE_NONE, ++fixups, ++warnings)) 13113ac7fe5aSThomas Gleixner goto out; 13123ac7fe5aSThomas Gleixner #endif 1313719e4843SFabian Frederick pr_info("selftest passed\n"); 13143ac7fe5aSThomas Gleixner 13153ac7fe5aSThomas Gleixner out: 13163ac7fe5aSThomas Gleixner debug_objects_fixups = oldfixups; 13173ac7fe5aSThomas Gleixner debug_objects_warnings = oldwarnings; 13183ac7fe5aSThomas Gleixner descr_test = NULL; 13193ac7fe5aSThomas Gleixner 13203ac7fe5aSThomas Gleixner local_irq_restore(flags); 1321661cc28bSThomas Gleixner return debug_objects_enabled; 13223ac7fe5aSThomas Gleixner } 13233ac7fe5aSThomas Gleixner #else 132455fb412eSThomas Gleixner static inline bool debug_objects_selftest(void) { return true; } 13253ac7fe5aSThomas Gleixner #endif 13263ac7fe5aSThomas Gleixner 13273ac7fe5aSThomas Gleixner /* 13283ac7fe5aSThomas Gleixner * Called during early boot to initialize the hash buckets and link 13293ac7fe5aSThomas Gleixner * the static object pool objects into the poll list. After this call 13303ac7fe5aSThomas Gleixner * the object tracker is fully operational. 13313ac7fe5aSThomas Gleixner */ 13323ac7fe5aSThomas Gleixner void __init debug_objects_early_init(void) 13333ac7fe5aSThomas Gleixner { 13343ac7fe5aSThomas Gleixner int i; 13353ac7fe5aSThomas Gleixner 13363ac7fe5aSThomas Gleixner for (i = 0; i < ODEBUG_HASH_SIZE; i++) 1337aef9cb05SThomas Gleixner raw_spin_lock_init(&obj_hash[i].lock); 13383ac7fe5aSThomas Gleixner 1339cb58d190SThomas Gleixner /* Keep early boot simple and add everything to the boot list */ 13403ac7fe5aSThomas Gleixner for (i = 0; i < ODEBUG_POOL_SIZE; i++) 1341cb58d190SThomas Gleixner hlist_add_head(&obj_static_pool[i].node, &pool_boot); 13423ac7fe5aSThomas Gleixner } 13433ac7fe5aSThomas Gleixner 13443ac7fe5aSThomas Gleixner /* 134555fb412eSThomas Gleixner * Convert the statically allocated objects to dynamic ones. 134655fb412eSThomas Gleixner * debug_objects_mem_init() is called early so only one CPU is up and 134755fb412eSThomas Gleixner * interrupts are disabled, which means it is safe to replace the active 134855fb412eSThomas Gleixner * object references. 13491be1cb7bSThomas Gleixner */ 135055fb412eSThomas Gleixner static bool __init debug_objects_replace_static_objects(struct kmem_cache *cache) 13511be1cb7bSThomas Gleixner { 13521be1cb7bSThomas Gleixner struct debug_bucket *db = obj_hash; 13531be1cb7bSThomas Gleixner struct debug_obj *obj, *new; 135455fb412eSThomas Gleixner struct hlist_node *tmp; 13551be1cb7bSThomas Gleixner HLIST_HEAD(objects); 1356241463f4SThomas Gleixner int i; 13571be1cb7bSThomas Gleixner 13581be1cb7bSThomas Gleixner for (i = 0; i < ODEBUG_POOL_SIZE; i++) { 135955fb412eSThomas Gleixner obj = kmem_cache_zalloc(cache, GFP_KERNEL); 13601be1cb7bSThomas Gleixner if (!obj) 13611be1cb7bSThomas Gleixner goto free; 13621be1cb7bSThomas Gleixner hlist_add_head(&obj->node, &objects); 13631be1cb7bSThomas Gleixner } 13641be1cb7bSThomas Gleixner 1365e18328ffSThomas Gleixner debug_objects_allocated = ODEBUG_POOL_SIZE; 1366e18328ffSThomas Gleixner pool_global.cnt = ODEBUG_POOL_SIZE; 1367eabb7f1aSwuchi 13681be1cb7bSThomas Gleixner /* 1369cb58d190SThomas Gleixner * Move the allocated objects to the global pool and disconnect the 1370cb58d190SThomas Gleixner * boot pool. 1371a0ae9504SZhen Lei */ 1372e18328ffSThomas Gleixner hlist_move_list(&objects, &pool_global.objects); 1373cb58d190SThomas Gleixner pool_boot.first = NULL; 13741be1cb7bSThomas Gleixner 13751be1cb7bSThomas Gleixner /* Replace the active object references */ 13761be1cb7bSThomas Gleixner for (i = 0; i < ODEBUG_HASH_SIZE; i++, db++) { 13771be1cb7bSThomas Gleixner hlist_move_list(&db->list, &objects); 13781be1cb7bSThomas Gleixner 1379b67bfe0dSSasha Levin hlist_for_each_entry(obj, &objects, node) { 1380e18328ffSThomas Gleixner new = hlist_entry(pool_global.objects.first, typeof(*obj), node); 13811be1cb7bSThomas Gleixner hlist_del(&new->node); 1382e18328ffSThomas Gleixner pool_global.cnt--; 13831be1cb7bSThomas Gleixner /* copy object data */ 13841be1cb7bSThomas Gleixner *new = *obj; 13851be1cb7bSThomas Gleixner hlist_add_head(&new->node, &db->list); 13861be1cb7bSThomas Gleixner } 13871be1cb7bSThomas Gleixner } 138855fb412eSThomas Gleixner return true; 13891be1cb7bSThomas Gleixner free: 139049a5cb82SThomas Gleixner /* Can't use free_object_list() as the cache is not populated yet */ 1391b67bfe0dSSasha Levin hlist_for_each_entry_safe(obj, tmp, &objects, node) { 13921be1cb7bSThomas Gleixner hlist_del(&obj->node); 139355fb412eSThomas Gleixner kmem_cache_free(cache, obj); 13941be1cb7bSThomas Gleixner } 139555fb412eSThomas Gleixner return false; 13961be1cb7bSThomas Gleixner } 13971be1cb7bSThomas Gleixner 13981be1cb7bSThomas Gleixner /* 13993ac7fe5aSThomas Gleixner * Called after the kmem_caches are functional to setup a dedicated 14003ac7fe5aSThomas Gleixner * cache pool, which has the SLAB_DEBUG_OBJECTS flag set. This flag 14013ac7fe5aSThomas Gleixner * prevents that the debug code is called on kmem_cache_free() for the 14023ac7fe5aSThomas Gleixner * debug tracker objects to avoid recursive calls. 14033ac7fe5aSThomas Gleixner */ 14043ac7fe5aSThomas Gleixner void __init debug_objects_mem_init(void) 14053ac7fe5aSThomas Gleixner { 140655fb412eSThomas Gleixner struct kmem_cache *cache; 14073f397bf9SThomas Gleixner int extras; 1408d86998b1SWaiman Long 14093ac7fe5aSThomas Gleixner if (!debug_objects_enabled) 14103ac7fe5aSThomas Gleixner return; 14113ac7fe5aSThomas Gleixner 141255fb412eSThomas Gleixner if (!debug_objects_selftest()) 1413eabb7f1aSwuchi return; 141455fb412eSThomas Gleixner 141555fb412eSThomas Gleixner cache = kmem_cache_create("debug_objects_cache", sizeof (struct debug_obj), 0, 141655fb412eSThomas Gleixner SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE, NULL); 141755fb412eSThomas Gleixner 141855fb412eSThomas Gleixner if (!cache || !debug_objects_replace_static_objects(cache)) { 1419661cc28bSThomas Gleixner debug_objects_enabled = false; 142055fb412eSThomas Gleixner pr_warn("Out of memory.\n"); 142155fb412eSThomas Gleixner return; 142255fb412eSThomas Gleixner } 142355fb412eSThomas Gleixner 142455fb412eSThomas Gleixner /* 142555fb412eSThomas Gleixner * Adjust the thresholds for allocating and freeing objects 142655fb412eSThomas Gleixner * according to the number of possible CPUs available in the 142755fb412eSThomas Gleixner * system. 142855fb412eSThomas Gleixner */ 142955fb412eSThomas Gleixner extras = num_possible_cpus() * ODEBUG_BATCH_SIZE; 143055fb412eSThomas Gleixner debug_objects_pool_size += extras; 143155fb412eSThomas Gleixner debug_objects_pool_min_level += extras; 143255fb412eSThomas Gleixner 143355fb412eSThomas Gleixner /* Everything worked. Expose the cache */ 143455fb412eSThomas Gleixner obj_cache = cache; 1435634d61f4SWaiman Long 143688451f2cSZqiang #ifdef CONFIG_HOTPLUG_CPU 143788451f2cSZqiang cpuhp_setup_state_nocalls(CPUHP_DEBUG_OBJ_DEAD, "object:offline", NULL, 143888451f2cSZqiang object_cpu_offline); 143988451f2cSZqiang #endif 144055fb412eSThomas Gleixner return; 14413ac7fe5aSThomas Gleixner } 1442