From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v8 5/7] arm64: Add trampoline code for kretprobes
Date: Wed, 12 Aug 2015 15:47:38 +0100 [thread overview]
Message-ID: <20150812144738.GG23540@arm.com> (raw)
In-Reply-To: <1439254364-15362-6-git-send-email-dave.long@linaro.org>
Hi Will,
On Tue, Aug 11, 2015 at 01:52:42AM +0100, David Long wrote:
> From: William Cohen <wcohen@redhat.com>
>
> The trampoline code is used by kretprobes to capture a return from a probed
> function. This is done by saving the registers, calling the handler, and
> restoring the registers. The code then returns to the original saved caller
> return address. It is necessary to do this directly instead of using a
> software breakpoint because the code used in processing that breakpoint
> could itself be kprobe'd and cause a problematic reentry into the debug
> exception handler.
>
> Signed-off-by: William Cohen <wcohen@redhat.com>
> Signed-off-by: David A. Long <dave.long@linaro.org>
[...]
> diff --git a/arch/arm64/kernel/kprobes_trampoline.S b/arch/arm64/kernel/kprobes_trampoline.S
> new file mode 100644
> index 0000000..dd0172b
> --- /dev/null
> +++ b/arch/arm64/kernel/kprobes_trampoline.S
> @@ -0,0 +1,61 @@
> +/*
> + * trampoline entry and return code for kretprobes.
> + */
> +
> +#include <linux/linkage.h>
> +#include <generated/asm-offsets.h>
> +
> + .text
> +
> +ENTRY(kretprobe_trampoline)
> +
> + sub sp, sp, #S_FRAME_SIZE
> +
> + stp x0, x1, [sp, #S_X0]
> + stp x2, x3, [sp, #S_X2]
> + stp x4, x5, [sp, #S_X4]
> + stp x6, x7, [sp, #S_X6]
> + stp x8, x9, [sp, #S_X8]
> + stp x10, x11, [sp, #S_X10]
> + stp x12, x13, [sp, #S_X12]
> + stp x14, x15, [sp, #S_X14]
> + stp x16, x17, [sp, #S_X16]
> + stp x18, x19, [sp, #S_X18]
> + stp x20, x21, [sp, #S_X20]
> + stp x22, x23, [sp, #S_X22]
> + stp x24, x25, [sp, #S_X24]
> + stp x26, x27, [sp, #S_X26]
> + stp x28, x29, [sp, #S_X28]
> + str x30, [sp, #S_LR]
> + mrs x0, nzcv
> + str x0, [sp, #S_PSTATE]
I'm slightly wary of this, as it means user_mode(regs) will return true
for the pt_regs passed into the handler. Do we need to force the mode?
What about things like the I bit?
Similarly, why don't you save the stack pointer?
> +
> + mov x0, sp
> + bl trampoline_probe_handler
> + /* Replace trampoline address in lr with actual
> + orig_ret_addr return address. */
> + str x0, [sp, #S_LR]
Why can't the trampoline_probe_handler update the pt_regs directly?
Will
WARNING: multiple messages have this Message-ID (diff)
From: Will Deacon <will.deacon@arm.com>
To: David Long <dave.long@linaro.org>
Cc: Catalin Marinas <Catalin.Marinas@arm.com>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
Russell King <linux@arm.linux.org.uk>,
"sandeepa.s.prabhu@gmail.com" <sandeepa.s.prabhu@gmail.com>,
William Cohen <wcohen@redhat.com>,
Steve Capper <steve.capper@linaro.org>,
"Jon Medhurst (Tixy)" <tixy@linaro.org>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>,
"davem@davemloft.net" <davem@davemloft.net>,
Mark Brown <broonie@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v8 5/7] arm64: Add trampoline code for kretprobes
Date: Wed, 12 Aug 2015 15:47:38 +0100 [thread overview]
Message-ID: <20150812144738.GG23540@arm.com> (raw)
In-Reply-To: <1439254364-15362-6-git-send-email-dave.long@linaro.org>
Hi Will,
On Tue, Aug 11, 2015 at 01:52:42AM +0100, David Long wrote:
> From: William Cohen <wcohen@redhat.com>
>
> The trampoline code is used by kretprobes to capture a return from a probed
> function. This is done by saving the registers, calling the handler, and
> restoring the registers. The code then returns to the original saved caller
> return address. It is necessary to do this directly instead of using a
> software breakpoint because the code used in processing that breakpoint
> could itself be kprobe'd and cause a problematic reentry into the debug
> exception handler.
>
> Signed-off-by: William Cohen <wcohen@redhat.com>
> Signed-off-by: David A. Long <dave.long@linaro.org>
[...]
> diff --git a/arch/arm64/kernel/kprobes_trampoline.S b/arch/arm64/kernel/kprobes_trampoline.S
> new file mode 100644
> index 0000000..dd0172b
> --- /dev/null
> +++ b/arch/arm64/kernel/kprobes_trampoline.S
> @@ -0,0 +1,61 @@
> +/*
> + * trampoline entry and return code for kretprobes.
> + */
> +
> +#include <linux/linkage.h>
> +#include <generated/asm-offsets.h>
> +
> + .text
> +
> +ENTRY(kretprobe_trampoline)
> +
> + sub sp, sp, #S_FRAME_SIZE
> +
> + stp x0, x1, [sp, #S_X0]
> + stp x2, x3, [sp, #S_X2]
> + stp x4, x5, [sp, #S_X4]
> + stp x6, x7, [sp, #S_X6]
> + stp x8, x9, [sp, #S_X8]
> + stp x10, x11, [sp, #S_X10]
> + stp x12, x13, [sp, #S_X12]
> + stp x14, x15, [sp, #S_X14]
> + stp x16, x17, [sp, #S_X16]
> + stp x18, x19, [sp, #S_X18]
> + stp x20, x21, [sp, #S_X20]
> + stp x22, x23, [sp, #S_X22]
> + stp x24, x25, [sp, #S_X24]
> + stp x26, x27, [sp, #S_X26]
> + stp x28, x29, [sp, #S_X28]
> + str x30, [sp, #S_LR]
> + mrs x0, nzcv
> + str x0, [sp, #S_PSTATE]
I'm slightly wary of this, as it means user_mode(regs) will return true
for the pt_regs passed into the handler. Do we need to force the mode?
What about things like the I bit?
Similarly, why don't you save the stack pointer?
> +
> + mov x0, sp
> + bl trampoline_probe_handler
> + /* Replace trampoline address in lr with actual
> + orig_ret_addr return address. */
> + str x0, [sp, #S_LR]
Why can't the trampoline_probe_handler update the pt_regs directly?
Will
next prev parent reply other threads:[~2015-08-12 14:47 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-11 0:52 [PATCH v8 0/7] arm64: Add kernel probes (kprobes) support David Long
2015-08-11 0:52 ` David Long
2015-08-11 0:52 ` [PATCH v8 1/7] arm64: Add HAVE_REGS_AND_STACK_ACCESS_API feature David Long
2015-08-11 0:52 ` David Long
2015-08-11 17:31 ` Will Deacon
2015-08-11 17:31 ` Will Deacon
2015-08-13 3:50 ` David Long
2015-08-13 3:50 ` David Long
2015-08-18 9:38 ` Will Deacon
2015-08-18 9:38 ` Will Deacon
2015-08-11 0:52 ` [PATCH v8 2/7] arm64: Add more test functions to insn.c David Long
2015-08-11 0:52 ` David Long
2015-08-11 18:00 ` Will Deacon
2015-08-11 18:00 ` Will Deacon
2015-08-13 4:23 ` David Long
2015-08-13 4:23 ` David Long
2015-08-11 0:52 ` [PATCH v8 3/7] arm64: Kprobes with single stepping support David Long
2015-08-11 0:52 ` David Long
2015-08-12 13:37 ` Will Deacon
2015-08-12 13:37 ` Will Deacon
2015-12-08 6:05 ` David Long
2015-12-08 6:05 ` David Long
2015-08-13 11:42 ` Steve Capper
2015-08-13 11:42 ` Steve Capper
2015-08-11 0:52 ` [PATCH v8 4/7] arm64: kprobes instruction simulation support David Long
2015-08-11 0:52 ` David Long
2015-08-12 14:29 ` Will Deacon
2015-08-12 14:29 ` Will Deacon
2015-08-11 0:52 ` [PATCH v8 5/7] arm64: Add trampoline code for kretprobes David Long
2015-08-11 0:52 ` David Long
2015-08-12 14:47 ` Will Deacon [this message]
2015-08-12 14:47 ` Will Deacon
2015-08-11 0:52 ` [PATCH v8 6/7] arm64: Add kernel return probes support (kretprobes) David Long
2015-08-11 0:52 ` David Long
2015-08-11 0:52 ` [PATCH v8 7/7] kprobes: Add arm64 case in kprobe example module David Long
2015-08-11 0:52 ` David Long
2015-08-12 16:22 ` Steve Capper
2015-08-12 16:22 ` Steve Capper
2015-08-11 16:56 ` [PATCH v8 0/7] arm64: Add kernel probes (kprobes) support Will Deacon
2015-08-11 16:56 ` Will Deacon
2015-08-11 17:03 ` David Long
2015-08-11 17:03 ` David Long
2015-08-11 17:36 ` Will Deacon
2015-08-11 17:36 ` Will Deacon
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=20150812144738.GG23540@arm.com \
--to=will.deacon@arm.com \
--cc=linux-arm-kernel@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.