[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251126095418.GW3245006@noisy.programming.kicks-ass.net>
Date: Wed, 26 Nov 2025 10:54:18 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Linus Torvalds <torvalds@...uxfoundation.org>
Cc: x86@...nel.org, ardb@...nel.org, linux-kernel@...r.kernel.org,
kees@...nel.org, acarmina@...hat.com, jpoimboe@...nel.org,
mark.rutland@....com, maciej.wieczor-retman@...el.com
Subject: Re: [PATCH v2 08/12] x86/bug: Add BUG_FORMAT basics
On Tue, Nov 25, 2025 at 08:27:50AM -0800, Linus Torvalds wrote:
> On Tue, 25 Nov 2025 at 07:17, Peter Zijlstra <peterz@...radead.org> wrote:
> >
> > Ard came up with this glorious hack :-)
>
> "glorious".
>
> Hmm. I _really_ don't love how it now uses that odd label across
> macros, it's not screaming "obvious" to me.
True.
> How bad would it be to just not use a NULL pointer at all, and instead
> make the "no format" be "empty format"?
Certainly, how does this look?
I verified it works on normal C code and that it compiles and the object
data looks right for Rust code.
---
diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h
index d0a96ff5c02c..4b5ab56903bb 100644
--- a/arch/x86/include/asm/bug.h
+++ b/arch/x86/include/asm/bug.h
@@ -86,7 +86,7 @@ extern void __WARN_trap(struct bug_entry *bug, ...);
#ifdef CONFIG_DEBUG_BUGVERBOSE_DETAILED
#define WARN_CONDITION_STR(cond_str) cond_str
#else
-#define WARN_CONDITION_STR(cond_str) NULL
+#define WARN_CONDITION_STR(cond_str) ""
#endif
#define _BUG_FLAGS(cond_str, ins, flags, extra) \
@@ -103,8 +103,12 @@ do { \
} while (0)
#define ARCH_WARN_ASM(file, line, flags, size) \
+ ".pushsection .rodata.str1.1, \"aMS\", @progbits, 1\n" \
+ "99:\n" \
+ "\t.string \"\"\n" \
+ ".popsection\n" \
"1:\t " ASM_UD2 "\n" \
- _BUG_FLAGS_ASM("0", file, line, flags, size, "")
+ _BUG_FLAGS_ASM("99b", file, line, flags, size, "")
#else
diff --git a/lib/bug.c b/lib/bug.c
index 581a66b88c5c..edd9041f89f3 100644
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -144,7 +144,17 @@ static const char *bug_get_format(struct bug_entry *bug)
const char *format = NULL;
#ifdef HAVE_ARCH_BUG_FORMAT
#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
- format = (const char *)&bug->format_disp + bug->format_disp;
+ /*
+ * Allow an architecture to:
+ * - relative encode NULL (difficult vs KASLR);
+ * - use a literal 0 (there are no valid objects inside
+ * the __bug_table itself to refer to after all);
+ * - use an empty string.
+ */
+ if (bug->format_disp)
+ format = (const char *)&bug->format_disp + bug->format_disp;
+ if (format && format[0] == '\0')
+ format = NULL;
#else
format = bug->format;
#endif
Powered by blists - more mailing lists