From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754712AbcKYO3J (ORCPT ); Fri, 25 Nov 2016 09:29:09 -0500 Received: from mx2.suse.de ([195.135.220.15]:39102 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753790AbcKYO3A (ORCPT ); Fri, 25 Nov 2016 09:29:00 -0500 Date: Fri, 25 Nov 2016 15:28:55 +0100 From: Petr Mladek To: Sergey Senozhatsky Cc: Andrew Morton , Jan Kara , Tejun Heo , Calvin Owens , Thomas Gleixner , Mel Gorman , Steven Rostedt , Ingo Molnar , Peter Zijlstra , Laura Abbott , Andy Lutomirski , Linus Torvalds , Kees Cook , linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: Re: [RFC][PATCHv4 5/6] printk: use printk_safe buffers Message-ID: <20161125142855.GI24103@pathway.suse.cz> References: <20161027154933.1211-1-sergey.senozhatsky@gmail.com> <20161027154933.1211-6-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161027154933.1211-6-sergey.senozhatsky@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 2016-10-28 00:49:32, Sergey Senozhatsky wrote: > Use printk_safe per-CPU buffers in in printk recursion-prone blocks: > -- around logbuf_lock protected sections in vprintk_emit() and > console_unlock() > -- around down_trylock_console_sem() and up_console_sem() > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > index 4675b8d..5907e92 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -1823,13 +1837,12 @@ asmlinkage int vprintk_emit(int facility, int level, > */ > if (!oops_in_progress && !lockdep_recursing(current)) > { > recursion_bug = true; > - local_irq_restore(flags); > + printk_safe_exit(flags); > return 0; > } > zap_locks(); > } > > - lockdep_off(); I really like this patch. The only small problem is that it enables lockdep and it does not explain why it is safe. The change itself looks fine but it took me some time to prove why. IMHO, it is worth a comment. One thing is printk() recursion caused by lockdep warning triggered from inside vprintk_emit(). It is safe because the critical sections are guarded by printk_safe_enter()/exit() now. Another thing is lockdep recursion caused by catching another lockdep issue when printing warning about the first one. This is safe because lockdep protects itself. First, it sets and checks current->lockdep_recursion around the critical sections. Second, further checks are disabled entirely once first lockdep issue is found. If you add some comments about lockdep, feel free to use: Reviewed-by: Petr Mladek Best Regards, Petr