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=1796325110; b=V7/gYZPDgWQIWm6Jk+DvNVVbsAQo+MHfXxbcnWj66HjyMwXBhvrfZh2pZ4GfBg6Qvgc8 2gy7URyHAh7CSe4x11SaXCkEW8dzm2BGw3xQ1mAxrbcYjD3HHd0/qMZ9OOusxABrtXMCj R+hE+NAqPY/amOkfkS/nccV96LfTlmrRsjZMUtaTgVyVOy2SpM/B0OoJyWEgeEGm+GESE BWL2oj45cPB0m2dcuJG7Hpxohf34FztnTFNLO7teYEGJ4DnSrNTPHcRSQga5wx/+hO2CF bCY1H6iQNn5C2DZGy+2YRcpLKAWuQGQ1p3dlPIpjomgbze2DeUS9mmnllZdJVa/iyGg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796325110; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-Id: In-Reply-To:References:X-Mailer:Mime-Version:Content-Type: Content-Transfer-Encoding; bh=p6XSH/Jo5bi3tBJBM/QFWE9/JhtjIaQ1AcU+5vQnOoQ=; b=fQAmlhpZ7fdnR3f/KRGAvc5+fbKCR+46i+Hy33Qo80E4TK3ge5lh5ZnQPQBDtABZxsbE ESbbJjqRHlISfeThllLc+HJ2LyuqkdvFgLHso3ljBwFoksFQQ8519K1FrjZ91DqB0PyPt unYM6n1B+o1i1eYDHLBmjOjhd3zqpqw7Lr/41d9rL6qhLzXPLPVu02GQi5UswDzPsgmQq YALRrntL7+Jull2Ga81A+wk5Ekb+ErE5DiaL46vtX26wVZ07awnUHycZIXWO26o66zvuN EzxOcHeH/rhPbYhIRfYkcUWs6pSuPvh+zZMm3ZL2/dE5xxaJbZ4vm8CqX2/8Y+LbjsA== 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=VqOKppdO; 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 86A1960A2604; Thu, 3 Dec 2026 19:11:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=VqOKppdO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46DE51F000C2; Thu, 3 Dec 2026 19:11:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796325110; bh=p6XSH/Jo5bi3tBJBM/QFWE9/JhtjIaQ1AcU+5vQnOoQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=VqOKppdObk03zIIMX2j46OgpWYrdUqu9iKqLCoquAZ0WLSiwPOxRy4Dmcgzps1ICb fgdBENqC94p335jLetWsPWSdO6dfKzZXDoM2rL1rfXAcCftw1cofGMdfL8FOm70b69 hQNZZ10nPAAxrWzdT4O3aBbNCBp1IjahQx0rqTY8= Date: Thu, 3 Dec 2026 11:11:47 -0800 From: Andrew Morton To: "David Hildenbrand (Arm)" Cc: Muchun Song , Oscar Salvador , Hongfu Li , Jinmeng Zhou , Mina Almasry , Davidlohr Bueso , Naoya Horiguchi , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Vivek Kasireddy , Mel Gorman , Hugh Dickins , Baolin Wang , Dave Airlie , Jason Gunthorpe , Andy Whitcroft , Roman Gushchin , Barry Song , Andrea Arcangeli , Lorenzo Stoakes , Suren Baghdasaryan , Shakeel Butt , Pedro Falcato , Jann Horn , Guillaume Morin , Yang Shi , James Houghton , Rik van Riel , Harry Yoo , Lance Yang , Axel Rasmussen , Peter Xu , Sasha Levin , Kiryl Shutsemau , Christian Brauner , "Steven Rostedt (Google)" , Hongbo Li , Gregory Price , Zi Yan , Joshua Hahn , Rakie Kim , Ying Huang , Matthew Brost , Byungchul Park , Alistair Popple , Andi Kleen , David Rientjes , Joern Engel , "Aneesh Kumar K.V" , linux-mm@kvack.org, linux-doc@vger.kernel.org, Gerd Hoffmann , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Johannes Weiner , Chris Mason , Jiaqi Yan , Sashiko , stable@vger.kernel.org Subject: Re: [PATCH v2 00/35] mm/hugetlb: various fixes (2) Message-Id: <20261203111147.70cf4c99e51503134c8d5ae1@linux-foundation.org> In-Reply-To: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 03 Dec 2026 12:37:23 +0100 "David Hildenbrand (Arm)" wrote: > Hi, > > this is v2 with a bunch more fixes, which I didn't want to send separately > to not cause a mess on the list. Most of the new ones are from Sashiko > reports, and some found while working on them. Chris reported two more. updated, thanks. > Changes in v2: > - Collected tags (thanks!). > - Dropped "mm/hugetlb: use the VMA lock to stabilize flags for PMD sharing". > - "mm/hugetlb_cgroup: charge faults to mm->owner" > - Dropped the RFC label. > - Fall back to current->mm like memcg, and also charge reservations to > the mm of the VMA. > - Minor patch description fixups. > - Added new fixes: > - "mm/hugetlb: restore the reservation if vma_needs_reservation() fails" > - "mm/hugetlb: restore the reservation when racing with another reservation" > - "mm/hugetlb: return the reservation to the subpool on error" > - "mm/hugetlb: report reservations that we actually added from > hugetlb_reserve_pages()" > - "mm/hugetlb: keep HPAGE_RESV_UNMAPPED when forking" > - "mm/hugetlb: wait for deferred frees before failing an allocation" > - "mm/hugetlb_cma: reset hugetlb_cma_size if the arch doesn't support it" > - "hugetlbfs: fix integer overflow when punching holes" > - "hugetlbfs: don't overflow the pseudo VMA address in fallocate()" > - "hugetlbfs: don't overflow the end of the unmap range on 32-bit" > - "hugetlbfs: don't skip private VMAs when unmapping on truncation" > - "mm/hugetlb: serialize private faults with truncation" > - "mm/hugetlb: check EOF for UFFDIO_COPY and UFFDIO_POISON" > - "hugetlbfs: zero all hugetlbfs-specific fields of new inodes" > - "mm/rmap: don't fail unmapping hugetlb folios from private VMAs" Here's how v2 altered mm.git: Documentation/mm/hugetlbfs_reserv.rst | 4 fs/hugetlbfs/inode.c | 42 +++--- mm/hugetlb.c | 158 +++++++++++++++--------- mm/hugetlb_cgroup.c | 2 mm/hugetlb_cma.c | 1 mm/rmap.c | 8 - 6 files changed, 129 insertions(+), 86 deletions(-) --- a/Documentation/mm/hugetlbfs_reserv.rst~b +++ a/Documentation/mm/hugetlbfs_reserv.rst @@ -257,8 +257,8 @@ compensate. See the section :ref:`Reservation Map Helper Routines ` for more information on these routines. -For CoW mappings, alloc_hugetlb_folio() calls -folio_clear_hugetlb_restore_reserve() if the reservation came from the subpool. +alloc_hugetlb_folio() calls folio_clear_hugetlb_restore_reserve() if the +reservation came from the subpool. This makes free_huge_folio() return the reservation to the subpool on error. --- a/fs/hugetlbfs/inode.c~b +++ a/fs/hugetlbfs/inode.c @@ -363,15 +363,12 @@ static unsigned long vma_offset_start(st static unsigned long vma_offset_end(struct vm_area_struct *vma, pgoff_t end) { - unsigned long t_end; + const pgoff_t nr_pages = end - vma->vm_pgoff; - if (!end) + if (!end || nr_pages >= vma_pages(vma)) return vma->vm_end; - t_end = ((end - vma->vm_pgoff) << PAGE_SHIFT) + vma->vm_start; - if (t_end > vma->vm_end) - t_end = vma->vm_end; - return t_end; + return vma->vm_start + (nr_pages << PAGE_SHIFT); } /* @@ -485,10 +482,16 @@ hugetlb_vmdelete_list(struct address_spa */ mapping_rmap_tree_foreach(vma, mapping, start, end ? end - 1 : ULONG_MAX) { + const bool need_vma_lock = __vma_shareable_lock(vma); unsigned long v_start; unsigned long v_end; - if (!hugetlb_vma_trylock_write(vma)) + /* + * We only need additional VMA locking here for PMD table + * sharing, which synchronizes on the shareable lock. Other VMAs + * never share PMD tables, so we can unmap them without it. + */ + if (need_vma_lock && !hugetlb_vma_trylock_write(vma)) continue; v_start = vma_offset_start(vma, start); @@ -496,12 +499,8 @@ hugetlb_vmdelete_list(struct address_spa unmap_hugepage_range(vma, v_start, v_end, NULL, zap_flags); - /* - * Note that vma lock only exists for shared/non-private - * vmas. Therefore, lock is not held when calling - * unmap_hugepage_range for private vmas. - */ - hugetlb_vma_unlock_write(vma); + if (need_vma_lock) + hugetlb_vma_unlock_write(vma); } } @@ -675,8 +674,12 @@ static long hugetlbfs_punch_hole(struct /* * hole_start and hole_end indicate the full pages within the hole. + * If rounding up overflows, there are no full pages in the hole. */ - hole_start = round_up(offset, hpage_size); + if (check_add_overflow(offset, hpage_size - 1, &hole_start)) + hole_start = offset + len; + else + hole_start = round_down(hole_start, hpage_size); hole_end = round_down(offset + len, hpage_size); inode_lock(inode); @@ -725,7 +728,6 @@ static long hugetlbfs_fallocate(struct f struct hstate *h = hstate_inode(inode); struct vm_area_struct pseudo_vma; struct mm_struct *mm = current->mm; - loff_t hpage_size = huge_page_size(h); unsigned long hpage_shift = huge_page_shift(h); pgoff_t start, index, end; int error; @@ -772,10 +774,11 @@ static long hugetlbfs_fallocate(struct f for (index = start; index < end; index++) { /* * This is supposed to be the vaddr where the page is being - * faulted in, but we have no vaddr here. + * faulted in, but we have no vaddr here. Let the pseudo VMA + * map the folio at address 0 to avoid overflows. */ + const unsigned long addr = 0; struct folio *folio; - unsigned long addr; cond_resched(); @@ -788,8 +791,7 @@ static long hugetlbfs_fallocate(struct f break; } - /* addr is the offset within the file (zero based) */ - addr = index * hpage_size; + pseudo_vma.vm_pgoff = index << huge_page_order(h); /* mutex taken here, fault path and hole punch */ hash = hugetlb_fault_mutex_hash(mapping, index); @@ -903,7 +905,6 @@ static struct inode *hugetlbfs_get_root( simple_inode_init_ts(inode); inode->i_op = &hugetlbfs_dir_inode_operations; inode->i_fop = &simple_dir_operations; - HUGETLBFS_I(inode)->resv_map = NULL; /* directory inodes start off with i_nlink == 2 (for "." entry) */ inc_nlink(inode); lockdep_annotate_inode_mutex_key(inode); @@ -1205,6 +1206,7 @@ static struct inode *hugetlbfs_alloc_ino hugetlbfs_inc_free_inodes(sbinfo); return NULL; } + memset_after(p, 0, vfs_inode); return &p->vfs_inode; } --- a/mm/hugetlb.c~b +++ a/mm/hugetlb.c @@ -1220,7 +1220,7 @@ void hugetlb_dup_vma_private(struct vm_a { VM_WARN_ON_ONCE_VMA(!vma_is_hugetlb(vma), vma); /* - * Clear vm_private_data + * Clear vm_private_data, except for HPAGE_RESV_UNMAPPED * - For shared mappings this is a per-vma semaphore that may be * allocated in a subsequent call to hugetlb_vm_op_open. * Before clearing, make sure pointer is not associated with vma @@ -1229,7 +1229,10 @@ void hugetlb_dup_vma_private(struct vm_a * been called to allocate a new structure. * - For MAP_PRIVATE mappings, this is the reserve map which does * not apply to children. Faults generated by the children are - * not guaranteed to succeed, even if read-only. + * not guaranteed to succeed, even if read-only. But keep + * HPAGE_RESV_UNMAPPED: if the reservation owner unmapped folios + * from this VMA when its COW fault failed, faults in children must + * fail as well. */ if (vma->vm_flags & VM_MAYSHARE) { struct hugetlb_vma_lock *vma_lock = vma->vm_private_data; @@ -1237,7 +1240,11 @@ void hugetlb_dup_vma_private(struct vm_a if (vma_lock && vma_lock->vma != vma) vma->vm_private_data = NULL; } else { + const bool unmapped = is_vma_resv_set(vma, HPAGE_RESV_UNMAPPED); + vma->vm_private_data = NULL; + if (unmapped) + set_vma_resv_flags(vma, HPAGE_RESV_UNMAPPED); } } @@ -2742,7 +2749,9 @@ static long vma_del_reservation(struct h * In case 2, simply undo reserve map modifications done by alloc_hugetlb_folio. * * For CoW mappings, allocations using a subpool reservation leave the - * flag clear and the reserve map unchanged. free_huge_folio returns the + * flag clear and the reserve map unchanged. The same applies to shared + * mappings, except that case 2 removes the reservation from the reserve map, + * unless updating the reserve map fails. free_huge_folio returns the * reservation to the subpool. */ void restore_reserve_on_error(struct hstate *h, struct vm_area_struct *vma, @@ -2750,21 +2759,27 @@ void restore_reserve_on_error(struct hst { long rc = vma_needs_reservation(h, vma, address); - if (folio_test_hugetlb_restore_reserve(folio)) { - if (unlikely(rc < 0)) - /* - * Rare out of memory condition in reserve map - * manipulation. Clear hugetlb_restore_reserve so - * that global reserve count will not be incremented - * by free_huge_folio. This will make it appear - * as though the reservation for this folio was - * consumed. This may prevent the task from - * faulting in the folio at a later time. This - * is better than inconsistent global huge page - * accounting of reserve counts. - */ + if (unlikely(rc < 0)) { + /* + * Rare out of memory condition in reserve map manipulation. + * + * In shared mappings, the reserve map has the reservation for + * this index, so let folio freeing code restore it. + * + * Otherwise, don't restore the reservation, making it appear + * as though it was consumed. This may prevent the task from + * faulting in the folio at a later time, but is better than + * inconsistent global huge page accounting of reserve counts. + */ + if (vma->vm_flags & VM_MAYSHARE) + folio_set_hugetlb_restore_reserve(folio); + else folio_clear_hugetlb_restore_reserve(folio); - else if (rc) + return; + } + + if (folio_test_hugetlb_restore_reserve(folio)) { + if (rc) (void)vma_add_reservation(h, vma, address); else vma_end_reservation(h, vma, address); @@ -2789,11 +2804,6 @@ void restore_reserve_on_error(struct hst * on a subsequent allocation. */ folio_set_hugetlb_restore_reserve(folio); - } else if (rc < 0) { - /* - * Region cache allocation can fail even if an entry exists. - * Leave the flag and reserve map unchanged. - */ } else { /* * No reservation present, do nothing @@ -3210,6 +3220,9 @@ static struct folio *__alloc_hugetlb_fol }; folio = hugetlb_alloc_folio(h, &mpoli, memcg_mm, alloc_flags); + /* Wait for deferred freeing and retry once before giving up. */ + if (IS_ERR(folio) && flush_work(&free_hpage_work)) + folio = hugetlb_alloc_folio(h, &mpoli, memcg_mm, alloc_flags); mpol_cond_put(mpol); @@ -3220,6 +3233,18 @@ static struct folio *__alloc_hugetlb_fol hugetlb_set_folio_subpool(folio, spool); + /* + * On error, let folio freeing code return the reservation to the + * subpool, unless we consumed a reservation from the reserve map. + * + * In private mappings, the reserve map might not exist or already + * account for another folio at this index. In shared mappings, + * restore_reserve_on_error() will remove the reservation we are about + * to add to the reserve map, unless updating the reserve map fails. + */ + if (map_chg != MAP_CHG_REUSE) + folio_clear_hugetlb_restore_reserve(folio); + if (map_chg != MAP_CHG_ENFORCED) { /* commit() is only needed if the map_chg is not enforced */ retval = vma_commit_reservation(h, vma, addr); @@ -3242,17 +3267,14 @@ static struct folio *__alloc_hugetlb_fol hugetlb_cgroup_uncharge_folio_rsvd( hstate_index(h), pages_per_huge_page(h), folio); spin_unlock_irq(&hugetlb_lock); + /* + * We consumed that existing reservation and must + * restore it when freeing the folio due to errors. + */ + folio_set_hugetlb_restore_reserve(folio); } } - /* - * Return subpool reservations to the subpool on error. A CoW mapping - * might not have a reserve map, or it might already account for - * another folio at this index. - */ - if (map_chg != MAP_CHG_REUSE && vma_is_cow_mapping(vma)) - folio_clear_hugetlb_restore_reserve(folio); - return folio; out_subpool_put: @@ -5975,6 +5997,7 @@ static vm_fault_t hugetlb_no_page(struct const bool pagecache_folio = vmf->vma->vm_flags & VM_MAYSHARE; u32 hash = hugetlb_fault_mutex_hash(mapping, vmf->pgoff); bool folio_locked = true, new_anon_folio = false; + bool invalidate_locked = false; struct vm_area_struct *vma = vmf->vma; struct mm_struct *mm = vma->vm_mm; struct hstate *h = hstate_vma(vma); @@ -6034,15 +6057,19 @@ static vm_fault_t hugetlb_no_page(struct ret = __vmf_anon_prepare(vmf); if (unlikely(ret)) goto out; - } else { - /* Recheck EOF before consuming an inode reservation. */ - filemap_invalidate_lock_shared(mapping); - if (!hugetlb_pgoff_valid(mapping, vmf->pgoff, /* partial= */ false)) { - filemap_invalidate_unlock_shared(mapping); - goto out; - } + ret = VM_FAULT_SIGBUS; } + /* + * Recheck EOF and keep truncation out until the folio is in the + * page cache, or until we mapped the new anonymous folio: + * truncation unmaps or removes it afterwards. + */ + filemap_invalidate_lock_shared(mapping); + invalidate_locked = true; + if (!hugetlb_pgoff_valid(mapping, vmf->pgoff, /* partial= */ false)) + goto out; + folio = alloc_hugetlb_folio(vma, vmf->address, false); if (IS_ERR(folio)) { /* @@ -6061,8 +6088,6 @@ static vm_fault_t hugetlb_no_page(struct ret = vmf_error(PTR_ERR(folio)); else ret = 0; - if (pagecache_folio) - filemap_invalidate_unlock_shared(mapping); goto out; } folio_zero_user(folio, vmf->real_address); @@ -6083,10 +6108,10 @@ static vm_fault_t hugetlb_no_page(struct folio); folio_put(folio); ret = VM_FAULT_SIGBUS; - filemap_invalidate_unlock_shared(mapping); goto out; } filemap_invalidate_unlock_shared(mapping); + invalidate_locked = false; folio_set_hugetlb_migratable(folio); } else { new_anon_folio = true; @@ -6185,6 +6210,8 @@ static vm_fault_t hugetlb_no_page(struct */ spin_unlock(vmf->ptl); out: + if (invalidate_locked) + filemap_invalidate_unlock_shared(mapping); hugetlb_vma_unlock_read(vma); /* @@ -6528,13 +6555,31 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_ bool folio_in_pagecache = false; pte_t dst_ptep; + /* + * Check EOF and keep truncation out until we mapped the new folio or + * installed the poison marker: truncation unmaps or removes it + * afterwards. + */ + if (!is_continue) { + filemap_invalidate_lock_shared(mapping); + if (!hugetlb_pgoff_valid(mapping, idx, /* partial= */ false)) { + if (*foliop) { + folio_put(*foliop); + *foliop = NULL; + } + ret = -EFAULT; + goto out; + } + } + if (uffd_flags_mode_is(flags, MFILL_ATOMIC_POISON)) { ptl = huge_pte_lock(h, dst_mm, dst_pte); /* Don't overwrite any existing PTEs (even markers) */ if (!huge_pte_none(huge_ptep_get(dst_mm, dst_addr, dst_pte))) { spin_unlock(ptl); - return -EEXIST; + ret = -EEXIST; + goto out; } VM_WARN_ON_ONCE(size == PMD_SIZE && hugetlb_pmd_shared(dst_pte)); @@ -6545,19 +6590,8 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_ update_mmu_cache(dst_vma, dst_addr, dst_pte); spin_unlock(ptl); - return 0; - } - - if (alloc_pagecache_folio) { - filemap_invalidate_lock_shared(mapping); - if (!hugetlb_pgoff_valid(mapping, idx, /* partial= */ false)) { - if (*foliop) { - folio_put(*foliop); - *foliop = NULL; - } - ret = -EFAULT; - goto out; - } + ret = 0; + goto out; } if (is_continue) { @@ -6726,7 +6760,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_ spin_unlock(ptl); ret = 0; out: - if (alloc_pagecache_folio) + if (!is_continue) filemap_invalidate_unlock_shared(mapping); return ret; out_release_unlock: @@ -6912,9 +6946,9 @@ next: /* * Update the reservation map for the range [from, to]. * - * Returns the number of entries that would be added to the reservation map - * associated with the range [from, to]. This number is greater or equal to - * zero. -EINVAL or -ENOMEM is returned in case of any errors. + * Returns the number of huge pages that we reserved in the range [from, to], + * or a negative error code. On a later error, callers must only undo + * these reservations, not reservations that already existed in the range. */ long hugetlb_reserve_pages(struct inode *inode, @@ -6987,7 +7021,8 @@ retry: } err = hugetlb_cgroup_charge_cgroup_rsvd(hstate_index(h), - chg * pages_per_huge_page(h), NULL, &h_cg); + chg * pages_per_huge_page(h), + vma ? vma->vm_mm : NULL, &h_cg); if (err < 0) goto out_err; @@ -7057,6 +7092,11 @@ retry: rsv_adjust = hugepage_subpool_put_pages(spool, chg - add); hugetlb_acct_memory(h, -rsv_adjust); + /* + * Only report the reservations that we added, such that + * callers will not undo the racing reservations. + */ + chg = add; } else if (h_cg) { /* * The file_regions will hold their own reference to --- a/mm/hugetlb_cgroup.c~b +++ a/mm/hugetlb_cgroup.c @@ -287,6 +287,8 @@ static struct hugetlb_cgroup *hugetlb_cg #ifdef CONFIG_MEMCG /* Like memcg, charge the owner of the mm we allocate for. */ + if (!mm) + mm = current->mm; if (mm) task = rcu_dereference(mm->owner); #endif --- a/mm/hugetlb_cma.c~b +++ a/mm/hugetlb_cma.c @@ -249,6 +249,7 @@ void __init hugetlb_cma_reserve(void) order = arch_hugetlb_cma_order(); if (!order) { pr_warn("hugetlb_cma: the option isn't supported by current arch\n"); + hugetlb_cma_size = 0; return; } --- a/mm/rmap.c~b +++ a/mm/rmap.c @@ -48,7 +48,7 @@ * hugetlbfs PageHuge() take locks in this order: * hugetlb_fault_mutex (hugetlbfs specific page fault mutex) * vma_lock (hugetlb specific lock for pmd_sharing) - * mapping->invalidate_lock (when allocating page cache folios) + * mapping->invalidate_lock (when allocating folios) * folio_lock * mapping->i_mmap_rwsem (also used for hugetlb pmd sharing) */ @@ -2049,7 +2049,7 @@ static bool try_to_unmap_poisoned_hugetl * acquiring vma_lock BEFORE i_mmap_rwsem. We can only try lock here and * fail if unsuccessful. */ - if (!folio_test_anon(folio)) { + if (__vma_shareable_lock(vma)) { struct mmu_gather tlb; VM_WARN_ON_ONCE(!(flags & TTU_RMAP_LOCKED)); @@ -2580,8 +2580,6 @@ static bool try_to_migrate_one(struct fo PageAnonExclusive(subpage); if (folio_test_hugetlb(folio)) { - bool anon = folio_test_anon(folio); - /* * huge_pmd_unshare may unmap an entire PMD page. * There is no way of knowing exactly which PMDs may @@ -2601,7 +2599,7 @@ static bool try_to_migrate_one(struct fo * i_mmap_rwsem. We can only try lock here and * fail if unsuccessful. */ - if (!anon) { + if (__vma_shareable_lock(vma)) { struct mmu_gather tlb; VM_BUG_ON(!(flags & TTU_RMAP_LOCKED)); _