Skip to contentSkip to conversation

kernel.h: Split out panic and oops helpers

PATCH Superseded Andy Shevchenko 12 participants 18 messages Apr 6, 2021 – Apr 9, 2021

Subsystems (25)
Network drivers x86 VFS PowerPC +21 more subsystems

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel.h: Split out panic and oops helpers

kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out panic and oops helpers.

At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for existing users.

---
 arch/powerpc/kernel/setup-common.c   |  1 +
 arch/x86/include/asm/desc.h          |  1 +
 arch/x86/kernel/cpu/mshyperv.c       |  1 +
 arch/x86/kernel/setup.c              |  1 +
 drivers/char/ipmi/ipmi_msghandler.c  |  1 +
 drivers/remoteproc/remoteproc_core.c |  1 +
 include/asm-generic/bug.h            |  3 +-
 include/linux/kernel.h               | 84 +-----------------------
 include/linux/panic.h                | 98 ++++++++++++++++++++++++++++
 include/linux/panic_notifier.h       | 12 ++++
 kernel/hung_task.c                   |  1 +
 kernel/kexec_core.c                  |  1 +
 kernel/panic.c                       |  1 +
 kernel/rcu/tree.c                    |  2 +
 kernel/sysctl.c                      |  1 +
 kernel/trace/trace.c                 |  1 +
 16 files changed, 126 insertions(+), 84 deletions(-)
 create mode 100644 include/linux/panic.h
 create mode 100644 include/linux/panic_notifier.h
arch/powerpc/kernel/setup-common.c +1 -0
index 74a98fff2c2f..046fe21b5c3b 100644
@@ -9,6 +9,7 @@
 #undef DEBUG
 
 #include <linux/export.h>
+#include <linux/panic_notifier.h>
 #include <linux/string.h>
 #include <linux/sched.h>
 #include <linux/init.h>
arch/x86/include/asm/desc.h +1 -0
index 476082a83d1c..ceb12683b6d1 100644
@@ -9,6 +9,7 @@
 #include <asm/irq_vectors.h>
 #include <asm/cpu_entry_area.h>
 
+#include <linux/debug_locks.h>
 #include <linux/smp.h>
 #include <linux/percpu.h>
 
arch/x86/kernel/cpu/mshyperv.c +1 -0
index 22f13343b5da..9e5c6f2b044d 100644
@@ -17,6 +17,7 @@
 #include <linux/irq.h>
 #include <linux/kexec.h>
 #include <linux/i8253.h>
+#include <linux/panic_notifier.h>
 #include <linux/random.h>
 #include <asm/processor.h>
 #include <asm/hypervisor.h>
arch/x86/kernel/setup.c +1 -0
index 59e5e0903b0c..570699eecf90 100644
@@ -14,6 +14,7 @@
 #include <linux/initrd.h>
 #include <linux/iscsi_ibft.h>
 #include <linux/memblock.h>
+#include <linux/panic_notifier.h>
 #include <linux/pci.h>
 #include <linux/root_dev.h>
 #include <linux/hugetlb.h>
drivers/char/ipmi/ipmi_msghandler.c +1 -0
index 8a0e97b33cae..e96cb5c4f97a 100644
@@ -16,6 +16,7 @@
 
 #include <linux/module.h>
 #include <linux/errno.h>
+#include <linux/panic_notifier.h>
 #include <linux/poll.h>
 #include <linux/sched.h>
 #include <linux/seq_file.h>
drivers/remoteproc/remoteproc_core.c +1 -0
index 626a6b90fba2..76dd8e2b1e7e 100644
@@ -20,6 +20,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/device.h>
+#include <linux/panic_notifier.h>
 #include <linux/slab.h>
 #include <linux/mutex.h>
 #include <linux/dma-map-ops.h>
include/asm-generic/bug.h +2 -1
index 76a10e0dca9f..719410b93f99 100644
@@ -17,7 +17,8 @@
 #endif
 
 #ifndef __ASSEMBLY__
-#include <linux/kernel.h>
+#include <linux/panic.h>
+#include <linux/printk.h>
 
 #ifdef CONFIG_BUG
 
include/linux/kernel.h +1 -83

116 lines not on this page · raw message

include/linux/panic.h new file +98 -0

98 lines not on this page · raw message

include/linux/panic_notifier.h new file +12 -0
new file mode 100644
index 000000000000..41e32483d7a7
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_PANIC_NOTIFIERS_H
+#define _LINUX_PANIC_NOTIFIERS_H
+
+#include <linux/notifier.h>
+#include <linux/types.h>
+
+extern struct atomic_notifier_head panic_notifier_list;
+
+extern bool crash_kexec_post_notifiers;
+
+#endif	/* _LINUX_PANIC_NOTIFIERS_H */
kernel/hung_task.c +1 -0
index bb2e3e15c84c..2871076e4d29 100644
@@ -15,6 +15,7 @@
 #include <linux/kthread.h>
 #include <linux/lockdep.h>
 #include <linux/export.h>
+#include <linux/panic_notifier.h>
 #include <linux/sysctl.h>
 #include <linux/suspend.h>
 #include <linux/utsname.h>
kernel/kexec_core.c +1 -0
index f099baee3578..4b34a9aa32bc 100644
@@ -26,6 +26,7 @@
 #include <linux/suspend.h>
 #include <linux/device.h>
 #include <linux/freezer.h>
+#include <linux/panic_notifier.h>
 #include <linux/pm.h>
 #include <linux/cpu.h>
 #include <linux/uaccess.h>
kernel/panic.c +1 -0
index 332736a72a58..edad89660a2b 100644
@@ -23,6 +23,7 @@
 #include <linux/reboot.h>
 #include <linux/delay.h>
 #include <linux/kexec.h>
+#include <linux/panic_notifier.h>
 #include <linux/sched.h>
 #include <linux/sysrq.h>
 #include <linux/init.h>
kernel/rcu/tree.c +2 -0
index ce5b4cd6bd18..a58c9c86fa13 100644
@@ -32,6 +32,8 @@
 #include <linux/export.h>
 #include <linux/completion.h>
 #include <linux/moduleparam.h>
+#include <linux/panic.h>
+#include <linux/panic_notifier.h>
 #include <linux/percpu.h>
 #include <linux/notifier.h>
 #include <linux/cpu.h>
kernel/sysctl.c +1 -0
index 3601786ddaeb..e5cf9c4ef5e1 100644
@@ -27,6 +27,7 @@
 #include <linux/sysctl.h>
 #include <linux/bitmap.h>
 #include <linux/signal.h>
+#include <linux/panic.h>
 #include <linux/printk.h>
 #include <linux/proc_fs.h>
 #include <linux/security.h>
kernel/trace/trace.c +1 -0
index 507a30bf26e4..9612a1d8fa13 100644
@@ -39,6 +39,7 @@
 #include <linux/slab.h>
 #include <linux/ctype.h>
 #include <linux/init.h>
+#include <linux/panic_notifier.h>
 #include <linux/poll.h>
 #include <linux/nmi.h>
 #include <linux/fs.h>
Signature · 7 lines
2.30.2


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Andy Shevchenko

kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out panic and oops helpers.

At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for existing users.

Regards,
Bjorn

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Acked-by on v1 1/1
#2 lore raw
In reply to Andy Shevchenko
Quoted 7 lines · Andy Shevchenko

kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out panic and oops helpers.

At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for existing users.

For the IPMI portion:

Quoted 432 lines
---
 arch/powerpc/kernel/setup-common.c   |  1 +
 arch/x86/include/asm/desc.h          |  1 +
 arch/x86/kernel/cpu/mshyperv.c       |  1 +
 arch/x86/kernel/setup.c              |  1 +
 drivers/char/ipmi/ipmi_msghandler.c  |  1 +
 drivers/remoteproc/remoteproc_core.c |  1 +
 include/asm-generic/bug.h            |  3 +-
 include/linux/kernel.h               | 84 +-----------------------
 include/linux/panic.h                | 98 ++++++++++++++++++++++++++++
 include/linux/panic_notifier.h       | 12 ++++
 kernel/hung_task.c                   |  1 +
 kernel/kexec_core.c                  |  1 +
 kernel/panic.c                       |  1 +
 kernel/rcu/tree.c                    |  2 +
 kernel/sysctl.c                      |  1 +
 kernel/trace/trace.c                 |  1 +
 16 files changed, 126 insertions(+), 84 deletions(-)
 create mode 100644 include/linux/panic.h
 create mode 100644 include/linux/panic_notifier.h
arch/powerpc/kernel/setup-common.c +1 -0
index 74a98fff2c2f..046fe21b5c3b 100644
@@ -9,6 +9,7 @@
 #undef DEBUG
 
 #include <linux/export.h>
+#include <linux/panic_notifier.h>
 #include <linux/string.h>
 #include <linux/sched.h>
 #include <linux/init.h>
arch/x86/include/asm/desc.h +1 -0
index 476082a83d1c..ceb12683b6d1 100644
@@ -9,6 +9,7 @@
 #include <asm/irq_vectors.h>
 #include <asm/cpu_entry_area.h>
 
+#include <linux/debug_locks.h>
 #include <linux/smp.h>
 #include <linux/percpu.h>
 
arch/x86/kernel/cpu/mshyperv.c +1 -0
index 22f13343b5da..9e5c6f2b044d 100644
@@ -17,6 +17,7 @@
 #include <linux/irq.h>
 #include <linux/kexec.h>
 #include <linux/i8253.h>
+#include <linux/panic_notifier.h>
 #include <linux/random.h>
 #include <asm/processor.h>
 #include <asm/hypervisor.h>
arch/x86/kernel/setup.c +1 -0
index 59e5e0903b0c..570699eecf90 100644
@@ -14,6 +14,7 @@
 #include <linux/initrd.h>
 #include <linux/iscsi_ibft.h>
 #include <linux/memblock.h>
+#include <linux/panic_notifier.h>
 #include <linux/pci.h>
 #include <linux/root_dev.h>
 #include <linux/hugetlb.h>
drivers/char/ipmi/ipmi_msghandler.c +1 -0
index 8a0e97b33cae..e96cb5c4f97a 100644
@@ -16,6 +16,7 @@
 
 #include <linux/module.h>
 #include <linux/errno.h>
+#include <linux/panic_notifier.h>
 #include <linux/poll.h>
 #include <linux/sched.h>
 #include <linux/seq_file.h>
drivers/remoteproc/remoteproc_core.c +1 -0
index 626a6b90fba2..76dd8e2b1e7e 100644
@@ -20,6 +20,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/device.h>
+#include <linux/panic_notifier.h>
 #include <linux/slab.h>
 #include <linux/mutex.h>
 #include <linux/dma-map-ops.h>
include/asm-generic/bug.h +2 -1
index 76a10e0dca9f..719410b93f99 100644
@@ -17,7 +17,8 @@
 #endif
 
 #ifndef __ASSEMBLY__
-#include <linux/kernel.h>
+#include <linux/panic.h>
+#include <linux/printk.h>
 
 #ifdef CONFIG_BUG
 
include/linux/kernel.h +1 -83
index 09035ac67d4b..6c5a05ac1ecb 100644
@@ -14,6 +14,7 @@
 #include <linux/math.h>
 #include <linux/minmax.h>
 #include <linux/typecheck.h>
+#include <linux/panic.h>
 #include <linux/printk.h>
 #include <linux/build_bug.h>
 #include <linux/static_call_types.h>
@@ -70,7 +71,6 @@
 #define lower_32_bits(n) ((u32)((n) & 0xffffffff))
 
 struct completion;
-struct pt_regs;
 struct user;
 
 #ifdef CONFIG_PREEMPT_VOLUNTARY
@@ -175,14 +175,6 @@ void __might_fault(const char *file, int line);
 static inline void might_fault(void) { }
 #endif
 
-extern struct atomic_notifier_head panic_notifier_list;
-extern long (*panic_blink)(int state);
-__printf(1, 2)
-void panic(const char *fmt, ...) __noreturn __cold;
-void nmi_panic(struct pt_regs *regs, const char *msg);
-extern void oops_enter(void);
-extern void oops_exit(void);
-extern bool oops_may_print(void);
 void do_exit(long error_code) __noreturn;
 void complete_and_exit(struct completion *, long) __noreturn;
 
@@ -368,52 +360,8 @@ extern int __kernel_text_address(unsigned long addr);
 extern int kernel_text_address(unsigned long addr);
 extern int func_ptr_is_kernel_text(void *ptr);
 
-#ifdef CONFIG_SMP
-extern unsigned int sysctl_oops_all_cpu_backtrace;
-#else
-#define sysctl_oops_all_cpu_backtrace 0
-#endif /* CONFIG_SMP */
-
 extern void bust_spinlocks(int yes);
-extern int panic_timeout;
-extern unsigned long panic_print;
-extern int panic_on_oops;
-extern int panic_on_unrecovered_nmi;
-extern int panic_on_io_nmi;
-extern int panic_on_warn;
-extern unsigned long panic_on_taint;
-extern bool panic_on_taint_nousertaint;
-extern int sysctl_panic_on_rcu_stall;
-extern int sysctl_max_rcu_stall_to_panic;
-extern int sysctl_panic_on_stackoverflow;
-
-extern bool crash_kexec_post_notifiers;
 
-/*
- * panic_cpu is used for synchronizing panic() and crash_kexec() execution. It
- * holds a CPU number which is executing panic() currently. A value of
- * PANIC_CPU_INVALID means no CPU has entered panic() or crash_kexec().
- */
-extern atomic_t panic_cpu;
-#define PANIC_CPU_INVALID	-1
-
-/*
- * Only to be used by arch init code. If the user over-wrote the default
- * CONFIG_PANIC_TIMEOUT, honor it.
- */
-static inline void set_arch_panic_timeout(int timeout, int arch_default_timeout)
-{
-	if (panic_timeout == arch_default_timeout)
-		panic_timeout = timeout;
-}
-extern const char *print_tainted(void);
-enum lockdep_ok {
-	LOCKDEP_STILL_OK,
-	LOCKDEP_NOW_UNRELIABLE
-};
-extern void add_taint(unsigned flag, enum lockdep_ok);
-extern int test_taint(unsigned flag);
-extern unsigned long get_taint(void);
 extern int root_mountflags;
 
 extern bool early_boot_irqs_disabled;
@@ -432,36 +380,6 @@ extern enum system_states {
 	SYSTEM_SUSPEND,
 } system_state;
 
-/* This cannot be an enum because some may be used in assembly source. */
-#define TAINT_PROPRIETARY_MODULE	0
-#define TAINT_FORCED_MODULE		1
-#define TAINT_CPU_OUT_OF_SPEC		2
-#define TAINT_FORCED_RMMOD		3
-#define TAINT_MACHINE_CHECK		4
-#define TAINT_BAD_PAGE			5
-#define TAINT_USER			6
-#define TAINT_DIE			7
-#define TAINT_OVERRIDDEN_ACPI_TABLE	8
-#define TAINT_WARN			9
-#define TAINT_CRAP			10
-#define TAINT_FIRMWARE_WORKAROUND	11
-#define TAINT_OOT_MODULE		12
-#define TAINT_UNSIGNED_MODULE		13
-#define TAINT_SOFTLOCKUP		14
-#define TAINT_LIVEPATCH			15
-#define TAINT_AUX			16
-#define TAINT_RANDSTRUCT		17
-#define TAINT_FLAGS_COUNT		18
-#define TAINT_FLAGS_MAX			((1UL << TAINT_FLAGS_COUNT) - 1)
-
-struct taint_flag {
-	char c_true;	/* character printed when tainted */
-	char c_false;	/* character printed when not tainted */
-	bool module;	/* also show as a per-module taint flag */
-};
-
-extern const struct taint_flag taint_flags[TAINT_FLAGS_COUNT];
-
 extern const char hex_asc[];
 #define hex_asc_lo(x)	hex_asc[((x) & 0x0f)]
 #define hex_asc_hi(x)	hex_asc[((x) & 0xf0) >> 4]
include/linux/panic.h new file +98 -0
new file mode 100644
index 000000000000..f5844908a089
@@ -0,0 +1,98 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_PANIC_H
+#define _LINUX_PANIC_H
+
+#include <linux/compiler_attributes.h>
+#include <linux/types.h>
+
+struct pt_regs;
+
+extern long (*panic_blink)(int state);
+__printf(1, 2)
+void panic(const char *fmt, ...) __noreturn __cold;
+void nmi_panic(struct pt_regs *regs, const char *msg);
+extern void oops_enter(void);
+extern void oops_exit(void);
+extern bool oops_may_print(void);
+
+#ifdef CONFIG_SMP
+extern unsigned int sysctl_oops_all_cpu_backtrace;
+#else
+#define sysctl_oops_all_cpu_backtrace 0
+#endif /* CONFIG_SMP */
+
+extern int panic_timeout;
+extern unsigned long panic_print;
+extern int panic_on_oops;
+extern int panic_on_unrecovered_nmi;
+extern int panic_on_io_nmi;
+extern int panic_on_warn;
+
+extern unsigned long panic_on_taint;
+extern bool panic_on_taint_nousertaint;
+
+extern int sysctl_panic_on_rcu_stall;
+extern int sysctl_max_rcu_stall_to_panic;
+extern int sysctl_panic_on_stackoverflow;
+
+extern bool crash_kexec_post_notifiers;
+
+/*
+ * panic_cpu is used for synchronizing panic() and crash_kexec() execution. It
+ * holds a CPU number which is executing panic() currently. A value of
+ * PANIC_CPU_INVALID means no CPU has entered panic() or crash_kexec().
+ */
+extern atomic_t panic_cpu;
+#define PANIC_CPU_INVALID	-1
+
+/*
+ * Only to be used by arch init code. If the user over-wrote the default
+ * CONFIG_PANIC_TIMEOUT, honor it.
+ */
+static inline void set_arch_panic_timeout(int timeout, int arch_default_timeout)
+{
+	if (panic_timeout == arch_default_timeout)
+		panic_timeout = timeout;
+}
+
+/* This cannot be an enum because some may be used in assembly source. */
+#define TAINT_PROPRIETARY_MODULE	0
+#define TAINT_FORCED_MODULE		1
+#define TAINT_CPU_OUT_OF_SPEC		2
+#define TAINT_FORCED_RMMOD		3
+#define TAINT_MACHINE_CHECK		4
+#define TAINT_BAD_PAGE			5
+#define TAINT_USER			6
+#define TAINT_DIE			7
+#define TAINT_OVERRIDDEN_ACPI_TABLE	8
+#define TAINT_WARN			9
+#define TAINT_CRAP			10
+#define TAINT_FIRMWARE_WORKAROUND	11
+#define TAINT_OOT_MODULE		12
+#define TAINT_UNSIGNED_MODULE		13
+#define TAINT_SOFTLOCKUP		14
+#define TAINT_LIVEPATCH			15
+#define TAINT_AUX			16
+#define TAINT_RANDSTRUCT		17
+#define TAINT_FLAGS_COUNT		18
+#define TAINT_FLAGS_MAX			((1UL << TAINT_FLAGS_COUNT) - 1)
+
+struct taint_flag {
+	char c_true;	/* character printed when tainted */
+	char c_false;	/* character printed when not tainted */
+	bool module;	/* also show as a per-module taint flag */
+};
+
+extern const struct taint_flag taint_flags[TAINT_FLAGS_COUNT];
+
+enum lockdep_ok {
+	LOCKDEP_STILL_OK,
+	LOCKDEP_NOW_UNRELIABLE,
+};
+
+extern const char *print_tainted(void);
+extern void add_taint(unsigned flag, enum lockdep_ok);
+extern int test_taint(unsigned flag);
+extern unsigned long get_taint(void);
+
+#endif	/* _LINUX_PANIC_H */
include/linux/panic_notifier.h new file +12 -0
new file mode 100644
index 000000000000..41e32483d7a7
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_PANIC_NOTIFIERS_H
+#define _LINUX_PANIC_NOTIFIERS_H
+
+#include <linux/notifier.h>
+#include <linux/types.h>
+
+extern struct atomic_notifier_head panic_notifier_list;
+
+extern bool crash_kexec_post_notifiers;
+
+#endif	/* _LINUX_PANIC_NOTIFIERS_H */
kernel/hung_task.c +1 -0
index bb2e3e15c84c..2871076e4d29 100644
@@ -15,6 +15,7 @@
 #include <linux/kthread.h>
 #include <linux/lockdep.h>
 #include <linux/export.h>
+#include <linux/panic_notifier.h>
 #include <linux/sysctl.h>
 #include <linux/suspend.h>
 #include <linux/utsname.h>
kernel/kexec_core.c +1 -0
index f099baee3578..4b34a9aa32bc 100644
@@ -26,6 +26,7 @@
 #include <linux/suspend.h>
 #include <linux/device.h>
 #include <linux/freezer.h>
+#include <linux/panic_notifier.h>
 #include <linux/pm.h>
 #include <linux/cpu.h>
 #include <linux/uaccess.h>
kernel/panic.c +1 -0
index 332736a72a58..edad89660a2b 100644
@@ -23,6 +23,7 @@
 #include <linux/reboot.h>
 #include <linux/delay.h>
 #include <linux/kexec.h>
+#include <linux/panic_notifier.h>
 #include <linux/sched.h>
 #include <linux/sysrq.h>
 #include <linux/init.h>
kernel/rcu/tree.c +2 -0
index ce5b4cd6bd18..a58c9c86fa13 100644
@@ -32,6 +32,8 @@
 #include <linux/export.h>
 #include <linux/completion.h>
 #include <linux/moduleparam.h>
+#include <linux/panic.h>
+#include <linux/panic_notifier.h>
 #include <linux/percpu.h>
 #include <linux/notifier.h>
 #include <linux/cpu.h>
kernel/sysctl.c +1 -0
index 3601786ddaeb..e5cf9c4ef5e1 100644
@@ -27,6 +27,7 @@
 #include <linux/sysctl.h>
 #include <linux/bitmap.h>
 #include <linux/signal.h>
+#include <linux/panic.h>
 #include <linux/printk.h>
 #include <linux/proc_fs.h>
 #include <linux/security.h>
kernel/trace/trace.c +1 -0
index 507a30bf26e4..9612a1d8fa13 100644
@@ -39,6 +39,7 @@
 #include <linux/slab.h>
 #include <linux/ctype.h>
 #include <linux/init.h>
+#include <linux/panic_notifier.h>
 #include <linux/poll.h>
 #include <linux/nmi.h>
 #include <linux/fs.h>
Signature · 1 line
2.30.2

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Andy Shevchenko
Quoted 9 lines · Andy Shevchenko

kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out panic and oops helpers.

At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for existing users.

Quoted 26 lines
---
 arch/powerpc/kernel/setup-common.c   |  1 +
 arch/x86/include/asm/desc.h          |  1 +
 arch/x86/kernel/cpu/mshyperv.c       |  1 +
 arch/x86/kernel/setup.c              |  1 +
 drivers/char/ipmi/ipmi_msghandler.c  |  1 +
 drivers/remoteproc/remoteproc_core.c |  1 +
 include/asm-generic/bug.h            |  3 +-
 include/linux/kernel.h               | 84 +-----------------------
 include/linux/panic.h                | 98 ++++++++++++++++++++++++++++
 include/linux/panic_notifier.h       | 12 ++++
 kernel/hung_task.c                   |  1 +
 kernel/kexec_core.c                  |  1 +
 kernel/panic.c                       |  1 +
 kernel/rcu/tree.c                    |  2 +
 kernel/sysctl.c                      |  1 +
 kernel/trace/trace.c                 |  1 +
 16 files changed, 126 insertions(+), 84 deletions(-)
 create mode 100644 include/linux/panic.h
 create mode 100644 include/linux/panic_notifier.h
arch/x86/include/asm/desc.h +0 -0
index 476082a83d1c..ceb12683b6d1 100644

arch/x86/include/asm/desc.h line 12

Quoted 4 lines
arch/x86/include/asm/desc.h +1 -0
@@ -9,6 +9,7 @@
 #include <asm/irq_vectors.h>
 #include <asm/cpu_entry_area.h>
 
+#include <linux/debug_locks.h>

This seems unrelated, but I might be missing something.

Quoted 3 lines
arch/x86/include/asm/desc.h +0 -0
 #include <linux/smp.h>
 #include <linux/percpu.h>
 
Signature · 2 lines
Sincerely yours,
Mike.
Acked-by on v1 1/1
#4 lore raw
In reply to Andy Shevchenko
Quoted 10 lines · Andy Shevchenko

kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out panic and oops helpers.

At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for existing users.

---

(I think David has tried something like this a few years ago too?) Good idea in any case. (Be good to see kbuild do an allmodconfig build of this though.)

Quoted 429 lines
 arch/powerpc/kernel/setup-common.c   |  1 +
 arch/x86/include/asm/desc.h          |  1 +
 arch/x86/kernel/cpu/mshyperv.c       |  1 +
 arch/x86/kernel/setup.c              |  1 +
 drivers/char/ipmi/ipmi_msghandler.c  |  1 +
 drivers/remoteproc/remoteproc_core.c |  1 +
 include/asm-generic/bug.h            |  3 +-
 include/linux/kernel.h               | 84 +-----------------------
 include/linux/panic.h                | 98 ++++++++++++++++++++++++++++
 include/linux/panic_notifier.h       | 12 ++++
 kernel/hung_task.c                   |  1 +
 kernel/kexec_core.c                  |  1 +
 kernel/panic.c                       |  1 +
 kernel/rcu/tree.c                    |  2 +
 kernel/sysctl.c                      |  1 +
 kernel/trace/trace.c                 |  1 +
 16 files changed, 126 insertions(+), 84 deletions(-)
 create mode 100644 include/linux/panic.h
 create mode 100644 include/linux/panic_notifier.h
arch/powerpc/kernel/setup-common.c +1 -0
index 74a98fff2c2f..046fe21b5c3b 100644
@@ -9,6 +9,7 @@
 #undef DEBUG
 
 #include <linux/export.h>
+#include <linux/panic_notifier.h>
 #include <linux/string.h>
 #include <linux/sched.h>
 #include <linux/init.h>
arch/x86/include/asm/desc.h +1 -0
index 476082a83d1c..ceb12683b6d1 100644
@@ -9,6 +9,7 @@
 #include <asm/irq_vectors.h>
 #include <asm/cpu_entry_area.h>
 
+#include <linux/debug_locks.h>
 #include <linux/smp.h>
 #include <linux/percpu.h>
 
arch/x86/kernel/cpu/mshyperv.c +1 -0
index 22f13343b5da..9e5c6f2b044d 100644
@@ -17,6 +17,7 @@
 #include <linux/irq.h>
 #include <linux/kexec.h>
 #include <linux/i8253.h>
+#include <linux/panic_notifier.h>
 #include <linux/random.h>
 #include <asm/processor.h>
 #include <asm/hypervisor.h>
arch/x86/kernel/setup.c +1 -0
index 59e5e0903b0c..570699eecf90 100644
@@ -14,6 +14,7 @@
 #include <linux/initrd.h>
 #include <linux/iscsi_ibft.h>
 #include <linux/memblock.h>
+#include <linux/panic_notifier.h>
 #include <linux/pci.h>
 #include <linux/root_dev.h>
 #include <linux/hugetlb.h>
drivers/char/ipmi/ipmi_msghandler.c +1 -0
index 8a0e97b33cae..e96cb5c4f97a 100644
@@ -16,6 +16,7 @@
 
 #include <linux/module.h>
 #include <linux/errno.h>
+#include <linux/panic_notifier.h>
 #include <linux/poll.h>
 #include <linux/sched.h>
 #include <linux/seq_file.h>
drivers/remoteproc/remoteproc_core.c +1 -0
index 626a6b90fba2..76dd8e2b1e7e 100644
@@ -20,6 +20,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/device.h>
+#include <linux/panic_notifier.h>
 #include <linux/slab.h>
 #include <linux/mutex.h>
 #include <linux/dma-map-ops.h>
include/asm-generic/bug.h +2 -1
index 76a10e0dca9f..719410b93f99 100644
@@ -17,7 +17,8 @@
 #endif
 
 #ifndef __ASSEMBLY__
-#include <linux/kernel.h>
+#include <linux/panic.h>
+#include <linux/printk.h>
 
 #ifdef CONFIG_BUG
 
include/linux/kernel.h +1 -83
index 09035ac67d4b..6c5a05ac1ecb 100644
@@ -14,6 +14,7 @@
 #include <linux/math.h>
 #include <linux/minmax.h>
 #include <linux/typecheck.h>
+#include <linux/panic.h>
 #include <linux/printk.h>
 #include <linux/build_bug.h>
 #include <linux/static_call_types.h>
@@ -70,7 +71,6 @@
 #define lower_32_bits(n) ((u32)((n) & 0xffffffff))
 
 struct completion;
-struct pt_regs;
 struct user;
 
 #ifdef CONFIG_PREEMPT_VOLUNTARY
@@ -175,14 +175,6 @@ void __might_fault(const char *file, int line);
 static inline void might_fault(void) { }
 #endif
 
-extern struct atomic_notifier_head panic_notifier_list;
-extern long (*panic_blink)(int state);
-__printf(1, 2)
-void panic(const char *fmt, ...) __noreturn __cold;
-void nmi_panic(struct pt_regs *regs, const char *msg);
-extern void oops_enter(void);
-extern void oops_exit(void);
-extern bool oops_may_print(void);
 void do_exit(long error_code) __noreturn;
 void complete_and_exit(struct completion *, long) __noreturn;
 
@@ -368,52 +360,8 @@ extern int __kernel_text_address(unsigned long addr);
 extern int kernel_text_address(unsigned long addr);
 extern int func_ptr_is_kernel_text(void *ptr);
 
-#ifdef CONFIG_SMP
-extern unsigned int sysctl_oops_all_cpu_backtrace;
-#else
-#define sysctl_oops_all_cpu_backtrace 0
-#endif /* CONFIG_SMP */
-
 extern void bust_spinlocks(int yes);
-extern int panic_timeout;
-extern unsigned long panic_print;
-extern int panic_on_oops;
-extern int panic_on_unrecovered_nmi;
-extern int panic_on_io_nmi;
-extern int panic_on_warn;
-extern unsigned long panic_on_taint;
-extern bool panic_on_taint_nousertaint;
-extern int sysctl_panic_on_rcu_stall;
-extern int sysctl_max_rcu_stall_to_panic;
-extern int sysctl_panic_on_stackoverflow;
-
-extern bool crash_kexec_post_notifiers;
 
-/*
- * panic_cpu is used for synchronizing panic() and crash_kexec() execution. It
- * holds a CPU number which is executing panic() currently. A value of
- * PANIC_CPU_INVALID means no CPU has entered panic() or crash_kexec().
- */
-extern atomic_t panic_cpu;
-#define PANIC_CPU_INVALID	-1
-
-/*
- * Only to be used by arch init code. If the user over-wrote the default
- * CONFIG_PANIC_TIMEOUT, honor it.
- */
-static inline void set_arch_panic_timeout(int timeout, int arch_default_timeout)
-{
-	if (panic_timeout == arch_default_timeout)
-		panic_timeout = timeout;
-}
-extern const char *print_tainted(void);
-enum lockdep_ok {
-	LOCKDEP_STILL_OK,
-	LOCKDEP_NOW_UNRELIABLE
-};
-extern void add_taint(unsigned flag, enum lockdep_ok);
-extern int test_taint(unsigned flag);
-extern unsigned long get_taint(void);
 extern int root_mountflags;
 
 extern bool early_boot_irqs_disabled;
@@ -432,36 +380,6 @@ extern enum system_states {
 	SYSTEM_SUSPEND,
 } system_state;
 
-/* This cannot be an enum because some may be used in assembly source. */
-#define TAINT_PROPRIETARY_MODULE	0
-#define TAINT_FORCED_MODULE		1
-#define TAINT_CPU_OUT_OF_SPEC		2
-#define TAINT_FORCED_RMMOD		3
-#define TAINT_MACHINE_CHECK		4
-#define TAINT_BAD_PAGE			5
-#define TAINT_USER			6
-#define TAINT_DIE			7
-#define TAINT_OVERRIDDEN_ACPI_TABLE	8
-#define TAINT_WARN			9
-#define TAINT_CRAP			10
-#define TAINT_FIRMWARE_WORKAROUND	11
-#define TAINT_OOT_MODULE		12
-#define TAINT_UNSIGNED_MODULE		13
-#define TAINT_SOFTLOCKUP		14
-#define TAINT_LIVEPATCH			15
-#define TAINT_AUX			16
-#define TAINT_RANDSTRUCT		17
-#define TAINT_FLAGS_COUNT		18
-#define TAINT_FLAGS_MAX			((1UL << TAINT_FLAGS_COUNT) - 1)
-
-struct taint_flag {
-	char c_true;	/* character printed when tainted */
-	char c_false;	/* character printed when not tainted */
-	bool module;	/* also show as a per-module taint flag */
-};
-
-extern const struct taint_flag taint_flags[TAINT_FLAGS_COUNT];
-
 extern const char hex_asc[];
 #define hex_asc_lo(x)	hex_asc[((x) & 0x0f)]
 #define hex_asc_hi(x)	hex_asc[((x) & 0xf0) >> 4]
include/linux/panic.h new file +98 -0
new file mode 100644
index 000000000000..f5844908a089
@@ -0,0 +1,98 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_PANIC_H
+#define _LINUX_PANIC_H
+
+#include <linux/compiler_attributes.h>
+#include <linux/types.h>
+
+struct pt_regs;
+
+extern long (*panic_blink)(int state);
+__printf(1, 2)
+void panic(const char *fmt, ...) __noreturn __cold;
+void nmi_panic(struct pt_regs *regs, const char *msg);
+extern void oops_enter(void);
+extern void oops_exit(void);
+extern bool oops_may_print(void);
+
+#ifdef CONFIG_SMP
+extern unsigned int sysctl_oops_all_cpu_backtrace;
+#else
+#define sysctl_oops_all_cpu_backtrace 0
+#endif /* CONFIG_SMP */
+
+extern int panic_timeout;
+extern unsigned long panic_print;
+extern int panic_on_oops;
+extern int panic_on_unrecovered_nmi;
+extern int panic_on_io_nmi;
+extern int panic_on_warn;
+
+extern unsigned long panic_on_taint;
+extern bool panic_on_taint_nousertaint;
+
+extern int sysctl_panic_on_rcu_stall;
+extern int sysctl_max_rcu_stall_to_panic;
+extern int sysctl_panic_on_stackoverflow;
+
+extern bool crash_kexec_post_notifiers;
+
+/*
+ * panic_cpu is used for synchronizing panic() and crash_kexec() execution. It
+ * holds a CPU number which is executing panic() currently. A value of
+ * PANIC_CPU_INVALID means no CPU has entered panic() or crash_kexec().
+ */
+extern atomic_t panic_cpu;
+#define PANIC_CPU_INVALID	-1
+
+/*
+ * Only to be used by arch init code. If the user over-wrote the default
+ * CONFIG_PANIC_TIMEOUT, honor it.
+ */
+static inline void set_arch_panic_timeout(int timeout, int arch_default_timeout)
+{
+	if (panic_timeout == arch_default_timeout)
+		panic_timeout = timeout;
+}
+
+/* This cannot be an enum because some may be used in assembly source. */
+#define TAINT_PROPRIETARY_MODULE	0
+#define TAINT_FORCED_MODULE		1
+#define TAINT_CPU_OUT_OF_SPEC		2
+#define TAINT_FORCED_RMMOD		3
+#define TAINT_MACHINE_CHECK		4
+#define TAINT_BAD_PAGE			5
+#define TAINT_USER			6
+#define TAINT_DIE			7
+#define TAINT_OVERRIDDEN_ACPI_TABLE	8
+#define TAINT_WARN			9
+#define TAINT_CRAP			10
+#define TAINT_FIRMWARE_WORKAROUND	11
+#define TAINT_OOT_MODULE		12
+#define TAINT_UNSIGNED_MODULE		13
+#define TAINT_SOFTLOCKUP		14
+#define TAINT_LIVEPATCH			15
+#define TAINT_AUX			16
+#define TAINT_RANDSTRUCT		17
+#define TAINT_FLAGS_COUNT		18
+#define TAINT_FLAGS_MAX			((1UL << TAINT_FLAGS_COUNT) - 1)
+
+struct taint_flag {
+	char c_true;	/* character printed when tainted */
+	char c_false;	/* character printed when not tainted */
+	bool module;	/* also show as a per-module taint flag */
+};
+
+extern const struct taint_flag taint_flags[TAINT_FLAGS_COUNT];
+
+enum lockdep_ok {
+	LOCKDEP_STILL_OK,
+	LOCKDEP_NOW_UNRELIABLE,
+};
+
+extern const char *print_tainted(void);
+extern void add_taint(unsigned flag, enum lockdep_ok);
+extern int test_taint(unsigned flag);
+extern unsigned long get_taint(void);
+
+#endif	/* _LINUX_PANIC_H */
include/linux/panic_notifier.h new file +12 -0
new file mode 100644
index 000000000000..41e32483d7a7
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_PANIC_NOTIFIERS_H
+#define _LINUX_PANIC_NOTIFIERS_H
+
+#include <linux/notifier.h>
+#include <linux/types.h>
+
+extern struct atomic_notifier_head panic_notifier_list;
+
+extern bool crash_kexec_post_notifiers;
+
+#endif	/* _LINUX_PANIC_NOTIFIERS_H */
kernel/hung_task.c +1 -0
index bb2e3e15c84c..2871076e4d29 100644
@@ -15,6 +15,7 @@
 #include <linux/kthread.h>
 #include <linux/lockdep.h>
 #include <linux/export.h>
+#include <linux/panic_notifier.h>
 #include <linux/sysctl.h>
 #include <linux/suspend.h>
 #include <linux/utsname.h>
kernel/kexec_core.c +1 -0
index f099baee3578..4b34a9aa32bc 100644
@@ -26,6 +26,7 @@
 #include <linux/suspend.h>
 #include <linux/device.h>
 #include <linux/freezer.h>
+#include <linux/panic_notifier.h>
 #include <linux/pm.h>
 #include <linux/cpu.h>
 #include <linux/uaccess.h>
kernel/panic.c +1 -0
index 332736a72a58..edad89660a2b 100644
@@ -23,6 +23,7 @@
 #include <linux/reboot.h>
 #include <linux/delay.h>
 #include <linux/kexec.h>
+#include <linux/panic_notifier.h>
 #include <linux/sched.h>
 #include <linux/sysrq.h>
 #include <linux/init.h>
kernel/rcu/tree.c +2 -0
index ce5b4cd6bd18..a58c9c86fa13 100644
@@ -32,6 +32,8 @@
 #include <linux/export.h>
 #include <linux/completion.h>
 #include <linux/moduleparam.h>
+#include <linux/panic.h>
+#include <linux/panic_notifier.h>
 #include <linux/percpu.h>
 #include <linux/notifier.h>
 #include <linux/cpu.h>
kernel/sysctl.c +1 -0
index 3601786ddaeb..e5cf9c4ef5e1 100644
@@ -27,6 +27,7 @@
 #include <linux/sysctl.h>
 #include <linux/bitmap.h>
 #include <linux/signal.h>
+#include <linux/panic.h>
 #include <linux/printk.h>
 #include <linux/proc_fs.h>
 #include <linux/security.h>
kernel/trace/trace.c +1 -0
index 507a30bf26e4..9612a1d8fa13 100644
@@ -39,6 +39,7 @@
 #include <linux/slab.h>
 #include <linux/ctype.h>
 #include <linux/init.h>
+#include <linux/panic_notifier.h>
 #include <linux/poll.h>
 #include <linux/nmi.h>
 #include <linux/fs.h>
Signature · 1 line
2.30.2
maintainer Acked-by on v1 1/1
#5 lore raw
In reply to Andy Shevchenko
Quoted 10 lines · Andy Shevchenko

kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out panic and oops helpers.

At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for existing users.

Nice!

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#6 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
include/linux/panic_notifier.h new file +2 -0
new file mode 100644
index 000000000000..41e32483d7a7
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_PANIC_NOTIFIERS_H

include/linux/panic_notifier.h line 12

Quoted 10 lines
include/linux/panic_notifier.h new file +10 -0
+#define _LINUX_PANIC_NOTIFIERS_H
+
+#include <linux/notifier.h>
+#include <linux/types.h>
+
+extern struct atomic_notifier_head panic_notifier_list;
+
+extern bool crash_kexec_post_notifiers;
+
+#endif	/* _LINUX_PANIC_NOTIFIERS_H */

Why is it worth it to add another file just for this? Seems like a very small file.

Luis

#7 lore raw
Quoted 14 lines · Luis Chamberlain
Quoted 12 lines · Andy Shevchenko
include/linux/panic_notifier.h new file +6 -0
new file mode 100644
index 000000000000..41e32483d7a7
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_PANIC_NOTIFIERS_H
+#define _LINUX_PANIC_NOTIFIERS_H
+
+#include <linux/notifier.h>
+#include <linux/types.h>
Quoted 8 lines

include/linux/panic_notifier.h line 12

Quoted 6 lines
include/linux/panic_notifier.h new file +6 -0
+
+extern struct atomic_notifier_head panic_notifier_list;
+
+extern bool crash_kexec_post_notifiers;
+
+#endif       /* _LINUX_PANIC_NOTIFIERS_H */

Why is it worth it to add another file just for this?

The main point is to break tons of loops that prevent having clean headers anymore.

In this case, see bug.h, which is very important in this sense.

Quoted 2 lines

Seems like a very
small file.

If it is an argument, it's kinda strange. We have much smaller headers.

Signature · 7 lines
With Best Regards,
Andy Shevchenko

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#8 lore raw
Quoted 24 lines · Andy Shevchenko
Quoted 14 lines · Luis Chamberlain
Quoted 12 lines · Andy Shevchenko
include/linux/panic_notifier.h new file +6 -0
new file mode 100644
index 000000000000..41e32483d7a7
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_PANIC_NOTIFIERS_H
+#define _LINUX_PANIC_NOTIFIERS_H
+
+#include <linux/notifier.h>
+#include <linux/types.h>
Quoted 8 lines

include/linux/panic_notifier.h line 12

Quoted 6 lines
include/linux/panic_notifier.h new file +6 -0
+
+extern struct atomic_notifier_head panic_notifier_list;
+
+extern bool crash_kexec_post_notifiers;
+
+#endif       /* _LINUX_PANIC_NOTIFIERS_H */

Why is it worth it to add another file just for this?

Quoted 4 lines

The main point is to break tons of loops that prevent having clean headers anymore.

In this case, see bug.h, which is very important in this sense.

OK based on the commit log this was not clear, it seemed more of moving panic stuff to its own file, so just cleanup.

Quoted 4 lines
Quoted 2 lines

Seems like a very
small file.

If it is an argument, it's kinda strange. We have much smaller headers.

The motivation for such separate file was just not clear on the commit log.

Luis

#9 lore raw
Quoted 3 lines · Luis Chamberlain
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Luis Chamberlain

On Tue, Apr 06, 2021 at 04:31:58PM +0300, Andy Shevchenko wrote:

...

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

Why is it worth it to add another file just for this?

The main point is to break tons of loops that prevent having clean headers anymore.

In this case, see bug.h, which is very important in this sense.

OK based on the commit log this was not clear, it seemed more of moving panic stuff to its own file, so just cleanup.

Sorry for that. it should have mentioned the kernel folder instead of lib. But I think it won't clarify the above.

In any case there are several purposes in this case
- dropping dependency in bug.h
- dropping a loop by moving out panic_notifier.h
- unload kernel.h from something which has its own domain

I think that you are referring to the commit message describing 3rd one, but not 1st and 2nd.

I will amend this for the future splits, thanks!

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Seems like a very
small file.

If it is an argument, it's kinda strange. We have much smaller headers.

The motivation for such separate file was just not clear on the commit log.

Signature · 7 lines
With Best Regards,
Andy Shevchenko

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#10 lore raw
Quoted 20 lines · Andy Shevchenko
Quoted 3 lines · Luis Chamberlain
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Luis Chamberlain

On Tue, Apr 06, 2021 at 04:31:58PM +0300, Andy Shevchenko wrote:

...

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

Why is it worth it to add another file just for this?

The main point is to break tons of loops that prevent having clean headers anymore.

In this case, see bug.h, which is very important in this sense.

OK based on the commit log this was not clear, it seemed more of moving panic stuff to its own file, so just cleanup.

Sorry for that. it should have mentioned the kernel folder instead of lib. But I think it won't clarify the above.

Quoted 7 lines

In any case there are several purposes in this case
- dropping dependency in bug.h
- dropping a loop by moving out panic_notifier.h
- unload kernel.h from something which has its own domain

I think that you are referring to the commit message describing 3rd one, but not 1st and 2nd.

Right!

Quoted 1 line

I will amend this for the future splits, thanks!

Don't get me wrong, I love the motivation behind just the 3rd purpose, however I figured there might be something more when I saw panic_notifier.h. It was just not clear.

But awesome stuff!

Luis

Acked-by on v1 1/1
#11 lore raw
In reply to Andy Shevchenko
Quoted 9 lines · Andy Shevchenko

kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out panic and oops helpers.

At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for existing users.

I like it! Do you have a multi-arch CI to do allmodconfig builds to double-check this?

-Kees

Signature · 6 lines
Kees Cook

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#12 lore raw
Quoted 6 lines · Kees Cook
Quoted 4 lines · Andy Shevchenko

kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out panic and oops helpers.

Quoted 8 lines
Quoted 5 lines

At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for existing users.

I like it! Do you have a multi-arch CI to do allmodconfig builds to double-check this?

Unfortunately no, I rely on plenty of bots that are harvesting mailing lists.

But I will appreciate it if somebody can run this through various build tests.

Quoted 1 line

Thanks!

Signature · 7 lines
With Best Regards,
Andy Shevchenko

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
maintainer
#13 lore raw
Quoted 11 lines · On Wed, 7 Apr 2021 11:46:37 +0300 Andy Shevchenko <[email protected]>…
Quoted 10 lines · Kees Cook
Quoted 8 lines · Andy Shevchenko

kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out panic and oops helpers.

At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for existing users.

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

I like it! Do you have a multi-arch CI to do allmodconfig builds to double-check this?

Unfortunately no, I rely on plenty of bots that are harvesting mailing lists.

But I will appreciate it if somebody can run this through various build tests.

um, did you try x86_64 allmodconfig?

I'm up to kernelh-split-out-panic-and-oops-helpers-fix-fix-fix-fix-fix-fix-fix.patch and counting.

From: Andrew Morton <[email protected]>
Subject: kernelh-split-out-panic-and-oops-helpers-fix

more files need panic_notifier.h

Cc Andy Shevchenko <[email protected]>

---

 arch/x86/xen/enlighten.c        |    1 +
 drivers/video/fbdev/hyperv_fb.c |    1 +
 2 files changed, 2 insertions(+)
arch/x86/xen/enlighten.c renamed from arch/x86/xen/enlighten.c~kernelh-split-out-panic-and-oops-helpers-fix +1 -0
@@ -6,6 +6,7 @@
 #include <linux/cpu.h>
 #include <linux/kexec.h>
 #include <linux/slab.h>
+#include <linux/panic_notifier.h>
 
 #include <xen/xen.h>
 #include <xen/features.h>
drivers/video/fbdev/hyperv_fb.c renamed from drivers/video/fbdev/hyperv_fb.c~kernelh-split-out-panic-and-oops-helpers-fix +1 -0
@@ -52,6 +52,7 @@
 #include <linux/completion.h>
 #include <linux/fb.h>
 #include <linux/pci.h>
+#include <linux/panic_notifier.h>
 #include <linux/efi.h>
 #include <linux/console.h>
 

_

From: Andrew Morton <[email protected]>
Subject: kernelh-split-out-panic-and-oops-helpers-fix-fix

arch/x86/purgatory/purgatory.c needs kernel.h

Cc Andy Shevchenko <[email protected]>

---

 arch/x86/purgatory/purgatory.c |    1 +
 1 file changed, 1 insertion(+)
arch/x86/purgatory/purgatory.c renamed from arch/x86/purgatory/purgatory.c~kernelh-split-out-panic-and-oops-helpers-fix-fix +1 -0
@@ -8,6 +8,7 @@
  *       Vivek Goyal <[email protected]>
  */
 
+#include <linux/kernel.h>
 #include <linux/bug.h>
 #include <crypto/sha2.h>
 #include <asm/purgatory.h>

_

From: Andrew Morton <[email protected]>
Subject: kernelh-split-out-panic-and-oops-helpers-fix-fix-fix

drivers/clk/analogbits/wrpll-cln28hpc.c needs minmax.h, math.h and limits.h

Cc Andy Shevchenko <[email protected]>

---

 drivers/clk/analogbits/wrpll-cln28hpc.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/clk/analogbits/wrpll-cln28hpc.c renamed from drivers/clk/analogbits/wrpll-cln28hpc.c~kernelh-split-out-panic-and-oops-helpers-fix-fix-fix +4 -0
@@ -25,6 +25,10 @@
 #include <linux/err.h>
 #include <linux/log2.h>
 #include <linux/math64.h>
+#include <linux/minmax.h>
+#include <linux/math.h>
+#include <linux/limits.h>
+
 #include <linux/clk/analogbits-wrpll-cln28hpc.h>
 
 /* MIN_INPUT_FREQ: minimum input clock frequency, in Hz (Fref_min) */

_

From: Andrew Morton <[email protected]>
Subject: kernelh-split-out-panic-and-oops-helpers-fix-fix-fix-fix

drivers/misc/pvpanic/pvpanic.c needs panic_notifier.h

Cc Andy Shevchenko <[email protected]>

---

 drivers/misc/pvpanic/pvpanic.c |    1 +
 1 file changed, 1 insertion(+)
drivers/misc/pvpanic/pvpanic.c renamed from drivers/misc/pvpanic/pvpanic.c~kernelh-split-out-panic-and-oops-helpers-fix-fix-fix-fix +1 -0
@@ -13,6 +13,7 @@
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/panic_notifier.h>
 #include <linux/types.h>
 #include <linux/cdev.h>
 #include <linux/list.h>

_
From: Andrew Morton <[email protected]>
Subject: kernelh-split-out-panic-and-oops-helpers-fix-fix-fix-fix-fix

fix drivers/misc/pvpanic/pvpanic.c and drivers/net/ipa/ipa_smp2p.c

Cc Andy Shevchenko <[email protected]>

---

 drivers/net/ipa/ipa_smp2p.c |    1 +
 1 file changed, 1 insertion(+)
drivers/net/ipa/ipa_smp2p.c renamed from drivers/net/ipa/ipa_smp2p.c~kernelh-split-out-panic-and-oops-helpers-fix-fix-fix-fix-fix +1 -0
@@ -8,6 +8,7 @@
 #include <linux/device.h>
 #include <linux/interrupt.h>
 #include <linux/notifier.h>
+#include <linux/panic_notifier.h>
 #include <linux/soc/qcom/smem.h>
 #include <linux/soc/qcom/smem_state.h>
 

_

From: Andrew Morton <[email protected]>
Subject: kernelh-split-out-panic-and-oops-helpers-fix-fix-fix-fix-fix-fix

fix drivers/power/reset/ltc2952-poweroff.c and drivers/misc/bcm-vk/bcm_vk_dev.c

Cc Andy Shevchenko <[email protected]>

---

 drivers/misc/bcm-vk/bcm_vk_dev.c       |    1 +
 drivers/power/reset/ltc2952-poweroff.c |    1 +
 2 files changed, 2 insertions(+)
drivers/power/reset/ltc2952-poweroff.c renamed from drivers/power/reset/ltc2952-poweroff.c~kernelh-split-out-panic-and-oops-helpers-fix-fix-fix-fix-fix-fix +1 -0
@@ -52,6 +52,7 @@
 #include <linux/slab.h>
 #include <linux/kmod.h>
 #include <linux/module.h>
+#include <linux/panic_notifier.h>
 #include <linux/mod_devicetable.h>
 #include <linux/gpio/consumer.h>
 #include <linux/reboot.h>
drivers/misc/bcm-vk/bcm_vk_dev.c renamed from drivers/misc/bcm-vk/bcm_vk_dev.c~kernelh-split-out-panic-and-oops-helpers-fix-fix-fix-fix-fix-fix +1 -0
@@ -9,6 +9,7 @@
 #include <linux/fs.h>
 #include <linux/idr.h>
 #include <linux/interrupt.h>
+#include <linux/panic_notifier.h>
 #include <linux/kref.h>
 #include <linux/module.h>
 #include <linux/mutex.h>

_

From: Andrew Morton <[email protected]>
Subject: kernelh-split-out-panic-and-oops-helpers-fix-fix-fix-fix-fix-fix-fix

fix drivers/leds/trigger/ledtrig-panic.c and drivers/firmware/google/gsmi.c

Cc Andy Shevchenko <[email protected]>

---

 drivers/firmware/google/gsmi.c       |    1 +
 drivers/leds/trigger/ledtrig-panic.c |    1 +
 2 files changed, 2 insertions(+)
drivers/leds/trigger/ledtrig-panic.c renamed from drivers/leds/trigger/ledtrig-panic.c~kernelh-split-out-panic-and-oops-helpers-fix-fix-fix-fix-fix-fix-fix +1 -0
@@ -8,6 +8,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/notifier.h>
+#include <linux/panic_notifier.h>
 #include <linux/leds.h>
 #include "../leds.h"
 
drivers/firmware/google/gsmi.c renamed from drivers/firmware/google/gsmi.c~kernelh-split-out-panic-and-oops-helpers-fix-fix-fix-fix-fix-fix-fix +1 -0
@@ -19,6 +19,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/fs.h>
 #include <linux/slab.h>
+#include <linux/panic_notifier.h>
 #include <linux/ioctl.h>
 #include <linux/acpi.h>
 #include <linux/io.h>

_

and.... drivers/leds/trigger/ledtrig-heartbeat.c as well.

I'll drop it.

#14 lore raw
Quoted 20 lines · Andrew Morton
Quoted 18 lines · On Wed, 7 Apr 2021 11:46:37 +0300 Andy Shevchenko <[email protected]>…
Quoted 6 lines · Kees Cook
Quoted 4 lines · Andy Shevchenko

kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out panic and oops helpers.

Quoted 8 lines
Quoted 5 lines

At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for existing users.

I like it! Do you have a multi-arch CI to do allmodconfig builds to double-check this?

Unfortunately no, I rely on plenty of bots that are harvesting mailing lists.

Quoted 8 lines
Quoted 2 lines

But I will appreciate it if somebody can run this through various build tests.

um, did you try x86_64 allmodconfig?

I'm up to kernelh-split-out-panic-and-oops-helpers-fix-fix-fix-fix-fix-fix-fix.patch and counting.

I will try on my side and will fix those, thanks!

Quoted 3 lines

and.... drivers/leds/trigger/ledtrig-heartbeat.c as well.

I'll drop it.

No problem, thanks for the report.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Acked-by on v1 1/1
#15 lore raw
In reply to Andy Shevchenko
Quoted 9 lines · Andy Shevchenko

kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out panic and oops helpers.

At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for existing users.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Acked-by on v1 1/1
#16 lore raw
In reply to Andy Shevchenko
Quoted 3 lines · Andy Shevchenko

kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out panic and oops helpers.

Yay.

Quoted 3 lines

At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for existing users.

I think it would be good to have some place to note that "This #include is just for backwards compatibility, it will go away RealSoonNow, so if you rely on something from linux/panic.h, include that explicitly yourself TYVM. And if you're looking for a janitorial task, write a script to check that every file that uses some identifier defined in panic.h actually includes that file. When all offenders are found and dealt with, remove the #include and this note.".

include/linux/panic.h line 86

Quoted 8 lines
include/linux/panic.h new file +8 -0
+
+struct taint_flag {
+	char c_true;	/* character printed when tainted */
+	char c_false;	/* character printed when not tainted */
+	bool module;	/* also show as a per-module taint flag */
+};
+
+extern const struct taint_flag taint_flags[TAINT_FLAGS_COUNT];

While you're doing this, nothing outside of kernel/panic.c cares about the definition of struct taint_flag or use the taint_flags array, so could you make the definition private to that file and make the array static? (Another patch, of course.)

include/linux/panic.h line 96

Quoted 9 lines
include/linux/panic.h new file +9 -0
+enum lockdep_ok {
+	LOCKDEP_STILL_OK,
+	LOCKDEP_NOW_UNRELIABLE,
+};
+
+extern const char *print_tainted(void);
+extern void add_taint(unsigned flag, enum lockdep_ok);
+extern int test_taint(unsigned flag);
+extern unsigned long get_taint(void);

I know you're just moving code, but it would be a nice opportunity to drop the redundant externs.

Rasmus

#17 lore raw
Quoted 8 lines · Rasmus Villemoes
Quoted 3 lines · Andy Shevchenko

kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out panic and oops helpers.

Yay.

Thanks!

Quoted 11 lines
Quoted 3 lines

At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for existing users.

I think it would be good to have some place to note that "This #include is just for backwards compatibility, it will go away RealSoonNow, so if you rely on something from linux/panic.h, include that explicitly yourself TYVM. And if you're looking for a janitorial task, write a script to check that every file that uses some identifier defined in panic.h actually includes that file. When all offenders are found and dealt with, remove the #include and this note.".

Good and...

Quoted 4 lines
Quoted 4 lines
include/linux/panic.h new file +4 -0
+struct taint_flag {
+	char c_true;	/* character printed when tainted */
+	char c_false;	/* character printed when not tainted */
+	bool module;	/* also show as a per-module taint flag */
Quoted 8 lines

include/linux/panic.h line 86

Quoted 3 lines
include/linux/panic.h new file +3 -0
+};
+
+extern const struct taint_flag taint_flags[TAINT_FLAGS_COUNT];

While you're doing this, nothing outside of kernel/panic.c cares about the definition of struct taint_flag or use the taint_flags array, so could you make the definition private to that file and make the array static? (Another patch, of course.)

...according to the above if *you are looking for a janitorial task*... :-))

Quoted 4 lines
Quoted 4 lines
include/linux/panic.h new file +4 -0
+enum lockdep_ok {
+	LOCKDEP_STILL_OK,
+	LOCKDEP_NOW_UNRELIABLE,
+};
Quoted 8 lines

include/linux/panic.h line 96

Quoted 5 lines
include/linux/panic.h new file +5 -0
+
+extern const char *print_tainted(void);
+extern void add_taint(unsigned flag, enum lockdep_ok);
+extern int test_taint(unsigned flag);
+extern unsigned long get_taint(void);

I know you're just moving code, but it would be a nice opportunity to drop the redundant externs.

As above. But for all these I have heard you. So, I'll keep this response as part of my always only growing TODO list.

Signature · 2 lines
With Best Regards,
Andy Shevchenko