From patchwork Wed Jan 7 15:31:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 42830 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f199.google.com (mail-we0-f199.google.com [74.125.82.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 03A3F2055F for ; Wed, 7 Jan 2015 15:31:49 +0000 (UTC) Received: by mail-we0-f199.google.com with SMTP id k11sf795970wes.6 for ; Wed, 07 Jan 2015 07:31:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=xNegA0v4b/nIZfXn/uzSLceAED9XU0+hrCx14C6x0Ys=; b=dyv4GWBWIuHttzT2+Fto5+8e+xeAAucip1flT5XyhNr1DaxNi6MycW52BFLpqA212v bR32gcbmtXCOFq/EMt6+PP/BvGjDuPzDpRN0wv+4KvU2H5vVP3doTv0NYPbXgNllHnMF l971InkXKykMXVT+aUyVErqlZWiDcXVHMKdLv45RifspFUjy+icbIQhiQNDJdblcKTsq 06QfSl4uhPcgA7uJOr4ECTyZ5nQipL8Oj16ZpM2wx8gMJfV7LNmQuapG+8Zb9NMdRnHi CoKjJaUzq7NKstEvd93/rQf5hyCNzjR+RmQT49RCV0almGy76wBA8sXiqTcQcNIIRJ2S Xaiw== X-Gm-Message-State: ALoCoQkS0piHSGvQUZoFzKiXvv6FUryiz3QAwQa89b+L8dJb4+1xUGcNCVNnIRDnI5fffl4Wec9e X-Received: by 10.112.219.199 with SMTP id pq7mr381346lbc.9.1420644708292; Wed, 07 Jan 2015 07:31:48 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.202 with SMTP id ao10ls200164lac.59.gmail; Wed, 07 Jan 2015 07:31:48 -0800 (PST) X-Received: by 10.153.11.170 with SMTP id ej10mr5644969lad.24.1420644708124; Wed, 07 Jan 2015 07:31:48 -0800 (PST) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id pr6si3510056lbb.30.2015.01.07.07.31.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 07 Jan 2015 07:31:47 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by mail-lb0-f170.google.com with SMTP id 10so1292911lbg.1 for ; Wed, 07 Jan 2015 07:31:47 -0800 (PST) X-Received: by 10.152.7.229 with SMTP id m5mr5637168laa.80.1420644707802; Wed, 07 Jan 2015 07:31:47 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.9.200 with SMTP id c8csp1516875lbb; Wed, 7 Jan 2015 07:31:47 -0800 (PST) X-Received: by 10.180.160.144 with SMTP id xk16mr50183694wib.12.1420644707004; Wed, 07 Jan 2015 07:31:47 -0800 (PST) Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com. [209.85.212.176]) by mx.google.com with ESMTPS id t7si32924592wiz.25.2015.01.07.07.31.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 07 Jan 2015 07:31:46 -0800 (PST) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.212.176 as permitted sender) client-ip=209.85.212.176; Received: by mail-wi0-f176.google.com with SMTP id ex7so7745446wid.9 for ; Wed, 07 Jan 2015 07:31:46 -0800 (PST) X-Received: by 10.180.208.79 with SMTP id mc15mr50134705wic.34.1420644706586; Wed, 07 Jan 2015 07:31:46 -0800 (PST) Received: from sundance.lan (cpc4-aztw19-0-0-cust157.18-1.cable.virginm.net. [82.33.25.158]) by mx.google.com with ESMTPSA id t12sm2536717wju.19.2015.01.07.07.31.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Jan 2015 07:31:45 -0800 (PST) From: Daniel Thompson To: Jason Wessel Cc: Daniel Thompson , linux-kernel@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, Andrew Morton , Ingo Molnar , patches@linaro.org, linaro-kernel@lists.linaro.org, John Stultz , Sumit Semwal , Joe Perches , stable@vger.kernel.org Subject: [RESEND PATCH v3 3.19-rc2] kdb: Avoid printing KERN_ levels to consoles Date: Wed, 7 Jan 2015 15:31:25 +0000 Message-Id: <1420644685-1973-1-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1415386070-18850-1-git-send-email-daniel.thompson@linaro.org> References: <1415386070-18850-1-git-send-email-daniel.thompson@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.thompson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Currently when kdb traps printk messages then the raw log level prefix (consisting of '\001' followed by a numeral) does not get stripped off before the message is issued to the various I/O handlers supported by kdb. This causes annoying visual noise as well as causing problems grepping for ^. It is also a change of behaviour compared to normal usage of printk() usage. For example -h ends up with different output to that of kdb's "sr h". This patch addresses the problem by stripping log levels from messages before they are issued to the I/O handlers. printk() which can also act as an i/o handler in some cases is special cased; if the caller provided a log level then the prefix will be preserved when sent to printk(). The addition of non-printable characters to the output of kdb commands is a regression, albeit and extremely elderly one, introduced by commit 04d2c8c83d0e ("printk: convert the format for KERN_ to a 2 byte pattern"). Note also that this patch does *not* restore the original behaviour from v3.5. Instead it makes printk() from within a kdb command display the message without any prefix (i.e. like printk() normally does). Signed-off-by: Daniel Thompson Cc: Jason Wessel Cc: Joe Perches Cc: stable@vger.kernel.org --- Notes: This patch is tested both on arm (kgdboc=ttyAMA0) and x86_64 (kgdboc=kdb,ttyS0). v3: * Introduce enum kdb_msgsrc to further improve the fidelity of messages that hit the log (Joe Perches). The output of "sr h" benefits a lot from this change. v2: * Adopt printk_skip_level() to skip the header characters (Joe Perches). * Update patch description to describe the addition of non-printable characters to kdb output as a regression and Cc: stable@ (Joe Perches). include/linux/kdb.h | 8 +++++++- kernel/debug/kdb/kdb_io.c | 22 +++++++++++++--------- kernel/printk/printk.c | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) -- 1.9.3 diff --git a/include/linux/kdb.h b/include/linux/kdb.h index 290db1269c4c..204901ae003a 100644 --- a/include/linux/kdb.h +++ b/include/linux/kdb.h @@ -112,8 +112,14 @@ typedef enum { KDB_REASON_SYSTEM_NMI, /* In NMI due to SYSTEM cmd; regs valid */ } kdb_reason_t; +enum kdb_msgsrc { + KDB_MSGSRC_INTERNAL, /* direct call to kdb_printf() */ + KDB_MSGSRC_PRINTK, /* trapped from printk() */ +}; + extern int kdb_trap_printk; -extern __printf(1, 0) int vkdb_printf(const char *fmt, va_list args); +extern __printf(2, 0) int vkdb_printf(enum kdb_msgsrc src, const char *fmt, + va_list args); extern __printf(1, 2) int kdb_printf(const char *, ...); typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...); diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 7c70812caea5..a550afb99ebe 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -548,7 +548,7 @@ static int kdb_search_string(char *searched, char *searchfor) return 0; } -int vkdb_printf(const char *fmt, va_list ap) +int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) { int diag; int linecount; @@ -691,19 +691,20 @@ kdb_printit: * Write to all consoles. */ retlen = strlen(kdb_buffer); + cp = (char *) printk_skip_level(kdb_buffer); if (!dbg_kdb_mode && kgdb_connected) { - gdbstub_msg_write(kdb_buffer, retlen); + gdbstub_msg_write(cp, retlen - (cp - kdb_buffer)); } else { if (dbg_io_ops && !dbg_io_ops->is_console) { - len = retlen; - cp = kdb_buffer; + len = retlen - (cp - kdb_buffer); + cp2 = cp; while (len--) { - dbg_io_ops->write_char(*cp); - cp++; + dbg_io_ops->write_char(*cp2); + cp2++; } } while (c) { - c->write(c, kdb_buffer, retlen); + c->write(c, cp, retlen - (cp - kdb_buffer)); touch_nmi_watchdog(); c = c->next; } @@ -711,7 +712,10 @@ kdb_printit: if (logging) { saved_loglevel = console_loglevel; console_loglevel = CONSOLE_LOGLEVEL_SILENT; - printk(KERN_INFO "%s", kdb_buffer); + if (printk_get_level(kdb_buffer) || src == KDB_MSGSRC_PRINTK) + printk("%s", kdb_buffer); + else + pr_info("%s", kdb_buffer); } if (KDB_STATE(PAGER)) { @@ -844,7 +848,7 @@ int kdb_printf(const char *fmt, ...) int r; va_start(ap, fmt); - r = vkdb_printf(fmt, ap); + r = vkdb_printf(KDB_MSGSRC_INTERNAL, fmt, ap); va_end(ap); return r; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 02d6b6d28796..fae29e3ffbf0 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1811,7 +1811,7 @@ int vprintk_default(const char *fmt, va_list args) #ifdef CONFIG_KGDB_KDB if (unlikely(kdb_trap_printk)) { - r = vkdb_printf(fmt, args); + r = vkdb_printf(KDB_MSGSRC_PRINTK, fmt, args); return r; } #endif