From patchwork Fri Jul 24 05:05:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 11682041 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7C4E513B1 for ; Fri, 24 Jul 2020 05:08:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 44A78206F0 for ; Fri, 24 Jul 2020 05:08:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 44A78206F0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 957A98D0025; Fri, 24 Jul 2020 01:08:37 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8E1328D0007; Fri, 24 Jul 2020 01:08:37 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D02D8D0025; Fri, 24 Jul 2020 01:08:37 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0055.hostedemail.com [216.40.44.55]) by kanga.kvack.org (Postfix) with ESMTP id 6539D8D0007 for ; Fri, 24 Jul 2020 01:08:37 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2FBE2181B04AA for ; Fri, 24 Jul 2020 05:08:37 +0000 (UTC) X-FDA: 77071789074.16.smash94_190349a26f44 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 5F7FB100E7FCF for ; Fri, 24 Jul 2020 05:06:53 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,jarkko.sakkinen@linux.intel.com,,RULES_HIT:30012:30029:30045:30054:30070,0,RBL:192.55.52.88:@linux.intel.com:.lbl8.mailshell.net-64.95.201.95 62.18.0.100;04ygox7ajg6zwbestsiqqehwbrxpwocik15rkouxnpc3ob7gr67reoakkzyy1ya.xikxrcq4mcnss3yz66ywhegsjjn6nzmbbtw5nx3gfg5zhsix4frafm3d5c9rorm.e-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: smash94_190349a26f44 X-Filterd-Recvd-Size: 8253 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Jul 2020 05:06:52 +0000 (UTC) IronPort-SDR: LreWFCKAg0rFtngM0YSyFet+z84vdyxZ51eG6NbgmSa61RdPbEYtfvYsmUiAEn5dL6ZKAmGcrT r8J7wtlAAV1w== X-IronPort-AV: E=McAfee;i="6000,8403,9691"; a="168791261" X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="168791261" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2020 22:06:51 -0700 IronPort-SDR: NkQ3nkTLEOTcS3WUcF0IMgpx6xsIhIk7jenqF0E1B2U0PJ6N8E5GZfdov8Qyi+ytdAnJoi+O1C cK1rk3kfUvoQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="432970230" Received: from itopinsk-mobl1.ccr.corp.intel.com (HELO localhost) ([10.249.36.179]) by orsmga004.jf.intel.com with ESMTP; 23 Jul 2020 22:06:41 -0700 From: Jarkko Sakkinen To: linux-kernel@vger.kernel.org Cc: Jarkko Sakkinen , linux-mm@kvack.org, Andi Kleen , Masami Hiramatsu , Peter Zijlstra , Jessica Yu , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Steven Rostedt , Ingo Molnar , Andrew Morton , "Aneesh Kumar K.V" , Will Deacon , Kees Cook , Sami Tolvanen , Alexandre Ghiti , Masahiro Yamada , Peter Collingbourne , Frederic Weisbecker , Krzysztof Kozlowski , Arnd Bergmann , Stephen Boyd Subject: [PATCH v5 6/6] kprobes: Remove CONFIG_MODULES dependency Date: Fri, 24 Jul 2020 08:05:53 +0300 Message-Id: <20200724050553.1724168-7-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200724050553.1724168-1-jarkko.sakkinen@linux.intel.com> References: <20200724050553.1724168-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5F7FB100E7FCF X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Remove CONFIG_MODULES dependency by flagging out the dependent code. This allows to use kprobes in a kernel without support for loadable modules, which is an useful feature for test kernels and embedded kernels. Cc: linux-mm@kvack.org Cc: Andi Kleen Cc: Masami Hiramatsu Cc: Peter Zijlstra Signed-off-by: Jarkko Sakkinen --- arch/Kconfig | 2 +- include/linux/module.h | 14 +++++------ kernel/kprobes.c | 48 +++++++++++++++++++++++-------------- kernel/trace/trace_kprobe.c | 16 +++++++++++-- 4 files changed, 52 insertions(+), 28 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 8cc35dc556c7..e3d6b6868ccb 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -61,7 +61,7 @@ config OPROFILE_NMI_TIMER config KPROBES bool "Kprobes" - depends on MODULES + depends on MODULES || ARCH_HAS_TEXT_ALLOC depends on HAVE_KPROBES select KALLSYMS help diff --git a/include/linux/module.h b/include/linux/module.h index 8850b9692b8f..22c646cff6bd 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -290,6 +290,13 @@ extern typeof(name) __mod_##type##__##name##_device_table \ struct notifier_block; +enum module_state { + MODULE_STATE_LIVE, /* Normal state. */ + MODULE_STATE_COMING, /* Full formed, running module_init. */ + MODULE_STATE_GOING, /* Going away. */ + MODULE_STATE_UNFORMED, /* Still setting it up. */ +}; + #ifdef CONFIG_MODULES extern int modules_disabled; /* for sysctl */ @@ -305,13 +312,6 @@ struct module_use { struct module *source, *target; }; -enum module_state { - MODULE_STATE_LIVE, /* Normal state. */ - MODULE_STATE_COMING, /* Full formed, running module_init. */ - MODULE_STATE_GOING, /* Going away. */ - MODULE_STATE_UNFORMED, /* Still setting it up. */ -}; - struct mod_tree_node { struct module *mod; struct latch_tree_node node; diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 611fcda9f6bf..bb2e3070481a 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1617,6 +1617,7 @@ static int check_kprobe_address_safe(struct kprobe *p, goto out; } +#ifdef CONFIG_MODULES /* * If the module freed .init.text, we couldn't insert * kprobes in there. @@ -1627,6 +1628,7 @@ static int check_kprobe_address_safe(struct kprobe *p, *probed_mod = NULL; ret = -ENOENT; } +#endif } out: preempt_enable(); @@ -2223,24 +2225,6 @@ int kprobe_add_area_blacklist(unsigned long start, unsigned long end) return 0; } -/* Remove all symbols in given area from kprobe blacklist */ -static void kprobe_remove_area_blacklist(unsigned long start, unsigned long end) -{ - struct kprobe_blacklist_entry *ent, *n; - - list_for_each_entry_safe(ent, n, &kprobe_blacklist, list) { - if (ent->start_addr < start || ent->start_addr >= end) - continue; - list_del(&ent->list); - kfree(ent); - } -} - -static void kprobe_remove_ksym_blacklist(unsigned long entry) -{ - kprobe_remove_area_blacklist(entry, entry + 1); -} - int __init __weak arch_populate_kprobe_blacklist(void) { return 0; @@ -2283,6 +2267,25 @@ static int __init populate_kprobe_blacklist(unsigned long *start, return ret ? : arch_populate_kprobe_blacklist(); } +#ifdef CONFIG_MODULES +/* Remove all symbols in given area from kprobe blacklist */ +static void kprobe_remove_area_blacklist(unsigned long start, unsigned long end) +{ + struct kprobe_blacklist_entry *ent, *n; + + list_for_each_entry_safe(ent, n, &kprobe_blacklist, list) { + if (ent->start_addr < start || ent->start_addr >= end) + continue; + list_del(&ent->list); + kfree(ent); + } +} + +static void kprobe_remove_ksym_blacklist(unsigned long entry) +{ + kprobe_remove_area_blacklist(entry, entry + 1); +} + static void add_module_kprobe_blacklist(struct module *mod) { unsigned long start, end; @@ -2328,6 +2331,15 @@ static void remove_module_kprobe_blacklist(struct module *mod) kprobe_remove_area_blacklist(start, end); } } +#else +static void add_module_kprobe_blacklist(struct module *mod) +{ +} + +static void remove_module_kprobe_blacklist(struct module *mod) +{ +} +#endif /* CONFIG_MODULES */ /* Module notifier call back, checking kprobes on the module */ static int kprobes_module_callback(struct notifier_block *nb, diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 710ec6a6aa8f..881c998d0162 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -103,8 +103,9 @@ static nokprobe_inline bool trace_kprobe_has_gone(struct trace_kprobe *tk) return !!(kprobe_gone(&tk->rp.kp)); } +#ifdef CONFIG_MODULES static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk, - struct module *mod) + struct module *mod) { int len = strlen(mod->name); const char *name = trace_kprobe_symbol(tk); @@ -129,6 +130,17 @@ static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) return ret; } +#else +static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk, + struct module *mod) +{ + return false; +} +static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) +{ + return false; +} +#endif static bool trace_kprobe_is_busy(struct dyn_event *ev) { @@ -688,7 +700,7 @@ static int trace_kprobe_module_callback(struct notifier_block *nb, if (ret) pr_warn("Failed to re-register probe %s on %s: %d\n", trace_probe_name(&tk->tp), - mod->name, ret); + module_name(mod), ret); } } mutex_unlock(&event_mutex);