[PATCH v3 14/15] powerpc/bug: Annotate reachable after warning trap

From: Christophe Leroy
Date: Fri Jun 23 2023 - 13:07:26 EST


This commit is copied from commit bfb1a7c91fb7 ("x86/bug: Merge
annotate_reachable() into _BUG_FLAGS() asm")

'twi 31,0,0' is a BUG instruction, which is by default a dead end.

But the same instruction is used for WARNINGs and the execution
resumes with the following instruction. Mark it reachable so
that objtool knows that it is not a dead end in that case.

Also change the unreachable() annotation by __builtin_unreachable()
since objtool already knows that a BUG instruction is a dead end.

Signed-off-by: Christophe Leroy <christophe.leroy@xxxxxxxxxx>
---
arch/powerpc/include/asm/bug.h | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/bug.h b/arch/powerpc/include/asm/bug.h
index a565995fb742..5550ebffb146 100644
--- a/arch/powerpc/include/asm/bug.h
+++ b/arch/powerpc/include/asm/bug.h
@@ -4,6 +4,7 @@
#ifdef __KERNEL__

#include <asm/asm-compat.h>
+#include <linux/objtool.h>

#ifdef CONFIG_BUG

@@ -51,10 +52,11 @@
".previous\n"
#endif

-#define BUG_ENTRY(insn, flags, ...) \
+#define BUG_ENTRY(insn, flags, extra, ...) \
__asm__ __volatile__( \
"1: " insn "\n" \
_EMIT_BUG_ENTRY \
+ extra \
: : "i" (__FILE__), "i" (__LINE__), \
"i" (flags), \
"i" (sizeof(struct bug_entry)), \
@@ -67,12 +69,12 @@
*/

#define BUG() do { \
- BUG_ENTRY("twi 31, 0, 0", 0); \
- unreachable(); \
+ BUG_ENTRY("twi 31, 0, 0", 0, ""); \
+ __builtin_unreachable(); \
} while (0)
#define HAVE_ARCH_BUG

-#define __WARN_FLAGS(flags) BUG_ENTRY("twi 31, 0, 0", BUGFLAG_WARNING | (flags))
+#define __WARN_FLAGS(flags) BUG_ENTRY("twi 31, 0, 0", BUGFLAG_WARNING | (flags), ASM_REACHABLE)

#ifdef CONFIG_PPC64
#define BUG_ON(x) do { \
@@ -80,7 +82,7 @@
if (x) \
BUG(); \
} else { \
- BUG_ENTRY(PPC_TLNEI " %4, 0", 0, "r" ((__force long)(x))); \
+ BUG_ENTRY(PPC_TLNEI " %4, 0", 0, "", "r" ((__force long)(x))); \
} \
} while (0)

@@ -92,7 +94,7 @@
} else { \
BUG_ENTRY(PPC_TLNEI " %4, 0", \
BUGFLAG_WARNING | BUGFLAG_TAINT(TAINT_WARN), \
- "r" (__ret_warn_on)); \
+ "", "r" (__ret_warn_on)); \
} \
unlikely(__ret_warn_on); \
})
--
2.40.1