From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755255AbcI2NUI (ORCPT ); Thu, 29 Sep 2016 09:20:08 -0400 Received: from mx2.suse.de ([195.135.220.15]:55656 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752168AbcI2NUB (ORCPT ); Thu, 29 Sep 2016 09:20:01 -0400 Date: Thu, 29 Sep 2016 15:19:58 +0200 From: Petr Mladek To: Sergey Senozhatsky Cc: Jan Kara , Andrew Morton , Tejun Heo , Calvin Owens , linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: Re: [RFC][PATCH 7/7] printk: new printk() recursion detection Message-ID: <20160929131958.GF26796@pathway.suse.cz> References: <20160927142237.5539-1-sergey.senozhatsky@gmail.com> <20160927142237.5539-8-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160927142237.5539-8-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 Tue 2016-09-27 23:22:37, Sergey Senozhatsky wrote: > We can't use alt_printk when we are flushing alt_printk buffers to logbuf, > because otherwise we would just flush messages back to alt_printk buffers. > At the same time, this opens a door for potential deadlock, should flushing > endup in recursive printk() call: > > irq_work_run() > alt_printk_flush_line() > printk() > WARN_ON() > ^^^^^^^^^ > depending on circumstances this can result in printk-deadlock. > > To cope with it, we can use alt_printk context ->entry_count: > - __alt_printk_flush() sets ->entry_count to 1 > - every printk() call from alt_printk_flush_foo() calls > alt_printk_enter() and alt_printk_exit() > - alt_printk_enter() increments ->entry_count and tests the value: > - if it's `==2' then we are in normal alt_printk_flush()->printk() path > - if it's `>=3' then we are in recursion. The first time we detect > recursion (->entry_count == 3) we switch from default printk() to > alt_printk(), to avoid possible deadlocks. > - in alt_printk_exit() we test if we were in normal printk() path or > in printk() recursion and rollback to default printk() if so; > and decrement ->entry_count. I am sorry but I do not understand this much. printk() should set the alternative implementation in the critical section by default. Why do we need to handle this so specially? Is it because of flushing in NMI context when panicing? I would call vprintk_emit() directly from the flush_line() function in this case. Then all other possible error printk's will get redirected to the NMI buffer which is good enouh. Best Regards, Petr