From patchwork Mon Sep 18 07:29:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13388977 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 791EECD37B0 for ; Mon, 18 Sep 2023 07:31:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FCBE6B0287; Mon, 18 Sep 2023 03:31:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0AD816B0289; Mon, 18 Sep 2023 03:31:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6AF46B028A; Mon, 18 Sep 2023 03:31:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D2EFA6B0287 for ; Mon, 18 Sep 2023 03:31:39 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id AB4D380BAB for ; Mon, 18 Sep 2023 07:31:39 +0000 (UTC) X-FDA: 81248898318.03.29A5161 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf10.hostedemail.com (Postfix) with ESMTP id 612D8C0002 for ; Mon, 18 Sep 2023 07:31:36 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=sUl4tcVd; spf=pass (imf10.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1695022298; 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=r7WH6k3cQ1gcDKVDqjiXKIrMyc70EktDzeRRqm44eao=; b=guK22mI3q5bVkvRQ3AgzwHdZlAm5g6GyBNiu66iyQJOEvJ9YsEftb+o5Cwh3LqPYMzpdDq lwLz7/xKuRtcq4GZSb2hdWYFm9p98ikadrQIfEeSTOXDxYzVqitbRvzCIBSXWZhJ63DW3m VQCWEQWjztckOTPAuvbaqoqOOofGcb8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695022298; a=rsa-sha256; cv=none; b=sHb4Me9aVLRn3hH6787Qxu6RhbYfIp4+Z9bIB+JI8YSPjz5wi0y98TwrlZETxWzoaZNvnA qrEbOYgCef+BhkCI3IJwLUL7UpuodgWWNNCerERaHS7EwgM7etwi4ecQTWH+QzCXFnAf8P Cxtayl8iEiG+E9oonMWhpL8GCkw6bis= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=sUl4tcVd; spf=pass (imf10.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 771DBCE0CE2; Mon, 18 Sep 2023 07:31:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90D66C4160E; Mon, 18 Sep 2023 07:31:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695022292; bh=Bxy7NNRI6l4akC8Uk0JGSyZsyMn1J934EmvkFA96qyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sUl4tcVd+CE1RIfDd+iHzBuo/TtqH+sjUX4AKoidjsBhiPE9N8u5sBFCrh0U2OnnW 02VNXIu/PasFZvJmqp4LQS/fRSyOWf9W0w4R1mThqbVlQHxfh9deE8Gen6PrybSKrA HQTfOkMmKWxzdY89y0l1tlT8/WpmYk4oOHqiKiyXMFacErx4oC2oV4nkojcJ6bpZun 9S9TLaBh1Kth+hdxlxcmXjxDVU8y/jq3PgPfSmOZxNeFoZYJdyBqlLfSCGOoTzYYQr s02+6pJi35T4N9EWcJQvWIbsw2teHNSr/sLV1vIIuBQWC8WuxxKTSKFPi24i20hJWy PMgDbwaP/8Fzw== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBl?= =?utf-8?b?bA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Luis Chamberlain , Mark Rutland , Michael Ellerman , Mike Rapoport , Nadav Amit , "Naveen N. Rao" , Palmer Dabbelt , Puranjay Mohan , Rick Edgecombe , Russell King , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@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 v3 08/13] riscv: extend execmem_params for generated code allocations Date: Mon, 18 Sep 2023 10:29:50 +0300 Message-Id: <20230918072955.2507221-9-rppt@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918072955.2507221-1-rppt@kernel.org> References: <20230918072955.2507221-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 612D8C0002 X-Rspam-User: X-Stat-Signature: 91uacuni16mnaxxbxebdg9bfwxmgmgud X-Rspamd-Server: rspam03 X-HE-Tag: 1695022296-782610 X-HE-Meta: U2FsdGVkX19cw3NReJRGrRno8Ss/HLHeKSjmP4c4RvMIo5DbeUPXOE0cTcLMGG5mMt+0tREZAipuYH+GMRibLZirDgF909EMIq3cNjGJCKgi75hYZUoJp/Rg4Ro/UiJ4rU/qXq8O85oW/IxRwbOk0I+1QmL+rEs5oxRld8bnBDrc3fOtAMcnGFpZdTT39w4joJxCRxFnRaEeM5LPeA5yh2EdwVzq67SxhctZ64QsC+rialVEDeS3Y09cFEmEOL4ocmrCu6QemR4ZrdflMtVFVUI6cmqgWTG46tLdeUuxH6dhMMsJGZMK6jBDKoD/ndbZ+TCskjYIT6Cjgdrxq7+LuzmfmpJnYVjw+jpMjqLpdQDePKazmQ4rqSbFs0etFlHFnrIup8UqkysLJ3XcBxTR04m2kP7LvDDxJz72cmalCL3OfJBZL1LHOwBSDM671IgHavPdOmaDWPDJpxRPnmt0cPg4MgW+qx0kMm63VtXywq7so9VGEp4VSXyxZaUKYA6YoJijkbUFLK2wUe4NomSmJIPgRuTX0FE9ozwUcALsWXSxLmoRT/xesHUQRtcyIR1q3Evntf9UoHwUGxvJBOCXJOxE0ehUeRKhSCzaWZoc4V+e3bWG+AzQr6tCK9JUzOnaBXfVMFX+Gd4TkIxIscxj5ZQC6vU+XR3+4UQshA6uc+nUFWFWDDFmOOYqliWqvBSTD91ENnIhuvKiS5jon9AlgC+3tGvEHHofGfFxSGAdjeEdQQjSMSCM6ilY0oE4IEj/nug1IjBNRFy+5oXyJyp75kt+VpMXYX+puDEN2XKDzULEjHs/Ptm5xSYzsJYLw2S9K91hC8sTOgXo1yjBqafWhtj/eVnUDVmTKQY1UYHQdWxKydwf933qvqkHCy8wc5uL/rU1zHA/SakmBHHdobFXh454p47ZmTwRmmtNt4jpavUXm6OybqtBqDeWs/wlclw8s7B1+ifyPo5D5pDbqdX QPtma5e/ t62//pW4E2H0Ctv9ViX9RWll5Hw1mOxe1e/ihw8vE8/Z7F2OYGhmoGWYbyPPpbGhAvI30oxIuVTolysUWPgyIixJKcNwTA23krhfw0UqCk6wfum8LYIFa2N9wdELtFW2rogsN0Du8iP0Q6Ho7K+FootEBeTKuNllssPhWRZkUeOORrCwSJjodRyEqu53laHAnTjoUPs0b5Y+l452DmmHB98DqjWaOqmGf/ObDPIQ8SRiV80Da0BhoK3Gki7/e6VDws4NgcaPo7PWYci+ylrwPxq+EPe7yrDvY0pBoehRiYf+fhmeAr8aUK/XkUDFJjt/cQ9lWVOgkDQpAOCukZm50GRD55KJNkOHen84w5eIXnB463uO+AXOYt2LhRst1BzUY4k2x57MviP2EM1h68bJi8aBppXQs6GO0SMSJTsssnIJ+06H/g4swN8WZv+MKr8Oe7FuhPdafTuM8j7c= 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: 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 343a0edfb6dd..31505ecb5c72 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -436,20 +436,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_params execmem_params __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 = 1, + }, }, }; struct execmem_params __init *execmem_arch_params(void) { +#ifdef CONFIG_64BIT execmem_params.ranges[EXECMEM_DEFAULT].start = MODULES_VADDR; execmem_params.ranges[EXECMEM_DEFAULT].end = MODULES_END; +#else + execmem_params.ranges[EXECMEM_DEFAULT].start = VMALLOC_START; + execmem_params.ranges[EXECMEM_DEFAULT].end = VMALLOC_END; +#endif + + execmem_params.ranges[EXECMEM_KPROBES].start = VMALLOC_START; + execmem_params.ranges[EXECMEM_KPROBES].end = VMALLOC_END; + + execmem_params.ranges[EXECMEM_BPF].start = BPF_JIT_REGION_START; + execmem_params.ranges[EXECMEM_BPF].end = BPF_JIT_REGION_END; return &execmem_params; } 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 7b70ccb7fec3..c8a758f0882b 100644 --- a/arch/riscv/net/bpf_jit_core.c +++ b/arch/riscv/net/bpf_jit_core.c @@ -218,19 +218,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;