From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753952AbcHRJvl (ORCPT ); Thu, 18 Aug 2016 05:51:41 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:36755 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753614AbcHRJvj (ORCPT ); Thu, 18 Aug 2016 05:51:39 -0400 Date: Thu, 18 Aug 2016 18:51:44 +0900 From: Sergey Senozhatsky To: Petr Mladek Cc: Sergey Senozhatsky , Viresh Kumar , Jan Kara , Andrew Morton , Sergey Senozhatsky , Jan Kara , Tejun Heo , Tetsuo Handa , "linux-kernel@vger.kernel.org" , Byungchul Park , vlevenetz@mm-sol.com, Greg Kroah-Hartman Subject: Re: [PATCH v10 1/2] printk: Make printk() completely async Message-ID: <20160818095144.GA425@swordfish> References: <1459789048-1337-1-git-send-email-sergey.senozhatsky@gmail.com> <1459789048-1337-2-git-send-email-sergey.senozhatsky@gmail.com> <20160404155149.a3e3307def2d1315e2099c63@linux-foundation.org> <20160406082758.GA3554@quack.suse.cz> <20160812094447.GD7339@pathway.suse.cz> <20160818022712.GB500@swordfish> <20160818093329.GL13300@pathway.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160818093329.GL13300@pathway.suse.cz> User-Agent: Mutt/1.6.2 (2016-07-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (08/18/16 11:33), Petr Mladek wrote: [..] > > > 2. Force synchronous printk inside WARN()/BUG() macros. > > > > will it help? semaphore up() calls wake_up_process() regardless the context. > > not to mention that we still may have spin_dump() enabled. > > Good point. That changes my preferences :-) > > > > > > 3. Force printk_deferred() inside WARN()/BUG() macros via the per-CPU > > > printk_func. > > > > > > It might be elegant. But we do not want this outside the scheduler > > > code. Therefore we would need special variants of WARN_*_SCHED() > > > BUG_*_SCHED() macros. > > Also we need to make sure that everything will be done on a single CPU > as the printk_func is per-CPU variable. lib/dump_stack.c dump_stack() disables local IRQs, so we will stay on the same CPU. schematically dump_stack_deferred() looks like the one below. I don't dump registers, that will require one more *_deferred() function. and as you can see I've replaced show_stack() with save_stack_trace(). it's not entirely universal (as of now), but worked for my needs at that time. --- asmlinkage __visible void dump_stack_deferred(void) { unsigned long flags; unsigned long stack_trace[16]; int was_locked; int old, cpu; int i; struct stack_trace trace = { .nr_entries = 0, .max_entries = ARRAY_SIZE(stack_trace), .entries = stack_trace, .skip = 0, }; local_irq_save(flags); retry: cpu = smp_processor_id(); old = atomic_cmpxchg(&dump_lock, -1, cpu); if (old == -1) { was_locked = 0; } else if (old == cpu) { was_locked = 1; } else { cpu_relax(); goto retry; } save_stack_trace(&trace); for (i = 0; i < trace.nr_entries; i++) { printk_deferred("[%p] %pS\n", (void *)stack_trace[i], (void *)stack_trace[i]); } if (!was_locked) atomic_set(&dump_lock, -1); local_irq_restore(flags); } --- -ss