[PATCH] x86/entry/64: Simplify ENCODE_FRAME_POINTER

From: Josh Poimboeuf
Date: Tue Feb 20 2018 - 21:42:24 EST


On Tue, Feb 20, 2018 at 02:25:03PM -0800, Linus Torvalds wrote:
> On Tue, Feb 20, 2018 at 1:01 PM, Dominik Brodowski
> <linux@xxxxxxxxxxxxxxxxxxxx> wrote:
> > +ENTRY(interrupt_entry)
> > + UNWIND_HINT_FUNC
> > +
> > + PUSH_AND_CLEAR_REGS save_ret=1
> > + ENCODE_FRAME_POINTER 8
> > +
> > + ret
> > +END(interrupt_entry)
>
> There's nothing wrong with this patch, but it does expose what a nasty
> hack our "ENCODE_FRAME_POINTER" thing is.
>
> It generates (when there is an offset, like this):
>
> leaq \ptregs_offset(%rsp), %rbp
> orq $0x1, %rbp
>
> and I would _really_ hope that the stack pointer is always aligned on
> interrupt entry, so I don't see why it's not just
>
> leaq 1+\ptregs_offset(%rsp), %rbp
>
> instead.
>
> I dunno. Let's ask Josh what the reason for the separate "or" was.
>
> But this is an independent issue of this patch, really.

Indeed, how about this?

----

From: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
Subject: [PATCH] x86/entry/64: Simplify ENCODE_FRAME_POINTER

On 64-bit, the stack pointer is always aligned on interrupt, so instead
of setting the LSB of the pt_regs address, we can just add 1 to it.

Suggested-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
---
arch/x86/entry/calling.h | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
index dce7092ab24a..400cea8bbf4b 100644
--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -172,12 +172,7 @@ For 32-bit we have the following conventions - kernel is built with
*/
.macro ENCODE_FRAME_POINTER ptregs_offset=0
#ifdef CONFIG_FRAME_POINTER
- .if \ptregs_offset
- leaq \ptregs_offset(%rsp), %rbp
- .else
- mov %rsp, %rbp
- .endif
- orq $0x1, %rbp
+ leaq 1+\ptregs_offset(%rsp), %rbp
#endif
.endm

--
2.14.3