debugobjects checks during initialization where the real object resides.
Kernel must use debug_object_init() or debug_object_init_on_stack()
accordingly. I'm not sure if it's worth to check debug_object
initialization place, but it seems to be well-documented.

If initialization function finds that the debug object actually resides
in a different place than was annotated, warning is being printed.

Unfortunately, it becomes error-prone to use WARN() or printing under
debugobjects bucket lock: printk() may defer work to workqueue, and
realization of workqueues uses debugobjects. Further, console drivers
use page allocator, potentially vmalloc() or slub/slab. Which reasonably
makes lockdep to go nuts as there are debug_check_no_obj_freed() checks
in allocators.

Move printings out of debugobjets bucket lock to address the potential
lockups.

Link: lkml.kernel.org/r/20181211091154.GL23332@shao2-debian
Reported-by: kernel test robot <rong.a.c...@intel.com>
Cc: Andrew Morton <a...@linux-foundation.org>
Cc: Ingo Molnar <mi...@kernel.org>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Sergey Senozhatsky <sergey.senozhatsky.w...@gmail.com>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: Waiman Long <long...@redhat.com>
Signed-off-by: Dmitry Safonov <d...@arista.com>
---
 lib/debugobjects.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index 55437fd5128b..98968219405b 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -368,13 +368,14 @@ static void debug_object_is_on_stack(void *addr, int 
onstack)
        WARN_ON(1);
 }
 
-static void
-__debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack)
+static bool
+__debug_object_init(void *addr, struct debug_obj_descr *descr)
 {
        enum debug_obj_state state;
        struct debug_bucket *db;
        struct debug_obj *obj;
        unsigned long flags;
+       bool allocated = false;
 
        fill_pool();
 
@@ -389,9 +390,9 @@ __debug_object_init(void *addr, struct debug_obj_descr 
*descr, int onstack)
                        debug_objects_enabled = 0;
                        raw_spin_unlock_irqrestore(&db->lock, flags);
                        debug_objects_oom();
-                       return;
+                       return false;
                }
-               debug_object_is_on_stack(addr, onstack);
+               allocated = true;
        }
 
        switch (obj->state) {
@@ -406,7 +407,7 @@ __debug_object_init(void *addr, struct debug_obj_descr 
*descr, int onstack)
                state = obj->state;
                raw_spin_unlock_irqrestore(&db->lock, flags);
                debug_object_fixup(descr->fixup_init, addr, state);
-               return;
+               return allocated;
 
        case ODEBUG_STATE_DESTROYED:
                debug_print_object(obj, "init");
@@ -416,6 +417,7 @@ __debug_object_init(void *addr, struct debug_obj_descr 
*descr, int onstack)
        }
 
        raw_spin_unlock_irqrestore(&db->lock, flags);
+       return allocated;
 }
 
 /**
@@ -428,7 +430,8 @@ void debug_object_init(void *addr, struct debug_obj_descr 
*descr)
        if (!debug_objects_enabled)
                return;
 
-       __debug_object_init(addr, descr, 0);
+       if (__debug_object_init(addr, descr))
+               debug_object_is_on_stack(addr, 0);
 }
 EXPORT_SYMBOL_GPL(debug_object_init);
 
@@ -443,7 +446,8 @@ void debug_object_init_on_stack(void *addr, struct 
debug_obj_descr *descr)
        if (!debug_objects_enabled)
                return;
 
-       __debug_object_init(addr, descr, 1);
+       if (__debug_object_init(addr, descr))
+               debug_object_is_on_stack(addr, 1);
 }
 EXPORT_SYMBOL_GPL(debug_object_init_on_stack);
 
-- 
2.20.0

Reply via email to