Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3917789imj; Tue, 12 Feb 2019 06:55:13 -0800 (PST) X-Google-Smtp-Source: AHgI3IbDdpI3pymc/hSH8WO/Q+4lZx61aeThrY0hJOr868E03jmhYWYG5LaI5ZY+xlKXnrvVQ0Vz X-Received: by 2002:a17:902:f81:: with SMTP id 1mr4323511plz.174.1549983313918; Tue, 12 Feb 2019 06:55:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549983313; cv=none; d=google.com; s=arc-20160816; b=furga6pkziuvt3VQO+fJlUzy/8+WdH+DodtYuWUvnpXdYMi2zmQt5yHKFxU/tjw1l1 gdWgkvzOJk+M7++ynttZOQLCicPRPWt4yr3qcdeSA5TzA2zDuVLwlJwz9KGV4MNHk1Fb v2o1Q/g3A/cRpKSne7S0njwLCQCe6e3Do1LKlF435f8kZRMNCH3C9X665UF82bHG6GZ2 1Iyy3mol65FTgvqHrmTddN2fQgvrgJ6N5RrONEhFARzWSyfdBpvrJO2NLlXMzhzWqRlL FQ7mN8HsZjksvNDHQl0eJTQ0+Fu/ADx1+OJ5clFJykuXccVyTPlkUDPwd98ZWyUytRrj Ob8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=KFWvVg3JpkzL2+op1vBa0QSL8kiYMs9SmT2YBAb3OlQ=; b=KMLKinupZ7JRlplYqzbhozpqHkb34gG9NTql8nfLYK2AUKmX1pvrbljmtVn0caNPxX PZMaua+6gWcIy4mGN6Nk+8g9gU2XjAwRGJMD5ImFVPM5gq2wo76QS7vzcYUFXm+iGlry 56/tIThoGpNyTXCrqUq9a8Nk4do4kwj85GOL/nx7/MChht8JjPMGQOE8BdDR8vlnF9wL nXtGl5ElTsHQ4Jeo104JZogQDo+YpnJbeZDy4XxHqk4uRo5ushmG5rjhDaePXO9oZdXR ssSO2Ew5UJB4vNKlS4WjPJB18lNnmbBuHS99gyNcVssONUH9tmZI+VlB47T6RYlzq0rO LOQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w6si13135474plp.429.2019.02.12.06.54.57; Tue, 12 Feb 2019 06:55:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728914AbfBLOcY (ORCPT + 99 others); Tue, 12 Feb 2019 09:32:24 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:43770 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730256AbfBLOae (ORCPT ); Tue, 12 Feb 2019 09:30:34 -0500 Received: from [5.158.153.53] (helo=linux.lab.linutronix.de.) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1gtZ4n-0005Af-MY; Tue, 12 Feb 2019 15:30:21 +0100 From: John Ogness To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Daniel Wang , Andrew Morton , Linus Torvalds , Greg Kroah-Hartman , Alan Cox , Jiri Slaby , Peter Feiner , linux-serial@vger.kernel.org, Sergey Senozhatsky Subject: [RFC PATCH v1 15/25] printk: print history for new consoles Date: Tue, 12 Feb 2019 15:29:53 +0100 Message-Id: <20190212143003.48446-16-john.ogness@linutronix.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190212143003.48446-1-john.ogness@linutronix.de> References: <20190212143003.48446-1-john.ogness@linutronix.de> X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When new consoles register, they currently print how many messages they have missed. However, many (or all) of those messages may still be in the ring buffer. Add functionality to print as much of the history as available. This is a clean replacement of the old exclusive console hack. Signed-off-by: John Ogness --- include/linux/console.h | 1 + kernel/printk/printk.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/include/linux/console.h b/include/linux/console.h index 7fa06a058339..633fb741e871 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -154,6 +154,7 @@ struct console { short index; int cflag; unsigned long printk_seq; + int wrote_history; void *data; struct console *next; }; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 897219f34cab..6c875abd7b17 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1506,6 +1506,77 @@ static void format_text(struct printk_log *msg, u64 seq, } } +static void printk_write_history(struct console *con, u64 master_seq) +{ + struct prb_iterator iter; + bool time = printk_time; + static char *ext_text; + static char *text; + static char *buf; + u64 seq; + + ext_text = kmalloc(CONSOLE_EXT_LOG_MAX, GFP_KERNEL); + text = kmalloc(PRINTK_SPRINT_MAX, GFP_KERNEL); + buf = kmalloc(PRINTK_RECORD_MAX, GFP_KERNEL); + if (!ext_text || !text || !buf) + return; + + if (!(con->flags & CON_ENABLED)) + goto out; + + if (!con->write) + goto out; + + if (!cpu_online(raw_smp_processor_id()) && + !(con->flags & CON_ANYTIME)) + goto out; + + prb_iter_init(&iter, &printk_rb, NULL); + + for (;;) { + struct printk_log *msg; + size_t ext_len; + size_t len; + int ret; + + ret = prb_iter_next(&iter, buf, PRINTK_RECORD_MAX, &seq); + if (ret == 0) { + break; + } else if (ret < 0) { + prb_iter_init(&iter, &printk_rb, NULL); + continue; + } + + if (seq > master_seq) + break; + + con->printk_seq++; + if (con->printk_seq < seq) { + print_console_dropped(con, seq - con->printk_seq); + con->printk_seq = seq; + } + + msg = (struct printk_log *)buf; + format_text(msg, master_seq, ext_text, &ext_len, text, + &len, time); + + if (len == 0 && ext_len == 0) + continue; + + if (con->flags & CON_EXTENDED) + con->write(con, ext_text, ext_len); + else + con->write(con, text, len); + + printk_delay(msg->level); + } +out: + con->wrote_history = 1; + kfree(ext_text); + kfree(text); + kfree(buf); +} + /* * Call the console drivers, asking them to write out * log_buf[start] to log_buf[end - 1]. @@ -1524,6 +1595,10 @@ static void call_console_drivers(u64 seq, const char *ext_text, size_t ext_len, for_each_console(con) { if (!(con->flags & CON_ENABLED)) continue; + if (!con->wrote_history) { + printk_write_history(con, seq); + continue; + } if (!con->write) continue; if (!cpu_online(raw_smp_processor_id()) && -- 2.11.0