Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp666989pxj; Thu, 17 Jun 2021 10:59:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpuSVnpAtEmpZZWf+EMXJnqoIk38GHsXVJ6FRXUTgfj/ZfCdXy4KGmoCMvCZtTt5XVWHNx X-Received: by 2002:a05:6402:138c:: with SMTP id b12mr8442521edv.268.1623952799572; Thu, 17 Jun 2021 10:59:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623952799; cv=none; d=google.com; s=arc-20160816; b=yxJrvverGbWfc4tXn1VH3msD8+9d46KWpZIKK5sNeiZ7wVGnpeMmnORlW81korYIkJ mUtxQB8l7ryZWjIpZ1Vx//lrfgKbm5cHxAbjy80RLsFYv/wfaazZU305FA7+t8m+/CRi sPwHwRptBA3MG7H8TMx9E3b5T4BQ3tQVaPzDcQIJULeQUlXOG0ApG9CPh953/CENqYTY 8kx45oUoHdVDa8Py7leQgeo+3Ia+gjCGo/eurjfiCZWNa3nQtN5+KzFKqXnbUOa76XZk eBopvRIEEpitUodlgcpRGpxyKfMpYErsRZIIrTcl/sItZxNKyhmfaX66iFymMlfvUqF/ MN4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=wOqPqeCD6LyWilAP8UVdnNBHGXbjB5c2aESCVEQDcCQ=; b=o8CnfP1y2srp0DFLQEOB61MR3jqIPrMX/EC/UwYIEBlP/P14LoS5mf6FUkb8HOntkP NPmDsyUENH9nXxFqR2T091ydIjVJJO/1Npt5xZjLDrUt1yiN3GtsEz9496dl4luNzle3 QR1jVhBu/p/XaTFGVRRyYLIG/reGAzn0r76S9Va6QOgwETp5ag/WkADdsSImy0tJD3+a S5S4pHZ2jmnJUg2+tMXWvBPza3qw2wRMNKxRldECo6Ytct1okvBd9MU/r+c4pI/Nfsvr rlT2uV3dgqZpLoGPhhU2/cedLgXPU5nVVnNUeOJ05dFSbEWqG8Ko2QlogN1d8gzQwle2 557Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds7si6751664ejc.304.2021.06.17.10.59.36; Thu, 17 Jun 2021 10:59:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232445AbhFQNey (ORCPT + 99 others); Thu, 17 Jun 2021 09:34:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:34424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231654AbhFQNey (ORCPT ); Thu, 17 Jun 2021 09:34:54 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 62E776044F; Thu, 17 Jun 2021 13:32:45 +0000 (UTC) Date: Thu, 17 Jun 2021 09:32:43 -0400 From: Steven Rostedt To: John Ogness Cc: Petr Mladek , Sergey Senozhatsky , Thomas Gleixner , linux-kernel@vger.kernel.org, Stephen Rothwell , Andrew Morton , Peter Zijlstra , Daniel Bristot de Oliveira , Stephen Boyd , Alexander Potapenko Subject: Re: [PATCH next v4 1/2] lib/dump_stack: move cpu lock to printk.c Message-ID: <20210617093243.795b4853@gandalf.local.home> In-Reply-To: <20210617095051.4808-2-john.ogness@linutronix.de> References: <20210617095051.4808-1-john.ogness@linutronix.de> <20210617095051.4808-2-john.ogness@linutronix.de> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 17 Jun 2021 11:56:50 +0206 John Ogness wrote: > dump_stack() implements its own cpu-reentrant spinning lock to > best-effort serialize stack traces in the printk log. However, > there are other functions (such as show_regs()) that can also > benefit from this serialization. > > Move the cpu-reentrant spinning lock (cpu lock) into new helper > functions printk_cpu_lock_irqsave()/printk_cpu_unlock_irqrestore() > so that it is available for others as well. For !CONFIG_SMP the > cpu lock is a NOP. > > Note that having multiple cpu locks in the system can easily > lead to deadlock. Code needing a cpu lock should use the > printk cpu lock, since the printk cpu lock could be acquired > from any code and any context. > > Also note that it is not necessary for a cpu lock to disable > interrupts. However, in upcoming work this cpu lock will be used > for emergency tasks (for example, atomic consoles during kernel > crashes) and any interruptions while holding the cpu lock should > be avoided if possible. > > Signed-off-by: John Ogness > --- Can we add this lock to early_printk() ? This would make early_printk() so much more readable. -- Steve diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 421c35571797..2b749c745c1f 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2259,6 +2259,7 @@ struct console *early_console; asmlinkage __visible void early_printk(const char *fmt, ...) { + unsigned long flags; va_list ap; char buf[512]; int n; @@ -2270,7 +2271,9 @@ asmlinkage __visible void early_printk(const char *fmt, ...) n = vscnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); + printk_cpu_lock_irqsave(flags); early_console->write(early_console, buf, n); + printk_cpu_unlock_irqrestore(flags); } #endif