From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755484AbcDAPAg (ORCPT ); Fri, 1 Apr 2016 11:00:36 -0400 Received: from mx2.suse.de ([195.135.220.15]:38949 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751410AbcDAPAf (ORCPT ); Fri, 1 Apr 2016 11:00:35 -0400 Date: Fri, 1 Apr 2016 17:00:32 +0200 From: Petr Mladek To: Sergey Senozhatsky Cc: Andrew Morton , Jan Kara , Tejun Heo , Tetsuo Handa , linux-kernel@vger.kernel.org, Byungchul Park , Sergey Senozhatsky , Jan Kara Subject: Re: [RFC][PATCH v9 1/2] printk: Make printk() completely async Message-ID: <20160401150032.GE1023@pathway.suse.cz> References: <1459519805-23626-1-git-send-email-sergey.senozhatsky@gmail.com> <1459519805-23626-2-git-send-email-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1459519805-23626-2-git-send-email-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-04-01 23:10:04, Sergey Senozhatsky wrote: > This patch makes printk() completely asynchronous (similar to what > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > index bfbf284..2e50c48 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -2722,6 +2761,47 @@ static int __init printk_late_init(void) > late_initcall(printk_late_init); > > #if defined CONFIG_PRINTK > +static int printk_kthread_func(void *data) > +{ > + while (1) { > + set_current_state(TASK_INTERRUPTIBLE); > + if (!printk_kthread_need_flush_console) > + schedule(); > + > + __set_current_state(TASK_RUNNING); > + > + console_lock(); > + console_unlock(); > + /* > + * Avoid an infinite loop when console_unlock() cannot > + * access consoles, e.g. because console_suspended is > + * true. schedule(), someone else will print the messages > + * from resume_console(). > + */ > + printk_kthread_need_flush_console = false; You need to move this assigment right above the console_lock()/console_unlock() calls. Otherwise, there is a race: CPU0: CPU1 printk_kthread_func() console_unlock() printk() printk_kthread_need_flush_console = true; wake_up_process(printk_kthread); printk_kthread_need_flush_console = false; set_current_state(TASK_INTERRUPTIBLE); if (!printk_kthread_need_flush_console) schedule(); => sleeping without processing the last message. You could safely set it false before calling console_lock()/console_unlock() because you are calling the commands that are requested by the flag. With the above described change: Reviewed-by: Petr Mladek Best Regards, Petr