[1/5] leds: triggers: Allow to switch the trigger to "panic" on a kernel panic
diff mbox series

Message ID 1459801326-5541-2-git-send-email-ezequiel@vanguardiasur.com.ar
State New, archived
Headers show
Series
  • Extend the LED panic trigger
Related show

Commit Message

Ezequiel Garcia April 4, 2016, 8:22 p.m. UTC
This commit adds a new led_cdev flag LED_BLINK_AT_PANIC, which
allows to mark a specific LED to be switched to the "panic"
trigger, on a kernel panic.

This is useful to allow the user to assign a regular trigger
to a given LED, and still blink that LED on a kernel panic.

Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
---
 drivers/leds/led-triggers.c | 52 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/leds.h        |  1 +
 2 files changed, 53 insertions(+)

Comments

Jacek Anaszewski April 5, 2016, 9:36 p.m. UTC | #1
Hi Ezequiel,

Thanks for the patch. I have one comment below.

On 04/04/2016 10:22 PM, Ezequiel Garcia wrote:
> This commit adds a new led_cdev flag LED_BLINK_AT_PANIC, which
> allows to mark a specific LED to be switched to the "panic"
> trigger, on a kernel panic.
>
> This is useful to allow the user to assign a regular trigger
> to a given LED, and still blink that LED on a kernel panic.
>
> Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
> ---
>   drivers/leds/led-triggers.c | 52 +++++++++++++++++++++++++++++++++++++++++++++
>   include/linux/leds.h        |  1 +
>   2 files changed, 53 insertions(+)
>
> diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
> index 2181581795d3..f5c9d7c4d181 100644
> --- a/drivers/leds/led-triggers.c
> +++ b/drivers/leds/led-triggers.c
> @@ -148,6 +148,43 @@ void led_trigger_remove(struct led_classdev *led_cdev)
>   }
>   EXPORT_SYMBOL_GPL(led_trigger_remove);
>
> +/*
> + * This is a called in a special context by the atomic panic
> + * notifier. This means the trigger can be changed without
> + * worrying about locking.
> + */
> +static void led_trigger_set_panic(struct led_classdev *led_cdev)
> +{
> +	struct led_trigger *trig;
> +
> +	list_for_each_entry(trig, &trigger_list, next_trig) {
> +		if (strcmp("panic", trig->name))
> +			continue;
> +		if (led_cdev->trigger)
> +			list_del(&led_cdev->trig_list);
> +		list_add_tail(&led_cdev->trig_list, &trig->led_cdevs);
> +		led_cdev->trigger = trig;
> +		if (trig->activate)
> +			trig->activate(led_cdev);
> +		break;
> +	}
> +}
> +
> +static int led_trigger_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)
> +		if (led_cdev->flags & LED_BLINK_AT_PANIC)
> +			led_trigger_set_panic(led_cdev);
> +	return NOTIFY_DONE;
> +}
> +
> +static struct notifier_block led_trigger_panic_nb = {
> +	.notifier_call = led_trigger_panic_notifier,
> +};
> +
>   void led_trigger_set_default(struct led_classdev *led_cdev)
>   {
>   	struct led_trigger *trig;
> @@ -356,6 +393,21 @@ void led_trigger_unregister_simple(struct led_trigger *trig)
>   }
>   EXPORT_SYMBOL_GPL(led_trigger_unregister_simple);
>
> +static int __init leds_trigger_init(void)
> +{
> +	atomic_notifier_chain_register(&panic_notifier_list,
> +				       &led_trigger_panic_nb);
> +	return 0;
> +}
> +
> +static void __exit leds_trigger_exit(void)
> +{
> +	atomic_notifier_chain_unregister(&panic_notifier_list,
> +					 &led_trigger_panic_nb);
> +}
> +module_init(leds_trigger_init);
> +module_exit(leds_trigger_exit);
> +
>   MODULE_AUTHOR("Richard Purdie");
>   MODULE_LICENSE("GPL");
>   MODULE_DESCRIPTION("LED Triggers Core");
> diff --git a/include/linux/leds.h b/include/linux/leds.h
> index f203a8f89d30..7f1428bb1e69 100644
> --- a/include/linux/leds.h
> +++ b/include/linux/leds.h
> @@ -50,6 +50,7 @@ struct led_classdev {
>   #define LED_SYSFS_DISABLE	(1 << 22)
>   #define LED_DEV_CAP_FLASH	(1 << 23)
>   #define LED_HW_PLUGGABLE	(1 << 24)
> +#define LED_BLINK_AT_PANIC	(1 << 25)

LED_BLINK prefixed macros control LED subsystem inherent
blinking feature.

Would you mind renaming it to LED_PANIC_INDICATOR?

>
>   	/* Set LED brightness level
>   	 * Must not sleep. Use brightness_set_blocking for drivers
>
Pavel Machek April 24, 2016, 9:25 a.m. UTC | #2
On Mon 2016-04-04 17:22:02, Ezequiel Garcia wrote:
> This commit adds a new led_cdev flag LED_BLINK_AT_PANIC, which
> allows to mark a specific LED to be switched to the "panic"
> trigger, on a kernel panic.
> 
> This is useful to allow the user to assign a regular trigger
> to a given LED, and still blink that LED on a kernel panic.
> 
> Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>


>  drivers/leds/led-triggers.c | 52 +++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/leds.h        |  1 +

Could we get this out of the core? I'm pretty sure most users are not
interested...

								Pavel
								
> +/*
> + * This is a called in a special context by the atomic panic
> + * notifier. This means the trigger can be changed without
> + * worrying about locking.
> + */
> +static void led_trigger_set_panic(struct led_classdev *led_cdev)
> +{
> +	struct led_trigger *trig;
> +
> +	list_for_each_entry(trig, &trigger_list, next_trig) {
> +		if (strcmp("panic", trig->name))
> +			continue;
> +		if (led_cdev->trigger)
> +			list_del(&led_cdev->trig_list);
> +		list_add_tail(&led_cdev->trig_list, &trig->led_cdevs);
> +		led_cdev->trigger = trig;
> +		if (trig->activate)
> +			trig->activate(led_cdev);
> +		break;
> +	}
> +}
> +
> +static int led_trigger_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)
> +		if (led_cdev->flags & LED_BLINK_AT_PANIC)
> +			led_trigger_set_panic(led_cdev);
> +	return NOTIFY_DONE;
> +}
> +
> +static struct notifier_block led_trigger_panic_nb = {
> +	.notifier_call = led_trigger_panic_notifier,
> +};
> +
>  void led_trigger_set_default(struct led_classdev *led_cdev)
>  {
>  	struct led_trigger *trig;
> @@ -356,6 +393,21 @@ void led_trigger_unregister_simple(struct led_trigger *trig)
>  }
>  EXPORT_SYMBOL_GPL(led_trigger_unregister_simple);
>  
> +static int __init leds_trigger_init(void)
> +{
> +	atomic_notifier_chain_register(&panic_notifier_list,
> +				       &led_trigger_panic_nb);
> +	return 0;
> +}
> +
> +static void __exit leds_trigger_exit(void)
> +{
> +	atomic_notifier_chain_unregister(&panic_notifier_list,
> +					 &led_trigger_panic_nb);
> +}
> +module_init(leds_trigger_init);
> +module_exit(leds_trigger_exit);
> +
>  MODULE_AUTHOR("Richard Purdie");
>  MODULE_LICENSE("GPL");
>  MODULE_DESCRIPTION("LED Triggers Core");
> diff --git a/include/linux/leds.h b/include/linux/leds.h
> index f203a8f89d30..7f1428bb1e69 100644
> --- a/include/linux/leds.h
> +++ b/include/linux/leds.h
> @@ -50,6 +50,7 @@ struct led_classdev {
>  #define LED_SYSFS_DISABLE	(1 << 22)
>  #define LED_DEV_CAP_FLASH	(1 << 23)
>  #define LED_HW_PLUGGABLE	(1 << 24)
> +#define LED_BLINK_AT_PANIC	(1 << 25)
>  
>  	/* Set LED brightness level
>  	 * Must not sleep. Use brightness_set_blocking for drivers
Pavel Machek April 24, 2016, 9:29 a.m. UTC | #3
On Sun 2016-04-24 11:25:51, Pavel Machek wrote:
> On Mon 2016-04-04 17:22:02, Ezequiel Garcia wrote:
> > This commit adds a new led_cdev flag LED_BLINK_AT_PANIC, which
> > allows to mark a specific LED to be switched to the "panic"
> > trigger, on a kernel panic.
> > 
> > This is useful to allow the user to assign a regular trigger
> > to a given LED, and still blink that LED on a kernel panic.
> > 
> > Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
> 
> 
> >  drivers/leds/led-triggers.c | 52 +++++++++++++++++++++++++++++++++++++++++++++
> >  include/linux/leds.h        |  1 +
> 
> Could we get this out of the core? I'm pretty sure most users are not
> interested...

Thinking about it some more....

This is not really a trigger. This is very special. Maybe hard-coded
handling, like we do for keyboard leds on x86 would be suitable?


> 
> 								Pavel
> 								
> > +/*
> > + * This is a called in a special context by the atomic panic
> > + * notifier. This means the trigger can be changed without
> > + * worrying about locking.
> > + */
> > +static void led_trigger_set_panic(struct led_classdev *led_cdev)
> > +{
> > +	struct led_trigger *trig;
> > +
> > +	list_for_each_entry(trig, &trigger_list, next_trig) {
> > +		if (strcmp("panic", trig->name))
> > +			continue;
> > +		if (led_cdev->trigger)
> > +			list_del(&led_cdev->trig_list);
> > +		list_add_tail(&led_cdev->trig_list, &trig->led_cdevs);
> > +		led_cdev->trigger = trig;
> > +		if (trig->activate)
> > +			trig->activate(led_cdev);
> > +		break;
> > +	}
> > +}
> > +
> > +static int led_trigger_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)
> > +		if (led_cdev->flags & LED_BLINK_AT_PANIC)
> > +			led_trigger_set_panic(led_cdev);
> > +	return NOTIFY_DONE;
> > +}
> > +
> > +static struct notifier_block led_trigger_panic_nb = {
> > +	.notifier_call = led_trigger_panic_notifier,
> > +};
> > +
> >  void led_trigger_set_default(struct led_classdev *led_cdev)
> >  {
> >  	struct led_trigger *trig;
> > @@ -356,6 +393,21 @@ void led_trigger_unregister_simple(struct led_trigger *trig)
> >  }
> >  EXPORT_SYMBOL_GPL(led_trigger_unregister_simple);
> >  
> > +static int __init leds_trigger_init(void)
> > +{
> > +	atomic_notifier_chain_register(&panic_notifier_list,
> > +				       &led_trigger_panic_nb);
> > +	return 0;
> > +}
> > +
> > +static void __exit leds_trigger_exit(void)
> > +{
> > +	atomic_notifier_chain_unregister(&panic_notifier_list,
> > +					 &led_trigger_panic_nb);
> > +}
> > +module_init(leds_trigger_init);
> > +module_exit(leds_trigger_exit);
> > +
> >  MODULE_AUTHOR("Richard Purdie");
> >  MODULE_LICENSE("GPL");
> >  MODULE_DESCRIPTION("LED Triggers Core");
> > diff --git a/include/linux/leds.h b/include/linux/leds.h
> > index f203a8f89d30..7f1428bb1e69 100644
> > --- a/include/linux/leds.h
> > +++ b/include/linux/leds.h
> > @@ -50,6 +50,7 @@ struct led_classdev {
> >  #define LED_SYSFS_DISABLE	(1 << 22)
> >  #define LED_DEV_CAP_FLASH	(1 << 23)
> >  #define LED_HW_PLUGGABLE	(1 << 24)
> > +#define LED_BLINK_AT_PANIC	(1 << 25)
> >  
> >  	/* Set LED brightness level
> >  	 * Must not sleep. Use brightness_set_blocking for drivers
>
Jacek Anaszewski April 25, 2016, 6:56 a.m. UTC | #4
On 04/24/2016 11:29 AM, Pavel Machek wrote:
> On Sun 2016-04-24 11:25:51, Pavel Machek wrote:
>> On Mon 2016-04-04 17:22:02, Ezequiel Garcia wrote:
>>> This commit adds a new led_cdev flag LED_BLINK_AT_PANIC, which
>>> allows to mark a specific LED to be switched to the "panic"
>>> trigger, on a kernel panic.
>>>
>>> This is useful to allow the user to assign a regular trigger
>>> to a given LED, and still blink that LED on a kernel panic.
>>>
>>> Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
>>
>>
>>>   drivers/leds/led-triggers.c | 52 +++++++++++++++++++++++++++++++++++++++++++++
>>>   include/linux/leds.h        |  1 +
>>
>> Could we get this out of the core? I'm pretty sure most users are not
>> interested...

Good point.

> Thinking about it some more....
>
> This is not really a trigger. This is very special. Maybe hard-coded
> handling, like we do for keyboard leds on x86 would be suitable?

Could you please spot the piece of code you have on mind?

>
>
>>
>> 								Pavel
>> 								
>>> +/*
>>> + * This is a called in a special context by the atomic panic
>>> + * notifier. This means the trigger can be changed without
>>> + * worrying about locking.
>>> + */
>>> +static void led_trigger_set_panic(struct led_classdev *led_cdev)
>>> +{
>>> +	struct led_trigger *trig;
>>> +
>>> +	list_for_each_entry(trig, &trigger_list, next_trig) {
>>> +		if (strcmp("panic", trig->name))
>>> +			continue;
>>> +		if (led_cdev->trigger)
>>> +			list_del(&led_cdev->trig_list);
>>> +		list_add_tail(&led_cdev->trig_list, &trig->led_cdevs);
>>> +		led_cdev->trigger = trig;
>>> +		if (trig->activate)
>>> +			trig->activate(led_cdev);
>>> +		break;
>>> +	}
>>> +}
>>> +
>>> +static int led_trigger_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)
>>> +		if (led_cdev->flags & LED_BLINK_AT_PANIC)
>>> +			led_trigger_set_panic(led_cdev);
>>> +	return NOTIFY_DONE;
>>> +}
>>> +
>>> +static struct notifier_block led_trigger_panic_nb = {
>>> +	.notifier_call = led_trigger_panic_notifier,
>>> +};
>>> +
>>>   void led_trigger_set_default(struct led_classdev *led_cdev)
>>>   {
>>>   	struct led_trigger *trig;
>>> @@ -356,6 +393,21 @@ void led_trigger_unregister_simple(struct led_trigger *trig)
>>>   }
>>>   EXPORT_SYMBOL_GPL(led_trigger_unregister_simple);
>>>
>>> +static int __init leds_trigger_init(void)
>>> +{
>>> +	atomic_notifier_chain_register(&panic_notifier_list,
>>> +				       &led_trigger_panic_nb);
>>> +	return 0;
>>> +}
>>> +
>>> +static void __exit leds_trigger_exit(void)
>>> +{
>>> +	atomic_notifier_chain_unregister(&panic_notifier_list,
>>> +					 &led_trigger_panic_nb);
>>> +}
>>> +module_init(leds_trigger_init);
>>> +module_exit(leds_trigger_exit);
>>> +
>>>   MODULE_AUTHOR("Richard Purdie");
>>>   MODULE_LICENSE("GPL");
>>>   MODULE_DESCRIPTION("LED Triggers Core");
>>> diff --git a/include/linux/leds.h b/include/linux/leds.h
>>> index f203a8f89d30..7f1428bb1e69 100644
>>> --- a/include/linux/leds.h
>>> +++ b/include/linux/leds.h
>>> @@ -50,6 +50,7 @@ struct led_classdev {
>>>   #define LED_SYSFS_DISABLE	(1 << 22)
>>>   #define LED_DEV_CAP_FLASH	(1 << 23)
>>>   #define LED_HW_PLUGGABLE	(1 << 24)
>>> +#define LED_BLINK_AT_PANIC	(1 << 25)
>>>
>>>   	/* Set LED brightness level
>>>   	 * Must not sleep. Use brightness_set_blocking for drivers
>>
>
Ezequiel Garcia April 25, 2016, 4:27 p.m. UTC | #5
On 25 April 2016 at 03:56, Jacek Anaszewski <j.anaszewski@samsung.com> wrote:
> On 04/24/2016 11:29 AM, Pavel Machek wrote:
>>
>> On Sun 2016-04-24 11:25:51, Pavel Machek wrote:
>>>
>>> On Mon 2016-04-04 17:22:02, Ezequiel Garcia wrote:
>>>>
>>>> This commit adds a new led_cdev flag LED_BLINK_AT_PANIC, which
>>>> allows to mark a specific LED to be switched to the "panic"
>>>> trigger, on a kernel panic.
>>>>
>>>> This is useful to allow the user to assign a regular trigger
>>>> to a given LED, and still blink that LED on a kernel panic.
>>>>
>>>> Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
>>>
>>>
>>>
>>>>   drivers/leds/led-triggers.c | 52
>>>> +++++++++++++++++++++++++++++++++++++++++++++
>>>>   include/linux/leds.h        |  1 +
>>>
>>>
>>> Could we get this out of the core? I'm pretty sure most users are not
>>> interested...
>
>
> Good point.
>

Not sure how we can get it out of the core, and still implement it.

The goal is to run-time switch user-specified LEDs and blink them when
the kernel panics, and so it needs to mess up with some core private
structures.

Unless we don't want this feature at all.
Jacek Anaszewski April 26, 2016, 7:15 a.m. UTC | #6
Hi Ezequiel,

On 04/25/2016 06:27 PM, Ezequiel Garcia wrote:
> On 25 April 2016 at 03:56, Jacek Anaszewski <j.anaszewski@samsung.com> wrote:
>> On 04/24/2016 11:29 AM, Pavel Machek wrote:
>>>
>>> On Sun 2016-04-24 11:25:51, Pavel Machek wrote:
>>>>
>>>> On Mon 2016-04-04 17:22:02, Ezequiel Garcia wrote:
>>>>>
>>>>> This commit adds a new led_cdev flag LED_BLINK_AT_PANIC, which
>>>>> allows to mark a specific LED to be switched to the "panic"
>>>>> trigger, on a kernel panic.
>>>>>
>>>>> This is useful to allow the user to assign a regular trigger
>>>>> to a given LED, and still blink that LED on a kernel panic.
>>>>>
>>>>> Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
>>>>
>>>>
>>>>
>>>>>    drivers/leds/led-triggers.c | 52
>>>>> +++++++++++++++++++++++++++++++++++++++++++++
>>>>>    include/linux/leds.h        |  1 +
>>>>
>>>>
>>>> Could we get this out of the core? I'm pretty sure most users are not
>>>> interested...
>>
>>
>> Good point.
>>
>
> Not sure how we can get it out of the core, and still implement it.
>
> The goal is to run-time switch user-specified LEDs and blink them when
> the kernel panics, and so it needs to mess up with some core private
> structures.
>
> Unless we don't want this feature at all.
>

It seems that the entire added code can be easily moved to a separate
module, let's say led-panic-notifier.c ? It should select
LEDS_TRIGGER_PANIC, as it would make no sense to have the former enabled
without the latter.
Ezequiel Garcia April 27, 2016, 8:10 p.m. UTC | #7
On 26 April 2016 at 04:15, Jacek Anaszewski <j.anaszewski@samsung.com> wrote:
> Hi Ezequiel,
>
> On 04/25/2016 06:27 PM, Ezequiel Garcia wrote:
>>
>> On 25 April 2016 at 03:56, Jacek Anaszewski <j.anaszewski@samsung.com>
>> wrote:
>>>
>>> On 04/24/2016 11:29 AM, Pavel Machek wrote:
>>>>
>>>>
>>>> On Sun 2016-04-24 11:25:51, Pavel Machek wrote:
>>>>>
>>>>>
>>>>> On Mon 2016-04-04 17:22:02, Ezequiel Garcia wrote:
>>>>>>
>>>>>>
>>>>>> This commit adds a new led_cdev flag LED_BLINK_AT_PANIC, which
>>>>>> allows to mark a specific LED to be switched to the "panic"
>>>>>> trigger, on a kernel panic.
>>>>>>
>>>>>> This is useful to allow the user to assign a regular trigger
>>>>>> to a given LED, and still blink that LED on a kernel panic.
>>>>>>
>>>>>> Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>    drivers/leds/led-triggers.c | 52
>>>>>> +++++++++++++++++++++++++++++++++++++++++++++
>>>>>>    include/linux/leds.h        |  1 +
>>>>>
>>>>>
>>>>>
>>>>> Could we get this out of the core? I'm pretty sure most users are not
>>>>> interested...
>>>
>>>
>>>
>>> Good point.
>>>
>>
>> Not sure how we can get it out of the core, and still implement it.
>>
>> The goal is to run-time switch user-specified LEDs and blink them when
>> the kernel panics, and so it needs to mess up with some core private
>> structures.
>>
>> Unless we don't want this feature at all.
>>
>
> It seems that the entire added code can be easily moved to a separate
> module, let's say led-panic-notifier.c ? It should select
> LEDS_TRIGGER_PANIC, as it would make no sense to have the former enabled
> without the latter.
>

OK, let me try that.
Pavel Machek May 2, 2016, 7:06 a.m. UTC | #8
On Mon 2016-04-25 08:56:46, Jacek Anaszewski wrote:
> On 04/24/2016 11:29 AM, Pavel Machek wrote:
> >On Sun 2016-04-24 11:25:51, Pavel Machek wrote:
> >>On Mon 2016-04-04 17:22:02, Ezequiel Garcia wrote:
> >>>This commit adds a new led_cdev flag LED_BLINK_AT_PANIC, which
> >>>allows to mark a specific LED to be switched to the "panic"
> >>>trigger, on a kernel panic.
> >>>
> >>>This is useful to allow the user to assign a regular trigger
> >>>to a given LED, and still blink that LED on a kernel panic.
> >>>
> >>>Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
> >>
> >>
> >>>  drivers/leds/led-triggers.c | 52 +++++++++++++++++++++++++++++++++++++++++++++
> >>>  include/linux/leds.h        |  1 +
> >>
> >>Could we get this out of the core? I'm pretty sure most users are not
> >>interested...
> 
> Good point.

Dunno. Perhaps we can have something like struct led *panic_led, which
architecture can set, and then some helper that would blink the panic
led...? Should be smaller than this and will only be compiled on
platforms where it makes sense. On x86 we already have such support...

> >Thinking about it some more....
> >
> >This is not really a trigger. This is very special. Maybe hard-coded
> >handling, like we do for keyboard leds on x86 would be suitable?
> 
> Could you please spot the piece of code you have on mind?

drivers/input/serio/i8042.c: * i8042_panic_blink() will turn the keyboard LEDs on or off and is called

			       			   	     	 	  Pavel

Patch
diff mbox series

diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index 2181581795d3..f5c9d7c4d181 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -148,6 +148,43 @@  void led_trigger_remove(struct led_classdev *led_cdev)
 }
 EXPORT_SYMBOL_GPL(led_trigger_remove);
 
+/*
+ * This is a called in a special context by the atomic panic
+ * notifier. This means the trigger can be changed without
+ * worrying about locking.
+ */
+static void led_trigger_set_panic(struct led_classdev *led_cdev)
+{
+	struct led_trigger *trig;
+
+	list_for_each_entry(trig, &trigger_list, next_trig) {
+		if (strcmp("panic", trig->name))
+			continue;
+		if (led_cdev->trigger)
+			list_del(&led_cdev->trig_list);
+		list_add_tail(&led_cdev->trig_list, &trig->led_cdevs);
+		led_cdev->trigger = trig;
+		if (trig->activate)
+			trig->activate(led_cdev);
+		break;
+	}
+}
+
+static int led_trigger_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)
+		if (led_cdev->flags & LED_BLINK_AT_PANIC)
+			led_trigger_set_panic(led_cdev);
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block led_trigger_panic_nb = {
+	.notifier_call = led_trigger_panic_notifier,
+};
+
 void led_trigger_set_default(struct led_classdev *led_cdev)
 {
 	struct led_trigger *trig;
@@ -356,6 +393,21 @@  void led_trigger_unregister_simple(struct led_trigger *trig)
 }
 EXPORT_SYMBOL_GPL(led_trigger_unregister_simple);
 
+static int __init leds_trigger_init(void)
+{
+	atomic_notifier_chain_register(&panic_notifier_list,
+				       &led_trigger_panic_nb);
+	return 0;
+}
+
+static void __exit leds_trigger_exit(void)
+{
+	atomic_notifier_chain_unregister(&panic_notifier_list,
+					 &led_trigger_panic_nb);
+}
+module_init(leds_trigger_init);
+module_exit(leds_trigger_exit);
+
 MODULE_AUTHOR("Richard Purdie");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("LED Triggers Core");
diff --git a/include/linux/leds.h b/include/linux/leds.h
index f203a8f89d30..7f1428bb1e69 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -50,6 +50,7 @@  struct led_classdev {
 #define LED_SYSFS_DISABLE	(1 << 22)
 #define LED_DEV_CAP_FLASH	(1 << 23)
 #define LED_HW_PLUGGABLE	(1 << 24)
+#define LED_BLINK_AT_PANIC	(1 << 25)
 
 	/* Set LED brightness level
 	 * Must not sleep. Use brightness_set_blocking for drivers