From patchwork Sun May 5 14:25:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654320 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 E88D6C4345F for ; Sun, 5 May 2024 14:28:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 889646B00A0; Sun, 5 May 2024 10:28:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8614E6B00A1; Sun, 5 May 2024 10:28:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7502B6B00A2; Sun, 5 May 2024 10:28:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 575886B00A0 for ; Sun, 5 May 2024 10:28:13 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CDF231401BF for ; Sun, 5 May 2024 14:28:12 +0000 (UTC) X-FDA: 82084572024.14.F27D9EF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id 3E655120007 for ; Sun, 5 May 2024 14:28:11 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=sZBNbgqZ; spf=pass (imf29.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 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=1714919291; 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=Z+DKxu/RxmswMLvlQUnHFrB1qdjK5/llzcSNffn9s0AWjEYJ3rn1LTUkSIJ6QI6iIw1DNf RncJeiM3E3XvWH4WJkMu2l+Sgo7fyrxU0tY0xDwmD9KtUHWPVnZcoPLRFJQ8G9HgaNcwnN ZqX2G0EpbmCwJM4GaMir0x5lLEmKUJQ= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=sZBNbgqZ; spf=pass (imf29.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 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=1714919291; a=rsa-sha256; cv=none; b=tzWm3YxekLs3zxkodmjsPGaD62D5W5yOPB4gSZhQCdx4Bhc/B3EoUBEcsa3EqBspySBld3 a1aMVebm5Y2ZK6cVg4wnNaWAKd7kKG0x1C0rd5b9zRR45Qbor2fnOeyCO5EXAgDakU8ajq Mc0zSpc1elf+JgH4VFDCFg+Q/+sKjb8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 8166160C86; Sun, 5 May 2024 14:28:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8C15C4DDE5; Sun, 5 May 2024 14:27:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714919290; bh=Rvc7E+HMMA3ADjVUaU2tKv0yhJenjSe9igrLALIYU0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sZBNbgqZM8fTpMpBIBBoIMNevcLneOWz+UMMuh5HD7Hvyw9pJcz9NSX7Wij/nV9xL FtyRL9b/dN++XMHIoZNxaO4GQuW0VU6rNLHqyyl84qxvOPYK29X0F47LMEwWU8sF4A x9UZbUS0hTu1I8D3OWYGcsxjD39bntUTvR0tofqfQlPU4AsCyZ62yE+AwEfyfv/P7K 45ZZqBubHl+xUs4uvKql4FjTbOwrVDDFHgGPcgdZUNlZaYGaKxY5t9crBYuWtEI0VN thOvqqdmcv3ghDx/TpyAKkcVarp8ljHwhRscC474CnsGiuV5nPh1lZuZ7pduWhc6l8 tnGnCtCNfFB9g== 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 , Liviu Dudau , 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 v8 09/17] riscv: extend execmem_params for generated code allocations Date: Sun, 5 May 2024 17:25:52 +0300 Message-ID: <20240505142600.2322517-10-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505142600.2322517-1-rppt@kernel.org> References: <20240505142600.2322517-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 3E655120007 X-Rspamd-Server: rspam06 X-Stat-Signature: 4ibz5hr6awnqgzaoh88z3ytjbqd6bjwb X-HE-Tag: 1714919291-744103 X-HE-Meta: U2FsdGVkX18NfGx/ujUphGK9VOV+diBDh1c0gDwgAvG2Kqx0cmLjt9Lu+YUVukKb9/rLSgatUdVRSpqjdF2kWVRJ4sZGmgz7e+xULOEJoLMpJ/fZ3oMQ+C8hMl5a2ofq7AKLden0ua271Ijoqx+gEjeJ1WzeOGJVD/e15h9dnIWA+2r5TNRwX63ek/mS6N354rwMj98hrYlbs9NheJKeFyuEmKve06ivqKw69imTVsi+NPaDOkOsuIILR3JpWfVg3W9XCGS3O/2Nuz2VoV0HNOfVRxkedJ8IPKZBOmkbVeSq0UNFrIe0lphQD8j88uLAu4n0Z6C7rFUL/rcTiYQUV8GoGSXZ6MRSY2YwuL4qcN1RSIse8QivBfkIkg+QWFmrYPbs84FEELK+TjUohqNSNtyUXbAv0u1OzgRsOkE6Tr1JfPEs/bZ3wsdZ7QlHHRYvk3zvreddeVVUjHjbVT/XnRRQKYw7ObxJc1TXNMTEFdBENyJsxIXZ1rh8HgxX7WpYVMmBJUazi/3+K6RARciTsiCIP3tyKDh5rl0C8U+++MgvYwYcyBaK1Pg5n4aBtclGYyFzQYDOxhEbGZe585q8+2MLQI4VAjnNlkWi2QjaOnGN2slTTeGn7zyhgY73uJQHRtWAhFKvkVQlJUiF0V/S9inZxZTNZ4W7uAIuWZSzHLFn6TFVi9WG8Pbr0h/qBE+SWzUq+XHKYMR7f74PuSye+JqJdAfb4gd8isCPgnBIOwxD+khdwwpeavVpDKWg7FgklW9mDdOWa1io0iFQ59iv0ZQ7+gcfeDOXm/SZTHKY5dih+Xh95oLI0zTv2SZ6AeHRqVu0SRZPrxSNiiU2bBcqSlACQ0jDVjpZhMOQyajl77G0YST18wBfr9ttelJrlgrn4oXXdG0cnJ/zh5psjVImQXirGayUCmDWMpkjhqhJjqiFZ+olCk5qHJ8z5O3bHL0uon+xj5ezjHpIc6yVgGz mZEETeCf 3/m/HgsL661eTXJIMREawy/LxpMSIsol9mHScl7IDKt1abIpVxxqapZFGsKDuufJbsslxtVUIVFD0qm/Za9C9FLs1lyAEjX/E3N1tddM4dQlqMUfXWPbOpLElGzEP+l+mlJabl/Ms0F3i7DnnXsGMe4i0VCGGhmThydW6eZAIIGcxuBxiIFMeyuovWqcFEZZfa7eQTggyZpxquX4BxcxvJ51btHtpM5+tpyyeWlMzpdd6zJ6udTsNrIgj76Yfs8o5R4JSWx6BIjvV+A3DsYv4kviNjvfw4Ods9h7wUQbP1LZsKDWYfKmxr1YAjay6OcU135TtU7H1dB9bbOL2Ps61sM+xbyXPxoUbvKEc8qiBdEPd+97//AtDWrZD0+tXoHvzFe86z8mGph6R/+6MrHR3R1S+fMENVZO0Gt3WW6RwAKS1cq4= 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;