Re: [PATCH 2/2] debugobjects: Print warnings outside bucket lock

From: Waiman Long
Date: Thu Dec 13 2018 - 17:04:18 EST


On 12/12/2018 11:34 PM, Dmitry Safonov wrote:
> Whenever debugobjects finds invalid pattern during life time of a kernel
> object such as:
> - Activation of uninitialized objects
> - Initialization of active objects
> - Usage of freed/destroyed objects
> it prints a warning and tries to make fixup over an object.
>
> 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.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 | 89 ++++++++++++++++++++++++----------------------
> 1 file changed, 47 insertions(+), 42 deletions(-)
>
> diff --git a/lib/debugobjects.c b/lib/debugobjects.c
> index 98968219405b..0c92e46cb588 100644
> --- a/lib/debugobjects.c
> +++ b/lib/debugobjects.c
> @@ -313,7 +313,7 @@ static struct debug_bucket *get_bucket(unsigned long addr)
> return &obj_hash[hash];
> }
>
> -static void debug_print_object(struct debug_obj *obj, char *msg)
> +static void __debug_print_object(struct debug_obj *obj, char *msg)
> {
> struct debug_obj_descr *descr = obj->descr;
> static int limit;
> @@ -330,6 +330,14 @@ static void debug_print_object(struct debug_obj *obj, char *msg)
> debug_objects_warnings++;
> }
>
> +#define debug_print_object(obj, msg, lock, flags) \
> + do { \
> + struct debug_obj tmp = *obj; \
> + \
> + raw_spin_unlock_irqrestore(lock, flags); \
> + __debug_print_object(&tmp, msg); \
> + } while(0)
> +

My main problem with this patch is the hiding of the unlock call in the
macro. I will prefer matching unlocks to be clearly visible in the
function bodies. Otherwise, the readers may be confused.

Cheers,
Longman