Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp6205922imm; Sat, 19 May 2018 20:49:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqw1FxGwqytHRu/Av90cyO5ww99rhDHBdIb9cdxcZKQXxSzqIsA9rV4UeZudhhrpnoS4MeQ X-Received: by 2002:a63:701b:: with SMTP id l27-v6mr2040936pgc.145.1526788168664; Sat, 19 May 2018 20:49:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526788168; cv=none; d=google.com; s=arc-20160816; b=VhQeemyJMdwGN6Qzt36iqr69Tdjn3f5NtwZt0N1muEQqAJOnPkHbl/tD1DDUn3O0rS znET+atw5pc8wP2Qr26EUXCdjHCHmygnmiSDHhM4elAlzg1tgLmtSxINqKZzIBWCqkE5 af+TeHv08MZ2Ezt877OHHrn3RGnmqQGoKAHZEO1fwvctcB96ykzy7hOg3VNWrovxOUWF AhBoIKXfTlLyOVIyryERcedVAqqlzqkNpAd8RqjIYI/qfvP0NVnlLJLcHNdwlAAWf1ct iGtoWWwloEhjcLIZ70zxbntfno6CjsfUdidlbwttDVCo1+JkH9egrDvkHeNiO1eQTbfk sGww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=MeS4HsjtZUCwHHSwFB4w5HWMSW9K/msrFQ2vooDEbWs=; b=Hspcb3WZWzvXDqCSjoQFI3Oqtk19BCnhnsFqAWuuIlYEtOLh2mXLPC8JVHuKZpuKwf yV2uZjKpl7/XedPTe5+UAbiPDtqHjY4S3cecOSD7RfqGzTbd/4Mj4nvEvXotZkiiKCKO 9O0uE5UJVbDRg3RTTy7vAYwgx71jPG/Q1t5XXkvS+Uwx/gdTByWbRpU1/Enixv14ggeN TZ03Nz24948iGJ6aDrlHtGxe3ZtNMGtMyfrHHG3FtDfreF0Qcq+8/wfPDzviWVnFMve2 XyX6kvmH/NOVYo5WxbR/VM+HwlU+IVlpWIX1QrmWN4k9DImIGEMSkgUmNoCEpSSAMQbv d/Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=RJp/VNE0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cisco.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bg6-v6si10328458plb.243.2018.05.19.20.49.14; Sat, 19 May 2018 20:49:28 -0700 (PDT) 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; dkim=pass header.i=@cisco.com header.s=iport header.b=RJp/VNE0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cisco.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752535AbeETDtE (ORCPT + 99 others); Sat, 19 May 2018 23:49:04 -0400 Received: from alln-iport-7.cisco.com ([173.37.142.94]:13671 "EHLO alln-iport-7.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752459AbeETDtB (ORCPT ); Sat, 19 May 2018 23:49:01 -0400 X-Greylist: delayed 560 seconds by postgrey-1.27 at vger.kernel.org; Sat, 19 May 2018 23:49:01 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=3494; q=dns/txt; s=iport; t=1526788141; x=1527997741; h=date:from:to:cc:subject:message-id:mime-version; bh=9ryFrHzak8EXasXSRbP2uruoLEgFwRWy6ePXC2KZ3gM=; b=RJp/VNE0DBLMZDhvSdyjyzKtkoP2sPULz8ToHvWsvcZ+G6Kr+5FUvW8P wUYwj6eQIEknsKhoBMHXROif/JHWw7d1yi6rEHE5CszfMwlNfSkes+v19 C93EP57k1Ox5N+zXrSdFf6StcHD801ik333sE6qD3WhzUAn04jsB/s/f1 4=; X-IronPort-AV: E=Sophos;i="5.49,421,1520899200"; d="scan'208";a="116550154" Received: from rcdn-core-2.cisco.com ([173.37.93.153]) by alln-iport-7.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 May 2018 03:39:41 +0000 Received: from sjc-ads-587.cisco.com (sjc-ads-587.cisco.com [171.70.56.29]) by rcdn-core-2.cisco.com (8.14.5/8.14.5) with ESMTP id w4K3deKh016899; Sun, 20 May 2018 03:39:40 GMT Received: by sjc-ads-587.cisco.com (Postfix, from userid 292853) id 8B302E89; Sat, 19 May 2018 20:39:40 -0700 (PDT) Date: Sat, 19 May 2018 20:39:40 -0700 From: Stefan M Schaeckeler To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Cc: sschaeck@cisco.com Subject: [PATCH] mtd: mtdoops: optionally dump boottime Message-ID: <20180520033940.GA35444@sjc-ads-587.cisco.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Optionally dump boottime on the mtd device in the form of <0>[ 0.000000] Boot time mm/dd/yyyy hh:mm:ss Time-stamps of oops messages are in seconds since boottime. Recording also the boottime helps correlating oopses with other events having occured at the same time. This correlation will be otherwise lost after (multiple) reboots. Signed-off-by: Stefan M Schaeckeler --- drivers/mtd/mtdoops.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index 9f25111..11f93aa 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -54,6 +54,11 @@ module_param(dump_oops, int, 0600); MODULE_PARM_DESC(dump_oops, "set to 1 to dump oopses, 0 to only dump panics (default 1)"); +static bool dump_boottime = false; +module_param(dump_boottime, bool, 0400); +MODULE_PARM_DESC(dump_boottime, + "set to 1 to dump boottime, 0 to disable (default 0)"); + static struct mtdoops_context { struct kmsg_dumper dump; @@ -69,6 +74,10 @@ static struct mtdoops_context { void *oops_buf; } oops_cxt; +/* fake kernel message syslog level and monotonic timestamp */ +#define boottime_prefix "<0>[ 0.000000] Boot time " +static char boottime[100] = {0}; + static void mark_page_used(struct mtdoops_context *cxt, int page) { set_bit(page, cxt->oops_page_used); @@ -285,13 +294,17 @@ static void mtdoops_do_dump(struct kmsg_dumper *dumper, { struct mtdoops_context *cxt = container_of(dumper, struct mtdoops_context, dump); + u8 boot_len = strlen(boottime); /* 0 if dump_boottime is not set */ /* Only dump oopses if dump_oops is set */ if (reason == KMSG_DUMP_OOPS && !dump_oops) return; - kmsg_dump_get_buffer(dumper, true, cxt->oops_buf + MTDOOPS_HEADER_SIZE, - record_size - MTDOOPS_HEADER_SIZE, NULL); + strncpy(cxt->oops_buf + MTDOOPS_HEADER_SIZE, boottime, boot_len); + + kmsg_dump_get_buffer(dumper, true, cxt->oops_buf + MTDOOPS_HEADER_SIZE + + boot_len, record_size - (MTDOOPS_HEADER_SIZE + + boot_len), NULL); /* Panics must be written immediately */ if (reason != KMSG_DUMP_OOPS) @@ -350,7 +363,13 @@ static void mtdoops_notify_add(struct mtd_info *mtd) cxt->mtd = mtd; cxt->oops_pages = (int)mtd->size / record_size; find_next_position(cxt); - printk(KERN_INFO "mtdoops: Attached to MTD device %d\n", mtd->index); + if (dump_boottime) { + printk(KERN_INFO "mtdoops: Attached to MTD device %d " + "dumping boottime\n", mtd->index); + } else { + printk(KERN_INFO "mtdoops: Attached to MTD device %d " + "not dumping boottime\n", mtd->index); + } } static void mtdoops_notify_remove(struct mtd_info *mtd) @@ -379,6 +398,19 @@ static int __init mtdoops_init(void) struct mtdoops_context *cxt = &oops_cxt; int mtd_index; char *endp; + struct timespec64 bt; + struct tm tm_val; + + if (dump_boottime) { + /* Precompute boot time ahead of an oops */ + getboottime64(&bt); + time_to_tm(bt.tv_sec, 0, &tm_val); + + snprintf(boottime, sizeof(boottime), + boottime_prefix "%02d/%02d/%4d %02d:%02d:%02d\n", + tm_val.tm_mon + 1, tm_val.tm_mday, tm_val.tm_year + 1900, + tm_val.tm_hour, tm_val.tm_min, tm_val.tm_sec); + } if (strlen(mtddev) == 0) { printk(KERN_ERR "mtdoops: mtd device (mtddev=name/number) must be supplied\n"); -- 2.10.3.dirty