Received: by 2002:ab2:7988:0:b0:1f4:b336:87c4 with SMTP id g8csp88482lqj; Thu, 11 Apr 2024 10:33:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWBy5rYNBIsRnyqwcjYEwLsH5lEJ5/p5XOa4AXlanlWuql/u2CFz6y0AiffBXjE0Gj5xkgBFDc6rfo4V55XtQBngQBn0CVNV8HC1sU/LA== X-Google-Smtp-Source: AGHT+IECbXO3IWse/aIoPAQ0ioJcu+6/xDkuvukpXc2A+RlrLgNf5UHuhVanivqvFBH0SISEoCOq X-Received: by 2002:a19:7604:0:b0:515:b0ef:2ae3 with SMTP id c4-20020a197604000000b00515b0ef2ae3mr242489lff.39.1712856792736; Thu, 11 Apr 2024 10:33:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712856792; cv=pass; d=google.com; s=arc-20160816; b=yDuJgV7RBpYQA9WYC87ZcdbgdO6IEWjbA152LHhEZMAevbiXhHOIEJ3lAyUMab+ee5 biYTwIsb5Ak+9BcYAbggr0E7eAcyrNUT/Xjjv6Qkf4QGLRfyvbkzIk7c/aGCH8NLfnmF Lhl+Z6MRN79hGWKbmP2D8HUL4PAhc5ohPn5grhZiWKfZeXHjNWThOXXTvtSPktxE417C peHDSeT4GSR23HLacQ7utbkxAPbMqJn4qyrOYmM6Bd4HTzdxZyogF+h1LJ4XplveQY/l 7Pl6Ko4G0CTkE4lV4PH7uclGi+HzfCYMsXntIZgFs6kGRV0c9fbLXGEIQ2Ts2Ni8ThS1 c3eA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Cs0NDNexKOhrv5nHga8HplHks0EW5Fx/pq9Nc8aSjM4=; fh=SgAimfoqqdos20VWKa/NZoWkGX6dsss6oX4o+VgWJ6E=; b=GL41PksIQ3i9QRJQ2ATHPbKlp6XqePfjODF4ObU175uTGmeSaOGGBy2OxQKhz5m/Ma o6A8l9gAc8dG0LOx9mA587bRm6hugDjHs/se1D5ox2O8JPinreSwYZnWwZKhf5N2P0pA z8enKSTE04KeQ6tjW5CYnBpRmfSPgFQL3PBluEIyPXdQ78Eo8NbnuQtVZl7IdWCzSrs3 oVNUCHseAHAnZD4XkUeqeKoWuWHkGvVvzsK1UFTS5UZkENwlSlrd87atnMSgWIDpDWmV zrrOBnA/OrJV5iUdQbp4FLQq8t9+epcFQClLmXgijWnTkln3DCYjJ1RjLNohaqDAgdjS fG5w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LhJUoNdh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-141262-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141262-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id n25-20020a5099d9000000b0056c3b60243bsi908179edb.308.2024.04.11.10.33.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 10:33:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141262-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LhJUoNdh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-141262-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141262-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 73FC71F21EEB for ; Thu, 11 Apr 2024 17:33:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A030613442D; Thu, 11 Apr 2024 16:03:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LhJUoNdh" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9685F13329C; Thu, 11 Apr 2024 16:03:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712851399; cv=none; b=pajju4r+52geYmIGH4n7U8TqevmbyZ3Dj/gZaET+eny9uKBLIFz5yK3UErx3bTgjGcbjPV+AB6nZHJuJ+jaqtJaVPlG19ZfdWbzRuAhke+k3IBs/M4ffnnlrktxjXU2AhJGL40sCz/R0bYlgUKqb8v2UB/LlKQy0x4nk8yAtCqo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712851399; c=relaxed/simple; bh=MDN1WZXA3xhpqzlVolNbN2nPNGabqu/EHQ96vnrSojU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JaQtBB3bAIncCS7EIcIPvTca4gC8MJRCi3cRfHk9TjywHqLRpLJTpA1U78N43aop++x7kkRwgomHpfun3gcxgZX61neWnaTG0SvHuq3nml8QaFoHdq+6f8JvCvx5JUaGs5Zq36mSlJmJfU8wViEnn0cz6Ntk7IB74k9sW2QACkc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LhJUoNdh; arc=none smtp.client-ip=10.30.226.201 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?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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; -- 2.43.0