From patchwork Mon Mar 2 14:25:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 5913921 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 3136F9F36A for ; Mon, 2 Mar 2015 14:41:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4BD492020F for ; Mon, 2 Mar 2015 14:41:21 +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 2B8D4201FA for ; Mon, 2 Mar 2015 14:41:20 +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 1YSRUF-0006A4-9B; Mon, 02 Mar 2015 14:38:23 +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 1YSRJH-00045S-JN for linux-arm-kernel@bombadil.infradead.org; Mon, 02 Mar 2015 14:27:03 +0000 Received: from szxga02-in.huawei.com ([119.145.14.65]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YSRJE-0003SP-OF for linux-arm-kernel@lists.infradead.org; Mon, 02 Mar 2015 14:27:02 +0000 Received: from 172.24.2.119 (EHLO lggeml422-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CHW85029; Mon, 02 Mar 2015 22:26:01 +0800 (CST) Received: from kernel-host.huawei (10.107.197.247) by lggeml422-hub.china.huawei.com (10.72.61.32) with Microsoft SMTP Server id 14.3.158.1; Mon, 2 Mar 2015 22:25:50 +0800 From: Wang Nan To: , , , , Subject: [RFC PATCH v4 24/34] early kprobes on ftrace: introduce x86 arch_fix_ftrace_early_kprobe(). Date: Mon, 2 Mar 2015 22:25:02 +0800 Message-ID: <1425306312-3437-25-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1425306312-3437-1-git-send-email-wangnan0@huawei.com> References: <1425306312-3437-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.197.247] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150302_092701_371600_85F1D26F X-CRM114-Status: UNSURE ( 9.81 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -4.2 (----) Cc: x86@kernel.org, lizefan@huawei.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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: , 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.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_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 arch_fix_ftrace_early_kprobe() will be called during ftrace converting its entries into nops. This function is made for kprobe adjusting its internal data. To make as much as arch independent logic out of arch specific code, arch_fix_ftrace_early_kprobe() doesn't iterate on kprobes in a aggr kprobe. Such iteration should be done in kernel/kprobes.c. Signed-off-by: Wang Nan --- arch/x86/kernel/kprobes/core.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/kprobes.h | 9 +++++++++ 2 files changed, 43 insertions(+) diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index 4e3d5a9..ead5b51 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -1126,3 +1126,37 @@ int arch_trampoline_kprobe(struct kprobe *p) { return 0; } + +#if defined(CONFIG_KPROBES_ON_FTRACE) && defined(CONFIG_EARLY_KPROBES) + +#define INT3_SIZE sizeof(kprobe_opcode_t) + +void arch_fix_ftrace_early_kprobe(struct kprobe *kp, + struct optimized_kprobe *op, int optimized) +{ + const unsigned char *ftrace_nop = ideal_nops[NOP_ATOMIC5]; + const unsigned char *src = ftrace_nop + INT3_SIZE; + unsigned char *dest = kp->addr + INT3_SIZE; + size_t length = MCOUNT_INSN_SIZE - INT3_SIZE; + + BUG_ON(op && (&op->kp != kp)); + BUG_ON(optimized && op && (!(kp->flags & KPROBE_FLAG_OPTIMIZED))); + + if ((!optimized) && (memcmp(dest, src, length) != 0)) + text_poke_early(dest, src, length); + + memcpy(&kp->opcode, ftrace_nop, INT3_SIZE); + if (op && op->kp.flags & KPROBE_FLAG_OPTIMIZED) { + /* + * We are not allowed to use internal data of struct + * optimized_kprobe if CONFIG_OPTPROBES is not defined. + */ +#ifdef CONFIG_OPTPROBES + memcpy(op->optinsn.copied_insn, src, length); +#else + BUG_ON(1); +#endif + } +} + +#endif diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h index 96dc842..f8f2ac2 100644 --- a/include/linux/kprobes.h +++ b/include/linux/kprobes.h @@ -271,7 +271,16 @@ extern void show_registers(struct pt_regs *regs); extern void kprobes_inc_nmissed_count(struct kprobe *p); extern bool arch_within_kprobe_blacklist(unsigned long addr); +/* + * Only when CONFIG_OPTPROBES struct optimized_kprobe is defined. Only use + * its pointer in function decl list. + */ +struct optimized_kprobe; + #if defined(CONFIG_EARLY_KPROBES) && defined(CONFIG_KPROBES_ON_FTRACE) +extern void arch_fix_ftrace_early_kprobe(struct kprobe *kp, + struct optimized_kprobe *op, int optimized); + extern void init_kprobes_on_ftrace(void); #else static inline void init_kprobes_on_ftrace(void)