From patchwork Mon Sep 18 07:29:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13388981 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 ED1D6CD13D1 for ; Mon, 18 Sep 2023 07:32:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 877666B0290; Mon, 18 Sep 2023 03:32:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 827AB6B0292; Mon, 18 Sep 2023 03:32:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C8E26B0294; Mon, 18 Sep 2023 03:32:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5CA616B0290 for ; Mon, 18 Sep 2023 03:32:15 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2877B140BD7 for ; Mon, 18 Sep 2023 07:32:15 +0000 (UTC) X-FDA: 81248899830.05.22A94D8 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id 759DB4002E for ; Mon, 18 Sep 2023 07:32:13 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kT3NctsE; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf27.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=1695022333; 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=dqCPvIMXOTJlhRnOJhYfwq6l5xz7OPueXxaVIBOdmGc=; b=HOABFERSYY+j5/fVjXvfsoYophbC5Vf3unX8Ac8H/QBHLPVIF8ayaS4GhR7C9KXv3jDhT+ hzi+Xj02hc5Zwmwk75vhvNwirxA+2gXSrkKSApWLPAReZVfXPNw4qZpwPQYa+uXd6jgJsF R3nyWiKNl5mGFt//b50Ti0RmiT3VcBk= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=kT3NctsE; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf27.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=1695022333; a=rsa-sha256; cv=none; b=Mp9xNGeeaDRV1ALZRMbggKE82beLy1/51jdPest2ACyIdPGLNC/HqYSYacJfL94Fd9STCg CIijZIDpfVdjotDWF1CFSC1M+yepl1PphVkyn9RwXkg3iHlVvVSeIKhYpkuwAGlneIgMMR wzWTlzflbFaRsiQkPJxmzZP3LV8QtkA= 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 B68D660FA0; Mon, 18 Sep 2023 07:32:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B212CC433A9; Mon, 18 Sep 2023 07:32:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695022331; bh=g2ysQzPrupxvZBEk8R4nz6nGqIwxox2mdTADaK2KSBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kT3NctsEzR46ZMcvQmZYEzpOY6ldmIA+UpjJflzhcN6xMD3eDfrH5TshpxPSzqYKZ 4RtqZhzZqqMGjQFg0TiMJ4pIA+4pgayZMlfPQIIGjFZSqPjnRRF0/SACLSULT/WzJX e5w4J3wzseysRp3HjruUqlEklzGHP8/6ICjr9417gwdOyxSuUT0n9ca5FaDmjgMb4N wh+TlKoXNolf6tuh2rWFnkZ3l88wMsKsT34tZyIMrsdUBBtjJC/AKV44QLF3klepDN XUU8NCM4DCe8D1KxoJHEl8Op3szJMcdX1IE3cH+lAoAp79l+6uCu78MbUgn4aNR/c+ j8TJxIqTZhi6w== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBl?= =?utf-8?b?bA==?= , 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 v3 12/13] kprobes: remove dependency on CONFIG_MODULES Date: Mon, 18 Sep 2023 10:29:54 +0300 Message-Id: <20230918072955.2507221-13-rppt@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918072955.2507221-1-rppt@kernel.org> References: <20230918072955.2507221-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 759DB4002E X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 7kqwe6p5x3ckpr8w9q9yxwa71d1549xp X-HE-Tag: 1695022333-256426 X-HE-Meta: U2FsdGVkX1+BBUlQ/udIjdXmNkoIttxJ8dIhB2SSH5OPzUzAcYc64YmmTc1IDv19R+n4k1N9IrR8fpz9XQCsKR4Di+EBE+A34pBo/La3bAeoY+eqH7KwluAVAzthnAkj1QE/fBWAO0UTTXVsgnpEax5fTSwE6FXo6FzPPX43QqZ/qYsKy9M0StXvmcgchRkI72xEZECu/OdUDnqMqoywfRJAxdFf28lACq4jJovfepmbhEnicv27wEIN9jlj8uVNBm6AGmy2wJoNcTAr8jiJfy3emPx3vltpYMuz8YwNrpPvhxkMqxQBEzIvPvkpcw7rRNTOhZuLn+Uv2aLMzQWFv9esTUNtER8EwfYDK86orEpBISbzuyC/VZQUBxTiinJ3qOkphUtruQA/ZAoWwhnMALVFCt+st3Ye483/rR2NdPUjllZrdHTEIf1PZ+rxUxjfeVlJlFb40GiInCq2Cu60peHCcRSZqudCWnxYCUs1TUuKw21NcDwX4nyUdCcZXoRY0Pt8ur/Geev+LomKaI5gW2JS1/rImnRr5DwnkKubkp2/wXXk/MKBMr7QR/iN1/BR9vPL5Pg6dgg1TfHUoF8M4gar7OXuXKrHSTFhJrn6XFHuoWMyCp0oJ17MYQs4RwYFJlZZLG/wW99ZDYoKS8S+dQMhysXOg651O5/7EGa/0vTiFyE24PzzO89PNL6p4tI/68wUeDY1BaFyA9S8naRUmVR/kDndM5xI+s09rrm98c1Sh4TqcHko/BFWR5XEkcEKW9KkoiuwkiDA3jtYCi7LV7WnegM5d1UTfSj6r8Fo2NIgk6aNhasU4D7LZ6Yv0xIRzjSnhGjaMs71xrTyCHlG2QHNO8HN2xw34YmQS5UuAonO4S+8O5Qvi1NwixPoyvLVgX6qxB02ohnJbCR/jBsrPvCvlIP29R93WGGkIAWuGp30mbiNvKhIyXDDiudXKompAI7D3pQxMU1nbOdwKkE I7LJvSq/ tMzhw/KjCRVfr5KDi94RD0yH2uF9wFaIUb2BbRuuV9z51G7tbXk67NJ9p/eUP2vV7EFf6zVqZe59EWO9mUOfXM2PxjTUxILQTFHrU7IvM1gOyDUwS5w7RzurtT8/Osn7pGbYGGa/8LPQZXEONuBTRcSCbzc/ifDhPSCFcWl/cWjSqbG0+vAMkfHSnPgRleVamFc20ocsFMz+Nl5jGyh78V4XN1TGGiYP9napCwYW4S2LKP1bs4+DW6OIFZjnGDjGx5IBPYR3IkurczsWOyhONR02FrHXNUgIrdK3iFJWkxgYzxHgU1U9miNd3DaR7xztZLf5aWsLNy9Is0tyADTXi5FfskM93r3UN89fpBhDmXvzMDQutRmzH7rB85eg6wYKHoJmk4kWL58WE0OnPtM6OilUbNn4f6sMCs4Cw4rrt1iYajaMSbTCd4dbSKmjO840QuwXi3Asz7Us6/1A= 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 12d51495caec..c52a600b63ca 100644 --- a/arch/Kconfig +++ b/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 diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 0ccb4d2ec9a2..c95d0088f966 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1580,6 +1580,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) { @@ -1603,6 +1604,8 @@ static int check_kprobe_address_safe(struct kprobe *p, ret = -ENOENT; } } +#endif + out: preempt_enable(); jump_label_unlock(); @@ -2495,24 +2498,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) { @@ -2577,6 +2562,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; @@ -2678,6 +2682,7 @@ static struct notifier_block kprobe_module_nb = { .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(); diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 3d7a180a8427..25a5293a80c0 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[]) { @@ -1810,8 +1819,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; }