From nobody Mon May 11 04:12:56 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A653C433F5 for ; Fri, 15 Apr 2022 00:14:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347938AbiDOAQg (ORCPT ); Thu, 14 Apr 2022 20:16:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347921AbiDOAQc (ORCPT ); Thu, 14 Apr 2022 20:16:32 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 254B974846 for ; Thu, 14 Apr 2022 17:14:05 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id h82-20020a25d055000000b00641d2fd5f3fso5232948ybg.11 for ; Thu, 14 Apr 2022 17:14:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=XrMml7qKUkK/vfRO+Yh9HesyPHxDc4iM4I0XZDhBTs0=; b=NOCt70nhWy1emhIvsudKXkm4pJsO2JlwqpGNAW593FYdxY46MUU9gMxIC1thIfmwFq 2yJTcFGDzWQLAn1FLyW19CMYYSsnhqt4HASAriTHBwL5szrjXnClfPOhyi1ozVCQ/YC+ cN896HhGn0hf55j8WigJsjtz3EBg8p0sAwhg9rJsEd2rneuZ2gbzhOyCIADBu5eN5/j8 Yd8JxQlSC8Q0VVyGq1jqAoE5UH2XrRzFbcHO08wxLp2xhklKU8jW6cvU0hWfqXOyTynp ltgIvcpB7DLWiXOJJsQBVKG1MZ3XRsLZrghodhDc8qNSCvH/o+HnDlz2LPIjPFm9XYHe d9EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=XrMml7qKUkK/vfRO+Yh9HesyPHxDc4iM4I0XZDhBTs0=; b=EAVEsntTD6yk75DtWoAivcWJ7abwH1zKoTwiRNSUVlhgGGglzZtBZx6G7K0534bFne FBs7F2My5b0Lt0ZqLf2hh/cJVJNqzfnPfmtBeo2R/zFEiMDQn5qFTVdLZRA4VhzHHqd3 1woHJOks+8i65+b9esdkX60ePNFL4/MeqzRw3P7LCMsDHp+jY1w5lnv5mIFzl+p70gp+ +f8l16HQL0pdWBGcMwSBWYh8P7VL6ptHx8rp5xDhBcR8YTHQ206XLS2UeaPCbbmPoVy4 RfiCwV8cwkoXp0t+xFUmWLed4Q8tyEgNRVdK1OB9buVm6otU7L9lno0OzBK4KI2Ilw74 Kr6Q== X-Gm-Message-State: AOAM5313yi4Lh1gXaeP8gkrLweCoQoSXXAtjDAyWjvAUK8ehgzsFsQir AcICbuWK+YdEK7RU8Gy9XuKu9AVKxbdw X-Google-Smtp-Source: ABdhPJw6OIlBScgMItG1ez9NzljktXTkxPDeFx6Lr0saWhpnJFjwgeDN+52OvPjR0WJONlvR/kqFmQ7v1Pyg X-Received: from pigloo.svl.corp.google.com ([2620:15c:2c5:13:7d77:8cae:9dfe:95c]) (user=jmeurin job=sendgmr) by 2002:a5b:8c8:0:b0:641:e8de:a6f4 with SMTP id w8-20020a5b08c8000000b00641e8dea6f4mr3814847ybq.533.1649981644388; Thu, 14 Apr 2022 17:14:04 -0700 (PDT) Date: Thu, 14 Apr 2022 17:13:19 -0700 In-Reply-To: <20220415001321.252848-1-jmeurin@google.com> Message-Id: <20220415001321.252848-2-jmeurin@google.com> Mime-Version: 1.0 References: <20220207163409.19c3bc4c@xps13> <20220415001321.252848-1-jmeurin@google.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog Subject: [PATCH v3 1/3] mtd: mtdoops: Fix the size of the header read buffer. From: Jean-Marc Eurin To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Jean-Marc Eurin Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The read buffer size depends on the MTDOOPS_HEADER_SIZE. Tested: Changed the header size, it doesn't panic, header is still read/written correctly. Signed-off-by: Jean-Marc Eurin --- drivers/mtd/mtdoops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index 227df24387df..09a26747f490 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -223,7 +223,7 @@ static void find_next_position(struct mtdoops_context *= cxt) { struct mtd_info *mtd =3D cxt->mtd; int ret, page, maxpos =3D 0; - u32 count[2], maxcount =3D 0xffffffff; + u32 count[MTDOOPS_HEADER_SIZE/sizeof(u32)], maxcount =3D 0xffffffff; size_t retlen; =20 for (page =3D 0; page < cxt->oops_pages; page++) { --=20 2.36.0.rc0.470.gd361397f0d-goog From nobody Mon May 11 04:12:56 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA99EC433EF for ; Fri, 15 Apr 2022 00:14:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347961AbiDOAQk (ORCPT ); Thu, 14 Apr 2022 20:16:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347921AbiDOAQg (ORCPT ); Thu, 14 Apr 2022 20:16:36 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9200A75C05 for ; Thu, 14 Apr 2022 17:14:10 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id f14-20020a5b0c0e000000b00641d371d9c8so5188870ybq.0 for ; Thu, 14 Apr 2022 17:14:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=j+3tJjiCf78FCu6r+r65AdoN2KDRFod1PmLEraQ3coY=; b=Caezxcdf/vNIhgSMCI6hmDKw41eI/IzIh12p3HqrzYy5BdmkRG+GsLLOhcXFMGq52d 3KFCwvz/AoUPz+l3+sm8mXAf5PozArFFzJ4m+Zc4phpLh7pM4DEkdrY2z4N2lzvh/I91 oqthovmJ955Vr9DosTQHL4tWD3y1s/m95U8l5w8+091pwxD0ZzbZKXcdAP6fXbDxewqc 5EGzuIT/q6kTl0dYwGeln0DNf7bQwGvt4r2mSNmCfYam7HwhcRMmxc/a+nt50UvKFHZ5 ydwwD0u3cRCLONs7Ry1zb1hgIqQ1HJ/4AbfBZ59BgN0aWbxiebdJ3XQCMUYtmKhs64ZX oKBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=j+3tJjiCf78FCu6r+r65AdoN2KDRFod1PmLEraQ3coY=; b=1kNWTCc5srICC7eO1yP97MZoePRA5GbrOWQ1UcrdZ7b7NnWwbhAIThuAXvBTvp7JB5 OKwxW1inKTnOzFMSsu53bHs1FZGsRIusfAMD2PWKs0yiVgcyGNQ5ppBS1YHT0JM1OSEI yEyMguq6hldTQa+LnHEEdIAtko/1qvlKlm+3JtvHnd3+BhU/fqV1PdXOih77XI29yTpl Yuec2DMz+5RoyzdzcgJmTZjMlu3+xi8+xtyRD2M6OT2vXz7RchiWwWvQJFW16hfc6z5H ZB/v7dhnu5wIrKFLjUmUVx4DoxsswOjGwkfGhHANEsj0MrrwrIpe8IflBUbVK2/62/+h 9kGw== X-Gm-Message-State: AOAM532RKy2aqMK+IqnfkrY2RClw5m2uKHJZSfb+jjSXa9qYF73m546U p8qD90ST969iq8tgHzNiKcnWO6dtCy57 X-Google-Smtp-Source: ABdhPJyvaWs/ucoEhalwvhW30u3+I0YIcXElUI1onpLQMvainyojc+8EwtVbGmuj+WqtK6/BNgz7CR/ycm13 X-Received: from pigloo.svl.corp.google.com ([2620:15c:2c5:13:7d77:8cae:9dfe:95c]) (user=jmeurin job=sendgmr) by 2002:a05:6902:72a:b0:641:283b:3946 with SMTP id l10-20020a056902072a00b00641283b3946mr3679439ybt.469.1649981649814; Thu, 14 Apr 2022 17:14:09 -0700 (PDT) Date: Thu, 14 Apr 2022 17:13:20 -0700 In-Reply-To: <20220415001321.252848-1-jmeurin@google.com> Message-Id: <20220415001321.252848-3-jmeurin@google.com> Mime-Version: 1.0 References: <20220207163409.19c3bc4c@xps13> <20220415001321.252848-1-jmeurin@google.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog Subject: [PATCH v3 2/3] mtd: mtdoops: Create a header structure for the saved mtdoops. From: Jean-Marc Eurin To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Jean-Marc Eurin , kernel test robot Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Create a dump header to enable the addition of fields without having to modify the rest of the code. Reported-by: kernel test robot Signed-off-by: Jean-Marc Eurin --- drivers/mtd/mtdoops.c | 55 +++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index 09a26747f490..f80468ef31c6 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -22,9 +22,6 @@ /* Maximum MTD partition size */ #define MTDOOPS_MAX_MTD_SIZE (8 * 1024 * 1024) =20 -#define MTDOOPS_KERNMSG_MAGIC 0x5d005d00 -#define MTDOOPS_HEADER_SIZE 8 - static unsigned long record_size =3D 4096; module_param(record_size, ulong, 0400); MODULE_PARM_DESC(record_size, @@ -40,6 +37,13 @@ module_param(dump_oops, int, 0600); MODULE_PARM_DESC(dump_oops, "set to 1 to dump oopses, 0 to only dump panics (default 1)"); =20 +#define MTDOOPS_KERNMSG_MAGIC 0x5d005d00 + +struct mtdoops_hdr { + u32 seq; + u32 magic; +} __packed; + static struct mtdoops_context { struct kmsg_dumper dump; =20 @@ -178,16 +182,16 @@ static void mtdoops_write(struct mtdoops_context *cxt= , int panic) { struct mtd_info *mtd =3D cxt->mtd; size_t retlen; - u32 *hdr; + struct mtdoops_hdr *hdr; int ret; =20 if (test_and_set_bit(0, &cxt->oops_buf_busy)) return; =20 /* Add mtdoops header to the buffer */ - hdr =3D cxt->oops_buf; - hdr[0] =3D cxt->nextcount; - hdr[1] =3D MTDOOPS_KERNMSG_MAGIC; + hdr =3D (struct mtdoops_hdr *)cxt->oops_buf; + hdr->seq =3D cxt->nextcount; + hdr->magic =3D MTDOOPS_KERNMSG_MAGIC; =20 if (panic) { ret =3D mtd_panic_write(mtd, cxt->nextpage * record_size, @@ -222,8 +226,9 @@ static void mtdoops_workfunc_write(struct work_struct *= work) static void find_next_position(struct mtdoops_context *cxt) { struct mtd_info *mtd =3D cxt->mtd; + struct mtdoops_hdr hdr; int ret, page, maxpos =3D 0; - u32 count[MTDOOPS_HEADER_SIZE/sizeof(u32)], maxcount =3D 0xffffffff; + u32 maxcount =3D 0xffffffff; size_t retlen; =20 for (page =3D 0; page < cxt->oops_pages; page++) { @@ -231,32 +236,31 @@ static void find_next_position(struct mtdoops_context= *cxt) continue; /* Assume the page is used */ mark_page_used(cxt, page); - ret =3D mtd_read(mtd, page * record_size, MTDOOPS_HEADER_SIZE, - &retlen, (u_char *)&count[0]); - if (retlen !=3D MTDOOPS_HEADER_SIZE || + ret =3D mtd_read(mtd, page * record_size, sizeof(hdr), + &retlen, (u_char *)&hdr); + if (retlen !=3D sizeof(hdr) || (ret < 0 && !mtd_is_bitflip(ret))) { - printk(KERN_ERR "mtdoops: read failure at %ld (%td of %d read), err %d\= n", - page * record_size, retlen, - MTDOOPS_HEADER_SIZE, ret); + printk(KERN_ERR "mtdoops: read failure at %ld (%td of %ld read), err %d= \n", + page * record_size, retlen, sizeof(hdr), ret); continue; } =20 - if (count[0] =3D=3D 0xffffffff && count[1] =3D=3D 0xffffffff) + if (hdr.seq =3D=3D 0xffffffff && hdr.magic =3D=3D 0xffffffff) mark_page_unused(cxt, page); - if (count[0] =3D=3D 0xffffffff || count[1] !=3D MTDOOPS_KERNMSG_MAGIC) + if (hdr.seq =3D=3D 0xffffffff || hdr.magic !=3D MTDOOPS_KERNMSG_MAGIC) continue; if (maxcount =3D=3D 0xffffffff) { - maxcount =3D count[0]; + maxcount =3D hdr.seq; maxpos =3D page; - } else if (count[0] < 0x40000000 && maxcount > 0xc0000000) { - maxcount =3D count[0]; + } else if (hdr.seq < 0x40000000 && maxcount > 0xc0000000) { + maxcount =3D hdr.seq; maxpos =3D page; - } else if (count[0] > maxcount && count[0] < 0xc0000000) { - maxcount =3D count[0]; + } else if (hdr.seq > maxcount && hdr.seq < 0xc0000000) { + maxcount =3D hdr.seq; maxpos =3D page; - } else if (count[0] > maxcount && count[0] > 0xc0000000 + } else if (hdr.seq > maxcount && hdr.seq > 0xc0000000 && maxcount > 0x80000000) { - maxcount =3D count[0]; + maxcount =3D hdr.seq; maxpos =3D page; } } @@ -287,8 +291,9 @@ static void mtdoops_do_dump(struct kmsg_dumper *dumper, =20 if (test_and_set_bit(0, &cxt->oops_buf_busy)) return; - kmsg_dump_get_buffer(&iter, true, cxt->oops_buf + MTDOOPS_HEADER_SIZE, - record_size - MTDOOPS_HEADER_SIZE, NULL); + kmsg_dump_get_buffer(&iter, true, + cxt->oops_buf + sizeof(struct mtdoops_hdr), + record_size - sizeof(struct mtdoops_hdr), NULL); clear_bit(0, &cxt->oops_buf_busy); =20 if (reason !=3D KMSG_DUMP_OOPS) { --=20 2.36.0.rc0.470.gd361397f0d-goog From nobody Mon May 11 04:12:56 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65897C433FE for ; Mon, 25 Apr 2022 16:10:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243187AbiDYQND (ORCPT ); Mon, 25 Apr 2022 12:13:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243245AbiDYQMk (ORCPT ); Mon, 25 Apr 2022 12:12:40 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 767193D4A7 for ; Mon, 25 Apr 2022 09:09:36 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id u9-20020a25b7c9000000b0064636cb9078so6209128ybj.1 for ; Mon, 25 Apr 2022 09:09:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=q8a8wJvEklAmCtCpSgW2FIcat+OGKagtU2H8hFgsok4=; b=La2lXw+CyTzmORqrvTtza6E1VmcDhBtZSejdp92C/j6nD1VzVby+OOi9gtDlyazQiq o+q7tinZHsfN+YfYPjeA0tfcepEpmXSDauc46eZyT+nZTh+kTgzyShblLGYKPNv8jofB KkG9nyuHtIbEyLZwe13V8j63/eXJE1wqviEBwxau4ZtGI1b+P0ci9a1cyZTJZXeJ9Cz6 XRolYviQLodpgkF6SJrjzpPTHkT//T6cq4RFBWdCzSHj94feeI8BGETpYBgMh8P/T3M8 rhp5X7/tV4cWACImM/yc90HCjkAzGPoVt2tAp/F11BETzg5AhDhkm5mj5JFXme/FqWHz 60tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=q8a8wJvEklAmCtCpSgW2FIcat+OGKagtU2H8hFgsok4=; b=arXo9Vd0OJszbFq50oGY/hCOcZGs1BqBy0JF5kh9+RXAX5UwrqoGDtQ3AZAS/CLRoh r5JCk7A1pm0XarAgH7IBeot8wCHVDsbQAK27x2Awjz/8QfV6w9eBA3V33FH5p9LSJ81Y s0iRn71piouiIXMtJRLHeeb3oFViJ6lM2SVavxx2teudgLtN4inO+r/Nxcd8H+ejHZ6J joORDGxRCueIbVZsuh3A3Q7alwXHzmrF9x7UD5TSZ3G0s058SqFfbvaqzrgEHybGWz7L CPRblcnRQ1dxHO3tv0sJy+2GSIJ3Op7qw092gjatCJO0irj5nCWWoWqayRfegCtZbRYg keRw== X-Gm-Message-State: AOAM5334oD2e6elr0XAjPpVSLbk7US4b80NnEwegNb588uvgPZ5q2iCw Zl0qgrSa1ewN9AK1i0muZaOD6yoiWd2Y X-Google-Smtp-Source: ABdhPJxLXU6NMM3kSh38aJIH/4lbhagzTjIvjo3KT34820k38yHRBMsFEiCubfGOgQGjyBUjvHo61vYWmKGW X-Received: from pigloo.svl.corp.google.com ([2620:15c:2c5:13:cacf:5ee9:4234:3c47]) (user=jmeurin job=sendgmr) by 2002:a25:3445:0:b0:648:3dd2:f210 with SMTP id b66-20020a253445000000b006483dd2f210mr8899114yba.3.1650902975700; Mon, 25 Apr 2022 09:09:35 -0700 (PDT) Date: Mon, 25 Apr 2022 09:09:27 -0700 In-Reply-To: <20220415001321.252848-1-jmeurin@google.com> Message-Id: <20220425160927.3823016-1-jmeurin@google.com> Mime-Version: 1.0 References: <20220415001321.252848-1-jmeurin@google.com> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH v4 3/3] mtd: mtdoops: Add a timestamp to the mtdoops header. From: Jean-Marc Eurin To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Jean-Marc Eurin Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On some systems, the oops only has relative time from boot. Signed-off-by: Jean-Marc Eurin --- drivers/mtd/mtdoops.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index 186eeb01bee1..3d4a2ffb5b01 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include =20 @@ -37,11 +38,13 @@ module_param(dump_oops, int, 0600); MODULE_PARM_DESC(dump_oops, "set to 1 to dump oopses, 0 to only dump panics (default 1)"); =20 -#define MTDOOPS_KERNMSG_MAGIC 0x5d005d00 +#define MTDOOPS_KERNMSG_MAGIC_v1 0x5d005d00 /* Original */ +#define MTDOOPS_KERNMSG_MAGIC_v2 0x5d005e00 /* Adds the timestamp */ =20 struct mtdoops_hdr { u32 seq; u32 magic; + ktime_t timestamp; } __packed; =20 static struct mtdoops_context { @@ -191,7 +194,8 @@ static void mtdoops_write(struct mtdoops_context *cxt, = int panic) /* Add mtdoops header to the buffer */ hdr =3D (struct mtdoops_hdr *)cxt->oops_buf; hdr->seq =3D cxt->nextcount; - hdr->magic =3D MTDOOPS_KERNMSG_MAGIC; + hdr->magic =3D MTDOOPS_KERNMSG_MAGIC_v2; + hdr->timestamp =3D ktime_get_real(); =20 if (panic) { ret =3D mtd_panic_write(mtd, cxt->nextpage * record_size, @@ -247,7 +251,9 @@ static void find_next_position(struct mtdoops_context *= cxt) =20 if (hdr.seq =3D=3D 0xffffffff && hdr.magic =3D=3D 0xffffffff) mark_page_unused(cxt, page); - if (hdr.seq =3D=3D 0xffffffff || hdr.magic !=3D MTDOOPS_KERNMSG_MAGIC) + if (hdr.seq =3D=3D 0xffffffff || + (hdr.magic !=3D MTDOOPS_KERNMSG_MAGIC_v1 && + hdr.magic !=3D MTDOOPS_KERNMSG_MAGIC_v2)) continue; if (maxcount =3D=3D 0xffffffff) { maxcount =3D hdr.seq; --=20 2.36.0.rc2.479.g8af0fa9b8e-goog From nobody Mon May 11 04:12:56 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AA73C433F5 for ; Fri, 15 Apr 2022 00:14:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347971AbiDOAQ4 (ORCPT ); Thu, 14 Apr 2022 20:16:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347943AbiDOAQm (ORCPT ); Thu, 14 Apr 2022 20:16:42 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF035931B0 for ; Thu, 14 Apr 2022 17:14:14 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2dc7bdd666fso55167797b3.7 for ; Thu, 14 Apr 2022 17:14:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ahv1rMnoXCJYqGoBMv8RBADWJdwEiPpEYtFvG6t6lwk=; b=VJ6FESzpi+kwKXbN4PjaEo5RYLhxcdrKaGb60eloOT8EztGcgCnZKP0rXMfhj3mZHw SCdNpZH64G5qdy3boXLj6xlC6VcyNv+lklrRgBJPeYOdLtWSl67eIfdB6AdanP/aUWTZ KgG7R3ZUhf6pliehqp5RIvSoZD2SQq1yaZCEaW1mZp4wNhEkAUUufjQhOe1Yu6Ua+FDU IU3qGidlqmUZFRnx0YjUnQImk2MrYdddWmeHDZYhn6iNNejUkEfYgXF0oQ/kqjXjXKqC +JH9jP8S+xbHyMwmuohtLSNf+/BFaZVtJC0YrAMgUqFL5j5qVjZ5vGcHVsvBGQBHMyRK HrJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ahv1rMnoXCJYqGoBMv8RBADWJdwEiPpEYtFvG6t6lwk=; b=stQK9xYRgNZ+zVOXFfSLsJTGI86Ad/x9ho8n05PYyNr3k8JRybu0s+ju2dQwtLiH7U WYiobHiPv9kRYHtltsspIGpfWocKz4k0/Lh6SwygzWyrlOE6sMvCeCUFciQOjXbZqOU2 +qCOyTqQn+TFY8dQI3sEb674mI7Y7qFOxMGbn0I4Ih/uKdT7diJiLZCKmFjX6S8DtNQ1 Sb2/P1+FAGSboVHn4v1ocHHSqdu3nRlXKBJJUR8UkUEkfOLwieUuRiZfOrJ7y4Kcm5Jh hXGc8lI2iTk8Kl8nkmyPuQ+j4+1eI0lnz0PcD4cy+xkEvp1B2lKwQN8052676E3k6pmB oeHw== X-Gm-Message-State: AOAM532FyMR1XdYO4bf4pCdAoFJMMKaH3KGWFRq83Mis3Kc+ZSWCfsPu hT3hxgdxj5HntstA0mBtu7WHJbfR2Yy0 X-Google-Smtp-Source: ABdhPJz0sRlJgwqEIUkD/l0xohBHj1hXJzIsDsQUZHoplQroWQ4UFZYNm68G+NEkRyeSyR95NY1r0n3mAmrh X-Received: from pigloo.svl.corp.google.com ([2620:15c:2c5:13:7d77:8cae:9dfe:95c]) (user=jmeurin job=sendgmr) by 2002:a05:6902:1109:b0:63d:caf3:73b5 with SMTP id o9-20020a056902110900b0063dcaf373b5mr3737845ybu.413.1649981654033; Thu, 14 Apr 2022 17:14:14 -0700 (PDT) Date: Thu, 14 Apr 2022 17:13:21 -0700 In-Reply-To: <20220415001321.252848-1-jmeurin@google.com> Message-Id: <20220415001321.252848-4-jmeurin@google.com> Mime-Version: 1.0 References: <20220207163409.19c3bc4c@xps13> <20220415001321.252848-1-jmeurin@google.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog Subject: [PATCH v3 3/3] mtd: mtdoops: Add a timestamp to the mtdoops header. From: Jean-Marc Eurin To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Jean-Marc Eurin Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On some systems, the oops only has relative time from boot. Signed-off-by: Jean-Marc Eurin --- drivers/mtd/mtdoops.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index f80468ef31c6..4e5ade91da36 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include =20 @@ -37,11 +38,13 @@ module_param(dump_oops, int, 0600); MODULE_PARM_DESC(dump_oops, "set to 1 to dump oopses, 0 to only dump panics (default 1)"); =20 -#define MTDOOPS_KERNMSG_MAGIC 0x5d005d00 +#define MTDOOPS_KERNMSG_MAGIC_v1 0x5d005d00 /* Original */ +#define MTDOOPS_KERNMSG_MAGIC_v2 0x5d005e00 /* Adds the timestamp */ =20 struct mtdoops_hdr { u32 seq; u32 magic; + ktime_t timestamp; } __packed; =20 static struct mtdoops_context { @@ -191,7 +194,8 @@ static void mtdoops_write(struct mtdoops_context *cxt, = int panic) /* Add mtdoops header to the buffer */ hdr =3D (struct mtdoops_hdr *)cxt->oops_buf; hdr->seq =3D cxt->nextcount; - hdr->magic =3D MTDOOPS_KERNMSG_MAGIC; + hdr->magic =3D MTDOOPS_KERNMSG_MAGIC_v2; + hdr->timestamp =3D ktime_get_real(); =20 if (panic) { ret =3D mtd_panic_write(mtd, cxt->nextpage * record_size, @@ -247,7 +251,9 @@ static void find_next_position(struct mtdoops_context *= cxt) =20 if (hdr.seq =3D=3D 0xffffffff && hdr.magic =3D=3D 0xffffffff) mark_page_unused(cxt, page); - if (hdr.seq =3D=3D 0xffffffff || hdr.magic !=3D MTDOOPS_KERNMSG_MAGIC) + if (hdr.seq =3D=3D 0xffffffff || + (hdr.magic !=3D MTDOOPS_KERNMSG_MAGIC_v1 && + hdr.magic !=3D MTDOOPS_KERNMSG_MAGIC_v2)) continue; if (maxcount =3D=3D 0xffffffff) { maxcount =3D hdr.seq; --=20 2.36.0.rc0.470.gd361397f0d-goog