[PATCH 1/2] debugobjects: Warn wrong annotation outside bucket lock

From: Dmitry Safonov
Date: Wed Dec 12 2018 - 23:34:56 EST

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

Link: lkml.kernel.org/r/20181211091154.GL23332@shao2-debian
Reported-by: kernel test robot <rong.a.chen@xxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@xxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Waiman Long <longman@xxxxxxxxxx>
Signed-off-by: Dmitry Safonov <dima@xxxxxxxxxx>
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)

-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;


@@ -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);
- 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;

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)

- __debug_object_init(addr, descr, 0);
+ if (__debug_object_init(addr, descr))
+ debug_object_is_on_stack(addr, 0);

@@ -443,7 +446,8 @@ void debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr)
if (!debug_objects_enabled)

- __debug_object_init(addr, descr, 1);
+ if (__debug_object_init(addr, descr))
+ debug_object_is_on_stack(addr, 1);