From: David Long <dave.long@linaro.org>
To: Huang Shijie <shijie.huang@arm.com>
Cc: "Catalin Marinas" <catalin.marinas@arm.com>,
"Will Deacon" <will.deacon@arm.com>,
"Sandeepa Prabhu" <sandeepa.s.prabhu@gmail.com>,
"William Cohen" <wcohen@redhat.com>,
"Pratyush Anand" <panand@redhat.com>,
"Steve Capper" <steve.capper@linaro.org>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
"Marc Zyngier" <marc.zyngier@arm.com>,
"Mark Rutland" <mark.rutland@arm.com>,
"Petr Mladek" <pmladek@suse.com>,
"Viresh Kumar" <viresh.kumar@linaro.org>,
"John Blackwood" <john.blackwood@ccur.com>,
"Feng Kan" <fkan@apm.com>, "Zi Shen Lim" <zlim.lnx@gmail.com>,
"Dave P Martin" <Dave.Martin@arm.com>,
"Yang Shi" <yang.shi@linaro.org>,
"Vladimir Murzin" <Vladimir.Murzin@arm.com>,
"Kees Cook" <keescook@chromium.org>,
"Suzuki K. Poulose" <suzuki.poulose@arm.com>,
"Mark Brown" <broonie@kernel.org>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Ard Biesheuvel" <ard.biesheuvel@linaro.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Mark Salyzyn" <salyzyn@android.com>,
"James Morse" <james.morse@arm.com>,
"Christoffer Dall" <christoffer.dall@linaro.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Robin Murphy" <Robin.Murphy@arm.com>,
"Jens Wiklander" <jens.wiklander@linaro.org>,
"Balamurugan Shanmugam" <bshanmugam@apm.com>,
nd@arm.com
Subject: Re: [PATCH v12 07/10] arm64: kprobes instruction simulation support
Date: Thu, 26 May 2016 15:28:32 -0400 [thread overview]
Message-ID: <57474E60.3050802@linaro.org> (raw)
In-Reply-To: <20160519015222.GA25870@sha-win-210.asiapac.arm.com>
On 05/18/2016 09:52 PM, Huang Shijie wrote:
> On Wed, Apr 27, 2016 at 02:53:02PM -0400, David Long wrote:
>> From: Sandeepa Prabhu <sandeepa.s.prabhu@gmail.com>
>>
>> Kprobes needs simulation of instructions that cannot be stepped
>> from a different memory location, e.g.: those instructions
>> that uses PC-relative addressing. In simulation, the behaviour
>> of the instruction is implemented using a copy of pt_regs.
>>
>> The following instruction categories are simulated:
>> - All branching instructions(conditional, register, and immediate)
>> - Literal access instructions(load-literal, adr/adrp)
>>
>> Conditional execution is limited to branching instructions in
>> ARM v8. If conditions at PSTATE do not match the condition fields
>> of opcode, the instruction is effectively NOP.
>>
>> Thanks to Will Cohen for assorted suggested changes.
>>
>> Signed-off-by: Sandeepa Prabhu <sandeepa.s.prabhu@gmail.com>
>> Signed-off-by: William Cohen <wcohen@redhat.com>
>> Signed-off-by: David A. Long <dave.long@linaro.org>
>> ---
>> arch/arm64/include/asm/insn.h | 1 +
>> arch/arm64/include/asm/probes.h | 5 +-
>> arch/arm64/kernel/Makefile | 3 +-
>> arch/arm64/kernel/insn.c | 1 +
>> arch/arm64/kernel/kprobes-arm64.c | 29 ++++
>> arch/arm64/kernel/kprobes.c | 32 ++++-
>> arch/arm64/kernel/probes-simulate-insn.c | 218 +++++++++++++++++++++++++++++++
>> arch/arm64/kernel/probes-simulate-insn.h | 28 ++++
>> 8 files changed, 311 insertions(+), 6 deletions(-)
>> create mode 100644 arch/arm64/kernel/probes-simulate-insn.c
>> create mode 100644 arch/arm64/kernel/probes-simulate-insn.h
>>
>> diff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h
>> index b9567a1..26cee10 100644
>> --- a/arch/arm64/include/asm/insn.h
>> +++ b/arch/arm64/include/asm/insn.h
>> @@ -410,6 +410,7 @@ u32 aarch32_insn_mcr_extract_crm(u32 insn);
>>
>> typedef bool (pstate_check_t)(unsigned long);
>> extern pstate_check_t * const opcode_condition_checks[16];
>> +
>> #endif /* __ASSEMBLY__ */
>>
>> #endif /* __ASM_INSN_H */
>> diff --git a/arch/arm64/include/asm/probes.h b/arch/arm64/include/asm/probes.h
>> index c5fcbe6..d524f7d 100644
>> --- a/arch/arm64/include/asm/probes.h
>> +++ b/arch/arm64/include/asm/probes.h
>> @@ -15,11 +15,12 @@
>> #ifndef _ARM_PROBES_H
>> #define _ARM_PROBES_H
>>
>> +#include <asm/opcodes.h>
>> +
>> struct kprobe;
>> struct arch_specific_insn;
>>
>> typedef u32 kprobe_opcode_t;
>> -typedef unsigned long (kprobes_pstate_check_t)(unsigned long);
>> typedef void (kprobes_handler_t) (u32 opcode, long addr, struct pt_regs *);
>>
>> enum pc_restore_type {
>> @@ -35,7 +36,7 @@ struct kprobe_pc_restore {
>> /* architecture specific copy of original instruction */
>> struct arch_specific_insn {
>> kprobe_opcode_t *insn;
>> - kprobes_pstate_check_t *pstate_cc;
>> + pstate_check_t *pstate_cc;
>> kprobes_handler_t *handler;
>> /* restore address after step xol */
>> struct kprobe_pc_restore restore;
>> diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
>> index 8816de2..43bf6cc 100644
>> --- a/arch/arm64/kernel/Makefile
>> +++ b/arch/arm64/kernel/Makefile
>> @@ -37,7 +37,8 @@ arm64-obj-$(CONFIG_CPU_PM) += sleep.o suspend.o
>> arm64-obj-$(CONFIG_CPU_IDLE) += cpuidle.o
>> arm64-obj-$(CONFIG_JUMP_LABEL) += jump_label.o
>> arm64-obj-$(CONFIG_KGDB) += kgdb.o
>> -arm64-obj-$(CONFIG_KPROBES) += kprobes.o kprobes-arm64.o
>> +arm64-obj-$(CONFIG_KPROBES) += kprobes.o kprobes-arm64.o \
>> + probes-simulate-insn.o
>> arm64-obj-$(CONFIG_EFI) += efi.o efi-entry.stub.o
>> arm64-obj-$(CONFIG_PCI) += pci.o
>> arm64-obj-$(CONFIG_ARMV8_DEPRECATED) += armv8_deprecated.o
>> diff --git a/arch/arm64/kernel/insn.c b/arch/arm64/kernel/insn.c
>> index f79e72e..bb2738c 100644
>> --- a/arch/arm64/kernel/insn.c
>> +++ b/arch/arm64/kernel/insn.c
>> @@ -30,6 +30,7 @@
>> #include <asm/cacheflush.h>
>> #include <asm/debug-monitors.h>
>> #include <asm/fixmap.h>
>> +#include <asm/opcodes.h>
>> #include <asm/insn.h>
>>
>> #define AARCH64_INSN_SF_BIT BIT(31)
>> diff --git a/arch/arm64/kernel/kprobes-arm64.c b/arch/arm64/kernel/kprobes-arm64.c
>> index e07727a..487238a 100644
>> --- a/arch/arm64/kernel/kprobes-arm64.c
>> +++ b/arch/arm64/kernel/kprobes-arm64.c
>> @@ -21,6 +21,7 @@
>> #include <asm/sections.h>
>>
>> #include "kprobes-arm64.h"
>> +#include "probes-simulate-insn.h"
>>
>> static bool __kprobes aarch64_insn_is_steppable(u32 insn)
>> {
>> @@ -62,8 +63,36 @@ arm_probe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi)
>> */
>> if (aarch64_insn_is_steppable(insn))
>> return INSN_GOOD;
>> +
>> + if (aarch64_insn_is_bcond(insn)) {
>> + asi->handler = simulate_b_cond;
>> + } else if (aarch64_insn_is_cbz(insn) ||
>> + aarch64_insn_is_cbnz(insn)) {
>> + asi->handler = simulate_cbz_cbnz;
>> + } else if (aarch64_insn_is_tbz(insn) ||
>> + aarch64_insn_is_tbnz(insn)) {
>> + asi->handler = simulate_tbz_tbnz;
>> + } else if (aarch64_insn_is_adr_adrp(insn))
>> + asi->handler = simulate_adr_adrp;
>> + else if (aarch64_insn_is_b(insn) ||
>> + aarch64_insn_is_bl(insn))
>> + asi->handler = simulate_b_bl;
>
> For the same codingstyle, we'd better add more "{}" here and below.
>
> thanks
> Huang Shijie
>
>> + else if (aarch64_insn_is_br(insn) ||
>> + aarch64_insn_is_blr(insn) ||
>> + aarch64_insn_is_ret(insn))
>> + asi->handler = simulate_br_blr_ret;
>> + else if (aarch64_insn_is_ldr_lit(insn))
>> + asi->handler = simulate_ldr_literal;
>> + else if (aarch64_insn_is_ldrsw_lit(insn))
>> + asi->handler = simulate_ldrsw_literal;
>> else
>> + /*
>> + * Instruction cannot be stepped out-of-line and we don't
>> + * (yet) simulate it.
>> + */
>> return INSN_REJECTED;
>> +
>> + return INSN_GOOD_NO_SLOT;
>> }
>
I've made this change for the next version of the patch.
Thanks,
-dl
next prev parent reply other threads:[~2016-05-26 19:28 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-27 18:52 [PATCH v12 00/10] arm64: Add kernel probes (kprobes) support David Long
2016-04-27 18:52 ` [PATCH v12 01/10] arm64: Add HAVE_REGS_AND_STACK_ACCESS_API feature David Long
2016-04-28 16:08 ` Marc Zyngier
2016-05-13 19:07 ` David Long
2016-05-17 9:14 ` Huang Shijie
2016-05-20 4:18 ` David Long
2016-04-27 18:52 ` [PATCH v12 02/10] arm64: Add more test functions to insn.c David Long
2016-04-27 18:52 ` [PATCH v12 03/10] arm64: add conditional instruction simulation support David Long
2016-04-27 18:52 ` [PATCH v12 04/10] arm64: Blacklist non-kprobe-able symbols David Long
2016-04-27 18:53 ` [PATCH v12 05/10] arm64: Kprobes with single stepping support David Long
2016-05-12 15:01 ` James Morse
2016-05-18 4:04 ` Masami Hiramatsu
2016-05-20 5:16 ` David Long
2016-05-17 8:58 ` Huang Shijie
2016-05-18 3:29 ` Masami Hiramatsu
2016-05-26 19:25 ` David Long
2016-05-26 15:40 ` David Long
2016-05-17 9:10 ` Huang Shijie
2016-06-01 5:15 ` David Long
2016-04-27 18:53 ` [PATCH v12 06/10] arm64: Treat all entry code as non-kprobe-able David Long
2016-05-12 14:49 ` James Morse
2016-05-20 5:28 ` David Long
2016-05-26 15:26 ` David Long
2016-04-27 18:53 ` [PATCH v12 07/10] arm64: kprobes instruction simulation support David Long
2016-05-19 1:52 ` Huang Shijie
2016-05-26 19:28 ` David Long [this message]
2016-04-27 18:53 ` [PATCH v12 08/10] arm64: Add trampoline code for kretprobes David Long
2016-04-27 18:53 ` [PATCH v12 09/10] arm64: Add kernel return probes support (kretprobes) David Long
2016-04-27 18:53 ` [PATCH v12 10/10] kprobes: Add arm64 case in kprobe example module David Long
2016-05-17 9:57 ` Huang Shijie
2016-05-17 10:24 ` Mark Brown
2016-05-18 1:31 ` Huang Shijie
2016-05-11 15:33 ` [PATCH v12 00/10] arm64: Add kernel probes (kprobes) support James Morse
2016-05-12 2:26 ` Li Bin
2016-05-13 20:02 ` David Long
2016-05-18 2:24 ` 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=57474E60.3050802@linaro.org \
--to=dave.long@linaro.org \
--cc=Dave.Martin@arm.com \
--cc=Robin.Murphy@arm.com \
--cc=Vladimir.Murzin@arm.com \
--cc=akpm@linux-foundation.org \
--cc=alex.bennee@linaro.org \
--cc=ard.biesheuvel@linaro.org \
--cc=broonie@kernel.org \
--cc=bshanmugam@apm.com \
--cc=catalin.marinas@arm.com \
--cc=christoffer.dall@linaro.org \
--cc=fkan@apm.com \
--cc=gregkh@linuxfoundation.org \
--cc=james.morse@arm.com \
--cc=jens.wiklander@linaro.org \
--cc=john.blackwood@ccur.com \
--cc=keescook@chromium.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=mark.rutland@arm.com \
--cc=nd@arm.com \
--cc=panand@redhat.com \
--cc=pmladek@suse.com \
--cc=salyzyn@android.com \
--cc=sandeepa.s.prabhu@gmail.com \
--cc=shijie.huang@arm.com \
--cc=steve.capper@linaro.org \
--cc=suzuki.poulose@arm.com \
--cc=viresh.kumar@linaro.org \
--cc=wcohen@redhat.com \
--cc=will.deacon@arm.com \
--cc=yang.shi@linaro.org \
--cc=zlim.lnx@gmail.com \
/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).