public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>,
	linux-kernel@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Andy Lutomirski <luto@amacapital.net>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [RFC][PATCH 4/5] ftrace/x86_32: Clean up ftrace_regs_caller
Date: Thu, 16 Mar 2017 17:39:02 +0900	[thread overview]
Message-ID: <20170316173902.a671795e57e8088e68525e3d@kernel.org> (raw)
In-Reply-To: <20170315191124.0e175b24@gandalf.local.home>

On Wed, 15 Mar 2017 19:11:24 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Wed, 15 Mar 2017 16:13:43 -0500
> Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> 
> > On Wed, Mar 15, 2017 at 03:55:31PM -0400, Steven Rostedt wrote:
> > > From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> > > 
> > > When ftrace_regs_caller was created, it was designed to preserve flags as
> > > much as possible as it needed to act just like a breakpoint triggered on the
> > > same location. But the design is over complicated as it treated all
> > > operations as modifying flags. But push, mov and lea do not modify flags.
> > > This means the code can become more simplified by allowing flags to be
> > > stored further down.
> > > 
> > > Making ftrace_regs_caller simpler will also be useful in implementing fentry
> > > logic.
> > > 
> > > Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> > > ---
> > >  arch/x86/kernel/ftrace_32.S | 45 +++++++++++++++++++++++++--------------------
> > >  1 file changed, 25 insertions(+), 20 deletions(-)
> > > 
> > > diff --git a/arch/x86/kernel/ftrace_32.S b/arch/x86/kernel/ftrace_32.S
> > > index 73d61a62649d..8ca33d9806ac 100644
> > > --- a/arch/x86/kernel/ftrace_32.S
> > > +++ b/arch/x86/kernel/ftrace_32.S
> > > @@ -55,23 +55,30 @@ WEAK(ftrace_stub)
> > >  END(ftrace_caller)
> > >  
> > >  ENTRY(ftrace_regs_caller)
> > > -	pushf	/* push flags before compare (in cs location) */
> > > -
> > >  	/*
> > >  	 * i386 does not save SS and ESP when coming from kernel.
> > >  	 * Instead, to get sp, &regs->sp is used (see ptrace.h).
> > >  	 * Unfortunately, that means eflags must be at the same location
> > >  	 * as the current return ip is. We move the return ip into the
> > > -	 * ip location, and move flags into the return ip location.
> > > -	 */
> > > -	pushl	4(%esp)				/* save return ip into ip slot */
> > > +	 * regs->ip location, and move flags into the return ip location.
> > > +         */
> > > +	pushl	$__KERNEL_CS
> > > +	pushl	4(%esp)				/* Save the return ip */
> > > +
> > > +	/* temporarily save flags in the orig_ax location */
> > > +	pushf
> > >  
> > > -	pushl	$0				/* Load 0 into orig_ax */
> > >  	pushl	%gs
> > >  	pushl	%fs
> > >  	pushl	%es
> > >  	pushl	%ds
> > >  	pushl	%eax
> > > +
> > > +	/* move flags into the location of where the return ip was */
> > > +	movl	5*4(%esp), %eax
> > > +	movl	$0, (%esp)			/* Load 0 into orig_ax */  
> > 
> > This writes a 0 into regs->ax instead of regs->orig_ax.
> > 
> 
> Ouch, I'm surprised this didn't crash my box. Thanks for catching it.

Since mcount/fentry is just "called", %eax (caller-saved register)
will be ignored :) Of course for kprobes and livepatch, this should be
critical.

Except for the above point, it seems good to me.

Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>

Thanks,

-- 
Masami Hiramatsu <mhiramat@kernel.org>

  reply	other threads:[~2017-03-16  8:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-15 19:55 [RFC][PATCH 0/5] ftrace/x86_32: Ftrace cleanup and add support for -mfentry Steven Rostedt
2017-03-15 19:55 ` [RFC][PATCH 1/5] x86/ftrace: Rename mcount_64.S to ftrace.S Steven Rostedt
2017-03-15 19:55 ` [RFC][PATCH 2/5] ftrace/x86-32: Move the ftrace specific code out of entry_32.S Steven Rostedt
2017-03-15 19:55 ` [RFC][PATCH 3/5] ftrace/x86_32: Add stack frame pointer to ftrace_caller Steven Rostedt
2017-03-15 21:13   ` Josh Poimboeuf
2017-03-15 19:55 ` [RFC][PATCH 4/5] ftrace/x86_32: Clean up ftrace_regs_caller Steven Rostedt
2017-03-15 21:13   ` Josh Poimboeuf
2017-03-15 23:11     ` Steven Rostedt
2017-03-16  8:39       ` Masami Hiramatsu [this message]
2017-03-15 19:55 ` [RFC][PATCH 5/5] ftrace/x86-32: Add -mfentry support to x86_32 with DYNAMIC_FTRACE set Steven Rostedt
2017-03-15 21:55   ` Josh Poimboeuf
2017-03-15 23:13     ` Steven Rostedt
2017-03-16  9:24   ` Masami Hiramatsu
2017-03-16 13:02     ` 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=20170316173902.a671795e57e8088e68525e3d@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /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