OSDN Git Service

mtd: mtdoops: synchronize kmsg_dumper
authorJohn Ogness <john.ogness@linutronix.de>
Wed, 3 Mar 2021 10:15:15 +0000 (11:15 +0100)
committerPetr Mladek <pmladek@suse.com>
Mon, 8 Mar 2021 10:42:46 +0000 (11:42 +0100)
commit40ddbbac7f16eb91f9f2bbc414f283102052ce14
tree3ceb1576e21a85bc71f9f89b7f969ae935c332fc
parentfdd2c1f4e2c2e2fee1d95d18b4b06bc0d15c368a
mtd: mtdoops: synchronize kmsg_dumper

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).

An atomic bit (rather than a spinlock) was chosen so that no
scheduling or preemption side-effects would be introduced. The MTD
kmsg_dumper may dump directly or it may be delayed (via scheduled
work). Depending on the context, different MTD callbacks are used.
For example, mtd_write() expects to be called in a non-atomic
context and may take a mutex.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20210303101528.29901-3-john.ogness@linutronix.de
drivers/mtd/mtdoops.c