Skip to contentSkip to conversation

Introduce the aural error reporting framework

PATCH In review Matteo Croce 4 participants 11 messages Apr 1, 2019 – Apr 2, 2019

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover Introduce the aural error reporting framework

The Linux kernel has had verbal error reporting since the beginning. Different error conditions trigger different error messages, with different severity: from a simple warning to the most feared kernel panic.

While this detailed error reporting is much helpful to developers or end users, there are some cases in which it's impossible to notice that an error happened.
The most common case is headless devices, such as home servers without an attached display, or routers without an exposed serial port. Needless to say, logging into the machine via SSH is not an option after such a severe error.
In other cases the monitor might be attached, but the system is unable to display the error, probably because there is an X server running and the KMS switch fails. Or simply the user is visually impaired.

These are all cases when the aural errors framework comes to help. This framework adds to the kernel a generic library to play sounds, which can be used to report errors or generic events.

As the sound card driver could, and most probably will, become unusable during a kernel crash, the sounds are played via the system buzzer which has been around since the dawn of time.
The buzzer driver is simple, requires just a few register writes to work, the hardware is extremely cheap and is already present on most machines.

The first patch introduces the framework functions, the other three make use of it in, respectively, kernel panic, warning and oops. The last patch, not to be merged, creates a procfs handler useful to test the error reporting.

Matteo Croce (4):
aural error reporting framework
panic: use the aural error reporting framework to report panics
bug: use the aural error reporting framework to report warnings
oops: use the aural error reporting framework to report oopses

 arch/x86/lib/Makefile |  1 +
 arch/x86/lib/play.c   | 75 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/play.h  | 34 ++++++++++++++++++++
 kernel/panic.c        | 61 +++++++++++++++++++++++++++++++++++
 lib/Kconfig.debug     | 35 ++++++++++++++++++++
 5 files changed, 206 insertions(+)
 create mode 100644 arch/x86/lib/play.c
 create mode 100644 include/linux/play.h
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/4 aural error reporting framework

The Linux kernel has had verbal error reporting since the beginning. Different error conditions trigger different error messages, with different severity: from a simple warning to the most feared kernel panic.

While this detailed error reporting is much helpful to developers or end users, there are some cases in which it's impossible to notice that an error happened.
The most common case is headless devices, such as home servers without an attached display, or routers without an exposed serial port. Needless to say, logging into the machine via SSH is not an option after such a severe error.
In other cases the monitor might be attached, but the system is unable to display the error, probably because there is an X server running and the KMS switch fails. Or simply the user is visually impaired.

These are all cases when the aural errors framework comes to help. This framework adds to the kernel a generic library to play sounds, which can be used to report errors or generic events.

As the sound card driver could, and most probably will, become unusable during a kernel crash, the sounds are played via the system buzzer which has been around since the dawn of time.
The buzzer driver is simple, requires just a few register writes to work, the hardware is extremely cheap and is already present on most machines.

---
 arch/x86/lib/Makefile |  1 +
 arch/x86/lib/play.c   | 75 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/play.h  | 34 ++++++++++++++++++++
 lib/Kconfig.debug     |  5 +++
 4 files changed, 115 insertions(+)
 create mode 100644 arch/x86/lib/play.c
 create mode 100644 include/linux/play.h
arch/x86/lib/Makefile +1 -0
index 140e61843a07..fcd1ee6adfad 100644
@@ -28,6 +28,7 @@ lib-$(CONFIG_INSTRUCTION_DECODER) += insn.o inat.o insn-eval.o
 lib-$(CONFIG_RANDOMIZE_BASE) += kaslr.o
 lib-$(CONFIG_FUNCTION_ERROR_INJECTION)	+= error-inject.o
 lib-$(CONFIG_RETPOLINE) += retpoline.o
+lib-$(CONFIG_PLAY_LIB) += play.o
 
 obj-y += msr.o msr-reg.o msr-reg-export.o hweight.o
 obj-y += iomem.o
arch/x86/lib/play.c new file +75 -0

75 lines not on this page · raw message

include/linux/play.h new file +34 -0
new file mode 100644
index 000000000000..ae30cb8a0c1d
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * play.h - Definitions and headers for the aural error reporting framework.
+ *
+ * Copyright (C) 2019 Matteo Croce <[email protected]>
+ *
+ * This file is released under the GPLv2.
+ */
+
+#ifndef _LINUX_PLAY_H
+#define _LINUX_PLAY_H
+
+#ifdef CONFIG_PLAY_LIB
+
+struct note {
+	unsigned int freq;
+	unsigned int dur;
+};
+
+void arch_play_one(unsigned int ms, unsigned int hz);
+
+#define play(notes, len) do {						\
+		int i;							\
+		for (i = 0; i < len; i++)				\
+			arch_play_one(notes[i].dur, notes[i].freq);	\
+	} while (0)
+
+#else
+
+#define play(n, l)
+
+#endif
+
+#endif
lib/Kconfig.debug +5 -0
index 0d9e81779e37..10d04b266aef 100644
@@ -992,6 +992,11 @@ config PANIC_TIMEOUT
 	  value n > 0 will wait n seconds before rebooting, while a timeout
 	  value n < 0 will reboot immediately.
 
+config PLAY_LIB
+	bool
+	depends on HAVE_PCSPKR_PLATFORM
+	default n
+
 config SCHED_DEBUG
 	bool "Collect scheduler debugging info"
 	depends on DEBUG_KERNEL && PROC_FS
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/4 panic: use the aural error reporting framework to report panics

In reply to Matteo Croce

Use the new aural error reporting framework to signal kernel panic. The error sound is emitted between the stack dump and the kexec jump.

---
 kernel/panic.c    | 25 +++++++++++++++++++++++++
 lib/Kconfig.debug | 10 ++++++++++
 2 files changed, 35 insertions(+)
kernel/panic.c +25 -0
index 0ae0d7332f12..360578e092e7 100644
@@ -29,6 +29,7 @@
 #include <linux/bug.h>
 #include <linux/ratelimit.h>
 #include <linux/debugfs.h>
+#include <linux/play.h>
 #include <asm/sections.h>
 
 #define PANIC_TIMER_STEP 100
@@ -57,6 +58,29 @@ ATOMIC_NOTIFIER_HEAD(panic_notifier_list);
 
 EXPORT_SYMBOL(panic_notifier_list);
 
+#ifdef CONFIG_AUDIBLE_PANIC
+static struct note panic_sound[] = {
+	{ 784, 400 },
+	{ 784, 400 },
+	{ 784, 400 },
+	{ 622, 300 },
+	{ 932, 100 },
+	{ 784, 400 },
+	{ 622, 300 },
+	{ 932, 100 },
+	{ 784, 800 },
+	{ 1174, 400 },
+	{ 1174, 400 },
+	{ 1174, 400 },
+	{ 1244, 300 },
+	{ 932, 100 },
+	{ 740, 400 },
+	{ 622, 300 },
+	{ 932, 100 },
+	{ 784, 800 },
+};
+#endif
+
 static long no_blink(int state)
 {
 	return 0;
@@ -213,6 +237,7 @@ void panic(const char *fmt, ...)
 	if (!test_taint(TAINT_DIE) && oops_in_progress <= 1)
 		dump_stack();
 #endif
+	play(panic_sound, ARRAY_SIZE(panic_sound));
 
 	/*
 	 * If we have crashed and we have a crash kernel loaded let it handle
lib/Kconfig.debug +10 -0
index 10d04b266aef..e5d187dfc74a 100644
@@ -997,6 +997,16 @@ config PLAY_LIB
 	depends on HAVE_PCSPKR_PLATFORM
 	default n
 
+config AUDIBLE_PANIC
+	bool "Aural panic"
+	select PLAY_LIB
+	default n
+	help
+	  If you say Y here, kernel panics will play a sound just
+	  after the stacktrace and registers dump. The sound is played via
+	  the system buzzer and not via any soundcard.
+	  Not available on all platforms.
+
 config SCHED_DEBUG
 	bool "Collect scheduler debugging info"
 	depends on DEBUG_KERNEL && PROC_FS
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/4 bug: use the aural error reporting framework to report warnings

In reply to Matteo Croce

Use the new aural error reporting framework to signal kernel bugs. Emit the sound at the end of the __warn(), so the WARN_* are all covered. If panic_on_warn is set, panic() will play its sound and never return, so there is no risk to emit two sounds or the wrong one.

---
 kernel/panic.c    | 18 ++++++++++++++++++
 lib/Kconfig.debug | 10 ++++++++++
 2 files changed, 28 insertions(+)
kernel/panic.c +18 -0
index 360578e092e7..b87c4403924d 100644
@@ -81,6 +81,22 @@ static struct note panic_sound[] = {
 };
 #endif
 
+#ifdef CONFIG_AUDIBLE_WARN
+static struct note warn_sound[] = {
+	{ 440, 400 },
+	{ 440, 300 },
+	{ 440, 100 },
+	{ 440, 400 },
+	{ 523, 300 },
+	{ 494, 100 },
+	{ 494, 300 },
+	{ 440, 100 },
+	{ 440, 300 },
+	{ 440, 100 },
+	{ 440, 800 },
+};
+#endif
+
 static long no_blink(int state)
 {
 	return 0;
@@ -609,6 +625,8 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
 
 	/* Just a warning, don't kill lockdep. */
 	add_taint(taint, LOCKDEP_STILL_OK);
+
+	play(warn_sound, ARRAY_SIZE(warn_sound));
 }
 
 #ifdef WANT_WARN_ON_SLOWPATH
lib/Kconfig.debug +10 -0
index e5d187dfc74a..909c271d283b 100644
@@ -1007,6 +1007,16 @@ config AUDIBLE_PANIC
 	  the system buzzer and not via any soundcard.
 	  Not available on all platforms.
 
+config AUDIBLE_WARN
+	bool "Aural warning"
+	select PLAY_LIB
+	default n
+	help
+	  If you say Y here, warnings will play a sound just
+	  after the stacktrace and registers dump. The sound is played via
+	  the system buzzer and not via any soundcard.
+	  Not available on all platforms.
+
 config SCHED_DEBUG
 	bool "Collect scheduler debugging info"
 	depends on DEBUG_KERNEL && PROC_FS
Signature · 1 line
2.20.1
#4 lore raw

PATCH 4/4 oops: use the aural error reporting framework to report oopses

In reply to Matteo Croce

Use the new aural error reporting framework when reporting an oops. The sound is emitted at the end of oops_exit(), to avoid interfering with other oops actions, like stack dump.

---
 kernel/panic.c    | 18 ++++++++++++++++++
 lib/Kconfig.debug | 10 ++++++++++
 2 files changed, 28 insertions(+)
kernel/panic.c +18 -0
index b87c4403924d..ea34f93ce410 100644
@@ -97,6 +97,23 @@ static struct note warn_sound[] = {
 };
 #endif
 
+#ifdef CONFIG_AUDIBLE_OOPS
+static struct note oops_sound[] = {
+	{ 494, 100 },
+	{ 698, 100 },
+	{   0, 100 },
+	{ 698, 100 },
+	{ 698, 133 },
+	{ 659, 133 },
+	{ 587, 133 },
+	{ 523, 100 },
+	{ 330, 100 },
+	{ 262, 100 },
+	{ 330, 100 },
+	{ 262, 100 },
+};
+#endif
+
 static long no_blink(int state)
 {
 	return 0;
@@ -575,6 +592,7 @@ void oops_exit(void)
 	do_oops_enter_exit();
 	print_oops_end_marker();
 	kmsg_dump(KMSG_DUMP_OOPS);
+	play(oops_sound, ARRAY_SIZE(oops_sound));
 }
 
 struct warn_args {
lib/Kconfig.debug +10 -0
index 909c271d283b..74745ef386ce 100644
@@ -1017,6 +1017,16 @@ config AUDIBLE_WARN
 	  the system buzzer and not via any soundcard.
 	  Not available on all platforms.
 
+config AUDIBLE_OOPS
+	bool "Aural oops"
+	select PLAY_LIB
+	default n
+	help
+	  If you say Y here, oops will play a sound just
+	  after the stacktrace and registers dump. The sound is played via
+	  the system buzzer and not via any soundcard.
+	  Not available on all platforms.
+
 config SCHED_DEBUG
 	bool "Collect scheduler debugging info"
 	depends on DEBUG_KERNEL && PROC_FS
Signature · 1 line
2.20.1
#5 lore raw

[PATCH 5/4] procfs: utility handler to trigger different errors

In reply to Matteo Croce

Add a /proc/crashtest handler which triggers different kernel errors. Just write a single character (if many are written, only the first one is read), to trigger different errors:
- p: raise a kernel panic
- w: generate a warning
- o: raise an oops
The handler permissions are set to 0220 to avoid non root users to crash the system.

---
 fs/proc/Makefile    |  1 +
 fs/proc/crashtest.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100644 fs/proc/crashtest.c
fs/proc/Makefile +1 -0
index ead487e80510..df99d3245ad9 100644
@@ -15,6 +15,7 @@ proc-$(CONFIG_TTY)      += proc_tty.o
 proc-y	+= cmdline.o
 proc-y	+= consoles.o
 proc-y	+= cpuinfo.o
+proc-y	+= crashtest.o
 proc-y	+= devices.o
 proc-y	+= interrupts.o
 proc-y	+= loadavg.o
fs/proc/crashtest.c new file +43 -0

43 lines not on this page · raw message

Signature · 1 line
2.20.1
#6 lore raw
In reply to Matteo Croce
Quoted 2 lines · Matteo Croce

The buzzer driver is simple, requires just a few register writes to work, the hardware is extremely cheap and is already present on most machines.

What, no morse-code register dumps?

#7 lore raw
Quoted 5 lines · Peter Zijlstra
Quoted 2 lines · Matteo Croce

The buzzer driver is simple, requires just a few register writes to work, the hardware is extremely cheap and is already present on most machines.

What, no morse-code register dumps?

Aside of that, where is the android-app to customize and decode the melodies?

I surely want to have the music theme of 'Once Upon a Time in the West' on kernel crashes.

Thanks,

tglx

#8 lore raw
Quoted 11 lines · Thomas Gleixner
Quoted 5 lines · Peter Zijlstra
Quoted 2 lines · Matteo Croce

The buzzer driver is simple, requires just a few register writes to work, the hardware is extremely cheap and is already present on most machines.

What, no morse-code register dumps?

Aside of that, where is the android-app to customize and decode the melodies?

Quoted 7 lines

I surely want to have the music theme of 'Once Upon a Time in the West' on kernel crashes.

Thanks,

tglx

Hi Thomas,

I'm a little rusty with Android programming, so I'll share the script I use to convert notes to frequences.
With some awk magic it can turn notes into a C array, I hope that you find it useful.

Bye,

Signature · 2 lines
Matteo Croce
per aspera ad upstream
#9 lore raw

Matteo,

Quoted 11 lines · Matteo Croce
Quoted 5 lines · Thomas Gleixner

Aside of that, where is the android-app to customize and decode the melodies?

I surely want to have the music theme of 'Once Upon a Time in the West' on kernel crashes.

I'm a little rusty with Android programming, so I'll share the script I use to convert notes to frequences.
With some awk magic it can turn notes into a C array, I hope that you find it useful.

That's great. Just a few nitpicks on the patches themself. You want to change msleep() to mdelay() in order to avoid "Scheduling while atomic" noise and you want to have global serialization because interleaving "La Paloma" from CPU1 and "Once Upon a Time in the West" from CPU2 sounds really horrible.

Thanks,

tglx

#10 lore raw
In reply to Matteo Croce

Il 01/04/19 12:24, Matteo Croce ha scritto:

Quoted 3 lines

These are all cases when the aural errors framework comes to help. This framework adds to the kernel a generic library to play sounds, which can be used to report errors or generic events.

hello Matteo,

this reminds me of a hack that Mr. Ferruccio Zulian (chief system architect for Olivetti, General Electric, Honeywell and IBM from 1965 to 1990) told us about during an interview we made for our computer art exhibition "bin/art"

When testing the hardware of a new system, back in the mid-60s, the engineers hooked audio output to circuitry for debugging purposes.

They kept in mind how a set of correctly executed operations **literally** sounded like and therefore they were able to detect errors in later executions when something sounded "wrong".

This was way more easy than looking at the light panels commonly used for similar debugging activities, as listening to sounds does not force you to be in a particular place, looking at a particular object.

As explained in the interview, an interesting side effect of this hack led to the early computer music experiments with Pietro Grossi (a real giant in contemporary and electronic music) that ended up in the recording "GE-115 concerto" 7 inch vinyl, distributed as christmas gift to all Olivetti/General Electric employees in 1967.

here's the link to a webpage with the interview (in italian)

https://binart.eu/ge-115-concerto/

and to the recording itself

side A: https://www.youtube.com/watch?v=CXosSsSekaU
side B: https://www.youtube.com/watch?v=bf8jMA_zizc

...so, what does this curious anectode say to us?

it looks like history is on the side of this patch :-)

hope it gets in the mainline code!

Ciao!
Emiliano Russo
---------------
Museo Interattivo di Archeologia Informatica (MIAI) Museo dell'Informatica Funzionante (MusIF)

Computer Musea :-)