From: mhiramat at kernel.org (Masami Hiramatsu)
Subject: [PATCH 2/4] x86/kprobes: Fix frame pointer annotations
Date: Thu, 9 May 2019 10:20:30 +0900 [thread overview]
Message-ID: <20190509102030.dfa62e058f09d0d8cbdd6053@kernel.org> (raw)
In-Reply-To: <20190508184848.qerg3flv3ej3xsev@treble>
Hi Josh,
On Wed, 8 May 2019 13:48:48 -0500
Josh Poimboeuf <jpoimboe at redhat.com> wrote:
> On Wed, May 08, 2019 at 05:39:07PM +0200, Peter Zijlstra wrote:
> > On Wed, May 08, 2019 at 07:42:48AM -0500, Josh Poimboeuf wrote:
> > > On Wed, May 08, 2019 at 02:04:16PM +0200, Peter Zijlstra wrote:
> >
> > > > Do the x86_64 variants also want some ORC annotation?
> > >
> > > Maybe so. Though it looks like regs->ip isn't saved. The saved
> > > registers might need to be tweaked. I'll need to look into it.
> >
> > What all these sites do (and maybe we should look at unifying them
> > somehow) is turn a CALL frame (aka RET-IP) into an exception frame (aka
> > pt_regs).
> >
> > So regs->ip will be the return address (which is fixed up to be the CALL
> > address in the handler).
>
> But from what I can tell, trampoline_handler() hard-codes regs->ip to
> point to kretprobe_trampoline(), and the original return address is
> placed in regs->sp.
>
> Masami, is there a reason why regs->ip doesn't have the original return
> address and regs->sp doesn't have the original SP? I think that would
> help the unwinder understand things.
Yes, for regs->ip, there is a histrical reason. Since previously, we had
an int3 at trampoline, so the user (kretprobe) handler expects that
regs->ip is trampoline address and ri->ret_addr is original return address.
It is better to check the other archs, but I think it is possible to
change the regs->ip to original return address, since no one cares such
"fixed address". :)
For the regs->sp, there are 2 reasons.
For x86-64, it's just for over-optimizing (reduce stack usage).
I think we can make a gap for putting return address, something like
"kretprobe_trampoline:\n"
#ifdef CONFIG_X86_64
" pushq %rsp\n" /* Make a gap for return address */
" pushq 0(%rsp)\n" /* Copy original stack pointer */
" pushfq\n"
SAVE_REGS_STRING
" movq %rsp, %rdi\n"
" call trampoline_handler\n"
/* Push the true return address to the bottom */
" movq %rax, 20*8(%rsp)\n"
RESTORE_REGS_STRING
" popfq\n"
" addq $8, %rsp\n" /* Skip original stack pointer */
For i386 (x86-32), there is no other way to keep ®s->sp as
the original stack pointer. It has to be changed with this series,
maybe as same as x86-64.
Thank you,
--
Masami Hiramatsu <mhiramat at kernel.org>
WARNING: multiple messages have this Message-ID (diff)
From: mhiramat@kernel.org (Masami Hiramatsu)
Subject: [PATCH 2/4] x86/kprobes: Fix frame pointer annotations
Date: Thu, 9 May 2019 10:20:30 +0900 [thread overview]
Message-ID: <20190509102030.dfa62e058f09d0d8cbdd6053@kernel.org> (raw)
Message-ID: <20190509012030.pMbDCkPTMeMBJzWf26XnlfDW7pboPsWUInp2-6MEN4I@z> (raw)
In-Reply-To: <20190508184848.qerg3flv3ej3xsev@treble>
Hi Josh,
On Wed, 8 May 2019 13:48:48 -0500
Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> On Wed, May 08, 2019@05:39:07PM +0200, Peter Zijlstra wrote:
> > On Wed, May 08, 2019@07:42:48AM -0500, Josh Poimboeuf wrote:
> > > On Wed, May 08, 2019@02:04:16PM +0200, Peter Zijlstra wrote:
> >
> > > > Do the x86_64 variants also want some ORC annotation?
> > >
> > > Maybe so. Though it looks like regs->ip isn't saved. The saved
> > > registers might need to be tweaked. I'll need to look into it.
> >
> > What all these sites do (and maybe we should look at unifying them
> > somehow) is turn a CALL frame (aka RET-IP) into an exception frame (aka
> > pt_regs).
> >
> > So regs->ip will be the return address (which is fixed up to be the CALL
> > address in the handler).
>
> But from what I can tell, trampoline_handler() hard-codes regs->ip to
> point to kretprobe_trampoline(), and the original return address is
> placed in regs->sp.
>
> Masami, is there a reason why regs->ip doesn't have the original return
> address and regs->sp doesn't have the original SP? I think that would
> help the unwinder understand things.
Yes, for regs->ip, there is a histrical reason. Since previously, we had
an int3 at trampoline, so the user (kretprobe) handler expects that
regs->ip is trampoline address and ri->ret_addr is original return address.
It is better to check the other archs, but I think it is possible to
change the regs->ip to original return address, since no one cares such
"fixed address". :)
For the regs->sp, there are 2 reasons.
For x86-64, it's just for over-optimizing (reduce stack usage).
I think we can make a gap for putting return address, something like
"kretprobe_trampoline:\n"
#ifdef CONFIG_X86_64
" pushq %rsp\n" /* Make a gap for return address */
" pushq 0(%rsp)\n" /* Copy original stack pointer */
" pushfq\n"
SAVE_REGS_STRING
" movq %rsp, %rdi\n"
" call trampoline_handler\n"
/* Push the true return address to the bottom */
" movq %rax, 20*8(%rsp)\n"
RESTORE_REGS_STRING
" popfq\n"
" addq $8, %rsp\n" /* Skip original stack pointer */
For i386 (x86-32), there is no other way to keep ®s->sp as
the original stack pointer. It has to be changed with this series,
maybe as same as x86-64.
Thank you,
--
Masami Hiramatsu <mhiramat at kernel.org>
next prev parent reply other threads:[~2019-05-09 1:20 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-08 7:49 [PATCH 0/4] x86: int3 fallout peterz
2019-05-08 7:49 ` Peter Zijlstra
2019-05-08 7:49 ` [PATCH 1/4] x86/entry/32: Clean up return from interrupt preemption path peterz
2019-05-08 7:49 ` Peter Zijlstra
2019-05-08 7:49 ` [PATCH 2/4] x86/kprobes: Fix frame pointer annotations peterz
2019-05-08 7:49 ` Peter Zijlstra
2019-05-08 11:54 ` jpoimboe
2019-05-08 11:54 ` Josh Poimboeuf
2019-05-08 12:04 ` peterz
2019-05-08 12:04 ` Peter Zijlstra
[not found] ` <20190508124248.u5ukpbhnh4wpiccq@treble>
[not found] ` <20190508153907.GM2589@hirez.programming.kicks-ass.net>
2019-05-08 18:48 ` jpoimboe
2019-05-08 18:48 ` Josh Poimboeuf
2019-05-09 1:20 ` mhiramat [this message]
2019-05-09 1:20 ` Masami Hiramatsu
2019-05-09 8:14 ` peterz
2019-05-09 8:14 ` Peter Zijlstra
2019-05-09 9:27 ` peterz
2019-05-09 9:27 ` Peter Zijlstra
2019-05-09 14:00 ` jpoimboe
2019-05-09 14:00 ` Josh Poimboeuf
2019-05-09 14:01 ` mhiramat
2019-05-09 14:01 ` Masami Hiramatsu
2019-05-09 17:14 ` peterz
2019-05-09 17:14 ` Peter Zijlstra
2019-05-10 4:58 ` mhiramat
2019-05-10 4:58 ` Masami Hiramatsu
2019-05-10 12:31 ` peterz
2019-05-10 12:31 ` Peter Zijlstra
2019-05-11 0:52 ` mhiramat
2019-05-11 0:52 ` Masami Hiramatsu
2019-05-10 12:40 ` peterz
2019-05-10 12:40 ` Peter Zijlstra
2019-05-11 0:56 ` mhiramat
2019-05-11 0:56 ` Masami Hiramatsu
2019-05-13 8:15 ` peterz
2019-05-13 8:15 ` Peter Zijlstra
2019-05-09 16:20 ` luto
2019-05-09 16:20 ` Andy Lutomirski
2019-05-09 17:18 ` peterz
2019-05-09 17:18 ` Peter Zijlstra
2019-05-09 17:43 ` rostedt
2019-05-09 17:43 ` Steven Rostedt
2019-05-10 3:21 ` mhiramat
2019-05-10 3:21 ` Masami Hiramatsu
2019-05-10 12:14 ` peterz
2019-05-10 12:14 ` Peter Zijlstra
2019-05-10 12:17 ` peterz
2019-05-10 12:17 ` Peter Zijlstra
2019-05-10 14:54 ` rostedt
2019-05-10 14:54 ` Steven Rostedt
2019-05-09 17:37 ` rostedt
2019-05-09 17:37 ` Steven Rostedt
2019-05-09 18:26 ` peterz
2019-05-09 18:26 ` Peter Zijlstra
2019-05-09 18:36 ` rostedt
2019-05-09 18:36 ` Steven Rostedt
2019-05-08 7:49 ` [PATCH 3/4] x86/ftrace: Add pt_regs frame annotations peterz
2019-05-08 7:49 ` Peter Zijlstra
2019-05-08 7:49 ` [RFC][PATCH 4/4] x86_32: Provide consistent pt_regs peterz
2019-05-08 7:49 ` Peter Zijlstra
2019-05-08 11:57 ` jpoimboe
2019-05-08 11:57 ` Josh Poimboeuf
2019-05-08 20:58 ` torvalds
2019-05-08 20:58 ` Linus Torvalds
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=20190509102030.dfa62e058f09d0d8cbdd6053@kernel.org \
--to=linux-kselftest@vger.kernel.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