From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751780AbcF0G54 (ORCPT ); Mon, 27 Jun 2016 02:57:56 -0400 Received: from mail-qk0-f172.google.com ([209.85.220.172]:34282 "EHLO mail-qk0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751215AbcF0G5y (ORCPT ); Mon, 27 Jun 2016 02:57:54 -0400 Date: Mon, 27 Jun 2016 12:27:49 +0530 From: Pratyush Anand To: David Long Cc: Catalin Marinas , Huang Shijie , James Morse , Marc Zyngier , Sandeepa Prabhu , Will Deacon , William Cohen , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Steve Capper , Masami Hiramatsu , Li Bin , Adam Buchbinder , Alex =?iso-8859-1?Q?Benn=E9e?= , Andrew Morton , Andrey Ryabinin , Ard Biesheuvel , Christoffer Dall , Daniel Thompson , Dave P Martin , Jens Wiklander , Jisheng Zhang , John Blackwood , Mark Rutland , Petr Mladek , Robin Murphy , Suzuki K Poulose , Vladimir Murzin , Yang Shi , Zi Shen Lim , yalin wang , Mark Brown Subject: Re: [PATCH v14 04/10] arm64: Kprobes with single stepping support Message-ID: <20160627065749.GB29870@dhcppc9> References: <1466996813-23295-1-git-send-email-dave.long@linaro.org> <1466996813-23295-5-git-send-email-dave.long@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1466996813-23295-5-git-send-email-dave.long@linaro.org> User-Agent: Mutt/1.6.1 (2016-04-27) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi David, On 26/06/2016:11:06:47 PM, David Long wrote: > From: Sandeepa Prabhu > > 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 > Signed-off-by: David A. Long > Signed-off-by: Pratyush Anand > --- > 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