From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08789C46CA1 for ; Mon, 18 Sep 2023 16:09:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229730AbjIRQJ0 (ORCPT ); Mon, 18 Sep 2023 12:09:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230075AbjIRQJH (ORCPT ); Mon, 18 Sep 2023 12:09:07 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 727DE5B95 for ; Mon, 18 Sep 2023 09:07:32 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D336CC116B0; Mon, 18 Sep 2023 15:52:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1695052352; bh=E9Ra3F0UHdUwaEbC0ONrdAvsI0AM5xGi3e4+aVePIpI=; h=Date:To:From:Subject:From; b=ntyjdLRetz2LgLtZyrDOA23y/XMBXBDb0hc2L9Gjb0KhWc0+gyxYyLeVxWzy7vxcq DbzKuOAMUMZSCta4/xDCCfV8LwSNnDs7TfteS4uvhbl9xuoYH2CZm2oa/j/O4iSsDl n1XaUAwBJ9gM9uoB6Ae0K21S8nV7OOg7kIJ1jyxg= Date: Mon, 18 Sep 2023 08:52:32 -0700 To: mm-commits@vger.kernel.org, will@kernel.org, tsbogend@alpha.franken.de, tglx@linutronix.de, song@kernel.org, rostedt@goodmis.org, rick.p.edgecombe@intel.com, puranjay12@gmail.com, palmer@dabbelt.com, naveen.n.rao@linux.ibm.com, nadav.amit@gmail.com, mpe@ellerman.id.au, mcgrof@kernel.org, mark.rutland@arm.com, linux@armlinux.org.uk, kent.overstreet@linux.dev, hca@linux.ibm.com, dinguyen@kernel.org, deller@gmx.de, davem@davemloft.net, christophe.leroy@csgroup.eu, chenhuacai@kernel.org, catalin.marinas@arm.com, bjorn@kernel.org, rppt@kernel.org, akpm@linux-foundation.org From: Andrew Morton Subject: + kprobes-remove-dependency-on-config_modules.patch added to mm-unstable branch Message-Id: <20230918155232.D336CC116B0@smtp.kernel.org> Precedence: bulk Reply-To: linux-kernel@vger.kernel.org List-ID: X-Mailing-List: mm-commits@vger.kernel.org The patch titled Subject: kprobes: remove dependency on CONFIG_MODULES has been added to the -mm mm-unstable branch. Its filename is kprobes-remove-dependency-on-config_modules.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/kprobes-remove-dependency-on-config_modules.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: "Mike Rapoport (IBM)" Subject: kprobes: remove dependency on CONFIG_MODULES Date: Mon, 18 Sep 2023 10:29:54 +0300 kprobes depended on CONFIG_MODULES because it has to allocate memory for code. Since code allocations are now implemented with execmem, kprobes can be enabled in non-modular kernels. Add #ifdef CONFIG_MODULE guards for the code dealing with kprobes inside modules, make CONFIG_KPROBES select CONFIG_EXECMEM and drop the dependency of CONFIG_KPROBES on CONFIG_MODULES. Link: https://lkml.kernel.org/r/20230918072955.2507221-13-rppt@kernel.org Signed-off-by: Mike Rapoport (IBM) Cc: Björn Töpel Cc: Catalin Marinas Cc: Christophe Leroy Cc: David S. Miller Cc: Dinh Nguyen Cc: Heiko Carstens Cc: Helge Deller Cc: Huacai Chen Cc: Kent Overstreet Cc: Luis Chamberlain Cc: Mark Rutland Cc: Michael Ellerman Cc: Nadav Amit Cc: "Naveen N. Rao" Cc: Palmer Dabbelt Cc: Puranjay Mohan Cc: Rick Edgecombe Cc: Russell King (Oracle) Cc: Song Liu Cc: Steven Rostedt (Google) Cc: Thomas Bogendoerfer Cc: Thomas Gleixner Cc: Will Deacon Signed-off-by: Andrew Morton --- arch/Kconfig | 2 - kernel/kprobes.c | 43 +++++++++++++++++++--------------- kernel/trace/trace_kprobe.c | 11 ++++++++ 3 files changed, 37 insertions(+), 19 deletions(-) --- a/arch/Kconfig~kprobes-remove-dependency-on-config_modules +++ a/arch/Kconfig @@ -52,9 +52,9 @@ config GENERIC_ENTRY config KPROBES bool "Kprobes" - depends on MODULES depends on HAVE_KPROBES select KALLSYMS + select EXECMEM select TASKS_RCU if PREEMPTION help Kprobes allows you to trap at almost any kernel address and --- a/kernel/kprobes.c~kprobes-remove-dependency-on-config_modules +++ a/kernel/kprobes.c @@ -1580,6 +1580,7 @@ static int check_kprobe_address_safe(str goto out; } +#ifdef CONFIG_MODULES /* Check if 'p' is probing a module. */ *probed_mod = __module_text_address((unsigned long) p->addr); if (*probed_mod) { @@ -1603,6 +1604,8 @@ static int check_kprobe_address_safe(str ret = -ENOENT; } } +#endif + out: preempt_enable(); jump_label_unlock(); @@ -2495,24 +2498,6 @@ int kprobe_add_area_blacklist(unsigned l 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 __weak arch_kprobe_get_kallsym(unsigned int *symnum, unsigned long *value, char *type, char *sym) { @@ -2577,6 +2562,25 @@ static int __init populate_kprobe_blackl 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; @@ -2678,6 +2682,7 @@ static struct notifier_block kprobe_modu .notifier_call = kprobes_module_callback, .priority = 0 }; +#endif void kprobe_free_init_mem(void) { @@ -2737,8 +2742,10 @@ static int __init init_kprobes(void) err = arch_init_kprobes(); if (!err) err = register_die_notifier(&kprobe_exceptions_nb); +#ifdef CONFIG_MODULES if (!err) err = register_module_notifier(&kprobe_module_nb); +#endif kprobes_initialized = (err == 0); kprobe_sysctls_init(); --- a/kernel/trace/trace_kprobe.c~kprobes-remove-dependency-on-config_modules +++ a/kernel/trace/trace_kprobe.c @@ -111,6 +111,7 @@ static nokprobe_inline bool trace_kprobe return strncmp(module_name(mod), name, len) == 0 && name[len] == ':'; } +#ifdef CONFIG_MODULES static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) { char *p; @@ -129,6 +130,12 @@ static nokprobe_inline bool trace_kprobe return ret; } +#else +static inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) +{ + return false; +} +#endif static bool trace_kprobe_is_busy(struct dyn_event *ev) { @@ -670,6 +677,7 @@ end: return ret; } +#ifdef CONFIG_MODULES /* Module notifier call back, checking event on the module */ static int trace_kprobe_module_callback(struct notifier_block *nb, unsigned long val, void *data) @@ -704,6 +712,7 @@ static struct notifier_block trace_kprob .notifier_call = trace_kprobe_module_callback, .priority = 1 /* Invoked after kprobe module callback */ }; +#endif static int __trace_kprobe_create(int argc, const char *argv[]) { @@ -1810,8 +1819,10 @@ static __init int init_kprobe_trace_earl if (ret) return ret; +#ifdef CONFIG_MODULES if (register_module_notifier(&trace_kprobe_module_nb)) return -EINVAL; +#endif return 0; } _ Patches currently in -mm which might be from rppt@kernel.org are nios2-define-virtual-address-space-for-modules.patch mm-introduce-execmem_text_alloc-and-execmem_free.patch mm-execmem-arch-convert-simple-overrides-of-module_alloc-to-execmem.patch mm-execmem-arch-convert-remaining-overrides-of-module_alloc-to-execmem.patch modules-execmem-drop-module_alloc.patch mm-execmem-introduce-execmem_data_alloc.patch arm64-execmem-extend-execmem_params-for-generated-code-allocations.patch riscv-extend-execmem_params-for-generated-code-allocations.patch powerpc-extend-execmem_params-for-kprobes-allocations.patch arch-make-execmem-setup-available-regardless-of-config_modules.patch x86-ftrace-enable-dynamic-ftrace-without-config_modules.patch kprobes-remove-dependency-on-config_modules.patch bpf-remove-config_bpf_jit-dependency-on-config_modules-of.patch