From patchwork Fri Oct 19 20:47:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 10650187 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0CDBE14E5 for ; Fri, 19 Oct 2018 20:51:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9E3E27FA3 for ; Fri, 19 Oct 2018 20:51:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D94E928451; Fri, 19 Oct 2018 20:51:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 442D827FA3 for ; Fri, 19 Oct 2018 20:51:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=7etnQYcBX2pNZ+qa7bQ70pHPrex1PfpWMqBUNbXLSos=; b=H+vOL3pzpZQq8BDSE/6QNFbrnF HcnLJKVUZmJ2gRa27ELGxkWsQPFC/2KE6+fzX7BBjnJnpTF6nQccTSJ+8fKe7NkaEtT8idIz+jov1 QgR+yBWbgGCRtY5yU70jDHfGfAsxssZbNXLbaVBXn+ccln+nQj2LZoF6Ipk6lkdm3FrAfFjCI0bkZ rpqJRf36VXLzPupdFujxnvmSm2u82qtDINsJpBxpJ5kqDmNYi6jIjnZXiC9PleXtG3MQDpyh6Af8e i6AtGGWdpHmrojC3qHnE69LmR/zPxbF2uYDf9WKp5XYjGP13QH2fp9y4ekSDqE7zwOISlXQYiYehy /uzyhG7Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gDbkH-00067M-GZ; Fri, 19 Oct 2018 20:51:45 +0000 Received: from mga07.intel.com ([134.134.136.100]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gDbjf-0005o2-27 for linux-arm-kernel@lists.infradead.org; Fri, 19 Oct 2018 20:51:09 +0000 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Oct 2018 13:50:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,401,1534834800"; d="scan'208";a="100971842" Received: from rpedgeco-desk5.jf.intel.com ([10.54.75.168]) by orsmga001.jf.intel.com with ESMTP; 19 Oct 2018 13:50:51 -0700 From: Rick Edgecombe To: kernel-hardening@lists.openwall.com, daniel@iogearbox.net, keescook@chromium.org, catalin.marinas@arm.com, will.deacon@arm.com, davem@davemloft.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, arnd@arndb.de, jeyu@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mips@linux-mips.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, jannh@google.com Subject: [PATCH v3 1/3] modules: Create arch versions of module alloc/free Date: Fri, 19 Oct 2018 13:47:21 -0700 Message-Id: <20181019204723.3903-2-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181019204723.3903-1-rick.p.edgecombe@intel.com> References: <20181019204723.3903-1-rick.p.edgecombe@intel.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181019_135107_224512_F802BA87 X-CRM114-Status: GOOD ( 14.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dave.hansen@intel.com, deneen.t.dock@intel.com, Rick Edgecombe , arjan@linux.intel.com, kristen@linux.intel.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In prep for module space rlimit, create a singular cross platform module_alloc and module_memfree that call into arch specific implementations. This has only been tested on x86. Signed-off-by: Rick Edgecombe --- arch/arm/kernel/module.c | 2 +- arch/arm64/kernel/module.c | 2 +- arch/mips/kernel/module.c | 2 +- arch/nds32/kernel/module.c | 2 +- arch/nios2/kernel/module.c | 4 ++-- arch/parisc/kernel/module.c | 2 +- arch/s390/kernel/module.c | 2 +- arch/sparc/kernel/module.c | 2 +- arch/unicore32/kernel/module.c | 2 +- arch/x86/kernel/module.c | 2 +- kernel/module.c | 14 ++++++++++++-- 11 files changed, 23 insertions(+), 13 deletions(-) diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c index 3ff571c2c71c..359838a4bb06 100644 --- a/arch/arm/kernel/module.c +++ b/arch/arm/kernel/module.c @@ -38,7 +38,7 @@ #endif #ifdef CONFIG_MMU -void *module_alloc(unsigned long size) +void *arch_module_alloc(unsigned long size) { gfp_t gfp_mask = GFP_KERNEL; void *p; diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index f0f27aeefb73..a6891eb2fc16 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -30,7 +30,7 @@ #include #include -void *module_alloc(unsigned long size) +void *arch_module_alloc(unsigned long size) { gfp_t gfp_mask = GFP_KERNEL; void *p; diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c index 491605137b03..e9ee8e7544f9 100644 --- a/arch/mips/kernel/module.c +++ b/arch/mips/kernel/module.c @@ -45,7 +45,7 @@ static LIST_HEAD(dbe_list); static DEFINE_SPINLOCK(dbe_lock); #ifdef MODULE_START -void *module_alloc(unsigned long size) +void *arch_module_alloc(unsigned long size) { return __vmalloc_node_range(size, 1, MODULE_START, MODULE_END, GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE, diff --git a/arch/nds32/kernel/module.c b/arch/nds32/kernel/module.c index 1e31829cbc2a..75535daa22a5 100644 --- a/arch/nds32/kernel/module.c +++ b/arch/nds32/kernel/module.c @@ -7,7 +7,7 @@ #include #include -void *module_alloc(unsigned long size) +void *arch_module_alloc(unsigned long size) { return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE, diff --git a/arch/nios2/kernel/module.c b/arch/nios2/kernel/module.c index e2e3f13f98d5..cd059a8e9a7b 100644 --- a/arch/nios2/kernel/module.c +++ b/arch/nios2/kernel/module.c @@ -28,7 +28,7 @@ * from 0x80000000 (vmalloc area) to 0xc00000000 (kernel) (kmalloc returns * addresses in 0xc0000000) */ -void *module_alloc(unsigned long size) +void *arch_module_alloc(unsigned long size) { if (size == 0) return NULL; @@ -36,7 +36,7 @@ void *module_alloc(unsigned long size) } /* Free memory returned from module_alloc */ -void module_memfree(void *module_region) +void arch_module_memfree(void *module_region) { kfree(module_region); } diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c index b5b3cb00f1fb..72ab3c8b103b 100644 --- a/arch/parisc/kernel/module.c +++ b/arch/parisc/kernel/module.c @@ -213,7 +213,7 @@ static inline int reassemble_22(int as22) ((as22 & 0x0003ff) << 3)); } -void *module_alloc(unsigned long size) +void *arch_module_alloc(unsigned long size) { /* using RWX means less protection for modules, but it's * easier than trying to map the text, data, init_text and diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c index d298d3cb46d0..e07c4a9384c0 100644 --- a/arch/s390/kernel/module.c +++ b/arch/s390/kernel/module.c @@ -30,7 +30,7 @@ #define PLT_ENTRY_SIZE 20 -void *module_alloc(unsigned long size) +void *arch_module_alloc(unsigned long size) { if (PAGE_ALIGN(size) > MODULES_LEN) return NULL; diff --git a/arch/sparc/kernel/module.c b/arch/sparc/kernel/module.c index df39580f398d..870581ba9205 100644 --- a/arch/sparc/kernel/module.c +++ b/arch/sparc/kernel/module.c @@ -40,7 +40,7 @@ static void *module_map(unsigned long size) } #endif /* CONFIG_SPARC64 */ -void *module_alloc(unsigned long size) +void *arch_module_alloc(unsigned long size) { void *ret; diff --git a/arch/unicore32/kernel/module.c b/arch/unicore32/kernel/module.c index e191b3448bd3..53ea96459d8c 100644 --- a/arch/unicore32/kernel/module.c +++ b/arch/unicore32/kernel/module.c @@ -22,7 +22,7 @@ #include #include -void *module_alloc(unsigned long size) +void *arch_module_alloc(unsigned long size) { return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, GFP_KERNEL, PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE, diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index f58336af095c..032e49180577 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -77,7 +77,7 @@ static unsigned long int get_module_load_offset(void) } #endif -void *module_alloc(unsigned long size) +void *arch_module_alloc(unsigned long size) { void *p; diff --git a/kernel/module.c b/kernel/module.c index 6746c85511fe..41c22aba8209 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -2110,11 +2110,16 @@ static void free_module_elf(struct module *mod) } #endif /* CONFIG_LIVEPATCH */ -void __weak module_memfree(void *module_region) +void __weak arch_module_memfree(void *module_region) { vfree(module_region); } +void module_memfree(void *module_region) +{ + arch_module_memfree(module_region); +} + void __weak module_arch_cleanup(struct module *mod) { } @@ -2728,11 +2733,16 @@ static void dynamic_debug_remove(struct module *mod, struct _ddebug *debug) ddebug_remove_module(mod->name); } -void * __weak module_alloc(unsigned long size) +void * __weak arch_module_alloc(unsigned long size) { return vmalloc_exec(size); } +void *module_alloc(unsigned long size) +{ + return arch_module_alloc(size); +} + #ifdef CONFIG_DEBUG_KMEMLEAK static void kmemleak_load_module(const struct module *mod, const struct load_info *info)