Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp434702ybk; Wed, 20 May 2020 03:27:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkz5z7fSFdXpX5pN+pThxW/q/SMX66zsfQ0KJFQi31NKC021U9JXGesClsHAGgdOi564En X-Received: by 2002:a17:906:9493:: with SMTP id t19mr2926735ejx.461.1589970422371; Wed, 20 May 2020 03:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589970422; cv=none; d=google.com; s=arc-20160816; b=nIRKo86lKo2x9H38SYSJrwPGZOJirp7ADYrSEIO166h4u1OPRSkgoC9jAvVItNkOon ZSNy8ZDlo3GYpew8F+CIk6nI5h7s2JlJwsX3vBtXdwdeL0UIQ6ZxbHd8rfdJE9GX6FIH 3qz2vREhIxBTE9ebXbmkr7GiIkYfWDUZZCVqUTPFRdwE1e5RyGVkKmtGYAsn1K5toV8w /fx+Lo1Nlazg+zqBTTlpZRLkyQbztxXErWaLVVTar/pP0s+MjjNYspXjHuKKcK0Gcf3N Oqr9cQGkyrVFzqa7Tz6xxcfBGLF2nLQxAuz4O7l49WyJZpk4Z4OODrDU+XeCVDio96ZO PEGw== 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=juXBKxLygGCPgkWIXf/+YwcrHV935SF6Y8y3UcJwBsE=; b=OH9kU+IH4HKklxlawJl4Y+5w+VUCLXEp7NbiXUcV2C3yK2MuxCKJGFU0mcekMYYWLR UJO6uFT5DLRFDKxtb9wrCT22FR+ODBg4bKZlfpLNO1YXgoUtNGy0xuWvTjuBPWaMbn7c vX6gh0kHbfatZiA2LNwkhkd2wBKK7j9jgBpdPm7+8lIf7ysAXd8ULH1l59h4Ew3ogeDw 5098EOxmEchZEBhjaOWBXb4fTsEwlTrMbRBsvl48zCCaGR5vCKx7R74Ef+pIK9pUzND9 GmHlJHB56qrfAnjUhviH0cDFzFgKqQGrIcu6NALK7k6DyMcMHfWv/swThpr+QddYQOwJ jqGw== 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 bu28si1248854edb.189.2020.05.20.03.26.40; Wed, 20 May 2020 03:27:02 -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 S1726857AbgETKWh (ORCPT + 99 others); Wed, 20 May 2020 06:22:37 -0400 Received: from mx2.suse.de ([195.135.220.15]:36640 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726435AbgETKWg (ORCPT ); Wed, 20 May 2020 06:22:36 -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 29739AEC2; Wed, 20 May 2020 10:22:37 +0000 (UTC) Date: Wed, 20 May 2020 12:22:33 +0200 From: Petr Mladek To: Daniel Thompson Cc: Sergey Senozhatsky , Sumit Garg , Jason Wessel , Douglas Anderson , kgdb-bugreport@lists.sourceforge.net, Linux Kernel Mailing List , Arnd Bergmann , Andrew Morton , Peter Zijlstra , Steven Rostedt , John Ogness Subject: [PATCH v2] printk/kdb: Redirect printk messages into kdb in any context Message-ID: <20200520102233.GC3464@linux-b0ei> References: <20200512142533.ta4uejwmq5gchtlx@holly.lan> <20200514084230.GO17734@linux-b0ei> <20200515085021.GS17734@linux-b0ei> <20200515103308.GD42471@jagdpanzerIV.localdomain> <20200515134806.5cw4xxnxw7k3223l@holly.lan> <20200518092139.GK7340@linux-b0ei> <20200520042102.GA938@jagdpanzerIV.localdomain> <20200520093557.lwwxnhvgmacipdce@holly.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200520093557.lwwxnhvgmacipdce@holly.lan> 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 has to get messages on consoles even when the system is stopped. It uses kdb_printf() internally and calls console drivers on its own. It uses a hack to reuse an existing code. It sets "kdb_trap_printk" global variable to redirect even the normal printk() into the kdb_printf() variant. The variable "kdb_trap_printk" is checked in printk_default() and it is ignored when printk is redirected to printk_safe in NMI context. Solve this by moving the check into printk_func(). It is obvious that it is not fully safe. But it does not make things worse. The console drivers are already called in this context by db_printf() direct calls. Reported-by: Sumit Garg Tested-by: Sumit Garg Signed-off-by: Petr Mladek --- Changes in v2: + more detailed commit message 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