From patchwork Mon Mar 2 14:24:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 5913661 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 E40E09F373 for ; Mon, 2 Mar 2015 14:32:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1BA8D2013A for ; Mon, 2 Mar 2015 14:32:50 +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 432F62012B for ; Mon, 2 Mar 2015 14:32:49 +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 1YSRLv-0005wO-3l; Mon, 02 Mar 2015 14:29:47 +0000 Received: from szxga01-in.huawei.com ([119.145.14.64]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YSRJ2-0003ib-Nu for linux-arm-kernel@lists.infradead.org; Mon, 02 Mar 2015 14:26:56 +0000 Received: from 172.24.2.119 (EHLO lggeml422-hub.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CKE50581; Mon, 02 Mar 2015 22:25:48 +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:37 +0800 From: Wang Nan To: , , , , Subject: [RFC PATCH v4 07/34] early kprobes: init kprobes at very early stage. Date: Mon, 2 Mar 2015 22:24:45 +0800 Message-ID: <1425306312-3437-8-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_062649_172642_24BFCE7C X-CRM114-Status: GOOD ( 14.22 ) X-Spam-Score: -2.3 (--) 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 Separate init_kprobes() into early and late phases, and do most of initialization after setup_arch(), so we are able to use kprobes at very early stage. Signed-off-by: Wang Nan --- include/linux/kprobes.h | 6 ++++++ init/main.c | 2 ++ kernel/kprobes.c | 39 ++++++++++++++++++++++++++------------- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h index a3de759..b7cb992 100644 --- a/include/linux/kprobes.h +++ b/include/linux/kprobes.h @@ -491,8 +491,14 @@ static unsigned long __used \ __attribute__((section("_kprobe_blacklist"))) \ _kbl_addr_##fname = (unsigned long)fname; #define NOKPROBE_SYMBOL(fname) __NOKPROBE_SYMBOL(fname) + +extern void init_kprobes_early(void); + #else #define NOKPROBE_SYMBOL(fname) + +static inline void init_kprobes_early(void) { return; } + #endif #endif /* _LINUX_KPROBES_H */ diff --git a/init/main.c b/init/main.c index 6f0f1c5f..679d49e 100644 --- a/init/main.c +++ b/init/main.c @@ -80,6 +80,7 @@ #include #include #include +#include #include #include @@ -518,6 +519,7 @@ asmlinkage __visible void __init start_kernel(void) page_address_init(); pr_notice("%s", linux_banner); setup_arch(&command_line); + init_kprobes_early(); mm_init_cpumask(&init_mm); setup_command_line(command_line); setup_nr_cpu_ids(); diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 2e728a4..614138c 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1521,6 +1521,11 @@ int register_kprobe(struct kprobe *p) struct module *probed_mod; kprobe_opcode_t *addr; +#ifndef CONFIG_EARLY_KPROBES + if (kprobes_is_early()) + return -EAGAIN; +#endif + /* Adjust probe address from symbol */ addr = kprobe_addr(p); if (IS_ERR(addr)) @@ -2161,11 +2166,7 @@ static struct notifier_block kprobe_module_nb = { .priority = 0 }; -/* Markers of _kprobe_blacklist section */ -extern unsigned long __start_kprobe_blacklist[]; -extern unsigned long __stop_kprobe_blacklist[]; - -static int __init init_kprobes(void) +void init_kprobes_early(void) { int i, err = 0; @@ -2177,14 +2178,6 @@ static int __init init_kprobes(void) raw_spin_lock_init(&(kretprobe_table_locks[i].lock)); } - err = populate_kprobe_blacklist(__start_kprobe_blacklist, - __stop_kprobe_blacklist); - if (err) { - pr_err("kprobes: failed to populate blacklist: %d\n", err); - pr_err("Please take care of using kprobes.\n"); - } - kprobes_blacklist_initialized = (err == 0); - if (kretprobe_blacklist_size) { /* lookup the function address from its name */ for (i = 0; kretprobe_blacklist[i].name != NULL; i++) { @@ -2215,6 +2208,26 @@ static int __init init_kprobes(void) err = register_module_notifier(&kprobe_module_nb); kprobes_initialized = (err == 0); +} + +static int __init init_kprobes(void) +{ + /* Markers of _kprobe_blacklist section */ + extern unsigned long __start_kprobe_blacklist[]; + extern unsigned long __stop_kprobe_blacklist[]; + int err = 0; + + err = populate_kprobe_blacklist(__start_kprobe_blacklist, + __stop_kprobe_blacklist); + if (err) { + pr_err("kprobes: failed to populate blacklist: %d\n", err); + pr_err("Please take care of using kprobes.\n"); + } + kprobes_blacklist_initialized = (err == 0); + + err = kprobes_is_early() ? -ENOSYS : 0; + + /* TODO: deal with early kprobes. */ if (!err) init_test_probes();