[PATCH v2 1/4] panic: Add panic_in_progress helper

From: Stephen Brennan
Date: Wed Jan 26 2022 - 18:03:08 EST


This helper will be used in printk code to avoid deadlocks during
panic().

Suggested-by: Petr Mladek <pmladek@xxxxxxxx>
Signed-off-by: Stephen Brennan <stephen.s.brennan@xxxxxxxxxx>
---

Notes:
v2: Switch to static inline function

include/linux/panic.h | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/include/linux/panic.h b/include/linux/panic.h
index f5844908a089..1022ec930d34 100644
--- a/include/linux/panic.h
+++ b/include/linux/panic.h
@@ -4,6 +4,7 @@

#include <linux/compiler_attributes.h>
#include <linux/types.h>
+#include <linux/atomic.h>

struct pt_regs;

@@ -45,6 +46,11 @@ extern bool crash_kexec_post_notifiers;
extern atomic_t panic_cpu;
#define PANIC_CPU_INVALID -1

+static inline bool panic_in_progress(void)
+{
+ return unlikely(atomic_read(&panic_cpu) != PANIC_CPU_INVALID);
+}
+
/*
* Only to be used by arch init code. If the user over-wrote the default
* CONFIG_PANIC_TIMEOUT, honor it.
--
2.30.2