From patchwork Fri Jul 24 05:05:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 11682025 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 D8AE7138A for ; Fri, 24 Jul 2020 05:06:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AE58E206F0 for ; Fri, 24 Jul 2020 05:06:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE58E206F0 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 C8E148D001D; Fri, 24 Jul 2020 01:06:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C3D2E8D0007; Fri, 24 Jul 2020 01:06:07 -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 B541A8D001D; Fri, 24 Jul 2020 01:06:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id 9F19D8D0007 for ; Fri, 24 Jul 2020 01:06:07 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5D07B1F86B for ; Fri, 24 Jul 2020 05:06:07 +0000 (UTC) X-FDA: 77071782774.18.lift25_151217426f44 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 2B83610053C00 for ; Fri, 24 Jul 2020 05:06:07 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,jarkko.sakkinen@linux.intel.com,,RULES_HIT:30054:30089,0,RBL:134.134.136.24:@linux.intel.com:.lbl8.mailshell.net-62.18.0.100 64.95.201.95;04y87h6r1u967g7wmeko3emzkaynxyphhr4gh6bu6of4k91g5difqqdmh4zr4tx.67hty9ajhnu9pibo84of9ie8xbn1b3x4fixsiwg1rsgjgmqhbk9phonua6dgt1k.k-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: lift25_151217426f44 X-Filterd-Recvd-Size: 4627 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Jul 2020 05:06:06 +0000 (UTC) IronPort-SDR: 5/g+zuTC+mtdg102ZJOoFgXCkJnlFYDKjHTHJsM/12twhBS7kS70KwT+kKJ1vQyM6mbF8jLVG3 hYyNSbO9eniw== X-IronPort-AV: E=McAfee;i="6000,8403,9691"; a="151951825" X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="151951825" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2020 22:06:05 -0700 IronPort-SDR: 7owJROGHpzz36HEmItdzDw0Nw/3DyF5BMdpr4J5OS4IUULuD9RpGDHGje9y10GjxxnbM3VRlJl oN5UfQdTdVQA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="302553454" Received: from itopinsk-mobl1.ccr.corp.intel.com (HELO localhost) ([10.249.36.179]) by orsmga002.jf.intel.com with ESMTP; 23 Jul 2020 22:05:59 -0700 From: Jarkko Sakkinen To: linux-kernel@vger.kernel.org Cc: Jarkko Sakkinen , linux-mm@kvack.org, Andi Kleen , Peter Zijlstra , Masami Hiramatsu , Jessica Yu , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Steven Rostedt , Ingo Molnar Subject: [PATCH v5 1/6] kprobes: Remove dependency to the module_mutex Date: Fri, 24 Jul 2020 08:05:48 +0300 Message-Id: <20200724050553.1724168-2-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: 2B83610053C00 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: Add lock_modules() and unlock_modules() wrappers for acquiring module_mutex in order to remove the compile time dependency to it. Cc: linux-mm@kvack.org Cc: Andi Kleen Cc: Peter Zijlstra Suggested-by: Masami Hiramatsu Signed-off-by: Jarkko Sakkinen Signed-off-by: Masami Hiramatsu --- include/linux/module.h | 18 ++++++++++++++++++ kernel/kprobes.c | 4 ++-- kernel/trace/trace_kprobe.c | 4 ++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 2e6670860d27..8850b9692b8f 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -705,6 +705,16 @@ static inline bool is_livepatch_module(struct module *mod) bool is_module_sig_enforced(void); void set_module_sig_enforced(void); +static inline void lock_modules(void) +{ + mutex_lock(&module_mutex); +} + +static inline void unlock_modules(void) +{ + mutex_unlock(&module_mutex); +} + #else /* !CONFIG_MODULES... */ static inline struct module *__module_address(unsigned long addr) @@ -852,6 +862,14 @@ void *dereference_module_function_descriptor(struct module *mod, void *ptr) return ptr; } +static inline void lock_modules(void) +{ +} + +static inline void unlock_modules(void) +{ +} + #endif /* CONFIG_MODULES */ #ifdef CONFIG_SYSFS diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 2e97febeef77..4e46d96d4e16 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -564,7 +564,7 @@ static void kprobe_optimizer(struct work_struct *work) cpus_read_lock(); mutex_lock(&text_mutex); /* Lock modules while optimizing kprobes */ - mutex_lock(&module_mutex); + lock_modules(); /* * Step 1: Unoptimize kprobes and collect cleaned (unused and disarmed) @@ -589,7 +589,7 @@ static void kprobe_optimizer(struct work_struct *work) /* Step 4: Free cleaned kprobes after quiesence period */ do_free_cleaned_kprobes(); - mutex_unlock(&module_mutex); + unlock_modules(); mutex_unlock(&text_mutex); cpus_read_unlock(); diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index aefb6065b508..710ec6a6aa8f 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -122,9 +122,9 @@ static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) if (!p) return true; *p = '\0'; - mutex_lock(&module_mutex); + lock_modules(); ret = !!find_module(tk->symbol); - mutex_unlock(&module_mutex); + unlock_modules(); *p = ':'; return ret; From patchwork Fri Jul 24 05:05:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 11682027 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 E905213B1 for ; Fri, 24 Jul 2020 05:06:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BA333206F0 for ; Fri, 24 Jul 2020 05:06:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA333206F0 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 07FBE8D001E; Fri, 24 Jul 2020 01:06:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 030108D0007; Fri, 24 Jul 2020 01:06:12 -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 E890E8D001E; Fri, 24 Jul 2020 01:06:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0074.hostedemail.com [216.40.44.74]) by kanga.kvack.org (Postfix) with ESMTP id D18368D0007 for ; Fri, 24 Jul 2020 01:06:12 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 985FE20BDF for ; Fri, 24 Jul 2020 05:06:12 +0000 (UTC) X-FDA: 77071782984.14.roof92_521842b26f44 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 6D9381807D7DD for ; Fri, 24 Jul 2020 05:06:12 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,jarkko.sakkinen@linux.intel.com,,RULES_HIT:30012:30054,0,RBL:192.55.52.43:@linux.intel.com:.lbl8.mailshell.net-62.18.0.100 64.95.201.95;04yroanatjgwsyf91wdewczok9ghgyptek3rscscp6cp7wg1nta8qiwkxx9f4xb.hdn988swtas8y54dk7d5xswm5uuuwd9w1ru64csdghom78figp3xyeshm1rmp9n.y-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:25,LUA_SUMMARY:none X-HE-Tag: roof92_521842b26f44 X-Filterd-Recvd-Size: 3103 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Jul 2020 05:06:11 +0000 (UTC) IronPort-SDR: hS6ZAikfBy541JnqdXksk4HC/hfPD7IEFZBsf5taBk6G1Tnz1KfNCyezoQrR4wyIYG+i3oo/Vl m6PbE/kCoQJg== X-IronPort-AV: E=McAfee;i="6000,8403,9691"; a="235538607" X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="235538607" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2020 22:06:10 -0700 IronPort-SDR: d4ms3xYCS47v748dTz8/hUkyD8ft8SyA2gI/KqU1nQ7NJMZNfTmvRlE4ns0yuPSbBWE/XDs919 NjVEtUrPPhZw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="288879310" Received: from itopinsk-mobl1.ccr.corp.intel.com (HELO localhost) ([10.249.36.179]) by orsmga006.jf.intel.com with ESMTP; 23 Jul 2020 22:06:07 -0700 From: Jarkko Sakkinen To: linux-kernel@vger.kernel.org Cc: Jarkko Sakkinen , linux-mm@kvack.org, Andi Kleen , Masami Hiramatsu , Peter Zijlstra , Andrew Morton Subject: [PATCH v5 2/6] vmalloc: Add text_alloc() and text_free() Date: Fri, 24 Jul 2020 08:05:49 +0300 Message-Id: <20200724050553.1724168-3-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: 6D9381807D7DD X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: Introduce functions for allocating memory for dynamic trampolines, such as kprobes. An arch can promote the availability of these functions with CONFIG_ARCH_HAS_TEXT_ALLOC. Cc: linux-mm@kvack.org Cc: Andi Kleen Cc: Masami Hiramatsu Suggested-by: Peter Zijlstra Signed-off-by: Jarkko Sakkinen --- include/linux/vmalloc.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 0221f852a7e1..6c151a0ac02a 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -249,4 +249,21 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms) int register_vmap_purge_notifier(struct notifier_block *nb); int unregister_vmap_purge_notifier(struct notifier_block *nb); +/* + * These functions can be optionally implemented by an arch in order to + * provide specialized functions for allocating trampoline code. + */ + +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC +/* + * Allocate memory to be used for trampoline code. + */ +void *text_alloc(unsigned long size); + +/* + * Free memory returned from text_alloc(). + */ +void text_free(void *region); +#endif /* CONFIG_ARCH_HAS_TEXT_ALLOC */ + #endif /* _LINUX_VMALLOC_H */ From patchwork Fri Jul 24 05:05:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 11682031 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 5D34C13B1 for ; Fri, 24 Jul 2020 05:06:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 337AC206F0 for ; Fri, 24 Jul 2020 05:06:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 337AC206F0 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 75DAC8D0020; Fri, 24 Jul 2020 01:06:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 734928D0007; Fri, 24 Jul 2020 01:06:25 -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 672B58D0020; Fri, 24 Jul 2020 01:06:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0173.hostedemail.com [216.40.44.173]) by kanga.kvack.org (Postfix) with ESMTP id 55FA18D0007 for ; Fri, 24 Jul 2020 01:06:25 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1A58B181A8DB5 for ; Fri, 24 Jul 2020 05:06:25 +0000 (UTC) X-FDA: 77071783530.03.pigs35_2309cca26f44 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id DE5DA2ADBA for ; Fri, 24 Jul 2020 05:06:24 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,jarkko.sakkinen@linux.intel.com,,RULES_HIT:30012:30054:30067:30069:30090,0,RBL:134.134.136.24:@linux.intel.com:.lbl8.mailshell.net-64.95.201.95 62.18.0.100;04ygyy89u4ja798c93tsucxmdfkhjyph37hjkxuajwkfekptanjuw98b4gd186i.wdzutx3dt4dz8snifisk533wkkq41gq43ntki7fpwhbixjc5m6tezyjytwjsc4j.n-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:23,LUA_SUMMARY:none X-HE-Tag: pigs35_2309cca26f44 X-Filterd-Recvd-Size: 4663 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Jul 2020 05:06:24 +0000 (UTC) IronPort-SDR: pMhJPavC7rj2ziUb6TaF5vyYTuST98BUBWiztXImdp6zXdfpB1kgk43DIX2sZDRljbp4/rKHem 3OEzN9/52MMg== X-IronPort-AV: E=McAfee;i="6000,8403,9691"; a="151951844" X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="151951844" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2020 22:06:22 -0700 IronPort-SDR: BpTQBF3s9QZc6iS4k6nuvNMFVTnO2nOQYYAfzwrnWN2LVf1K+TP6Hgz4b6S7DxVMszefEQ/ShD 2veaIvsrlLfg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="432970161" 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:15 -0700 From: Jarkko Sakkinen To: linux-kernel@vger.kernel.org Cc: Jarkko Sakkinen , linux-mm@kvack.org, Masami Hiramatsu , Andi Kleen , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , Andy Lutomirski , "Paul E. McKenney" , Marco Elver , Babu Moger , Brian Gerst , Nayna Jain Subject: [PATCH v5 3/6] arch/x86: Implement text_alloc() and text_free() Date: Fri, 24 Jul 2020 08:05:50 +0300 Message-Id: <20200724050553.1724168-4-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: DE5DA2ADBA X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: Implement text_alloc() and text_free() with with the vmalloc API. These can be used to allocate pages for trampoline code without relying on the module loader code. Cc: linux-mm@kvack.org Cc: Masami Hiramatsu Cc: Andi Kleen Suggested-by: Peter Zijlstra Signed-off-by: Jarkko Sakkinen --- arch/x86/Kconfig | 3 +++ arch/x86/kernel/Makefile | 1 + arch/x86/kernel/text_alloc.c | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 arch/x86/kernel/text_alloc.c diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 0dea7fdd7a00..a4ee5d1300f6 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -2035,6 +2035,9 @@ config KEXEC_FILE config ARCH_HAS_KEXEC_PURGATORY def_bool KEXEC_FILE +config ARCH_HAS_TEXT_ALLOC + def_bool y + config KEXEC_SIG bool "Verify kernel signature during kexec_file_load() syscall" depends on KEXEC_FILE diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index e77261db2391..fa1415424ae3 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -68,6 +68,7 @@ obj-y += tsc.o tsc_msr.o io_delay.o rtc.o obj-y += pci-iommu_table.o obj-y += resource.o obj-y += irqflags.o +obj-y += text_alloc.o obj-y += process.o obj-y += fpu/ diff --git a/arch/x86/kernel/text_alloc.c b/arch/x86/kernel/text_alloc.c new file mode 100644 index 000000000000..f31c2d82c258 --- /dev/null +++ b/arch/x86/kernel/text_alloc.c @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Kernel module help for x86. + * Copyright (C) 2001 Rusty Russell. + */ + +#include +#include +#include +#include +#include + +void *text_alloc(unsigned long size) +{ + void *p; + + if (PAGE_ALIGN(size) > MODULES_LEN) + return NULL; + + p = __vmalloc_node_range(size, MODULE_ALIGN, MODULES_VADDR, MODULES_END, + GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE, + __builtin_return_address(0)); + + if (p && (kasan_module_alloc(p, size) < 0)) { + vfree(p); + return NULL; + } + + return p; +} + +void text_free(void *region) +{ + /* + * This memory may be RO, and freeing RO memory in an interrupt is not + * supported by vmalloc. + */ + lockdep_assert_irqs_enabled(); + + vfree(region); +} From patchwork Fri Jul 24 05:05:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 11682039 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 4325413B1 for ; Fri, 24 Jul 2020 05:07:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1086F206F0 for ; Fri, 24 Jul 2020 05:07:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1086F206F0 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 5AF888D0024; Fri, 24 Jul 2020 01:07:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 55F388D0007; Fri, 24 Jul 2020 01:07:56 -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 427C78D0024; Fri, 24 Jul 2020 01:07:56 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0215.hostedemail.com [216.40.44.215]) by kanga.kvack.org (Postfix) with ESMTP id 27A568D0007 for ; Fri, 24 Jul 2020 01:07:56 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id DC4B7181A8DB5 for ; Fri, 24 Jul 2020 05:07:55 +0000 (UTC) X-FDA: 77071787310.20.moon35_11176bc26f44 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 2E09C1808CDDC for ; Fri, 24 Jul 2020 05:06:34 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,jarkko.sakkinen@linux.intel.com,,RULES_HIT:30054,0,RBL:134.134.136.100:@linux.intel.com:.lbl8.mailshell.net-64.95.201.95 62.18.0.100;04y895swytj96cnya7xodo7en6nsoopmxp5tgfdioumfdtnxxqzn6as5u7z4brx.wjn99z4enc8n5r8syouxj81jad97df7f3aecoxana37ig58xfdyczmxqg6jrmsp.o-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: moon35_11176bc26f44 X-Filterd-Recvd-Size: 3130 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Jul 2020 05:06:33 +0000 (UTC) IronPort-SDR: osEU5h3pJVVMJv/Bgs3NcAU0K9PpFrMD3mtxneSx6tgFQH2Dqch4tjLYyHdMHhtducET38XaMD MpO9Hp2ePhMA== X-IronPort-AV: E=McAfee;i="6000,8403,9691"; a="215249800" X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="215249800" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2020 22:06:32 -0700 IronPort-SDR: gKq9JMMfAB1WTxb1B75Tr/Y0+VWnZYl7rXeqRKzkcyBP5cyyEa9WGOlGd4Xw57NlUJVfrBbHUQ TREnjshwbUrQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="432970174" 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:25 -0700 From: Jarkko Sakkinen To: linux-kernel@vger.kernel.org Cc: Jarkko Sakkinen , linux-mm@kvack.org, Andi Kleen , Masami Hiramatsu , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , Andrew Morton , "Steven Rostedt (VMware)" , Mike Rapoport , Jiri Olsa Subject: [PATCH v5 4/6] arch/x86: kprobes: Use text_alloc() and text_free() Date: Fri, 24 Jul 2020 08:05:51 +0300 Message-Id: <20200724050553.1724168-5-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: 2E09C1808CDDC X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: Use text_alloc() and text_free() to implement alloc_insn_page() and free_insn_page(). Cc: linux-mm@kvack.org Cc: Andi Kleen Cc: Masami Hiramatsu Cc: Peter Zijlstra Signed-off-by: Jarkko Sakkinen Im --- arch/x86/kernel/kprobes/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index ada39ddbc922..9e57452b3a51 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -423,7 +423,7 @@ void *alloc_insn_page(void) { void *page; - page = module_alloc(PAGE_SIZE); + page = text_alloc(PAGE_SIZE); if (!page) return NULL; @@ -446,7 +446,7 @@ void *alloc_insn_page(void) /* Recover page to RW mode before releasing it */ void free_insn_page(void *page) { - module_memfree(page); + text_free(page); } static int arch_copy_kprobe(struct kprobe *p) From patchwork Fri Jul 24 05:05:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 11682035 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 E4C66138C for ; Fri, 24 Jul 2020 05:07:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B8AD9206F0 for ; Fri, 24 Jul 2020 05:07:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8AD9206F0 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 00A588D0022; Fri, 24 Jul 2020 01:07:01 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id ED5848D0007; Fri, 24 Jul 2020 01:07:00 -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 DC4FF8D0022; Fri, 24 Jul 2020 01:07:00 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0138.hostedemail.com [216.40.44.138]) by kanga.kvack.org (Postfix) with ESMTP id C24B78D0007 for ; Fri, 24 Jul 2020 01:07:00 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 872288248047 for ; Fri, 24 Jul 2020 05:07:00 +0000 (UTC) X-FDA: 77071785000.29.wave64_280573e26f44 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 83C2C1803016B for ; Fri, 24 Jul 2020 05:06:40 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,jarkko.sakkinen@linux.intel.com,,RULES_HIT:30054,0,RBL:192.55.52.93:@linux.intel.com:.lbl8.mailshell.net-64.95.201.95 62.18.0.100;04y8ptaanxxbaioruzpr4hnu616icyp5a8c67q9phhrwxw3aqco86kppe5m9q61.iykcqqsgt5bo1wnam5cpb4qsi79kxjejg73pbko9db6r1h99xk4qt3ipp8kbaht.1-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: wave64_280573e26f44 X-Filterd-Recvd-Size: 3049 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Jul 2020 05:06:39 +0000 (UTC) IronPort-SDR: 48yO1t/3SaWvOOwDajac4z+G3aqbsDWP81cSXaXCim6k4Oc2vhPUmt2pYsJ1iCNVJEIpbZWif/ Ljc7E+8WdZRQ== X-IronPort-AV: E=McAfee;i="6000,8403,9691"; a="148578055" X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="148578055" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2020 22:06:38 -0700 IronPort-SDR: Y745JBr6aV5Cuf4jsX3nKNPk6MjsigD/X68qgg7p4Wds3octHlH+g1sNv9NhVt3hjgBoYUFMjd TFgDaLoCIY0w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="432970205" 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:34 -0700 From: Jarkko Sakkinen To: linux-kernel@vger.kernel.org Cc: Jarkko Sakkinen , linux-mm@kvack.org, Andi Kleen , Masami Hiramatsu , Peter Zijlstra , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" Subject: [PATCH v5 5/6] kprobes: Use text_alloc() and text_free() Date: Fri, 24 Jul 2020 08:05:52 +0300 Message-Id: <20200724050553.1724168-6-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: 83C2C1803016B X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: Use text_alloc() and text_free() instead of module_alloc() and module_memfree() when an arch provides them. Cc: linux-mm@kvack.org Cc: Andi Kleen Cc: Masami Hiramatsu Cc: Peter Zijlstra Signed-off-by: Jarkko Sakkinen --- kernel/kprobes.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 4e46d96d4e16..611fcda9f6bf 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -40,6 +40,7 @@ #include #include #include +#include #define KPROBE_HASH_BITS 6 #define KPROBE_TABLE_SIZE (1 << KPROBE_HASH_BITS) @@ -111,12 +112,20 @@ enum kprobe_slot_state { void __weak *alloc_insn_page(void) { +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC + return text_alloc(PAGE_SIZE); +#else return module_alloc(PAGE_SIZE); +#endif } void __weak free_insn_page(void *page) { +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC + text_free(page); +#else module_memfree(page); +#endif } struct kprobe_insn_cache kprobe_insn_slots = { 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);