From patchwork Fri Apr 26 08:28:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644231 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 7F882C04FFE for ; Fri, 26 Apr 2024 08:30:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D8A46B00A8; Fri, 26 Apr 2024 04:30:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 060CC6B00A9; Fri, 26 Apr 2024 04:30:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF57A6B00AA; Fri, 26 Apr 2024 04:30:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C0B756B00A8 for ; Fri, 26 Apr 2024 04:30:57 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 786E5140529 for ; Fri, 26 Apr 2024 08:30:57 +0000 (UTC) X-FDA: 82051012554.21.EC001A4 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf16.hostedemail.com (Postfix) with ESMTP id CDD68180006 for ; Fri, 26 Apr 2024 08:30:55 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=TeunQcB9; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf16.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=1714120255; 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=ov+Zy6p+o+MKzsKOdrDu2h5RMDTUryzC1DCfp/0ZOLE=; b=RvOiXO2Dt+CiF/5ZF3IEZaxe1O78a94gY1UUed6LArpn8wf8CbhtSisWPKXisffuaX1LnL w8ZLQYkYhiYyla6/ux+bAReNcGcy+3exHRSlT5pEu8DJ+h8h9f1cXHx13NcZZn+/6A4ue5 kwUvkBc00gSobvHK0MZwbwCFuTTE3Dk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=TeunQcB9; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf16.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=1714120255; a=rsa-sha256; cv=none; b=Qhr/4wklKvKFXBavjFDUzE+etuPbuZVmnz8qeexMN0nwxObfx0wv3DS9C7u0PDewI9SkU2 +HEKZb+BPn9CEtgtAthKTlb7eFcPWmLaTuTtT9HONwpY6kIsyO6YKnSJjhmPrWz6djRiAC Hl5iBPqPhNqpuakRFcmqa78HKAA4I14= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id ED92562002; Fri, 26 Apr 2024 08:30:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F4F7C113CD; Fri, 26 Apr 2024 08:30:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120254; bh=rAIWAHsYUw427kTFrCCQC+4mkWqWWUZB9Zh1fdelySY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TeunQcB9PoWap6KReLYBjiDgwQ8R6NLCJAuYMonr4uIqQ+FDsUYfn+3QUwjES0THO 1olpZ/7FEsdEfyqW/qHnL8WrRHW7bhKWVRyd1ldZENl0wFTnC2tjVvMcsRqdWxQ0NG fOgKCeODWoEr15HF0gdHFTqF7s0R11U9gt/BL+AKAUE6DNfjLjlYSoOzlK5/SA6Ir3 aeEy+WpXsNjpRuCI4xRDKAQ1U1cl9VeCvbKO1szZlW8y1ZaBEW0T55yafFLe0HfOu8 RbNw8r8Ae2+ZkPMkhxCgXpo49Tk8Ol2963PvtEdvl1QII5UPXpu+UcDH08b+AIH1Si RHTXLgzCjPOuA== 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 , 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 v6 09/16] riscv: extend execmem_params for generated code allocations Date: Fri, 26 Apr 2024 11:28:47 +0300 Message-ID: <20240426082854.7355-10-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: CDD68180006 X-Stat-Signature: mdaprta7eeut48k9f88qut6ife1qbhji X-HE-Tag: 1714120255-431737 X-HE-Meta: U2FsdGVkX198NhpgknmA6nML+9+BhnfsL+n068lPH1nBczJB8rP2Q40wkP+Y6HplOIqATYtoayIZ/OEB3pvcFYTRFhdKHh4HNSl2B4bX0M4FSkPDC8O6xS5PApSqvogiw00MsBC5GOhcRbb3kuUAjbVRuK2hVx9kD+lWzz8DugnKZWQG3FW65pzTarUcM4fNSc95nknfQrnoiPGt8fBZqaxvXsojdkfbkNDl6MxGObYauzhGesZqWfZKuCE3xu/6JkHXZIJhqaeWac9FdMXBunOdiCIuWy8uBbf8AuShOKcvwHjIC5pAe+sSavBwSKvVPv85vNrVd4FnFnaHWAhnVmvheLwAyZnBquaQ0ReeWkOeo9QEn788IqB06MkEuCLbMZwMNoj2EExvNM85MVMJRlbwLE6qtKNXsTMiq1QfoTE6JHETlNWMIb+rRa/8GaP6wuYfd8I3AB1OUtMlC2SChEtgpK+PRphaj4tJK6tNTtLRQF6MNcp224vKxxoaWNKjyTlF+CNPc+K59JkIdxUF6lku+ICxVumywaXyUsrvUjPilYqfs+7jGy87rXcreqKXtm8jZXStoSqHUAQ2AO8CmpY6hJPoo4iZOXVun+AC+I2Fg33RvxT9q11QzM7We/giCl1icL0rdu/AntPlLZE5SRc4cP+/aPYLEehYH6s730ooXzZ9yk9xDgyXd4D2C+p5rXA8TXxKH9Lqw+CxkTa6WlrTLeYq5MQwcaGmoQWJq4sZNmt95L91Hi9OKa6jvxG1/ZOL3EWwZWFFhwV1kYwM50bxq1go7BCSxRE4ylzfHGJPt7DJN4A7vROb6eUhYdGKgCF34wYWaDJnr4T6rNd0vbOoqKItYnEfg5L/V9VcbsA9uLcgouej+5+3oQ40xmR5ibyFBO8q5fS/+dBdgtYsV7kolq9D+xehHDneWcSFxxwQhcyB5cNByb9y74KlYDbeTepvcVFU63ADpUDWE00 +OwWe4B+ 8UT8pj+WSY+4xEkRC7xQFbMduorqFh72S6hf5yZv2kRHwHRl+I08tyRIQ8Q55x58QDz6rZiECXsteZWLJTnpRvd6fWvhSBHUKCjwZoLjwRPkoOJ7f+NxbP4mk/vW4ByILLwYVwpgLmep4yrQsA3Po32AqSr61I3Ua4tPNVZHLPpcYHK8m7LzP2l64/DUdZzCZDuDfhDGkWeQQdz5m7jImicG+JLz05qxGoJo/9F4EnuPgODWIpr1g41mfusz9sykKfk5mF/QNnXJbkNZNWVThTgOxrocQPjAmUnO5LMG53wILrnRGCDwy3+Q1vwKnXm7lzvCP9zSaSuith7jIGZRnOm9vA+1rP3m5vr2VEzzlyN8OtKIXjI70aeuc44aJ67DCsxkPgfdyQherHgaJr06WkLobyPC1ouRid9b2sM9XCQx5x3U3ETb2EZHY8DKPJ3Xhoz2wZ0ugLQPUTk1RV5Zf5NitBpXOLMJFnS5t4apvqsrzwr6eqZqNiFcrXw== 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(). 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/kernel/module.c | 28 +++++++++++++++++++++++++--- arch/riscv/kernel/probes/kprobes.c | 10 ---------- arch/riscv/net/bpf_jit_core.c | 13 ------------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 182904127ba0..2ecbacbc9993 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -906,19 +906,41 @@ 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) { + unsigned long start, end; + + if (IS_ENABLED(CONFIG_64BIT)) { + start = MODULES_VADDR; + end = MODULES_END; + } else { + start = VMALLOC_START; + end = VMALLOC_END; + } + execmem_info = (struct execmem_info){ .ranges = { [EXECMEM_DEFAULT] = { - .start = MODULES_VADDR, - .end = MODULES_END, + .start = start, + .end = end, .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;