From: Steven Rostedt <rostedt@goodmis.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Miroslav Benes <mbenes@suse.cz>,
Thomas Gleixner <tglx@linutronix.de>,
Masami Hiramatsu <mhiramat@kernel.org>
Subject: Re: [PATCH 2/3 v4] ftrace/x86: Allow for arguments to be passed in to ftrace_regs by default
Date: Mon, 9 Nov 2020 18:16:10 -0500 [thread overview]
Message-ID: <20201109181610.1b3f7d9f@oasis.local.home> (raw)
In-Reply-To: <20201109111043.GD2594@hirez.programming.kicks-ass.net>
On Mon, 9 Nov 2020 12:10:43 +0100
Peter Zijlstra <peterz@infradead.org> wrote:
> > SYM_INNER_LABEL(ftrace_caller_op_ptr, SYM_L_GLOBAL)
> > /* Load the ftrace_ops into the 3rd parameter */
> > movq function_trace_op(%rip), %rdx
> >
> > - /* regs go into 4th parameter (but make it NULL) */
> > - movq $0, %rcx
> > + /* regs go into 4th parameter */
> > + leaq (%rsp), %rcx
> > +
> > + /* Only ops with REGS flag set should have CS register set */
> > + movq $0, CS(%rsp)
> >
> > SYM_INNER_LABEL(ftrace_call, SYM_L_GLOBAL)
> > call ftrace_stub
>
> You now seem to be relying on save_mcount_regs() resulting in a cleared
> CS, however, AFAICT CS is uninitialized stack garbage.
We have two trampolines that are also used to copy for other
trampolines that are dynamically created. There's this one
(ftrace_caller) and then there's the regs one (ftrace_regs_caller).
This one clears the CS in pt_regs to let the arch code know that the
ftrace_regs is not a full pt_regs and anyone trying to get it with
ftrace_get_regs() will get a NULL pointer. But the ftrace_regs_caller
loads the CS register with __KERNEL_CS, which is non zero, and the
ftrace_get_regs() will return the full pt_regs if it is set.
ftrace_caller:
[..]
movq $0, CS(%rsp) <- loads zero into pt_regs->cs for internal use only.
[..]
call callback
ftrace_regs_caller:
[..]
movq $__KERNEL_CS, %rcx
movq %rcx, CS(%rsp)
[..]
call callback
Then in the callback we have:
callback(..., struct ftrace_regs *fregs)
{
struct pt_regs *regs = ftrace_get_regs(fregs);
}
Where ftrace_get_regs is arch specific and returns for x86_64:
static __always_inline struct pt_regs *
arch_ftrace_get_regs(struct ftrace_regs *fregs)
{
/* Only when FL_SAVE_REGS is set, cs will be non zero */
if (!fregs->regs.cs)
return NULL;
return &fregs->regs;
}
What am I missing?
-- Steve
next prev parent reply other threads:[~2020-11-09 23:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-06 21:42 [PATCH 0/3 v4] ftrace: Add access to function arguments for all callbacks Steven Rostedt
2020-11-06 21:42 ` [PATCH 1/3 v4] ftrace: Have the callbacks receive a struct ftrace_regs instead of pt_regs Steven Rostedt
2020-11-07 4:29 ` Masami Hiramatsu
2020-11-06 21:42 ` [PATCH 2/3 v4] ftrace/x86: Allow for arguments to be passed in to ftrace_regs by default Steven Rostedt
2020-11-09 11:10 ` Peter Zijlstra
2020-11-09 23:16 ` Steven Rostedt [this message]
2020-11-10 9:20 ` Peter Zijlstra
2020-11-06 21:42 ` [PATCH 3/3 v4] livepatch: Use the default ftrace_ops instead of REGS when ARGS is available Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201109181610.1b3f7d9f@oasis.local.home \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox