From: John Ogness <john.ogness@linutronix.de> To: Petr Mladek <pmladek@suse.com> Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>, Sergey Senozhatsky <sergey.senozhatsky@gmail.com>, Steven Rostedt <rostedt@goodmis.org>, Thomas Gleixner <tglx@linutronix.de>, linux-kernel@vger.kernel.org, Miquel Raynal <miquel.raynal@bootlin.com>, Richard Weinberger <richard@nod.at>, Vignesh Raghavendra <vigneshr@ti.com>, linux-mtd@lists.infradead.org Subject: [PATCH next v3 02/15] mtd: mtdoops: synchronize kmsg_dumper Date: Thu, 25 Feb 2021 21:24:25 +0100 [thread overview] Message-ID: <20210225202438.28985-3-john.ogness@linutronix.de> (raw) In-Reply-To: <20210225202438.28985-1-john.ogness@linutronix.de> The kmsg_dumper can be called from any context and CPU, possibly from multiple CPUs simultaneously. Since the writing of the buffer can occur from a later scheduled work queue, the oops buffer must be protected against simultaneous dumping. Use an atomic bit to mark when the buffer is protected. Release the protection in between setting the buffer and the actual writing in order for a possible panic (immediate write) to be written during the scheduling of a previous oops (delayed write). Signed-off-by: John Ogness <john.ogness@linutronix.de> --- drivers/mtd/mtdoops.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index 774970bfcf85..8bbfba40a554 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -52,6 +52,7 @@ static struct mtdoops_context { int nextcount; unsigned long *oops_page_used; + unsigned long oops_buf_busy; void *oops_buf; } oops_cxt; @@ -180,6 +181,9 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic) u32 *hdr; int ret; + if (test_and_set_bit(0, &cxt->oops_buf_busy)) + return; + /* Add mtdoops header to the buffer */ hdr = cxt->oops_buf; hdr[0] = cxt->nextcount; @@ -190,7 +194,7 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic) record_size, &retlen, cxt->oops_buf); if (ret == -EOPNOTSUPP) { printk(KERN_ERR "mtdoops: Cannot write from panic without panic_write\n"); - return; + goto out; } } else ret = mtd_write(mtd, cxt->nextpage * record_size, @@ -203,6 +207,8 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic) memset(cxt->oops_buf, 0xff, record_size); mtdoops_inc_counter(cxt); +out: + clear_bit(0, &cxt->oops_buf_busy); } static void mtdoops_workfunc_write(struct work_struct *work) @@ -276,8 +282,11 @@ static void mtdoops_do_dump(struct kmsg_dumper *dumper, if (reason == KMSG_DUMP_OOPS && !dump_oops) return; + if (test_and_set_bit(0, &cxt->oops_buf_busy)) + return; kmsg_dump_get_buffer(dumper, true, cxt->oops_buf + MTDOOPS_HEADER_SIZE, record_size - MTDOOPS_HEADER_SIZE, NULL); + clear_bit(0, &cxt->oops_buf_busy); if (reason != KMSG_DUMP_OOPS) { /* Panics must be written immediately */ @@ -394,6 +403,7 @@ static int __init mtdoops_init(void) return -ENOMEM; } memset(cxt->oops_buf, 0xff, record_size); + cxt->oops_buf_busy = 0; INIT_WORK(&cxt->work_erase, mtdoops_workfunc_erase); INIT_WORK(&cxt->work_write, mtdoops_workfunc_write); -- 2.20.1
WARNING: multiple messages have this Message-ID (diff)
From: John Ogness <john.ogness@linutronix.de> To: Petr Mladek <pmladek@suse.com> Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>, Richard Weinberger <richard@nod.at>, linux-kernel@vger.kernel.org, Steven Rostedt <rostedt@goodmis.org>, Sergey Senozhatsky <sergey.senozhatsky@gmail.com>, linux-mtd@lists.infradead.org, Miquel Raynal <miquel.raynal@bootlin.com>, Thomas Gleixner <tglx@linutronix.de>, Vignesh Raghavendra <vigneshr@ti.com> Subject: [PATCH next v3 02/15] mtd: mtdoops: synchronize kmsg_dumper Date: Thu, 25 Feb 2021 21:24:25 +0100 [thread overview] Message-ID: <20210225202438.28985-3-john.ogness@linutronix.de> (raw) In-Reply-To: <20210225202438.28985-1-john.ogness@linutronix.de> The kmsg_dumper can be called from any context and CPU, possibly from multiple CPUs simultaneously. Since the writing of the buffer can occur from a later scheduled work queue, the oops buffer must be protected against simultaneous dumping. Use an atomic bit to mark when the buffer is protected. Release the protection in between setting the buffer and the actual writing in order for a possible panic (immediate write) to be written during the scheduling of a previous oops (delayed write). Signed-off-by: John Ogness <john.ogness@linutronix.de> --- drivers/mtd/mtdoops.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index 774970bfcf85..8bbfba40a554 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -52,6 +52,7 @@ static struct mtdoops_context { int nextcount; unsigned long *oops_page_used; + unsigned long oops_buf_busy; void *oops_buf; } oops_cxt; @@ -180,6 +181,9 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic) u32 *hdr; int ret; + if (test_and_set_bit(0, &cxt->oops_buf_busy)) + return; + /* Add mtdoops header to the buffer */ hdr = cxt->oops_buf; hdr[0] = cxt->nextcount; @@ -190,7 +194,7 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic) record_size, &retlen, cxt->oops_buf); if (ret == -EOPNOTSUPP) { printk(KERN_ERR "mtdoops: Cannot write from panic without panic_write\n"); - return; + goto out; } } else ret = mtd_write(mtd, cxt->nextpage * record_size, @@ -203,6 +207,8 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic) memset(cxt->oops_buf, 0xff, record_size); mtdoops_inc_counter(cxt); +out: + clear_bit(0, &cxt->oops_buf_busy); } static void mtdoops_workfunc_write(struct work_struct *work) @@ -276,8 +282,11 @@ static void mtdoops_do_dump(struct kmsg_dumper *dumper, if (reason == KMSG_DUMP_OOPS && !dump_oops) return; + if (test_and_set_bit(0, &cxt->oops_buf_busy)) + return; kmsg_dump_get_buffer(dumper, true, cxt->oops_buf + MTDOOPS_HEADER_SIZE, record_size - MTDOOPS_HEADER_SIZE, NULL); + clear_bit(0, &cxt->oops_buf_busy); if (reason != KMSG_DUMP_OOPS) { /* Panics must be written immediately */ @@ -394,6 +403,7 @@ static int __init mtdoops_init(void) return -ENOMEM; } memset(cxt->oops_buf, 0xff, record_size); + cxt->oops_buf_busy = 0; INIT_WORK(&cxt->work_erase, mtdoops_workfunc_erase); INIT_WORK(&cxt->work_write, mtdoops_workfunc_write); -- 2.20.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2021-02-25 20:25 UTC|newest] Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-02-25 20:24 [PATCH next v3 00/15] printk: remove logbuf_lock John Ogness 2021-02-25 20:24 ` John Ogness 2021-02-25 20:24 ` John Ogness 2021-02-25 20:24 ` John Ogness 2021-02-25 20:24 ` [PATCH next v3 01/15] um: synchronize kmsg_dumper John Ogness 2021-02-25 20:24 ` John Ogness 2021-03-01 16:16 ` Petr Mladek 2021-03-01 16:16 ` Petr Mladek 2021-03-01 16:57 ` Petr Mladek 2021-03-01 16:57 ` Petr Mladek 2021-03-02 8:06 ` John Ogness 2021-03-02 8:06 ` John Ogness 2021-03-02 10:12 ` Petr Mladek 2021-03-02 10:12 ` Petr Mladek 2021-02-25 20:24 ` John Ogness [this message] 2021-02-25 20:24 ` [PATCH next v3 02/15] mtd: mtdoops: " John Ogness 2021-03-01 12:13 ` Petr Mladek 2021-03-01 12:13 ` Petr Mladek 2021-03-02 10:45 ` John Ogness 2021-03-02 10:45 ` John Ogness 2021-03-02 12:48 ` Petr Mladek 2021-03-02 12:48 ` Petr Mladek 2021-02-25 20:24 ` [PATCH next v3 03/15] printk: limit second loop of syslog_print_all John Ogness 2021-02-25 20:24 ` [PATCH next v3 04/15] printk: kmsg_dump: remove unused fields John Ogness 2021-02-25 20:24 ` [PATCH next v3 05/15] printk: refactor kmsg_dump_get_buffer() John Ogness 2021-02-25 20:24 ` [PATCH next v3 06/15] printk: consolidate kmsg_dump_get_buffer/syslog_print_all code John Ogness 2021-02-25 20:24 ` [PATCH next v3 07/15] printk: introduce CONSOLE_LOG_MAX for improved multi-line support John Ogness 2021-03-02 13:54 ` Geert Uytterhoeven 2021-03-02 13:58 ` Geert Uytterhoeven 2021-03-02 14:34 ` John Ogness 2021-02-25 20:24 ` [PATCH next v3 08/15] printk: use seqcount_latch for clear_seq John Ogness 2021-02-25 20:24 ` [PATCH next v3 09/15] printk: use atomic64_t for devkmsg_user.seq John Ogness 2021-02-25 20:24 ` [PATCH next v3 10/15] printk: add syslog_lock John Ogness 2021-03-01 17:07 ` Petr Mladek 2021-02-25 20:24 ` [PATCH next v3 11/15] printk: kmsg_dumper: remove @active field John Ogness 2021-02-25 20:24 ` John Ogness 2021-03-01 17:09 ` Petr Mladek 2021-03-01 17:09 ` Petr Mladek 2021-02-25 20:24 ` [PATCH next v3 12/15] printk: introduce a kmsg_dump iterator John Ogness 2021-02-25 20:24 ` John Ogness 2021-02-25 20:24 ` John Ogness 2021-02-25 20:24 ` John Ogness 2021-02-25 21:59 ` Kees Cook 2021-02-25 21:59 ` Kees Cook 2021-02-25 21:59 ` Kees Cook 2021-02-26 2:57 ` kernel test robot 2021-02-26 7:59 ` John Ogness 2021-02-26 7:59 ` John Ogness 2021-02-26 7:59 ` John Ogness 2021-02-26 7:59 ` John Ogness 2021-02-26 7:59 ` John Ogness 2021-03-01 18:07 ` Petr Mladek 2021-03-01 18:07 ` Petr Mladek 2021-03-01 18:07 ` Petr Mladek 2021-03-01 18:07 ` Petr Mladek 2021-03-02 13:20 ` John Ogness 2021-03-02 13:20 ` John Ogness 2021-03-02 13:20 ` John Ogness 2021-03-02 13:55 ` Petr Mladek 2021-03-02 13:55 ` Petr Mladek 2021-03-02 13:55 ` Petr Mladek 2021-02-25 20:24 ` [PATCH next v3 13/15] printk: remove logbuf_lock John Ogness 2021-03-02 12:15 ` Petr Mladek 2021-02-25 20:24 ` [PATCH next v3 14/15] printk: kmsg_dump: remove _nolock() variants John Ogness 2021-02-25 20:24 ` John Ogness 2021-02-25 20:24 ` [PATCH next v3 15/15] printk: console: remove unnecessary safe buffer usage John Ogness
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210225202438.28985-3-john.ogness@linutronix.de \ --to=john.ogness@linutronix.de \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mtd@lists.infradead.org \ --cc=miquel.raynal@bootlin.com \ --cc=pmladek@suse.com \ --cc=richard@nod.at \ --cc=rostedt@goodmis.org \ --cc=sergey.senozhatsky.work@gmail.com \ --cc=sergey.senozhatsky@gmail.com \ --cc=tglx@linutronix.de \ --cc=vigneshr@ti.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.