Re: [RFC][PATCH 0/7] ftrace/x86: Clean up of mcount.S code

Linus Torvalds
2014-11-25T01:34:07Z

On Mon, Nov 24, 2014 at 4:42 PM, Steven Rostedt <rostedt@goodmis.org> wrote:
>
> Let me know if these changes have mcount.S give you less heebie-jeebies.

So I haven't looked at the individual patches, I just looked at the
rolled-up final patch in this email.

And yes, from that final patch, I certainly like this much more. At
least it now creates the frame in the obvious place, and the comments
explain the layout.

However, explain this (in the ftrace_caller_setup macro):

#ifdef CC_USING_FENTRY
- movq SS+16(%rsp), %rsi
+ movq MCOUNT_REG_SIZE+8+\added(%rsp), %rsi
#else
- movq 8(%rbp), %rsi
+ /* Need to grab the original %rbp */
+ movq RBP(%rsp), %rsi
+ /* Now parent address is 8 above original %rbp */
+ movq 8(%rsi), %rsi
#endif

Why isn't that "follow rbp" approach now *always* the right thing to
do, regardless of fentry-vs-not? And in particular, couldn't you have
made '%rsi' already contain that old rbp address in save_mcount_regs,
the same way %rdi contains the RIP value?

(Yes, you can only do that after you've saved the old %rsi, but that's
easy enough to do by just delaying the second

mov %rsp,%rbp

until after the save area, and replacing it with

mov %rbp,%rsi
lea MCOUNT_REG_SIZE - MCOUNT_FRAME_SIZE(%rsp),%rbp

after the saving of the frame. And now you have that RBP(%rsp) in %rsi
already, so regardless of whether you have CC_USING_FENTRY or not, the
above code becomes just

/* Now parent address is 8 above original %rbp */
movq 8(%rsi), %rsi

No?

Ok, so I didn't write it all out, and maybe I made some mistake while
writing this email. but it *looks* like your ftrace_caller_setup macro
is just unnecessarily complicated, and again, it's because you have
two different macros and they aren't taking advantage of each other
very well.

Hmm?

Linus