Add a new LED trigger for kernel panics (and use it)
Subsystems (4)
cover Add a new LED trigger for kernel panics (and use it)
This patchset adds a very simple kernel panic LED trigger, by hooking into panic_blink. I've tested this trigger on ARM Armada XP OpenBlocks AX3-4 machine.
The trigger is then used to replace the open-coded panic_blink usage in GTA02 board.
Note that I don't have a GTA02 board, so the last patch is only built tested.
Ezequiel Garcia (3):
leds: trigger: Introduce a kernel panic LED trigger
ARM: configs: Enable panic LED trigger on s3c2410
ARM: s3c24xx: Use the panic LED trigger for GTA02
arch/arm/configs/s3c2410_defconfig | 1 + arch/arm/mach-s3c24xx/mach-gta02.c | 35 ++++++++++++++++------------------- drivers/leds/trigger/Kconfig | 7 +++++++ drivers/leds/trigger/Makefile | 1 + drivers/leds/trigger/ledtrig-panic.c | 30 ++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 drivers/leds/trigger/ledtrig-panic.c
Signature · 1 line
2.7.0
PATCH 1/3 leds: trigger: Introduce a kernel panic LED trigger
This commit introduces a new LED trigger which allows to configure a LED to blink on a kernel panic (through panic_blink).
Notice that currently the Openmoko FreeRunner (GTA02) mach code sets panic_blink to blink a hard-coded LED. The new trigger is meant to introduce a generic mechanism to achieve this.
--- drivers/leds/trigger/Kconfig | 7 +++++++ drivers/leds/trigger/Makefile | 1 + drivers/leds/trigger/ledtrig-panic.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 drivers/leds/trigger/ledtrig-panic.c
drivers/leds/trigger/Kconfig +7 -0
@@ -108,4 +108,11 @@ config LEDS_TRIGGER_CAMERA This enables direct flash/torch on/off by the driver, kernel space. If unsure, say Y. +config LEDS_TRIGGER_PANIC + bool "LED Panic Trigger" + depends on LEDS_TRIGGERS + help + This allows LEDs to be configured to blink on a kernel panic. + If unsure, say Y. + endif # LEDS_TRIGGERS
drivers/leds/trigger/Makefile +1 -0
@@ -8,3 +8,4 @@ obj-$(CONFIG_LEDS_TRIGGER_CPU) += ledtrig-cpu.o obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT) += ledtrig-transient.o obj-$(CONFIG_LEDS_TRIGGER_CAMERA) += ledtrig-camera.o +obj-$(CONFIG_LEDS_TRIGGER_PANIC) += ledtrig-panic.o
drivers/leds/trigger/ledtrig-panic.c new file +30 -0
@@ -0,0 +1,30 @@ +/* +* Kernel Panic LED Trigger +* +* Copyright 2016 Ezequiel Garcia <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +*/ + +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/leds.h> + +static struct led_trigger *trigger; + +static long led_panic_blink (int state) +{ +led_trigger_event (trigger, state ?LED_FULL :LED_OFF ); +return 0 ; +} + +static int __init ledtrig_panic_init (void ) +{ +led_trigger_register_simple ("panic" , &trigger); + panic_blink = led_panic_blink; +return 0 ; +} +device_initcall (ledtrig_panic_init);
Signature · 1 line
2.7.0
Jacek Anaszewski
AppliedPATCH 1/3 leds: trigger: Introduce a kernel panic LED trigger
Hi Ezequiel,
Thanks for the patch. I've tested it on exynos4412-trats2 board with leds-aat1290 driver, by executing:
echo "c" > /proc/sysrq-trigger
I was able to notice the blinking then.
Applied to the for-next branch of linux-leds.git.
Thanks,
Jacek Anaszewski
Quoted 76 lines · Ezequiel Garcia
This commit introduces a new LED trigger which allows to configure a LED to blink on a kernel panic (through
panic_blink).Notice that currently the Openmoko FreeRunner (GTA02) mach code sets
panic_blinkto blink a hard-coded LED. The new trigger is meant to introduce a generic mechanism to achieve this.Signed-off-by Ezequiel Garcia <[email protected]>--- drivers/leds/trigger/Kconfig | 7 +++++++ drivers/leds/trigger/Makefile | 1 + drivers/leds/trigger/ledtrig-panic.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+)create mode 100644
drivers/leds/trigger/ledtrig-panic.cdrivers/leds/trigger/Kconfig +7
-0@@ -108,4 +108,11 @@ config LEDS_TRIGGER_CAMERA This enables direct flash/torch on/off by the driver, kernel space. If unsure, say Y. +config LEDS_TRIGGER_PANIC + bool "LED Panic Trigger" + depends on LEDS_TRIGGERS + help + This allows LEDs to be configured to blink on a kernel panic. + If unsure, say Y. + endif # LEDS_TRIGGERSdrivers/leds/trigger/Makefile +1
-0@@ -8,3 +8,4 @@ obj-$(CONFIG_LEDS_TRIGGER_CPU) += ledtrig-cpu.o obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT) += ledtrig-transient.o obj-$(CONFIG_LEDS_TRIGGER_CAMERA) += ledtrig-camera.o +obj-$(CONFIG_LEDS_TRIGGER_PANIC) += ledtrig-panic.odrivers/leds/trigger/ledtrig-panic.c new file +30
-0@@ -0,0 +1,30 @@ +/* +* Kernel Panic LED Trigger +* +* Copyright 2016 Ezequiel Garcia <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +*/ + +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/leds.h> + +static struct led_trigger *trigger; + +static long led_panic_blink (int state) +{ +led_trigger_event (trigger, state ?LED_FULL :LED_OFF ); +return 0 ; +} + +static int __init ledtrig_panic_init (void ) +{ +led_trigger_register_simple ("panic" , &trigger); + panic_blink = led_panic_blink; +return 0 ; +} +device_initcall (ledtrig_panic_init);
Re: [PATCH 1/3] leds: trigger: Introduce a kernel panic LED trigger
+lkml
Quoted 11 lines · Jacek Anaszewski
Hi Ezequiel,
Thanks for the patch. I've tested it on exynos4412-trats2 board with leds-aat1290 driver, by executing:
echo "c" >
/proc/sysrq-triggerI was able to notice the blinking then.
Applied to the for-next branch of linux-leds.git.
Notice that we currently need LEDs to be dedicated to the panic trigger, which is pretty lame as LEDs are scarce and are most likely assigned to something else.
So, here's a toy patch to switch all the installed LEDs to the panic trigger on kernel panic. Patch is half-baked, but it shows the idea.
(Interestingly, it also blinks the LEDs on a USB keyboard!)
Is there any value in polishing this and find a way upstream?
drivers/leds/led-class.c +16 -0
@@ -321,6 +321,20 @@ void devm_led_classdev_unregister(struct device *dev, }EXPORT_SYMBOL_GPL (devm_led_classdev_unregister); +static int led_panic_notifier (struct notifier_block *nb, +unsigned long code,void *unused) +{ +struct led_classdev *led_cdev; + +list_for_each_entry (led_cdev, &leds_list, node) +led_trigger_set_at_panic (led_cdev,"panic" ); +return NOTIFY_DONE ; +} + +static struct notifier_block led_panic_nb = { + .notifier_call = led_panic_notifier, +}; +static int __init leds_init (void ) { leds_class =class_create (THIS_MODULE ,"leds" );
@@ -328,6 +342,8 @@ static int __init leds_init(void)return PTR_ERR (leds_class); leds_class->pm = &leds_class_dev_pm_ops; leds_class->dev_groups = led_groups; +atomic_notifier_chain_register (&panic_notifier_list, + &led_panic_nb);return 0 ; }
drivers/leds/led-triggers.c +15 -0
@@ -148,6 +148,21 @@ void led_trigger_remove(struct led_classdev *led_cdev) }EXPORT_SYMBOL_GPL (led_trigger_remove); +void led_trigger_set_at_panic (struct led_classdev *led_cdev,const char *name) +{ +struct led_trigger *trig; + +list_for_each_entry (trig, &trigger_list, next_trig) { +if (strcmp (name, trig->name)) +continue ; +list_add_tail (&led_cdev->trig_list, &trig->led_cdevs); + led_cdev->trigger = trig; +if (trig->activate) + trig->activate (led_cdev); +break ; + } +} +void led_trigger_set_default (struct led_classdev *led_cdev) {struct led_trigger *trig;
drivers/leds/leds.h +1 -0
@@ -21,6 +21,7 @@ static inline int led_get_brightness(struct led_classdev *led_cdev)return led_cdev->brightness; } +void led_trigger_set_at_panic (struct led_classdev *led_cdev,const char *name);void led_init_core (struct led_classdev *led_cdev);void led_stop_software_blink (struct led_classdev *led_cdev); void led_set_brightness_nopm(struct led_classdev *led_cdev,
Signature · 6 lines
2.7.0 -- Ezequiel Garcia, VanguardiaSur www.vanguardiasur.com.ar
Re: [PATCH 1/3] leds: trigger: Introduce a kernel panic LED trigger
Hi Ezequiel,
Quoted 19 lines · Ezequiel Garcia
+lkml
Quoted 11 lines · Jacek Anaszewski
Hi Ezequiel,
Thanks for the patch. I've tested it on exynos4412-trats2 board with leds-aat1290 driver, by executing:
echo "c" >
/proc/sysrq-triggerI was able to notice the blinking then.
Applied to the for-next branch of linux-leds.git.
Notice that we currently need LEDs to be dedicated to the panic trigger, which is pretty lame as LEDs are scarce and are most likely assigned to something else.
Quoted 7 lines
So, here's a toy patch to switch all the installed LEDs to the panic trigger on kernel panic. Patch is half-baked, but it shows the idea.
(Interestingly, it also blinks the LEDs on a USB keyboard!)
Is there any value in polishing this and find a way upstream?
I like the idea, but I'd rather explicitly mark LEDs as panic indicators.
How about adding a "kernel-panic-indicator" Device Tree property to common LED bindings? LED class device could be registered for the panic trigger on kernel panic notification only when the property is present.
Adding Rob, Mark and devicetree list.
Quoted 39 lines
drivers/leds/led-class.c +16
-0@@ -321,6 +321,20 @@ void devm_led_classdev_unregister(struct device *dev, }EXPORT_SYMBOL_GPL (devm_led_classdev_unregister); +static int led_panic_notifier (struct notifier_block *nb, +unsigned long code,void *unused) +{ +struct led_classdev *led_cdev; + +list_for_each_entry (led_cdev, &leds_list, node) +led_trigger_set_at_panic (led_cdev,"panic" ); +return NOTIFY_DONE ; +} + +static struct notifier_block led_panic_nb = { + .notifier_call = led_panic_notifier, +}; +static int __init leds_init (void ) { leds_class =class_create (THIS_MODULE ,"leds" );@@ -328,6 +342,8 @@ static int __init leds_init(void)return PTR_ERR (leds_class); leds_class->pm = &leds_class_dev_pm_ops; leds_class->dev_groups = led_groups; +atomic_notifier_chain_register (&panic_notifier_list, + &led_panic_nb);return 0 ; }drivers/leds/led-triggers.c +0
-0
drivers/leds/led-triggers.c void led_trigger_remove(struct led_classdev *led_cdev) · line 152
Quoted 5 lines
drivers/leds/led-triggers.c +2
-0@@ -148,6 +148,21 @@ void led_trigger_remove(struct led_classdev *led_cdev) }EXPORT_SYMBOL_GPL (led_trigger_remove); +void led_trigger_set_at_panic (struct led_classdev *led_cdev,const char *name) +{
"name" parameter is not required, since setting other trigger than panic on kernel panic doesn't make sense.
Quoted 29 lines
drivers/leds/led-triggers.c +13
-0+struct led_trigger *trig; + +list_for_each_entry (trig, &trigger_list, next_trig) { +if (strcmp (name, trig->name)) +continue ; +list_add_tail (&led_cdev->trig_list, &trig->led_cdevs); + led_cdev->trigger = trig; +if (trig->activate) + trig->activate (led_cdev); +break ; + } +} +void led_trigger_set_default (struct led_classdev *led_cdev) {struct led_trigger *trig;drivers/leds/leds.h +1
-0@@ -21,6 +21,7 @@ static inline int led_get_brightness(struct led_classdev *led_cdev)return led_cdev->brightness; } +void led_trigger_set_at_panic (struct led_classdev *led_cdev,const char *name);void led_init_core (struct led_classdev *led_cdev);void led_stop_software_blink (struct led_classdev *led_cdev); void led_set_brightness_nopm(struct led_classdev *led_cdev,
Signature · 2 lines
Best regards, Jacek Anaszewski
Re: [PATCH 1/3] leds: trigger: Introduce a kernel panic LED trigger
Quoted 30 lines · Jacek Anaszewski
Hi Ezequiel,
Quoted 19 lines · Ezequiel Garcia
+lkml
Quoted 11 lines · Jacek Anaszewski
Hi Ezequiel,
Thanks for the patch. I've tested it on exynos4412-trats2 board with leds-aat1290 driver, by executing:
echo "c" >
/proc/sysrq-triggerI was able to notice the blinking then.
Applied to the for-next branch of linux-leds.git.
Notice that we currently need LEDs to be dedicated to the panic trigger, which is pretty lame as LEDs are scarce and are most likely assigned to something else.
Quoted 7 lines
So, here's a toy patch to switch all the installed LEDs to the panic trigger on kernel panic. Patch is half-baked, but it shows the idea.
(Interestingly, it also blinks the LEDs on a USB keyboard!)
Is there any value in polishing this and find a way upstream?
Quoted 7 lines
I like the idea, but I'd rather explicitly mark LEDs as panic indicators.
How about adding a "kernel-panic-indicator" Device Tree property to common LED bindings? LED class device could be registered for the panic trigger on kernel panic notification only when the property is present.
Of course we would need similar solution for ACPI based platforms, however I am not sure if this approach is feasible in that case, since device configuration data is enclosed in firmware then. Adding linux-acpi list.
Quoted 86 lines
Adding Rob, Mark and devicetree list.
Quoted 40 lines
drivers/leds/led-class.c +14
-0@@ -321,6 +321,20 @@ void devm_led_classdev_unregister(struct device *dev, }EXPORT_SYMBOL_GPL (devm_led_classdev_unregister); +static int led_panic_notifier (struct notifier_block *nb, +unsigned long code,void *unused) +{ +struct led_classdev *led_cdev; + +list_for_each_entry (led_cdev, &leds_list, node) +led_trigger_set_at_panic (led_cdev,"panic" ); +return NOTIFY_DONE ; +} + +static struct notifier_block led_panic_nb = { + .notifier_call = led_panic_notifier, +}; +static int __init leds_init (void ) {leds_class = class_create(THIS_MODULE, "leds");drivers/leds/led-class.c +2
-0@@ -328,6 +342,8 @@ static int __init leds_init(void)return PTR_ERR (leds_class); leds_class->pm = &leds_class_dev_pm_ops; leds_class->dev_groups = led_groups; +atomic_notifier_chain_register (&panic_notifier_list, + &led_panic_nb);return 0 ; }drivers/leds/led-triggers.c +0
-0drivers/leds/led-triggers.c void led_trigger_remove(struct led_classdev · line 154
Quoted 7 lines
drivers/leds/led-triggers.c +2
-0@@ -148,6 +148,21 @@ void led_trigger_remove(struct led_classdev *led_cdev) }EXPORT_SYMBOL_GPL (led_trigger_remove); +void led_trigger_set_at_panic (struct led_classdev *led_cdev,const char *name) +{"name" parameter is not required, since setting other trigger than panic on kernel panic doesn't make sense.
Quoted 31 lines
drivers/leds/led-triggers.c +13
-0+struct led_trigger *trig; + +list_for_each_entry (trig, &trigger_list, next_trig) { +if (strcmp (name, trig->name)) +continue ; +list_add_tail (&led_cdev->trig_list, &trig->led_cdevs); + led_cdev->trigger = trig; +if (trig->activate) + trig->activate (led_cdev); +break ; + } +} +void led_trigger_set_default (struct led_classdev *led_cdev){ struct led_trigger *trig;drivers/leds/leds.h +1
-0@@ -21,6 +21,7 @@ static inline int led_get_brightness(struct led_classdev *led_cdev)return led_cdev->brightness; } +void led_trigger_set_at_panic (struct led_classdev *led_cdev,const char *name);void led_init_core (struct led_classdev *led_cdev);void
led_stop_software_blink(struct led_classdev *led_cdev); void led_set_brightness_nopm(structled_classdev*led_cdev,
Signature · 2 lines
Best regards, Jacek Anaszewski
Re: [PATCH 1/3] leds: trigger: Introduce a kernel panic LED trigger
In reply to Ezequiel GarciaQuoted 1 line
(Interestingly, it also blinks the LEDs on a USB keyboard!)
Assuming USB is still working after a kernel panic ...
PATCH 2/3 ARM: configs: Enable panic LED trigger on s3c2410
In reply to Ezequiel GarciaLet's add the panic LED trigger, which will be used by the GTA02 board.
--- arch/arm/configs/s3c2410_defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm/configs/s3c2410_defconfig +1 -0
@@ -385,6 +385,7 @@ CONFIG_LEDS_TRIGGER_TIMER=m CONFIG_LEDS_TRIGGER_HEARTBEAT=m CONFIG_LEDS_TRIGGER_GPIO=m CONFIG_LEDS_TRIGGER_DEFAULT_ON=m +CONFIG_LEDS_TRIGGER_PANIC=y CONFIG_RTC_CLASS=y CONFIG_RTC_DRV_S3C=y CONFIG_EXT2_FS=y
Signature · 1 line
2.7.0
PATCH 3/3 ARM: s3c24xx: Use the panic LED trigger for GTA02
In reply to Ezequiel GarciaLet's take advantage of the recently introduced panic LED trigger, and get rid of the open-coded panic_blink usage.
Built tested only.
--- arch/arm/mach-s3c24xx/mach-gta02.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-)
arch/arm/mach-s3c24xx/mach-gta02.c +16 -19
@@ -71,6 +71,7 @@#include <linux/platform_data/touchscreen-s3c2410.h> #include <linux/platform_data/usb-ohci-s3c2410.h> #include <linux/platform_data/usb-s3c2410_udc.h> +#include <linux/platform_data/leds-s3c24xx.h> #include <mach/fb.h> #include <mach/hardware.h>
@@ -89,22 +90,6 @@static struct pcf50633 *gta02_pcf; -/* -* This gets called frequently when we paniced. -*/ - -static long gta02_panic_blink (int state) -{ -long delay =0 ; -char led; - - led = (state) ?1 :0 ; -gpio_direction_output (GTA02_GPIO_AUX_LED , led); - -return delay; -} - -static struct map_desc gta02_iodesc[]__initdata = { { .virtual =0xe0000000 ,
@@ -500,6 +485,20 @@ static struct platform_device gta02_buttons_device = { }, }; +static struct s3c24xx_led_platdata gta02_panic_led_pdata = { + .name ="panic" , + .gpio =GTA02_GPIO_AUX_LED , + .def_trigger ="panic" , +}; + +static struct platform_device gta02_panic_led_device = { + .name ="s3c24xx_led" , + .id =-1 , + .dev = { + .platform_data = >a02_panic_led_pdata, + }, +}; +static void __init gta02_map_io (void ) {s3c24xx_init_io (gta02_iodesc,ARRAY_SIZE (gta02_iodesc));
@@ -563,9 +562,7 @@ static void gta02_poweroff(void)static void __init gta02_machine_init (void ) { -/* Set the panic callback to turn AUX LED on or off. */ - panic_blink = gta02_panic_blink; - +platform_device_register (>a02_panic_led_device);s3c_pm_init ();#ifdef CONFIG_CHARGER_PCF50633
Signature · 1 line
2.7.0
cover Add a new LED trigger for kernel panics (and use it)
In reply to Ezequiel GarciaQuoted 15 lines · On Tuesday 29 March 2016 17:35:46 Ezequiel Garcia wrote:
This patchset adds a very simple kernel panic LED trigger, by hooking into
panic_blink. I've tested this trigger on ARM Armada XP OpenBlocks AX3-4 machine.The trigger is then used to replace the open-coded
panic_blinkusage in GTA02 board.Note that I don't have a GTA02 board, so the last patch is only built tested.
Ezequiel Garcia (3):
leds: trigger: Introduce a kernel panic LED trigger
ARM: configs: Enable panic LED trigger on s3c2410
ARM: s3c24xx: Use the panic LED trigger for GTA02
Quoted 7 lines
arch/arm/configs/s3c2410_defconfig | 1 + arch/arm/mach-s3c24xx/mach-gta02.c | 35 ++++++++++++++++------------------- drivers/leds/trigger/Kconfig | 7 +++++++ drivers/leds/trigger/Makefile | 1 + drivers/leds/trigger/ledtrig-panic.c | 30 ++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 drivers/leds/trigger/ledtrig-panic.c
Now we just need to port this 13-year old patch:
https://lwn.net/Articles/21857/
;-)
Arnd