From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751912AbdJPIMz (ORCPT ); Mon, 16 Oct 2017 04:12:55 -0400 Received: from mx2.suse.de ([195.135.220.15]:43105 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751591AbdJPIMy (ORCPT ); Mon, 16 Oct 2017 04:12:54 -0400 Date: Mon, 16 Oct 2017 10:12:52 +0200 From: Petr Mladek To: Steven Rostedt Cc: Sergey Senozhatsky , LKML , Peter Zijlstra , Andrew Morton Subject: Re: [PATCH] printk: Remove superfluous memory barriers from printk_safe Message-ID: <20171016081252.GG2795@pathway.suse.cz> References: <20171011124647.7781f98f@gandalf.local.home> <20171014092129.GD2973@tigerII.localdomain> <20171015202715.5c3bb075@vmware.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171015202715.5c3bb075@vmware.local.home> 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 Sun 2017-10-15 20:27:15, Steven Rostedt wrote: > On Sat, 14 Oct 2017 18:21:29 +0900 > Sergey Senozhatsky wrote: > > > On (10/11/17 12:46), Steven Rostedt wrote: > > > From: Steven Rostedt (VMware) > > > > > > The variable printk_safe_irq_ready is set and never cleared at system > > > boot up, when there's only one CPU active. It is set before other > > > CPUs come on line. Also, it is extremely unlikely that an NMI would > > > trigger this early in boot up (which I wonder why we even have this > > > variable at all). > > > > it's not only NMI related, printk() recursion can happen at any stages, > > including... um... wait a second. ... including the "before we set up > > per-CPU areas" stage? hmm... smells like a bug? > > I think this was just being overly paranoid. I was curious because it was not only about reading the per-CPU variables. We set and clear the printk_context per-CPU variable in every printk() call. I wondered if we accessed some non-initialized stuff. Fortunately, it seems that we are on the safe side. If I get it correctly, the per-CPU variables are set up in setup_per_cpu_areas(). But some per-CPU variables are used even before, see boot_cpu_init() smp_processor_id() raw_smp_processor_id() this_cpu_read(cpu_number) IMHO, the trick is the following code in setup_per_cpu_areas() from arch/x86/kernel/setup_percpu.c: /* * Up to this point, the boot CPU has been using .init.data * area. Reload any changed state for the boot CPU. */ if (!cpu) switch_to_new_gdt(cpu); IMHO, this means that per-CPU variable for the first boot-CPU can be used at any time. And all the interesting functions: boot_cpu_init(), setup_per_cpu_areas(), printk_safe_init() are still called in the single-CPU mode. Best Regards, Petr