linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Add new API is_being_panic()
@ 2020-12-18 11:44 Xiaoming Ni
  2020-12-18 11:44 ` [PATCH 1/4] panic: " Xiaoming Ni
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Xiaoming Ni @ 2020-12-18 11:44 UTC (permalink / raw)
  To: linux-kernel, linux-leds, pavel, dmurphy, akpm, keescook,
	gpiccoli, penguin-kernel
  Cc: nixiaoming, wangle6

Add is_being_panic() to check whether the system is in panic state.
Used to replace the global variable used to determine the panic status
in other features: hung_task ledtrig-activity ledtrig-heartbeat


Xiaoming Ni (4):
  panic: Add new API is_being_panic()
  hung_task: Replace "did_panic" with is_be_panic()
  leds:trigger:ledtrig-activity Replace "panic_detected" with
    is_be_panic()
  leds:trigger:ledtrig-heartbeat: Replace "panic_heartbeats" with
    is_be_panic()

 drivers/leds/trigger/ledtrig-activity.c  | 19 +------------------
 drivers/leds/trigger/ledtrig-heartbeat.c | 19 +------------------
 include/linux/kernel.h                   |  1 +
 kernel/hung_task.c                       | 17 +----------------
 kernel/panic.c                           |  6 ++++++
 5 files changed, 10 insertions(+), 52 deletions(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/4] panic: Add new API is_being_panic()
  2020-12-18 11:44 [PATCH 0/4] Add new API is_being_panic() Xiaoming Ni
@ 2020-12-18 11:44 ` Xiaoming Ni
  2020-12-18 11:44 ` [PATCH 2/4] hung_task: Replace "did_panic" with is_be_panic() Xiaoming Ni
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Xiaoming Ni @ 2020-12-18 11:44 UTC (permalink / raw)
  To: linux-kernel, linux-leds, pavel, dmurphy, akpm, keescook,
	gpiccoli, penguin-kernel
  Cc: nixiaoming, wangle6

Add is_being_panic() to check whether the system is in panic state.
Used to replace the global variable used to determine the panic status
in other features: hung_task ledtrig-activity ledtrig-heartbeat

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
---
 include/linux/kernel.h | 1 +
 kernel/panic.c         | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index f7902d8c1048..3d6f344771c1 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -167,6 +167,7 @@ void __might_fault(const char *file, int line);
 static inline void might_fault(void) { }
 #endif
 
+extern bool is_being_panic(void);
 extern struct atomic_notifier_head panic_notifier_list;
 extern long (*panic_blink)(int state);
 __printf(1, 2)
diff --git a/kernel/panic.c b/kernel/panic.c
index 332736a72a58..3b6a487702b0 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -125,6 +125,12 @@ void __weak crash_smp_send_stop(void)
 
 atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID);
 
+bool is_being_panic(void)
+{
+	return (atomic_read(&panic_cpu) != PANIC_CPU_INVALID);
+}
+EXPORT_SYMBOL(is_being_panic);
+
 /*
  * A variant of panic() called from NMI context. We return if we've already
  * panicked on this CPU. If another CPU already panicked, loop in
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/4] hung_task: Replace "did_panic" with is_be_panic()
  2020-12-18 11:44 [PATCH 0/4] Add new API is_being_panic() Xiaoming Ni
  2020-12-18 11:44 ` [PATCH 1/4] panic: " Xiaoming Ni
@ 2020-12-18 11:44 ` Xiaoming Ni
  2020-12-18 12:59   ` Pavel Machek
  2020-12-18 11:44 ` [PATCH 3/4] leds:trigger:ledtrig-activity Replace "panic_detected" " Xiaoming Ni
  2020-12-18 11:44 ` [PATCH 4/4] leds:trigger:ledtrig-heartbeat: Replace "panic_heartbeats" " Xiaoming Ni
  3 siblings, 1 reply; 9+ messages in thread
From: Xiaoming Ni @ 2020-12-18 11:44 UTC (permalink / raw)
  To: linux-kernel, linux-leds, pavel, dmurphy, akpm, keescook,
	gpiccoli, penguin-kernel
  Cc: nixiaoming, wangle6

Replace the global variable "did_panic" with is_be_panic()

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
---
 kernel/hung_task.c | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/kernel/hung_task.c b/kernel/hung_task.c
index bb2e3e15c84c..3374b993da4c 100644
--- a/kernel/hung_task.c
+++ b/kernel/hung_task.c
@@ -50,7 +50,6 @@ unsigned long __read_mostly sysctl_hung_task_check_interval_secs;
 
 int __read_mostly sysctl_hung_task_warnings = 10;
 
-static int __read_mostly did_panic;
 static bool hung_task_show_lock;
 static bool hung_task_call_panic;
 static bool hung_task_show_all_bt;
@@ -72,18 +71,6 @@ unsigned int __read_mostly sysctl_hung_task_all_cpu_backtrace;
 unsigned int __read_mostly sysctl_hung_task_panic =
 				CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE;
 
-static int
-hung_task_panic(struct notifier_block *this, unsigned long event, void *ptr)
-{
-	did_panic = 1;
-
-	return NOTIFY_DONE;
-}
-
-static struct notifier_block panic_block = {
-	.notifier_call = hung_task_panic,
-};
-
 static void check_hung_task(struct task_struct *t, unsigned long timeout)
 {
 	unsigned long switch_count = t->nvcsw + t->nivcsw;
@@ -223,7 +210,7 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
 	 * If the system crashed already then all bets are off,
 	 * do not report extra hung tasks:
 	 */
-	if (test_taint(TAINT_DIE) || did_panic)
+	if (test_taint(TAINT_DIE) || unlikely(is_being_panic()))
 		return;
 
 	hung_task_show_lock = false;
@@ -347,8 +334,6 @@ static int watchdog(void *dummy)
 
 static int __init hung_task_init(void)
 {
-	atomic_notifier_chain_register(&panic_notifier_list, &panic_block);
-
 	/* Disable hung task detector on suspend */
 	pm_notifier(hungtask_pm_notify, 0);
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/4] leds:trigger:ledtrig-activity Replace "panic_detected" with is_be_panic()
  2020-12-18 11:44 [PATCH 0/4] Add new API is_being_panic() Xiaoming Ni
  2020-12-18 11:44 ` [PATCH 1/4] panic: " Xiaoming Ni
  2020-12-18 11:44 ` [PATCH 2/4] hung_task: Replace "did_panic" with is_be_panic() Xiaoming Ni
@ 2020-12-18 11:44 ` Xiaoming Ni
  2020-12-18 11:44 ` [PATCH 4/4] leds:trigger:ledtrig-heartbeat: Replace "panic_heartbeats" " Xiaoming Ni
  3 siblings, 0 replies; 9+ messages in thread
From: Xiaoming Ni @ 2020-12-18 11:44 UTC (permalink / raw)
  To: linux-kernel, linux-leds, pavel, dmurphy, akpm, keescook,
	gpiccoli, penguin-kernel
  Cc: nixiaoming, wangle6

Replace the global variable "panic_detected" with is_be_panic()

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
---
 drivers/leds/trigger/ledtrig-activity.c | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)

diff --git a/drivers/leds/trigger/ledtrig-activity.c b/drivers/leds/trigger/ledtrig-activity.c
index 14ba7faaed9e..bbacb3dbe341 100644
--- a/drivers/leds/trigger/ledtrig-activity.c
+++ b/drivers/leds/trigger/ledtrig-activity.c
@@ -17,8 +17,6 @@
 #include <linux/timer.h>
 #include "../leds.h"
 
-static int panic_detected;
-
 struct activity_data {
 	struct timer_list timer;
 	struct led_classdev *led_cdev;
@@ -47,7 +45,7 @@ static void led_activity_function(struct timer_list *t)
 	if (test_and_clear_bit(LED_BLINK_BRIGHTNESS_CHANGE, &led_cdev->work_flags))
 		led_cdev->blink_brightness = led_cdev->new_blink_brightness;
 
-	if (unlikely(panic_detected)) {
+	if (unlikely(is_being_panic())) {
 		/* full brightness in case of panic */
 		led_set_brightness_nosleep(led_cdev, led_cdev->blink_brightness);
 		return;
@@ -226,28 +224,15 @@ static int activity_reboot_notifier(struct notifier_block *nb,
 	return NOTIFY_DONE;
 }
 
-static int activity_panic_notifier(struct notifier_block *nb,
-                                   unsigned long code, void *unused)
-{
-	panic_detected = 1;
-	return NOTIFY_DONE;
-}
-
 static struct notifier_block activity_reboot_nb = {
 	.notifier_call = activity_reboot_notifier,
 };
 
-static struct notifier_block activity_panic_nb = {
-	.notifier_call = activity_panic_notifier,
-};
-
 static int __init activity_init(void)
 {
 	int rc = led_trigger_register(&activity_led_trigger);
 
 	if (!rc) {
-		atomic_notifier_chain_register(&panic_notifier_list,
-					       &activity_panic_nb);
 		register_reboot_notifier(&activity_reboot_nb);
 	}
 	return rc;
@@ -256,8 +241,6 @@ static int __init activity_init(void)
 static void __exit activity_exit(void)
 {
 	unregister_reboot_notifier(&activity_reboot_nb);
-	atomic_notifier_chain_unregister(&panic_notifier_list,
-					 &activity_panic_nb);
 	led_trigger_unregister(&activity_led_trigger);
 }
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/4] leds:trigger:ledtrig-heartbeat: Replace "panic_heartbeats" with is_be_panic()
  2020-12-18 11:44 [PATCH 0/4] Add new API is_being_panic() Xiaoming Ni
                   ` (2 preceding siblings ...)
  2020-12-18 11:44 ` [PATCH 3/4] leds:trigger:ledtrig-activity Replace "panic_detected" " Xiaoming Ni
@ 2020-12-18 11:44 ` Xiaoming Ni
  3 siblings, 0 replies; 9+ messages in thread
From: Xiaoming Ni @ 2020-12-18 11:44 UTC (permalink / raw)
  To: linux-kernel, linux-leds, pavel, dmurphy, akpm, keescook,
	gpiccoli, penguin-kernel
  Cc: nixiaoming, wangle6

Replace the global variable "panic_heartbeats" with is_be_panic()

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
---
 drivers/leds/trigger/ledtrig-heartbeat.c | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)

diff --git a/drivers/leds/trigger/ledtrig-heartbeat.c b/drivers/leds/trigger/ledtrig-heartbeat.c
index 36b6709afe9f..3c34d49f0ed8 100644
--- a/drivers/leds/trigger/ledtrig-heartbeat.c
+++ b/drivers/leds/trigger/ledtrig-heartbeat.c
@@ -19,8 +19,6 @@
 #include <linux/reboot.h>
 #include "../leds.h"
 
-static int panic_heartbeats;
-
 struct heartbeat_trig_data {
 	struct led_classdev *led_cdev;
 	unsigned int phase;
@@ -39,7 +37,7 @@ static void led_heartbeat_function(struct timer_list *t)
 
 	led_cdev = heartbeat_data->led_cdev;
 
-	if (unlikely(panic_heartbeats)) {
+	if (unlikely(is_being_panic())) {
 		led_set_brightness_nosleep(led_cdev, LED_OFF);
 		return;
 	}
@@ -169,28 +167,15 @@ static int heartbeat_reboot_notifier(struct notifier_block *nb,
 	return NOTIFY_DONE;
 }
 
-static int heartbeat_panic_notifier(struct notifier_block *nb,
-				     unsigned long code, void *unused)
-{
-	panic_heartbeats = 1;
-	return NOTIFY_DONE;
-}
-
 static struct notifier_block heartbeat_reboot_nb = {
 	.notifier_call = heartbeat_reboot_notifier,
 };
 
-static struct notifier_block heartbeat_panic_nb = {
-	.notifier_call = heartbeat_panic_notifier,
-};
-
 static int __init heartbeat_trig_init(void)
 {
 	int rc = led_trigger_register(&heartbeat_led_trigger);
 
 	if (!rc) {
-		atomic_notifier_chain_register(&panic_notifier_list,
-					       &heartbeat_panic_nb);
 		register_reboot_notifier(&heartbeat_reboot_nb);
 	}
 	return rc;
@@ -199,8 +184,6 @@ static int __init heartbeat_trig_init(void)
 static void __exit heartbeat_trig_exit(void)
 {
 	unregister_reboot_notifier(&heartbeat_reboot_nb);
-	atomic_notifier_chain_unregister(&panic_notifier_list,
-					 &heartbeat_panic_nb);
 	led_trigger_unregister(&heartbeat_led_trigger);
 }
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/4] hung_task: Replace "did_panic" with is_be_panic()
  2020-12-18 11:44 ` [PATCH 2/4] hung_task: Replace "did_panic" with is_be_panic() Xiaoming Ni
@ 2020-12-18 12:59   ` Pavel Machek
  2020-12-18 14:36     ` Tetsuo Handa
  0 siblings, 1 reply; 9+ messages in thread
From: Pavel Machek @ 2020-12-18 12:59 UTC (permalink / raw)
  To: Xiaoming Ni
  Cc: linux-kernel, linux-leds, dmurphy, akpm, keescook, gpiccoli,
	penguin-kernel, wangle6

[-- Attachment #1: Type: text/plain, Size: 307 bytes --]

On Fri 2020-12-18 19:44:04, Xiaoming Ni wrote:
> Replace the global variable "did_panic" with is_be_panic()

Changelog does not match patch.

Plus.. is_being_panic is not really english. "is_paniccing" would be
closer...?

Best regards,
								Pavel
-- 
http://www.livejournal.com/~pavelmachek

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/4] hung_task: Replace "did_panic" with is_be_panic()
  2020-12-18 12:59   ` Pavel Machek
@ 2020-12-18 14:36     ` Tetsuo Handa
  2020-12-18 17:06       ` Randy Dunlap
  0 siblings, 1 reply; 9+ messages in thread
From: Tetsuo Handa @ 2020-12-18 14:36 UTC (permalink / raw)
  To: Pavel Machek, Xiaoming Ni
  Cc: linux-kernel, linux-leds, dmurphy, akpm, keescook, gpiccoli, wangle6

On 2020/12/18 21:59, Pavel Machek wrote:
> On Fri 2020-12-18 19:44:04, Xiaoming Ni wrote:
> Plus.. is_being_panic is not really english. "is_paniccing" would be
> closer...?

Or in_panic() ?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/4] hung_task: Replace "did_panic" with is_be_panic()
  2020-12-18 14:36     ` Tetsuo Handa
@ 2020-12-18 17:06       ` Randy Dunlap
  2020-12-20  2:58         ` Xiaoming Ni
  0 siblings, 1 reply; 9+ messages in thread
From: Randy Dunlap @ 2020-12-18 17:06 UTC (permalink / raw)
  To: Tetsuo Handa, Pavel Machek, Xiaoming Ni
  Cc: linux-kernel, linux-leds, dmurphy, akpm, keescook, gpiccoli, wangle6

On 12/18/20 6:36 AM, Tetsuo Handa wrote:
> On 2020/12/18 21:59, Pavel Machek wrote:
>> On Fri 2020-12-18 19:44:04, Xiaoming Ni wrote:
>> Plus.. is_being_panic is not really english. "is_paniccing" would be
>> closer...?
> 
> Or in_panic() ?
> 

Yes, or  in_panic_state()

-- 
~Randy


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/4] hung_task: Replace "did_panic" with is_be_panic()
  2020-12-18 17:06       ` Randy Dunlap
@ 2020-12-20  2:58         ` Xiaoming Ni
  0 siblings, 0 replies; 9+ messages in thread
From: Xiaoming Ni @ 2020-12-20  2:58 UTC (permalink / raw)
  To: Randy Dunlap, Tetsuo Handa, Pavel Machek
  Cc: linux-kernel, linux-leds, dmurphy, akpm, keescook, gpiccoli, wangle6

On 2020/12/19 1:06, Randy Dunlap wrote:
> On 12/18/20 6:36 AM, Tetsuo Handa wrote:
>> On 2020/12/18 21:59, Pavel Machek wrote:
>>> On Fri 2020-12-18 19:44:04, Xiaoming Ni wrote:
>>> Plus.. is_being_panic is not really english. "is_paniccing" would be
>>> closer...?
>>
>> Or in_panic() ?
>>
> 
> Yes, or  in_panic_state()
> 

Thank you,
I'll resend the patch later on according to your suggestion.

Thanks
Xiaoming Ni
.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-12-20  2:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-18 11:44 [PATCH 0/4] Add new API is_being_panic() Xiaoming Ni
2020-12-18 11:44 ` [PATCH 1/4] panic: " Xiaoming Ni
2020-12-18 11:44 ` [PATCH 2/4] hung_task: Replace "did_panic" with is_be_panic() Xiaoming Ni
2020-12-18 12:59   ` Pavel Machek
2020-12-18 14:36     ` Tetsuo Handa
2020-12-18 17:06       ` Randy Dunlap
2020-12-20  2:58         ` Xiaoming Ni
2020-12-18 11:44 ` [PATCH 3/4] leds:trigger:ledtrig-activity Replace "panic_detected" " Xiaoming Ni
2020-12-18 11:44 ` [PATCH 4/4] leds:trigger:ledtrig-heartbeat: Replace "panic_heartbeats" " Xiaoming Ni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).