Skip to content

Commit fdd2c1f

Browse files
jognesspmladek
authored andcommitted
um: synchronize kmsg_dumper
The kmsg_dumper can be called from any context and CPU, possibly from multiple CPUs simultaneously. Since a static buffer is used to retrieve the kernel logs, this buffer must be protected against simultaneous dumping. Skip dumping if another context is already dumping. 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-2-john.ogness@linutronix.de
1 parent b2bec7d commit fdd2c1f

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

arch/um/kernel/kmsg_dump.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include <linux/kmsg_dump.h>
3+
#include <linux/spinlock.h>
34
#include <linux/console.h>
45
#include <linux/string.h>
56
#include <shared/init.h>
@@ -9,8 +10,10 @@
910
static void kmsg_dumper_stdout(struct kmsg_dumper *dumper,
1011
enum kmsg_dump_reason reason)
1112
{
13+
static DEFINE_SPINLOCK(lock);
1214
static char line[1024];
1315
struct console *con;
16+
unsigned long flags;
1417
size_t len = 0;
1518

1619
/* only dump kmsg when no console is available */
@@ -29,11 +32,16 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper,
2932
if (con)
3033
return;
3134

35+
if (!spin_trylock_irqsave(&lock, flags))
36+
return;
37+
3238
printf("kmsg_dump:\n");
3339
while (kmsg_dump_get_line(dumper, true, line, sizeof(line), &len)) {
3440
line[len] = '\0';
3541
printf("%s", line);
3642
}
43+
44+
spin_unlock_irqrestore(&lock, flags);
3745
}
3846

3947
static struct kmsg_dumper kmsg_dumper = {

0 commit comments

Comments
 (0)