Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp335004ybk; Fri, 15 May 2020 01:54:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOqnSSeHGddSYRiq+SBmh2UlIwsg0noBtrLyQhJpJzBP8XVR+VxG2Ei5pZmAjzerSEXFL+ X-Received: by 2002:aa7:dd91:: with SMTP id g17mr1704741edv.374.1589532881356; Fri, 15 May 2020 01:54:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589532881; cv=none; d=google.com; s=arc-20160816; b=E4REYy5zxxuwP0ZDpzO+WsW6E+AoUmtp/UoZ+za8AV1Dg8ueCdtc8B/o984ab83mw+ sznLpPmU80/L0ztzKVVV21aGVgw3K4p3eRmsKTJDvY4oOavurJu0BuUYf06dAng7zuyv vNCBFJJEFthoY71juEjBKvzxvpmxgUFdvd7vGXsRLCzrhYRSM2UJXr6Sy85CLwhX2ArW G6xqboq/aF9/YKtLEiZFExMSFqMQlHDAZrGzL6BmEP2FfCal+PAvQXmKpQvro9xCJ+vL 0HURUh2iyAG2UkudyhzTrBHHJDzxYnhhn7G6S8t9R7ciW6bP/kxrLAVZYhXIaDdRmxDI BRSA== 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=vDJ5WNtcPMuzlshl2NOgjpaI557zyoRCX6907JN2H3U=; b=WePtORVB1Vp2yJMI8rBb4zb8+APk56N6PQDMvBsvqID5ilRW+GZU4zGQ0VVISbEog/ dLbQQrHDk9Hc3fMj1BNIsjrDHpZK2O0pEK9NtWPcAk7rfbJKjJ2JKB4zzHDmY8zhi0q0 zdyBDqPTKLLC+lr4BbVD8DZQ9ysmLjrtbjNMVZysj2H+ZI7aDSTqN2/3wqwyzCCYeiyN Efge7q0N7w1qjvyg5+iI8zv6L3XDoOg687IlJbKf3GbjZpLFHPmkWGmweOeCNoWI4lUN ptDnK9BvUe8nOr/j1Eo3/H6xnTcCmV1wL7A0gKoexyrR+h9wXsJf38HPN/bSPrdUVvjO Z4Zg== 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 v5si901212edf.320.2020.05.15.01.54.17; Fri, 15 May 2020 01:54:41 -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 S1727811AbgEOIuZ (ORCPT + 99 others); Fri, 15 May 2020 04:50:25 -0400 Received: from mx2.suse.de ([195.135.220.15]:41220 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727050AbgEOIuZ (ORCPT ); Fri, 15 May 2020 04:50:25 -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 BF189AC77; Fri, 15 May 2020 08:50:25 +0000 (UTC) Date: Fri, 15 May 2020 10:50:21 +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 , Sergey Senozhatsky , John Ogness , Petr Mladek Subject: [PATCH] printk/kdb: Redirect printk messages into kdb in any context Message-ID: <20200515085021.GS17734@linux-b0ei> References: <1589273314-12060-1-git-send-email-sumit.garg@linaro.org> <20200512142533.ta4uejwmq5gchtlx@holly.lan> <20200514084230.GO17734@linux-b0ei> 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 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. Reported-by: Sumit Garg Tested-by: Sumit Garg Signed-off-by: Petr Mladek --- Sending as proper patch for review. Adding Sergey into CC and John into CC. kernel/printk/printk.c | 14 +------------- kernel/printk/printk_safe.c | 7 +++++++ 2 files changed, 8 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..7ccb821d0bfe 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,12 @@ 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