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

Reply via email to