From patchwork Mon Jun 15 19:07:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Long X-Patchwork-Id: 49929 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 62563205DE for ; Mon, 15 Jun 2015 19:07:28 +0000 (UTC) Received: by labnp3 with SMTP id np3sf9047048lab.1 for ; Mon, 15 Jun 2015 12:07:27 -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=xvpPZ0a7vk/hUHyG8TzbGfdF7H7YxCrdkCBEBT11J/s=; b=TP+svdO0gbNHwGIStCay4I5sNme/m4qvFFtC5EDBpOBa7PTsybNsE202M/M02v3EHd h+Gby7q6haQSHXiNfe5h7srtSXs31w0A9QWnCs1+z/ojAsm9fy6nJpdCtcurvQRsLkFE nQIzp1J5garvYzHEJ/Te9epsAPAkFrVUl85kgRVtOtaMd5n9c7s+GwE+VZfq2BOXjh0w N3uH6Hh05olDfqdoZ0wW2rSHGiGlQIl1CzvfNeEjZXxpaw87lfNJrJ0gerbFBR7qT561 3Za1sVrhagAfVspEuuxz+tS+sTdI8PcvKJ2c2iBAZJjEEQq4x1f9QEJS2EIjH3Y22olv 3kww== X-Gm-Message-State: ALoCoQmJQ8qAnILZXuk5T6UoPQGQm2kl2pDCWLLg8uTsYh3T0yqbnelUzxnc4iml1l9YJWf/32Md X-Received: by 10.152.9.3 with SMTP id v3mr31052627laa.6.1434395247368; Mon, 15 Jun 2015 12:07:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.36 with SMTP id g4ls946488lah.33.gmail; Mon, 15 Jun 2015 12:07:27 -0700 (PDT) X-Received: by 10.152.8.168 with SMTP id s8mr28569342laa.116.1434395247217; Mon, 15 Jun 2015 12:07:27 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id p2si11171970lap.109.2015.06.15.12.07.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2015 12:07:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by laka10 with SMTP id a10so16615710lak.0 for ; Mon, 15 Jun 2015 12:07:27 -0700 (PDT) X-Received: by 10.112.140.231 with SMTP id rj7mr1601838lbb.76.1434395247118; Mon, 15 Jun 2015 12:07:27 -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.108.230 with SMTP id hn6csp1616824lbb; Mon, 15 Jun 2015 12:07:26 -0700 (PDT) X-Received: by 10.55.16.218 with SMTP id 87mr63981838qkq.67.1434395237822; Mon, 15 Jun 2015 12:07:17 -0700 (PDT) Received: from mail-qc0-f173.google.com (mail-qc0-f173.google.com. [209.85.216.173]) by mx.google.com with ESMTPS id k91si3871465qkh.21.2015.06.15.12.07.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2015 12:07:17 -0700 (PDT) Received-SPF: pass (google.com: domain of dave.long@linaro.org designates 209.85.216.173 as permitted sender) client-ip=209.85.216.173; Received: by qcwx2 with SMTP id x2so5867060qcw.1 for ; Mon, 15 Jun 2015 12:07:17 -0700 (PDT) X-Received: by 10.55.25.40 with SMTP id k40mr13282174qkh.30.1434395237211; Mon, 15 Jun 2015 12:07:17 -0700 (PDT) Received: from localhost.localdomain (pool-72-71-243-249.cncdnh.fast00.myfairpoint.net. [72.71.243.249]) by mx.google.com with ESMTPSA id 6sm6748404qks.37.2015.06.15.12.07.16 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 15 Jun 2015 12:07:16 -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 v7 5/7] arm64: Add trampoline code for kretprobes Date: Mon, 15 Jun 2015 15:07:07 -0400 Message-Id: <1434395229-6654-6-git-send-email-dave.long@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1434395229-6654-1-git-send-email-dave.long@linaro.org> References: <1434395229-6654-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.43 as permitted sender) smtp.mail=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 roginal 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 | 1 + arch/arm64/kernel/kprobes-arm64.h | 41 +++++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/kprobes.c | 26 +++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/arch/arm64/include/asm/kprobes.h b/arch/arm64/include/asm/kprobes.h index af31c4d..d081f49 100644 --- a/arch/arm64/include/asm/kprobes.h +++ b/arch/arm64/include/asm/kprobes.h @@ -58,5 +58,6 @@ 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); #endif /* _ARM_KPROBES_H */ diff --git a/arch/arm64/kernel/kprobes-arm64.h b/arch/arm64/kernel/kprobes-arm64.h index ff8a55f..bdcfa62 100644 --- a/arch/arm64/kernel/kprobes-arm64.h +++ b/arch/arm64/kernel/kprobes-arm64.h @@ -27,4 +27,45 @@ extern kprobes_pstate_check_t * const kprobe_condition_checks[16]; enum kprobe_insn __kprobes arm_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi); +#define SAVE_REGS_STRING\ + " stp x0, x1, [sp, #16 * 0]\n" \ + " stp x2, x3, [sp, #16 * 1]\n" \ + " stp x4, x5, [sp, #16 * 2]\n" \ + " stp x6, x7, [sp, #16 * 3]\n" \ + " stp x8, x9, [sp, #16 * 4]\n" \ + " stp x10, x11, [sp, #16 * 5]\n" \ + " stp x12, x13, [sp, #16 * 6]\n" \ + " stp x14, x15, [sp, #16 * 7]\n" \ + " stp x16, x17, [sp, #16 * 8]\n" \ + " stp x18, x19, [sp, #16 * 9]\n" \ + " stp x20, x21, [sp, #16 * 10]\n" \ + " stp x22, x23, [sp, #16 * 11]\n" \ + " stp x24, x25, [sp, #16 * 12]\n" \ + " stp x26, x27, [sp, #16 * 13]\n" \ + " stp x28, x29, [sp, #16 * 14]\n" \ + " str x30, [sp, #16 * 15]\n" \ + " mrs x0, nzcv\n" \ + " str x0, [sp, #8 * 33]\n" + + +#define RESTORE_REGS_STRING\ + " ldr x0, [sp, #8 * 33]\n" \ + " msr nzcv, x0\n" \ + " ldp x0, x1, [sp, #16 * 0]\n" \ + " ldp x2, x3, [sp, #16 * 1]\n" \ + " ldp x4, x5, [sp, #16 * 2]\n" \ + " ldp x6, x7, [sp, #16 * 3]\n" \ + " ldp x8, x9, [sp, #16 * 4]\n" \ + " ldp x10, x11, [sp, #16 * 5]\n" \ + " ldp x12, x13, [sp, #16 * 6]\n" \ + " ldp x14, x15, [sp, #16 * 7]\n" \ + " ldp x16, x17, [sp, #16 * 8]\n" \ + " ldp x18, x19, [sp, #16 * 9]\n" \ + " ldp x20, x21, [sp, #16 * 10]\n" \ + " ldp x22, x23, [sp, #16 * 11]\n" \ + " ldp x24, x25, [sp, #16 * 12]\n" \ + " ldp x26, x27, [sp, #16 * 13]\n" \ + " ldp x28, x29, [sp, #16 * 14]\n" \ + " ldr x30, [sp, #16 * 15]\n" + #endif /* _ARM_KERNEL_KPROBES_ARM64_H */ diff --git a/arch/arm64/kernel/kprobes.c b/arch/arm64/kernel/kprobes.c index 6255814..570218c 100644 --- a/arch/arm64/kernel/kprobes.c +++ b/arch/arm64/kernel/kprobes.c @@ -560,6 +560,32 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs) return 0; } +/* + * When a retprobed function returns, this code saves registers and + * calls trampoline_handler() runs, which calls the kretprobe's handler. + */ +static void __used __kprobes kretprobe_trampoline_holder(void) +{ + asm volatile (".global kretprobe_trampoline\n" + "kretprobe_trampoline:\n" + "sub sp, sp, %0\n" + SAVE_REGS_STRING + "mov x0, sp\n" + "bl trampoline_probe_handler\n" + /* Replace trampoline address in lr with actual + orig_ret_addr return address. */ + "str x0, [sp, #16 * 15]\n" + RESTORE_REGS_STRING + "add sp, sp, %0\n" + "ret\n" + : : "I"(sizeof(struct pt_regs)) : "memory"); +} + +static void __kprobes __used *trampoline_probe_handler(struct pt_regs *regs) +{ + return (void *) 0; +} + int __init arch_init_kprobes(void) { return 0;