From patchwork Mon Mar 2 14:25:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 5913961 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4BEE2BF440 for ; Mon, 2 Mar 2015 14:43:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 657CD201FB for ; Mon, 2 Mar 2015 14:43:47 +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 854C2201FA for ; Mon, 2 Mar 2015 14:43:46 +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 1YSRWV-0000g2-AM; Mon, 02 Mar 2015 14:40:43 +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 1YSRJI-00045t-7i for linux-arm-kernel@bombadil.infradead.org; Mon, 02 Mar 2015 14:27:04 +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-0003SQ-O7 for linux-arm-kernel@lists.infradead.org; Mon, 02 Mar 2015 14:27:03 +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 CHW85023; Mon, 02 Mar 2015 22:26:00 +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:49 +0800 From: Wang Nan To: , , , , Subject: [RFC PATCH v4 23/34] ftrace: notify kprobe when ftrace is initialized. Date: Mon, 2 Mar 2015 22:25:01 +0800 Message-ID: <1425306312-3437-24-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_371405_C2E50CD1 X-CRM114-Status: GOOD ( 12.16 ) 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 Makes ftrace calls init_kprobes_on_ftrace() when ftrace_init() finished. Before this call, marks kprobes on ftrace with 'KPROBE_FLAG_FTRACE_EARLY' instead of 'KPROBE_FLAG_FTRACE' to make kprobe not to kprobe treats these kprobes as ftrace kprobes. Following patches should convert such kprobes into kprobes on ftrace. Signed-off-by: Wang Nan --- include/linux/kprobes.h | 11 +++++++++++ kernel/kprobes.c | 17 ++++++++++++++++- kernel/trace/ftrace.c | 2 ++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h index bb2b2c6..96dc842 100644 --- a/include/linux/kprobes.h +++ b/include/linux/kprobes.h @@ -130,6 +130,8 @@ struct kprobe { * this flag is only for optimized_kprobe. */ #define KPROBE_FLAG_FTRACE 8 /* probe is using ftrace */ +/* probe will use ftrace, but ftrace is not ready when registering */ +#define KPROBE_FLAG_FTRACE_EARLY 16 /* Has this kprobe gone ? */ static inline int kprobe_gone(struct kprobe *p) @@ -269,6 +271,14 @@ 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); +#if defined(CONFIG_EARLY_KPROBES) && defined(CONFIG_KPROBES_ON_FTRACE) +extern void init_kprobes_on_ftrace(void); +#else +static inline void init_kprobes_on_ftrace(void) +{ +} +#endif // CONFIG_EARLY_KPROBES && CONFIG_KPROBES_ON_FTRACE + #ifdef CONFIG_EARLY_KPROBES #define NR_EARLY_KPROBES_SLOTS CONFIG_NR_EARLY_KPROBES_SLOTS @@ -453,6 +463,7 @@ extern int proc_kprobes_optimization_handler(struct ctl_table *table, extern void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *ops, struct pt_regs *regs); extern int arch_prepare_kprobe_ftrace(struct kprobe *p); + #endif int arch_check_ftrace_location(struct kprobe *p); diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 4b7b20a..b5e13ba 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -69,6 +69,11 @@ static int kprobes_initialized; static int kprobes_blacklist_initialized; +#if defined(CONFIG_KPROBES_ON_FTRACE) && defined(CONFIG_EARLY_KPROBES) +static bool kprobes_on_ftrace_initialized __read_mostly = false; +#else +# define kprobes_on_ftrace_initialized false +#endif bool kprobes_is_early(void) { @@ -1497,7 +1502,10 @@ int __weak arch_check_ftrace_location(struct kprobe *p) /* Given address is not on the instruction boundary */ if ((unsigned long)p->addr != ftrace_addr) return -EILSEQ; - p->flags |= KPROBE_FLAG_FTRACE; + if (unlikely(!kprobes_on_ftrace_initialized)) + p->flags |= KPROBE_FLAG_FTRACE_EARLY; + else + p->flags |= KPROBE_FLAG_FTRACE; #else /* !CONFIG_KPROBES_ON_FTRACE */ return -EINVAL; #endif @@ -2574,3 +2582,10 @@ module_init(init_kprobes); /* defined in arch/.../kernel/kprobes.c */ EXPORT_SYMBOL_GPL(jprobe_return); + +#if defined(CONFIG_KPROBES_ON_FTRACE) && defined(CONFIG_EARLY_KPROBES) +void init_kprobes_on_ftrace(void) +{ + kprobes_on_ftrace_initialized = true; +} +#endif diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 7fa88d0..5cb0269 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -5022,6 +5023,7 @@ void __init ftrace_init(void) if (ret) pr_warning("Failed to register trace ftrace module exit notifier\n"); + init_kprobes_on_ftrace(); set_ftrace_early_filters(); return;