From patchwork Thu Jun 18 03:58:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pratyush Anand X-Patchwork-Id: 6632941 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6CF4A9F326 for ; Thu, 18 Jun 2015 04:03:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6C02C2085C for ; Thu, 18 Jun 2015 04:03:43 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7385F20671 for ; Thu, 18 Jun 2015 04:03:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z5R10-00059m-Dd; Thu, 18 Jun 2015 04:01:22 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z5Qzh-0003GI-D4 for linux-arm-kernel@bombadil.infradead.org; Thu, 18 Jun 2015 04:00:01 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z5Qzf-0001Oh-G3 for linux-arm-kernel@lists.infradead.org; Thu, 18 Jun 2015 04:00:00 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 04B01B7A84; Thu, 18 Jun 2015 03:59:36 +0000 (UTC) Received: from localhost (vpn-48-37.rdu2.redhat.com [10.10.48.37]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5I3xXx7003720; Wed, 17 Jun 2015 23:59:34 -0400 From: Pratyush Anand To: linux-arm-kernel@lists.infradead.org, linux@arm.linux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com Subject: [RFC PATCH V2 01/10] arm64: kprobe: Make prepare and handler function independent of 'struct kprobe' Date: Thu, 18 Jun 2015 09:28:48 +0530 Message-Id: <0091224459129b3da73b9ff1bfadd9865f0c4a27.1434598237.git.panand@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150617_235959_687522_4A9AB77C X-CRM114-Status: GOOD ( 13.43 ) X-Spam-Score: -7.5 (-------) Cc: Pratyush Anand , steve.capper@linaro.org, srikar@linux.vnet.ibm.com, vijaya.kumar@caviumnetworks.com, linux-kernel@vger.kernel.org, oleg@redhat.com, dave.long@linaro.org, wcohen@redhat.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP prepare and handler function will also be used by uprobe. So, make them struct kprobe independent. Signed-off-by: Pratyush Anand --- arch/arm64/include/asm/probes.h | 5 +++-- arch/arm64/kernel/kprobes-arm64.c | 33 +++++++++++++-------------------- arch/arm64/kernel/kprobes.c | 7 ++++--- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/arch/arm64/include/asm/probes.h b/arch/arm64/include/asm/probes.h index 7f5a27fa071c..f07968f1335f 100644 --- a/arch/arm64/include/asm/probes.h +++ b/arch/arm64/include/asm/probes.h @@ -21,9 +21,10 @@ struct arch_specific_insn; typedef u32 kprobe_opcode_t; typedef unsigned long (kprobes_pstate_check_t)(unsigned long); typedef unsigned long -(probes_condition_check_t)(struct kprobe *p, struct pt_regs *); +(probes_condition_check_t)(u32 opcode, struct arch_specific_insn *asi, + struct pt_regs *); typedef void -(probes_prepare_t)(struct kprobe *, struct arch_specific_insn *); +(probes_prepare_t)(u32 insn, struct arch_specific_insn *); typedef void (kprobes_handler_t) (u32 opcode, long addr, struct pt_regs *); enum pc_restore_type { diff --git a/arch/arm64/kernel/kprobes-arm64.c b/arch/arm64/kernel/kprobes-arm64.c index 8a7e6b0290a7..d8f6e79b4de0 100644 --- a/arch/arm64/kernel/kprobes-arm64.c +++ b/arch/arm64/kernel/kprobes-arm64.c @@ -26,68 +26,61 @@ * condition check functions for kprobes simulation */ static unsigned long __kprobes -__check_pstate(struct kprobe *p, struct pt_regs *regs) +__check_pstate(u32 opcode, struct arch_specific_insn *asi, struct pt_regs *regs) { - struct arch_specific_insn *asi = &p->ainsn; unsigned long pstate = regs->pstate & 0xffffffff; return asi->pstate_cc(pstate); } static unsigned long __kprobes -__check_cbz(struct kprobe *p, struct pt_regs *regs) +__check_cbz(u32 opcode, struct arch_specific_insn *asi, struct pt_regs *regs) { - return check_cbz((u32)p->opcode, regs); + return check_cbz(opcode, regs); } static unsigned long __kprobes -__check_cbnz(struct kprobe *p, struct pt_regs *regs) +__check_cbnz(u32 opcode, struct arch_specific_insn *asi, struct pt_regs *regs) { - return check_cbnz((u32)p->opcode, regs); + return check_cbnz(opcode, regs); } static unsigned long __kprobes -__check_tbz(struct kprobe *p, struct pt_regs *regs) +__check_tbz(u32 opcode, struct arch_specific_insn *asi, struct pt_regs *regs) { - return check_tbz((u32)p->opcode, regs); + return check_tbz(opcode, regs); } static unsigned long __kprobes -__check_tbnz(struct kprobe *p, struct pt_regs *regs) +__check_tbnz(u32 opcode, struct arch_specific_insn *asi, struct pt_regs *regs) { - return check_tbnz((u32)p->opcode, regs); + return check_tbnz(opcode, regs); } /* * prepare functions for instruction simulation */ static void __kprobes -prepare_none(struct kprobe *p, struct arch_specific_insn *asi) +prepare_none(u32 insn, struct arch_specific_insn *asi) { } static void __kprobes -prepare_bcond(struct kprobe *p, struct arch_specific_insn *asi) +prepare_bcond(u32 insn, struct arch_specific_insn *asi) { - kprobe_opcode_t insn = p->opcode; - asi->check_condn = __check_pstate; asi->pstate_cc = kprobe_condition_checks[insn & 0xf]; } static void __kprobes -prepare_cbz_cbnz(struct kprobe *p, struct arch_specific_insn *asi) +prepare_cbz_cbnz(u32 insn, struct arch_specific_insn *asi) { - kprobe_opcode_t insn = p->opcode; - asi->check_condn = (insn & (1 << 24)) ? __check_cbnz : __check_cbz; } static void __kprobes -prepare_tbz_tbnz(struct kprobe *p, struct arch_specific_insn *asi) +prepare_tbz_tbnz(u32 insn, struct arch_specific_insn *asi) { - kprobe_opcode_t insn = p->opcode; - asi->check_condn = (insn & (1 << 24)) ? __check_tbnz : __check_tbz; } diff --git a/arch/arm64/kernel/kprobes.c b/arch/arm64/kernel/kprobes.c index 7e34ef381055..740f71695b07 100644 --- a/arch/arm64/kernel/kprobes.c +++ b/arch/arm64/kernel/kprobes.c @@ -60,7 +60,7 @@ static void __kprobes arch_prepare_ss_slot(struct kprobe *p) static void __kprobes arch_prepare_simulate(struct kprobe *p) { if (p->ainsn.prepare) - p->ainsn.prepare(p, &p->ainsn); + p->ainsn.prepare(p->opcode, &p->ainsn); /* This instructions is not executed xol. No need to adjust the PC */ p->ainsn.restore.addr = 0; @@ -271,7 +271,8 @@ static int __kprobes reenter_kprobe(struct kprobe *p, switch (kcb->kprobe_status) { case KPROBE_HIT_SSDONE: case KPROBE_HIT_ACTIVE: - if (!p->ainsn.check_condn || p->ainsn.check_condn(p, regs)) { + if (!p->ainsn.check_condn || + p->ainsn.check_condn((u32)p->opcode, &p->ainsn, regs)) { kprobes_inc_nmissed_count(p); setup_singlestep(p, regs, kcb, 1); } else { @@ -402,7 +403,7 @@ void __kprobes kprobe_handler(struct pt_regs *regs) if (reenter_kprobe(p, regs, kcb)) return; } else if (!p->ainsn.check_condn || - p->ainsn.check_condn(p, regs)) { + p->ainsn.check_condn((u32)p->opcode, &p->ainsn, regs)) { /* Probe hit and conditional execution check ok. */ set_current_kprobe(p); kcb->kprobe_status = KPROBE_HIT_ACTIVE;