Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2604751rdb; Fri, 22 Sep 2023 03:45:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IElYpVVAQDCFWWfXaQyx3TEk0Z7RVvW2g9eNEvQN2U0zB2oGcRBZW2+ba4Rtg5VvxVeN2CQ X-Received: by 2002:a05:6358:5e17:b0:13a:6748:9312 with SMTP id q23-20020a0563585e1700b0013a67489312mr9274038rwn.19.1695379536804; Fri, 22 Sep 2023 03:45:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695379536; cv=none; d=google.com; s=arc-20160816; b=HsuHZM65iIv4N3+q5nFGAelUi8TUQzXvNrjgz4HAqlBmqkZuxFy159PqK5lYtqACWp 8F8qsvYT/Ozj+gelZeX9kANOe6EEAgPa47F2c3vIo+U09f4VR4/14bgaXY8YP3/RmneF XYWTJVGwrSscdrYFScGsDalS2Yqut+7cSmGJcd6myBOddEurBAAVm3lahoz3P9gyCXBh ESLhle3+uvOcam4dmRGZiu7GZfi7V8v1cSLnOpZetKc1u5jIDMnHOC6RTBVd+xwt5unu 1Qua8bYR9bpzrDJuBpe05QiGYkd3NuF80nRAIzyh8XZaYS6vlTPWdLUz+4KccEch1Ko0 7T5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=MnfyPyP1eXY85yzC1NyuH5AqhjSL71JC0ohrFZx2gnQ=; fh=0w4ucDDsSCkYHmSbzJ2JLC+J0hfQq60L+TmCI6MkBdc=; b=Jxzw7DCFCM31SgTrWqNflyACK5cDzo8R8WqSkY6qIwuZDljT2dUQ9innpRnpuX/veq D2zYLYnn+QOn72UIYSFyigUTphqR1IlyZ5j8V4CrZkHCnICPbEAVx/XrjDnexifyzdAv yfBP2HLSB7ivxr3+At24KO1cROrU1HraCVnf0Bmwhbz/R/j9naaMnNm0OPYTuAu1IsfY BQcYEQJnwoaqLHwUmkyNF9b3J17Fv32OxBmtiud/FRrUXECj0mc3IDC+jKH66sXlJzQ+ 2PvAi3ByEQQUK3mMS4TrmsH1+avZx4/+WTUUiqgFahP8mhoYEbZw+WLxqCfoODh0caxF NMOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id o6-20020a056a0015c600b00690d935fa4csi3698792pfu.356.2023.09.22.03.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 03:45:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 1B528825E484; Fri, 22 Sep 2023 03:38:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233361AbjIVKhj (ORCPT + 99 others); Fri, 22 Sep 2023 06:37:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233366AbjIVKhc (ORCPT ); Fri, 22 Sep 2023 06:37:32 -0400 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B9F999; Fri, 22 Sep 2023 03:37:24 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 85F6740004; Fri, 22 Sep 2023 10:37:08 +0000 (UTC) Message-ID: <6d686c54-078d-8d71-d4e2-c754cf92c557@ghiti.fr> Date: Fri, 22 Sep 2023 12:37:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v3 08/13] riscv: extend execmem_params for generated code allocations Content-Language: en-US To: Mike Rapoport , linux-kernel@vger.kernel.org Cc: Andrew Morton , =?UTF-8?B?QmrDtnJuIFTDtnBl?= =?UTF-8?Q?l?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Luis Chamberlain , Mark Rutland , Michael Ellerman , 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 References: <20230918072955.2507221-1-rppt@kernel.org> <20230918072955.2507221-9-rppt@kernel.org> From: Alexandre Ghiti In-Reply-To: <20230918072955.2507221-9-rppt@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-GND-Sasl: alex@ghiti.fr X-Spam-Status: No, score=-2.2 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 22 Sep 2023 03:38:18 -0700 (PDT) Hi Mike, On 18/09/2023 09:29, Mike Rapoport wrote: > 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) > --- > 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, Not entirely sure it is the same alignment (sorry did not go through the entire series), but if it is, the alignment above ^ is not the same that is requested by our current bpf_jit_alloc_exec() implementation which is PAGE_SIZE. > + }, > }, > }; > > 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; Otherwise, you can add: Reviewed-by: Alexandre Ghiti Thanks, Alex