History

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.

John Ogness committed 5 years ago

Commit fdd2c1f1 parent b2bec7d1 file · +8 −0Browse files

Unified · Split

arch/um/kernel/kmsg_dump.c+8−0
@@ -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 @@ · 3 unmodified lines
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, · 12 unmodified lines
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 = {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t