Received: by 2002:ab2:3c46:0:b0:1f5:f2ab:c469 with SMTP id x6csp128784lqf; Fri, 26 Apr 2024 01:34:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVta4A45kWmzwTANnkoAjBoOlupBkoBZTX7zRWDzvdACScpvWE/9uGMf9t2scyUg1X7D9cU1QBKkBrDiNSAkh35SgWHys9ssbWuU0bqHg== X-Google-Smtp-Source: AGHT+IENXKVllHcYqI1ZbUlWhGSsR4Jx62JSO+vG0f07ALZ6+qLfHgC1L7Dw+KJy4qdufJn2TS7S X-Received: by 2002:a50:8d42:0:b0:56e:2e10:7dad with SMTP id t2-20020a508d42000000b0056e2e107dadmr1487717edt.35.1714120454063; Fri, 26 Apr 2024 01:34:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714120454; cv=pass; d=google.com; s=arc-20160816; b=haLyftwQOo3J5KOPeE4n8lLj716SNdyChxeWuNwtKz4dbOvpH5YCqSG9RGUdwnJF5S S5gMUP9EyWntgqMN2le0rfppLOAsW836sX8gPShcVNj1s14XAKlKav8jVSF4wOu1sRBL dUoMqTmUNz1GktErfbp7vr36g62UsVVytyjt+mmyCoZ69Tq+0yFCz9ZO5QeFitVB05xT tMpPGIYYXtbPTSZxFvCBoBziCBpFsCYS1FjeMBKhAPFENcx4VpEEG8CzzVL/bgeIgt9f QasWm0UgLGfS2e101cV4zLRTamnjjYNVQzP7F1/Ss4t6B14OsgFzEftIqqdbOvYL6k6B G1eQ== 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=ov+Zy6p+o+MKzsKOdrDu2h5RMDTUryzC1DCfp/0ZOLE=; fh=CzSJNj8w8iUnmlgWvNYhDvD5pl9OAXL/ljrL7Y6PMxw=; b=VZ6SDlmrokwcoW9xO3Kp5uq4FW+yHfjrvdgu+Me+BaeOJTroz3b4RIobCv48RsFcWE a8/MeKbTfPBnPjB6Q+L7mODmKGV2f4zP1SLFZwFpRIEs8SULPKavCBmwCcvZ7pJpYJgW H2mAL+uS5Be9iKBPjKD3jY+s9N8fKcYjv45JCLQD8+mKDurvWQI9pMrqKrc7NswVo58o fXq+2zHGV6jkzuGxCIL0bxktjVSOFdhtiMv6lKjmixlzW0VM54gDSzfx3qaSHHV/JhRT 0/1cQHYmcmt9MdpEHK4zoFTIjvmJuOOK1Jg5rKZsRKDIBioMuqxrlwrc/GBKi3TqJcvG l16Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TeunQcB9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-159705-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159705-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 h3-20020a056402280300b00571d592afabsi10008508ede.606.2024.04.26.01.34.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 01:34:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159705-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=TeunQcB9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-159705-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159705-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 B4C521F239D9 for ; Fri, 26 Apr 2024 08:34:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01831144D24; Fri, 26 Apr 2024 08:30:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TeunQcB9" 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 02DE513DB90; Fri, 26 Apr 2024 08:30:54 +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=1714120255; cv=none; b=klRNel5PsqyLa4h8/z7KHuJqwCiKUSZ07fOAq3HhrAiaYD3gjmg+kGT+KnGweqQt69dqHJYubutkScYQq+MtY4DlMc9XMHKWMMBYXkcGQnLGwJA5RLOk/oPuMdKFcCO3eakKAIRuzJ885ZyU1ivHKCERr0p4LC42OMRR5B9JXeo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714120255; c=relaxed/simple; bh=rAIWAHsYUw427kTFrCCQC+4mkWqWWUZB9Zh1fdelySY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L77VgGV/xCyb/ZOyDqRsRZRmGHOFh/vwGKNT2NJlfXxTu5hq1rPoFg/2E2q+/baY8yQgZsrOxtKnl+cWVJmP8sKZCzdB9+yR39PB9HpLJ0l8N4R8OPquFxbkRX1rSD/QZj8FyU0HH9wQ+1SJvB3kbNxKjQQQXRG1VTX42W0kLIk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TeunQcB9; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F4F7C113CD; Fri, 26 Apr 2024 08:30:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120254; bh=rAIWAHsYUw427kTFrCCQC+4mkWqWWUZB9Zh1fdelySY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TeunQcB9PoWap6KReLYBjiDgwQ8R6NLCJAuYMonr4uIqQ+FDsUYfn+3QUwjES0THO 1olpZ/7FEsdEfyqW/qHnL8WrRHW7bhKWVRyd1ldZENl0wFTnC2tjVvMcsRqdWxQ0NG fOgKCeODWoEr15HF0gdHFTqF7s0R11U9gt/BL+AKAUE6DNfjLjlYSoOzlK5/SA6Ir3 aeEy+WpXsNjpRuCI4xRDKAQ1U1cl9VeCvbKO1szZlW8y1ZaBEW0T55yafFLe0HfOu8 RbNw8r8Ae2+ZkPMkhxCgXpo49Tk8Ol2963PvtEdvl1QII5UPXpu+UcDH08b+AIH1Si RHTXLgzCjPOuA== 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 , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 09/16] riscv: extend execmem_params for generated code allocations Date: Fri, 26 Apr 2024 11:28:47 +0300 Message-ID: <20240426082854.7355-10-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-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 | 28 +++++++++++++++++++++++++--- arch/riscv/kernel/probes/kprobes.c | 10 ---------- arch/riscv/net/bpf_jit_core.c | 13 ------------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 182904127ba0..2ecbacbc9993 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -906,19 +906,41 @@ 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) { + unsigned long start, end; + + if (IS_ENABLED(CONFIG_64BIT)) { + start = MODULES_VADDR; + end = MODULES_END; + } else { + start = VMALLOC_START; + end = VMALLOC_END; + } + execmem_info = (struct execmem_info){ .ranges = { [EXECMEM_DEFAULT] = { - .start = MODULES_VADDR, - .end = MODULES_END, + .start = start, + .end = end, .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; -- 2.43.0