Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7490494rwd; Tue, 6 Jun 2023 11:27:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6CaXJE7845uajOWc7zZIcwcLnSlj/ThiACzB5KasZQVQQ7ERcaDempKLLkMqv6bKPK1fNw X-Received: by 2002:ac8:5acf:0:b0:3f7:b95:f088 with SMTP id d15-20020ac85acf000000b003f70b95f088mr774861qtd.20.1686076021552; Tue, 06 Jun 2023 11:27:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686076021; cv=none; d=google.com; s=arc-20160816; b=A1XIlbzCvrhuE6FJJpT7DMOVt+WLtWnB63EK8raMdX5+jVn5oXbanOzVdwgxFSRnAv u0i0z1gaRfMANrQmIBU6Pup+SlbHAOCFDSFRyclyIpZHuL7KDup3rRU+YJ40971lA0wC rYwZYTZas2I8RDpmSfVj8ZEfje/pMltw2QfEpjCj887TnogJJ6qhkzrIHFUtL5KS8DJs GVpV2UQyIRghzHuw8PhQt5ljwUOtTaWDfbiSteW2BIM+WsiMfZTiXB71SJ5H1ZH+Yihi P8mDL8KtPgOzr3iXkR78qx5C2IoGbkTiOCDO0oGUcFzlUwrnO0tWAj811w6oC2+PKvBW 2MxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=gUp1lyN0N2Ks0pVMczla3oRBRAnjVdsr6Z2JxKGyImU=; b=sw1f9+xnilsZxenkevDrbyccMbF7AmIlASSRwcdcOykTj+MvMJ5Yc1oyvR48kEURvR XDKM+hM3HQ5VaKiPrDzaQicRUccKLhi5AqLFjoFLQlp7Mq6/n+MieBINg61wf6jNlwHx 0U/3GGrXOZ1dgUjcpyRq/kDI1djngLJstDaV8Q3HeM56ZP1Z0kbmXBYGIwxDc9PuDKYM X5ymsxMLsvq5tH1YkSkM/yFcKHldDOV/rtR0jc2Qq6PdSoiL8ThxDVpcc1ya2ahhXW17 IMI3++CfgC6/0/xOFlt89eIvl6oZOSrOKyourIELXtumw9VQ/NRYd6OGqw+bKjk5Cknk Mu7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PvVbLJcY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j13-20020a05622a038d00b003f02ab8a1efsi6484598qtx.499.2023.06.06.11.26.46; Tue, 06 Jun 2023 11:27:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PvVbLJcY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238340AbjFFSWV (ORCPT + 99 others); Tue, 6 Jun 2023 14:22:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238431AbjFFSWQ (ORCPT ); Tue, 6 Jun 2023 14:22:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA00F170A; Tue, 6 Jun 2023 11:22:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4586963696; Tue, 6 Jun 2023 18:22:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A236EC433A8; Tue, 6 Jun 2023 18:22:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686075733; bh=08bgDTu6K2r14VqmkEIMfCPJQ/ZZrnAx7Zh60inB9tQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=PvVbLJcYr9sEPc4KvXnz7da5hnzjz64447Y1vyViBiCb+fl59qj0pvbLDlkg7Wuob rzrnBjSOFtiQecuq+LZ/SRRxmzgXLdbIbqyyYrcYGhY29RsiV56QlreCUSnVm+stVt UoVEGKhBSdT54YRh1gXdKSmvd62cZB1711kSzDIW8D76YUK3gBLlfz43UtqujOAa4M WNIOBkfcw2WKv0IUzEzdSsuoiqNT0iAk+aytnzF0p5Ex5Qs+2o2gd4vHHiQKTwquZM rFReB/rrpz7owlp/MdxR2Mp3uAIDm8MwdFNdtC8Gq4wlspi7VJYfgsGIf9GhxSZs3/ 0v9cbIwE3cmiA== Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2b1a4250b07so75710911fa.3; Tue, 06 Jun 2023 11:22:13 -0700 (PDT) X-Gm-Message-State: AC+VfDzCXm5+70Ovpz7W746cGaUigh8vo5Bs482Vva0c0k6BOaC8cWYw xXE/STitpg+B5AXPalqdCtTYAhMWQ+XDi+gPtfw= X-Received: by 2002:a2e:82d0:0:b0:2b0:297c:cbdf with SMTP id n16-20020a2e82d0000000b002b0297ccbdfmr1546782ljh.1.1686075731505; Tue, 06 Jun 2023 11:22:11 -0700 (PDT) MIME-Version: 1.0 References: <20230601101257.530867-1-rppt@kernel.org> <20230605092040.GB3460@kernel.org> In-Reply-To: From: Song Liu Date: Tue, 6 Jun 2023 11:21:59 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 00/13] mm: jit/text allocator To: Mark Rutland Cc: Mike Rapoport , Kent Overstreet , linux-kernel@vger.kernel.org, Andrew Morton , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Heiko Carstens , Helge Deller , Huacai Chen , Luis Chamberlain , Michael Ellerman , "Naveen N. Rao" , Palmer Dabbelt , Russell King , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 5, 2023 at 3:09=E2=80=AFAM Mark Rutland = wrote: [...] > > > > Can you give more detail on what parameters you need? If the only e= xtra > > > > parameter is just "does this allocation need to live close to kerne= l > > > > text", that's not that big of a deal. > > > > > > My thinking was that we at least need the start + end for each caller= . That > > > might be it, tbh. > > > > Do you mean that modules will have something like > > > > jit_text_alloc(size, MODULES_START, MODULES_END); > > > > and kprobes will have > > > > jit_text_alloc(size, KPROBES_START, KPROBES_END); > > ? > > Yes. How about we start with two APIs: jit_text_alloc(size); jit_text_alloc_range(size, start, end); AFAICT, arm64 is the only arch that requires the latter API. And TBH, I am not quite convinced it is needed. > > > It sill can be achieved with a single jit_alloc_arch_params(), just by > > adding enum jit_type parameter to jit_text_alloc(). > > That feels backwards to me; it centralizes a bunch of information about > distinct users to be able to shove that into a static array, when the cal= lsites > can pass that information. I think we only two type of users: module and everything else (ftrace, kpro= be, bpf stuff). The key differences are: 1. module uses text and data; while everything else only uses text. 2. module code is generated by the compiler, and thus has stronger requirements in address ranges; everything else are generated via some JIT or manual written assembly, so they are more flexible with address ranges (in JIT, we can avoid using instructions that requires a specific address range). The next question is, can we have the two types of users share the same address ranges? If not, we can reserve the preferred range for modules, and let everything else use the other range. I don't see reasons to further separate users in the "everything else" group. > > What's *actually* common after separating out the ranges? Is it just the > permissions? I believe permission is the key, as we need the hardware to enforce permission. > > If we want this to be able to share allocations and so on, why can't we d= o this > like a kmem_cache, and have the callsite pass a pointer to the allocator = data? > That would make it easy for callsites to share an allocator or use a dist= inct > one. Sharing among different call sites will give us more benefit (in TLB misses rate, etc.). For example, a 2MB page may host text of two kernel modules, 4 kprob= es, 6 ftrace trampolines, and 10 BPF programs. All of these only require one en= try in the iTLB. Thanks, Song