From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E017B3D8912; Fri, 9 Oct 2026 14:44:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791557094; cv=none; b=Hwtxfkk4tiHk1rC40Yhs7Oma3UX7izAQM5n63JK1OawMk/OTIFDsoxIwEptnh4unWGSSaCHISMFQXGnPJqMUC3/OJmv4ber/CBeBiOn6Gogb6dr5VU++Pm9h25WA3dyWY4vdcBMtTFvJv7vUVbaaPrxHVeuKknqT52d1oLqJFx4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791557094; c=relaxed/simple; bh=JKISAsTPdfRTQ0HOZkaM0pP/CZFRxxkIKUIHnKrPd4Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=agvzhr/A/G63eiqeRCr0n71+Xt4sBOIP+jysFRUH8y+FttXNiWAdFbkHAIM9n/wzvpxe7QgnwY5rFP8nie20jOpINQRMVFZkBXuQzKz2MytOmYSM9dpIaFceuAYeojS+PI1TdpCTF9lj5zQ7bWQpJTMTIaBe2sJZOiwR6cQoRz4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=BMR8ivIk; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="BMR8ivIk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1FF11F000FF; Fri, 9 Oct 2026 14:44:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1791557092; bh=QzjS9JUIBPatGI9fPZ5ghc/j4PknDudpaY2XQLjDBSU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BMR8ivIkBbKmI+3NKIeINcR6YLC2Q/zaBwct0CJrx7wcVduZ/meeEw4NEQsTX3x+N HuJosjx695yubCbuFpxiN/wnh46u2OZwdMtAQJr8L2lfTw51zB/UWHalqSD9rBUryI rIelWsx8IEHBfh72R0XytgGtTlt+lHql+sMbdzsw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Lorenzo Stoakes , David Hildenbrand , Jason Gunthorpe , Pedro Falcato , Alexander Gordeev , Al Viro , Andreas Larsson , Andrey Konovalov , Arnd Bergmann , Baolin Wang , Baoquan He , "Chatre, Reinette" , Christian Borntraeger , Christian Brauner , Dan Williams , Dave Jiang , Dave Martin , Dave Young , "David S. Miller" , Dmitriy Vyukov , Guo Ren , Heiko Carstens , Hugh Dickins , James Morse , Jan Kara , Jann Horn , Jonathan Corbet , Kevin Tian , Konstantin Komarov , Liam Howlett , "Luck, Tony" , "Matthew Wilcox (Oracle)" , Michal Hocko , Mike Rapoport , Muchun Song , Nicolas Pitre , Oscar Salvador , Robin Murohy , Sumanth Korikkar , Suren Baghdasaryan , Sven Schnelle , Thomas Bogendoerfer , "Uladzislau Rezki (Sony)" , Vasily Gorbik , Vishal Verma , Vivek Goyal , Vlastimil Babka , Will Deacon , Andrew Morton , Sasha Levin Subject: [PATCH 6.18 345/403] mm/vma: rename __mmap_prepare() function to avoid confusion Date: Fri, 9 Oct 2026 16:11:46 +0200 Message-ID: <20261009141000.334027270@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261009140952.119038291@linuxfoundation.org> References: <20261009140952.119038291@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lorenzo Stoakes [ Upstream commit 2bcd9207dedc585bae33ad7b337f2232a8a11da8 ] Now we have the f_op->mmap_prepare() hook, having a static function called __mmap_prepare() that has nothing to do with it is confusing, so rename the function to __mmap_setup(). Link: https://lkml.kernel.org/r/d25a22c60ca0f04091697ef9cda0d72ce0cf8af3.1760959442.git.lorenzo.stoakes@oracle.com Signed-off-by: Lorenzo Stoakes Reviewed-by: David Hildenbrand Reviewed-by: Jason Gunthorpe Reviewed-by: Pedro Falcato Cc: Alexander Gordeev Cc: Al Viro Cc: Andreas Larsson Cc: Andrey Konovalov Cc: Arnd Bergmann Cc: Baolin Wang Cc: Baoquan He Cc: Chatre, Reinette Cc: Christian Borntraeger Cc: Christian Brauner Cc: Dan Williams Cc: Dave Jiang Cc: Dave Martin Cc: Dave Young Cc: David S. Miller Cc: Dmitriy Vyukov Cc: Greg Kroah-Hartman Cc: Guo Ren Cc: Heiko Carstens Cc: Hugh Dickins Cc: James Morse Cc: Jan Kara Cc: Jann Horn Cc: Jonathan Corbet Cc: Kevin Tian Cc: Konstantin Komarov Cc: Liam Howlett Cc: "Luck, Tony" Cc: Matthew Wilcox (Oracle) Cc: Michal Hocko Cc: Mike Rapoport Cc: Muchun Song Cc: Nicolas Pitre Cc: Oscar Salvador Cc: Robin Murohy Cc: Sumanth Korikkar Cc: Suren Baghdasaryan Cc: Sven Schnelle Cc: Thomas Bogendoerfer Cc: "Uladzislau Rezki (Sony)" Cc: Vasily Gorbik Cc: Vishal Verma Cc: Vivek Goyal Cc: Vlastimil Babka Cc: Will Deacon Signed-off-by: Andrew Morton Preserve the separate setup and callback error paths so a failed callback still undoes memory accounting. Record whether merging found a VMA and use that result to select new VMA allocation. This preserves existing behavior while providing the allocated_new flag needed by the follow-up change to user-defined fields. Move the error declaration below the mapping state to avoid a conflict with the follow-up const qualifier change. Stable-dep-of: 976d5e0ddac8 ("mm/vma: predicate setting mmap_prepare VMA fields on new vma alloc") Signed-off-by: Sasha Levin --- mm/vma.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 5beb18b0610b0..d160cc6a608af 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -2382,7 +2382,7 @@ static void update_ksm_flags(struct mmap_state *map) } /* - * __mmap_prepare() - Prepare to gather any overlapping VMAs that need to be + * __mmap_setup() - Prepare to gather any overlapping VMAs that need to be * unmapped once the map operation is completed, check limits, account mapping * and clean up any pre-existing VMAs. * @@ -2391,7 +2391,7 @@ static void update_ksm_flags(struct mmap_state *map) * * Returns: 0 on success, error code otherwise. */ -static int __mmap_prepare(struct mmap_state *map, struct list_head *uf) +static int __mmap_setup(struct mmap_state *map, struct list_head *uf) { int error; struct vma_iterator *vmi = map->vmi; @@ -2693,14 +2693,15 @@ static unsigned long __mmap_region(struct file *file, unsigned long addr, { struct mm_struct *mm = current->mm; struct vm_area_struct *vma = NULL; - int error; bool have_mmap_prepare = file && file->f_op->mmap_prepare; VMA_ITERATOR(vmi, mm, addr); MMAP_STATE(map, mm, &vmi, addr, len, pgoff, vm_flags, file); + bool allocated_new; + int error; map.check_ksm_early = can_set_ksm_flags_early(&map); - error = __mmap_prepare(&map, uf); + error = __mmap_setup(&map, uf); if (error) goto abort_munmap; if (have_mmap_prepare) @@ -2719,7 +2720,8 @@ static unsigned long __mmap_region(struct file *file, unsigned long addr, } /* ...but if we can't, allocate a new VMA. */ - if (!vma) { + allocated_new = !vma; + if (allocated_new) { error = __mmap_new_vma(&map, &vma); if (error) goto unacct_error; @@ -2732,7 +2734,7 @@ static unsigned long __mmap_region(struct file *file, unsigned long addr, return addr; - /* Accounting was done by __mmap_prepare(). */ + /* Accounting was done by __mmap_setup(). */ unacct_error: if (map.charged) vm_unacct_memory(map.charged); -- 2.53.0