From patchwork Thu Apr 11 16:00:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13626219 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 063F5C4345F for ; Thu, 11 Apr 2024 16:03:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8CBB66B00AA; Thu, 11 Apr 2024 12:03:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 87C376B00AB; Thu, 11 Apr 2024 12:03:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71D316B00AC; Thu, 11 Apr 2024 12:03:22 -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 530126B00AA for ; Thu, 11 Apr 2024 12:03:22 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 12BFCA0A8C for ; Thu, 11 Apr 2024 16:03:22 +0000 (UTC) X-FDA: 81997720644.24.9193279 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf25.hostedemail.com (Postfix) with ESMTP id 688E7A0028 for ; Thu, 11 Apr 2024 16:03:20 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LhJUoNdh; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf25.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=1712851400; 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=Cs0NDNexKOhrv5nHga8HplHks0EW5Fx/pq9Nc8aSjM4=; b=aX6MF+/8gzSB8r+7YhqJ0pGqY0lbKtqL6ig5CAAdHmwZUmWCtl68vwRjjH2JQOsQGjriH3 bH1x3mlWVRpJB+lhLbYHiVFWg97hAlJoLq5lIrDkVcc9Ko91MXtduC9De02US0HaB0Vwcz O41OXzTXQYS14c1MmCCMwBBAWTnIj70= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LhJUoNdh; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf25.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=1712851400; a=rsa-sha256; cv=none; b=aQ1hjU1FbxD4mwmiExOxxAWaIIBC9dXQRyS84bz+3YHw6CVNttAVZNFlyBka0z9+DjVQyI Fn/grt6lgUa1nii1lqEV8szPlyGjhJf02n7eeCbRqC0mo4bMNwfPW6xxed0YfGH0Jn05o8 ZdOmFfAKkQ5wtwEtWILUG6RLlykr2qo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B857D620ED; Thu, 11 Apr 2024 16:03:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94880C2BD11; Thu, 11 Apr 2024 16:03:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712851399; bh=MDN1WZXA3xhpqzlVolNbN2nPNGabqu/EHQ96vnrSojU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LhJUoNdhtV0oZXoRrDXU6eMRqs3zZ5XHBNvrq+6ByzAMbDAa6uq7MBqyMKgbGqZFW HrzUCiC8TYoTAiZJ4eUrIKHEBCy1h9cvybi1lknpDvZxBUbpLxDlWVac4fFQo8y3tl 6XYZrA/ZIeDOZnAcush9O5J+oz/E9mCdnu9FG5iSvvfxcbchbVMnbZJ0Ot60g9khR8 6hlVhoKuSdfItxauM9IOtBNhB/qhuG+DV//AyfCzDUlFwdosD585kNGC5cwqVdOxlh 8Zby1LP7fTPzIayJ9Zh0PVhOV8QUnueDvX81krMeKPRGIRxcKLNazZfZgzVpP34N6W ovAGcgA2RpWQg== 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 , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Puranjay Mohan , Rick Edgecombe , Russell King , 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 v4 09/15] riscv: extend execmem_params for generated code allocations Date: Thu, 11 Apr 2024 19:00:45 +0300 Message-ID: <20240411160051.2093261-10-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240411160051.2093261-1-rppt@kernel.org> References: <20240411160051.2093261-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X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o02H 22+hPWat l7WkyF0Rn+ev4BIgCDPycFJl74OT1oOmuAAHLAnj4dMmBVpiqQblNDfPG3t7Re7rGoYHWfyc1qHaEmb44l0ZD5CY7tVlIqxqMZrMg/O9oFJF5T8QGULx8J0Hm0tGDUOGBCCtgfv3UBteDfq5OasIpdlJahLj7S+/0kcKydZajDdt324l6/gaIOjoewg3R4PAtpgPp16vwMUy+un0JW+5o0gBj27WuHRlGtVmO6/+ONtaik0Hf9Dd6WpPv4y4GdbETEh4MkT6RNaa46Ob4fbCvMIG9Laicv4VerndgvSzBJpBgSiuUw/Evdl0h4fAFvHhvuzlxeS0AT9UNLvkhuaUUnJIBNHYTCDFRZFlY0Bbo0T8ee4Y6IJDUZaMBpcIfbFc8rorLK7+nWB/FVA95KKG86Wiy5svya+GjMiQn7JroPutGP+Y= 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 | 21 ++++++++++++++++++++- arch/riscv/kernel/probes/kprobes.c | 10 ---------- arch/riscv/net/bpf_jit_core.c | 13 ------------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index ad32e2a8621a..aad158bb2022 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -906,20 +906,39 @@ 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 = { .ranges = { [EXECMEM_DEFAULT] = { .pgprot = PAGE_KERNEL, .alignment = 1, }, + [EXECMEM_KPROBES] = { + .pgprot = PAGE_KERNEL_READ_EXEC, + .alignment = 1, + }, + [EXECMEM_BPF] = { + .pgprot = PAGE_KERNEL, + .alignment = PAGE_SIZE, + }, }, }; struct execmem_info __init *execmem_arch_setup(void) { +#ifdef CONFIG_64BIT execmem_info.ranges[EXECMEM_DEFAULT].start = MODULES_VADDR; execmem_info.ranges[EXECMEM_DEFAULT].end = MODULES_END; +#else + execmem_info.ranges[EXECMEM_DEFAULT].start = VMALLOC_START; + execmem_info.ranges[EXECMEM_DEFAULT].end = VMALLOC_END; +#endif + + execmem_info.ranges[EXECMEM_KPROBES].start = VMALLOC_START; + execmem_info.ranges[EXECMEM_KPROBES].end = VMALLOC_END; + + execmem_info.ranges[EXECMEM_BPF].start = BPF_JIT_REGION_START; + execmem_info.ranges[EXECMEM_BPF].end = BPF_JIT_REGION_END; return &execmem_info; } 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;