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 104E4C3ABD9 for ; Wed, 14 May 2025 09:04:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D22F66B010A; Wed, 14 May 2025 05:04:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD1C86B010B; Wed, 14 May 2025 05:04:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9B336B010C; Wed, 14 May 2025 05:04:20 -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 99B966B010A for ; Wed, 14 May 2025 05:04:20 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9BB0D140B82 for ; Wed, 14 May 2025 09:04:20 +0000 (UTC) X-FDA: 83440927080.24.4577F73 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf20.hostedemail.com (Postfix) with ESMTP id 67DB31C0004 for ; Wed, 14 May 2025 09:04:18 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=vO9H0UFg; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Nddhf0kz; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=vO9H0UFg; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Nddhf0kz; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf20.hostedemail.com: domain of pfalcato@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=pfalcato@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1747213458; a=rsa-sha256; cv=none; b=Jd0YtkAT5nogVlTSAN5tke7n38ZrTnypOWd/Vb7QY8t3GrPA6K3+QAwvmeSBLVKDn5I/99 6bwVrJs6qyuIaEGVtdv9YtPiRz82HKjYlEdamEz1SOfh6eSjo7mmjvJ2LV9HL/Dls+BJh+ YP7lvGpOcJv/LbYD7UVwOQn/BVIZ+jM= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=vO9H0UFg; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Nddhf0kz; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=vO9H0UFg; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Nddhf0kz; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf20.hostedemail.com: domain of pfalcato@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=pfalcato@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1747213458; 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=uil2b5IHzAypI/ph0mhKh3JmhrE9zgPSiFLLhXdGaQQ=; b=SgLf16b2zFh3/Jhc6K6c7wcp4/oIkyQONaF7qJUVwK5gKMUWB/yduuD2btJ3p/surE7nqE PCZvHErU/DClA+d+79C3DTpVeOOm0caKyE7mFB08ihIxWCITEEDRbVphbYgzq8KqNitVme i7/JUswQ1MzpHGigwfYbEVBsvf2F8dA= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B44D01F455; Wed, 14 May 2025 09:04:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1747213456; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=uil2b5IHzAypI/ph0mhKh3JmhrE9zgPSiFLLhXdGaQQ=; b=vO9H0UFgUGPqAD7S9PR22XyYmZEo4xckkeaxaJy2QBBk19e+FlGmdCsHuHCdQrFO51dAN4 K1hyHUGgN4/RImC8hR4QHwnpOniqJ0dRR6JF0KeZeDfz3/k7RdD9faZGPYaX1yTC5Ydplb kijPL7F+gCVhqt1Jg4H7vIlMIEpLoH4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1747213456; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=uil2b5IHzAypI/ph0mhKh3JmhrE9zgPSiFLLhXdGaQQ=; b=Nddhf0kzJBh7W69czTE7u1ndGQPV5T9HrRdfSFAl72xwPjchGcqyXIzCOQwli2z7vIWld/ IZLdF+OQi3LUDaBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1747213456; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=uil2b5IHzAypI/ph0mhKh3JmhrE9zgPSiFLLhXdGaQQ=; b=vO9H0UFgUGPqAD7S9PR22XyYmZEo4xckkeaxaJy2QBBk19e+FlGmdCsHuHCdQrFO51dAN4 K1hyHUGgN4/RImC8hR4QHwnpOniqJ0dRR6JF0KeZeDfz3/k7RdD9faZGPYaX1yTC5Ydplb kijPL7F+gCVhqt1Jg4H7vIlMIEpLoH4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1747213456; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=uil2b5IHzAypI/ph0mhKh3JmhrE9zgPSiFLLhXdGaQQ=; b=Nddhf0kzJBh7W69czTE7u1ndGQPV5T9HrRdfSFAl72xwPjchGcqyXIzCOQwli2z7vIWld/ IZLdF+OQi3LUDaBg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id BEBE7137E8; Wed, 14 May 2025 09:04:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id fySAK49cJGjpIAAAD6G6ig (envelope-from ); Wed, 14 May 2025 09:04:15 +0000 Date: Wed, 14 May 2025 10:04:06 +0100 From: Pedro Falcato To: Lorenzo Stoakes Cc: Andrew Morton , David Hildenbrand , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jann Horn , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Viro , Christian Brauner , Jan Kara , Matthew Wilcox Subject: Re: [PATCH v2 1/3] mm: introduce new .mmap_prepare() file callback Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Action: no action X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 67DB31C0004 X-Rspam-User: X-Stat-Signature: 8gxx5fyhgnrmp3yudzygtmm7ot8bpkus X-HE-Tag: 1747213458-639977 X-HE-Meta: U2FsdGVkX1/6/i8VhjEXbBy621cWBuibcHER5k2AooPYf3DlrCJoTUDQXsYDqtM0ukAivjbLkw2oIN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2iKn5QDjnFXe+3er1lDLqd09rOsbEgIcFBZFNoNVbWt0DByR9wBNq+AFRgQxbaSilFAVcVQ7NfhUBVkpjgO1vUo4S3Xrrk2kO//447Sep1gB+kwSKx4nKW1bJHVzkmXA3CARxaU29bNjtekZFtNW5e9mC80w5F6WcJZbFBSiJpOVbfJRw+58E98SBfqxFP1Kh4eaBLJeMIjzKorXw== 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 Fri, May 09, 2025 at 01:13:34PM +0100, Lorenzo Stoakes wrote: > Provide a means by which drivers can specify which fields of those > permitted to be changed should be altered to prior to mmap()'ing a > range (which may either result from a merge or from mapping an entirely new > VMA). > > Doing so is substantially safer than the existing .mmap() calback which > provides unrestricted access to the part-constructed VMA and permits > drivers and file systems to do 'creative' things which makes it hard to > reason about the state of the VMA after the function returns. > > The existing .mmap() callback's freedom has caused a great deal of issues, > especially in error handling, as unwinding the mmap() state has proven to > be non-trivial and caused significant issues in the past, for instance > those addressed in commit 5de195060b2e ("mm: resolve faulty mmap_region() > error path behaviour"). > > It also necessitates a second attempt at merge once the .mmap() callback > has completed, which has caused issues in the past, is awkward, adds > overhead and is difficult to reason about. > > The .mmap_prepare() callback eliminates this requirement, as we can update > fields prior to even attempting the first merge. It is safer, as we heavily > restrict what can actually be modified, and being invoked very early in the > mmap() process, error handling can be performed safely with very little > unwinding of state required. > > The .mmap_prepare() and deprecated .mmap() callbacks are mutually > exclusive, so we permit only one to be invoked at a time. > > Update vma userland test stubs to account for changes. > > Signed-off-by: Lorenzo Stoakes Reviewed-by: Pedro Falcato Neat idea, thanks. This should also help out with the insane proliferation of vm_flags_set in ->mmap() callbacks all over. Hopefully. However, could we: 1) Add a small writeup to Documentation/filesystems/vfs.rst for this callback 2) Possibly add a ->mmap_finish()? With a fully constructed vma at that point. So things like remap_pfn_range can still be used by drivers' mmap() implementation. 1) is particularly important so our VFS and driver friends know this is supposed to be The Way Forward. -- Pedro