Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2532098pxy; Tue, 3 Aug 2021 08:35:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbf6jxiA/m7FyZnYc0K3Q8Vn8+rt8xVAHHa0gfIpj0Sqnl7prUpZk8rKf6CxoszoPLXofU X-Received: by 2002:aa7:d519:: with SMTP id y25mr25631419edq.191.1628004901109; Tue, 03 Aug 2021 08:35:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628004901; cv=none; d=google.com; s=arc-20160816; b=cxV85Ps5lsGLUV3fTbqgRu9UB2SfMECcJdTcBMMQHzEaWpAYd8X48SkGcFJ50Zyghk PtgOwgDVIDE6lP0pJp7L6Tt9ygHfvwMb0PlcEUY1gZOp2KGOr9SJDYnTKpwVUrAT4EES NBv/VJHVxTL8p9hDhCyEcP6kUliZGUnw4t0n0EoH5ykpYIdD2nufyuRT8xNLwo/cim/N lV85fKfYJUh4Kpx6OGvktcB6fjl3qeVWEJybt5Gx2hNFOk0huWyBU0AUEmzMIwJ81PHU McWH9QJoKwS8naOSoi80jCgOko8J00D48Szamwcee4K1dDR+KZ1V21IxqPF84qPYusDx RS7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=JYAidDTtZlwD0eAmDJGiwHLKb2zrViR5iopfW/47ycc=; b=cO7b1ZQikpJwEFwApPCUj+HZGyNfGCzrZAzSDa7Qed8qrsuBUrbyZ26maayqoqJ3lf EMi/Ylbc6m0O22nIxHzHOjCxs/zw1SeHqFpP5+eBnLv5yjBQj1ZNmkag1tPpEAt4UUUm NobNODYQd4l4cHWj1rLl+fxg/gtisL//0HUHn6hY4zdsMvc1U6P6BkdPgNbVdjIW8Jub v8bd34/ZBXyHRxGcRBHLArikP7Gn45f54fK9BCfXcPqyowLNT4B1CAABAT6iUucc6orl kv+a8LloR78Jt/E4qFe13/FeTJk5qTfyyoFSFKXNgsghvA3sCZFWV4DvPu99N2XoskVf bFWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="OqjOI/Fb"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=+B9KGpXL; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f13si13445924edw.513.2021.08.03.08.34.38; Tue, 03 Aug 2021 08:35:01 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b="OqjOI/Fb"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=+B9KGpXL; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236758AbhHCPbA (ORCPT + 99 others); Tue, 3 Aug 2021 11:31:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236741AbhHCPay (ORCPT ); Tue, 3 Aug 2021 11:30:54 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09550C0617B1 for ; Tue, 3 Aug 2021 08:30:36 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1628004633; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JYAidDTtZlwD0eAmDJGiwHLKb2zrViR5iopfW/47ycc=; b=OqjOI/FbmrK18S3ZvolMVu6MnmqMbOBo9jrdeXX3wxV7sqCVpdjTRar0H7i0ExNzY5bR/X PdP6sVQRAPdOYEMbxPgbQpXhiP/YVGhgrClPXAfjkOLUjk6nKsl2opF1S0+2EWZi8fdTVQ OyF18c9yESpVQ1ED39gaPl7oFtEgs51vYZX7ouRviNrfeq89w+mkATGMlPRG116iVVa1sP aAVNstXlI6g5+Od+hSIym7JtGUKKUBCybkbw6Tq9/SDXhAX0rTcnPPRvsN0GraIj3Cb00c qPHfZgWp/+9IGkAMNPiGT1MYOTT8EI5B06YAqc4VThaM1sSv5Bxo5RItB4a/cg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1628004633; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JYAidDTtZlwD0eAmDJGiwHLKb2zrViR5iopfW/47ycc=; b=+B9KGpXLz+WiAwY5HjTHSwrgLkU2AO4ktjbvjOzrUjWKgCCoYGx8mHsRRMGq0543zI3G5c yoN+x2AyyiqMdSCw== To: Daniel Thompson Cc: Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Jason Wessel , Douglas Anderson , Srikar Dronamraju , "Gautham R. Shenoy" , Chengyang Fan , Christophe Leroy , Bhaskar Chowdhury , Nicholas Piggin , =?utf-8?Q?C=C3=A9dric?= Le Goater , "Gustavo A. R. Silva" , Peter Zijlstra , linuxppc-dev@lists.ozlabs.org, kgdb-bugreport@lists.sourceforge.net Subject: Re: [PATCH printk v1 03/10] kgdb: delay roundup if holding printk cpulock In-Reply-To: <20210803142558.cz7apumpgijs5y4y@maple.lan> References: <20210803131301.5588-1-john.ogness@linutronix.de> <20210803131301.5588-4-john.ogness@linutronix.de> <20210803142558.cz7apumpgijs5y4y@maple.lan> Date: Tue, 03 Aug 2021 17:36:32 +0206 Message-ID: <87tuk635rb.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-08-03, Daniel Thompson wrote: > On Tue, Aug 03, 2021 at 03:18:54PM +0206, John Ogness wrote: >> kgdb makes use of its own cpulock (@dbg_master_lock, @kgdb_active) >> during cpu roundup. This will conflict with the printk cpulock. > > When the full vision is realized what will be the purpose of the printk > cpulock? > > I'm asking largely because it's current role is actively unhelpful > w.r.t. kdb. It is possible that cautious use of in_dbg_master() might > be a better (and safer) solution. However it sounds like there is a > larger role planned for the printk cpulock... The printk cpulock is used as a synchronization mechanism for implementing atomic consoles, which need to be able to safely interrupt the console write() activity at any time and immediately continue with their own printing. The ultimate goal is to move all console printing into per-console dedicated kthreads, so the primary function of the printk cpulock is really to immediately _stop_ the CPU/kthread performing write() in order to allow write_atomic() (from any context on any CPU) to safely and reliably take over. Atomic consoles are actually quite similar to the kgdb_io ops. For example, comparing: serial8250_console_write_atomic() + serial8250_console_putchar_locked() with serial8250_put_poll_char() The difference is that serial8250_console_write_atomic() is line-based and synchronizing with serial8250_console_write() so that if the kernel crashes while outputing to the console, write() can be interrupted by write_atomic() and cleanly formatted crash data can be output. Also serial8250_put_poll_char() is calling into __pm_runtime_resume(), which includes a spinlock and possibly sleeping. This would not be acceptable for atomic consoles. Although, as Andy pointed out [0], I will need to figure out how to deal with suspended consoles. Or just implement a policy that registered atomic consoles may never be suspended. I had not considered merging kgdb_io ops with atomic console ops. But now that I look at it more closely, there may be some useful overlap. I will consider this. Thank you for this idea. >> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c >> index 3d0c933937b4..1b546e117f10 100644 >> --- a/kernel/printk/printk.c >> +++ b/kernel/printk/printk.c >> @@ -214,6 +215,7 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, >> #ifdef CONFIG_SMP >> static atomic_t printk_cpulock_owner = ATOMIC_INIT(-1); >> static atomic_t printk_cpulock_nested = ATOMIC_INIT(0); >> +static unsigned int kgdb_cpu = -1; > > Is this the flag to provoke retriggering? It appears to be a write-only > variable (at least in this patch). How is it consumed? Critical catch! Thank you. I am quite unhappy to see these hunks were accidentally dropped when generating this series. @@ -3673,6 +3675,9 @@ EXPORT_SYMBOL(__printk_cpu_trylock); */ void __printk_cpu_unlock(void) { + bool trigger_kgdb = false; + unsigned int cpu; + if (atomic_read(&printk_cpulock_nested)) { atomic_dec(&printk_cpulock_nested); return; @@ -3683,6 +3688,12 @@ void __printk_cpu_unlock(void) * LMM(__printk_cpu_unlock:A) */ + cpu = smp_processor_id(); + if (kgdb_cpu == cpu) { + trigger_kgdb = true; + kgdb_cpu = -1; + } + /* * Guarantee loads and stores from this CPU when it was the * lock owner are visible to the next lock owner. This pairs @@ -3703,6 +3714,21 @@ void __printk_cpu_unlock(void) */ atomic_set_release(&printk_cpulock_owner, -1); /* LMM(__printk_cpu_unlock:B) */ + + if (trigger_kgdb) { + pr_warn("re-triggering kgdb roundup for CPU#%d\n", cpu); + kgdb_roundup_cpu(cpu); + } } EXPORT_SYMBOL(__printk_cpu_unlock); John Ogness [0] https://lore.kernel.org/lkml/YQlKAeXS9MPmE284@smile.fi.intel.com