Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp133472pxt; Wed, 4 Aug 2021 07:34:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwf/2Z7umXwjijS9LNyi6wePJ62rw8gTIKNWSoHAfs5UUh1HmE4aEl2mWv+hJvRkUqAhLet X-Received: by 2002:a17:906:5e07:: with SMTP id n7mr26585565eju.552.1628087655656; Wed, 04 Aug 2021 07:34:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628087655; cv=none; d=google.com; s=arc-20160816; b=cD8qyjWnzDsi4l95xopfh+/EQBa/CdP+3kKpFJbSLaEuGJyGuieuP4/G3w/LFccBMd +9G2GB+oFGkBc4IdBadn/6DVBJOAKLFJCbA7DZvqBqTIxt0zUoAmXiTULdwkvyQoYPQK GeyaALPdl+DWtjlb/MriSX9PV28JnLVdcR6wSB2rJRj8L4QBuPZPnP9X/HoLSwdLC3k/ BL9I1NtiBZaTA8WmstFJAyGngriyxOY2m9DNoX89BcLFn0GS+vWYmLZjOmh2oSPUVEaO FepznExwQJ8zSJgiGImp12lgyYbjq9xkFjKKAoA10Z44VUVpm1uV1SL2vGa9XozU4z9z XYwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=DC4/KiaX6Vt6MBJgEki+wBHi3z9bnh0HTsoiAX5JG+Y=; b=VCcLXBQH78hnKTuArfdXErgPLLFFg+53kptZctQNObSMis0LYY29X8dKkeEmOjrKkw O4riSey2W0SLbTaHn98AAx2TYhOOKZNG0QY+TLrvE9uxJrmSwe2s8rIA5/fc4RLKh+zm LbMMO+tBd4m80mKtb2hWxpKdk6A7uirWYRv7vGOoastnDacgLQ1excHyOjiQ3isu0F+F qRs+xJIxh+3DEACNZ1UZK1JRKZWGfdcOgUvJvwgdgm0y2YvnLNuGIgUY6b+ODtIrCGb3 GwDM0ikkoAzacidBAqQtsv4b9arnki+aPU086X2mEmV9kHW/Q46pvhDlXWvXY5MpvZC1 5nSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=qv89K6eJ; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k17si2203428ejc.528.2021.08.04.07.33.45; Wed, 04 Aug 2021 07:34:15 -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=@suse.com header.s=susede1 header.b=qv89K6eJ; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238096AbhHDMbv (ORCPT + 99 others); Wed, 4 Aug 2021 08:31:51 -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); > + } > }