From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751453AbcHaEA3 (ORCPT ); Wed, 31 Aug 2016 00:00:29 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33361 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750708AbcHaEA2 (ORCPT ); Wed, 31 Aug 2016 00:00:28 -0400 Date: Wed, 31 Aug 2016 13:00:35 +0900 From: Sergey Senozhatsky To: Petr Mladek Cc: Sergey Senozhatsky , Sergey Senozhatsky , Andrew Morton , Jan Kara , linux-kernel@vger.kernel.org Subject: Re: [PATCH] printk/nmi: avoid direct printk()-s from __printk_nmi_flush() Message-ID: <20160831040035.GB390@swordfish> References: <20160829123220.1295-1-sergey.senozhatsky@gmail.com> <20160829151600.GM4866@pathway.suse.cz> <20160830075834.GA494@swordfish> <20160830090436.GO4866@pathway.suse.cz> <20160830093918.GA23693@swordfish> <20160830111948.GQ4866@pathway.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160830111948.GQ4866@pathway.suse.cz> User-Agent: Mutt/1.7.0 (2016-08-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (08/30/16 13:19), Petr Mladek wrote: [..] > > yes, x86 has a per-cpu nmi_state to handle the case when NMI is > > loosing its NMI context. But other arch-s, as far as I can see, > > don't do that. Does it mean that we are safe only on x86? > > My understanding is that the kernel would crash on the other > architectures if a double iret was called. By other words, > they would have bigger problems than the nmi_enter()/nmi_exit() > calls. So, we should be on the safe side. > > > this printk_func_saved thing is still will be needed, I think, > > for alt_printk. > > > > Example: > > > > process abc > > printk() > > alt_printk_enter() > > this_cpu_write(printk_func, vprintk_alt); > > -> NMI > > : printk_nmi_enter() > > : this_cpu_write(printk_func, vprintk_nmi); > > : printk_nmi_exit() > > : this_cpu_write(printk_func, vprintk_default); > > return NMI > > > > printk() <<<< nested printk -> vprintk_default(), set by nmi_exit() > > alt_printk_exit() > > ... > > I see. But then we will need to be more careful because printk_func > and printk_func_saved will be manipulated in different contexts: > normal, irq, nmi. A solution might be using an atomic counter > and selecting the right vprintk_func according to the value. yes, I thought about something like this. ... or we can use the one and only 'nmi_seq' buffer and share it between NMI and alt_printk, adding a special prefix to every message if (in_nmi()) sprintf("NMI:%s", message) else sprintf("%s", message) so, yes, it can get hairy, but at least it will be grep-able, still better than nothing. > Well, I am still afraid that yet another alt_printk is not > the way to go. well, it might be and it might be not. -ss