From patchwork Tue Aug 11 00:52:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Long X-Patchwork-Id: 52275 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id BD1D72152A for ; Tue, 11 Aug 2015 00:53:03 +0000 (UTC) Received: by wicja10 with SMTP id ja10sf19040332wic.2 for ; Mon, 10 Aug 2015 17:53:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=gip2pOKahSpoP+kVidbiAWoDAM+xzRV4nlqY8XquNRM=; b=iQWwq99l64ce8NVKT7n7lG3G7S3V7XpntpEDNqa46OR7A7OEqkXXuXB/zBUfNiLcCd 8frssCd9pZFar7/J/gTCG7Zl4Pj8nJTMMDMaLTWfbN8RFci2lH9SEfWxvBzfakbdOFeR ckSlcm+oJgu4KemAacEGAywfflrcLSiCx9IlHYf9xdF1ANZ2520pFDHcuR9Ba95g90vP ggKtQNeXjxCrK364PueRz9zndUNVcogk2jkl9jQjEC3R9mNrXOIPnC1nztIwlAQytuoq gZ4F3qBICTQYeFJz6q9zS1FL2GjZjbAzvbfylGNRn35mTSQYyHug4wl8ziuGTs1IBLeE 3hLw== X-Gm-Message-State: ALoCoQnXZZPL7O470/iUW4b+pVObboEnEDBLUGwXVus3M4BvTJlpvVSaRv+xCgQYhpYAlyOY26YJ X-Received: by 10.180.77.105 with SMTP id r9mr1082936wiw.0.1439254383109; Mon, 10 Aug 2015 17:53:03 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.2 with SMTP id s2ls720960lal.86.gmail; Mon, 10 Aug 2015 17:53:02 -0700 (PDT) X-Received: by 10.112.199.66 with SMTP id ji2mr11595555lbc.1.1439254382941; Mon, 10 Aug 2015 17:53:02 -0700 (PDT) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id tu2si22433lbb.57.2015.08.10.17.53.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Aug 2015 17:53:02 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by labd1 with SMTP id d1so49039435lab.1 for ; Mon, 10 Aug 2015 17:53:02 -0700 (PDT) X-Received: by 10.112.160.42 with SMTP id xh10mr23502544lbb.88.1439254382518; Mon, 10 Aug 2015 17:53:02 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.7.198 with SMTP id l6csp2215528lba; Mon, 10 Aug 2015 17:53:01 -0700 (PDT) X-Received: by 10.140.194.133 with SMTP id p127mr45699175qha.38.1439254373019; Mon, 10 Aug 2015 17:52:53 -0700 (PDT) Received: from mail-qg0-f41.google.com (mail-qg0-f41.google.com. [209.85.192.41]) by mx.google.com with ESMTPS id a6si71727qkh.29.2015.08.10.17.52.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Aug 2015 17:52:53 -0700 (PDT) Received-SPF: pass (google.com: domain of dave.long@linaro.org designates 209.85.192.41 as permitted sender) client-ip=209.85.192.41; Received: by qgeg42 with SMTP id g42so93445968qge.1 for ; Mon, 10 Aug 2015 17:52:52 -0700 (PDT) X-Received: by 10.140.108.164 with SMTP id j33mr40137248qgf.83.1439254372369; Mon, 10 Aug 2015 17:52:52 -0700 (PDT) Received: from localhost.localdomain (pool-72-71-243-249.cncdnh.fast00.myfairpoint.net. [72.71.243.249]) by smtp.googlemail.com with ESMTPSA id m62sm167234qhb.45.2015.08.10.17.52.51 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Aug 2015 17:52:51 -0700 (PDT) From: David Long To: Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, Russell King Cc: sandeepa.s.prabhu@gmail.com, William Cohen , Steve Capper , "Jon Medhurst (Tixy)" , Masami Hiramatsu , Ananth N Mavinakayanahalli , Anil S Keshavamurthy , , Mark Brown , linux-kernel@vger.kernel.org Subject: [PATCH v8 5/7] arm64: Add trampoline code for kretprobes Date: Mon, 10 Aug 2015 20:52:42 -0400 Message-Id: <1439254364-15362-6-git-send-email-dave.long@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1439254364-15362-1-git-send-email-dave.long@linaro.org> References: <1439254364-15362-1-git-send-email-dave.long@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: dave.long@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: William Cohen 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 Signed-off-by: David A. Long --- arch/arm64/include/asm/kprobes.h | 2 ++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/asm-offsets.c | 22 ++++++++++++ arch/arm64/kernel/kprobes.c | 5 +++ arch/arm64/kernel/kprobes_trampoline.S | 61 ++++++++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 arch/arm64/kernel/kprobes_trampoline.S diff --git a/arch/arm64/include/asm/kprobes.h b/arch/arm64/include/asm/kprobes.h index af31c4d..83399aa 100644 --- a/arch/arm64/include/asm/kprobes.h +++ b/arch/arm64/include/asm/kprobes.h @@ -58,5 +58,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *data); int kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr); int kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr); +void kretprobe_trampoline(void); +void __kprobes *trampoline_probe_handler(struct pt_regs *regs); #endif /* _ARM_KPROBES_H */ diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 5e9d54f..75d5fb0 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -33,6 +33,7 @@ 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 \ + kprobes_trampoline.o \ probes-simulate-insn.o \ probes-condn-check.o arm64-obj-$(CONFIG_EFI) += efi.o efi-stub.o efi-entry.o diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index c99701a..475c93b 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -49,6 +49,28 @@ int main(void) DEFINE(S_X5, offsetof(struct pt_regs, regs[5])); DEFINE(S_X6, offsetof(struct pt_regs, regs[6])); DEFINE(S_X7, offsetof(struct pt_regs, regs[7])); + DEFINE(S_X8, offsetof(struct pt_regs, regs[8])); + DEFINE(S_X9, offsetof(struct pt_regs, regs[9])); + DEFINE(S_X10, offsetof(struct pt_regs, regs[10])); + DEFINE(S_X11, offsetof(struct pt_regs, regs[11])); + DEFINE(S_X12, offsetof(struct pt_regs, regs[12])); + DEFINE(S_X13, offsetof(struct pt_regs, regs[13])); + DEFINE(S_X14, offsetof(struct pt_regs, regs[14])); + DEFINE(S_X15, offsetof(struct pt_regs, regs[15])); + DEFINE(S_X16, offsetof(struct pt_regs, regs[16])); + DEFINE(S_X17, offsetof(struct pt_regs, regs[17])); + DEFINE(S_X18, offsetof(struct pt_regs, regs[18])); + DEFINE(S_X19, offsetof(struct pt_regs, regs[19])); + DEFINE(S_X20, offsetof(struct pt_regs, regs[20])); + DEFINE(S_X21, offsetof(struct pt_regs, regs[21])); + DEFINE(S_X22, offsetof(struct pt_regs, regs[22])); + DEFINE(S_X23, offsetof(struct pt_regs, regs[23])); + DEFINE(S_X24, offsetof(struct pt_regs, regs[24])); + DEFINE(S_X25, offsetof(struct pt_regs, regs[25])); + DEFINE(S_X26, offsetof(struct pt_regs, regs[26])); + DEFINE(S_X27, offsetof(struct pt_regs, regs[27])); + DEFINE(S_X28, offsetof(struct pt_regs, regs[28])); + DEFINE(S_X29, offsetof(struct pt_regs, regs[29])); DEFINE(S_LR, offsetof(struct pt_regs, regs[30])); DEFINE(S_SP, offsetof(struct pt_regs, sp)); #ifdef CONFIG_COMPAT diff --git a/arch/arm64/kernel/kprobes.c b/arch/arm64/kernel/kprobes.c index 6255814..98db85c 100644 --- a/arch/arm64/kernel/kprobes.c +++ b/arch/arm64/kernel/kprobes.c @@ -560,6 +560,11 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs) return 0; } +void __kprobes __used *trampoline_probe_handler(struct pt_regs *regs) +{ + return (void *) 0; +} + int __init arch_init_kprobes(void) { return 0; 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 +#include + + .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] + + mov x0, sp + bl trampoline_probe_handler + /* Replace trampoline address in lr with actual + orig_ret_addr return address. */ + str x0, [sp, #S_LR] + + ldr x0, [sp, #S_PSTATE] + msr nzcv, x0 + ldp x0, x1, [sp, #S_X0] + ldp x2, x3, [sp, #S_X2] + ldp x4, x5, [sp, #S_X4] + ldp x6, x7, [sp, #S_X6] + ldp x8, x9, [sp, #S_X8] + ldp x10, x11, [sp, #S_X10] + ldp x12, x13, [sp, #S_X12] + ldp x14, x15, [sp, #S_X14] + ldp x16, x17, [sp, #S_X16] + ldp x18, x19, [sp, #S_X18] + ldp x20, x21, [sp, #S_X20] + ldp x22, x23, [sp, #S_X22] + ldp x24, x25, [sp, #S_X24] + ldp x26, x27, [sp, #S_X26] + ldp x28, x29, [sp, #S_X28] + ldr x30, [sp, #S_LR] + + add sp, sp, #S_FRAME_SIZE + ret + +ENDPROC(kretprobe_trampoline)