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 0526DC369DC for ; Tue, 29 Apr 2025 16:55:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 515ED6B0022; Tue, 29 Apr 2025 12:55:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C4B36B0023; Tue, 29 Apr 2025 12:55:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38D436B0024; Tue, 29 Apr 2025 12:55:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 196666B0022 for ; Tue, 29 Apr 2025 12:55:24 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 19FFD1CE401 for ; Tue, 29 Apr 2025 16:55:25 +0000 (UTC) X-FDA: 83387682210.16.8484BCA Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf10.hostedemail.com (Postfix) with ESMTP id 78372C000B for ; Tue, 29 Apr 2025 16:55:23 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="OYga2AQ/"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf10.hostedemail.com: domain of kees@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kees@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745945723; a=rsa-sha256; cv=none; b=iSqPQ3XamKlUR0WBdeKjh84Tf978o5XrxxmljaAMPInfbrms4+VqVmfOtwATFdQpiHcZZo U7FBcyzG/tE3/a6VxQk58rcbZd9JjOwi77itpDuCi6UY0EGrLYUekmyo23/VfcwKrpTI1P 2vLxom+3Nx6K+oYC0u/BODMQ0u7REJ8= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="OYga2AQ/"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf10.hostedemail.com: domain of kees@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kees@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1745945723; 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:dkim-signature; bh=5QHUPWSMguxYaS7zcae6gCahJWBo/d9b/4Mk0EXL7l0=; b=2opoz4odi2zq/qof7R+NJq7CmQKUNEqMXIglrZSm5vczMg2qTtzPKoxbmtMttmVO+R5uj8 gytTFo3pwJu6mBelrscHEEGwWA8fHI4J3fQozWqXnzkqY2qYPfXl/FLHNDPWE8if3XBmUm UrC8gAeJ0lQT+QpV26tevBfXLgufLNk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 997425C0574; Tue, 29 Apr 2025 16:53:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69EF4C4CEE3; Tue, 29 Apr 2025 16:55:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745945722; bh=zOfFyoWEGxCDaELYIHhgqtimzYsmJUad3XFMv+J9Gww=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OYga2AQ/n5CMnGfLO0FrGw4hYy0VS9DZAsGKM8g3JMDjgTvyqNtaCRzsd86TIL2tl LMq5LcvAYc1YEiGMhkue/+b6Nz7EChrQhsPzOnTdbUDGhtPC7ZjUe9Q7VAU5ufb9qF EmQByFib7oHXtw1nYB33UXQXD/IJxGTiuNjzHsrqV0drlM/NwrBG1fk4pvaq+Ch4Nz 5B12gH/ch0V0XfCs+y6OBJnjld6CMqzRQOC3X7yEyLFe/i7y5Ox/jwVVlgKMkn4Z/4 GJlzvH5StU9voS8WmcFy9X3YqP2460VMS67lyI3O+uMdhEdoulaiIw5x0UWFRKKue8 usES8/yRhdO2g== Date: Tue, 29 Apr 2025 09:55:19 -0700 From: Kees Cook To: Lorenzo Stoakes Cc: Vlastimil Babka , Andrew Morton , "Liam R . Howlett" , Jann Horn , Pedro Falcato , David Hildenbrand , Alexander Viro , Christian Brauner , Jan Kara , Suren Baghdasaryan , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 0/4] move all VMA allocation, freeing and duplication logic to mm Message-ID: <202504290954.C391C2B@keescook> References: <044b4684-4b88-4228-9bf6-31491b7738ba@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 78372C000B X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: homsxedyj67hzde6osi4wx7ebx8px3xt X-HE-Tag: 1745945723-951286 X-HE-Meta: U2FsdGVkX1/Wl84/4VNLljfxeW5YNQXEluvJ2Ks92GUvpnWqc1sVdqhHr0dSzIKs46MXcjZasDG5h+QZHEX8ykxnAMIzpQze1lEPwUHMsbhBZGD5XpKkZfpwRh3FjHfImix9fa6bLAJXhd9EDOZPVg7kp4uyXRJAwutUSLtdnbJimdYoJEXljgvMTbfWVk0ZQ7T4ZRWOlRTw2Yx9TwsDrsdJZTs9Ubbz4iVfYCypxDnCUfbRCtOl1UYB4P78uNIXbQR1W7a2p7yflKGVe6CjQsfvmCtlcAJI9UkGHfkeGvExOynFQ4UikhyIzQSz+4Lzf4D+1vcfheGeLBiwBESC7utus/Ze/oUxSMHlF3/yj5mMhRhXqr2oMGnpFbtBTkq83kx6rDI6RgPj+spy1JgF1dflLNQiGPkrETQ76c3qi17QeQDIcwzUH3o3Zd7hfDg0Uh88/BSXgU5kh2FdL+Wteh2pPHthmECLLZTbxDib2yjfAGvdQin6byww7d+WZ1awmovkajHJZEZCbgq6jK3Af7+XOjdWlyahbQ3377enS/dy/PsU87T6lBqAEp7ZzTikcEjfG/hsK3XiDgmKMH46ENnvYELjJPRwzoFswWrkYNcxgVgjJNlTd+A9nToNCmZNPxbjUdLxhlyAtHLP+UMpdE0Ei3MzfcuDUd18EUPEc2hdQbyAJ1zG0TcF8f6d+6TLaUY6DpHDIdw8ws+G+kH4HSrgX3YevsuR65VjsBhgnfbuVGNtlNA/ZWP+7lnKj7uySeZlXpH9n9wbS5KEAVAU4zpmnyD6mXryDnhDHsbj41desnh243dYtMDsTBTwDVbgsCWPfl5oNseU/yym+raZsyRyNGiy7OBg3rROsdf3jLlvauVR0C/oJx0H96DBQhbYe26yLXVWgnjYZ8cd7za9m6CcTedAczrDRIQG4CaI069U2L9K+G5U0CcUpy9u3NWB13pnHutuaA1aRFpF0V2 WDlRek8m A3I1B6pjBo8HJE8cMQHJsVW7SMPf2mkyv17SwUDVkibrI+FGWTHe/MKoH3kIBNqZaTCJqbA6p3Xz8Cupo60HSxdlsTbIeB4czOdyS95xsEsQdVofIcjyUM3QhcD5uK8fiOu1SIa4C0zlMsXYXSVDt74Ozl6QiBdL9GUI4HLKSudH83LfNlMKnd/K/sG/sirYIHCaxFrbWNSd7jwjTCX46cHEdrsW7KS6k2gAEvD4aT2tcUdpxWkKQxT35DLzmuZSGiuum 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: List-Subscribe: List-Unsubscribe: On Tue, Apr 29, 2025 at 11:23:25AM +0100, Lorenzo Stoakes wrote: > On Tue, Apr 29, 2025 at 09:28:05AM +0200, Vlastimil Babka wrote: > > On 4/28/25 17:28, Lorenzo Stoakes wrote: > > > Currently VMA allocation, freeing and duplication exist in kernel/fork.c, > > > which is a violation of separation of concerns, and leaves these functions > > > exposed to the rest of the kernel when they are in fact internal > > > implementation details. > > > > > > Resolve this by moving this logic to mm, and making it internal to vma.c, > > > vma.h. > > > > > > This also allows us, in future, to provide userland testing around this > > > functionality. > > > > > > We additionally abstract dup_mmap() to mm, being careful to ensure > > > kernel/fork.c acceses this via the mm internal header so it is not exposed > > > elsewhere in the kernel. > > > > > > As part of this change, also abstract initial stack allocation performed in > > > __bprm_mm_init() out of fs code into mm via the create_init_stack_vma(), as > > > this code uses vm_area_alloc() and vm_area_free(). > > > > > > In order to do so sensibly, we introduce a new mm/vma_exec.c file, which > > > contains the code that is shared by mm and exec. This file is added to both > > > memory mapping and exec sections in MAINTAINERS so both sets of maintainers > > > can maintain oversight. > > > > Note that kernel/fork.c itself belongs to no section. Maybe we could put it > > somewhere too, maybe also multiple subsystems? I'm thinking something > > between MM, SCHEDULER, EXEC, perhaps PIDFD? > > Thanks, indeed I was wondering about where this should be, and the fact we can > put stuff in multiple places is actually pretty powerful! > > This is on my todo, will take a look at this. Yeah, I'd be interested in having fork.c multi-maintainer-sectioned with EXEC/BINFMT too, when the time comes. -- Kees Cook