From patchwork Mon Apr 29 12:16:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13646779 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 D2D5EC04FFE for ; Mon, 29 Apr 2024 12:18:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 464986B0092; Mon, 29 Apr 2024 08:18:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 413F96B0093; Mon, 29 Apr 2024 08:18:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3031A6B0095; Mon, 29 Apr 2024 08:18:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 13E136B0092 for ; Mon, 29 Apr 2024 08:18:29 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CE09FA2CDD for ; Mon, 29 Apr 2024 12:18:28 +0000 (UTC) X-FDA: 82062472296.25.3967D33 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf10.hostedemail.com (Postfix) with ESMTP id 8A129C000A for ; Mon, 29 Apr 2024 12:18:26 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="sWk/NDmz"; spf=pass (imf10.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714393107; 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=4DBgWrGRLrMji5A4t9bmWQ2nAQ4rfSDlHheE5nQXccM=; b=8ouhe2bJHY8THtBuUaGPY+1pu8AsLzODe6p05CtEqoUhLnq/cL8hT7o3b6VrFrj2mA3QrV EpCVjTaLyxVoCpWFdnfigNFVVBaWfMNIxWZp3KGa2/7U98jO7To4QRCqp+MlgGzO4eSxJs d3AQe3acNr372rWFLbu9/r4D8F7RqsE= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="sWk/NDmz"; spf=pass (imf10.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714393107; a=rsa-sha256; cv=none; b=k9AioAbwA+uZnv5muTQguItFqiFvqdSiXhrzszUixAtZaluwVIfKQYjoSGY/kc4lSLbiq9 HtL5lY4qpfxf4a1pO6R7Vfhew0QP62F9b5je2LffBUArEyc0QsqX0eOVcnf4GUlAT0dG1G FU3j8OH+uz88zObloawsllZNtmHPYVE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 5768CCE0B5B; Mon, 29 Apr 2024 12:18:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9733C4AF4D; Mon, 29 Apr 2024 12:18:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714393101; bh=Rvc7E+HMMA3ADjVUaU2tKv0yhJenjSe9igrLALIYU0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sWk/NDmz3i5vr9Jv0qDjcUmsYiwDRQThiqhFVVZLqNw47kUEmH6HJt90/yg8TSIAn X8EJF0tdrP3OFzXUlKytIboRy/v+tKau6KDzl9uPY44J6Jea2kq6OssgeiedfE3heY M0LTdSW+l/cScv8edC3m/JOinkVMDAMeESbGhZLm9zyf4sgYNPf9y4P1iaMFoxCnND vmpP6mwHVkZTAqMzRQP8/xQtUuPRQkyg610OXx+F4hllN2VqM9JAkoH61yZltFlFPJ XqHK9UAaIQCm8F+CNnlQHgTMrBZV4LIp55MEtO6e0ArM3BMcNebQO1S7NqiSh5fsw2 ZYASF40QaHGlQ== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 v7 09/16] riscv: extend execmem_params for generated code allocations Date: Mon, 29 Apr 2024 15:16:13 +0300 Message-ID: <20240429121620.1186447-10-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240429121620.1186447-1-rppt@kernel.org> References: <20240429121620.1186447-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 8A129C000A X-Rspamd-Server: rspam06 X-Stat-Signature: zecrkqyqhcza76m13uxktmc7kuwzqb9h X-HE-Tag: 1714393106-881304 X-HE-Meta: U2FsdGVkX1/QpRS4gzSkf0qhJFbjHRPi6i9oGDGaka8dS9e7n8GrXWTHyHg7hS+qqXSRE6KL738iWMMJUgRSwrvrBiPb50U50bnD+sZ5T/418GqvhupTWqqDh0bRjt/fV40nHzGI3kRaBp1ZhtDAE4MS7qHcDzhaPG1d7BvNYvvb09XGC1RCS99JX3dRg7rvtKWwGe6vE9S+LIIFOWGwbggZTgwjwCmGYT7ffByATdEkPvlKyJslcsx5372kPRk1Uczci5GGJrsBpG4XCPYtCrMof2Gu7FfR3CGmJunHcitEzxOOEaZcTQZWp/NFNqxRYe2AVpw+6rn9oNUYikm35BJEX/NvJQd8irpFRRUH7iSJU7iIHgTQAeqSyrJAGn1VMFmql0OSl54D5c4peXrbQy22wUIXPq1rOpkhF+rxAPzI8T9UEMZ0ACUvZluBOAulxofuhRpRvjj0FR8BBcUTPBlDbMbRcdPuoPBSOy1kPycNva5j/E4AEtsBJpZKV5mrIQ9z2nW5VVTAlMhgI4dfcDJTiciH66JIVfXUmfWL2HzTY0Jd3fBNlEz3tj1rRdxu9X1sm7UuCXFrxG6eM+29DGUnNMQawQUxaBQzQRXrdVjWV7vgeDkPTDIMB3vejGrHgESWR2B7AhmqrS0suaXl3Ss5UOCgbdJLD4TZkgvYXKPhxTvtOmueGEGQgZvtZcid7c2EnO78ixjc++xLk1kc42lIR3BaKpQtFhNtlNFPOQ5Jvta73OdhNcOqVdPfFBZt/bigkzSrSC0GA8NQfLryryvnzQWuPOedtR8pwQJiC11fS75Ym9BhH2FFAsu/jnkWBJppfyE9DJbb/Jp4y6M150oWv50PsfEYRef0fFk//sRAV4DGilJSrSE/pm1x29NBBn+5OcfCJOTnVsKvReNkMePNvQM83sHrpza9ebW+3IhgTYxmBfxUleM1/1ud5x2AlRWiTKjR7g8MdvomGQl ppkPguxH NZMWsAvoO+/1hZ342ffgw/pAXMFSIUy1IFyvm4IK8B2RFVbRXZ+y7urxZPKgty+eQ1Ta80NWYxp+RLWe9wN4yBxO4UqOHUf4iggFZjcm3dC2wxZloHlijZIZ2QsOEpAhf+L8BD6NreIKZN6RCbidj1n9i7H7dKHzPtJe74Zy/cXVL7N9H/r00Iw+SRpBf4d6d3LY16dvVKOZ+bw/GtiTXnDE8AYHeG9pnmtqIRdtv/01VCkRPHXTTTm5fV3I84Bajky3rA/g58h3I2HnKsw345EFl9zq1kNVEUBut2DcSnvCJtZVQTOmZviuAIY9OmqTe78pON6nJFUFitJsgF9ZusoC/PdT+HkcfTX2Tf+slbCCQRN4jJoZxVdr6dRCmSMxxIEVokJu3AwYwVkIgQEF5+K7onPzSQE00sy5h 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" The memory allocations for kprobes and BPF on RISC-V are not placed in the modules area and these custom allocations are implemented with overrides of alloc_insn_page() and bpf_jit_alloc_exec(). Define MODULES_VADDR and MODULES_END as VMALLOC_START and VMALLOC_END for 32 bit and slightly reorder execmem_params initialization to support both 32 and 64 bit variants, define EXECMEM_KPROBES and EXECMEM_BPF ranges in riscv::execmem_params and drop overrides of alloc_insn_page() and bpf_jit_alloc_exec(). Signed-off-by: Mike Rapoport (IBM) Reviewed-by: Alexandre Ghiti --- arch/riscv/include/asm/pgtable.h | 3 +++ arch/riscv/kernel/module.c | 14 +++++++++++++- arch/riscv/kernel/probes/kprobes.c | 10 ---------- arch/riscv/net/bpf_jit_core.c | 13 ------------- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 9f8ea0e33eb1..5f21814e438e 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -55,6 +55,9 @@ #define MODULES_LOWEST_VADDR (KERNEL_LINK_ADDR - SZ_2G) #define MODULES_VADDR (PFN_ALIGN((unsigned long)&_end) - SZ_2G) #define MODULES_END (PFN_ALIGN((unsigned long)&_start)) +#else +#define MODULES_VADDR VMALLOC_START +#define MODULES_END VMALLOC_END #endif /* diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 182904127ba0..0e6415f00fca 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -906,7 +906,7 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, return 0; } -#if defined(CONFIG_MMU) && defined(CONFIG_64BIT) +#ifdef CONFIG_MMU static struct execmem_info execmem_info __ro_after_init; struct execmem_info __init *execmem_arch_setup(void) @@ -919,6 +919,18 @@ struct execmem_info __init *execmem_arch_setup(void) .pgprot = PAGE_KERNEL, .alignment = 1, }, + [EXECMEM_KPROBES] = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .pgprot = PAGE_KERNEL_READ_EXEC, + .alignment = 1, + }, + [EXECMEM_BPF] = { + .start = BPF_JIT_REGION_START, + .end = BPF_JIT_REGION_END, + .pgprot = PAGE_KERNEL, + .alignment = PAGE_SIZE, + }, }, }; diff --git a/arch/riscv/kernel/probes/kprobes.c b/arch/riscv/kernel/probes/kprobes.c index 2f08c14a933d..e64f2f3064eb 100644 --- a/arch/riscv/kernel/probes/kprobes.c +++ b/arch/riscv/kernel/probes/kprobes.c @@ -104,16 +104,6 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p) return 0; } -#ifdef CONFIG_MMU -void *alloc_insn_page(void) -{ - return __vmalloc_node_range(PAGE_SIZE, 1, VMALLOC_START, VMALLOC_END, - GFP_KERNEL, PAGE_KERNEL_READ_EXEC, - VM_FLUSH_RESET_PERMS, NUMA_NO_NODE, - __builtin_return_address(0)); -} -#endif - /* install breakpoint in text */ void __kprobes arch_arm_kprobe(struct kprobe *p) { diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c index 6b3acac30c06..e238fdbd5dbc 100644 --- a/arch/riscv/net/bpf_jit_core.c +++ b/arch/riscv/net/bpf_jit_core.c @@ -219,19 +219,6 @@ u64 bpf_jit_alloc_exec_limit(void) return BPF_JIT_REGION_SIZE; } -void *bpf_jit_alloc_exec(unsigned long size) -{ - return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START, - BPF_JIT_REGION_END, GFP_KERNEL, - PAGE_KERNEL, 0, NUMA_NO_NODE, - __builtin_return_address(0)); -} - -void bpf_jit_free_exec(void *addr) -{ - return vfree(addr); -} - void *bpf_arch_text_copy(void *dst, void *src, size_t len) { int ret;