From: panand@redhat.com (Pratyush Anand)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v14 04/10] arm64: Kprobes with single stepping support
Date: Mon, 27 Jun 2016 12:27:49 +0530 [thread overview]
Message-ID: <20160627065749.GB29870@dhcppc9> (raw)
In-Reply-To: <1466996813-23295-5-git-send-email-dave.long@linaro.org>
Hi David,
On 26/06/2016:11:06:47 PM, David Long wrote:
> From: Sandeepa Prabhu <sandeepa.s.prabhu@gmail.com>
>
> Add support for basic kernel probes(kprobes) and jump probes
> (jprobes) for ARM64.
>
> Kprobes utilizes software breakpoint and single step debug
> exceptions supported on ARM v8.
>
> A software breakpoint is placed at the probe address to trap the
> kernel execution into the kprobe handler.
>
> ARM v8 supports enabling single stepping before the break exception
> return (ERET), with next PC in exception return address (ELR_EL1). The
> kprobe handler prepares an executable memory slot for out-of-line
> execution with a copy of the original instruction being probed, and
> enables single stepping. The PC is set to the out-of-line slot address
> before the ERET. With this scheme, the instruction is executed with the
> exact same register context except for the PC (and DAIF) registers.
>
> Debug mask (PSTATE.D) is enabled only when single stepping a recursive
> kprobe, e.g.: during kprobes reenter so that probed instruction can be
> single stepped within the kprobe handler -exception- context.
> The recursion depth of kprobe is always 2, i.e. upon probe re-entry,
> any further re-entry is prevented by not calling handlers and the case
> counted as a missed kprobe).
>
> Single stepping from the x-o-l slot has a drawback for PC-relative accesses
> like branching and symbolic literals access as the offset from the new PC
> (slot address) may not be ensured to fit in the immediate value of
> the opcode. Such instructions need simulation, so reject
> probing them.
>
> Instructions generating exceptions or cpu mode change are rejected
> for probing.
>
> Exclusive load/store instructions are rejected too. Additionally, the
> code is checked to see if it is inside an exclusive load/store sequence
> (code from Pratyush).
>
> System instructions are mostly enabled for stepping, except MSR/MRS
> accesses to "DAIF" flags in PSTATE, which are not safe for
> probing.
>
> Thanks to Steve Capper and Pratyush Anand for several suggested
> Changes.
>
> Signed-off-by: Sandeepa Prabhu <sandeepa.s.prabhu@gmail.com>
> Signed-off-by: David A. Long <dave.long@linaro.org>
> Signed-off-by: Pratyush Anand <panand@redhat.com>
> ---
> arch/arm64/Kconfig | 1 +
> arch/arm64/include/asm/debug-monitors.h | 5 +
> arch/arm64/include/asm/insn.h | 2 +
> arch/arm64/include/asm/kprobes.h | 60 ++++
> arch/arm64/include/asm/probes.h | 34 +++
> arch/arm64/include/asm/ptrace.h | 1 +
> arch/arm64/kernel/Makefile | 2 +-
> arch/arm64/kernel/debug-monitors.c | 16 +-
> arch/arm64/kernel/kprobes/Makefile | 1 +
> arch/arm64/kernel/kprobes/decode-insn.c | 143 +++++++++
> arch/arm64/kernel/kprobes/decode-insn.h | 34 +++
> arch/arm64/kernel/kprobes/kprobes.c | 525 ++++++++++++++++++++++++++++++++
> arch/arm64/kernel/vmlinux.lds.S | 1 +
> arch/arm64/mm/fault.c | 26 ++
> 14 files changed, 848 insertions(+), 3 deletions(-)
> create mode 100644 arch/arm64/include/asm/kprobes.h
> create mode 100644 arch/arm64/include/asm/probes.h
> create mode 100644 arch/arm64/kernel/kprobes/Makefile
> create mode 100644 arch/arm64/kernel/kprobes/decode-insn.c
> create mode 100644 arch/arm64/kernel/kprobes/decode-insn.h
Can we rename kernel/kprobes as kernel/probes? uprobes code will use
decode-insn.c and further simulate-insn.c as well. So, I would like to place my
uprobes.c in same directory.
> create mode 100644 arch/arm64/kernel/kprobes/kprobes.c
>
[...]
> diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h
> index 6c0c7d3..c7bbeed 100644
> --- a/arch/arm64/include/asm/ptrace.h
> +++ b/arch/arm64/include/asm/ptrace.h
> @@ -209,6 +209,7 @@ struct task_struct;
> int valid_user_regs(struct user_pt_regs *regs, struct task_struct *task);
>
> #define instruction_pointer(regs) ((unsigned long)(regs)->pc)
> +#define instruction_pointer_set(regs, value) ((regs)->pc = ((u64) (value)))
IIRC, Will Daecon had asked to include asm-generic/ptrace.h into asm/ptrace.h when
I had done similar changes for uprobe needs. May be you can pick patch from
my uprobe tree.
https://github.com/pratyushanand/linux/commit/bb3e114797c2888ed8ad528cca20e569dd2d818e
~Pratyush
next prev parent reply other threads:[~2016-06-27 6:57 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-27 3:06 [PATCH v14 00/10] arm64: Add kernel probes (kprobes) support David Long
2016-06-27 3:06 ` [PATCH v14 01/10] arm64: Add HAVE_REGS_AND_STACK_ACCESS_API feature David Long
2016-06-27 3:06 ` [PATCH v14 02/10] arm64: Add more test functions to insn.c David Long
2016-06-27 3:06 ` [PATCH v14 03/10] arm64: add conditional instruction simulation support David Long
2016-06-27 3:06 ` [PATCH v14 04/10] arm64: Kprobes with single stepping support David Long
2016-06-27 6:57 ` Pratyush Anand [this message]
2016-06-27 14:06 ` David Long
2016-06-28 7:25 ` Masami Hiramatsu
2016-06-27 3:06 ` [PATCH v14 05/10] arm64: Blacklist non-kprobe-able symbol David Long
2016-06-27 3:06 ` [PATCH v14 06/10] arm64: Treat all entry code as non-kprobe-able David Long
2016-06-27 3:06 ` [PATCH v14 07/10] arm64: kprobes instruction simulation support David Long
2016-06-27 3:06 ` [PATCH v14 08/10] arm64: Add trampoline code for kretprobes David Long
2016-06-27 3:06 ` [PATCH v14 09/10] arm64: Add kernel return probes support (kretprobes) David Long
2016-06-27 3:06 ` [PATCH v14 10/10] kprobes: Add arm64 case in kprobe example module David Long
2016-06-28 7:31 ` [PATCH v14 00/10] arm64: Add kernel probes (kprobes) support Masami Hiramatsu
2016-06-28 8:13 ` Huang Shijie
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=20160627065749.GB29870@dhcppc9 \
--to=panand@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).