x86/alternatives: Add stack frame dependency to alternative_call_2()
authorJosh Poimboeuf <jpoimboe@redhat.com>
Fri, 23 Sep 2016 21:49:39 +0000 (16:49 -0500)
committerIngo Molnar <mingo@kernel.org>
Sat, 24 Sep 2016 07:30:03 +0000 (09:30 +0200)
Linus reported the following objtool warning:

  kernel/signal.o: warning: objtool: .altinstr_replacement+0x54: call without frame pointer save/setup

The warning is valid.  It's caused by the fact that gcc placed the call
instruction in alternative_call_2()'s inline asm before the frame
pointer setup, which breaks frame pointer convention and can result in a
bad stack trace.

Force a stack frame to be created before the call instruction by listing
the stack pointer as an output operand in the inline asm statement.

Reported-and-tested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20160923214939.j5o7c67nhepzmh3t@treble
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/include/asm/alternative.h

index e77a6443104ff1d2b3162e17b1958b753c95be39..1b020381ab38965ae2a80d2d86df32c66c92e2e8 100644 (file)
@@ -217,10 +217,14 @@ static inline int alternatives_text_reserved(void *start, void *end)
  */
 #define alternative_call_2(oldfunc, newfunc1, feature1, newfunc2, feature2,   \
                           output, input...)                                  \
+{                                                                            \
+       register void *__sp asm(_ASM_SP);                                     \
        asm volatile (ALTERNATIVE_2("call %P[old]", "call %P[new1]", feature1,\
                "call %P[new2]", feature2)                                    \
-               : output : [old] "i" (oldfunc), [new1] "i" (newfunc1),        \
-               [new2] "i" (newfunc2), ## input)
+               : output, "+r" (__sp)                                         \
+               : [old] "i" (oldfunc), [new1] "i" (newfunc1),                 \
+                 [new2] "i" (newfunc2), ## input);                           \
+}
 
 /*
  * use this macro(s) if you need more than one output parameter