From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796149741; b=P+t4goMiKgbcHhSB2QxIJWEqHjuU0EwiRXN5fUrtI7r/wni+zcmSdZmP7rzj7feevGx4 nwobBYVktec7MtCqyC0L0UrKdcvFyxLJH9xAGhWpsYhQmhs40tmfifP8/Izm96NppKH/b I/8wRAts51e/9BdGypAWiPEbpzkqUuwEGuFw3ELLd6bd/lBrYJNDs2X43X3xQq3kaRxPk wznfaiEMMBu6zTfbtcFh5cAZ/n6ZM3H4NMHVL1xmNtrAv4ciunuqmykXUO3I0vFHUMiBf AxHoHNoQ8a8HklesqNzskJp+HYqx0U4TC97k0LP4i1DMwUA9SHtrZp7r/Aoz6xRjKDg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796149741; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=bqbxETis3QvaMWcG3xRuO7JJaxJnthipRAt5l33EQHA=; b=NSrT/X7MzbBCnFWeXexuCszP1sQawo89WqyD1bRbcT2sWKl/qDhjl6zC1+mBXBoZGM8I S35lp59vGW6Rpm/uhcdv5oOFud37rj5Kv8EMF3lwod3L02nKKHIey8aWARHvrcpTc1Gew hLBdoribnnr33fHK6qnayqBVSVeWF/Zm/+mw4/WzS3051s1z0KVEHhbt0G9y56eyEi4ry Axe2/AsNwS6D7hutSVs8MUsB0KDXTmoyB/qVpS4aEvzsEAeHVvWABJFOZRHtbCAwkhCVM k3fTv9RJ4cDqRJFN5+xVxlNyyS0ZAosLt4xrZGP//onDL0Vm/6K//tesx9OP/b2BOBw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b="Z/zyEldc"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 337EA606A337 for ; Tue, 1 Dec 2026 18:29:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=Z/zyEldc Received: by smtp.kernel.org (Postfix) with ESMTPSA id 948AA1F00926; Tue, 1 Dec 2026 18:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796149740; bh=bqbxETis3QvaMWcG3xRuO7JJaxJnthipRAt5l33EQHA=; h=Date:To:From:In-Reply-To:References:Subject; b=Z/zyEldcOHNfKdICuJfKqHqAfIiXpIQcDte/IaTPl19XAuG34yebw+gCHTnD2+qyk UP/vK8yPatnSdM4kRnKaLa/XzTXoctzM0UQZavTSxFQpVA/W5WELlBHRZxrPAa2oKY ejOs4XUfwXU+oXhT3KQj1qRExzisCXt+3vJ93np0= Date: Tue, 01 Dec 2026 10:29:00 -0800 To: mm-commits@vger.kernel.org,ziy@nvidia.com,ying.huang@linux.alibaba.com, vivek.kasireddy@intel.com,vbabka@kernel.org,surenb@google.com, skhan@linuxfoundation.org,shy828301@gmail.com,shakeel.butt@linux.dev, sasha.levin@oracle.com,rppt@kernel.org,rientjes@google.com,riel@surriel.com, rdunlap@infradead.org,rakie.kim@sk.com,pfalcato@suse.de,osalvador@suse.de, nao.horiguchi@gmail.com,muchun.song@linux.dev,mhocko@suse.com,mel@csn.ul.ie, matthew.brost@intel.com,mason@kernel.org,luojiajun3@huawei.com, ljs@kernel.org,liwanp@linux.vnet.ibm.com,lihongfu@kylinos.cn, liam@infradead.org,lance.yang@linux.dev,kraxel@redhat.com, kenneth.w.chen@intel.com,kas@kernel.org,kamezawa.hiroyu@jp.fujitsu.com, jthoughton@google.com,joshua.hahnjy@gmail.com,josef@toxicpanda.com, joern@logfs.org,jinmengzhou22@gmail.com,jiaqiyan@google.com,jgg@ziepe.ca, jannh@google.com,hughd@google.com,harry@kernel.org,guillaume@morinfr.org, gourry@gourry.net,dave.mccracken@oracle.com,corbet@lwn.net,byungchul@sk.com, baolin.wang@linux.alibaba.com,apw@shadowen.org,apopple@nvidia.com, aneesh.kumar@linux.vnet.ibm.com,ak@linux.intel.com,airlied@redhat.com, agl@us.ibm.com,ackerleytng@google.com,aarcange@redhat.com,4ncienth@gmail.com, david@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261125-hugetlb_fixes_2-v1-19-db27fd2f71a8@kernel.org> References: <20261125-hugetlb_fixes_2-v1-19-db27fd2f71a8@kernel.org> Subject: [to-be-updated] mm-hugetlb-use-the-vma-lock-to-stabilize-flags-for-pmd-sharing.patch removed from -mm tree Message-Id: <20261201182900.948AA1F00926@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The quilt patch titled Subject: mm/hugetlb: use the VMA lock to stabilize flags for PMD sharing has been removed from the -mm tree. Its filename was mm-hugetlb-use-the-vma-lock-to-stabilize-flags-for-pmd-sharing.patch This patch was dropped because an updated version will be issued ------------------------------------------------------ From: "David Hildenbrand (Arm)" Subject: mm/hugetlb: use the VMA lock to stabilize flags for PMD sharing Date: Wed, 25 Nov 2026 23:33:17 +0100 huge_pmd_share() currently only shares the page tables of another VMA if it can read-lock the mmap lock of the corresponding mm. That refuses sharing whenever that mm is write-locked or if the mmap lock is contended. mprotect() holds the VMA write lock while changing the flags and the page table entries, so let's read-lock only that VMA instead. As we hold i_mmap_rwsem, that VMA remains part of its mm and cannot go away. Add vma_trylock_read(), a variant of vma_start_read(), that does not require being called with the RCU read lock held, and will also not drop it itself. Link: https://patch.msgid.link/20261125-hugetlb_fixes_2-v1-19-db27fd2f71a8@kernel.org Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton Cc: Muchun Song Cc: Oscar Salvador Cc: Jinmeng Zhou Cc: Hongfu Li Cc: Andrea Arcangeli Cc: Naoya Horiguchi Cc: Hugh Dickins Cc: Baolin Wang Cc: Dave Airlie Cc: Vivek Kasireddy Cc: Gerd Hoffmann Cc: Mike Rapoport Cc: Mel Gorman Cc: Dave McCracken Cc: Andy Whitcroft Cc: Adam Litke Cc: Lorenzo Stoakes Cc: Rik van Riel Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Harry Yoo Cc: Jann Horn Cc: Lance Yang Cc: James Houghton Cc: Yang Shi Cc: Suren Baghdasaryan Cc: Shakeel Butt Cc: Pedro Falcato Cc: Gregory Price Cc: Zi Yan Cc: Joshua Hahn Cc: Rakie Kim Cc: Ying Huang Cc: Matthew Brost Cc: Byungchul Park Cc: Alistair Popple Cc: Wanpeng Li Cc: Andi Kleen Cc: Kenneth W Chen Cc: Michal Hocko Cc: David Rientjes Cc: Joern Engel Cc: Jonathan Corbet Cc: Shuah Khan Cc: Randy Dunlap Cc: Aneesh Kumar K.V Cc: KAMEZAWA Hiroyuki Cc: Kiryl Shutsemau Cc: Sasha Levin Cc: Guillaume Morin Cc: Wanpeng Li Cc: Jason Gunthorpe Cc: Chris Mason Cc: luojiajun Cc: Josef Bacik Cc: Daehyeon Ko <4ncienth@gmail.com> Cc: Ackerley Tng Cc: Jiaqi Yan include/linux/mmap_lock.h | 1 mm/hugetlb.c | 4 - mm/mmap_lock.c | 78 ++++++++++++++++++++++++------------ 3 files changed, 55 insertions(+), 28 deletions(-) --- a/include/linux/mmap_lock.h~mm-hugetlb-use-the-vma-lock-to-stabilize-flags-for-pmd-sharing +++ a/include/linux/mmap_lock.h @@ -278,6 +278,7 @@ static inline bool vma_start_read_locked struct vm_area_struct *vma_start_read_unlocked(struct mm_struct *mm, unsigned long address); +bool vma_trylock_read(struct vm_area_struct *vma); static inline void vma_end_read(struct vm_area_struct *vma) { --- a/mm/hugetlb.c~mm-hugetlb-use-the-vma-lock-to-stabilize-flags-for-pmd-sharing +++ a/mm/hugetlb.c @@ -7264,7 +7264,7 @@ pte_t *huge_pmd_share(struct mm_struct * * Stabilize the svma flags, as mprotect() changes flags * before adjusting page tables. */ - if (!mmap_read_trylock(svma->vm_mm)) + if (!vma_trylock_read(svma)) continue; saddr = page_table_shareable(svma, vma, addr, idx); @@ -7274,7 +7274,7 @@ pte_t *huge_pmd_share(struct mm_struct * if (spte) ptdesc_pmd_pts_inc(virt_to_ptdesc(spte)); } - mmap_read_unlock(svma->vm_mm); + vma_end_read(svma); if (spte) break; } --- a/mm/mmap_lock.c~mm-hugetlb-use-the-vma-lock-to-stabilize-flags-for-pmd-sharing +++ a/mm/mmap_lock.c @@ -212,26 +212,17 @@ static bool vma_seqcount_is_write_locked } /* - * Try to read-lock a vma. The function is allowed to occasionally yield false - * locked result to avoid performance overhead, in which case we fall back to - * using mmap_lock. The function should never yield false unlocked result. - * False locked result is possible if vma gets reused and attached to a - * different mm before we lock it. - * Returns the vma on success, NULL on failure to lock and EAGAIN if vma got - * detached. - * - * IMPORTANT: RCU lock must be held upon entering the function, but upon error - * IT IS RELEASED. The caller must handle this correctly. + * Like vma_start_read(), but without RCU handling: the caller must make sure + * that the vma cannot be freed, for example by holding the RCU lock. */ -static struct vm_area_struct *vma_start_read(struct mm_struct *mm, - struct vm_area_struct *vma) +static struct vm_area_struct *__vma_start_read(struct mm_struct *mm, + struct vm_area_struct *vma) { unsigned int vma_seq; unsigned int mm_seq; struct mm_struct *other_mm; int oldcnt; - RCU_LOCKDEP_WARN(!rcu_read_lock_held(), "no rcu lock held"); /* * Check before locking. A race might cause false locked result. * We can use READ_ONCE() for the mm_lock_seq here, and don't need @@ -241,10 +232,8 @@ static struct vm_area_struct *vma_start_ */ vma_seq = READ_ONCE(vma->vm_lock_seq); mm_seq = READ_ONCE(mm->mm_lock_seq.sequence); - if (vma_seqcount_is_write_locked(vma_seq, mm_seq)) { - vma = NULL; - goto err; - } + if (vma_seqcount_is_write_locked(vma_seq, mm_seq)) + return NULL; /* * If VM_REFCNT_EXCLUDE_READERS_FLAG is set, @@ -257,8 +246,7 @@ static struct vm_area_struct *vma_start_ if (unlikely(!__refcount_inc_not_zero_limited_acquire(&vma->vm_refcnt, &oldcnt, VM_REFCNT_LIMIT))) { /* return EAGAIN if vma got detached from under us */ - vma = oldcnt ? NULL : ERR_PTR(-EAGAIN); - goto err; + return oldcnt ? NULL : ERR_PTR(-EAGAIN); } __vma_lockdep_acquire_read(vma); @@ -288,15 +276,10 @@ static struct vm_area_struct *vma_start_ mm_seq = raw_read_seqcount(&mm->mm_lock_seq); if (unlikely(vma_seqcount_is_write_locked(vma_seq, mm_seq))) { vma_refcount_put(vma); - vma = NULL; - goto err; + return NULL; } return vma; -err: - rcu_read_unlock(); - - return vma; err_unstable: /* * If vma got attached to another mm from under us, that mm is not @@ -309,11 +292,54 @@ err_unstable: mmgrab(other_mm); vma_refcount_put(vma); mmdrop_async(other_mm); - rcu_read_unlock(); return NULL; } +/** + * vma_start_read() - Try to read-lock a vma looked up under RCU. + * @mm: The mm the vma is expected to belong to. + * @vma: The vma to read-lock. + * + * The function is allowed to occasionally yield false locked result to avoid + * performance overhead, in which case we fall back to using mmap_lock. The + * function should never yield false unlocked result. False locked result is + * possible if vma gets reused and attached to a different mm before we lock it. + * + * Context: RCU lock must be held upon entering the function, but upon error + * IT IS RELEASED. The caller must handle this correctly. + * + * Return: The vma on success, NULL on failure to lock and ERR_PTR(-EAGAIN) if + * the vma got detached. + */ +static struct vm_area_struct *vma_start_read(struct mm_struct *mm, + struct vm_area_struct *vma) +{ + RCU_LOCKDEP_WARN(!rcu_read_lock_held(), "no rcu lock held"); + + vma = __vma_start_read(mm, vma); + if (IS_ERR_OR_NULL(vma)) + rcu_read_unlock(); + return vma; +} + +/** + * vma_trylock_read() - Try to read-lock a VMA that belongs to its mm. + * @vma: The VMA to read-lock. + * + * Unlike vma_start_read(), this function does not deal with VMAs that might + * get freed and reused in another mm concurrently. + * + * Context: The caller must make sure that @vma remains part of @vma->vm_mm + * and cannot go away. + * + * Return: true if @vma is read-locked, false otherwise. + */ +bool vma_trylock_read(struct vm_area_struct *vma) +{ + return !IS_ERR_OR_NULL(__vma_start_read(vma->vm_mm, vma)); +} + /* * Lookup and lock a VMA under RCU protection. Returned VMA is guaranteed to be * stable and not isolated. If the VMA is not found or is being modified the _ Patches currently in -mm which might be from david@kernel.org are mm-hugetlb-charge-the-copy-made-at-fork-to-the-parent.patch mm-mprotect-dont-skip-uffd-marker-install-when-racing-with-pte-table-reclaim.patch mm-userfaultfd-prevent-poison-marker-loss.patch mm-hugetlb-compare-against-persistent-count-when-freeing-lowmem-folios.patch mm-hugetlb-preserve-reservations-when-shrinking-on-highmem.patch mm-hugetlb-account-temporary-folios-separately.patch mm-hugetlb-account-temporary-folios-separately-fix.patch mm-hugetlb-serialize-page-cache-allocations-with-truncation.patch mm-hugetlb-serialize-page-cache-allocations-with-truncation-fix.patch mm-memfd-recheck-the-page-cache-before-allocating-a-hugetlb-folio.patch mm-hugetlb-count-again-if-the-reserve-map-shrank.patch mm-hugetlb-account-restored-reservations-before-freeing-folios.patch mm-hugetlb-delay-anon-folio-rmap-removal-until-after-the-tlb-flush.patch mm-userfaultfd-reject-dax-mappings.patch uprobes-skip-mappings-not-managed-by-core-mm.patch mm-memory-store-the-pfn-of-cow-pfnmap-mappings-in-the-anon-page-offset.patch mm-hugetlb-always-mark-new-page-cache-folios-migratable.patch mm-memfd-mark-new-hugetlb-folios-migratable.patch mm-hugetlb-free-surplus-folios-of-other-nodes-on-free.patch hugetlbfs-dont-zero-poisoned-pages-in-a-hole-punch.patch mm-hugetlb-only-check-pmd-table-sharing-for-pmd-sized-folios.patch mm-migrate-check-hugetlb-pmd-sharing-in-move_pages.patch mm-hugetlb-dont-share-page-tables-of-a-vma-during-mprotect.patch mm-hugetlb-count-migration-entries-at-fork-and-unmap.patch mm-hugetlb-stop-accounting-hugetlbpages-once-pmd-tables-were-shared.patch fs-proc-task_mmu-dont-clear-vm_softdirty-on-hugetlb-vmas.patch rfc-mm-hugetlb_cgroup-charge-faults-to-mm-owner.patch mm-filemap-avoid-retrying-faults-on-uffd-wp-markers.patch