From: "chengjian (D)" <cj.chengjian@huawei.com>
To: <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org>
Cc: <will@kernel.org>, <catalin.marinas@arm.com>,
<mhiramat@kernel.org>, <naveen.n.rao@linux.ibm.com>,
<sandeepa.s.prabhu@gmail.com>, <bobo.shaobowang@huawei.com>
Subject: Re: [PATCH] arm64/kprobe: add support for KPROBES_ON_FTRACE
Date: Mon, 23 Dec 2019 20:39:10 +0800 [thread overview]
Message-ID: <a7c7b8f0-126e-a755-43ee-d384de74e43e@huawei.com> (raw)
In-Reply-To: <20191223123828.39543-1-cj.chengjian@huawei.com>
I am SORRY.
I searched on patchwork and found this :
arm64: implement KPROBES_ON_FTRACE
https://lore.kernel.org/patchwork/patch/1169445/
So please ignore my EMAIL.
Thank you.
---- Cheng Jian
On 2019/12/23 20:38, Cheng Jian wrote:
> Allow KPROBES to use the ftrace infrastructure.
> This depends on HAVE_DYNAMIC_FTRACE_WITH_REGS
> which introduce by :
> commit 3b23e4991fb6 ("arm64: implement ftrace with regs")
>
> Based on the x86 code by Masami.
>
> With:
> # cd /sys/kernel/debug/tracing
> # echo 'p _do_fork+0x4' > kprobe_events
>
> before patch:
> # cat ../kprobes/list
> sh: write error: Invalid argument
>
> after patch:
> # cat ../kprobes/list
> ffffa00016aa9d4c k _do_fork+0x4 [FTRACE]
>
> Signed-off-by: Cheng Jian <cj.chengjian@huawei.com>
> ---
> .../debug/kprobes-on-ftrace/arch-support.txt | 2 +-
> arch/arm64/Kconfig | 1 +
> arch/arm64/kernel/probes/Makefile | 2 +
> arch/arm64/kernel/probes/ftrace.c | 65 +++++++++++++++++++
> 4 files changed, 69 insertions(+), 1 deletion(-)
> create mode 100644 arch/arm64/kernel/probes/ftrace.c
>
> diff --git a/Documentation/features/debug/kprobes-on-ftrace/arch-support.txt b/Documentation/features/debug/kprobes-on-ftrace/arch-support.txt
> index 4fae0464ddff..f9dd9dd91e0c 100644
> --- a/Documentation/features/debug/kprobes-on-ftrace/arch-support.txt
> +++ b/Documentation/features/debug/kprobes-on-ftrace/arch-support.txt
> @@ -9,7 +9,7 @@
> | alpha: | TODO |
> | arc: | TODO |
> | arm: | TODO |
> - | arm64: | TODO |
> + | arm64: | ok |
> | c6x: | TODO |
> | csky: | TODO |
> | h8300: | TODO |
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index b1b4476ddb83..d613be9c2346 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -144,6 +144,7 @@ config ARM64
> select HAVE_DYNAMIC_FTRACE
> select HAVE_DYNAMIC_FTRACE_WITH_REGS \
> if $(cc-option,-fpatchable-function-entry=2)
> + select HAVE_KPROBES_ON_FTRACE if HAVE_DYNAMIC_FTRACE_WITH_REGS
> select HAVE_EFFICIENT_UNALIGNED_ACCESS
> select HAVE_FAST_GUP
> select HAVE_FTRACE_MCOUNT_RECORD
> diff --git a/arch/arm64/kernel/probes/Makefile b/arch/arm64/kernel/probes/Makefile
> index 8e4be92e25b1..45a9d916a47d 100644
> --- a/arch/arm64/kernel/probes/Makefile
> +++ b/arch/arm64/kernel/probes/Makefile
> @@ -4,3 +4,5 @@ obj-$(CONFIG_KPROBES) += kprobes.o decode-insn.o \
> simulate-insn.o
> obj-$(CONFIG_UPROBES) += uprobes.o decode-insn.o \
> simulate-insn.o
> +
> +obj-$(CONFIG_KPROBES_ON_FTRACE) += ftrace.o
> diff --git a/arch/arm64/kernel/probes/ftrace.c b/arch/arm64/kernel/probes/ftrace.c
> new file mode 100644
> index 000000000000..f89bfaa3e5f3
> --- /dev/null
> +++ b/arch/arm64/kernel/probes/ftrace.c
> @@ -0,0 +1,65 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Dynamic Ftrace based Kprobes Optimization
> + *
> + * Copyright (C) Hitachi Ltd., 2012
> + * Copyright (C) 2019 Huawei Inc.
> + * Copyright 2019 Cheng Jian <cj.chengjian@huawei.com>
> + */
> +#include <linux/kprobes.h>
> +#include <linux/ptrace.h>
> +#include <linux/hardirq.h>
> +#include <linux/preempt.h>
> +#include <linux/ftrace.h>
> +
> +
> +/* Ftrace callback handler for kprobes -- called under preepmt disabed */
> +void kprobe_ftrace_handler(unsigned long pc, unsigned long parent_pc,
> + struct ftrace_ops *ops, struct pt_regs *regs)
> +{
> + struct kprobe *p;
> + struct kprobe_ctlblk *kcb;
> +
> + /* Preempt is disabled by ftrace */
> + p = get_kprobe((kprobe_opcode_t *)pc);
> + if (unlikely(!p) || kprobe_disabled(p))
> + return;
> +
> + kcb = get_kprobe_ctlblk();
> + if (kprobe_running()) {
> + kprobes_inc_nmissed_count(p);
> + } else {
> + /*
> + * On ARM64, recg->pc is *before* this instruction for the
> + * pre handler.
> + */
> + regs->pc -= MCOUNT_INSN_SIZE;
> +
> + __this_cpu_write(current_kprobe, p);
> + kcb->kprobe_status = KPROBE_HIT_ACTIVE;
> + if (!p->pre_handler || !p->pre_handler(p, regs)) {
> + /*
> + * Emulate singlestep (and also recover regs->ip)
> + * as if there is a nop
> + */
> + regs->pc += MCOUNT_INSN_SIZE;
> + if (unlikely(p->post_handler)) {
> + kcb->kprobe_status = KPROBE_HIT_SSDONE;
> + p->post_handler(p, regs, 0);
> + }
> + }
> + /*
> + * If pre_handler returns !0, it changes regs->ip. We have to
> + * skip emulating post_handler.
> + */
> + __this_cpu_write(current_kprobe, NULL);
> + }
> +}
> +NOKPROBE_SYMBOL(kprobe_ftrace_handler);
> +
> +int arch_prepare_kprobe_ftrace(struct kprobe *p)
> +{
> + p->ainsn.api.insn = NULL;
> +
> + return 0;
> +}
prev parent reply other threads:[~2019-12-23 12:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-23 12:38 Cheng Jian
2019-12-23 12:39 ` chengjian (D) [this message]
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=a7c7b8f0-126e-a755-43ee-d384de74e43e@huawei.com \
--to=cj.chengjian@huawei.com \
--cc=bobo.shaobowang@huawei.com \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=naveen.n.rao@linux.ibm.com \
--cc=sandeepa.s.prabhu@gmail.com \
--cc=will@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
all inboxes | Powered by JetHome®