From patchwork Sun May 5 16:06:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654471 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 821E7C4345F for ; Sun, 5 May 2024 16:08:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D8B56B009D; Sun, 5 May 2024 12:08:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18A066B009E; Sun, 5 May 2024 12:08:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 029BC6B009F; Sun, 5 May 2024 12:08:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D88D16B009D for ; Sun, 5 May 2024 12:08:37 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 960061C0AD9 for ; Sun, 5 May 2024 16:08:37 +0000 (UTC) X-FDA: 82084825074.12.4D23331 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id E98AA1C0006 for ; Sun, 5 May 2024 16:08:35 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=shLi723c; spf=pass (imf18.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=1714925316; 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=pRof1tSTgmEXMUdk4kAFoVLet559tdniCWQVUpJ+idFMx1NhwRahD5HQouteeNcZQlV0Cd slV40ycf2vpfYNSqzJOpxgxwHSfrFhdEbecSgMxhUMkE2VMPZopeq1wB50y7r2q5R3JET7 6Arfecya6WjCA56BKAnDds/1/qE+YUI= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=shLi723c; spf=pass (imf18.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=1714925316; a=rsa-sha256; cv=none; b=J/yYDVctnNtwOZEzbcMv0B57TY1oWzXI2zEdoft6IXXNFjROTguDDga7XNeIdI/e/UmBpn QSpmeb6YcBtNErW2ZU/Hhk12Jf2mOp+l2uVlC13kF42QhLQmYyrb2vvIc76+Ue8KSWVgzO m1Lbrhs+zb5I4HNgGDAukuQxdsBE73s= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 27C9460CA0; Sun, 5 May 2024 16:08:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D6A0C4DDE6; Sun, 5 May 2024 16:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925314; bh=Rvc7E+HMMA3ADjVUaU2tKv0yhJenjSe9igrLALIYU0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=shLi723c0/Ur3b0A8AHsKhvLohUMcp+fFUUMZ6JoWOuO5vEUs39+L/bLU4HZMazLh Oe6j35z9wVArorVs5UWBuTif/KnGVNE2nfSyvJKdHwrGSco94b1q6uzOJ2LqA78xCn r0X3Zn9A9c05w7DN1MgC7iLBw5Ui0bVVQ40QO9g5xM2P2hs4Y6ocEzmpBsDnuRAR4P G3oB630XCTubm/c95bjffP8cHPmyJKAYpKOuSeWQhA9ZJFkEyZKwxIOrliQxhSZR7j LUCtg/FcS7hI0tGhTTnDjYlsQ2LUMngmkGzHm7RFwEmCYtpOND4xtNEjQmNcnbgywN nVHYzWj/AfQUg== 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 RESEND v8 09/16] riscv: extend execmem_params for generated code allocations Date: Sun, 5 May 2024 19:06:21 +0300 Message-ID: <20240505160628.2323363-10-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: E98AA1C0006 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 4femefiu3yy7ian9ytj3bgojbawjcn6r X-HE-Tag: 1714925315-243030 X-HE-Meta: U2FsdGVkX185IfW4SN+ITBrMsyDVKbkiCI3hv1v/n3V71vqH+KtXR7DkaKFOguH3RctPKcehQXBg0RwWOclBioYXrUQLAonsgOJ1VUtcK8YbtO4Uh6WvrDNpPJ0mxJg/Vl6iHIZc1Jzsh/uzJ/ulDvUGJUKsgUQRhmo2km4+kKJhSClnXByjPaZrHi4g2sB6kbhYhGDunTtzv1L+OcBjswMA9ioK17SKHYy5CKai0jTw9hc2ND7my9AROHPKYgP9y6G/PeonVRslD6nKSIkGcgjasqU7V4X0wZ8f679vnaxtjlVwlJSx3ab8Q9MggmQrgQaeDGWM+Qx5Cav8KJm62ueXcUNFHqBhbHYbT4p8Gp9MbVOCzrd/HaAzzGCopnWlhUDrIdln6tt+ezhqAKWIxmXDpe+biafqfryRqodxeHBbr07Gn19MCESUi7f0djQoba3qPEOKKoznoeATUqnQdH6fGBzuFXY7ahZEIyzDyLe5wA07h33QawBYNtmJWE5BQGyOR3AetZryDdFPLoGEZ7O27wpsGtrHxWby8VhLCeuglGgbHPeW0dNxnT/ObF0n/lMm8UUOFuHIJon5pNxWdXZd6Tig3L71jLDYhfY9178CM/MZO3+tYbPsoQdILmD8dC7AnygVWDX0tFkZ4Ds8axpoo05lTiGaby9c5FeV3nvuZbaD5YyLQ/W86DI3hZUhlRQwy7zkCsXZ0bdTrljgz3G7SlgX5Q4oiVdnDpvEnJDEyTTG3GKOnFj5BK3Ln5ayGDjm6uqNxJnBS3OvnO+T5HQUIkxvp+7TMbaeMVajT/RdER0wSFV0i9KOanzhzacQzkP3CdBZwI6k/7rAbGKf5tPlDAW4XsQOtauATf5r+FLcfHJ342SW0zx2oRzmQOMIBjM02OInKG73ygH+Ivz8bH86ODnBk7o2yfs/e/U8cnHGqc5JdpxaT2C50Zp/MXL4NJJZdLg1lzJnRIHY/wG AcIR8mhy 7u3yXLK1c9bfWKndkdWYZOunMqu3dvbHX5PI9wRxsdNAdb/jJWc2iCh3w0PWYZKFIaB5+xywJJBLw3+eo/ze3e28UZaKl5gEhpxHj9uNQoG9eltN2V0alqJCRXxweIITLcsOs9SmezpRV4krJuXA+ahQ2wSJRHnIp2QB+jyacbom8C1YyUJyuzC7WrdGM+aTw9Xsg+gfkiZekzt7k1MQWF4Uz5H+PvVsMoNIMHq+Mzq/oHwF7RVa1Z0z9P4dH6ufk7PSJjYlzMCpHG7o8xge8C9ZE1T4PaXOVjMlh+MKiJlBKRnALZYZE/rKH+NTwPkJhWzVcGdByRRrlO6FRTIFa2cZDz4PYOceX0JVoiksU2L6dsDGqVL2iAg/q3iuLEnshgdk3kdT+mkd86TA795oTyQpjDlZdHN9m4TOKsjyYGCvJB6c= 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;