From patchwork Fri Jun 16 08:50:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13282257 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA6E9EB64D7 for ; Fri, 16 Jun 2023 08:53:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 488036B007E; Fri, 16 Jun 2023 04:53:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 410666B0081; Fri, 16 Jun 2023 04:53:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28A246B0082; Fri, 16 Jun 2023 04:53:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 183CC6B007E for ; Fri, 16 Jun 2023 04:53:00 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E2CB51A0C18 for ; Fri, 16 Jun 2023 08:52:59 +0000 (UTC) X-FDA: 80907996078.20.1DFFD15 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id 39A7940010 for ; Fri, 16 Jun 2023 08:52:58 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hYgQUzoC; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686905578; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=n+OjOAbW+AXHS2lVhkLUH6RyxxpJe8lgn6JVSJJU4pY=; b=UdB/y92Lv1ePyX2J0Lqw4k4cFRWVVrXjzd9g9DhgPUjsoZjqwFKS2wZT0szkOmhvprwSgB ApfHtPO++p4hhOo7EtHZtaSlcftKqnQ4+bahL7UjjquMHNLuxD5xsAwyL3vXDQxa6LXNbR h+cj3DcQoKADohAVqNc0jcl0Je9hviU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hYgQUzoC; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686905578; a=rsa-sha256; cv=none; b=l+/geaXw6NiOx6UcAyW9MjS9d+HtJmBzCRM7y3Mt9WMNfJoj3WNi5dicpJ4n4v8cwXbHFj WK9nq3V0IAizz8mXxtRej5Zn9kG6k8i575GMgZnUFC8m2/ZuZYAG7ta2lt7vJ+Wpy9fmlD dKAldOYCvK6P3qP3g7r08N86qCwuq7U= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6FE8F63179; Fri, 16 Jun 2023 08:52:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56BDBC433B7; Fri, 16 Jun 2023 08:52:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686905576; bh=SlBOw3U7lsp9qLHlWO7lhIx8iQG/0zpTGMZK7G5/it8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hYgQUzoC3B593p/Dgn3+TPdeozzDLlm25AwOJLKar+VYJDrbbr1SdOshPlvaqnZ8s oK4MqcxpbnUG6MN7D2/qW05fsNi7mGmQ8dkORzT35xnDbj/W36F4FOLgzNY6M4PcNO R3dJCpZ2E2H3cOtS1aHqXGRpmTKYKqXX++q6sKyIgoNy1Dep39n7ShkhJ3lsnlw8th aR1/N9N5ytcJ2bDrtfUkFPDUA8Szf79x0wrzFCuYoJoIX5C0i1dhO9TiZnBW1OemBT RXhSF4tkazIA43z1geCwwCrTDTs/h4A7kL6naX8kmJ5EqzOEA8QYfISw3S41ve05F0 LFf/ib3wO4hbg== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Luis Chamberlain , Mark Rutland , Michael Ellerman , Mike Rapoport , Nadav Amit , "Naveen N. Rao" , Palmer Dabbelt , Puranjay Mohan , Rick Edgecombe , Russell King , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, netdev@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org Subject: [PATCH v2 12/12] kprobes: remove dependcy on CONFIG_MODULES Date: Fri, 16 Jun 2023 11:50:38 +0300 Message-Id: <20230616085038.4121892-13-rppt@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230616085038.4121892-1-rppt@kernel.org> References: <20230616085038.4121892-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 39A7940010 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: kyw38rfq5bxxhbom4itofesqx5xksufj X-HE-Tag: 1686905578-607780 X-HE-Meta: U2FsdGVkX18kn6X5zuZEDt3XGDVdTKxsmG89UdvE9QjnGLCJiz40VeRZl9XBHO+HdfosxZNmhiumoYvkvJkwjoEaU+KVyL4YHrAvrgZX6qea5LLstTVt2447JCynQNlNd16F0TPAi8aWJcu88NKQQRSS+tThd48zjS+5WI9na+GmnVqI5JZQU7JlH8IKWt9WS8VVsxW/BDOBT9yfW/P3kJ2Ez3b+pPybn4J5sSja+8u+4eL9fFTEzFT4E/CMASP1bffxNjQUw+R0v3+25mAIn/KdNb0T+hBncaSkQh9x21bu9Ne1eDCpjD/gUgLRs7q4DQN74C3m0rcrKFnPZTu1Wi7WF1uxWdUrCFU90OYHIYvcCYqxDVfnlNAn3Ens1cqH3htwxA2wqdkVJJIEHW944uoNtdi0KMe1ILPapOo4/Mq+e9JzC0jbTQPzQfL26I5gsUtb47GWXKsOLcbH1xmAGB4lLvjUNTfFd4nbRLADC1Su1FvLCQR7xmf4oFQPpz3Eks3nORP051I6q1+9x/TcQZRWBvgyFIxOM1fofBPciD3fq2PpH6qVpMrpYtiSZM17QBOpz8Q+GvEMFNwk0R6LvrCCpme3csLrFCNTUyDJPVBQfbi2DmDaTI2k3lM5kay8CgqhXyhSuZhaf30eZ4w5x1QHMO67WjINjpg7AsWW7glXq4LrRhsdVF2C+SgvwsAQ7ZqVvZufOrqe9Pugxmi4CXq6PBmKv/UxdhDviX8faTBTIwBP0CarsEw2V2haGCWfspRECyQJg1P82LKGofhKlkwYuEAAhGlNltE1RB7ycDS6iC1HU/b1zPpnZ01nqrDrSBxmyOOYXixTj61p7h6U1vAuda78OdARTJHDTk4VDAt+d0GvDuFInY6E9ZX5Rrobq9m63LFLts9RqcQcMnNezbDWr/TrU1dtIiJQbrpJhH/Du0kd01U2XAjtKyr3mV9HMQ7qCPqnaGHoAUIk4UH kVvq4sJ8 vbpSC2FsS8uL6VJE/HlyUzq0+LaLeptXnIaToIuaxnns5x9FHOw4uRtMP7u4t2pNZIxjxN6cXw2RLjLJkGxZqF9UyD4J4qKL8z6ap+9OsbtzcnStUi+XtscKBXXxWESCy7vi3gMUEdibGU3RUTGJr+pl1SnV2ps0JJEDPZPTK6hlZsyrnZ6gc+jvoYH0Mh5Hftw0YRbJU2jHsVMQL7c6w3XGRcAgwfA40PcKTHoGFi3lpaDw1xFvIfEhX9FO0PVa2CsOrWb37fLe4N7oEWSo65SSnHMjcxbAYf1X26NeGjH0s1pm2r28sr1u/702o+VDkft84sTtNAVW0k/wx7Qmf9C3qNqMHRCRffzzuvtx8en+qT9TTOUVUVlev2uGdxNx8zpZUrCtQxenVhgS2xqdIfrnyE6oTrsnNj23b818+lYW59aUQumwNASNnx12oJwN88TNVsi6KOuPpfww= 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: From: "Mike Rapoport (IBM)" 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. Signed-off-by: Mike Rapoport (IBM) --- arch/Kconfig | 2 +- kernel/kprobes.c | 43 +++++++++++++++++++++---------------- kernel/trace/trace_kprobe.c | 11 ++++++++++ 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 205fd23e0cad..f2e9f82c7d0d 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -39,9 +39,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 diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 37c928d5deaf..2c2ba29d3f9a 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1568,6 +1568,7 @@ static int check_kprobe_address_safe(struct kprobe *p, goto out; } +#ifdef CONFIG_MODULES /* Check if 'p' is probing a module. */ *probed_mod = __module_text_address((unsigned long) p->addr); if (*probed_mod) { @@ -1591,6 +1592,8 @@ static int check_kprobe_address_safe(struct kprobe *p, ret = -ENOENT; } } +#endif + out: preempt_enable(); jump_label_unlock(); @@ -2484,24 +2487,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 __weak arch_kprobe_get_kallsym(unsigned int *symnum, unsigned long *value, char *type, char *sym) { @@ -2566,6 +2551,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; @@ -2667,6 +2671,7 @@ static struct notifier_block kprobe_module_nb = { .notifier_call = kprobes_module_callback, .priority = 0 }; +#endif void kprobe_free_init_mem(void) { @@ -2726,8 +2731,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(); diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 59cda19a9033..cf804e372554 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -111,6 +111,7 @@ static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk, 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_module_exist(struct trace_kprobe *tk) 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 @@ static int register_trace_kprobe(struct trace_kprobe *tk) 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_kprobe_module_nb = { .notifier_call = trace_kprobe_module_callback, .priority = 1 /* Invoked after kprobe module callback */ }; +#endif static int __trace_kprobe_create(int argc, const char *argv[]) { @@ -1797,8 +1806,10 @@ static __init int init_kprobe_trace_early(void) if (ret) return ret; +#ifdef CONFIG_MODULES if (register_module_notifier(&trace_kprobe_module_nb)) return -EINVAL; +#endif return 0; }