Skip to contentSkip to conversation

x86/traps: add CONFIG_BUG to the use of __warn()

PATCH In review Stephen Zhang 3 participants 5 messages Apr 25, 2022 – Apr 26, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/traps: add CONFIG_BUG to the use of __warn()

From: zhangshida <[email protected]>

__warn() is declared when CONFIG_BUG is defined, so add CONFIG_BUG when used.

---
 arch/x86/kernel/traps.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kernel/traps.c +2 -0
index 1563fb995005..81cc28a59c24 100644
@@ -246,7 +246,9 @@ DEFINE_IDTENTRY_ERRORCODE(exc_control_protection)
 	pr_err("Missing ENDBR: %pS\n", (void *)instruction_pointer(regs));
 	if (!ibt_fatal) {
 		printk(KERN_DEFAULT CUT_HERE);
+#ifdef CONFIG_BUG
 		__warn(__FILE__, __LINE__, (void *)regs->ip, TAINT_WARN, regs, NULL);
+#endif
 		return;
 	}
 	BUG();
Signature · 1 line
2.25.1
#1 lore raw

arch/x86/kernel/traps.c DEFINE_IDTENTRY_ERRORCODE(exc_control_protection) · line 251

Quoted 9 lines · Stephen Zhang
arch/x86/kernel/traps.c +2 -0
@@ -246,7 +246,9 @@ DEFINE_IDTENTRY_ERRORCODE(exc_control_protection)
 	pr_err("Missing ENDBR: %pS\n", (void *)instruction_pointer(regs));
 	if (!ibt_fatal) {
 		printk(KERN_DEFAULT CUT_HERE);
+#ifdef CONFIG_BUG
 		__warn(__FILE__, __LINE__, (void *)regs->ip, TAINT_WARN, regs, NULL);
+#endif

This really should be done with an #ifdef'd stub in in bug.h, not an #ifdef at every call site. I assume there was a good reason for not using the normal WARN*() macros.

#2 lore raw
Quoted 14 lines · Dave Hansen

arch/x86/kernel/traps.c DEFINE_IDTENTRY_ERRORCODE(exc_control_protection) · line 251

Quoted 9 lines · Stephen Zhang
arch/x86/kernel/traps.c +2 -0
@@ -246,7 +246,9 @@ DEFINE_IDTENTRY_ERRORCODE(exc_control_protection)
 	pr_err("Missing ENDBR: %pS\n", (void *)instruction_pointer(regs));
 	if (!ibt_fatal) {
 		printk(KERN_DEFAULT CUT_HERE);
+#ifdef CONFIG_BUG
 		__warn(__FILE__, __LINE__, (void *)regs->ip, TAINT_WARN, regs, NULL);
+#endif

This really should be done with an #ifdef'd stub in in bug.h, not an #ifdef at every call site. I assume there was a good reason for not using the normal WARN*() macros.

I think the idea was to have the pr_err() unconditional, and if you have the fancy crap on also print a full backtrace or something.

But yeah, a few stubs in bug.h ought to make this go away too.

#3 lore raw
Quoted 16 lines · Peter Zijlstra
Quoted 14 lines · Dave Hansen

arch/x86/kernel/traps.c DEFINE_IDTENTRY_ERRORCODE(exc_control_protection) · line 251

Quoted 9 lines · Stephen Zhang
arch/x86/kernel/traps.c +2 -0
@@ -246,7 +246,9 @@ DEFINE_IDTENTRY_ERRORCODE(exc_control_protection)
 	pr_err("Missing ENDBR: %pS\n", (void *)instruction_pointer(regs));
 	if (!ibt_fatal) {
 		printk(KERN_DEFAULT CUT_HERE);
+#ifdef CONFIG_BUG
 		__warn(__FILE__, __LINE__, (void *)regs->ip, TAINT_WARN, regs, NULL);
+#endif

This really should be done with an #ifdef'd stub in in bug.h, not an #ifdef at every call site. I assume there was a good reason for not using the normal WARN*() macros.

Quoted 4 lines

I think the idea was to have the pr_err() unconditional, and if you have the fancy crap on also print a full backtrace or something.

But yeah, a few stubs in bug.h ought to make this go away too.

As pointed out by Boris, __warn is actually uncondtionally defined in panic.c, the below seems to build.

---

include/asm-generic/bug.h +6 -5
index edb0e2a602a8..ba1f860af38b 100644
@@ -21,6 +21,12 @@
 #include <linux/panic.h>
 #include <linux/printk.h>
 
+struct warn_args;
+struct pt_regs;
+
+void __warn(const char *file, int line, void *caller, unsigned taint,
+	    struct pt_regs *regs, struct warn_args *args);
+
 #ifdef CONFIG_BUG
 
 #ifdef CONFIG_GENERIC_BUG
@@ -110,11 +116,6 @@ extern __printf(1, 2) void __warn_printk(const char *fmt, ...);
 #endif
 
 /* used internally by panic.c */
-struct warn_args;
-struct pt_regs;
-
-void __warn(const char *file, int line, void *caller, unsigned taint,
-	    struct pt_regs *regs, struct warn_args *args);
 
 #ifndef WARN_ON
 #define WARN_ON(condition) ({						\
#4 lore raw
Quoted 23 lines

As pointed out by Boris, __warn is actually uncondtionally defined in panic.c, the below seems to build.

---

include/asm-generic/bug.h +6 -0
index edb0e2a602a8..ba1f860af38b 100644
@@ -21,6 +21,12 @@
 #include <linux/panic.h>
 #include <linux/printk.h>
 
+struct warn_args;
+struct pt_regs;
+
+void __warn(const char *file, int line, void *caller, unsigned taint,
+           struct pt_regs *regs, struct warn_args *args);
+
 #ifdef CONFIG_BUG
 
 #ifdef CONFIG_GENERIC_BUG
@@ -110,11 +116,6 @@ extern __printf(1, 2) void __warn_printk(const char *fmt, ...);
 #endif

include/asm-generic/bug.h extern __printf(1, 2) void __warn_printk(const char *fmt, ...); · line 121

Quoted 10 lines
include/asm-generic/bug.h +0 -5
 
 /* used internally by panic.c */
-struct warn_args;
-struct pt_regs;
-
-void __warn(const char *file, int line, void *caller, unsigned taint,
-           struct pt_regs *regs, struct warn_args *args);
 
 #ifndef WARN_ON
 #define WARN_ON(condition) ({                                          \

Thanks.I will make a new version based on this suggestion.