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 @@
1// SPDX-License-Identifier: GPL-2.01// SPDX-License-Identifier: GPL-2.0
2#include <linux/kmsg_dump.h>2#include <linux/kmsg_dump.h>
3#include <linux/spinlock.h>
3#include <linux/console.h>4#include <linux/console.h>
4#include <linux/string.h>5#include <linux/string.h>
5#include <shared/init.h>6#include <shared/init.h>
@@ -9,8 +10,10 @@ · 3 unmodified lines
9static void kmsg_dumper_stdout(struct kmsg_dumper *dumper,10static void kmsg_dumper_stdout(struct kmsg_dumper *dumper,
10 enum kmsg_dump_reason reason)11 enum kmsg_dump_reason reason)
11{12{
13 static DEFINE_SPINLOCK(lock);
12 static char line[1024];14 static char line[1024];
13 struct console *con;15 struct console *con;
16 unsigned long flags;
14 size_t len = 0;17 size_t len = 0;
15 18
16 /* only dump kmsg when no console is available */19 /* only dump kmsg when no console is available */
@@ -29,11 +32,16 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, · 12 unmodified lines
29 if (con)32 if (con)
30 return;33 return;
31 34
35 if (!spin_trylock_irqsave(&lock, flags))
36 return;
37
32 printf("kmsg_dump:\n");38 printf("kmsg_dump:\n");
33 while (kmsg_dump_get_line(dumper, true, line, sizeof(line), &len)) {39 while (kmsg_dump_get_line(dumper, true, line, sizeof(line), &len)) {
34 line[len] = '\0';40 line[len] = '\0';
35 printf("%s", line);41 printf("%s", line);
36 }42 }
43
44 spin_unlock_irqrestore(&lock, flags);
37}45}
38 46
39static struct kmsg_dumper kmsg_dumper = {47static 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