From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B338AC4338F for ; Wed, 4 Aug 2021 12:31:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 91EB9601FC for ; Wed, 4 Aug 2021 12:31:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238125AbhHDMbw (ORCPT ); Wed, 4 Aug 2021 08:31:52 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:34166 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237690AbhHDMbv (ORCPT ); Wed, 4 Aug 2021 08:31:51 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 1C1141FDD3; Wed, 4 Aug 2021 12:31:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1628080298; h=from:from:reply-to: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=DC4/KiaX6Vt6MBJgEki+wBHi3z9bnh0HTsoiAX5JG+Y=; b=qv89K6eJX6qCyTdTbWC4KoIJyZrT3KxOobSvMJygB5ThmfxOox1BDe2omC2JBPPAoLMtGB bKFSc+u2up5Woqc9r/hhTWJ8Ov9DX5HAMaytSa9uS/AcZYXU1vxKGHzVBgdDIPMeXPJbGJ AqnoLG6rfavK0Kh86LcdVpnFJG8pEbA= Received: from suse.cz (unknown [10.100.216.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 4A1B3A3B84; Wed, 4 Aug 2021 12:31:37 +0000 (UTC) Date: Wed, 4 Aug 2021 14:31:36 +0200 From: Petr Mladek To: John Ogness Cc: Daniel Thompson , 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 , =?iso-8859-1?Q?C=E9dric?= 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 Message-ID: References: <20210803131301.5588-1-john.ogness@linutronix.de> <20210803131301.5588-4-john.ogness@linutronix.de> <20210803142558.cz7apumpgijs5y4y@maple.lan> <87tuk635rb.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87tuk635rb.fsf@jogness.linutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 2021-08-03 17:36:32, John Ogness wrote: > 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. > > > >> 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; > + } Just in case that this approach is used in the end. This code looks racy. kgdb_roundup_delay() seems to be called in NMI context. NMI might happen at this point and set kgdb_cpu after it was checked. I am afraid that it won't be easy to make this safe using a single global variable. A solution might be a per-CPU variable set by kgdb_roundup_delay() when it owns printk_cpu_lock. __printk_cpu_unlock() would call kgdb_roundup_cpu(cpu) when the variable is set. Nit: The name "kgdb_cpu" is too generic. It is not clear what is so special about this CPU. I would call the per-CPU variable "kgdb_delayed_roundup" or so. Best Regards, Petr > /* > * 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); > + } > }