From patchwork Fri Jul 24 05:04:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 11682023 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 EF474159A for ; Fri, 24 Jul 2020 05:05:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BB63220714 for ; Fri, 24 Jul 2020 05:05:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB63220714 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 11D198D001C; Fri, 24 Jul 2020 01:05:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0CE148D0007; Fri, 24 Jul 2020 01:05:18 -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 F24B48D001C; Fri, 24 Jul 2020 01:05:17 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0082.hostedemail.com [216.40.44.82]) by kanga.kvack.org (Postfix) with ESMTP id DD21D8D0007 for ; Fri, 24 Jul 2020 01:05:17 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9E34D13E89 for ; Fri, 24 Jul 2020 05:05:17 +0000 (UTC) X-FDA: 77071780674.09.head77_1f0b50626f44 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 72B5E180691A0 for ; Fri, 24 Jul 2020 05:05:17 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,jarkko.sakkinen@linux.intel.com,,RULES_HIT:30054:30089,0,RBL:134.134.136.65:@linux.intel.com:.lbl8.mailshell.net-64.95.201.95 62.18.0.100;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:25,LUA_SUMMARY:none X-HE-Tag: head77_1f0b50626f44 X-Filterd-Recvd-Size: 4627 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Jul 2020 05:05:16 +0000 (UTC) IronPort-SDR: V2s1uDEHYrdVr2B4BLq1PgC9SKa9xEUXsYgX9pHF0+3ZHkGzveI6vrguelUye2tSlfLdF0CxUl JIVWksvKCl5A== X-IronPort-AV: E=McAfee;i="6000,8403,9691"; a="150645707" X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="150645707" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2020 22:05:14 -0700 IronPort-SDR: fwZRTobzmQpzUlmLRedOJhXoZ3qvV74pep3Scq0sn0GbOgaln93ZjCNH0qOHrEwoohaB+8b+c2 pWXkRhH72SYA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="302553089" 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:08 -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:04:55 +0300 Message-Id: <20200724050501.1723315-2-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200724050501.1723315-1-jarkko.sakkinen@linux.intel.com> References: <20200724050501.1723315-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 72B5E180691A0 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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 --- 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:04:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 11682029 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 33E31138A for ; Fri, 24 Jul 2020 05:06:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 09498206F6 for ; Fri, 24 Jul 2020 05:06:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 09498206F6 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 478CF8D001F; Fri, 24 Jul 2020 01:06:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 427E78D0007; Fri, 24 Jul 2020 01:06:18 -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 364918D001F; Fri, 24 Jul 2020 01:06:18 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0143.hostedemail.com [216.40.44.143]) by kanga.kvack.org (Postfix) with ESMTP id 21E588D0007 for ; Fri, 24 Jul 2020 01:06:18 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E0D881801FFE2 for ; Fri, 24 Jul 2020 05:06:17 +0000 (UTC) X-FDA: 77071783194.11.sound29_240f15126f44 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id D8EE918033E53 for ; Fri, 24 Jul 2020 05:05:18 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,jarkko.sakkinen@linux.intel.com,,RULES_HIT:30012:30054,0,RBL:134.134.136.65:@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:23,LUA_SUMMARY:none X-HE-Tag: sound29_240f15126f44 X-Filterd-Recvd-Size: 3105 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Jul 2020 05:05:18 +0000 (UTC) IronPort-SDR: szi6S2zGjenlOK8xxVY8OugQwXrg+gOFeAkc6z8SBSk+/PHUwVx9VSGMHWltsDfFSVhyWUDN4s W0x34FlFvTJQ== X-IronPort-AV: E=McAfee;i="6000,8403,9691"; a="150645715" X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="150645715" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2020 22:05:18 -0700 IronPort-SDR: qY/icntTHNX8zoRFkoNoJ9PavRZVse1JH+1/o2alo5VC1HFLRyNHZrsE1xfYPp1L/E2n4a6MXl Bw89swfNwqww== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="302553101" 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:15 -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:04:56 +0300 Message-Id: <20200724050501.1723315-3-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200724050501.1723315-1-jarkko.sakkinen@linux.intel.com> References: <20200724050501.1723315-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: D8EE918033E53 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: 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:04:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 11682033 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 0E543138C for ; Fri, 24 Jul 2020 05:06:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D56E120737 for ; Fri, 24 Jul 2020 05:06:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D56E120737 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 207D88D0021; Fri, 24 Jul 2020 01:06:51 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 190588D0007; Fri, 24 Jul 2020 01:06:51 -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 057A08D0021; Fri, 24 Jul 2020 01:06:50 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0071.hostedemail.com [216.40.44.71]) by kanga.kvack.org (Postfix) with ESMTP id DF44D8D0007 for ; Fri, 24 Jul 2020 01:06:50 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id AC37422C09 for ; Fri, 24 Jul 2020 05:06:50 +0000 (UTC) X-FDA: 77071784580.12.root11_2a1322c26f44 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 6CD55180454FA for ; Fri, 24 Jul 2020 05:05:34 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,jarkko.sakkinen@linux.intel.com,,RULES_HIT:30012:30054:30067:30069:30090,0,RBL:192.55.52.43:@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:25,LUA_SUMMARY:none X-HE-Tag: root11_2a1322c26f44 X-Filterd-Recvd-Size: 4695 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Jul 2020 05:05:33 +0000 (UTC) IronPort-SDR: 8YsTI7mv7KpFMTCIC63Dd2C8MwVoTShXVBxFC9TM/QF6C8PCBFStbhuZ7Ljfo5i1Jnczn1OAD+ hXoiQ/+gx0Tg== X-IronPort-AV: E=McAfee;i="6000,8403,9691"; a="235538567" X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="235538567" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2020 22:05:31 -0700 IronPort-SDR: FxIvEMr0VQstUo688TaoH7q9kyNYHCyZJgcCSuv1J8SKcwm2cz5knGFhZivT5JLVpbetc4YIXy liasXZaTbPdA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,389,1589266800"; d="scan'208";a="302553164" 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:24 -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" , Nayna Jain , Omar Sandoval , Brian Gerst , Marco Elver , Babu Moger Subject: [PATCH v5 3/6] arch/x86: Implement text_alloc() and text_free() Date: Fri, 24 Jul 2020 08:04:57 +0300 Message-Id: <20200724050501.1723315-4-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200724050501.1723315-1-jarkko.sakkinen@linux.intel.com> References: <20200724050501.1723315-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6CD55180454FA 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); +}