From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S942867AbcJSOlt (ORCPT ); Wed, 19 Oct 2016 10:41:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:42721 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S942792AbcJSOlp (ORCPT ); Wed, 19 Oct 2016 10:41:45 -0400 Date: Wed, 19 Oct 2016 16:41:40 +0200 From: Petr Mladek To: Peter Zijlstra Cc: Sergey Senozhatsky , Andrew Morton , Jan Kara , Tejun Heo , Calvin Owens , Thomas Gleixner , Mel Gorman , Steven Rostedt , Ingo Molnar , linux-kernel@vger.kernel.org, Jason Wessel Subject: Re: [PATCH 1/3] printk: Fix kdb_trap_printk placement Message-ID: <20161019144140.GG11071@pathway.suse.cz> References: <20161018170830.405990950@infradead.org> <20161018171513.585962054@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161018171513.585962054@infradead.org> 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-10-18 19:08:31, Peter Zijlstra wrote: > Some people figured vprintk_emit() makes for a nice API and exported > it, bypassing the kdb trap. > > This still leaves vprintk_nmi() outside of the kbd reach, should that > be fixed too? Good question! vkdb_printf() tries to avoid a deadlock but the code is racy: int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) { [...] /* Serialize kdb_printf if multiple cpus try to write at once. * But if any cpu goes recursive in kdb, just print the output, * even if it is interleaved with any other text. */ if (!KDB_STATE(PRINTF_LOCK)) { KDB_STATE_SET(PRINTF_LOCK); spin_lock_irqsave(&kdb_printf_lock, flags); got_printf_lock = 1; atomic_inc(&kdb_event); } else { __acquire(kdb_printf_lock); } Let's have the following situation: CPU1 CPU2 if (!KDB_STATE(PRINTF_LOCK)) { KDB_STATE_SET(PRINTF_LOCK); if (!KDB_STATE(PRINTF_LOCK)) { } else { __acquire(kdb_printf_lock); } Now, both CPUs are in the critical section and happily writing over each other, e.g. in vsnprintf(next_avail, size_avail, fmt, ap); I quess that we want to fix this race. But I am not sure if it will be done an NMI-safe way. I am going to send a patch for this. Well, vkdb_printf() is called later when the messages are pushed to the main logbuffer by printk_nmi_flush_line(). It is not perfect but... > Cc: Jason Wessel > Signed-off-by: Peter Zijlstra (Intel) Otherwise, your patch makes sense: Reviewed-by: Petr Mladek Best Regards, Petr