From patchwork Mon Mar 2 14:25:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 5913901 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 CA33D9F36A for ; Mon, 2 Mar 2015 14:39:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F13AE201FB for ; Mon, 2 Mar 2015 14:39:04 +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 1E3D8201FA for ; Mon, 2 Mar 2015 14:39:04 +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 1YSRRn-0004RM-MQ; Mon, 02 Mar 2015 14:35:51 +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-00045v-Aa 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-0003SS-O9 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 CHW85028; 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:51 +0800 From: Wang Nan To: , , , , Subject: [RFC PATCH v4 25/34] ftrace: don't fire ftrace_bug if the instruction is taken by early kprobes. Date: Mon, 2 Mar 2015 22:25:03 +0800 Message-ID: <1425306312-3437-26-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_366622_DB85B3BD X-CRM114-Status: GOOD ( 12.95 ) 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 During ftrace_init(), if an early kprobe has already probed at an instruction, don't fire ftrace_bug(). Instead, kprobe_fix_ftrace_make_nop() is for this fixing. It calls arch_fix_ftrace_early_kprobe() to adjust arch specific data. Following patches will convert such kprobes into ftrace. It's kprobe's responsibility for setting and clearing FTRACE_FL_EARLY_KPROBES flag. When ftrace try to makenop, set this flag. When ftrace try to create call instruction on it, unset it. Signed-off-by: Wang Nan --- include/linux/ftrace.h | 5 +++-- include/linux/kprobes.h | 7 +++++++ kernel/kprobes.c | 39 +++++++++++++++++++++++++++++++++++++++ kernel/trace/ftrace.c | 17 ++++++++++++----- 4 files changed, 61 insertions(+), 7 deletions(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 8db315a..fe99166 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -341,10 +341,11 @@ enum { FTRACE_FL_TRAMP = (1UL << 28), FTRACE_FL_TRAMP_EN = (1UL << 27), FTRACE_FL_IPMODIFY = (1UL << 26), + FTRACE_FL_EARLY_KPROBES = (1UL << 25), }; -#define FTRACE_REF_MAX_SHIFT 26 -#define FTRACE_FL_BITS 6 +#define FTRACE_REF_MAX_SHIFT 25 +#define FTRACE_FL_BITS 7 #define FTRACE_FL_MASKED_BITS ((1UL << FTRACE_FL_BITS) - 1) #define FTRACE_FL_MASK (FTRACE_FL_MASKED_BITS << FTRACE_REF_MAX_SHIFT) #define FTRACE_REF_MAX ((1UL << FTRACE_REF_MAX_SHIFT) - 1) diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h index f8f2ac2..ab1a330 100644 --- a/include/linux/kprobes.h +++ b/include/linux/kprobes.h @@ -282,10 +282,17 @@ extern void arch_fix_ftrace_early_kprobe(struct kprobe *kp, struct optimized_kprobe *op, int optimized); extern void init_kprobes_on_ftrace(void); +extern bool kprobe_fix_ftrace_make_nop(struct dyn_ftrace *rec); #else static inline void init_kprobes_on_ftrace(void) { } + +static inline bool kprobe_fix_ftrace_make_nop(struct dyn_ftrace *_unused) +{ + + return false; +} #endif // CONFIG_EARLY_KPROBES && CONFIG_KPROBES_ON_FTRACE #ifdef CONFIG_EARLY_KPROBES diff --git a/kernel/kprobes.c b/kernel/kprobes.c index b5e13ba..20b6ab8 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -2584,6 +2584,45 @@ module_init(init_kprobes); EXPORT_SYMBOL_GPL(jprobe_return); #if defined(CONFIG_KPROBES_ON_FTRACE) && defined(CONFIG_EARLY_KPROBES) +bool kprobe_fix_ftrace_make_nop(struct dyn_ftrace *rec) +{ + struct optimized_kprobe *op; + struct kprobe *kp; + int optimized; + void *addr; + + if (kprobes_on_ftrace_initialized) + return false; + + addr = (void *)rec->ip; + mutex_lock(&kprobe_mutex); + kp = get_kprobe(addr); + + if (!kp || !(kp->flags & KPROBE_FLAG_FTRACE_EARLY)) { + mutex_unlock(&kprobe_mutex); + return false; + } + + op = kprobe_aggrprobe(kp) ? + container_of(kp, struct optimized_kprobe, kp) + : NULL; + + optimized = op ? op->kp.flags & KPROBE_FLAG_OPTIMIZED : 0; + arch_fix_ftrace_early_kprobe(kp, op, optimized); + if (op != NULL) { + struct kprobe *list_p; + + /* Fix all kprobes connected to it */ + list_for_each_entry_rcu(list_p, &op->kp.list, list) + arch_fix_ftrace_early_kprobe(list_p, NULL, optimized); + } + + mutex_unlock(&kprobe_mutex); + + rec->flags |= FTRACE_FL_EARLY_KPROBES; + return true; +} + void init_kprobes_on_ftrace(void) { kprobes_on_ftrace_initialized = true; diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 5cb0269..78787d4 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -2387,11 +2387,18 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec) return 0; ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR); - if (ret) { - ftrace_bug(ret, rec); - return 0; - } - return 1; + + if (!ret) + return 1; + +#if defined(CONFIG_KPROBES_ON_FTRACE) && defined(CONFIG_EARLY_KPROBES) + /* FTRACE_FL_EARLY_KPROBES should have been set for rec */ + if (kprobe_fix_ftrace_make_nop(rec)) + return 1; +#endif + + ftrace_bug(ret, rec); + return 0; } /*