From mboxrd@z Thu Jan 1 00:00:00 1970 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 29C43C4345F for ; Mon, 15 Apr 2024 17:36:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 776126B009D; Mon, 15 Apr 2024 13:36:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 726086B009E; Mon, 15 Apr 2024 13:36:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6142D6B009F; Mon, 15 Apr 2024 13:36:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 439776B009D for ; Mon, 15 Apr 2024 13:36:58 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E169C1A0720 for ; Mon, 15 Apr 2024 17:36:57 +0000 (UTC) X-FDA: 82012471674.23.2488B80 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf27.hostedemail.com (Postfix) with ESMTP id D95F440016 for ; Mon, 15 Apr 2024 17:36:55 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of mark.rutland@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=mark.rutland@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713202616; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3B1XBSbVzHR6uLKaOnU39HK4qtAlE9TOmILPHc8pjb8=; b=e3JDV0p/EkIY/0AXDKzMcOACBvO9Jd2uQDjDo0wgwRvRdOMFWSL73WliEjP6PlIzE26gsn XeMM+bFpZpSK8prPXlXa60I2NJg5ob4oroMJ7A65/YL0Z2ISg1zOg+dJ28jLsl4xlM1a61 KzR63YNrs5qaiTFOK9YEh0cGMWsYgBE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713202616; a=rsa-sha256; cv=none; b=gMG/JC37iW8j+u8ZhZbSIBhMQKuvvUNmqfVqjppTPnJ29zadakt13JO7RtNTDjqQeMy2n2 HBf6ytCBTxD8t5kUxbvqaqliNixOrAAAYs1w/1IT05uwvj2HERfVFWLcz6DXuKhKqPikWZ I4F9o0ON2ufxf2bGszIaFJuO786hZZY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of mark.rutland@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=mark.rutland@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 30ED11515; Mon, 15 Apr 2024 10:37:23 -0700 (PDT) Received: from FVFF77S0Q05N.cambridge.arm.com (FVFF77S0Q05N.cambridge.arm.com [10.1.38.162]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6579A3F64C; Mon, 15 Apr 2024 10:36:49 -0700 (PDT) Date: Mon, 15 Apr 2024 18:36:39 +0100 From: Mark Rutland To: Peter Zijlstra Cc: Mike Rapoport , linux-kernel@vger.kernel.org, Alexandre Ghiti , Andrew Morton , "Bj\"orn T\"opel" , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Luis Chamberlain , Michael Ellerman , 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: Re: [PATCH v4 05/15] mm: introduce execmem_alloc() and execmem_free() Message-ID: References: <20240411160051.2093261-1-rppt@kernel.org> <20240411160051.2093261-6-rppt@kernel.org> <20240415075241.GF40213@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240415075241.GF40213@noisy.programming.kicks-ass.net> X-Rspamd-Queue-Id: D95F440016 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: my53jkpqqyym3ze71t59s5rh8s5ia5wg X-HE-Tag: 1713202615-256544 X-HE-Meta: U2FsdGVkX1/JRjvACKw0BLCmO/LBflIFETV1TkPwgPFL2xx9ULcy2NCW+mfmYTjXHs39Pj9e1ZqENn2I7jpeqtopis56So2ZEWzXybhJssRXO90N9e+eWJNWwYHDjom51gVglFZmM4N3UPiQMBi/DxcU2cFrX8DOJA+u0Eo1uFrYbAXQRhz3KOoehUt+rSNiZpXvuQyfpDG89JCThpj5brRBjTc6Kn3wsbUHKJmS12wdnv3wWzBVXy/DErVrwwaDU3np9RWtNZgSYvwNFH865pg4MZHSx8h6PSN2QAEV9w4zVeY5kJsvia+CIe2ODJccyRZtufeNOoWR9lYY9h4Mf7h7FFaPw1xC3kM8EPaL++RhibGVo4iGbIsJrRfzD6erEVinB+JLYeBS/XALkjljNGBElJ3+999jyDUgm1B6Y7mysR3hFXGhvLiWyZ/N3HWlzv3xQXtyC2nY6xcOYIu33V3jql5RBYO/5XxZoNGP3Lnilf5adAcBhBOsg8Kikutq5F3UTXaD/+T7OL6mP8FoBWEZeALGO0Co9w4mpJXRMkL107f1YftEd0OxKJeswjpkK5CXYF/VQ0FGgDU8xyaeFBinnV8ZsXnJiuKwdM1YgHeDcUfCY2byPjaGG7i+2A543FBc2QKwmIGYXigZTmRh/WWpv0eItQcRVtO81cLQg6+uNiQ6AWYHJhi+KeZgjOJtZPocrvhtBFFik/dUBU6YeR0A3FQ+xl/V82CbT2D7s3dVfncsw62XM1mB6QPd1ZWBLWULvBJa9F9Gwn3R1E/XsfHyWP1OS1AfS4avRZ8XU/C+OPHl21ATEJHwInw78IVsWdhp8xo+Yi+XL2zUAmawcz2DXdqPHtlrDRGFZjo9GPgT5nu54cZuy8cfSnPY02Jq1DeFaok9L3ejewHUIJEUNdMuWl68EST/KUu28ZVvlFVUf85EjpVdSXYEEfooZLw0pBvNWn49VM3P+n5HM4+ eDiBJPe2 yt2NUgCWzFZCsCml4raSYdnkLH9BQ84DU1vmU2gezaN0kXaANcTXPItEKqaCKNBWBcFyYpuRE2EzMTGpNVc5MTOGevipfWrDpQDfItNas+BhK9MmsKE9G/4OqiykqJOnB4r7PDNTEqOayZfAiw/JB0egcV5SW6X2Kj9XqKlLh1M479FTRQH3MgXr/apU5s6X16dywYVXiu8aVrRH46v63IN8fjKjr2/miS6mHHJSNP5m42Dq4ApFQFUMzEDpuGvVoyRK/nZbNkEio+S5NxVefsSRLUEM23CR8d3SkYO8sj2o6ysu3SpVzVGTPNtGfYiTAntLD X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Apr 15, 2024 at 09:52:41AM +0200, Peter Zijlstra wrote: > On Thu, Apr 11, 2024 at 07:00:41PM +0300, Mike Rapoport wrote: > > +/** > > + * enum execmem_type - types of executable memory ranges > > + * > > + * There are several subsystems that allocate executable memory. > > + * Architectures define different restrictions on placement, > > + * permissions, alignment and other parameters for memory that can be used > > + * by these subsystems. > > + * Types in this enum identify subsystems that allocate executable memory > > + * and let architectures define parameters for ranges suitable for > > + * allocations by each subsystem. > > + * > > + * @EXECMEM_DEFAULT: default parameters that would be used for types that > > + * are not explcitly defined. > > + * @EXECMEM_MODULE_TEXT: parameters for module text sections > > + * @EXECMEM_KPROBES: parameters for kprobes > > + * @EXECMEM_FTRACE: parameters for ftrace > > + * @EXECMEM_BPF: parameters for BPF > > + * @EXECMEM_TYPE_MAX: > > + */ > > +enum execmem_type { > > + EXECMEM_DEFAULT, > > + EXECMEM_MODULE_TEXT = EXECMEM_DEFAULT, > > + EXECMEM_KPROBES, > > + EXECMEM_FTRACE, > > + EXECMEM_BPF, > > + EXECMEM_TYPE_MAX, > > +}; > > Can we please get a break-down of how all these types are actually > different from one another? > > I'm thinking some platforms have a tiny immediate space (arm64 comes to > mind) and has less strict placement constraints for some of them? Yeah, and really I'd *much* rather deal with that in arch code, as I have said several times. For arm64 we have two bsaic restrictions: 1) Direct branches can go +/-128M We can expand this range by having direct branches go to PLTs, at a performance cost. 2) PREL32 relocations can go +/-2G We cannot expand this further. * We don't need to allocate memory for ftrace. We do not use trampolines. * Kprobes XOL areas don't care about either of those; we don't place any PC-relative instructions in those. Maybe we want to in future. * Modules care about both; we'd *prefer* to place them within +/-128M of all other kernel/module code, but if there's no space we can use PLTs and expand that to +/-2G. Since modules can refreence other modules, that ends up actually being halved, and modules have to fit within some 2G window that also covers the kernel. * I'm not sure about BPF's requirements; it seems happy doing the same as modules. So if we *must* use a common execmem allocator, what we'd reall want is our own types, e.g. EXECMEM_ANYWHERE EXECMEM_NOPLT EXECMEM_PREL32 ... and then we use those in arch code to implement module_alloc() and friends. Mark.