From: Andi Kleen <[email protected]>

The speculative jump trampoline has to contain unreachable code.
objtool keeps complaining

arch/x86/lib/retpoline.o: warning: objtool: __x86.indirect_thunk()+0x8: 
unreachable instruction

I tried to fix it here by adding ASM_UNREACHABLE annotation (after
supporting them for pure assembler), but it still complains.
Seems like a objtool bug?

So it doesn't actually fix the warning oyet.
Of course it's just a warning so the kernel will still work fine.

Perhaps Josh can figure it out

Cc: [email protected]
Not-Signed-off-by: Andi Kleen <[email protected]>
Not-Signed-off-by: David Woodhouse <[email protected]>
---
 arch/x86/lib/retpoline.S |  5 +++++
 include/linux/compiler.h | 10 +++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/arch/x86/lib/retpoline.S b/arch/x86/lib/retpoline.S
index bbdda5cc136e..8112feaea6ff 100644
--- a/arch/x86/lib/retpoline.S
+++ b/arch/x86/lib/retpoline.S
@@ -2,6 +2,7 @@
 
 #include <linux/stringify.h>
 #include <linux/linkage.h>
+#include <linux/compiler.h>
 #include <asm/dwarf2.h>
 #include <asm/cpufeatures.h>
 #include <asm/alternative-asm.h>
@@ -14,7 +15,9 @@ ENTRY(__x86.indirect_thunk.\reg)
        ALTERNATIVE "call 2f", __stringify(jmp *%\reg), X86_BUG_NO_RETPOLINE
 1:
        lfence
+       ASM_UNREACHABLE
        jmp     1b
+       ASM_UNREACHABLE
 2:
        mov     %\reg, (%\sp)
        ret
@@ -40,7 +43,9 @@ ENTRY(__x86.indirect_thunk)
        ALTERNATIVE "call 2f", "ret", X86_BUG_NO_RETPOLINE
 1:
        lfence
+       ASM_UNREACHABLE
        jmp     1b
+       ASM_UNREACHABLE
 2:
        lea     4(%esp), %esp
        ret
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 52e611ab9a6c..cfba91acc79a 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -269,7 +269,15 @@ static __always_inline void __write_once_size(volatile 
void *p, void *res, int s
 
 #endif /* __KERNEL__ */
 
-#endif /* __ASSEMBLY__ */
+#else /* __ASSEMBLY__ */
+
+#define ASM_UNREACHABLE \
+       999:                                            \
+       .pushsection .discard.unreachable;              \
+       .long 999b - .;                                 \
+       .popsection
+
+#endif /* !__ASSEMBLY__ */
 
 /* Compile time object size, -1 for unknown */
 #ifndef __compiletime_object_size
-- 
2.14.3

Reply via email to