Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1157269ybk; Thu, 14 May 2020 01:47:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlUmg6grFPosjpDh5OkqdR+h0nEefF1iHHBg3S/ZOd5dPPn4Uwszxdz+nap0N/F7Qt9BlX X-Received: by 2002:aa7:cb4f:: with SMTP id w15mr3013938edt.239.1589446030644; Thu, 14 May 2020 01:47:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589446030; cv=none; d=google.com; s=arc-20160816; b=uYV/IwPtueiNyv679iaqiNubYITx/t10wXigl3k1rczHxwJZFumlRpxkaTT5DqmpmK dwivH19G9mBZqXdNLZH/knbKzHMvT4HOssXciAeCOi+m+eIEzcx8ImklElo/NXZuHXHA o8vzh7DO5sgqaDxeFfFeUh3LvYZAD0LGbHArf31Rs47svKSdhlwFfpKBJG0GMH4IeBU4 gsWnERH8HLze0031QQOoIcFC8+DXeg4OGgct4e0+CFP4FVF4QCSQAnwxgChECoHcRDE+ zTth/CP+vAn/ouVu9nxvIeybFfsfHRir5vWPmox073UzZdBwb2gCYSuPDjxejd/lIjuA mWWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=5iSUz4RzShc46MC67Q/iaDq2PFyj21LilB84xi2bBaM=; b=mzvcpUEAHWZVERCd8nzPmdYTn+fljgiJyRVcd3kRdEAmLXa6YayJDZvzGfthrgg2gh hsHQQN4coGIe9MrGJSpffFTFHPxQonrreSOMNyPwOopUEFHGx5DZr1yJT/1WnUz7qLDb w210DIQRDmFKm3OUrUBQ5AFbd6PZ8Sv3MAuLAvehMl74Q3452CRciexOniSjvBarvxF4 v6OpflLZL0D12Bqc3+NbpfCs8wXlUBimjW4vutT2hBaZv/rjjpGyLNRgVUkRVQVNO2/O FlLgFW51YVTtatq4h/5JHprNobwUSsuB657DB/emJd+m65gelm7KWZX5QUJtWiY+gnLR ptrg== 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 no5si1384124ejb.204.2020.05.14.01.46.47; Thu, 14 May 2020 01:47:10 -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 S1725999AbgENInY (ORCPT + 99 others); Thu, 14 May 2020 04:43:24 -0400 Received: from mx2.suse.de ([195.135.220.15]:54744 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725925AbgENInY (ORCPT ); Thu, 14 May 2020 04:43:24 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 99CA3AF48; Thu, 14 May 2020 08:43:24 +0000 (UTC) Date: Thu, 14 May 2020 10:42:36 +0200 From: Petr Mladek To: Sumit Garg Cc: Daniel Thompson , Jason Wessel , Douglas Anderson , kgdb-bugreport@lists.sourceforge.net, Linux Kernel Mailing List , Arnd Bergmann , Andrew Morton , Peter Zijlstra , Steven Rostedt Subject: Re: [PATCH] kgdb: Fix broken handling of printk() in NMI context Message-ID: <20200514084230.GO17734@linux-b0ei> References: <1589273314-12060-1-git-send-email-sumit.garg@linaro.org> <20200512142533.ta4uejwmq5gchtlx@holly.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 2020-05-13 19:04:48, Sumit Garg wrote: > On Tue, 12 May 2020 at 19:55, Daniel Thompson > wrote: > > > > On Tue, May 12, 2020 at 02:18:34PM +0530, Sumit Garg wrote: > > > Since commit 42a0bb3f7138 ("printk/nmi: generic solution for safe printk > > > in NMI"), kgdb entry in NMI context defaults to use safe NMI printk() > > > > I didn't see the author on Cc: nor any of the folks whose hands it > > passed through. It would definitely be good to involve them in this > > discussion. > > > > Thanks for updating the Cc: list. > > > > > > which involves CPU specific buffers and deferred printk() until exit from > > > NMI context. > > > > > > But kgdb being a stop-the-world debugger, we don't want to defer printk() > > > especially backtrace on corresponding CPUs. So instead switch to normal > > > printk() mode in kgdb_cpu_enter() if entry is in NMI context. > > > > So, firstly I should *definitely* take a mea cupla for not shouting > > about this at the time (I was on Cc:... twice). Only thing I can say > > confidently is that the test suite didn't yell about this and so I > > didn't look at this as closely as I should have done (and that it > > didn't yell is mostly because I'm still building out the test suite > > coverage). > > > > Anyhow... > > > > This feels a little like we are smearing the printk() interception logic > > across the kernel in ways that make things hard to read. If we accepted > > this patch we then have, the new NMI interception logic, the old kdb > > interception logic and some hacks in the kgdb trap handler to defang the > > NMI interception logic and force the kdb logic to kick in. > > > > Wouldn't it be better to migrate kdb interception logic up a couple of > > levels so that it continues to function even when we are in nmi printk > > mode. That way *all* the printk() interception code would end up in > > one place. > > > > Yes it would be better to have all printk() interception code at one > place. Let me see if I can come up with an integrated logic. It might be enough to move the kdb_check from vprintk_default() to vprintk_func(). I have never used kdb. I did not know that it was able to stop kernel in any context. Would this work? It is only compile tested! From 14ae6c9f0cbd1479cb898c864c7ab46e20f3cf6f Mon Sep 17 00:00:00 2001 From: Petr Mladek Date: Thu, 14 May 2020 10:37:44 +0200 Subject: [PATCH] printk/kdb: Redirect printk messages into kdb in any context kdb is able to stop kernel even in NMI context where printk() is redirected to the printk_safe() lockless variant. Move the check and redirect to kdb even in this case. Signed-off-by: Petr Mladek --- kernel/printk/printk.c | 14 +------------- kernel/printk/printk_safe.c | 8 ++++++++ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 9a9b6156270b..63a1aa377cd9 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -2036,18 +2035,7 @@ EXPORT_SYMBOL(vprintk); int vprintk_default(const char *fmt, va_list args) { - int r; - -#ifdef CONFIG_KGDB_KDB - /* Allow to pass printk() to kdb but avoid a recursion. */ - if (unlikely(kdb_trap_printk && kdb_printf_cpu < 0)) { - r = vkdb_printf(KDB_MSGSRC_PRINTK, fmt, args); - return r; - } -#endif - r = vprintk_emit(0, LOGLEVEL_DEFAULT, NULL, 0, fmt, args); - - return r; + return vprintk_emit(0, LOGLEVEL_DEFAULT, NULL, 0, fmt, args); } EXPORT_SYMBOL_GPL(vprintk_default); diff --git a/kernel/printk/printk_safe.c b/kernel/printk/printk_safe.c index d9a659a686f3..81734497c625 100644 --- a/kernel/printk/printk_safe.c +++ b/kernel/printk/printk_safe.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -359,6 +360,13 @@ void __printk_safe_exit(void) __printf(1, 0) int vprintk_func(const char *fmt, va_list args) { +#ifdef CONFIG_KGDB_KDB + /* Allow to pass printk() to kdb but avoid a recursion. */ + if (unlikely(kdb_trap_printk && kdb_printf_cpu < 0)) { + return vkdb_printf(KDB_MSGSRC_PRINTK, fmt, args); + } +#endif + /* * Try to use the main logbuf even in NMI. But avoid calling console * drivers that might have their own locks. -- 2.26.1